| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
function _walk_bookmarks($bookmarks, $args = '' ) { |
|---|
| 52 |
$defaults = array( |
|---|
| 53 |
'show_updated' => 0, 'show_description' => 0, |
|---|
| 54 |
'show_images' => 1, 'show_name' => 0, |
|---|
| 55 |
'before' => '<li>', 'after' => '</li>', 'between' => "\n", |
|---|
| 56 |
'show_rating' => 0, 'link_before' => '', 'link_after' => '' |
|---|
| 57 |
); |
|---|
| 58 |
|
|---|
| 59 |
$r = wp_parse_args( $args, $defaults ); |
|---|
| 60 |
extract( $r, EXTR_SKIP ); |
|---|
| 61 |
|
|---|
| 62 |
$output = ''; |
|---|
| 63 |
|
|---|
| 64 |
foreach ( (array) $bookmarks as $bookmark ) { |
|---|
| 65 |
if ( !isset($bookmark->recently_updated) ) |
|---|
| 66 |
$bookmark->recently_updated = false; |
|---|
| 67 |
$output .= $before; |
|---|
| 68 |
if ( $show_updated && $bookmark->recently_updated ) |
|---|
| 69 |
$output .= get_option('links_recently_updated_prepend'); |
|---|
| 70 |
|
|---|
| 71 |
$the_link = '#'; |
|---|
| 72 |
if ( !empty($bookmark->link_url) ) |
|---|
| 73 |
$the_link = clean_url($bookmark->link_url); |
|---|
| 74 |
|
|---|
| 75 |
$rel = $bookmark->link_rel; |
|---|
| 76 |
if ( '' != $rel ) |
|---|
| 77 |
$rel = ' rel="' . $rel . '"'; |
|---|
| 78 |
|
|---|
| 79 |
$desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display')); |
|---|
| 80 |
$name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display')); |
|---|
| 81 |
$title = $desc; |
|---|
| 82 |
|
|---|
| 83 |
if ( $show_updated ) |
|---|
| 84 |
if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) { |
|---|
| 85 |
$title .= ' ('; |
|---|
| 86 |
$title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600))); |
|---|
| 87 |
$title .= ')'; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
if ( '' != $title ) |
|---|
| 91 |
$title = ' title="' . $title . '"'; |
|---|
| 92 |
|
|---|
| 93 |
$alt = ' alt="' . $name . '"'; |
|---|
| 94 |
|
|---|
| 95 |
$target = $bookmark->link_target; |
|---|
| 96 |
if ( '' != $target ) |
|---|
| 97 |
$target = ' target="' . $target . '"'; |
|---|
| 98 |
|
|---|
| 99 |
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>'; |
|---|
| 100 |
|
|---|
| 101 |
$output .= $link_before; |
|---|
| 102 |
|
|---|
| 103 |
if ( $bookmark->link_image != null && $show_images ) { |
|---|
| 104 |
if ( strpos($bookmark->link_image, 'http') !== false ) |
|---|
| 105 |
$output .= "<img src=\"$bookmark->link_image\" $alt $title />"; |
|---|
| 106 |
else |
|---|
| 107 |
$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; |
|---|
| 108 |
|
|---|
| 109 |
if ($show_name) $output .= $name; |
|---|
| 110 |
} else { |
|---|
| 111 |
$output .= $name; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
$output .= $link_after; |
|---|
| 115 |
|
|---|
| 116 |
$output .= '</a>'; |
|---|
| 117 |
|
|---|
| 118 |
if ( $show_updated && $bookmark->recently_updated ) |
|---|
| 119 |
$output .= get_option('links_recently_updated_append'); |
|---|
| 120 |
|
|---|
| 121 |
if ( $show_description && '' != $desc ) |
|---|
| 122 |
$output .= $between . $desc; |
|---|
| 123 |
|
|---|
| 124 |
if ($show_rating) { |
|---|
| 125 |
$output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display'); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
$output .= "$after\n"; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
return $output; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
function wp_list_bookmarks($args = '') { |
|---|
| 199 |
$defaults = array( |
|---|
| 200 |
'orderby' => 'name', 'order' => 'ASC', |
|---|
| 201 |
'limit' => -1, 'category' => '', 'exclude_category' => '', |
|---|
| 202 |
'category_name' => '', 'hide_invisible' => 1, |
|---|
| 203 |
'show_updated' => 0, 'echo' => 1, |
|---|
| 204 |
'categorize' => 1, 'title_li' => __('Bookmarks'), |
|---|
| 205 |
'title_before' => '<h2>', 'title_after' => '</h2>', |
|---|
| 206 |
'category_orderby' => 'name', 'category_order' => 'ASC', |
|---|
| 207 |
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', |
|---|
| 208 |
'category_after' => '</li>' |
|---|
| 209 |
); |
|---|
| 210 |
|
|---|
| 211 |
$r = wp_parse_args( $args, $defaults ); |
|---|
| 212 |
extract( $r, EXTR_SKIP ); |
|---|
| 213 |
|
|---|
| 214 |
$output = ''; |
|---|
| 215 |
|
|---|
| 216 |
if ( $categorize ) { |
|---|
| 217 |
|
|---|
| 218 |
$cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0)); |
|---|
| 219 |
|
|---|
| 220 |
foreach ( (array) $cats as $cat ) { |
|---|
| 221 |
$params = array_merge($r, array('category'=>$cat->term_id)); |
|---|
| 222 |
$bookmarks = get_bookmarks($params); |
|---|
| 223 |
if ( empty($bookmarks) ) |
|---|
| 224 |
continue; |
|---|
| 225 |
$output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); |
|---|
| 226 |
$catname = apply_filters( "link_category", $cat->name ); |
|---|
| 227 |
$output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n"; |
|---|
| 228 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 229 |
$output .= "\n\t</ul>\n$category_after\n"; |
|---|
| 230 |
} |
|---|
| 231 |
} else { |
|---|
| 232 |
|
|---|
| 233 |
$bookmarks = get_bookmarks($r); |
|---|
| 234 |
|
|---|
| 235 |
if ( !empty($bookmarks) ) { |
|---|
| 236 |
if ( !empty( $title_li ) ){ |
|---|
| 237 |
$output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); |
|---|
| 238 |
$output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n"; |
|---|
| 239 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 240 |
$output .= "\n\t</ul>\n$category_after\n"; |
|---|
| 241 |
} else { |
|---|
| 242 |
$output .= _walk_bookmarks($bookmarks, $r); |
|---|
| 243 |
} |
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
$output = apply_filters( 'wp_list_bookmarks', $output ); |
|---|
| 248 |
|
|---|
| 249 |
if ( !$echo ) |
|---|
| 250 |
return $output; |
|---|
| 251 |
echo $output; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
?> |
|---|
| 255 |
|
|---|