Make WordPress Core


Ignore:
Timestamp:
08/22/2006 09:24:31 AM (19 years ago)
Author:
ryan
Message:

Code purtification from Mark J. fixes #3060

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/bookmark-template.php

    r3899 r4108  
    2121    parse_str($args);
    2222
    23     if (! isset($category)) $category = -1;
    24     if (! isset($before)) $before = '';
    25     if (! isset($after)) $after = '<br />';
    26     if (! isset($between))  $between = ' ';
    27     if (! isset($show_images)) $show_images = true;
    28     if (! isset($orderby)) $orderby = 'name';
    29     if (! isset($show_description)) $show_description = true;
    30     if (! isset($show_rating)) $show_rating = false;
    31     if (! isset($limit)) $limit = -1;
    32     if (! isset($show_updated)) $show_updated = 1;
    33     if (! isset($echo)) $echo = true;
     23    if ( !isset($category) )         $category = -1;
     24    if ( !isset($before) )          $before = '';
     25    if ( !isset($after) )            $after = '<br />';
     26    if ( !isset($between) )          $between = ' ';
     27    if ( !isset($show_images) )      $show_images = true;
     28    if ( !isset($orderby) )          $orderby = 'name';
     29    if ( !isset($show_description) ) $show_description = true;
     30    if ( !isset($show_rating) )      $show_rating = false;
     31    if ( !isset($limit) )            $limit = -1;
     32    if ( !isset($show_updated) )    $show_updated = 1;
     33    if ( !isset($echo) )            $echo = true;
    3434
    3535    return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
     
    7474
    7575    $order = 'ASC';
    76     if (substr($orderby, 0, 1) == '_') {
     76    if ( substr($orderby, 0, 1) == '_' ) {
    7777        $order = 'DESC';
    7878        $orderby = substr($orderby, 1);
    7979    }
    80    
    81     if ($category == -1) { //get_bookmarks uses '' to signify all categories
     80
     81    if ( $category == -1 ) //get_bookmarks uses '' to signify all categories
    8282        $category = '';
    83     }
    8483
    8584    $results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=$show_updated&limit=$limit");
    8685
    87     if (!$results) {
     86    if ( !$results )
    8887        return;
    89     }
    90 
    9188
    9289    $output = '';
    9390
    94     foreach ($results as $row) {
    95         if (!isset($row->recently_updated)) $row->recently_updated = false;
    96             $output .= $before;
    97         if ($show_updated && $row->recently_updated) {
     91    foreach ( (array) $results as $row ) {
     92        if ( !isset($row->recently_updated) )
     93            $row->recently_updated = false;
     94        $output .= $before;
     95        if ( $show_updated && $row->recently_updated )
    9896            $output .= get_settings('links_recently_updated_prepend');
    99         }
    100 
    10197        $the_link = '#';
    102         if (!empty($row->link_url))
     98        if ( !empty($row->link_url) )
    10399            $the_link = wp_specialchars($row->link_url);
    104 
    105100        $rel = $row->link_rel;
    106         if ($rel != '') {
     101        if ( '' != $rel )
    107102            $rel = ' rel="' . $rel . '"';
    108         }
    109103
    110104        $desc = wp_specialchars($row->link_description, ENT_QUOTES);
     
    112106        $title = $desc;
    113107
    114         if ($show_updated) {
    115             if (substr($row->link_updated_f, 0, 2) != '00') {
     108        if ( $show_updated )
     109            if (substr($row->link_updated_f, 0, 2) != '00')
    116110                $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) . ')';
    117             }
    118         }
    119 
    120         if ('' != $title) {
     111
     112        if ( '' != $title )
    121113            $title = ' title="' . $title . '"';
    122         }
    123114
    124115        $alt = ' alt="' . $name . '"';
    125116
    126117        $target = $row->link_target;
    127         if ('' != $target) {
     118        if ( '' != $target )
    128119            $target = ' target="' . $target . '"';
    129         }
    130120
    131121        $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
    132122
    133         if (($row->link_image != null) && $show_images) {
    134             if (strstr($row->link_image, 'http'))
     123        if ( $row->link_image != null && $show_images ) {
     124            if ( strpos($row->link_image, 'http') !== false )
    135125                $output .= "<img src=\"$row->link_image\" $alt $title />";
    136126            else // If it's a relative path
     
    142132        $output .= '</a>';
    143133
    144         if ($show_updated && $row->recently_updated) {
     134        if ( $show_updated && $row->recently_updated )
    145135            $output .= get_settings('links_recently_updated_append');
    146         }
    147 
    148         if ($show_description && ($desc != '')) {
     136
     137        if ( $show_description && '' != $desc )
    149138            $output .= $between . $desc;
    150         }
     139
    151140        $output .= "$after\n";
    152141    } // end while
    153142
    154     if ($echo) {
    155         echo $output;
    156     } else {
     143    if ( !$echo )
    157144        return $output;
    158     }
     145    echo $output;
    159146}
    160147
     
    171158    $id = (int) $id;
    172159
    173     if ( empty($id) )
    174         return '';
    175  
     160    if ( empty($id) )
     161        return '';
     162
    176163    $cats = wp_get_link_cats($id);
    177164
     
    195182 **   count (default true) - the number of links in the db
    196183 */
    197 function links_popup_script($text = 'Links', $width=400, $height=400,
    198                             $file='links.all.php', $count = true) {
    199    if ($count == true) {
    200       $counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");
    201    }
    202 
    203    $javascript = "<a href=\"#\" " .
    204                  " onclick=\"javascript:window.open('$file?popup=1', '_blank', " .
    205                  "'width=$width,height=$height,scrollbars=yes,status=no'); " .
    206                  " return false\">";
    207    $javascript .= $text;
    208 
    209    if ($count == true) {
    210       $javascript .= " ($counts)";
    211    }
    212 
    213    $javascript .="</a>\n\n";
    214    echo $javascript;
     184function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) {
     185    if ( $count )
     186        $counts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links");
     187
     188    $javascript = "<a href=\"#\" onclick=\"javascript:window.open('$file?popup=1', '_blank', 'width=$width,height=$height,scrollbars=yes,status=no'); return false\">";
     189    $javascript .= $text;
     190
     191    if ( $count )
     192        $javascript .= " ($counts)";
     193
     194    $javascript .= "</a>\n\n";
     195        echo $javascript;
    215196}
    216197
     
    234215    // Handle link category sorting
    235216    $direction = 'ASC';
    236     if (substr($order,0,1) == '_') {
     217    if ( '_' == substr($order,0,1) ) {
    237218        $direction = 'DESC';
    238219        $order = substr($order,1);
    239220    }
    240221
    241     if (!isset($direction)) $direction = '';
     222    if ( !isset($direction) )
     223        $direction = '';
    242224
    243225    $cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0");
    244226
    245227    // Display each category
    246     if ($cats) {
    247         foreach ($cats as $cat) {
     228    if ( $cats ) {
     229        foreach ( (array) $cats as $cat ) {
    248230            // Handle each category.
    249231
     
    251233            echo '  <li id="linkcat-' . $cat->cat_ID . '"><h2>' . $cat->cat_name . "</h2>\n\t<ul>\n";
    252234            // Call get_links() with all the appropriate params
    253             get_links($cat->cat_ID,
    254                 '<li>',"</li>","\n", true, 'name', false);
     235            get_links($cat->cat_ID, '<li>', "</li>", "\n", true, 'name', false);
    255236
    256237            // Close the last category
     
    272253
    273254    foreach ( (array) $bookmarks as $bookmark ) {
    274         if (!isset($bookmark->recently_updated)) $bookmark->recently_updated = false;
    275             $output .= $before;
    276         if ($show_updated && $bookmark->recently_updated) {
     255        if ( !isset($bookmark->recently_updated) )
     256            $bookmark->recently_updated = false;
     257        $output .= $before;
     258        if ( $show_updated && $bookmark->recently_updated )
    277259            $output .= get_settings('links_recently_updated_prepend');
    278         }
    279260
    280261        $the_link = '#';
    281         if (!empty($bookmark->link_url))
     262        if ( !empty($bookmark->link_url) )
    282263            $the_link = wp_specialchars($bookmark->link_url);
    283264
    284265        $rel = $bookmark->link_rel;
    285         if ($rel != '') {
     266        if ( '' != $rel )
    286267            $rel = ' rel="' . $rel . '"';
    287         }
    288268
    289269        $desc = wp_specialchars($bookmark->link_description, ENT_QUOTES);
     
    291271        $title = $desc;
    292272
    293         if ($show_updated) {
    294             if (substr($bookmark->link_updated_f, 0, 2) != '00') {
     273        if ( $show_updated )
     274            if ( '00' != substr($bookmark->link_updated_f, 0, 2) )
    295275                $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $bookmark->link_updated_f + (get_settings('gmt_offset') * 3600)) . ')';
    296             }
    297         }
    298 
    299         if ('' != $title) {
     276
     277        if ( '' != $title )
    300278            $title = ' title="' . $title . '"';
    301         }
    302279
    303280        $alt = ' alt="' . $name . '"';
    304281
    305282        $target = $bookmark->link_target;
    306         if ('' != $target) {
     283        if ( '' != $target )
    307284            $target = ' target="' . $target . '"';
    308         }
    309285
    310286        $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
    311287
    312         if (($bookmark->link_image != null) && $show_images) {
    313             if (strstr($bookmark->link_image, 'http'))
     288        if ( $bookmark->link_image != null && $show_images ) {
     289            if ( strpos($bookmark->link_image, 'http') !== false )
    314290                $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
    315291            else // If it's a relative path
     
    321297        $output .= '</a>';
    322298
    323         if ($show_updated && $bookmark->recently_updated) {
     299        if ( $show_updated && $bookmark->recently_updated )
    324300            $output .= get_settings('links_recently_updated_append');
    325         }
    326 
    327         if ($show_description && ($desc != '')) {
     301
     302        if ( $show_description && '' != $desc )
    328303            $output .= $between . $desc;
    329         }
    330304        $output .= "$after\n";
    331305    } // end while
     
    346320    $r = array_merge($defaults, $r);
    347321    extract($r);
    348    
     322
    349323    // TODO: The rest of it.
    350324    // If $categorize, group links by category with the category name being the
    351     // title of each li, otherwise just list them with title_li as the li title. 
     325    // title of each li, otherwise just list them with title_li as the li title.
    352326    // If $categorize and $category or $category_name, list links for the given category
    353327    // with the category name as the title li.  If not $categorize, use title_li.
     
    370344    }
    371345
    372     if ($echo)
    373         echo $output;
    374 
    375     return $output;
     346    if ( !$echo )
     347        return $output;
     348    echo $output;
    376349}
    377350
Note: See TracChangeset for help on using the changeset viewer.