| [ Index ] |
PHP Cross Reference of zeList |
[Summary view] [Print] [Text view]
1 <?php 2 3 function the_directory_description() { 4 echo get_the_directory_description(); 5 } 6 function get_the_directory_description() { 7 if($description = get_option('zelist_directory_name')) return $description; 8 else return get_bloginfo('description'); 9 } 10 11 function the_zelist_category() { 12 if(!is_link_category()) return false; 13 global $current_link_category; 14 return $current_link_category; 15 } 16 function the_link_category_description($args = '') 17 { 18 $defaults = array( 19 'before' => '<p class="link_category_description">', 20 'after' => '</p>', 21 ); 22 $args = wp_parse_args( $args, $defaults ); 23 extract($args, EXTR_SKIP); 24 $description = get_link_category_description($args); 25 if(!$description) return; 26 27 echo $before . $description . $after ; 28 } 29 30 function get_link_category_description($args = '') { 31 $category = the_zelist_category(); 32 if($category && !empty($category->description)) return $category->description; 33 return false; 34 } 35 36 37 38 function the_image($args = '') { 39 $defaults = array( 40 'width' => 0, 41 'height' => 0, 42 'resize' => 0, 43 ); 44 $args = wp_parse_args($args,$defaults); 45 extract($args,EXTR_OVERWRITE); 46 47 $image = has_image(); 48 if(!$image) return; 49 $string = '<img class="link_image" src="'.$image.'" '; 50 $string .= 'alt="'.$link->link_name.'" '; 51 52 53 // @TODO image size... or image hosting 54 if($width || $height) { 55 if($resize && $size = @getimagesize($image)) { } 56 else { 57 if($width) $string .= 'width="'.$width.' px" '; 58 if($height) $string .= 'height="'.$height.' px" '; 59 } 60 } 61 62 63 $string .= '/>'; 64 echo apply_filters('the_image',$string); 65 } 66 67 function has_image() { 68 global $link; 69 if(!empty($link->link_image)) return $link->link_image; 70 return false; 71 } 72 73 74 function the_host() { 75 echo apply_filters('the_host',get_the_host()); 76 } 77 function get_the_host() { 78 $url = get_the_url(); 79 if(!$url) return; 80 $url = parse_url($url); 81 return $url['host']; 82 83 } 84 85 function the_url() { 86 echo apply_filters('the_url',get_the_url()); 87 } 88 89 function get_the_url() { 90 global $link; 91 if(strlen($link->link_url)) return $link->link_url; 92 return false; 93 } 94 95 function the_link_permalink() { 96 echo apply_filters('the_permalink',get_link_permalink()); 97 } 98 99 function the_rating() { 100 echo apply_filters('the_rating',get_the_rating()); 101 } 102 function get_the_rating() { 103 global $link; 104 return $link->link_rating; 105 } 106 function has_pagerank() { 107 global $link; 108 $pagerank = get_link_meta($link->link_id, 'pagerank',true); 109 if($pagerank && !empty($pagerank)) return $pagerank; 110 return false; 111 } 112 113 function the_pagerank_image($pagerank = false) { 114 if(!$pagerank && !$pagerank = has_pagerank()) return false; 115 $pagerank = absint($pagerank); 116 $img = (file_exists(TEMPLATEPATH . 'pr'.$pagerank.'.gif')) ? 117 TEMPLATEPATH . 'pr'.$pagerank.'.gif' : 118 ZELIST_URL.'/style/pr'.$pagerank.'.gif'; 119 $string = '<img class="pagerank" src="'.$img.'" />'; 120 echo $string; 121 } 122 123 function get_zelist_stats() { 124 $stats = array(); 125 foreach(array('numactive','numpending','numcats','numposts','datelastlink','datelastsubmit') as $stat) $stats[$stat] = false; 126 return $stats; 127 128 } 129 130 /** 131 * Retrieve the tags for a link. 132 * 133 * @since 2.3.0 134 * 135 * @param string $before Optional. Before list. 136 * @param string $sep Optional. Separate items using this. 137 * @param string $after Optional. After list. 138 * @return string 139 */ 140 function the_link_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) { 141 global $link; 142 if(!$link) return; 143 return the_terms( $link->link_id, 'link_tag', $before, $sep, $after ); 144 } 145 146 function has_rss($link_id = 0) { 147 if($link_id > 0) $link = get_link($link_id); 148 else global $link; 149 if(!empty($link->link_rss)) return $link->link_rss; 150 else return false; 151 } 152 153 function the_rss($args = '') 154 { 155 $defaults = array( 156 'echo' => 1, 157 'feed' => false, 158 'class' => 'site_feed', 159 'limit' => 10, 160 'excerpt' => 150, 161 'title_li' => '<h3>'.__('Site feed','zelist').'</h3>', 162 'feed_title' => false, 163 'link_id' => false, 164 ); 165 $args = wp_parse_args( $args, $defaults ); 166 extract($args, EXTR_SKIP); 167 168 global $link; 169 if(!$feed && $link_id) $feed = has_rss($link_id); 170 elseif(!$feed && $link->link_rss) $feed = $link->link_rss; 171 elseif(!$feed) return false; 172 173 $rss = parse_the_feed($feed); 174 if(!$rss->items) return __('No items in feed','zelist'); 175 176 $string_start = "\n$title_li\n<ul class='$class'>"; 177 178 179 $output = '<ul>'; 180 181 $rss->items = array_slice($rss->items,0,$limit); 182 if($feed_title && $rss->channel['title']) $output .= "\n".'<li class="title_li">'.$rss->channel['title'].'</li>'; 183 elseif($title_li) $output .= "\n".'<li class="title_li">'.$title_li.'</li>'; 184 $items_shown = 0; 185 $urls = array(); 186 $urls[$link->zelist_url] = true; 187 foreach($rss->items as $item) 188 { 189 // de duplicate 190 if($urls[$item['link']]) continue; 191 $urls[$item['link']] = true; 192 193 $items_shown++; 194 if($excerpt && strlen($item['description']) > $excerpt) $item['description'] = substr($item['description'],0,$excerpt).'...'; 195 //elseif(strlen($item['description']) > $) $item['description'] = substr($item['description'],0,59).'...'; 196 197 $output .= ' 198 <li><a href="'.$item['link'].'">'.$item['title'].'</a>'; 199 if($excerpt) $output .= ' 200 <span class="content">'.$item['description'].'</span>'; 201 $output .= '</li>'; 202 if($items_shown >= $limit) break; 203 } 204 $output_end = "\n</ul>"; 205 if(!$output) return; 206 if(!$items_shown) return; 207 $output = $output_start . $output . $output_end; 208 if($echo) echo $output; 209 else return $output; 210 } 211 212 function parse_the_feed($feed_url) { 213 include_once(ABSPATH . WPINC . '/rss.php'); 214 $rss = fetch_rss($feed_url); 215 return $rss; 216 } 217 218 function the_submit_link() { 219 if($link = get_submit_link()) { 220 echo '<a href="'.$link.'" title="'.__('Submit','zelist').'">'.__('Submit','zelist').'</a>'; 221 } 222 } 223 function get_submit_link() { 224 $page_id = get_option('zelist_submit_page'); 225 $link = get_permalink($page_id); 226 $link_category = get_zelist_query_var('link_category'); 227 if($link_category) $link = add_query_arg('link_category',$link_category,$link); 228 return apply_filters('get_submit_link',$link); 229 } 230 231 232 /** 233 * Display the classes for the link div. 234 * 235 * @since 2.7.0 236 * 237 * @param string|array $class One or more classes to add to the class list. 238 * @param int $link_id An optional link ID. 239 */ 240 function link_class( $class = '', $link_id = null ) { 241 // Separates classes with a single space, collates classes for link DIV 242 echo 'class="' . join( ' ', get_link_class( $class, $link_id ) ) . '"'; 243 } 244 245 246 /** 247 * Retrieve the classes for the link div as an array. 248 * 249 * The class names are add are many. If the link is a sticky, then the 'sticky' 250 * class name. The class 'hentry' is always added to each link. For each 251 * category, the class will be added with 'category-' with category slug is 252 * added. The tags are the same way as the categories with 'tag-' before the tag 253 * slug. All classes are passed through the filter, 'link_class' with the list 254 * of classes, followed by $class parameter value, with the link ID as the last 255 * parameter. 256 * 257 * @since 2.7.0 258 * 259 * @param string|array $class One or more classes to add to the class list. 260 * @param int $link_id An optional link ID. 261 * @return array Array of classes. 262 */ 263 function get_link_class( $class = '', $link_id = null ) { 264 $link = get_link($link_id); 265 266 $classes = array(); 267 268 // hlink for hAtom compliace 269 $classes[] = 'hlink'; 270 271 $classes[] = 'link'; 272 273 // Categories 274 foreach ( (array) get_the_link_category($link->link_id) as $cat ) { 275 if ( empty($cat->slug ) ) 276 continue; 277 $classes[] = 'category-' . $cat->slug; 278 } 279 280 // Tags 281 foreach ( (array) wp_get_link_tags($link->ID) as $tag ) { 282 if ( empty($tag->slug ) ) 283 continue; 284 $classes[] = 'tag-' . $tag->slug; 285 } 286 287 if ( !empty($class) ) { 288 if ( !is_array( $class ) ) 289 $class = preg_split('#\s+#', $class); 290 $classes = array_merge($classes, $class); 291 } 292 293 return apply_filters('link_class', $classes, $class, $link_id); 294 } 295 296 /** 297 * Display the next links pages link. 298 * 299 * @since 0.71 300 * @uses get_next_links_link() 301 * 302 * @param string $label Content for link text. 303 * @param int $max_page Optional. Max pages. 304 */ 305 function next_links_link( $label = 'Next Page »', $max_page = 0 ) { 306 echo get_next_links_link( $label, $max_page ); 307 } 308 /** 309 * Return the next links pages link. 310 * 311 * @since 2.7.0 312 * 313 * @param string $label Content for link text. 314 * @param int $max_page Optional. Max pages. 315 * @return string|null 316 */ 317 function get_next_links_link( $label = 'Next Page »', $max_page = 0 ) { 318 global $paged, $wp_query; 319 320 if ( !$max_page ) { 321 $max_page = $wp_query->max_num_pages; 322 } 323 324 if ( !$paged ) 325 $paged = 1; 326 327 $nextpage = intval($paged) + 1; 328 329 if ( !is_a_link() && ( empty($paged) || $nextpage <= $max_page) ) { 330 $attr = apply_filters( 'next_links_link_attributes', '' ); 331 return '<a href="' . next_links( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; 332 } 333 } 334 335 /** 336 * Return the previous links pages link. 337 * 338 * @since 2.7.0 339 * 340 * @param string $label Optional. Previous page link text. 341 * @return string|null 342 */ 343 function get_previous_links_link( $label = '« Previous Page' ) { 344 global $paged; 345 346 if ( !is_a_link() && $paged > 1 ) { 347 $attr = apply_filters( 'previous_links_link_attributes', '' ); 348 return '<a href="' . previous_links( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>'; 349 } 350 } 351 352 353 354 /** 355 * Display the previous links page link. 356 * 357 * @since 0.71 358 * @uses get_previous_links_link() 359 * 360 * @param string $label Optional. Previous page link text. 361 */ 362 function previous_links_link( $label = '« Previous Page' ) { 363 echo get_previous_links_link( $label ); 364 } 365 366 367 /** 368 * Retrieve edit links link for link. 369 * 370 * @since 1.0.0 371 * 372 * @param string $link Optional. Anchor text. 373 * @param string $before Optional. Display before edit link. 374 * @param string $after Optional. Display after edit link. 375 */ 376 function edit_link_link( $anchor = 'Edit This', $before = '', $after = '' ) { 377 if(!current_user_can('manage_links')) return; 378 global $link; 379 380 $location = ZELIST_ADMIN_URL_LINK.'&action=edit&link_id='.$link->link_id; 381 $link_string = '<a href="' . $location . '" title="' . attribute_escape( __( 'Edit link' ) ) . '">' . $anchor . '</a>'; 382 echo $before . apply_filters( 'edit_link_link', $link_string, $link->link_id ) . $after; 383 } 384 385 /** 386 * Display the time at which the link was written. 387 * 388 * @since 0.71 389 * 390 * @param string $d Either 'G', 'U', or php date format. 391 */ 392 function the_link_time( $d = '' ) { 393 echo apply_filters('the_time', get_the_link_time( $d ), $d); 394 } 395 396 397 /** 398 * Display or Retrieve the date the link was written. 399 * 400 * Will only output the date if the current link's date is different from the 401 * previous one output. 402 * 403 * @since 0.71 404 * 405 * @param string $d Optional. PHP date format defaults to the date_format option if not specified. 406 * @param string $before Optional. Output before the date. 407 * @param string $after Optional. Output after the date. 408 * @param bool $echo Optional, default is display. Whether to echo the date or return it. 409 * @return string|null Null if displaying, string if retrieving. 410 */ 411 function the_link_date($d='', $before='', $after='', $echo = true, $updated = false) { 412 global $link, $day, $previousday; 413 $the_date = ''; 414 if ( $day != $previousday ) { 415 $the_date .= $before; 416 if($updated) $link_date = $link->link_updated; 417 else $link_date = $link->link_added; 418 419 if ( $d=='' ) 420 $the_date .= mysql2date(get_option('date_format'), $link_date); 421 else 422 $the_date .= mysql2date($d, $link_date); 423 $the_date .= $after; 424 $previousday = $day; 425 } 426 $the_date = apply_filters('the_link_date', $the_date, $d, $before, $after); 427 if ( $echo ) 428 echo $the_date; 429 else 430 return $the_date; 431 } 432 433 /** 434 * {@internal Missing Short Description}} 435 * 436 * @since unknown 437 */ 438 class Walker_Link_Category_Checklist extends Walker { 439 var $tree_type = 'category'; 440 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this 441 442 function start_lvl(&$output, $depth, $args) { 443 $indent = str_repeat("\t", $depth); 444 $output .= "$indent<ul class='children'>\n"; 445 } 446 447 function end_lvl(&$output, $depth, $args) { 448 $indent = str_repeat("\t", $depth); 449 $output .= "$indent</ul>\n"; 450 } 451 452 function start_el(&$output, $category, $depth, $args) { 453 extract($args); 454 $type = (get_option('zelist_allow_multiple_categories')) ? 'checkbox' : 'radio'; 455 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; 456 $output .= "\n<li id='category-$category->term_id'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="'.$type.'" name="link_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . wp_specialchars( apply_filters('the_category', $category->name )) . '</label>'; 457 } 458 459 function end_el(&$output, $category, $depth, $args) { 460 $output .= "</li>\n"; 461 } 462 } 463 464 /** 465 * {@internal Missing Short Description}} 466 * 467 * @since unknown 468 * 469 * @param unknown_type $post_id 470 * @param unknown_type $descendants_and_self 471 * @param unknown_type $selected_cats 472 * @param unknown_type $popular_cats 473 */ 474 function zelist_link_category_checklist( $link_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null ) { 475 if ( empty($walker) || !is_a($walker, 'Walker') ) 476 $walker = new Walker_Link_Category_Checklist; 477 478 $descendants_and_self = (int) $descendants_and_self; 479 480 $args = array(); 481 482 if ( is_array( $selected_cats ) ) 483 $args['selected_cats'] = $selected_cats; 484 elseif ( $link_id ) 485 $args['selected_cats'] = wp_get_link_categories($link_id); 486 else 487 $args['selected_cats'] = array(); 488 489 if ( is_array( $popular_cats ) ) 490 $args['popular_cats'] = $popular_cats; 491 else 492 $args['popular_cats'] = get_terms( 'link_category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); 493 494 if ( $descendants_and_self ) { 495 $categories = get_categories( "type=link&child_of=$descendants_and_self&hierarchical=0&hide_empty=0" ); 496 $self = get_category( $descendants_and_self ); 497 array_unshift( $categories, $self ); 498 } else { 499 $categories = get_categories('type=link&get=all'); 500 } 501 502 // link process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all links (for any query cache) 503 $checked_categories = array(); 504 for ( $i = 0; isset($categories[$i]); $i++ ) { 505 if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) { 506 $checked_categories[] = $categories[$i]; 507 unset($categories[$i]); 508 } 509 } 510 511 // Put checked cats on top 512 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); 513 // Then the rest of them 514 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); 515 } 516 517 518 /** 519 * {@internal Missing Short Description}} 520 * 521 * @since unknown 522 * 523 * @param unknown_type $taxonomy 524 * @param unknown_type $default 525 * @param unknown_type $number 526 * @param unknown_type $echo 527 * @return unknown 528 */ 529 function zelist_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { 530 global $link_id; 531 if ( $link_id ) 532 $checked_categories = wp_get_link_categories($link_id); 533 else 534 $checked_categories = array(); 535 $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); 536 537 $popular_ids = array(); 538 foreach ( (array) $categories as $category ) { 539 $popular_ids[] = $category->term_id; 540 if ( !$echo ) // hack for AJAX use 541 continue; 542 $id = "popular-category-$category->term_id"; 543 $type = (get_option('zelist_allow_multiple_categories')) ? 'checkbox' : 'radio'; 544 ?> 545 546 <li id="<?php echo $id; ?>" class="popular-category"><label 547 class="selectit"> <input id="in-<?php echo $id; ?>" 548 type="<?php echo $type; ?>" 549 value="<?php echo (int) $category->term_id; ?>" /> <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?> 550 </label></li> 551 552 <?php 553 } 554 return $popular_ids; 555 } 556 557 558 559 function the_link_searchform() { 560 if(file_exists(TEMPLATEPATH . "/link-searchform.php")) include (TEMPLATEPATH . "/link-searchform.php"); 561 else include (ZELIST_PATH.'/style/link-searchform.php'); 562 } 563 564 /** 565 * Generates an excerpt from the content, if needed. 566 * 567 * The excerpt word amount will be 55 words and if the amount is greater than 568 * that, then the string '[...]' will be appended to the excerpt. If the string 569 * is less than 55 words, then the content will be returned as is. 570 * 571 * @since 1.5.0 572 * 573 * @param string $text The exerpt. If set to empty an excerpt is generated. 574 * @return string The excerpt. 575 */ 576 function zelist_trim_excerpt($text = '', $excerpt_length = false) { 577 if ( '' == $text ) { 578 global $link; 579 $text = $link->link_description; 580 } 581 if(!$excerpt_length) $excerpt_length = apply_filters('excerpt_length', 55); 582 583 $text = strip_shortcodes( $text ); 584 $text = strip_tags($text); 585 586 $text = apply_filters('the_content', $text); 587 $text = str_replace(']]>', ']]>', $text); 588 $text = strip_tags($text); 589 590 $words = explode(' ', $text); 591 $new_words = array(); 592 $new_length = 0; 593 while($new_length < $excerpt_length) { 594 $word = array_shift($words); 595 $new_words[] = $word; 596 $new_length += strlen($word)+1; 597 } 598 if(count($words)) { 599 $new_words[] = '[...]'; 600 } 601 602 $text = implode(' ', $new_words); 603 return $text; 604 } 605 606 function the_submit_message() { 607 608 if(!isset($_GET['error_id']) || !$error_id = absint($_GET['error_id'])) return; 609 610 $errors = array( 611 1 => __('Link already known','zelist'), 612 2 => __('Link not created','zelist'), 613 3 => __('Missing Fields','zelist'), 614 ); 615 echo '<div class="error">'.$errors[$error_id].'</div>'; 616 $actions = array(); 617 if($link_id = absint($_GET['link_id'])) { 618 619 if(link_is_visible($link_id)) $actions[] = sprintf(__('<a href="%s">View link</a>'),get_link_permalink($link_id)); 620 if(current_user_can('edit_links',$link_id)) $actions[] = sprintf(__('<a href="%s">Edit link</a>'),get_edit_bookmark_link($link_id)); 621 if(count($actions)) echo '<div class="tip">'.implode(' | ',$actions).'</div>'; 622 } 623 624 } 625 626 function the_submit_form_action() { 627 echo ZELIST_ADMIN_URL_LINK.'&noheader=1&action=new'; 628 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat May 30 23:51:06 2009 | Cross-referenced by PHPXref 0.7 |