Plugin Directory

Changeset 403829


Ignore:
Timestamp:
07/02/2011 07:31:12 PM (15 years ago)
Author:
froman118
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • my-link-order/trunk/mylinkorder.php

    r196530 r403829  
    44Plugin URI: http://www.geekyweekly.com/mylinkorder
    55Description: My Link Order allows you to set the order in which links and link categories will appear in the sidebar. Uses a drag and drop interface for ordering. Adds a widget with additional options for easy installation on widgetized themes.
    6 Version: 2.9.1
     6Version: 3.1.4
    77Author: Andrew Charlton
    88Author URI: http://www.geekyweekly.com
     
    1010*/
    1111
    12 function mylinkorder_init() {
    13 
    1412function mylinkorder_menu()
    15 {   if (function_exists('add_submenu_page'))
    16         add_submenu_page(mylinkorder_getTarget(), 'My Link Order', __('My Link Order', 'mylinkorder'), 5, "mylinkorder", 'mylinkorder');
     13{    
     14    add_links_page(__('My Link Order', 'mylinkorder'), __('My Link Order', 'mylinkorder'), 'manage_links', 'mylinkorder', 'mylinkorder');
    1715}
    1816
    1917function mylinkorder_js_libs() {
    20     if ( $_GET['page'] == "mylinkorder" ) {
     18    if ( isset($_GET['page']) && $_GET['page'] == "mylinkorder" ) {
    2119        wp_enqueue_script('jquery');
    2220        wp_enqueue_script('jquery-ui-core');
     
    2624
    2725function mylinkorder_getTarget() {
    28     return "link-manager.php";
     26    return "link-manager.php?page=mylinkorder";
    2927}
    3028
     
    3432    if ($file == $plugin) {
    3533        return array_merge( $links, array(
    36             '<a href="link-manager.php?page=mylinkorder">' . __('Order Links') . '</a>',
     34            '<a href="' . mylinkorder_getTarget() . '">' . __('Order Links') . '</a>',
    3735            '<a href="http://wordpress.org/tags/my-link-order?forum_id=10#postform">' . __('Support Forum') . '</a>',
    3836            '<a href="http://geekyweekly.com/gifts-and-donations">' . __('Donate') . '</a>'
     
    4240}
    4341
    44 add_filter( 'plugin_row_meta', 'mylinkorder_set_plugin_meta', 10, 2 );
     42add_filter('plugin_row_meta', 'mylinkorder_set_plugin_meta', 10, 2 );
    4543add_action('admin_menu', 'mylinkorder_menu');
    46 add_action('admin_menu', 'mylinkorder_js_libs');
     44add_action('admin_print_scripts', 'mylinkorder_js_libs');
    4745
    4846function mylinkorder()
    4947{
    5048    global $wpdb;
    51     $mode = "";
    52     $mode = $_GET['mode'];
    5349    $success = "";
    54     $catID = "";
    55    
     50    $catID = 0;
     51   
     52    if (isset($_POST['btnCats']))
     53        $catID = $_POST['cats'];
     54    elseif (isset($_POST['hdnCatID']))
     55        $catID = $_POST['hdnCatID'];
     56
     57    if (isset($_POST['btnReturnParent']))
     58        $catID = 0;
     59
    5660    if(isset($_GET['hideNote']))
    5761        update_option('mylinkorder_hideNote', '1');
     
    6973        $wpdb->query("ALTER TABLE $wpdb->links ADD `link_order` INT( 4 ) NULL DEFAULT '0'");
    7074   
    71     if($mode == "act_OrderCategories")
    72     {
    73         $idString = $_GET['idString'];
     75    if (isset($_POST['btnOrderCats'])) {
     76        $idString = $_POST['hdnMyLinkOrder'];
    7477        $catIDs = explode(",", $idString);
    7578        $result = count($catIDs);
    7679        for($i = 0; $i <= $result; $i++)
    77             $wpdb->query("UPDATE $wpdb->terms SET term_order = '$i' WHERE term_id ='$catIDs[$i]'");
     80        {
     81            $str = str_replace("id_", "", $catIDs[$i]);
     82            $wpdb->query("UPDATE $wpdb->terms SET term_order = '$i' WHERE term_id ='$str'");
     83        }
    7884           
    7985        $success = '<div id="message" class="updated fade"><p>'. __('Link Categories updated successfully.', 'mylinkorder').'</p></div>';
    8086    }
    8187   
    82     if($mode == "act_OrderLinks")
    83     {
    84         $idString = $_GET['idString'];
     88    if (isset($_POST['btnOrderLinks'])) {
     89        $idString = $_POST['hdnMyLinkOrder'];
    8590        $linkIDs = explode(",", $idString);
    8691        $result = count($linkIDs);
    8792        for($i = 0; $i <= $result; $i++)
    88             $wpdb->query("UPDATE $wpdb->links SET link_order = '$i' WHERE link_id ='$linkIDs[$i]'");
     93        {
     94            $str = str_replace("id_", "", $linkIDs[$i]);
     95            $wpdb->query("UPDATE $wpdb->links SET link_order = '$i' WHERE link_id ='$str'");
     96        }
    8997       
    9098        $success = '<div id="message" class="updated fade"><p>'. __('Links updated successfully.', 'mylinkorder').'</p></div>';
    91         $mode = "dsp_OrderLinks";
    92     }
    93 
    94     if($mode == "dsp_OrderLinks")
     99    }
     100?>
     101
     102<div class='wrap'>
     103    <form name="frmMyLinkOrder" method="post" action="">
     104        <h2><?php _e('My Link Order', 'mylinkorder') ?></h2>
     105        <?php
     106        echo $success;
     107       
     108        if (get_option("mylinkorder_hideNote") != "1")
     109        {   ?>
     110            <div class="updated">
     111                <strong><p><?php _e('If you like my plugin please consider donating. Every little bit helps me provide support and continue development.','mylinkorder'); ?> <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mylinkorder'); ?></a>&nbsp;&nbsp;<small><a href="<?php echo mylinkorder_getTarget(); ?>&hideNote=true"><?php _e('No thanks, hide this', 'mylinkorder'); ?></a></small></p></strong>
     112            </div>
     113        <?php
     114        }
     115       
     116    if($catID != 0)
    95117    {
    96         $catID = $_GET['catID'];
    97118        $results=$wpdb->get_results("SELECT * FROM $wpdb->links l inner join $wpdb->term_relationships tr on l.link_id = tr.object_id inner join $wpdb->term_taxonomy tt on tt.term_taxonomy_id = tr.term_taxonomy_id inner join $wpdb->terms t on t.term_id = tt.term_id WHERE t.term_id = $catID ORDER BY link_order ASC");
    98119        $cat_name = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_id=$catID");
    99120    ?>
    100 
    101     <div class='wrap'>
    102         <h2><?php _e('Order Links for', 'mylinkorder') ?> <?=$cat_name?></h2>
    103        
    104         <?php
    105         echo $success;
    106         if (get_option("mylinkorder_hideNote") != "1")
    107         {   ?>
    108             <div class="updated">
    109                 <strong><p><?php _e('If you like my plugin please consider donating. Every little bit helps me provide support and continue development.','mylinkorder'); ?> <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mylinkorder'); ?></a>&nbsp;&nbsp;<small><a href="link-manager.php?page=mylinkorder&hideNote=true"><?php _e('No thanks, hide this', 'mylinkorder'); ?></a></small></p></strong>
    110             </div>
    111         <?php
    112         }
    113        
    114         ?>
    115        
     121        <h3><?php _e('Order Links for', 'mylinkorder') ?> <?php _e($cat_name) ?></h3>
     122
    116123        <p><?php _e('Order the links by dragging and dropping them into the desired order.', 'mylinkorder') ?></p>
    117         <ul id="order" style="width: 90%; margin:10px 10px 10px 0px; padding:10px; border:1px solid #B2B2B2; list-style:none;"><?php
     124        <ul id="myLinkOrderList"><?php
    118125        foreach($results as $row)
    119126        {
    120             echo "<li id='$row->link_id' class='lineitem'>$row->link_name</li>";
     127            echo "<li id='id_$row->link_id' class='lineitem'>".__($row->link_name)."</li>";
    121128        }?>
    122129        </ul>
    123130   
    124         <input type="button" id="orderButton" Value="<?php _e('Click to Order Links', 'mylinkorder') ?>" onclick="javascript:orderLinks();">&nbsp;&nbsp;<strong id="updateText"></strong>
    125         <br /><br />
    126         <a href='<?php echo mylinkorder_getTarget(); ?>?page=mylinkorder'><?php _e('Go Back', 'mylinkorder') ?></a>
    127    
    128     </div>
    129 
     131        <input type="submit" id="btnOrderLinks" name="btnOrderLinks" class="button-primary" value="<?php _e('Click to Order Links', 'mylinkorder') ?>" onclick="javascript:orderLinks(); return true;" />
     132        &nbsp;&nbsp;<input type="submit" class="button" id="btnReturnParent" name="btnReturnParent" value="<?php _e('Go Back', 'mylinkorder') ?>" />
    130133    <?php
    131134    }
     
    134137        $results=$wpdb->get_results("SELECT DISTINCT t.term_id, name FROM $wpdb->term_taxonomy tt inner join $wpdb->term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id inner join $wpdb->terms t on t.term_id = tt.term_id where taxonomy = 'link_category' ORDER BY t.term_order ASC");
    135138        ?>
    136     <div class='wrap'>
    137         <h2><?php _e('My Link Order', 'mylinkorder') ?></h2>
    138        
    139         <?php
    140         echo $success;
    141         if (get_option("mylinkorder_hideNote") != "1")
    142         {   ?>
    143             <div class="updated">
    144                 <strong><p><?php _e('If you like my plugin please consider donating. Every little bit helps me provide support and continue development.','mylinkorder'); ?> <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mylinkorder'); ?></a>&nbsp;&nbsp;<small><a href="link-manager.php?page=mylinkorder&hideNote=true"><?php _e('No thanks, hide this', 'mylinkorder'); ?></a></small></p></strong>
    145             </div>
    146         <?php
    147         }
    148        
    149         ?>
    150139       
    151140        <p><?php _e('Choose a category from the drop down to order the links in that category or order the categories by dragging and dropping them.', 'mylinkorder') ?></p>
     
    153142        <h3><?php _e('Order Links', 'mylinkorder') ?></h3>
    154143   
    155         <select id="cats" name='cats'><?php
     144        <select id="cats" name="cats"><?php
    156145        foreach($results as $row)
    157146        {
    158             echo "<option value='$row->term_id'>$row->name</option>";
     147            echo "<option value='$row->term_id'>".__($row->name)."</option>";
    159148        }?>
    160149        </select>
    161         &nbsp;<input type="button" name="edit" Value="<?php _e('Order Links in this Category', 'mylinkorder') ?>" onClick="javascript:goEdit();">
     150        &nbsp;<input type="submit" name="btnCats" id="btnCats" class="button" value="<?php _e('Order Links in this Category', 'mylinkorder') ?>" />
    162151   
    163152        <h3><?php _e('Order Link Categories', 'mylinkorder') ?></h3>
    164153   
    165         <ul id="order" style="width: 90%; margin:10px 10px 10px 0px; padding:10px; border:1px solid #B2B2B2; list-style:none;"><?php
     154        <ul id="myLinkOrderList"><?php
    166155        foreach($results as $row)
    167156        {
    168             echo "<li id='$row->term_id' class='lineitem'>$row->name</li>";
     157            echo "<li id='id_$row->term_id' class='lineitem'>".__($row->name)."</li>";
    169158        }?>
    170159        </ul>
    171         <input type="button" id="orderButton" Value="<?php _e('Click to Order Categories', 'mylinkorder') ?>" onclick="javascript:orderLinkCats();">&nbsp;&nbsp;<strong id="updateText"></strong>
    172        
    173         <p>
    174             <a href="http://geekyweekly.com/mylinkorder"><?php _e('Plugin Homepage', 'mylinkorder') ?></a>
    175             &nbsp;|&nbsp;
    176             <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mylinkorder') ?></a>
    177             &nbsp;|&nbsp;
    178             <a href="http://wordpress.org/tags/my-link-order?forum_id=10"><?php _e('Support Forum', 'mylinkorder') ?></a>
    179         </p>
     160        <input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="<?php _e('Click to Order Categories', 'mylinkorder') ?>" onclick="javascript:orderLinkCats(); return true;" />
     161       
     162    <?php
     163    }
     164    ?>
     165    &nbsp;&nbsp;<strong id="updateText"></strong>
     166    <br /><br />
     167        <p>
     168            <a href="http://geekyweekly.com/mylinkorder"><?php _e('Plugin Homepage', 'mylinkorder') ?></a>&nbsp;|&nbsp;<a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mylinkorder') ?></a>&nbsp;|&nbsp;<a href="http://wordpress.org/tags/my-link-order?forum_id=10"><?php _e('Support Forum', 'mylinkorder') ?></a>
     169        </p>
     170        <input type="hidden" id="hdnMyLinkOrder" name="hdnMyLinkOrder" />
     171        <input type="hidden" id="hdnCatID" name="hdnCatID" value="<?php echo $catID; ?>" />
     172        </form>
    180173    </div>
    181     <?php
    182     }
    183     ?>
    184     <style>
     174   
     175    <style type="text/css">
     176        #myLinkOrderList {
     177            width: 90%;
     178            border:1px solid #B2B2B2;
     179            margin:10px 10px 10px 0px;
     180            padding:5px 10px 5px 10px;
     181            list-style:none;
     182            background-color:#fff;
     183            -moz-border-radius:3px;
     184            -webkit-border-radius:3px;
     185        }
     186
    185187        li.lineitem {
    186             margin: 3px 0px;
     188            border:1px solid #B2B2B2;
     189            -moz-border-radius:3px;
     190            -webkit-border-radius:3px;
     191            background-color:#F1F1F1;
     192            color:#000;
     193            cursor:move;
     194            font-size:13px;
     195            margin-top:5px;
     196            margin-bottom:5px;
    187197            padding: 2px 5px 2px 5px;
    188             background-color: #F1F1F1;
    189             border:1px solid #B2B2B2;
    190             cursor: move;
     198            height:1.5em;
     199            line-height:1.5em;
     200        }
     201       
     202        .sortable-placeholder{
     203            border:1px dashed #B2B2B2;
     204            margin-top:5px;
     205            margin-bottom:5px;
     206            padding: 2px 5px 2px 5px;
     207            height:1.5em;
     208            line-height:1.5em; 
    191209        }
    192210    </style>
     
    195213   
    196214        function mylinkorderaddloadevent(){
    197             jQuery("#order").sortable({
    198                 placeholder: "ui-selected",
     215            jQuery("#myLinkOrderList").sortable({
     216                placeholder: "sortable-placeholder",
    199217                revert: false,
    200218                tolerance: "pointer"
     
    205223   
    206224        function orderLinkCats() {
    207             jQuery("#orderButton").css("display", "none");
    208225            jQuery("#updateText").html("<?php _e('Updating Link Category Order...', 'mylinkorder') ?>");
    209            
    210             idList = jQuery("#order").sortable("toArray");
    211             location.href = '<?php echo mylinkorder_getTarget(); ?>?page=mylinkorder&mode=act_OrderCategories&idString='+idList;
     226            jQuery("#hdnMyLinkOrder").val(jQuery("#myLinkOrderList").sortable("toArray"));
    212227        }
    213228   
    214229        function orderLinks() {
    215             jQuery("#orderButton").css("display", "none");
    216230            jQuery("#updateText").html("<?php _e('Updating Link Order...', 'mylinkorder') ?>");
    217            
    218             idList = jQuery("#order").sortable("toArray");
    219             location.href = '<?php echo mylinkorder_getTarget(); ?>?page=mylinkorder&mode=act_OrderLinks&catID=<?php echo $catID; ?>&idString='+idList;
    220         }
    221    
    222         function goEdit ()
    223         {
    224             if(jQuery("#cats").val() != "")
    225                 location.href="<?php echo mylinkorder_getTarget(); ?>?page=mylinkorder&mode=dsp_OrderLinks&catID="+jQuery("#cats").val();
    226         }
     231            jQuery("#hdnMyLinkOrder").val(jQuery("#myLinkOrderList").sortable("toArray"));
     232        }
     233       
    227234    </script>
    228235
    229236    <?php
    230 }
    231237}
    232238
     
    240246
    241247add_filter('get_terms_orderby', 'mylinkorder_applyorderfilter', 10, 2);
    242 
    243 add_action('plugins_loaded', 'mylinkorder_init');
    244 
    245 /* Load Translations */
    246248add_action('init', 'mylinkorder_loadtranslation');
    247249
     
    282284
    283285        $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
    284         wp_list_bookmarks(apply_filters('widget_links_args', array('title_before' => $before_title, 'title_after' => $after_title, 'class' => 'linkcat widget',
     286        mylinkorder_list_bookmarks(apply_filters('widget_links_args', array('title_before' => $before_title, 'title_after' => $after_title, 'class' => 'linkcat widget',
    285287            'category_before' => $before_widget, 'category_after' => $after_widget, 'exclude' => $exclude, 'include' => $include,
    286288            'title_li' => $title_li, 'category_orderby' => $category_orderby, 'category_order' => $category_order, 'orderby' => $orderby, 'order' => $order,
     
    480482add_action('widgets_init', 'mylinkorder_widgets_init');
    481483
     484function mylinkorder_list_bookmarks($args = '') {
     485    $defaults = array(
     486        'orderby' => 'name', 'order' => 'ASC',
     487        'limit' => -1, 'category' => '', 'exclude_category' => '',
     488        'category_name' => '', 'hide_invisible' => 1,
     489        'show_updated' => 0, 'echo' => 1,
     490        'categorize' => 1, 'title_li' => __('Bookmarks'),
     491        'title_before' => '<h2>', 'title_after' => '</h2>',
     492        'category_orderby' => 'name', 'category_order' => 'ASC',
     493        'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
     494        'category_after' => '</li>'
     495    );
     496
     497    $r = wp_parse_args( $args, $defaults );
     498    extract( $r, EXTR_SKIP );
     499
     500    $output = '';
     501
     502    if ( $categorize ) {
     503        //Split the bookmarks into ul's for each category
     504        $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
     505
     506        foreach ( (array) $cats as $cat ) {
     507            $params = array_merge($r, array('category'=>$cat->term_id));
     508            $bookmarks = mylinkorder_get_bookmarks($params);
     509            if ( empty($bookmarks) )
     510                continue;
     511            $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
     512            $catname = apply_filters( "link_category", $cat->name );
     513            $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
     514            $output .= _walk_bookmarks($bookmarks, $r);
     515            $output .= "\n\t</ul>\n$category_after\n";
     516        }
     517    } else {
     518        //output one single list using title_li for the title
     519        $bookmarks = mylinkorder_get_bookmarks($r);
     520
     521        if ( !empty($bookmarks) ) {
     522            if ( !empty( $title_li ) ){
     523                $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
     524                $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
     525                $output .= _walk_bookmarks($bookmarks, $r);
     526                $output .= "\n\t</ul>\n$category_after\n";
     527            } else {
     528                $output .= _walk_bookmarks($bookmarks, $r);
     529            }
     530        }
     531    }
     532
     533    $output = apply_filters( 'wp_list_bookmarks', $output );
     534
     535    if ( !$echo )
     536        return $output;
     537    echo $output;
     538}
     539
     540function mylinkorder_get_bookmarks($args = '') {
     541    global $wpdb;
     542
     543    $defaults = array(
     544        'orderby' => 'name', 'order' => 'ASC',
     545        'limit' => -1, 'category' => '',
     546        'category_name' => '', 'hide_invisible' => 1,
     547        'show_updated' => 0, 'include' => '',
     548        'exclude' => '', 'search' => ''
     549    );
     550
     551    $r = wp_parse_args( $args, $defaults );
     552    extract( $r, EXTR_SKIP );
     553
     554    $cache = array();
     555    $key = md5( serialize( $r ) );
     556    if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) {
     557        if ( is_array($cache) && isset( $cache[ $key ] ) )
     558            return apply_filters('get_bookmarks', $cache[ $key ], $r );
     559    }
     560
     561    if ( !is_array($cache) )
     562        $cache = array();
     563
     564    $inclusions = '';
     565    if ( !empty($include) ) {
     566        $exclude = '';  //ignore exclude, category, and category_name params if using include
     567        $category = '';
     568        $category_name = '';
     569        $inclinks = preg_split('/[\s,]+/',$include);
     570        if ( count($inclinks) ) {
     571            foreach ( $inclinks as $inclink ) {
     572                if (empty($inclusions))
     573                    $inclusions = ' AND ( link_id = ' . intval($inclink) . ' ';
     574                else
     575                    $inclusions .= ' OR link_id = ' . intval($inclink) . ' ';
     576            }
     577        }
     578    }
     579    if (!empty($inclusions))
     580        $inclusions .= ')';
     581
     582    $exclusions = '';
     583    if ( !empty($exclude) ) {
     584        $exlinks = preg_split('/[\s,]+/',$exclude);
     585        if ( count($exlinks) ) {
     586            foreach ( $exlinks as $exlink ) {
     587                if (empty($exclusions))
     588                    $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' ';
     589                else
     590                    $exclusions .= ' AND link_id <> ' . intval($exlink) . ' ';
     591            }
     592        }
     593    }
     594    if (!empty($exclusions))
     595        $exclusions .= ')';
     596
     597    if ( !empty($category_name) ) {
     598        if ( $category = get_term_by('name', $category_name, 'link_category') ) {
     599            $category = $category->term_id;
     600        } else {
     601            $cache[ $key ] = array();
     602            wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     603            return apply_filters( 'get_bookmarks', array(), $r );
     604        }
     605    }
     606
     607    if ( ! empty($search) ) {
     608        $search = like_escape($search);
     609        $search = " AND ( (link_url LIKE '%$search%') OR (link_name LIKE '%$search%') OR (link_description LIKE '%$search%') ) ";
     610    }
     611
     612    $category_query = '';
     613    $join = '';
     614    if ( !empty($category) ) {
     615        $incategories = preg_split('/[\s,]+/',$category);
     616        if ( count($incategories) ) {
     617            foreach ( $incategories as $incat ) {
     618                if (empty($category_query))
     619                    $category_query = ' AND ( tt.term_id = ' . intval($incat) . ' ';
     620                else
     621                    $category_query .= ' OR tt.term_id = ' . intval($incat) . ' ';
     622            }
     623        }
     624    }
     625    if (!empty($category_query)) {
     626        $category_query .= ") AND taxonomy = 'link_category'";
     627        $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id";
     628    }
     629
     630    if ( $show_updated && get_option('links_recently_updated_time') ) {
     631        $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL " . get_option('links_recently_updated_time') . " MINUTE) >= NOW(), 1,0) as recently_updated ";
     632    } else {
     633        $recently_updated_test = '';
     634    }
     635
     636    $get_updated = ( $show_updated ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : '';
     637
     638    $orderby = strtolower($orderby);
     639    $length = '';
     640    switch ( $orderby ) {
     641        case 'length':
     642            $length = ", CHAR_LENGTH(link_name) AS length";
     643            break;
     644        case 'rand':
     645            $orderby = 'rand()';
     646            break;
     647        case 'link_id':
     648            $orderby = "$wpdb->links.link_id";
     649            break;
     650        default:
     651            $orderparams = array();
     652            foreach ( explode(',', $orderby) as $ordparam ) {
     653                $ordparam = trim($ordparam);
     654                if ( in_array( $ordparam, array( 'order', 'name', 'url', 'visible', 'rating', 'owner', 'updated' ) ) )
     655                    $orderparams[] = 'link_' . $ordparam;
     656            }
     657            $orderby = implode(',', $orderparams);
     658    }
     659
     660    if ( empty( $orderby ) )
     661        $orderby = 'link_name';
     662
     663    $order = strtoupper( $order );
     664    if ( '' !== $order && !in_array( $order, array( 'ASC', 'DESC' ) ) )
     665        $order = 'ASC';
     666
     667    $visible = '';
     668    if ( $hide_invisible )
     669        $visible = "AND link_visible = 'Y'";
     670
     671    $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query";
     672    $query .= " $exclusions $inclusions $search";
     673    $query .= " ORDER BY $orderby $order";
     674    if ($limit != -1)
     675        $query .= " LIMIT $limit";
     676
     677    $results = $wpdb->get_results($query);
     678
     679    $cache[ $key ] = $results;
     680    wp_cache_set( 'get_bookmarks', $cache, 'bookmark' );
     681
     682    return apply_filters('get_bookmarks', $results, $r);
     683}
     684
    482685?>
Note: See TracChangeset for help on using the changeset viewer.