1 | <?php |
2 | /** |
3 | * Template WordPress Administration API. |
4 | * |
5 | * A Big Mess. Also some neat functions that are nicely written. |
6 | * |
7 | * @package WordPress |
8 | * @subpackage Administration |
9 | */ |
10 | |
11 | /** |
12 | * {@internal Missing Short Description}} |
13 | * |
14 | * @since 2.7 |
15 | * |
16 | * Outputs the HTML for the hidden table rows used in Categories, Link Categories and Tags quick edit. |
17 | * |
18 | * @param string $type "edit-tags", "categoried" or "edit-link-categories" |
19 | * @param string $taxonomy The taxonomy of the row. |
20 | * @return |
21 | */ |
22 | function inline_edit_term_row($type, $taxonomy) { |
23 | |
24 | $tax = get_taxonomy($taxonomy); |
25 | if ( ! current_user_can( $tax->cap->edit_terms ) ) |
26 | return; |
27 | |
28 | $columns = get_column_headers($type); |
29 | $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) ); |
30 | $col_count = count($columns) - count($hidden); |
31 | ?> |
32 | |
33 | <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> |
34 | <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>"> | //Cross Site Scripting
|
35 | |
36 | <fieldset><div class="inline-edit-col"> |
37 | <h4><?php _e( 'Quick Edit' ); ?></h4> |
38 | |
39 | <label> |
40 | <span class="title"><?php _e( 'Name' ); ?></span> |
41 | <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span> |
42 | </label> |
43 | <?php if ( !is_multisite() ) { ?> |
44 | <label> |
45 | <span class="title"><?php _e( 'Slug' ); ?></span> |
46 | <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span> |
47 | </label> |
48 | <?php } ?> |
49 | |
50 | </div></fieldset> |
51 | |
52 | <?php |
53 | |
54 | $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true ); |
55 | |
56 | foreach ( $columns as $column_name => $column_display_name ) { |
57 | if ( isset( $core_columns[$column_name] ) ) |
58 | continue; |
59 | do_action( 'quick_edit_custom_box', $column_name, $type, $taxonomy ); |
60 | } |
61 | |
62 | ?> |
63 | |
64 | <p class="inline-edit-save submit"> |
65 | <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a> |
66 | <?php $update_text = $tax->labels->update_item; ?> |
67 | <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> | //Cross Site Scripting
|
68 | <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> |
69 | <span class="error" style="display:none;"></span> |
70 | <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> |
71 | <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" /> |
72 | <br class="clear" /> |
73 | </p> |
74 | </td></tr> |
75 | </tbody></table></form> |
76 | <?php |
77 | } |
78 | |
79 | /** |
80 | * {@internal Missing Short Description}} |
81 | * |
82 | * @since unknown |
83 | * |
84 | * @param unknown_type $category |
85 | * @param unknown_type $name_override |
86 | * @return unknown |
87 | */ |
88 | function link_cat_row( $category, $name_override = false ) { |
89 | static $row_class = ''; |
90 | |
91 | if ( !$category = get_term( $category, 'link_category', OBJECT, 'display' ) ) |
92 | return false; |
93 | if ( is_wp_error( $category ) ) |
94 | return $category; |
95 | |
96 | $default_cat_id = (int) get_option( 'default_link_category' ); |
97 | $name = ( $name_override ? $name_override : $category->name ); |
98 | $edit_link = "link-category.php?action=edit&cat_ID=$category->term_id"; |
99 | if ( current_user_can( 'manage_categories' ) ) { |
100 | $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit “%s”'), $category->name)) . "'>$name</a><br />"; |
101 | $actions = array(); |
102 | $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; |
103 | $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick Edit') . '</a>'; |
104 | if ( $default_cat_id != $category->term_id ) |
105 | $actions['delete'] = "<a class='delete:the-list:link-cat-$category->term_id submitdelete' href='" . wp_nonce_url("link-category.php?action=delete&cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id) . "'>" . __('Delete') . "</a>"; |
106 | $actions = apply_filters('link_cat_row_actions', $actions, $category); |
107 | $action_count = count($actions); |
108 | $i = 0; |
109 | $edit .= '<div class="row-actions">'; |
110 | foreach ( $actions as $action => $link ) { |
111 | ++$i; |
112 | ( $i == $action_count ) ? $sep = '' : $sep = ' | '; |
113 | $edit .= "<span class='$action'>$link$sep</span>"; |
114 | } |
115 | $edit .= '</div>'; |
116 | } else { |
117 | $edit = $name; |
118 | } |
119 | |
120 | $row_class = 'alternate' == $row_class ? '' : 'alternate'; |
121 | $qe_data = get_term_to_edit($category->term_id, 'link_category'); |
122 | |
123 | $category->count = number_format_i18n( $category->count ); |
124 | $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count; |
125 | $output = "<tr id='link-cat-$category->term_id' class='iedit $row_class'>"; |
126 | $columns = get_column_headers('edit-link-categories'); |
127 | $hidden = get_hidden_columns('edit-link-categories'); |
128 | foreach ( $columns as $column_name => $column_display_name ) { |
129 | $class = "class=\"$column_name column-$column_name\""; |
130 | |
131 | $style = ''; |
132 | if ( in_array($column_name, $hidden) ) |
133 | $style = ' style="display:none;"'; |
134 | |
135 | $attributes = "$class$style"; |
136 | |
137 | switch ($column_name) { |
138 | case 'cb': |
139 | $output .= "<th scope='row' class='check-column'>"; |
140 | if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) { |
141 | $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />"; |
142 | } else { |
143 | $output .= " "; |
144 | } |
145 | $output .= "</th>"; |
146 | break; |
147 | case 'name': |
148 | $output .= "<td $attributes>$edit"; |
149 | $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; |
150 | $output .= '<div class="name">' . $qe_data->name . '</div>'; |
151 | $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; |
152 | $output .= '<div class="cat_parent">' . $qe_data->parent . '</div></div></td>'; |
153 | break; |
154 | case 'description': |
155 | $output .= "<td $attributes>$category->description</td>"; |
156 | break; |
157 | case 'slug': |
158 | $output .= "<td $attributes>" . apply_filters('editable_slug', $category->slug) . "</td>"; |
159 | break; |
160 | case 'links': |
161 | $attributes = 'class="links column-links num"' . $style; |
162 | $output .= "<td $attributes>$count</td>"; |
163 | break; |
164 | default: |
165 | $output .= "<td $attributes>"; |
166 | $output .= apply_filters('manage_link_categories_custom_column', '', $column_name, $category->term_id); |
167 | $output .= "</td>"; |
168 | } |
169 | } |
170 | $output .= '</tr>'; |
171 | |
172 | return $output; |
173 | } |
174 | |
175 | // |
176 | // Category Checklists |
177 | // |
178 | |
179 | /** |
180 | * {@internal Missing Short Description}} |
181 | * |
182 | * @since unknown |
183 | */ |
184 | class Walker_Category_Checklist extends Walker { |
185 | var $tree_type = 'category'; |
186 | var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this |
187 | |
188 | function start_lvl(&$output, $depth, $args) { |
189 | $indent = str_repeat("\t", $depth); |
190 | $output .= "$indent<ul class='children'>\n"; |
191 | } |
192 | |
193 | function end_lvl(&$output, $depth, $args) { |
194 | $indent = str_repeat("\t", $depth); |
195 | $output .= "$indent</ul>\n"; |
196 | } |
197 | |
198 | function start_el(&$output, $category, $depth, $args) { |
199 | extract($args); | //Possible Control Flow
|
200 | if ( empty($taxonomy) ) |
201 | $taxonomy = 'category'; |
202 | |
203 | if ( $taxonomy == 'category' ) |
204 | $name = 'post_category'; |
205 | else |
206 | $name = 'tax_input['.$taxonomy.']'; |
207 | |
208 | $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; |
209 | $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>'; |
210 | } |
211 | |
212 | function end_el(&$output, $category, $depth, $args) { |
213 | $output .= "</li>\n"; |
214 | } |
215 | } |
216 | |
217 | /** |
218 | * {@internal Missing Short Description}} |
219 | * |
220 | * @since unknown |
221 | * |
222 | * @param unknown_type $post_id |
223 | * @param unknown_type $descendants_and_self |
224 | * @param unknown_type $selected_cats |
225 | * @param unknown_type $popular_cats |
226 | */ |
227 | function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { |
228 | wp_terms_checklist($post_id, |
229 | array( |
230 | 'taxonomy' => 'category', |
231 | 'descendants_and_self' => $descendants_and_self, |
232 | 'selected_cats' => $selected_cats, |
233 | 'popular_cats' => $popular_cats, |
234 | 'walker' => $walker, |
235 | 'checked_ontop' => $checked_ontop |
236 | )); |
237 | } |
238 | |
239 | /** |
240 | * Taxonomy independent version of wp_category_checklist |
241 | * |
242 | * @param int $post_id |
243 | * @param array $args |
244 | */ |
245 | function wp_terms_checklist($post_id = 0, $args = array()) { |
246 | $defaults = array( |
247 | 'descendants_and_self' => 0, |
248 | 'selected_cats' => false, |
249 | 'popular_cats' => false, |
250 | 'walker' => null, |
251 | 'taxonomy' => 'category', |
252 | 'checked_ontop' => true |
253 | ); |
254 | extract( wp_parse_args($args, $defaults), EXTR_SKIP ); |
255 | |
256 | if ( empty($walker) || !is_a($walker, 'Walker') ) |
257 | $walker = new Walker_Category_Checklist; |
258 | |
259 | $descendants_and_self = (int) $descendants_and_self; |
260 | |
261 | $args = array('taxonomy' => $taxonomy); |
262 | |
263 | $tax = get_taxonomy($taxonomy); |
264 | $args['disabled'] = !current_user_can($tax->cap->assign_terms); |
265 | |
266 | if ( is_array( $selected_cats ) ) |
267 | $args['selected_cats'] = $selected_cats; |
268 | elseif ( $post_id ) |
269 | $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); |
270 | else |
271 | $args['selected_cats'] = array(); |
272 | |
273 | if ( is_array( $popular_cats ) ) |
274 | $args['popular_cats'] = $popular_cats; |
275 | else |
276 | $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); |
277 | |
278 | if ( $descendants_and_self ) { |
279 | $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) ); |
280 | $self = get_term( $descendants_and_self, $taxonomy ); |
281 | array_unshift( $categories, $self ); |
282 | } else { |
283 | $categories = (array) get_terms($taxonomy, array('get' => 'all')); |
284 | } |
285 | |
286 | if ( $checked_ontop ) { |
287 | // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) |
288 | $checked_categories = array(); |
289 | $keys = array_keys( $categories ); |
290 | |
291 | foreach( $keys as $k ) { |
292 | if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { |
293 | $checked_categories[] = $categories[$k]; |
294 | unset( $categories[$k] ); |
295 | } |
296 | } |
297 | |
298 | // Put checked cats on top |
299 | echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); |
300 | } |
301 | // Then the rest of them |
302 | echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); |
303 | } |
304 | |
305 | /** |
306 | * {@internal Missing Short Description}} |
307 | * |
308 | * @since unknown |
309 | * |
310 | * @param unknown_type $taxonomy |
311 | * @param unknown_type $default |
312 | * @param unknown_type $number |
313 | * @param unknown_type $echo |
314 | * @return unknown |
315 | */ |
316 | function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { |
317 | global $post_ID; |
318 | |
319 | if ( $post_ID ) |
320 | $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids')); |
321 | else |
322 | $checked_terms = array(); |
323 | |
324 | $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); |
325 | |
326 | $tax = get_taxonomy($taxonomy); |
327 | if ( ! current_user_can($tax->cap->assign_terms) ) |
328 | $disabled = 'disabled="disabled"'; |
329 | else |
330 | $disabled = ''; |
331 | |
332 | $popular_ids = array(); |
333 | foreach ( (array) $terms as $term ) { |
334 | $popular_ids[] = $term->term_id; |
335 | if ( !$echo ) // hack for AJAX use |
336 | continue; |
337 | $id = "popular-$taxonomy-$term->term_id"; |
338 | $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; |
339 | ?> |
340 | |
341 | <li id="<?php echo $id; ?>" class="popular-category"> | //Cross Site Scripting
|
342 | <label class="selectit"> |
343 | <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/> | //Cross Site Scripting
|
344 | <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?> |
345 | </label> |
346 | </li> |
347 | |
348 | <?php |
349 | } |
350 | return $popular_ids; |
351 | } |
352 | |
353 | /** |
354 | * {@internal Missing Short Description}} |
355 | * |
356 | * @since unknown |
357 | * |
358 | * @param unknown_type $link_id |
359 | */ |
360 | function wp_link_category_checklist( $link_id = 0 ) { |
361 | $default = 1; |
362 | |
363 | if ( $link_id ) { |
364 | $checked_categories = wp_get_link_cats( $link_id ); |
365 | // No selected categories, strange |
366 | if ( ! count( $checked_categories ) ) |
367 | $checked_categories[] = $default; |
368 | } else { |
369 | $checked_categories[] = $default; |
370 | } |
371 | |
372 | $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); |
373 | |
374 | if ( empty( $categories ) ) |
375 | return; |
376 | |
377 | foreach ( $categories as $category ) { |
378 | $cat_id = $category->term_id; |
379 | $name = esc_html( apply_filters( 'the_category', $category->name ) ); |
380 | $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; |
381 | 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, '/> ', $name, "</label></li>"; |
382 | } |
383 | } |
384 | |
385 | // Tag stuff |
386 | |
387 | // Returns a single tag row (see tag_rows below) |
388 | // Note: this is also used in admin-ajax.php! |
389 | /** |
390 | * {@internal Missing Short Description}} |
391 | * |
392 | * @since unknown |
393 | * |
394 | * @param unknown_type $tag |
395 | * @param unknown_type $class |
396 | * @return unknown |
397 | */ |
398 | function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) { |
399 | global $post_type, $current_screen; |
400 | static $row_class = ''; |
401 | $row_class = ($row_class == '' ? ' class="alternate"' : ''); |
402 | |
403 | $count = number_format_i18n( $tag->count ); |
404 | $tax = get_taxonomy($taxonomy); |
405 | |
406 | if ( 'post_tag' == $taxonomy ) { |
407 | $tagsel = 'tag'; |
408 | } elseif ( 'category' == $taxonomy ) { |
409 | $tagsel = 'category_name'; |
410 | } elseif ( ! empty($tax->query_var) ) { |
411 | $tagsel = $tax->query_var; |
412 | } else { |
413 | $tagsel = $taxonomy; |
414 | } |
415 | |
416 | $pad = str_repeat( '— ', max(0, $level) ); |
417 | $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); |
418 | $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit'); |
419 | $edit_link = "edit-tags.php?action=edit&taxonomy=$taxonomy&post_type=$post_type&tag_ID=$tag->term_id"; |
420 | |
421 | $out = ''; |
422 | $out .= '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>'; |
423 | |
424 | |
425 | $columns = get_column_headers($current_screen); |
426 | $hidden = get_hidden_columns($current_screen); |
427 | $default_term = get_option('default_' . $taxonomy); |
428 | foreach ( $columns as $column_name => $column_display_name ) { |
429 | $class = "class=\"$column_name column-$column_name\""; |
430 | |
431 | $style = ''; |
432 | if ( in_array($column_name, $hidden) ) |
433 | $style = ' style="display:none;"'; |
434 | |
435 | $attributes = "$class$style"; |
436 | |
437 | switch ($column_name) { |
438 | case 'cb': |
439 | if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term ) |
440 | $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>'; |
441 | else |
442 | $out .= '<th scope="row" class="check-column"> </th>'; |
443 | break; |
444 | case 'name': |
445 | $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit “%s”'), $name)) . '">' . $name . '</a></strong><br />'; |
446 | $actions = array(); |
447 | if ( current_user_can($tax->cap->edit_terms) ) { |
448 | $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; |
449 | $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick Edit') . '</a>'; |
450 | } |
451 | if ( current_user_can($tax->cap->delete_terms) && $tag->term_id != $default_term ) |
452 | $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>"; |
453 | |
454 | $actions = apply_filters('tag_row_actions', $actions, $tag); |
455 | $actions = apply_filters("${taxonomy}_row_actions", $actions, $tag); |
456 | |
457 | $action_count = count($actions); |
458 | $i = 0; |
459 | $out .= '<div class="row-actions">'; |
460 | foreach ( $actions as $action => $link ) { |
461 | ++$i; |
462 | ( $i == $action_count ) ? $sep = '' : $sep = ' | '; |
463 | $out .= "<span class='$action'>$link$sep</span>"; |
464 | } |
465 | $out .= '</div>'; |
466 | $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; |
467 | $out .= '<div class="name">' . $qe_data->name . '</div>'; |
468 | $out .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; |
469 | $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>'; |
470 | break; |
471 | case 'description': |
472 | $out .= "<td $attributes>$tag->description</td>"; |
473 | break; |
474 | case 'slug': |
475 | $out .= "<td $attributes>" . apply_filters('editable_slug', $tag->slug) . "</td>"; |
476 | break; |
477 | case 'posts': |
478 | $attributes = 'class="posts column-posts num"' . $style; |
479 | $out .= "<td $attributes><a href='edit.php?$tagsel=$tag->slug&post_type=$post_type'>$count</a></td>"; |
480 | break; |
481 | default: |
482 | $out .= "<td $attributes>"; |
483 | $out .= apply_filters("manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id); |
484 | $out .= "</td>"; |
485 | } |
486 | } |
487 | |
488 | $out .= "</tr>\n"; |
489 | |
490 | return $out; |
491 | } |
492 | |
493 | // Outputs appropriate rows for the Nth page of the Tag Management screen, |
494 | // assuming M tags displayed at a time on the page |
495 | // Returns the number of tags displayed |
496 | /** |
497 | * {@internal Missing Short Description}} |
498 | * |
499 | * @since unknown |
500 | * |
501 | * @param unknown_type $page |
502 | * @param unknown_type $pagesize |
503 | * @param unknown_type $searchterms |
504 | * @return unknown |
505 | */ |
506 | function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'post_tag' ) { |
507 | |
508 | // Get a page worth of tags |
509 | $start = ($page - 1) * $pagesize; |
510 | |
511 | $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0); |
512 | |
513 | if ( !empty( $searchterms ) ) |
514 | $args['search'] = $searchterms; |
515 | |
516 | // convert it to table rows |
517 | $out = ''; |
518 | $count = 0; |
519 | if ( is_taxonomy_hierarchical($taxonomy) ) { |
520 | // We'll need the full set of terms then. |
521 | $args['number'] = $args['offset'] = 0; |
522 | |
523 | $terms = get_terms( $taxonomy, $args ); |
524 | if ( !empty( $searchterms ) ) // Ignore children on searches. |
525 | $children = array(); |
526 | else |
527 | $children = _get_term_hierarchy($taxonomy); |
528 | |
529 | // Some funky recursion to get the job done(Paging & parents mainly) is contained within, Skip it for non-hierarchical taxonomies for performance sake |
530 | $out .= _term_rows($taxonomy, $terms, $children, $page, $pagesize, $count); |
531 | } else { |
532 | $terms = get_terms( $taxonomy, $args ); |
533 | foreach( $terms as $term ) |
534 | $out .= _tag_row( $term, 0, $taxonomy ); |
535 | $count = $pagesize; // Only displaying a single page. |
536 | } |
537 | |
538 | echo $out; | //Cross Site Scripting
|
539 | return $count; |
540 | } |
541 | |
542 | function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0 ) { |
543 | |
544 | $start = ($page - 1) * $per_page; |
545 | $end = $start + $per_page; |
546 | |
547 | $output = ''; |
548 | foreach ( $terms as $key => $term ) { |
549 | |
550 | if ( $count >= $end ) |
551 | break; |
552 | |
553 | if ( $term->parent != $parent && empty($_GET['s']) ) |
554 | continue; |
555 | |
556 | // If the page starts in a subtree, print the parents. |
557 | if ( $count == $start && $term->parent > 0 && empty($_GET['s']) ) { |
558 | $my_parents = $parent_ids = array(); |
559 | $p = $term->parent; |
560 | while ( $p ) { |
561 | $my_parent = get_term( $p, $taxonomy ); |
562 | $my_parents[] = $my_parent; |
563 | $p = $my_parent->parent; |
564 | if ( in_array($p, $parent_ids) ) // Prevent parent loops. |
565 | break; |
566 | $parent_ids[] = $p; |
567 | } |
568 | unset($parent_ids); |
569 | |
570 | $num_parents = count($my_parents); |
571 | while ( $my_parent = array_pop($my_parents) ) { |
572 | $output .= "\t" . _tag_row( $my_parent, $level - $num_parents, $taxonomy ); |
573 | $num_parents--; |
574 | } |
575 | } |
576 | |
577 | if ( $count >= $start ) |
578 | $output .= "\t" . _tag_row( $term, $level, $taxonomy ); |
579 | |
580 | ++$count; |
581 | |
582 | unset($terms[$key]); |
583 | |
584 | if ( isset($children[$term->term_id]) && empty($_GET['s']) ) |
585 | $output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 ); |
586 | } |
587 | |
588 | return $output; |
589 | } |
590 | |
591 | // define the columns to display, the syntax is 'internal name' => 'display name' |
592 | /** |
593 | * {@internal Missing Short Description}} |
594 | * |
595 | * @since unknown |
596 | * |
597 | * @return unknown |
598 | */ |
599 | function wp_manage_posts_columns( $screen = '') { |
600 | if ( empty($screen) ) |
601 | $post_type = 'post'; |
602 | else |
603 | $post_type = $screen->post_type; |
604 | |
605 | $posts_columns = array(); |
606 | $posts_columns['cb'] = '<input type="checkbox" />'; |
607 | /* translators: manage posts column name */ |
608 | $posts_columns['title'] = _x('Title', 'column name'); |
609 | $posts_columns['author'] = __('Author'); |
610 | if ( empty($post_type) || is_object_in_taxonomy($post_type, 'category') ) |
611 | $posts_columns['categories'] = __('Categories'); |
612 | if ( empty($post_type) || is_object_in_taxonomy($post_type, 'post_tag') ) |
613 | $posts_columns['tags'] = __('Tags'); |
614 | $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all'; |
615 | if ( !in_array( $post_status, array('pending', 'draft', 'future') ) && ( empty($post_type) || post_type_supports($post_type, 'comments') ) ) |
616 | $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>'; |
617 | $posts_columns['date'] = __('Date'); |
618 | |
619 | if ( 'page' == $post_type ) |
620 | $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns ); |
621 | else |
622 | $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type ); |
623 | $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); |
624 | |
625 | return $posts_columns; |
626 | } |
627 | |
628 | // define the columns to display, the syntax is 'internal name' => 'display name' |
629 | /** |
630 | * {@internal Missing Short Description}} |
631 | * |
632 | * @since unknown |
633 | * |
634 | * @return unknown |
635 | */ |
636 | function wp_manage_media_columns() { |
637 | $posts_columns = array(); |
638 | $posts_columns['cb'] = '<input type="checkbox" />'; |
639 | $posts_columns['icon'] = ''; |
640 | /* translators: column name */ |
641 | $posts_columns['media'] = _x('File', 'column name'); |
642 | $posts_columns['author'] = __('Author'); |
643 | //$posts_columns['tags'] = _x('Tags', 'column name'); |
644 | /* translators: column name */ |
645 | $posts_columns['parent'] = _x('Attached to', 'column name'); |
646 | $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>'; |
647 | //$posts_columns['comments'] = __('Comments'); |
648 | /* translators: column name */ |
649 | $posts_columns['date'] = _x('Date', 'column name'); |
650 | $posts_columns = apply_filters('manage_media_columns', $posts_columns); |
651 | |
652 | return $posts_columns; |
653 | } |
654 | |
655 | /** |
656 | * {@internal Missing Short Description}} |
657 | * |
658 | * @since unknown |
659 | * |
660 | * @return unknown |
661 | */ |
662 | function wp_manage_pages_columns() { |
663 | return wp_manage_posts_columns(); |
664 | } |
665 | |
666 | /** |
667 | * Get the column headers for a screen |
668 | * |
669 | * @since unknown |
670 | * |
671 | * @param string|object $screen The screen you want the headers for |
672 | * @return array Containing the headers in the format id => UI String |
673 | */ |
674 | function get_column_headers($screen) { |
675 | global $_wp_column_headers; |
676 | |
677 | if ( !isset($_wp_column_headers) ) |
678 | $_wp_column_headers = array(); |
679 | |
680 | if ( is_string($screen) ) |
681 | $screen = convert_to_screen($screen); |
682 | |
683 | // Store in static to avoid running filters on each call |
684 | if ( isset($_wp_column_headers[$screen->id]) ) |
685 | return $_wp_column_headers[$screen->id]; |
686 | |
687 | switch ($screen->base) { |
688 | case 'edit': |
689 | $_wp_column_headers[$screen->id] = wp_manage_posts_columns( $screen ); |
690 | break; |
691 | case 'edit-comments': |
692 | $_wp_column_headers[$screen->id] = array( |
693 | 'cb' => '<input type="checkbox" />', |
694 | 'author' => __('Author'), |
695 | /* translators: column name */ |
696 | 'comment' => _x('Comment', 'column name'), |
697 | //'date' => __('Submitted'), |
698 | 'response' => __('In Response To') |
699 | ); |
700 | |
701 | break; |
702 | case 'link-manager': |
703 | $_wp_column_headers[$screen->id] = array( |
704 | 'cb' => '<input type="checkbox" />', |
705 | 'name' => __('Name'), |
706 | 'url' => __('URL'), |
707 | 'categories' => __('Categories'), |
708 | 'rel' => __('Relationship'), |
709 | 'visible' => __('Visible'), |
710 | 'rating' => __('Rating') |
711 | ); |
712 | |
713 | break; |
714 | case 'upload': |
715 | $_wp_column_headers[$screen->id] = wp_manage_media_columns(); |
716 | break; |
717 | case 'categories': |
718 | $_wp_column_headers[$screen->id] = array( |
719 | 'cb' => '<input type="checkbox" />', |
720 | 'name' => __('Name'), |
721 | 'description' => __('Description'), |
722 | 'slug' => __('Slug'), |
723 | 'posts' => __('Posts') |
724 | ); |
725 | |
726 | break; |
727 | case 'edit-link-categories': |
728 | $_wp_column_headers[$screen->id] = array( |
729 | 'cb' => '<input type="checkbox" />', |
730 | 'name' => __('Name'), |
731 | 'description' => __('Description'), |
732 | 'slug' => __('Slug'), |
733 | 'links' => __('Links') |
734 | ); |
735 | |
736 | break; |
737 | case 'edit-tags': |
738 | $_wp_column_headers[$screen->id] = array( |
739 | 'cb' => '<input type="checkbox" />', |
740 | 'name' => __('Name'), |
741 | 'description' => __('Description'), |
742 | 'slug' => __('Slug'), |
743 | 'posts' => __('Posts') |
744 | ); |
745 | |
746 | break; |
747 | case 'users': |
748 | $_wp_column_headers[$screen->id] = array( |
749 | 'cb' => '<input type="checkbox" />', |
750 | 'username' => __('Username'), |
751 | 'name' => __('Name'), |
752 | 'email' => __('E-mail'), |
753 | 'role' => __('Role'), |
754 | 'posts' => __('Posts') |
755 | ); |
756 | break; |
757 | default : |
758 | $_wp_column_headers[$screen->id] = array(); |
759 | } |
760 | |
761 | $_wp_column_headers[$screen->id] = apply_filters('manage_' . $screen->id . '_columns', $_wp_column_headers[$screen->id]); |
762 | return $_wp_column_headers[$screen->id]; |
763 | } |
764 | |
765 | /** |
766 | * {@internal Missing Short Description}} |
767 | * |
768 | * @since unknown |
769 | * |
770 | * @param unknown_type $screen |
771 | * @param unknown_type $id |
772 | */ |
773 | function print_column_headers( $screen, $id = true ) { |
774 | if ( is_string($screen) ) |
775 | $screen = convert_to_screen($screen); |
776 | |
777 | $columns = get_column_headers( $screen ); |
778 | $hidden = get_hidden_columns($screen); |
779 | $styles = array(); |
780 | |
781 | foreach ( $columns as $column_key => $column_display_name ) { |
782 | $class = ' class="manage-column'; |
783 | |
784 | $class .= " column-$column_key"; |
785 | |
786 | if ( 'cb' == $column_key ) |
787 | $class .= ' check-column'; |
788 | elseif ( in_array($column_key, array('posts', 'comments', 'links')) ) |
789 | $class .= ' num'; |
790 | |
791 | $class .= '"'; |
792 | |
793 | $style = ''; |
794 | if ( in_array($column_key, $hidden) ) |
795 | $style = 'display:none;'; |
796 | |
797 | if ( isset($styles[$screen->id]) && isset($styles[$screen->id][$column_key]) ) |
798 | $style .= ' ' . $styles[$screen>id][$column_key]; |
799 | $style = ' style="' . $style . '"'; |
800 | ?> |
801 | <th scope="col" <?php echo $id ? "id=\"$column_key\"" : ""; echo $class; echo $style; ?>><?php echo $column_display_name; ?></th> | //Cross Site Scripting
|
802 | <?php } |
803 | } |
804 | |
805 | /** |
806 | * Register column headers for a particular screen. The header names will be listed in the Screen Options. |
807 | * |
808 | * @since 2.7.0 |
809 | * |
810 | * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions. |
811 | * @param array $columns An array of columns with column IDs as the keys and translated column names as the values |
812 | * @see get_column_headers(), print_column_headers(), get_hidden_columns() |
813 | */ |
814 | function register_column_headers($screen, $columns) { |
815 | global $_wp_column_headers; |
816 | |
817 | if ( is_string($screen) ) |
818 | $screen = convert_to_screen($screen); |
819 | |
820 | if ( !isset($_wp_column_headers) ) |
821 | $_wp_column_headers = array(); |
822 | |
823 | $_wp_column_headers[$screen->id] = $columns; |
824 | } |
825 | |
826 | /** |
827 | * {@internal Missing Short Description}} |
828 | * |
829 | * @since unknown |
830 | * |
831 | * @param unknown_type $screen |
832 | */ |
833 | function get_hidden_columns($screen) { |
834 | if ( is_string($screen) ) |
835 | $screen = convert_to_screen($screen); |
836 | |
837 | return (array) get_user_option( 'manage' . $screen->id. 'columnshidden' ); |
838 | } |
839 | |
840 | /** |
841 | * {@internal Missing Short Description}} |
842 | * |
843 | * Outputs the quick edit and bulk edit table rows for posts and pages |
844 | * |
845 | * @since 2.7 |
846 | * |
847 | * @param string $screen |
848 | */ |
849 | function inline_edit_row( $screen ) { |
850 | global $mode; |
851 | |
852 | if ( is_string($screen) ) { |
853 | $screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen ); |
854 | $screen = (object) $screen; |
855 | } |
856 | |
857 | $post = get_default_post_to_edit( $screen->post_type ); |
858 | $post_type_object = get_post_type_object( $screen->post_type ); |
859 | |
860 | $taxonomy_names = get_object_taxonomies( $screen->post_type ); |
861 | $hierarchical_taxonomies = array(); |
862 | $flat_taxonomies = array(); |
863 | foreach ( $taxonomy_names as $taxonomy_name ) { |
864 | $taxonomy = get_taxonomy( $taxonomy_name); |
865 | |
866 | if ( !$taxonomy->show_ui ) |
867 | continue; |
868 | |
869 | if ( $taxonomy->hierarchical ) |
870 | $hierarchical_taxonomies[] = $taxonomy; |
871 | else |
872 | $flat_taxonomies[] = $taxonomy; |
873 | } |
874 | |
875 | $columns = wp_manage_posts_columns($screen); |
876 | $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) ); |
877 | $col_count = count($columns) - count($hidden); |
878 | $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list'; |
879 | $can_publish = current_user_can($post_type_object->cap->publish_posts); |
880 | $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true ); |
881 | |
882 | ?> |
883 | |
884 | <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> |
885 | <?php |
886 | $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page'; |
887 | $bulk = 0; |
888 | while ( $bulk < 2 ) { ?> |
889 | |
890 | <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type "; | //Cross Site Scripting
|
891 | echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type"; | //Cross Site Scripting
|
892 | ?>" style="display: none"><td colspan="<?php echo $col_count; ?>"> | //Cross Site Scripting
|
893 | |
894 | <fieldset class="inline-edit-col-left"><div class="inline-edit-col"> |
895 | <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4> | //Cross Site Scripting
|
896 | |
897 | |
898 | <?php |
899 | |
900 | if ( post_type_supports( $screen->post_type, 'title' ) ) : |
901 | if ( $bulk ) : ?> |
902 | <div id="bulk-title-div"> |
903 | <div id="bulk-titles"></div> |
904 | </div> |
905 | |
906 | <?php else : // $bulk ?> |
907 | |
908 | <label> |
909 | <span class="title"><?php _e( 'Title' ); ?></span> |
910 | <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> |
911 | </label> |
912 | |
913 | <label> |
914 | <span class="title"><?php _e( 'Slug' ); ?></span> |
915 | <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span> |
916 | </label> |
917 | |
918 | <?php endif; // $bulk |
919 | endif; // post_type_supports title ?> |
920 | |
921 | <?php if ( !$bulk ) : ?> |
922 | <label><span class="title"><?php _e( 'Date' ); ?></span></label> |
923 | <div class="inline-edit-date"> |
924 | <?php touch_time(1, 1, 4, 1); ?> |
925 | </div> |
926 | <br class="clear" /> |
927 | |
928 | <?php endif; // $bulk |
929 | |
930 | if ( post_type_supports( $screen->post_type, 'author' ) ) : |
931 | $authors = get_editable_user_ids( get_current_user_id(), true, $screen->post_type ); // TODO: ROLE SYSTEM |
932 | $authors_dropdown = ''; |
933 | if ( $authors && count( $authors ) > 1 ) : |
934 | $users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0); | //Arbitrary code inclusion
|
935 | if ( $bulk ) |
936 | $users_opt['show_option_none'] = __('— No Change —'); |
937 | $authors_dropdown = '<label>'; |
938 | $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>'; |
939 | $authors_dropdown .= wp_dropdown_users( $users_opt ); |
940 | $authors_dropdown .= '</label>'; |
941 | |
942 | endif; // authors |
943 | ?> |
944 | |
945 | <?php if ( !$bulk ) echo $authors_dropdown; | //Cross Site Scripting
|
946 | endif; // post_type_supports author |
947 | |
948 | if ( !$bulk ) : |
949 | ?> |
950 | |
951 | <div class="inline-edit-group"> |
952 | <label class="alignleft"> |
953 | <span class="title"><?php _e( 'Password' ); ?></span> |
954 | <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span> |
955 | </label> |
956 | |
957 | <em style="margin:5px 10px 0 0" class="alignleft"> |
958 | <?php |
959 | /* translators: Between password field and private checkbox on post quick edit interface */ |
960 | echo __( '–OR–' ); |
961 | ?> |
962 | </em> |
963 | <label class="alignleft inline-edit-private"> |
964 | <input type="checkbox" name="keep_private" value="private" /> |
965 | <span class="checkbox-title"><?php echo __('Private'); ?></span> |
966 | </label> |
967 | </div> |
968 | |
969 | <?php endif; ?> |
970 | |
971 | </div></fieldset> |
972 | |
973 | <?php if ( count($hierarchical_taxonomies) && !$bulk ) : ?> |
974 | |
975 | <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col"> |
976 | |
977 | <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?> |
978 | |
979 | <span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->labels->name) ?> |
980 | <span class="catshow"><?php _e('[more]'); ?></span> |
981 | <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span> |
982 | </span> |
983 | <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr($taxonomy->name) . '][]'; ?>" value="0" /> | //Cross Site Scripting
|
984 | <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist"> |
985 | <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?> |
986 | </ul> |
987 | |
988 | <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?> |
989 | |
990 | </div></fieldset> |
991 | |
992 | <?php endif; // count($hierarchical_taxonomies) && !$bulk ?> |
993 | |
994 | <fieldset class="inline-edit-col-right"><div class="inline-edit-col"> |
995 | |
996 | <?php |
997 | if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) |
998 | echo $authors_dropdown; | //Cross Site Scripting
|
999 | ?> |
1000 | |