PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 // 4 // Big Mess 5 // 6 7 // Dandy new recursive multiple category stuff. 8 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { 9 if ( !$categories ) 10 $categories = get_categories( 'hide_empty=0' ); 11 12 $children = _get_term_hierarchy('category'); 13 14 if ( $categories ) { 15 ob_start(); 16 foreach ( $categories as $category ) { 17 if ( $category->parent == $parent) { 18 echo "\t" . _cat_row( $category, $level ); 19 if ( isset($children[$category->term_id]) ) 20 cat_rows( $category->term_id, $level +1, $categories ); 21 } 22 } 23 $output = ob_get_contents(); 24 ob_end_clean(); 25 26 $output = apply_filters('cat_rows', $output); 27 28 echo $output; 29 } else { 30 return false; 31 } 32 } 33 34 function _cat_row( $category, $level, $name_override = false ) { 35 global $class; 36 37 $category = get_category( $category ); 38 39 $pad = str_repeat( '— ', $level ); 40 if ( current_user_can( 'manage_categories' ) ) { 41 $edit = "<a href='categories.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>"; 42 $default_cat_id = (int) get_option( 'default_category' ); 43 44 if ( $category->term_id != $default_cat_id ) 45 $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&cat_ID=$category->term_id", 'delete-category_' . $category->term_id ) . "' class='delete:the-list:cat-$category->term_id delete'>".__( 'Delete' )."</a>"; 46 else 47 $edit .= "<td style='text-align:center'>".__( "Default" ); 48 } else 49 $edit = ''; 50 51 $class = " class='alternate'" == $class ? '' : " class='alternate'"; 52 53 $category->count = number_format_i18n( $category->count ); 54 $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count; 55 $output = "<tr id='cat-$category->term_id'$class> 56 <th scope='row' style='text-align: center'>$category->term_id</th> 57 <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td> 58 <td>$category->description</td> 59 <td align='center'>$posts_count</td> 60 <td>$edit</td>\n\t</tr>\n"; 61 62 return apply_filters('cat_row', $output); 63 } 64 65 function link_cat_row( $category ) { 66 global $class; 67 68 if ( !$category = get_term( $category, 'link_category' ) ) 69 return false; 70 if ( is_wp_error( $category ) ) 71 return $category; 72 73 if ( current_user_can( 'manage_categories' ) ) { 74 $edit = "<a href='link-category.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>"; 75 $default_cat_id = (int) get_option( 'default_link_category' ); 76 77 $delete_url = wp_nonce_url( "link-category.php?action=delete&cat_ID=$category->term_id", "delete-link-category_$category->term_id" ); 78 if ( $category->term_id != $default_cat_id ) 79 $edit .= "<td><a href='$delete_url' class='delete:the-list:link-cat-$category->term_id delete'>" . __( 'Delete' ) . "</a>"; 80 else 81 $edit .= "<td style='text-align:center'>" . __( "Default" ); 82 } else { 83 $edit = ''; 84 } 85 86 $class = " class='alternate'" == $class ? '' : " class='alternate'"; 87 88 $category->count = number_format_i18n( $category->count ); 89 $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count; 90 $output = "<tr id='link-cat-$category->term_id'$class> 91 <th scope='row' style='text-align: center'>$category->term_id</th> 92 <td>" . ( $name_override ? $name_override : $category->name ) . "</td> 93 <td>$category->description</td> 94 <td align='center'>$count</td> 95 <td>$edit</td>\n\t</tr>\n"; 96 97 return apply_filters( 'link_cat_row', $output ); 98 } 99 100 function checked( $checked, $current) { 101 if ( $checked == $current) 102 echo ' checked="checked"'; 103 } 104 105 // TODO: Remove? 106 function documentation_link( $for ) { 107 return; 108 } 109 110 function selected( $selected, $current) { 111 if ( $selected == $current) 112 echo ' selected="selected"'; 113 } 114 115 // 116 // Nasty Category Stuff 117 // 118 119 function sort_cats( $cat1, $cat2 ) { 120 if ( $cat1['checked'] || $cat2['checked'] ) 121 return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; 122 else 123 return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); 124 } 125 126 function get_nested_categories( $default = 0, $parent = 0 ) { 127 global $post_ID, $checked_categories; 128 129 if ( empty($checked_categories) ) { 130 if ( $post_ID ) { 131 $checked_categories = wp_get_post_categories($post_ID); 132 133 if ( count( $checked_categories ) == 0 ) { 134 // No selected categories, strange 135 $checked_categories[] = $default; 136 } 137 } else { 138 $checked_categories[] = $default; 139 } 140 } 141 142 $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); 143 144 $result = array (); 145 if ( is_array( $cats ) ) { 146 foreach ( $cats as $cat) { 147 $result[$cat]['children'] = get_nested_categories( $default, $cat); 148 $result[$cat]['cat_ID'] = $cat; 149 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 150 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 151 } 152 } 153 154 $result = apply_filters('get_nested_categories', $result); 155 usort( $result, 'sort_cats' ); 156 157 return $result; 158 } 159 160 function write_nested_categories( $categories ) { 161 foreach ( $categories as $category ) { 162 echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>"; 163 164 if ( $category['children'] ) { 165 echo "<ul>\n"; 166 write_nested_categories( $category['children'] ); 167 echo "</ul>\n"; 168 } 169 } 170 } 171 172 function dropdown_categories( $default = 0 ) { 173 write_nested_categories( get_nested_categories( $default) ); 174 } 175 176 function dropdown_link_categories( $default = 0 ) { 177 global $link_id; 178 179 if ( $link_id ) { 180 $checked_categories = wp_get_link_cats($link_id); 181 182 if ( count( $checked_categories ) == 0 ) { 183 // No selected categories, strange 184 $checked_categories[] = $default; 185 } 186 } else { 187 $checked_categories[] = $default; 188 } 189 190 $categories = get_terms('link_category', 'orderby=count&hide_empty=0'); 191 192 if ( empty($categories) ) 193 return; 194 195 foreach ( $categories as $category ) { 196 $cat_id = $category->term_id; 197 $name = wp_specialchars( apply_filters('the_category', $category->name)); 198 $checked = in_array( $cat_id, $checked_categories ); 199 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>"; 200 } 201 } 202 203 // define the columns to display, the syntax is 'internal name' => 'display name' 204 function wp_manage_posts_columns() { 205 $posts_columns = array(); 206 $posts_columns['id'] = '<div style="text-align: center">' . __('ID') . '</div>'; 207 if ( 'draft' === $_GET['post_status'] ) 208 $posts_columns['modified'] = __('Modified'); 209 elseif ( 'pending' === $_GET['post_status'] ) 210 $posts_columns['modified'] = __('Submitted'); 211 else 212 $posts_columns['date'] = __('When'); 213 $posts_columns['title'] = __('Title'); 214 $posts_columns['categories'] = __('Categories'); 215 if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) ) 216 $posts_columns['comments'] = '<div style="text-align: center">' . __('Comments') . '</div>'; 217 $posts_columns['author'] = __('Author'); 218 $posts_columns = apply_filters('manage_posts_columns', $posts_columns); 219 220 // you can not edit these at the moment 221 $posts_columns['control_view'] = ''; 222 $posts_columns['control_edit'] = ''; 223 $posts_columns['control_delete'] = ''; 224 225 return $posts_columns; 226 } 227 228 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { 229 global $class, $post; 230 231 if (!$pages ) 232 $pages = get_pages( 'sort_column=menu_order' ); 233 234 if (! $pages ) 235 return false; 236 237 foreach ( $pages as $post) { 238 setup_postdata( $post); 239 if ( $hierarchy && ($post->post_parent != $parent) ) 240 continue; 241 242 $post->post_title = wp_specialchars( $post->post_title ); 243 $pad = str_repeat( '— ', $level ); 244 $id = (int) $post->ID; 245 $class = ('alternate' == $class ) ? '' : 'alternate'; 246 ?> 247 <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'> 248 <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th> 249 <td> 250 <?php echo $pad; ?><?php the_title() ?> 251 </td> 252 <td><?php the_author() ?></td> 253 <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td> 254 <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td> 255 <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td> 256 <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&post=$id", 'delete-page_' . $id ) . "' class='delete:the-list:page-$id delete'>" . __( 'Delete' ) . "</a>"; } ?></td> 257 </tr> 258 259 <?php 260 if ( $hierarchy ) 261 page_rows( $id, $level + 1, $pages ); 262 } 263 } 264 265 function user_row( $user_object, $style = '' ) { 266 if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) 267 $user_object = new WP_User( (int) $user_object ); 268 $email = $user_object->user_email; 269 $url = $user_object->user_url; 270 $short_url = str_replace( 'http://', '', $url ); 271 $short_url = str_replace( 'www.', '', $short_url ); 272 if ('/' == substr( $short_url, -1 )) 273 $short_url = substr( $short_url, 0, -1 ); 274 if ( strlen( $short_url ) > 35 ) 275 $short_url = substr( $short_url, 0, 32 ).'...'; 276 $numposts = get_usernumposts( $user_object->ID ); 277 $r = "<tr id='user-$user_object->ID'$style> 278 <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td> 279 <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 280 <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 281 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td> 282 <td><a href='$url' title='website: $url'>$short_url</a></td>"; 283 $r .= "\n\t\t<td align='center'>"; 284 if ( $numposts > 0 ) { 285 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>"; 286 $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts); 287 $r .= '</a>'; 288 } 289 $r .= "</td>\n\t\t<td>"; 290 if ( current_user_can( 'edit_user', $user_object->ID ) ) { 291 $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ); 292 $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>"; 293 } 294 $r .= "</td>\n\t</tr>"; 295 return $r; 296 } 297 298 function _wp_get_comment_list( $s = false, $start, $num ) { 299 global $wpdb; 300 301 $start = abs( (int) $start ); 302 $num = (int) $num; 303 304 if ( $s ) { 305 $s = $wpdb->escape($s); 306 $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE 307 (comment_author LIKE '%$s%' OR 308 comment_author_email LIKE '%$s%' OR 309 comment_author_url LIKE ('%$s%') OR 310 comment_author_IP LIKE ('%$s%') OR 311 comment_content LIKE ('%$s%') ) AND 312 comment_approved != 'spam' 313 ORDER BY comment_date DESC LIMIT $start, $num"); 314 } else { 315 $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" ); 316 } 317 318 update_comment_cache($comments); 319 320 $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); 321 322 return array($comments, $total); 323 } 324 325 function _wp_comment_list_item( $id, $alt = 0 ) { 326 global $authordata, $comment; 327 $comment =& get_comment( $id ); 328 $id = (int) $comment->comment_ID; 329 $class = ''; 330 $post = get_post($comment->comment_post_ID); 331 $authordata = get_userdata($post->post_author); 332 $comment_status = wp_get_comment_status($id); 333 if ( 'unapproved' == $comment_status ) 334 $class .= ' unapproved'; 335 if ( $alt % 2 ) 336 $class .= ' alternate'; 337 echo "<li id='comment-$id' class='$class'>"; 338 ?> 339 <p><strong class="comment-author"><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p> 340 341 <?php comment_text() ?> 342 343 <p><?php comment_date(__('M j, g:i A')); ?> — [ 344 <?php 345 if ( current_user_can('edit_post', $comment->comment_post_ID) ) { 346 echo " <a href='comment.php?action=editcomment&c=$id'>" . __('Edit') . '</a>'; 347 $url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$id", "delete-comment_$id" ) ); 348 echo " | <a href='$url' class='delete:the-comment-list:comment-$id'>" . __('Delete') . '</a> '; 349 if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) { 350 $url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$id", "unapprove-comment_$id" ) ); 351 echo "<span class='unapprove'> | <a href='$url' class='dim:the-comment-list:comment-$id:unapproved:FFFF33'>" . __('Unapprove') . '</a> </span>'; 352 $url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$id", "approve-comment_$id" ) ); 353 echo "<span class='approve'> | <a href='$url' class='dim:the-comment-list:comment-$id:unapproved:33FF33:33FF33'>" . __('Approve') . '</a> </span>'; 354 } 355 $url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$id", "delete-comment_$id" ) ); 356 echo " | <a href='$url' class='delete:the-comment-list:comment-$id::spam=1'>" . __('Spam') . '</a> '; 357 } 358 if ( !is_single() ) { 359 $post = get_post($comment->comment_post_ID, OBJECT, 'display'); 360 $post_title = wp_specialchars( $post->post_title, 'double' ); 361 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" :