| [ Index ] |
PHP Cross Reference of zeList |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Retrieve the tags for a link. 4 * 5 * There is only one default for this function, called 'fields' and by default 6 * is set to 'all'. There are other defaults that can be override in 7 * {@link wp_get_object_terms()}. 8 * 9 * @package WordPress 10 * @subpackage link 11 * @since 2.3.0 12 * 13 * @uses wp_get_object_terms() Gets the tags for returning. Args can be found here 14 * 15 * @param int $link_id Optional. The link ID 16 * @param array $args Optional. Overwrite the defaults 17 * @return array List of link tags. 18 */ 19 function wp_get_link_tags( $link_id = 0, $args = array() ) { 20 $link_id = (int) $link_id; 21 $defaults = array('fields' => 'all'); 22 $args = wp_parse_args( $args, $defaults ); 23 $tags = wp_get_object_terms($link_id, 'link_tag', $args); 24 return apply_filters( 'wp_get_link_tags', $tags); 25 } 26 27 /** 28 * Return link tags in edit context 29 * 30 * @since unknown 31 * 32 * @param unknown_type $link_id 33 * @return unknown 34 */ 35 function get_link_tags_to_edit( $link_id ) { 36 $link_id = (int) $link_id; 37 if ( !$link_id ) 38 return false; 39 40 $tags = wp_get_link_tags($link_id); 41 42 if ( !$tags ) 43 return false; 44 45 foreach ( $tags as $tag ) 46 $tag_names[] = $tag->name; 47 $tags_to_edit = join( ',', $tag_names ); 48 $tags_to_edit = attribute_escape( $tags_to_edit ); 49 $tags_to_edit = apply_filters( 'link_tags_to_edit', $tags_to_edit ); 50 return $tags_to_edit; 51 } 52 53 /** 54 * Set the tags for a link. 55 * 56 * @since 2.3.0 57 * @uses wp_set_object_terms() Sets the tags for the link. 58 * 59 * @param int $link_id link ID. 60 * @param string $tags The tags to set for the link, separated by commas. 61 * @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags. 62 * @return bool|null Will return false if $link_id is not an integer or is 0. Will return null otherwise 63 */ 64 function wp_set_link_tags( $link_id = 0, $tags = '', $append = false ) { 65 66 $link_id = (int) $link_id; 67 68 if ( !$link_id ) 69 return false; 70 71 if ( empty($tags) ) 72 $tags = array(); 73 $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") ); 74 wp_set_object_terms($link_id, $tags, 'link_tag', $append); 75 } 76 77 /** 78 * Will update term count based on links. 79 * 80 * Private function for the default callback for link_tag and category 81 * taxonomies. 82 * 83 * @package WordPress 84 * @subpackage Taxonomy 85 * @access private 86 * @since 2.3.0 87 * @uses $wpdb 88 * 89 * @param array $terms List of Term taxonomy IDs 90 */ 91 function _update_link_term_count( $terms ) { 92 global $wpdb; 93 foreach ( (array) $terms as $term ) { 94 //echo "<br />\n".$wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->term_relationships.object_id AND link_status = 'publish' AND term_taxonomy_id = %d", $term ); 95 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->term_relationships.object_id AND link_status = 'publish' AND term_taxonomy_id = %d", $term ) ); 96 $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 97 } 98 } 99 100 /** 101 * Return edit link for a link tag 102 * @param $tag_id 103 * @return unknown_type 104 */ 105 function get_edit_link_tag_link( $tag_id = 0 ) { 106 $tag = get_term($tag_id, 'link_tag'); 107 108 if ( !current_user_can('manage_categories') ) return; 109 $location = ZELIST_ADMIN_URL_TAGS."&action=edit&tag_ID=$tag->term_id"; 110 return apply_filters( 'get_edit_link_tag_link', $location ); 111 } 112 113 /** 114 * Return front end link for a link tag 115 * @param $tag_id 116 * @return unknown_type 117 */ 118 function get_link_tag_link( $tag_id ) { 119 global $wp_rewrite; 120 121 if($wp_rewrite->using_permalinks() && get_option('zelist_rewrite')) 122 $taglink = $wp_rewrite->get_extra_permastruct('link_tag'); 123 124 $tag = &get_term( $tag_id, 'link_tag' ); 125 if ( is_wp_error( $tag ) ) return $tag; 126 127 $slug = $tag->slug; 128 129 if ( empty( $taglink ) ) { 130 $root = untrailingslashit(get_permalink(get_option('zelist_root'))); 131 $taglink = add_query_arg('link_tag',$slug,$root); 132 } else { 133 $taglink = str_replace( '%link_tag%', $slug, $taglink ); 134 //$taglink = get_option( 'zelist_root' ) . user_trailingslashit( $taglink, 'category' ); 135 $home = trailingslashit(untrailingslashit(get_option('home'))); 136 //$home = get_option('home'); 137 $taglink = $home . $taglink; 138 } 139 return apply_filters( 'link_tag_link', $taglink, $tag_id ); 140 } 141 142 /** 143 * Checks wether a link tag exists 144 * @param $tag_name 145 * @return unknown_type 146 */ 147 function link_tag_exists($tag_name) { 148 return is_term($tag_name,'link_tag'); 149 } 150 151 /** 152 * Display link tag cloud. 153 * 154 * The text size is set by the 'smallest' and 'largest' arguments, which will 155 * use the 'unit' argument value for the CSS text size unit. The 'format' 156 * argument can be 'flat' (default), 'list', or 'array'. The flat value for the 157 * 'format' argument will separate tags with spaces. The list value for the 158 * 'format' argument will format the tags in a UL HTML list. The array value for 159 * the 'format' argument will return in PHP array type format. 160 * 161 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'. 162 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. 163 * 164 * The 'number' argument is how many tags to return. By default, the limit will 165 * be to return the top 45 tags in the tag cloud list. 166 * 167 * The 'topic_count_text_callback' argument is a function, which, given the count 168 * of the posts with that tag, returns a text for the tooltip of the tag link. 169 * @see default_topic_count_text 170 * 171 * The 'exclude' and 'include' arguments are used for the {@link get_tags()} 172 * function. Only one should be used, because only one will be used and the 173 * other ignored, if they are both set. 174 * 175 * @since 2.3.0 176 * 177 * @param array|string $args Optional. Override default arguments. 178 * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. 179 */ 180 function wp_link_tag_cloud( $args = '' ) { 181 $defaults = array( 182 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 183 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 184 'exclude' => '', 'include' => '', 'link' => 'view' 185 ); 186 $args = wp_parse_args( $args, $defaults ); 187 188 189 $tags = get_links_tags( array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags 190 191 if ( empty( $tags ) ) 192 return; 193 194 foreach ( $tags as $key => $tag ) { 195 if ( 'edit' == $args['link'] ) 196 $link = get_edit_link_tag_link( $tag->term_id ); 197 else 198 $link = get_link_tag_link( $tag->term_id ); 199 200 if ( is_wp_error( $link ) ) 201 return false; 202 203 $tags[ $key ]->link = $link; 204 $tags[ $key ]->id = $tag->term_id; 205 } 206 207 $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args 208 209 $return = apply_filters( 'wp_link_tag_cloud', $return, $args ); 210 211 if ( 'array' == $args['format'] ) 212 return $return; 213 214 echo $return; 215 }
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 |