| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function _walk_bookmarks($bookmarks, $args = '' ) { |
|---|
| 4 |
$defaults = array( |
|---|
| 5 |
'show_updated' => 0, 'show_description' => 0, |
|---|
| 6 |
'show_images' => 1, 'before' => '<li>', |
|---|
| 7 |
'after' => '</li>', 'between' => "\n" |
|---|
| 8 |
); |
|---|
| 9 |
|
|---|
| 10 |
$r = wp_parse_args( $args, $defaults ); |
|---|
| 11 |
extract( $r, EXTR_SKIP ); |
|---|
| 12 |
|
|---|
| 13 |
foreach ( (array) $bookmarks as $bookmark ) { |
|---|
| 14 |
if ( !isset($bookmark->recently_updated) ) |
|---|
| 15 |
$bookmark->recently_updated = false; |
|---|
| 16 |
$output .= $before; |
|---|
| 17 |
if ( $show_updated && $bookmark->recently_updated ) |
|---|
| 18 |
$output .= get_option('links_recently_updated_prepend'); |
|---|
| 19 |
|
|---|
| 20 |
$the_link = '#'; |
|---|
| 21 |
if ( !empty($bookmark->link_url) ) |
|---|
| 22 |
$the_link = clean_url($bookmark->link_url); |
|---|
| 23 |
|
|---|
| 24 |
$rel = $bookmark->link_rel; |
|---|
| 25 |
if ( '' != $rel ) |
|---|
| 26 |
$rel = ' rel="' . $rel . '"'; |
|---|
| 27 |
|
|---|
| 28 |
$desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display')); |
|---|
| 29 |
$name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display')); |
|---|
| 30 |
$title = $desc; |
|---|
| 31 |
|
|---|
| 32 |
if ( $show_updated ) |
|---|
| 33 |
if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) { |
|---|
| 34 |
$title .= ' '; |
|---|
| 35 |
$title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600))); |
|---|
| 36 |
$title .= ')'; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
if ( '' != $title ) |
|---|
| 40 |
$title = ' title="' . $title . '"'; |
|---|
| 41 |
|
|---|
| 42 |
$alt = ' alt="' . $name . '"'; |
|---|
| 43 |
|
|---|
| 44 |
$target = $bookmark->link_target; |
|---|
| 45 |
if ( '' != $target ) |
|---|
| 46 |
$target = ' target="' . $target . '"'; |
|---|
| 47 |
|
|---|
| 48 |
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>'; |
|---|
| 49 |
|
|---|
| 50 |
if ( $bookmark->link_image != null && $show_images ) { |
|---|
| 51 |
if ( strpos($bookmark->link_image, 'http') !== false ) |
|---|
| 52 |
$output .= "<img src=\"$bookmark->link_image\" $alt $title />"; |
|---|
| 53 |
else |
|---|
| 54 |
$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; |
|---|
| 55 |
} else { |
|---|
| 56 |
$output .= $name; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$output .= '</a>'; |
|---|
| 60 |
|
|---|
| 61 |
if ( $show_updated && $bookmark->recently_updated ) |
|---|
| 62 |
$output .= get_option('links_recently_updated_append'); |
|---|
| 63 |
|
|---|
| 64 |
if ( $show_description && '' != $desc ) |
|---|
| 65 |
$output .= $between . $desc; |
|---|
| 66 |
|
|---|
| 67 |
if ($show_rating) { |
|---|
| 68 |
$output .= $between . get_linkrating($bookmark); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
$output .= "$after\n"; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
return $output; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
function wp_list_bookmarks($args = '') { |
|---|
| 78 |
$defaults = array( |
|---|
| 79 |
'orderby' => 'name', 'order' => 'ASC', |
|---|
| 80 |
'limit' => -1, 'category' => '', |
|---|
| 81 |
'category_name' => '', 'hide_invisible' => 1, |
|---|
| 82 |
'show_updated' => 0, 'echo' => 1, |
|---|
| 83 |
'categorize' => 1, 'title_li' => __('Bookmarks'), |
|---|
| 84 |
'title_before' => '<h2>', 'title_after' => '</h2>', |
|---|
| 85 |
'category_orderby' => 'name', 'category_order' => 'ASC', |
|---|
| 86 |
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', |
|---|
| 87 |
'category_after' => '</li>' |
|---|
| 88 |
); |
|---|
| 89 |
|
|---|
| 90 |
$r = wp_parse_args( $args, $defaults ); |
|---|
| 91 |
extract( $r, EXTR_SKIP ); |
|---|
| 92 |
|
|---|
| 93 |
$output = ''; |
|---|
| 94 |
|
|---|
| 95 |
if ( $categorize ) { |
|---|
| 96 |
|
|---|
| 97 |
$cats = get_terms('link_category', "category_name=$category_name&include=$category&orderby=$category_orderby&order=$category_order&hierarchical=0"); |
|---|
| 98 |
|
|---|
| 99 |
foreach ( (array) $cats as $cat ) { |
|---|
| 100 |
$params = array_merge($r, array('category'=>$cat->term_id)); |
|---|
| 101 |
$bookmarks = get_bookmarks($params); |
|---|
| 102 |
if ( empty($bookmarks) ) |
|---|
| 103 |
continue; |
|---|
| 104 |
$output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); |
|---|
| 105 |
$catname = apply_filters( "link_category", $cat->name ); |
|---|
| 106 |
$output .= "$title_before$catname$title_after\n\t<ul>\n"; |
|---|
| 107 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 108 |
$output .= "\n\t</ul>\n$category_after\n"; |
|---|
| 109 |
} |
|---|
| 110 |
} else { |
|---|
| 111 |
|
|---|
| 112 |
$bookmarks = get_bookmarks($r); |
|---|
| 113 |
|
|---|
| 114 |
if ( !empty($bookmarks) ) { |
|---|
| 115 |
if ( !empty( $title_li ) ){ |
|---|
| 116 |
$output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); |
|---|
| 117 |
$output .= "$title_before$title_li$title_after\n\t<ul>\n"; |
|---|
| 118 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 119 |
$output .= "\n\t</ul>\n$category_after\n"; |
|---|
| 120 |
} else { |
|---|
| 121 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
if ( !$echo ) |
|---|
| 127 |
return $output; |
|---|
| 128 |
echo $output; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
?> |
|---|
| 132 |
|
|---|