PageRenderTime 80ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/msw/dev/wp-admin/includes/template.php

https://github.com/chrissiebrodigan/USC
PHP | 3941 lines | 2725 code | 511 blank | 705 comment | 604 complexity | 6ace5a2cffbf414241be68d8e3af7a25 MD5 | raw file
  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. * {@internal Missing Short Description}}
  12. *
  13. * @since 2.7
  14. *
  15. * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit.
  16. *
  17. * @param string $type "edit-tags", "categoried" or "edit-link-categories"
  18. * @param string $taxonomy The taxonomy of the row.
  19. * @return
  20. */
  21. function inline_edit_term_row($type, $taxonomy) {
  22. $tax = get_taxonomy($taxonomy);
  23. if ( ! current_user_can( $tax->edit_cap ) )
  24. return;
  25. $columns = get_column_headers($type);
  26. $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) );
  27. $col_count = count($columns) - count($hidden);
  28. ?>
  29. <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  30. <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>">
  31. <fieldset><div class="inline-edit-col">
  32. <h4><?php _e( 'Quick Edit' ); ?></h4>
  33. <label>
  34. <span class="title"><?php _e( 'Name' ); ?></span>
  35. <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
  36. </label>
  37. <?php if ( !is_multisite() ) { ?>
  38. <label>
  39. <span class="title"><?php _e( 'Slug' ); ?></span>
  40. <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
  41. </label>
  42. <?php } ?>
  43. </div></fieldset>
  44. <?php
  45. $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
  46. foreach ( $columns as $column_name => $column_display_name ) {
  47. if ( isset( $core_columns[$column_name] ) )
  48. continue;
  49. do_action( 'quick_edit_custom_box', $column_name, $type, $taxonomy );
  50. }
  51. ?>
  52. <p class="inline-edit-save submit">
  53. <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
  54. <?php $update_text = sprintf( __('Update %s'), $tax->singular_label ); ?>
  55. <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
  56. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  57. <span class="error" style="display:none;"></span>
  58. <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
  59. <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
  60. <br class="clear" />
  61. </p>
  62. </td></tr>
  63. </tbody></table></form>
  64. <?php
  65. }
  66. /**
  67. * {@internal Missing Short Description}}
  68. *
  69. * @since unknown
  70. *
  71. * @param unknown_type $category
  72. * @param unknown_type $name_override
  73. * @return unknown
  74. */
  75. function link_cat_row( $category, $name_override = false ) {
  76. static $row_class = '';
  77. if ( !$category = get_term( $category, 'link_category', OBJECT, 'display' ) )
  78. return false;
  79. if ( is_wp_error( $category ) )
  80. return $category;
  81. $default_cat_id = (int) get_option( 'default_link_category' );
  82. $name = ( $name_override ? $name_override : $category->name );
  83. $edit_link = "link-category.php?action=edit&amp;cat_ID=$category->term_id";
  84. if ( current_user_can( 'manage_categories' ) ) {
  85. $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $category->name)) . "'>$name</a><br />";
  86. $actions = array();
  87. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  88. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  89. if ( $default_cat_id != $category->term_id )
  90. $actions['delete'] = "<a class='delete:the-list:link-cat-$category->term_id submitdelete' href='" . wp_nonce_url("link-category.php?action=delete&amp;cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id) . "'>" . __('Delete') . "</a>";
  91. $actions = apply_filters('link_cat_row_actions', $actions, $category);
  92. $action_count = count($actions);
  93. $i = 0;
  94. $edit .= '<div class="row-actions">';
  95. foreach ( $actions as $action => $link ) {
  96. ++$i;
  97. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  98. $edit .= "<span class='$action'>$link$sep</span>";
  99. }
  100. $edit .= '</div>';
  101. } else {
  102. $edit = $name;
  103. }
  104. $row_class = 'alternate' == $row_class ? '' : 'alternate';
  105. $qe_data = get_term_to_edit($category->term_id, 'link_category');
  106. $category->count = number_format_i18n( $category->count );
  107. $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
  108. $output = "<tr id='link-cat-$category->term_id' class='iedit $row_class'>";
  109. $columns = get_column_headers('edit-link-categories');
  110. $hidden = get_hidden_columns('edit-link-categories');
  111. foreach ( $columns as $column_name => $column_display_name ) {
  112. $class = "class=\"$column_name column-$column_name\"";
  113. $style = '';
  114. if ( in_array($column_name, $hidden) )
  115. $style = ' style="display:none;"';
  116. $attributes = "$class$style";
  117. switch ($column_name) {
  118. case 'cb':
  119. $output .= "<th scope='row' class='check-column'>";
  120. if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) {
  121. $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
  122. } else {
  123. $output .= "&nbsp;";
  124. }
  125. $output .= "</th>";
  126. break;
  127. case 'name':
  128. $output .= "<td $attributes>$edit";
  129. $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  130. $output .= '<div class="name">' . $qe_data->name . '</div>';
  131. $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
  132. $output .= '<div class="cat_parent">' . $qe_data->parent . '</div></div></td>';
  133. break;
  134. case 'description':
  135. $output .= "<td $attributes>$category->description</td>";
  136. break;
  137. case 'slug':
  138. $output .= "<td $attributes>" . apply_filters('editable_slug', $category->slug) . "</td>";
  139. break;
  140. case 'links':
  141. $attributes = 'class="links column-links num"' . $style;
  142. $output .= "<td $attributes>$count</td>";
  143. break;
  144. default:
  145. $output .= "<td $attributes>";
  146. $output .= apply_filters('manage_link_categories_custom_column', '', $column_name, $category->term_id);
  147. $output .= "</td>";
  148. }
  149. }
  150. $output .= '</tr>';
  151. return $output;
  152. }
  153. //
  154. // Category Checklists
  155. //
  156. /**
  157. * {@internal Missing Short Description}}
  158. *
  159. * @since unknown
  160. */
  161. class Walker_Category_Checklist extends Walker {
  162. var $tree_type = 'category';
  163. var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  164. function start_lvl(&$output, $depth, $args) {
  165. $indent = str_repeat("\t", $depth);
  166. $output .= "$indent<ul class='children'>\n";
  167. }
  168. function end_lvl(&$output, $depth, $args) {
  169. $indent = str_repeat("\t", $depth);
  170. $output .= "$indent</ul>\n";
  171. }
  172. function start_el(&$output, $category, $depth, $args) {
  173. extract($args);
  174. if ( empty($taxonomy) )
  175. $taxonomy = 'category';
  176. if ( $taxonomy == 'category' )
  177. $name = 'post_category';
  178. else
  179. $name = 'tax_input['.$taxonomy.']';
  180. $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
  181. $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>';
  182. }
  183. function end_el(&$output, $category, $depth, $args) {
  184. $output .= "</li>\n";
  185. }
  186. }
  187. /**
  188. * {@internal Missing Short Description}}
  189. *
  190. * @since unknown
  191. *
  192. * @param unknown_type $post_id
  193. * @param unknown_type $descendants_and_self
  194. * @param unknown_type $selected_cats
  195. * @param unknown_type $popular_cats
  196. */
  197. function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
  198. wp_terms_checklist($post_id,
  199. array(
  200. 'taxonomy' => 'category',
  201. 'descendants_and_self' => $descendants_and_self,
  202. 'selected_cats' => $selected_cats,
  203. 'popular_cats' => $popular_cats,
  204. 'walker' => $walker,
  205. 'checked_ontop' => $checked_ontop
  206. ));
  207. }
  208. /**
  209. * Taxonomy independent version of wp_category_checklist
  210. *
  211. * @param int $post_id
  212. * @param array $args
  213. */
  214. function wp_terms_checklist($post_id = 0, $args = array()) {
  215. $defaults = array(
  216. 'descendants_and_self' => 0,
  217. 'selected_cats' => false,
  218. 'popular_cats' => false,
  219. 'walker' => null,
  220. 'taxonomy' => 'category',
  221. 'checked_ontop' => true
  222. );
  223. extract( wp_parse_args($args, $defaults), EXTR_SKIP );
  224. if ( empty($walker) || !is_a($walker, 'Walker') )
  225. $walker = new Walker_Category_Checklist;
  226. $descendants_and_self = (int) $descendants_and_self;
  227. $args = array('taxonomy' => $taxonomy);
  228. $tax = get_taxonomy($taxonomy);
  229. $args['disabled'] = !current_user_can($tax->assign_cap);
  230. if ( is_array( $selected_cats ) )
  231. $args['selected_cats'] = $selected_cats;
  232. elseif ( $post_id )
  233. $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
  234. else
  235. $args['selected_cats'] = array();
  236. if ( is_array( $popular_cats ) )
  237. $args['popular_cats'] = $popular_cats;
  238. else
  239. $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  240. if ( $descendants_and_self ) {
  241. $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
  242. $self = get_term( $descendants_and_self, $taxonomy );
  243. array_unshift( $categories, $self );
  244. } else {
  245. $categories = (array) get_terms($taxonomy, array('get' => 'all'));
  246. }
  247. if ( $checked_ontop ) {
  248. // 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)
  249. $checked_categories = array();
  250. $keys = array_keys( $categories );
  251. foreach( $keys as $k ) {
  252. if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {
  253. $checked_categories[] = $categories[$k];
  254. unset( $categories[$k] );
  255. }
  256. }
  257. // Put checked cats on top
  258. echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
  259. }
  260. // Then the rest of them
  261. echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
  262. }
  263. /**
  264. * {@internal Missing Short Description}}
  265. *
  266. * @since unknown
  267. *
  268. * @param unknown_type $taxonomy
  269. * @param unknown_type $default
  270. * @param unknown_type $number
  271. * @param unknown_type $echo
  272. * @return unknown
  273. */
  274. function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
  275. global $post_ID;
  276. if ( $post_ID )
  277. $checked_terms = wp_get_object_terms($post_ID, $taxonomy, array('fields'=>'ids'));
  278. else
  279. $checked_terms = array();
  280. $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
  281. $tax = get_taxonomy($taxonomy);
  282. if ( ! current_user_can($tax->assign_cap) )
  283. $disabled = 'disabled="disabled"';
  284. else
  285. $disabled = '';
  286. $popular_ids = array();
  287. foreach ( (array) $terms as $term ) {
  288. $popular_ids[] = $term->term_id;
  289. if ( !$echo ) // hack for AJAX use
  290. continue;
  291. $id = "popular-$taxonomy-$term->term_id";
  292. $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
  293. ?>
  294. <li id="<?php echo $id; ?>" class="popular-category">
  295. <label class="selectit">
  296. <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php echo $disabled ?>/>
  297. <?php echo esc_html( apply_filters( 'the_category', $term->name ) ); ?>
  298. </label>
  299. </li>
  300. <?php
  301. }
  302. return $popular_ids;
  303. }
  304. /**
  305. * {@internal Missing Short Description}}
  306. *
  307. * @since unknown
  308. *
  309. * @param unknown_type $link_id
  310. */
  311. function wp_link_category_checklist( $link_id = 0 ) {
  312. $default = 1;
  313. if ( $link_id ) {
  314. $checked_categories = wp_get_link_cats( $link_id );
  315. // No selected categories, strange
  316. if ( ! count( $checked_categories ) )
  317. $checked_categories[] = $default;
  318. } else {
  319. $checked_categories[] = $default;
  320. }
  321. $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
  322. if ( empty( $categories ) )
  323. return;
  324. foreach ( $categories as $category ) {
  325. $cat_id = $category->term_id;
  326. $name = esc_html( apply_filters( 'the_category', $category->name ) );
  327. $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
  328. 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>";
  329. }
  330. }
  331. // Tag stuff
  332. // Returns a single tag row (see tag_rows below)
  333. // Note: this is also used in admin-ajax.php!
  334. /**
  335. * {@internal Missing Short Description}}
  336. *
  337. * @since unknown
  338. *
  339. * @param unknown_type $tag
  340. * @param unknown_type $class
  341. * @return unknown
  342. */
  343. function _tag_row( $tag, $level, $taxonomy = 'post_tag' ) {
  344. global $post_type;
  345. static $row_class = '';
  346. $row_class = ($row_class == '' ? ' class="alternate"' : '');
  347. $count = number_format_i18n( $tag->count );
  348. $tax = get_taxonomy($taxonomy);
  349. if ( 'post_tag' == $taxonomy ) {
  350. $tagsel = 'tag';
  351. } elseif ( 'category' == $taxonomy ) {
  352. $tagsel = 'category_name';
  353. } elseif ( ! empty($tax->query_var) ) {
  354. $tagsel = $tax->query_var;
  355. } else {
  356. $tagsel = $taxonomy;
  357. }
  358. $pad = str_repeat( '&#8212; ', max(0, $level) );
  359. $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
  360. $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit');
  361. $edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;post_type=$post_type&amp;tag_ID=$tag->term_id";
  362. $out = '';
  363. $out .= '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
  364. $columns = get_column_headers('edit-tags');
  365. $hidden = get_hidden_columns('edit-tags');
  366. $default_term = get_option('default_' . $taxonomy);
  367. foreach ( $columns as $column_name => $column_display_name ) {
  368. $class = "class=\"$column_name column-$column_name\"";
  369. $style = '';
  370. if ( in_array($column_name, $hidden) )
  371. $style = ' style="display:none;"';
  372. $attributes = "$class$style";
  373. switch ($column_name) {
  374. case 'cb':
  375. if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
  376. $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
  377. else
  378. $out .= '<th scope="row" class="check-column">&nbsp;</th>';
  379. break;
  380. case 'name':
  381. $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $name)) . '">' . $name . '</a></strong><br />';
  382. $actions = array();
  383. if ( current_user_can($tax->edit_cap) ) {
  384. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  385. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  386. }
  387. if ( current_user_can($tax->delete_cap) && $tag->term_id != $default_term )
  388. $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>";
  389. $actions = apply_filters('tag_row_actions', $actions, $tag);
  390. $actions = apply_filters("${taxonomy}_row_actions", $actions, $tag);
  391. $action_count = count($actions);
  392. $i = 0;
  393. $out .= '<div class="row-actions">';
  394. foreach ( $actions as $action => $link ) {
  395. ++$i;
  396. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  397. $out .= "<span class='$action'>$link$sep</span>";
  398. }
  399. $out .= '</div>';
  400. $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  401. $out .= '<div class="name">' . $qe_data->name . '</div>';
  402. $out .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
  403. $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
  404. break;
  405. case 'description':
  406. $out .= "<td $attributes>$tag->description</td>";
  407. break;
  408. case 'slug':
  409. $out .= "<td $attributes>" . apply_filters('editable_slug', $tag->slug) . "</td>";
  410. break;
  411. case 'posts':
  412. $attributes = 'class="posts column-posts num"' . $style;
  413. $out .= "<td $attributes><a href='edit.php?$tagsel=$tag->slug&amp;post_type=$post_type'>$count</a></td>";
  414. break;
  415. default:
  416. $out .= "<td $attributes>";
  417. $out .= apply_filters("manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id);
  418. $out .= "</td>";
  419. }
  420. }
  421. $out .= "</tr>\n";
  422. return $out;
  423. }
  424. // Outputs appropriate rows for the Nth page of the Tag Management screen,
  425. // assuming M tags displayed at a time on the page
  426. // Returns the number of tags displayed
  427. /**
  428. * {@internal Missing Short Description}}
  429. *
  430. * @since unknown
  431. *
  432. * @param unknown_type $page
  433. * @param unknown_type $pagesize
  434. * @param unknown_type $searchterms
  435. * @return unknown
  436. */
  437. function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'post_tag' ) {
  438. // Get a page worth of tags
  439. $start = ($page - 1) * $pagesize;
  440. $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
  441. if ( !empty( $searchterms ) )
  442. $args['search'] = $searchterms;
  443. // convert it to table rows
  444. $out = '';
  445. $count = 0;
  446. if ( is_taxonomy_hierarchical($taxonomy) ) {
  447. // We'll need the full set of terms then.
  448. $args['number'] = $args['offset'] = 0;
  449. $terms = get_terms( $taxonomy, $args );
  450. if ( !empty( $searchterms ) ) // Ignore children on searches.
  451. $children = array();
  452. else
  453. $children = _get_term_hierarchy($taxonomy);
  454. // Some funky recursion to get the job done(Paging & parents mainly) is contained within, Skip it for non-hierarchical taxonomies for performance sake
  455. $out .= _term_rows($taxonomy, $terms, $children, $page, $pagesize, $count);
  456. } else {
  457. $terms = get_terms( $taxonomy, $args );
  458. foreach( $terms as $term )
  459. $out .= _tag_row( $term, 0, $taxonomy );
  460. $count = $pagesize; // Only displaying a single page.
  461. }
  462. echo $out;
  463. return $count;
  464. }
  465. function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
  466. $start = ($page - 1) * $per_page;
  467. $end = $start + $per_page;
  468. $output = '';
  469. foreach ( $terms as $key => $term ) {
  470. if ( $count >= $end )
  471. break;
  472. if ( $term->parent != $parent && empty($_GET['s']) )
  473. continue;
  474. // If the page starts in a subtree, print the parents.
  475. if ( $count == $start && $term->parent > 0 && empty($_GET['s']) ) {
  476. $my_parents = $parent_ids = array();
  477. $p = $term->parent;
  478. while ( $p ) {
  479. $my_parent = get_term( $p, $taxonomy );
  480. $my_parents[] = $my_parent;
  481. $p = $my_parent->parent;
  482. if ( in_array($p, $parent_ids) ) // Prevent parent loops.
  483. break;
  484. $parent_ids[] = $p;
  485. }
  486. unset($parent_ids);
  487. $num_parents = count($my_parents);
  488. while ( $my_parent = array_pop($my_parents) ) {
  489. $output .= "\t" . _tag_row( $my_parent, $level - $num_parents, $taxonomy );
  490. $num_parents--;
  491. }
  492. }
  493. if ( $count >= $start )
  494. $output .= "\t" . _tag_row( $term, $level, $taxonomy );
  495. ++$count;
  496. unset($terms[$key]);
  497. if ( isset($children[$term->term_id]) && empty($_GET['s']) )
  498. $output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 );
  499. }
  500. return $output;
  501. }
  502. // define the columns to display, the syntax is 'internal name' => 'display name'
  503. /**
  504. * {@internal Missing Short Description}}
  505. *
  506. * @since unknown
  507. *
  508. * @return unknown
  509. */
  510. function wp_manage_posts_columns( $screen = '') {
  511. if ( empty($screen) )
  512. $post_type = 'post';
  513. else
  514. $post_type = $screen->post_type;
  515. $posts_columns = array();
  516. $posts_columns['cb'] = '<input type="checkbox" />';
  517. /* translators: manage posts column name */
  518. $posts_columns['title'] = _x('Title', 'column name');
  519. $posts_columns['author'] = __('Author');
  520. if ( empty($post_type) || is_object_in_taxonomy($post_type, 'category') )
  521. $posts_columns['categories'] = __('Categories');
  522. if ( empty($post_type) || is_object_in_taxonomy($post_type, 'post_tag') )
  523. $posts_columns['tags'] = __('Tags');
  524. $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all';
  525. if ( !in_array( $post_status, array('pending', 'draft', 'future') ) && ( empty($post_type) || post_type_supports($post_type, 'comments') ) )
  526. $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
  527. $posts_columns['date'] = __('Date');
  528. if ( 'page' == $post_type )
  529. $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
  530. else
  531. $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
  532. $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
  533. return $posts_columns;
  534. }
  535. // define the columns to display, the syntax is 'internal name' => 'display name'
  536. /**
  537. * {@internal Missing Short Description}}
  538. *
  539. * @since unknown
  540. *
  541. * @return unknown
  542. */
  543. function wp_manage_media_columns() {
  544. $posts_columns = array();
  545. $posts_columns['cb'] = '<input type="checkbox" />';
  546. $posts_columns['icon'] = '';
  547. /* translators: column name */
  548. $posts_columns['media'] = _x('File', 'column name');
  549. $posts_columns['author'] = __('Author');
  550. //$posts_columns['tags'] = _x('Tags', 'column name');
  551. /* translators: column name */
  552. $posts_columns['parent'] = _x('Attached to', 'column name');
  553. $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></div>';
  554. //$posts_columns['comments'] = __('Comments');
  555. /* translators: column name */
  556. $posts_columns['date'] = _x('Date', 'column name');
  557. $posts_columns = apply_filters('manage_media_columns', $posts_columns);
  558. return $posts_columns;
  559. }
  560. /**
  561. * {@internal Missing Short Description}}
  562. *
  563. * @since unknown
  564. *
  565. * @return unknown
  566. */
  567. function wp_manage_pages_columns() {
  568. return wp_manage_posts_columns();
  569. }
  570. /**
  571. * {@internal Missing Short Description}}
  572. *
  573. * @since unknown
  574. *
  575. * @param unknown_type $screen
  576. * @return unknown
  577. */
  578. function get_column_headers($screen) {
  579. global $_wp_column_headers;
  580. if ( !isset($_wp_column_headers) )
  581. $_wp_column_headers = array();
  582. if ( is_string($screen) )
  583. $screen = convert_to_screen($screen);
  584. // Store in static to avoid running filters on each call
  585. if ( isset($_wp_column_headers[$screen->id]) )
  586. return $_wp_column_headers[$screen->id];
  587. switch ($screen->base) {
  588. case 'edit':
  589. $_wp_column_headers[$screen->id] = wp_manage_posts_columns( $screen );
  590. break;
  591. case 'edit-comments':
  592. $_wp_column_headers[$screen->id] = array(
  593. 'cb' => '<input type="checkbox" />',
  594. 'author' => __('Author'),
  595. /* translators: column name */
  596. 'comment' => _x('Comment', 'column name'),
  597. //'date' => __('Submitted'),
  598. 'response' => __('In Response To')
  599. );
  600. break;
  601. case 'link-manager':
  602. $_wp_column_headers[$screen->id] = array(
  603. 'cb' => '<input type="checkbox" />',
  604. 'name' => __('Name'),
  605. 'url' => __('URL'),
  606. 'categories' => __('Categories'),
  607. 'rel' => __('Relationship'),
  608. 'visible' => __('Visible'),
  609. 'rating' => __('Rating')
  610. );
  611. break;
  612. case 'upload':
  613. $_wp_column_headers[$screen->id] = wp_manage_media_columns();
  614. break;
  615. case 'categories':
  616. $_wp_column_headers[$screen->id] = array(
  617. 'cb' => '<input type="checkbox" />',
  618. 'name' => __('Name'),
  619. 'description' => __('Description'),
  620. 'slug' => __('Slug'),
  621. 'posts' => __('Posts')
  622. );
  623. break;
  624. case 'edit-link-categories':
  625. $_wp_column_headers[$screen->id] = array(
  626. 'cb' => '<input type="checkbox" />',
  627. 'name' => __('Name'),
  628. 'description' => __('Description'),
  629. 'slug' => __('Slug'),
  630. 'links' => __('Links')
  631. );
  632. break;
  633. case 'edit-tags':
  634. $_wp_column_headers[$screen->id] = array(
  635. 'cb' => '<input type="checkbox" />',
  636. 'name' => __('Name'),
  637. 'description' => __('Description'),
  638. 'slug' => __('Slug'),
  639. 'posts' => __('Posts')
  640. );
  641. break;
  642. case 'users':
  643. $_wp_column_headers[$screen->id] = array(
  644. 'cb' => '<input type="checkbox" />',
  645. 'username' => __('Username'),
  646. 'name' => __('Name'),
  647. 'email' => __('E-mail'),
  648. 'role' => __('Role'),
  649. 'posts' => __('Posts')
  650. );
  651. break;
  652. default :
  653. $_wp_column_headers[$screen->id] = array();
  654. }
  655. $_wp_column_headers[$screen->id] = apply_filters('manage_' . $screen->id . '_columns', $_wp_column_headers[$screen->id]);
  656. return $_wp_column_headers[$screen->id];
  657. }
  658. /**
  659. * {@internal Missing Short Description}}
  660. *
  661. * @since unknown
  662. *
  663. * @param unknown_type $screen
  664. * @param unknown_type $id
  665. */
  666. function print_column_headers( $screen, $id = true ) {
  667. if ( is_string($screen) )
  668. $screen = convert_to_screen($screen);
  669. $columns = get_column_headers( $screen );
  670. $hidden = get_hidden_columns($screen);
  671. $styles = array();
  672. foreach ( $columns as $column_key => $column_display_name ) {
  673. $class = ' class="manage-column';
  674. $class .= " column-$column_key";
  675. if ( 'cb' == $column_key )
  676. $class .= ' check-column';
  677. elseif ( in_array($column_key, array('posts', 'comments', 'links')) )
  678. $class .= ' num';
  679. $class .= '"';
  680. $style = '';
  681. if ( in_array($column_key, $hidden) )
  682. $style = 'display:none;';
  683. if ( isset($styles[$screen->id]) && isset($styles[$screen->id][$column_key]) )
  684. $style .= ' ' . $styles[$screen>id][$column_key];
  685. $style = ' style="' . $style . '"';
  686. ?>
  687. <th scope="col" <?php echo $id ? "id=\"$column_key\"" : ""; echo $class; echo $style; ?>><?php echo $column_display_name; ?></th>
  688. <?php }
  689. }
  690. /**
  691. * Register column headers for a particular screen. The header names will be listed in the Screen Options.
  692. *
  693. * @since 2.7.0
  694. *
  695. * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  696. * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
  697. * @see get_column_headers(), print_column_headers(), get_hidden_columns()
  698. */
  699. function register_column_headers($screen, $columns) {
  700. global $_wp_column_headers;
  701. if ( is_string($screen) )
  702. $screen = convert_to_screen($screen);
  703. if ( !isset($_wp_column_headers) )
  704. $_wp_column_headers = array();
  705. $_wp_column_headers[$screen->id] = $columns;
  706. }
  707. /**
  708. * {@internal Missing Short Description}}
  709. *
  710. * @since unknown
  711. *
  712. * @param unknown_type $screen
  713. */
  714. function get_hidden_columns($screen) {
  715. if ( is_string($screen) )
  716. $screen = convert_to_screen($screen);
  717. return (array) get_user_option( 'manage' . $screen->id. 'columnshidden' );
  718. }
  719. /**
  720. * {@internal Missing Short Description}}
  721. *
  722. * Outputs the quick edit and bulk edit table rows for posts and pages
  723. *
  724. * @since 2.7
  725. *
  726. * @param string $screen
  727. */
  728. function inline_edit_row( $screen ) {
  729. global $current_user, $mode;
  730. if ( is_string($screen) ) {
  731. $screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen );
  732. $screen = (object) $screen;
  733. }
  734. $post = get_default_post_to_edit( $screen->post_type );
  735. $post_type_object = get_post_type_object( $screen->post_type );
  736. $taxonomy_names = get_object_taxonomies( $screen->post_type );
  737. $hierarchical_taxonomies = array();
  738. $flat_taxonomies = array();
  739. foreach ( $taxonomy_names as $taxonomy_name ) {
  740. $taxonomy = get_taxonomy( $taxonomy_name);
  741. if ( !$taxonomy->show_ui )
  742. continue;
  743. if ( $taxonomy->hierarchical )
  744. $hierarchical_taxonomies[] = $taxonomy;
  745. else
  746. $flat_taxonomies[] = $taxonomy;
  747. }
  748. $columns = wp_manage_posts_columns($screen);
  749. $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) );
  750. $col_count = count($columns) - count($hidden);
  751. $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
  752. $can_publish = current_user_can($post_type_object->publish_cap);
  753. $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
  754. ?>
  755. <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  756. <?php
  757. $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
  758. $bulk = 0;
  759. while ( $bulk < 2 ) { ?>
  760. <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
  761. 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";
  762. ?>" style="display: none"><td colspan="<?php echo $col_count; ?>">
  763. <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
  764. <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
  765. <?php
  766. if ( post_type_supports( $screen->post_type, 'title' ) ) :
  767. if ( $bulk ) : ?>
  768. <div id="bulk-title-div">
  769. <div id="bulk-titles"></div>
  770. </div>
  771. <?php else : // $bulk ?>
  772. <label>
  773. <span class="title"><?php _e( 'Title' ); ?></span>
  774. <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
  775. </label>
  776. <label>
  777. <span class="title"><?php _e( 'Slug' ); ?></span>
  778. <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
  779. </label>
  780. <?php endif; // $bulk
  781. endif; // post_type_supports title ?>
  782. <?php if ( !$bulk ) : ?>
  783. <label><span class="title"><?php _e( 'Date' ); ?></span></label>
  784. <div class="inline-edit-date">
  785. <?php touch_time(1, 1, 4, 1); ?>
  786. </div>
  787. <br class="clear" />
  788. <?php endif; // $bulk
  789. if ( post_type_supports( $screen->post_type, 'author' ) ) :
  790. $authors = get_editable_user_ids( $current_user->id, true, $screen->post_type ); // TODO: ROLE SYSTEM
  791. $authors_dropdown = '';
  792. if ( $authors && count( $authors ) > 1 ) :
  793. $users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0);
  794. if ( $bulk )
  795. $users_opt['show_option_none'] = __('&mdash; No Change &mdash;');
  796. $authors_dropdown = '<label>';
  797. $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
  798. $authors_dropdown .= wp_dropdown_users( $users_opt );
  799. $authors_dropdown .= '</label>';
  800. endif; // authors
  801. ?>
  802. <?php if ( !$bulk ) echo $authors_dropdown;
  803. endif; // post_type_supports author
  804. if ( !$bulk ) :
  805. ?>
  806. <div class="inline-edit-group">
  807. <label class="alignleft">
  808. <span class="title"><?php _e( 'Password' ); ?></span>
  809. <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
  810. </label>
  811. <em style="margin:5px 10px 0 0" class="alignleft">
  812. <?php
  813. /* translators: Between password field and private checkbox on post quick edit interface */
  814. echo __( '&ndash;OR&ndash;' );
  815. ?>
  816. </em>
  817. <label class="alignleft inline-edit-private">
  818. <input type="checkbox" name="keep_private" value="private" />
  819. <span class="checkbox-title"><?php echo __('Private'); ?></span>
  820. </label>
  821. </div>
  822. <?php endif; ?>
  823. </div></fieldset>
  824. <?php if ( count($hierarchical_taxonomies) && !$bulk ) : ?>
  825. <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
  826. <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
  827. <span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->label) ?>
  828. <span class="catshow"><?php _e('[more]'); ?></span>
  829. <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span>
  830. </span>
  831. <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist">
  832. <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?>
  833. </ul>
  834. <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
  835. </div></fieldset>
  836. <?php endif; // count($hierarchical_taxonomies) && !$bulk ?>
  837. <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
  838. <?php
  839. if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
  840. echo $authors_dropdown;
  841. ?>
  842. <?php if ( $post_type_object->hierarchical ) : ?>
  843. <label>
  844. <span class="title"><?php _e( 'Parent' ); ?></span>
  845. <?php
  846. $dropdown_args = array('post_type' => $post_type_object->name, 'selected' => $post->post_parent, 'name' => 'post_parent', 'show_option_none' => __('Main Page (no parent)'), 'option_none_value' => 0, 'sort_column'=> 'menu_order, post_title');
  847. if ( $bulk )
  848. $dropdown_args['show_option_no_change'] = __('&mdash; No Change &mdash;');
  849. $dropdown_args = apply_filters('quick_edit_dropdown_pages_args', $dropdown_args);
  850. wp_dropdown_pages($dropdown_args);
  851. ?>
  852. </label>
  853. <?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
  854. if ( !$bulk ) : ?>
  855. <label>
  856. <span class="title"><?php _e( 'Order' ); ?></span>
  857. <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
  858. </label>
  859. <?php endif; // !$bulk ?>
  860. <label>
  861. <span class="title"><?php _e( 'Template' ); ?></span>
  862. <select name="page_template">
  863. <?php if ( $bulk ) : ?>
  864. <option value="-1"><?php _e('&mdash; No Change &mdash;'); ?></option>
  865. <?php endif; // $bulk ?>
  866. <option value="default"><?php _e( 'Default Template' ); ?></option>
  867. <?php page_template_dropdown() ?>
  868. </select>
  869. </label>
  870. <?php
  871. endif; // post_type_supports page-attributes
  872. endif; // $post_type_object->hierarchical ?>
  873. <?php if ( count($flat_taxonomies) && !$bulk ) : ?>
  874. <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
  875. <label class="inline-edit-tags">
  876. <span class="title"><?php echo esc_html($taxonomy->label) ?></span>
  877. <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr($taxonomy->name)?>]" class="tax_input_<?php echo esc_attr($taxonomy->name)?>"></textarea>
  878. </label>
  879. <?php endforeach; //$flat_taxonomies as $taxonomy ?>
  880. <?php endif; // count($flat_taxonomies) && !$bulk ?>
  881. <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
  882. if ( $bulk ) : ?>
  883. <div class="inline-edit-group">
  884. <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
  885. <label class="alignleft">
  886. <span class="title"><?php _e( 'Comments' ); ?></span>
  887. <select name="comment_status">
  888. <option value=""><?php _e('&mdash; No Change &mdash;'); ?></option>
  889. <option value="open"><?php _e('Allow'); ?></option>
  890. <option value="closed"><?php _e('Do not allow'); ?></option>
  891. </select>
  892. </label>
  893. <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
  894. <label class="alignright">
  895. <span class="title"><?php _e( 'Pings' ); ?></span>
  896. <select name="ping_status">
  897. <option value=""><?php _e('&mdash; No Change &mdash;'); ?></option>
  898. <option value="open"><?php _e('Allow'); ?></option>
  899. <option value="closed"><?php _e('Do not allow'); ?></option>
  900. </select>
  901. </label>
  902. <?php endif; ?>
  903. </div>
  904. <?php else : // $bulk ?>
  905. <div class="inline-edit-group">
  906. <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
  907. <label class="alignleft">
  908. <input type="checkbox" name="comment_status" value="open" />
  909. <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
  910. </label>
  911. <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
  912. <label class="alignleft">
  913. <input type="checkbox" name="ping_status" value="open" />
  914. <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
  915. </label>
  916. <?php endif; ?>
  917. </div>
  918. <?php endif; // $bulk
  919. endif; // post_type_supports comments or pings ?>
  920. <div class="inline-edit-group">
  921. <label class="inline-edit-status alignleft">
  922. <span class="title"><?php _e( 'Status' ); ?></span>
  923. <select name="_status">
  924. <?php if ( $bulk ) : ?>
  925. <option value="-1"><?php _e('&mdash; No Change &mdash;'); ?></option>
  926. <?php endif; // $bulk ?>
  927. <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
  928. <option value="publish"><?php _e( 'Published' ); ?></option>
  929. <option value="future"><?php _e( 'Scheduled' ); ?></option>
  930. <?php if ( $bulk ) : ?>
  931. <option value="private"><?php _e('Private') ?></option>
  932. <?php endif; // $bulk ?>
  933. <?php endif; ?>
  934. <option value="pending"><?php _e( 'Pending Review' ); ?></option>
  935. <option value="draft"><?php _e( 'Draft' ); ?></option>
  936. </select>
  937. </label>
  938. <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->edit_others_cap ) ) : ?>
  939. <?php if ( $bulk ) : ?>
  940. <label class="alignright">
  941. <span class="title"><?php _e( 'Sticky' ); ?></span>
  942. <select name="sticky">
  943. <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  944. <option value="sticky"><?php _e( 'Sticky' ); ?></option>
  945. <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
  946. </select>
  947. </label>
  948. <?php else : // $bulk ?>
  949. <label class="alignleft">
  950. <input type="checkbox" name="sticky" value="sticky" />
  951. <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
  952. </label>
  953. <?php endif; // $bulk ?>
  954. <?php endif; // !$is_page && $can_publish && current_user_can( 'edit_others_cap' ) ?>
  955. </div>
  956. </div></fieldset>
  957. <?php
  958. foreach ( $columns as $column_name => $column_display_name ) {
  959. if ( isset( $core_columns[$column_name] ) )
  960. continue;
  961. do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
  962. }
  963. ?>
  964. <p class="submit inline-edit-save">
  965. <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="button-secondary cancel alignleft"><?php _e('Cancel'); ?></a>
  966. <?php if ( ! $bulk ) {
  967. wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
  968. $update_text = __( 'Update' );
  969. ?>
  970. <a accesskey="s" href="#inline-edit" title="<?php _e('Update'); ?>" class="button-primary save alignright"><?php echo esc_attr( $update_text ); ?></a>
  971. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  972. <?php } else {
  973. $update_text = __( 'Update' );
  974. ?>
  975. <input accesskey="s" class="button-primary alignright" type="submit" name="bulk_edit" value="<?php echo esc_attr( $update_text ); ?>" />
  976. <?php } ?>
  977. <input type="hidden" name="post_view" value="<?php echo esc_attr($m); ?>" />
  978. <input type="hidden" name="screen" value="<?php echo esc_attr($screen->id); ?>" />
  979. <br class="clear" />
  980. </p>
  981. </td></tr>
  982. <?php
  983. $bulk++;
  984. } ?>
  985. </tbody></table></form>
  986. <?php
  987. }
  988. // adds hidden fields with the data for use in the inline editor for posts and pages
  989. /**
  990. * {@internal Missing Short Description}}
  991. *
  992. * @since unknown
  993. *
  994. * @param unknown_type $post
  995. */
  996. function get_inline_data($post) {
  997. $post_type_object = get_post_type_object($post->post_type);
  998. if ( ! current_user_can($post_type_object->edit_cap, $post->ID) )
  999. return;
  1000. $title = esc_attr( get_the_title( $post->ID ) );
  1001. echo '
  1002. <div class="hidden" id="inline_' . $post->ID . '">
  1003. <div class="post_title">' . $title . '</div>
  1004. <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div>
  1005. <div class="post_author">' . $post->post_author . '</div>
  1006. <div class="comment_status">' . $post->comment_status . '</div>
  1007. <div class="ping_status">' . $post->ping_status . '</div>
  1008. <div class="_status">' . $post->post_status . '</div>
  1009. <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
  1010. <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
  1011. <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
  1012. <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
  1013. <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
  1014. <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
  1015. <div class="post_password">' . esc_html( $post->post_password ) . '</div>';
  1016. if ( $post_type_object->hierarchical )
  1017. echo '<div class="post_parent">' . $post->post_parent . '</div>';
  1018. if ( $post->post_type == 'page' )
  1019. echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>';
  1020. if ( $post_type_object->hierarchical )
  1021. echo '<div class="menu_order">' . $post->menu_order . '</div>';
  1022. $taxonomy_names = get_object_taxonomies( $post->post_type );
  1023. foreach ( $taxonomy_names as $taxonomy_name) {
  1024. $taxonomy = get_taxonomy( $taxonomy_name );
  1025. if ( $taxonomy->hierarchical && $taxonomy->show_ui )
  1026. echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
  1027. elseif ( $taxonomy->show_ui )
  1028. echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
  1029. }
  1030. if ( !$post_type_object->hierarchical )
  1031. echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
  1032. echo '</div>';
  1033. }
  1034. /**
  1035. * {@internal Missing Short Description}}
  1036. *
  1037. * @since unknown
  1038. *
  1039. * @param unknown_type $posts
  1040. */
  1041. function post_rows( $posts = array() ) {
  1042. global $wp_query, $post, $mode;
  1043. add_filter('the_title','esc_html');
  1044. // Create array of post IDs.
  1045. $post_ids = array();
  1046. if ( empty($posts) )
  1047. $posts = &$wp_query->posts;
  1048. foreach ( $posts as $a_post )
  1049. $post_ids[] = $a_post->ID;
  1050. $comment_pending_count = get_pending_comments_num($post_ids);
  1051. foreach ( $posts as $post ) {
  1052. if ( empty($comment_pending_count[$post->ID]) )
  1053. $comment_pending_count[$post->ID] = 0;
  1054. _post_row($post, $comment_pending_count[$post->ID], $mode);
  1055. }
  1056. }
  1057. /**
  1058. * {@internal Missing Short Description}}
  1059. *
  1060. * @since unknown
  1061. *
  1062. * @param unknown_type $a_post
  1063. * @param unknown_type $pending_comments
  1064. * @param unknown_type $mode
  1065. */
  1066. function _post_row($a_post, $pending_comments, $mode) {
  1067. global $post, $current_user, $current_screen;
  1068. static $rowclass;
  1069. $global_post = $post;
  1070. $post = $a_post;
  1071. setup_postdata($post);
  1072. $rowclass = 'alternate' == $rowclass ? '' : 'alternate';
  1073. $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
  1074. $edit_link = get_edit_post_link( $post->ID );
  1075. $title = _draft_or_post_title();
  1076. $post_type_object = get_post_type_object($post->post_type);
  1077. ?>
  1078. <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $rowclass . ' author-' . $post_owner . ' status-' . $post->post_status ); ?> iedit' valign="top">
  1079. <?php
  1080. $posts_columns = get_column_headers( $current_screen );
  1081. $hidden = get_hidden_columns( $current_screen );
  1082. foreach ( $posts_columns as $column_name=>$column_display_name ) {
  1083. $class = "class=\"$column_name column-$column_name\"";
  1084. $style = '';
  1085. if ( in_array($column_name, $hidden) )
  1086. $style = ' style="display:none;"';
  1087. $attributes = "$class$style";
  1088. switch ($column_name) {
  1089. case 'cb':
  1090. ?>
  1091. <th scope="row" class="check-column"><?php if ( current_user_can( $post_type_object->edit_cap, $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
  1092. <?php
  1093. break;
  1094. case 'date':
  1095. if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
  1096. $t_time = $h_time = __('Unpublished');
  1097. $time_diff = 0;
  1098. } else {
  1099. $t_time = get_the_time(__('Y/m/d g:i:s A'));
  1100. $m_time = $post->post_date;
  1101. $time = get_post_time('G', true, $post);
  1102. $time_diff = time() - $time;
  1103. if ( $time_diff > 0 && $time_diff < 24*60*60 )
  1104. $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
  1105. else
  1106. $h_time = mysql2date(__('Y/m/d'), $m_time);
  1107. }
  1108. echo '<td ' . $attributes . '>';
  1109. if ( 'excerpt' == $mode )
  1110. echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode);
  1111. else
  1112. echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) . '</abbr>';
  1113. echo '<br />';
  1114. if ( 'publish' == $post->post_status ) {
  1115. _e('Published');
  1116. } elseif ( 'future' == $post->post_status ) {
  1117. if ( $time_diff > 0 )
  1118. echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
  1119. else
  1120. _e('Scheduled');
  1121. } else {
  1122. _e('Last Modified');
  1123. }
  1124. echo '</td>';
  1125. break;
  1126. case 'title':
  1127. $attributes = 'class="post-title column-title"' . $style;
  1128. ?>
  1129. <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $post->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
  1130. <?php
  1131. if ( 'excerpt' == $mode )
  1132. the_excerpt();
  1133. $actions = array();
  1134. if ( current_user_can($post_type_object->edit_cap, $post->ID) && 'trash' != $post->post_status ) {
  1135. $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
  1136. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
  1137. }
  1138. if ( current_user_can($post_type_object->delete_cap, $post->ID) ) {
  1139. if ( 'trash' == $post->post_status )
  1140. $actions['untrash'] = "<a title='" . esc_attr(__('Restore this post from the Trash')) . "' href='" . wp_nonce_url( admin_url( sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __('Restore') . "</a>";
  1141. elseif ( EMPTY_TRASH_DAYS )
  1142. $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
  1143. if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
  1144. $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post permanently')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently') . "</a>";
  1145. }
  1146. if ( in_array($post->post_status, array('pending', 'draft')) ) {
  1147. if ( current_user_can($post_type_object->edit_cap, $post->ID) )
  1148. $actions['view'] = '<a href="' . add_query_arg( 'preview', 'true', get_permalink($post->ID) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
  1149. } elseif ( 'trash' != $post->post_status ) {
  1150. $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
  1151. }
  1152. $actions = apply_filters('post_row_actions', $actions, $post);
  1153. $action_count = count($actions);
  1154. $i = 0;
  1155. echo '<div class="row-actions">';
  1156. foreach ( $actions as $action => $link ) {
  1157. ++$i;
  1158. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  1159. echo "<span class='$action'>$link$sep</span>";
  1160. }
  1161. echo '</div>';
  1162. get_inline_data($post);
  1163. ?>
  1164. </td>
  1165. <?php
  1166. break;
  1167. case 'categories':
  1168. ?>
  1169. <td <?php echo $attributes ?>><?php
  1170. $categories = get_the_category();
  1171. if ( !empty( $categories ) ) {
  1172. $out = array();
  1173. foreach ( $categories as $c )
  1174. $out[] = "<a href='edit.php?category_name=$c->slug'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
  1175. echo join( ', ', $out );
  1176. } else {
  1177. _e('Uncategorized');
  1178. }
  1179. ?></td>
  1180. <?php
  1181. break;
  1182. case 'tags':
  1183. ?>
  1184. <td <?php echo $attributes ?>><?php
  1185. $tags = get_the_tags($post->ID);
  1186. if ( !empty( $tags ) ) {
  1187. $out = array();
  1188. foreach ( $tags as $c )
  1189. $out[] = "<a href='edit.php?tag=$c->slug'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>";
  1190. echo join( ', ', $out );
  1191. } else {
  1192. _e('No Tags');
  1193. }
  1194. ?></td>
  1195. <?php
  1196. break;
  1197. case 'comments':
  1198. ?>
  1199. <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
  1200. <?php
  1201. $pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
  1202. if ( $pending_comments )
  1203. echo '<strong>';
  1204. comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
  1205. if ( $pending_comments )
  1206. echo '</strong>';
  1207. ?>
  1208. </div></td>
  1209. <?php
  1210. break;
  1211. case 'author':
  1212. ?>
  1213. <td <?php echo $attributes ?>><a href="edit.php?author=<?php the_author_meta('ID'); ?>"><?php the_author() ?></a></td>
  1214. <?php
  1215. break;
  1216. case 'control_view':
  1217. ?>
  1218. <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e('View'); ?></a></td>
  1219. <?php
  1220. break;
  1221. case 'control_edit':
  1222. ?>
  1223. <td><?php if ( current_user_can($post_type_object->edit_cap, $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
  1224. <?php
  1225. break;
  1226. case 'control_delete':
  1227. ?>
  1228. <td><?php if ( current_user_can($post_type_object->delete_cap, $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
  1229. <?php
  1230. break;
  1231. default:
  1232. ?>
  1233. <td <?php echo $attributes ?>><?php do_action('manage_posts_custom_column', $column_name, $post->ID); ?></td>
  1234. <?php
  1235. break;
  1236. }
  1237. }
  1238. ?>
  1239. </tr>
  1240. <?php
  1241. $post = $global_post;
  1242. }
  1243. /*
  1244. * display one row if the page doesn't have any children
  1245. * otherwise, display the row and its children in subsequent rows
  1246. */
  1247. /**
  1248. * {@internal Missing Short Description}}
  1249. *
  1250. * @since unknown
  1251. *
  1252. * @param unknown_type $page
  1253. * @param unknown_type $level
  1254. */
  1255. function display_page_row( $page, $level = 0 ) {
  1256. global $post, $current_screen;
  1257. static $rowclass;
  1258. $post = $page;
  1259. setup_postdata($page);
  1260. if ( 0 == $level && (int)$page->post_parent > 0 ) {
  1261. //sent level 0 by accident, by default, or because we don't know the actual level
  1262. $find_main_page = (int)$page->post_parent;
  1263. while ( $find_main_page > 0 ) {
  1264. $parent = get_page($find_main_page);
  1265. if ( is_null($parent) )
  1266. break;
  1267. $level++;
  1268. $find_main_page = (int)$parent->post_parent;
  1269. if ( !isset($parent_name) )
  1270. $parent_name = $parent->post_title;
  1271. }
  1272. }
  1273. $page->post_title = esc_html( $page->post_title );
  1274. $pad = str_repeat( '&#8212; ', $level );
  1275. $id = (int) $page->ID;
  1276. $rowclass = 'alternate' == $rowclass ? '' : 'alternate';
  1277. $posts_columns = get_column_headers( $current_screen );
  1278. $hidden = get_hidden_columns( $current_screen );
  1279. $title = _draft_or_post_title();
  1280. $post_type = $page->post_type;
  1281. $post_type_object = get_post_type_object($post_type);
  1282. ?>
  1283. <tr id="page-<?php echo $id; ?>" class="<?php echo $rowclass; ?> iedit">
  1284. <?php
  1285. foreach ( $posts_columns as $column_name => $column_display_name ) {
  1286. $class = "class=\"$column_name column-$column_name\"";
  1287. $style = '';
  1288. if ( in_array($column_name, $hidden) )
  1289. $style = ' style="display:none;"';
  1290. $attributes = "$class$style";
  1291. switch ($column_name) {
  1292. case 'cb':
  1293. ?>
  1294. <th scope="row" class="check-column"><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /></th>
  1295. <?php
  1296. break;
  1297. case 'date':
  1298. if ( '0000-00-00 00:00:00' == $page->post_date && 'date' == $column_name ) {
  1299. $t_time = $h_time = __('Unpublished');
  1300. $time_diff = 0;
  1301. } else {
  1302. $t_time = get_the_time(__('Y/m/d g:i:s A'));
  1303. $m_time = $page->post_date;
  1304. $time = get_post_time('G', true);
  1305. $time_diff = time() - $time;
  1306. if ( $time_diff > 0 && $time_diff < 24*60*60 )
  1307. $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
  1308. else
  1309. $h_time = mysql2date(__('Y/m/d'), $m_time);
  1310. }
  1311. echo '<td ' . $attributes . '>';
  1312. echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $page, $column_name, '') . '</abbr>';
  1313. echo '<br />';
  1314. if ( 'publish' == $page->post_status ) {
  1315. _e('Published');
  1316. } elseif ( 'future' == $page->post_status ) {
  1317. if ( $time_diff > 0 )
  1318. echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
  1319. else
  1320. _e('Scheduled');
  1321. } else {
  1322. _e('Last Modified');
  1323. }
  1324. echo '</td>';
  1325. break;
  1326. case 'title':
  1327. $attributes = 'class="post-title page-title column-title"' . $style;
  1328. $edit_link = get_edit_post_link( $page->ID );
  1329. ?>
  1330. <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
  1331. <?php
  1332. $actions = array();
  1333. if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) {
  1334. $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
  1335. $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  1336. }
  1337. if ( current_user_can($post_type_object->delete_cap, $page->ID) ) {
  1338. if ( $post->post_status == 'trash' )
  1339. $actions['untrash'] = "<a title='" . esc_attr(__('Remove this page from the Trash')) . "' href='" . wp_nonce_url("post.php?post_type=$post_type&amp;action=untrash&amp;post=$page->ID", 'untrash-' . $post->post_type . '_' . $page->ID) . "'>" . __('Restore') . "</a>";
  1340. elseif ( EMPTY_TRASH_DAYS )
  1341. $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . get_delete_post_link($page->ID) . "'>" . __('Trash') . "</a>";
  1342. if ( $post->post_status == 'trash' || !EMPTY_TRASH_DAYS )
  1343. $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page permanently')) . "' href='" . wp_nonce_url("post.php?post_type=$post_type&amp;action=delete&amp;post=$page->ID", 'delete-' . $post->post_type . '_' . $page->ID) . "'>" . __('Delete Permanently') . "</a>";
  1344. }
  1345. if ( in_array($post->post_status, array('pending', 'draft')) ) {
  1346. if ( current_user_can($post_type_object->edit_cap, $page->ID) )
  1347. $actions['view'] = '<a href="' . add_query_arg( 'preview', 'true', get_permalink($page->ID) ) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
  1348. } elseif ( $post->post_status != 'trash' ) {
  1349. $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
  1350. }
  1351. $actions = apply_filters('page_row_actions', $actions, $page);
  1352. $action_count = count($actions);
  1353. $i = 0;
  1354. echo '<div class="row-actions">';
  1355. foreach ( $actions as $action => $link ) {
  1356. ++$i;
  1357. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  1358. echo "<span class='$action'>$link$sep</span>";
  1359. }
  1360. echo '</div>';
  1361. get_inline_data($post);
  1362. echo '</td>';
  1363. break;
  1364. case 'comments':
  1365. ?>
  1366. <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
  1367. <?php
  1368. $left = get_pending_comments_num( $page->ID );
  1369. $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
  1370. if ( $left )
  1371. echo '<strong>';
  1372. comments_number("<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
  1373. if ( $left )
  1374. echo '</strong>';
  1375. ?>
  1376. </div></td>
  1377. <?php
  1378. break;
  1379. case 'author':
  1380. ?>
  1381. <td <?php echo $attributes ?>><a href="edit-pages.php?author=<?php the_author_meta('ID'); ?>"><?php the_author() ?></a></td>
  1382. <?php
  1383. break;
  1384. default:
  1385. ?>
  1386. <td <?php echo $attributes ?>><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td>
  1387. <?php
  1388. break;
  1389. }
  1390. }
  1391. ?>
  1392. </tr>
  1393. <?php
  1394. }
  1395. /*
  1396. * displays pages in hierarchical order with paging support
  1397. */
  1398. /**
  1399. * {@internal Missing Short Description}}
  1400. *
  1401. * @since unknown
  1402. *
  1403. * @param unknown_type $pages
  1404. * @param unknown_type $pagenum
  1405. * @param unknown_type $per_page
  1406. * @return unknown
  1407. */
  1408. function page_rows($pages, $pagenum = 1, $per_page = 20) {
  1409. global $wpdb;
  1410. $level = 0;
  1411. if ( ! $pages ) {
  1412. $pages = get_pages( array('sort_column' => 'menu_order') );
  1413. if ( ! $pages )
  1414. return false;
  1415. }
  1416. /*
  1417. * arrange pages into two parts: top level pages and children_pages
  1418. * children_pages is two dimensional array, eg.
  1419. * children_pages[10][] contains all sub-pages whose parent is 10.
  1420. * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations
  1421. * If searching, ignore hierarchy and treat everything as top level
  1422. */
  1423. if ( empty($_GET['s']) ) {
  1424. $top_level_pages = array();
  1425. $children_pages = array();
  1426. foreach ( $pages as $page ) {
  1427. // catch and repair bad pages
  1428. if ( $page->post_parent == $page->ID ) {
  1429. $page->post_parent = 0;
  1430. $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));
  1431. clean_page_cache( $page->ID );
  1432. }
  1433. if ( 0 == $page->post_parent )
  1434. $top_level_pages[] = $page;
  1435. else
  1436. $children_pages[ $page->post_parent ][] = $page;
  1437. }
  1438. $pages = &$top_level_pages;
  1439. }
  1440. $count = 0;
  1441. $start = ($pagenum - 1) * $per_page;
  1442. $end = $start + $per_page;
  1443. foreach ( $pages as $page ) {
  1444. if ( $count >= $end )
  1445. break;
  1446. if ( $count >= $start )
  1447. echo "\t" . display_page_row( $page, $level );
  1448. $count++;
  1449. if ( isset($children_pages) )
  1450. _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
  1451. }
  1452. // if it is the last pagenum and there are orphaned pages, display them with paging as well
  1453. if ( isset($children_pages) && $count < $end ){
  1454. foreach( $children_pages as $orphans ){
  1455. foreach ( $orphans as $op ) {
  1456. if ( $count >= $end )
  1457. break;
  1458. if ( $count >= $start )
  1459. echo "\t" . display_page_row( $op, 0 );
  1460. $count++;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. /*
  1466. * Given a top level page ID, display the nested hierarchy of sub-pages
  1467. * together with paging support
  1468. */
  1469. /**
  1470. * {@internal Missing Short Description}}
  1471. *
  1472. * @since unknown
  1473. *
  1474. * @param unknown_type $children_pages
  1475. * @param unknown_type $count
  1476. * @param unknown_type $parent
  1477. * @param unknown_type $level
  1478. * @param unknown_type $pagenum
  1479. * @param unknown_type $per_page
  1480. */
  1481. function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
  1482. if ( ! isset( $children_pages[$parent] ) )
  1483. return;
  1484. $start = ($pagenum - 1) * $per_page;
  1485. $end = $start + $per_page;
  1486. foreach ( $children_pages[$parent] as $page ) {
  1487. if ( $count >= $end )
  1488. break;
  1489. // If the page starts in a subtree, print the parents.
  1490. if ( $count == $start && $page->post_parent > 0 ) {
  1491. $my_parents = array();
  1492. $my_parent = $page->post_parent;
  1493. while ( $my_parent) {
  1494. $my_parent = get_post($my_parent);
  1495. $my_parents[] = $my_parent;
  1496. if ( !$my_parent->post_parent )
  1497. break;
  1498. $my_parent = $my_parent->post_parent;
  1499. }
  1500. $num_parents = count($my_parents);
  1501. while( $my_parent = array_pop($my_parents) ) {
  1502. echo "\t" . display_page_row( $my_parent, $level - $num_parents );
  1503. $num_parents--;
  1504. }
  1505. }
  1506. if ( $count >= $start )
  1507. echo "\t" . display_page_row( $page, $level );
  1508. $count++;
  1509. _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
  1510. }
  1511. unset( $children_pages[$parent] ); //required in order to keep track of orphans
  1512. }
  1513. /**
  1514. * Generate HTML for a single row on the users.php admin panel.
  1515. *
  1516. * @since 2.1.0
  1517. *
  1518. * @param object $user_object
  1519. * @param string $style Optional. Attributes added to the TR element. Must be sanitized.
  1520. * @param string $role Key for the $wp_roles array.
  1521. * @param int $numposts Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts.
  1522. * @return string
  1523. */
  1524. function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
  1525. global $wp_roles;
  1526. $current_user = wp_get_current_user();
  1527. if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
  1528. $user_object = new WP_User( (int) $user_object );
  1529. $user_object = sanitize_user_object($user_object, 'display');
  1530. $email = $user_object->user_email;
  1531. $url = $user_object->user_url;
  1532. $short_url = str_replace( 'http://', '', $url );
  1533. $short_url = str_replace( 'www.', '', $short_url );
  1534. if ('/' == substr( $short_url, -1 ))
  1535. $short_url = substr( $short_url, 0, -1 );
  1536. if ( strlen( $short_url ) > 35 )
  1537. $short_url = substr( $short_url, 0, 32 ).'...';
  1538. $checkbox = '';
  1539. // Check if the user for this row is editable
  1540. if ( current_user_can( 'list_users' ) ) {
  1541. // Set up the user editing link
  1542. // TODO: make profile/user-edit determination a separate function
  1543. if ($current_user->ID == $user_object->ID) {
  1544. $edit_link = 'profile.php';
  1545. } else {
  1546. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
  1547. }
  1548. $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
  1549. // Set up the hover actions for this user
  1550. $actions = array();
  1551. if ( current_user_can('edit_user', $user_object->ID) ) {
  1552. $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
  1553. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  1554. } else {
  1555. $edit = "<strong>$user_object->user_login</strong><br />";
  1556. }
  1557. if ( !is_multisite() && $current_user->ID != $user_object->ID && current_user_can('delete_user', $user_object->ID) )
  1558. $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . "</a>";
  1559. if ( is_multisite() && $current_user->ID != $user_object->ID && current_user_can('remove_user', $user_object->ID) )
  1560. $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Remove') . "</a>";
  1561. $actions = apply_filters('user_row_actions', $actions, $user_object);
  1562. $action_count = count($actions);
  1563. $i = 0;
  1564. $edit .= '<div class="row-actions">';
  1565. foreach ( $actions as $action => $link ) {
  1566. ++$i;
  1567. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  1568. $edit .= "<span class='$action'>$link$sep</span>";
  1569. }
  1570. $edit .= '</div>';
  1571. // Set up the checkbox (because the user is editable, otherwise its empty)
  1572. $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
  1573. } else {
  1574. $edit = '<strong>' . $user_object->user_login . '</strong>';
  1575. }
  1576. $role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : __('None');
  1577. $r = "<tr id='user-$user_object->ID'$style>";
  1578. $columns = get_column_headers('users');
  1579. $hidden = get_hidden_columns('users');
  1580. $avatar = get_avatar( $user_object->ID, 32 );
  1581. foreach ( $columns as $column_name => $column_display_name ) {
  1582. $class = "class=\"$column_name column-$column_name\"";
  1583. $style = '';
  1584. if ( in_array($column_name, $hidden) )
  1585. $style = ' style="display:none;"';
  1586. $attributes = "$class$style";
  1587. switch ($column_name) {
  1588. case 'cb':
  1589. $r .= "<th scope='row' class='check-column'>$checkbox</th>";
  1590. break;
  1591. case 'username':
  1592. $r .= "<td $attributes>$avatar $edit</td>";
  1593. break;
  1594. case 'name':
  1595. $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
  1596. break;
  1597. case 'email':
  1598. $r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __('E-mail: %s' ), $email ) . "'>$email</a></td>";
  1599. break;
  1600. case 'role':
  1601. $r .= "<td $attributes>$role_name</td>";
  1602. break;
  1603. case 'posts':
  1604. $attributes = 'class="posts column-posts num"' . $style;
  1605. $r .= "<td $attributes>";
  1606. if ( $numposts > 0 ) {
  1607. $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
  1608. $r .= $numposts;
  1609. $r .= '</a>';
  1610. } else {
  1611. $r .= 0;
  1612. }
  1613. $r .= "</td>";
  1614. break;
  1615. default:
  1616. $r .= "<td $attributes>";
  1617. $r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
  1618. $r .= "</td>";
  1619. }
  1620. }
  1621. $r .= '</tr>';
  1622. return $r;
  1623. }
  1624. /**
  1625. * {@internal Missing Short Description}}
  1626. *
  1627. * @since unknown
  1628. *
  1629. * @param string $status Comment status (approved, spam, trash, etc)
  1630. * @param string $s Term to search for
  1631. * @param int $start Offset to start at for pagination
  1632. * @param int $num Maximum number of comments to return
  1633. * @param int $post Post ID or 0 to return all comments
  1634. * @param string $type Comment type (comment, trackback, pingback, etc)
  1635. * @return array [0] contains the comments and [1] contains the total number of comments that match (ignoring $start and $num)
  1636. */
  1637. function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0, $type = '' ) {
  1638. global $wpdb;
  1639. $start = abs( (int) $start );
  1640. $num = (int) $num;
  1641. $post = (int) $post;
  1642. $count = wp_count_comments();
  1643. $index = '';
  1644. if ( 'moderated' == $status ) {
  1645. $approved = "c.comment_approved = '0'";
  1646. $total = $count->moderated;
  1647. } elseif ( 'approved' == $status ) {
  1648. $approved = "c.comment_approved = '1'";
  1649. $total = $count->approved;
  1650. } elseif ( 'spam' == $status ) {
  1651. $approved = "c.comment_approved = 'spam'";
  1652. $total = $count->spam;
  1653. } elseif ( 'trash' == $status ) {
  1654. $approved = "c.comment_approved = 'trash'";
  1655. $total = $count->trash;
  1656. } else {
  1657. $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )";
  1658. $total = $count->moderated + $count->approved;
  1659. $index = 'USE INDEX (c.comment_date_gmt)';
  1660. }
  1661. if ( $post ) {
  1662. $total = '';
  1663. $post = " AND c.comment_post_ID = '$post'";
  1664. } else {
  1665. $post = '';
  1666. }
  1667. $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT $start, $num";
  1668. if ( 'comment' == $type )
  1669. $typesql = "AND c.comment_type = ''";
  1670. elseif ( 'pings' == $type )
  1671. $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )";
  1672. elseif ( 'all' == $type )
  1673. $typesql = '';
  1674. elseif ( !empty($type) )
  1675. $typesql = $wpdb->prepare("AND c.comment_type = %s", $type);
  1676. else
  1677. $typesql = '';
  1678. if ( !empty($type) )
  1679. $total = '';
  1680. $query = "FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ";
  1681. if ( $s ) {
  1682. $total = '';
  1683. $s = $wpdb->escape($s);
  1684. $query .= "AND
  1685. (c.comment_author LIKE '%$s%' OR
  1686. c.comment_author_email LIKE '%$s%' OR
  1687. c.comment_author_url LIKE ('%$s%') OR
  1688. c.comment_author_IP LIKE ('%$s%') OR
  1689. c.comment_content LIKE ('%$s%') ) AND
  1690. $approved
  1691. $typesql";
  1692. } else {
  1693. $query .= "AND $approved $post $typesql";
  1694. }
  1695. $comments = $wpdb->get_results("SELECT * $query $orderby");
  1696. if ( '' === $total )
  1697. $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) $query");
  1698. update_comment_cache($comments);
  1699. return array($comments, $total);
  1700. }
  1701. /**
  1702. * {@internal Missing Short Description}}
  1703. *
  1704. * @since unknown
  1705. *
  1706. * @param unknown_type $comment_id
  1707. * @param unknown_type $mode
  1708. * @param unknown_type $comment_status
  1709. * @param unknown_type $checkbox
  1710. */
  1711. function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true, $from_ajax = false ) {
  1712. global $comment, $post, $_comment_pending_count;
  1713. $comment = get_comment( $comment_id );
  1714. $post = get_post($comment->comment_post_ID);
  1715. $the_comment_status = wp_get_comment_status($comment->comment_ID);
  1716. $post_type_object = get_post_type_object($post->post_type);
  1717. $user_can = current_user_can($post_type_object->edit_cap, $post->ID);
  1718. $comment_url = esc_url(get_comment_link($comment->comment_ID));
  1719. $author_url = get_comment_author_url();
  1720. if ( 'http://' == $author_url )
  1721. $author_url = '';
  1722. $author_url_display = preg_replace('|http://(www\.)?|i', '', $author_url);
  1723. if ( strlen($author_url_display) > 50 )
  1724. $author_url_display = substr($author_url_display, 0, 49) . '...';
  1725. $ptime = date('G', strtotime( $comment->comment_date ) );
  1726. if ( ( abs(time() - $ptime) ) < 86400 )
  1727. $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
  1728. else
  1729. $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
  1730. if ( $user_can ) {
  1731. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  1732. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  1733. $approve_url = esc_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
  1734. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
  1735. $spam_url = esc_url( "comment.php?action=spamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
  1736. $unspam_url = esc_url( "comment.php?action=unspamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
  1737. $trash_url = esc_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
  1738. $untrash_url = esc_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
  1739. $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
  1740. }
  1741. echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
  1742. $columns = get_column_headers('edit-comments');
  1743. $hidden = get_hidden_columns('edit-comments');
  1744. foreach ( $columns as $column_name => $column_display_name ) {
  1745. $class = "class=\"$column_name column-$column_name\"";
  1746. $style = '';
  1747. if ( in_array($column_name, $hidden) )
  1748. $style = ' style="display:none;"';
  1749. $attributes = "$class$style";
  1750. switch ($column_name) {
  1751. case 'cb':
  1752. if ( !$checkbox ) break;
  1753. echo '<th scope="row" class="check-column">';
  1754. if ( $user_can ) echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
  1755. echo '</th>';
  1756. break;
  1757. case 'comment':
  1758. echo "<td $attributes>";
  1759. echo '<div id="submitted-on">';
  1760. /* translators: 2: comment date, 3: comment time */
  1761. printf( __( '<a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
  1762. /* translators: comment date format. See http://php.net/date */ get_comment_date( __('Y/m/d') ),
  1763. /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) );
  1764. if ( $comment->comment_parent ) {
  1765. $parent = get_comment( $comment->comment_parent );
  1766. $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
  1767. $name = apply_filters( 'get_comment_author', $parent->comment_author ); // there's no API function for this
  1768. printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
  1769. }
  1770. echo '</div>';
  1771. comment_text();
  1772. if ( $user_can ) { ?>
  1773. <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
  1774. <textarea class="comment" rows="1" cols="1"><?php echo htmlspecialchars( apply_filters('comment_edit_pre', $comment->comment_content), ENT_QUOTES ); ?></textarea>
  1775. <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
  1776. <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
  1777. <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
  1778. <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
  1779. </div>
  1780. <?php
  1781. }
  1782. if ( $user_can ) {
  1783. // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
  1784. $actions = array(
  1785. 'approve' => '', 'unapprove' => '',
  1786. 'reply' => '',
  1787. 'quickedit' => '',
  1788. 'edit' => '',
  1789. 'spam' => '', 'unspam' => '',
  1790. 'trash' => '', 'untrash' => '', 'delete' => ''
  1791. );
  1792. if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
  1793. if ( 'approved' == $the_comment_status )
  1794. $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
  1795. else if ( 'unapproved' == $the_comment_status )
  1796. $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
  1797. } else {
  1798. $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
  1799. $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
  1800. }
  1801. if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
  1802. $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
  1803. } elseif ( 'spam' == $the_comment_status ) {
  1804. $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
  1805. } elseif ( 'trash' == $the_comment_status ) {
  1806. $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
  1807. }
  1808. if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
  1809. $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
  1810. } else {
  1811. $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
  1812. }
  1813. if ( 'trash' != $the_comment_status ) {
  1814. $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
  1815. $actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.esc_attr__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
  1816. if ( 'spam' != $the_comment_status )
  1817. $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
  1818. }
  1819. $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
  1820. $i = 0;
  1821. echo '<div class="row-actions">';
  1822. foreach ( $actions as $action => $link ) {
  1823. ++$i;
  1824. ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  1825. // Reply and quickedit need a hide-if-no-js span when not added with ajax
  1826. if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
  1827. $action .= ' hide-if-no-js';
  1828. elseif ( ($action == 'untrash' && $the_comment_status == 'trash') || ($action == 'unspam' && $the_comment_status == 'spam') ) {
  1829. if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
  1830. $action .= ' approve';
  1831. else
  1832. $action .= ' unapprove';
  1833. }
  1834. echo "<span class='$action'>$sep$link</span>";
  1835. }
  1836. echo '</div>';
  1837. }
  1838. echo '</td>';
  1839. break;
  1840. case 'author':
  1841. echo "<td $attributes><strong>"; comment_author(); echo '</strong><br />';
  1842. if ( !empty($author_url) )
  1843. echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
  1844. if ( $user_can ) {
  1845. if ( !empty($comment->comment_author_email) ) {
  1846. comment_author_email_link();
  1847. echo '<br />';
  1848. }
  1849. echo '<a href="edit-comments.php?s=';
  1850. comment_author_IP();
  1851. echo '&amp;mode=detail';
  1852. if ( 'spam' == $comment_status )
  1853. echo '&amp;comment_status=spam';
  1854. echo '">';
  1855. comment_author_IP();
  1856. echo '</a>';
  1857. } //current_user_can
  1858. echo '</td>';
  1859. break;
  1860. case 'date':
  1861. echo "<td $attributes>" . get_comment_date(__('Y/m/d \a\t g:ia')) . '</td>';
  1862. break;
  1863. case 'response':
  1864. if ( 'single' !== $mode ) {
  1865. if ( isset( $_comment_pending_count[$post->ID] ) ) {
  1866. $pending_comments = $_comment_pending_count[$post->ID];
  1867. } else {
  1868. $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
  1869. $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
  1870. }
  1871. if ( $user_can ) {
  1872. $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";
  1873. $post_link .= get_the_title($post->ID) . '</a>';
  1874. } else {
  1875. $post_link = get_the_title($post->ID);
  1876. }
  1877. echo "<td $attributes>\n";
  1878. echo '<div class="response-links"><span class="post-com-count-wrapper">';
  1879. echo $post_link . '<br />';
  1880. $pending_phrase = esc_attr(sprintf( __('%s pending'), number_format( $pending_comments ) ));
  1881. if ( $pending_comments )
  1882. echo '<strong>';
  1883. comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('0', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link */ _x('1', 'comment count') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . /* translators: comment count link: % will be substituted by comment count */ _x('%', 'comment count') . '</span></a>');
  1884. if ( $pending_comments )
  1885. echo '</strong>';
  1886. echo '</span> ';
  1887. echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
  1888. echo '</div>';
  1889. if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) )
  1890. echo $thumb;
  1891. echo '</td>';
  1892. }
  1893. break;
  1894. default:
  1895. echo "<td $attributes>\n";
  1896. do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
  1897. echo "</td>\n";
  1898. break;
  1899. }
  1900. }
  1901. echo "</tr>\n";
  1902. }
  1903. /**
  1904. * {@internal Missing Short Description}}
  1905. *
  1906. * @since unknown
  1907. *
  1908. * @param unknown_type $position
  1909. * @param unknown_type $checkbox
  1910. * @param unknown_type $mode
  1911. */
  1912. function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
  1913. global $current_user;
  1914. // allow plugin to replace the popup content
  1915. $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
  1916. if ( ! empty($content) ) {
  1917. echo $content;
  1918. return;
  1919. }
  1920. $columns = get_column_headers('edit-comments');
  1921. $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns('edit-comments') ) );
  1922. $col_count = count($columns) - count($hidden);
  1923. ?>
  1924. <form method="get" action="">
  1925. <?php if ( $table_row ) : ?>
  1926. <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $col_count; ?>">
  1927. <?php else : ?>
  1928. <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
  1929. <?php endif; ?>
  1930. <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div>
  1931. <div id="edithead" style="display:none;">
  1932. <div class="inside">
  1933. <label for="author"><?php _e('Name') ?></label>
  1934. <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
  1935. </div>
  1936. <div class="inside">
  1937. <label for="author-email"><?php _e('E-mail') ?></label>
  1938. <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
  1939. </div>
  1940. <div class="inside">
  1941. <label for="author-url"><?php _e('URL') ?></label>
  1942. <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
  1943. </div>
  1944. <div style="clear:both;"></div>
  1945. </div>
  1946. <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div>
  1947. <p id="replysubmit" class="submit">
  1948. <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
  1949. <a href="#comments-form" class="save button-primary alignright" tabindex="104">
  1950. <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
  1951. <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
  1952. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  1953. <span class="error" style="display:none;"></span>
  1954. <br class="clear" />
  1955. </p>
  1956. <input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" />
  1957. <input type="hidden" name="action" id="action" value="" />
  1958. <input type="hidden" name="comment_ID" id="comment_ID" value="" />
  1959. <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
  1960. <input type="hidden" name="status" id="status" value="" />
  1961. <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
  1962. <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
  1963. <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
  1964. <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce', false ); ?>
  1965. <?php wp_comment_form_unfiltered_html_nonce(); ?>
  1966. <?php if ( $table_row ) : ?>
  1967. </td></tr></tbody></table>
  1968. <?php else : ?>
  1969. </div></div>
  1970. <?php endif; ?>
  1971. </form>
  1972. <?php
  1973. }
  1974. /**
  1975. * Output 'undo move to trash' text for comments
  1976. *
  1977. * @since 2.9.0
  1978. */
  1979. function wp_comment_trashnotice() {
  1980. ?>
  1981. <div class="hidden" id="trash-undo-holder">
  1982. <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
  1983. </div>
  1984. <div class="hidden" id="spam-undo-holder">
  1985. <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
  1986. </div>
  1987. <?php
  1988. }
  1989. /**
  1990. * {@internal Missing Short Description}}
  1991. *
  1992. * @since unknown
  1993. *
  1994. * @param unknown_type $meta
  1995. */
  1996. function list_meta( $meta ) {
  1997. // Exit if no meta
  1998. if ( ! $meta ) {
  1999. echo '
  2000. <table id="list-table" style="display: none;">
  2001. <thead>
  2002. <tr>
  2003. <th class="left">' . __( 'Name' ) . '</th>
  2004. <th>' . __( 'Value' ) . '</th>
  2005. </tr>
  2006. </thead>
  2007. <tbody id="the-list" class="list:meta">
  2008. <tr><td></td></tr>
  2009. </tbody>
  2010. </table>'; //TBODY needed for list-manipulation JS
  2011. return;
  2012. }
  2013. $count = 0;
  2014. ?>
  2015. <table id="list-table">
  2016. <thead>
  2017. <tr>
  2018. <th class="left"><?php _e( 'Name' ) ?></th>
  2019. <th><?php _e( 'Value' ) ?></th>
  2020. </tr>
  2021. </thead>
  2022. <tbody id='the-list' class='list:meta'>
  2023. <?php
  2024. foreach ( $meta as $entry )
  2025. echo _list_meta_row( $entry, $count );
  2026. ?>
  2027. </tbody>
  2028. </table>
  2029. <?php
  2030. }
  2031. /**
  2032. * {@internal Missing Short Description}}
  2033. *
  2034. * @since unknown
  2035. *
  2036. * @param unknown_type $entry
  2037. * @param unknown_type $count
  2038. * @return unknown
  2039. */
  2040. function _list_meta_row( $entry, &$count ) {
  2041. static $update_nonce = false;
  2042. if ( !$update_nonce )
  2043. $update_nonce = wp_create_nonce( 'add-meta' );
  2044. $r = '';
  2045. ++ $count;
  2046. if ( $count % 2 )
  2047. $style = 'alternate';
  2048. else
  2049. $style = '';
  2050. if ('_' == $entry['meta_key'] { 0 } )
  2051. $style .= ' hidden';
  2052. if ( is_serialized( $entry['meta_value'] ) ) {
  2053. if ( is_serialized_string( $entry['meta_value'] ) ) {
  2054. // this is a serialized string, so we should display it
  2055. $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
  2056. } else {
  2057. // this is a serialized array/object so we should NOT display it
  2058. --$count;
  2059. return;
  2060. }
  2061. }
  2062. $entry['meta_key'] = esc_attr($entry['meta_key']);
  2063. $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
  2064. $entry['meta_id'] = (int) $entry['meta_id'];
  2065. $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
  2066. $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
  2067. $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
  2068. $r .= "\n\t\t<div class='submit'><input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
  2069. $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='". esc_attr__( 'Delete' ) ."' />";
  2070. $r .= "\n\t\t<input name='updatemeta' type='submit' tabindex='6' value='". esc_attr__( 'Update' ) ."' class='add:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$update_nonce updatemeta' /></div>";
  2071. $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
  2072. $r .= "</td>";
  2073. $r .= "\n\t\t<td><label class='screen-reader-text' for='meta[{$entry['meta_id']}][value]'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
  2074. return $r;
  2075. }
  2076. /**
  2077. * {@internal Missing Short Description}}
  2078. *
  2079. * @since unknown
  2080. */
  2081. function meta_form() {
  2082. global $wpdb;
  2083. $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
  2084. $keys = $wpdb->get_col( "
  2085. SELECT meta_key
  2086. FROM $wpdb->postmeta
  2087. GROUP BY meta_key
  2088. HAVING meta_key NOT LIKE '\_%'
  2089. ORDER BY meta_key
  2090. LIMIT $limit" );
  2091. if ( $keys )
  2092. natcasesort($keys);
  2093. ?>
  2094. <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
  2095. <table id="newmeta">
  2096. <thead>
  2097. <tr>
  2098. <th class="left"><label for="metakeyselect"><?php _e( 'Name' ) ?></label></th>
  2099. <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
  2100. </tr>
  2101. </thead>
  2102. <tbody>
  2103. <tr>
  2104. <td id="newmetaleft" class="left">
  2105. <?php if ( $keys ) { ?>
  2106. <select id="metakeyselect" name="metakeyselect" tabindex="7">
  2107. <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
  2108. <?php
  2109. foreach ( $keys as $key ) {
  2110. echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
  2111. }
  2112. ?>
  2113. </select>
  2114. <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
  2115. <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
  2116. <span id="enternew"><?php _e('Enter new'); ?></span>
  2117. <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
  2118. <?php } else { ?>
  2119. <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
  2120. <?php } ?>
  2121. </td>
  2122. <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
  2123. </tr>
  2124. <tr><td colspan="2" class="submit">
  2125. <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php esc_attr_e( 'Add Custom Field' ) ?>" />
  2126. <?php wp_nonce_field( 'add-meta', '_ajax_nonce', false ); ?>
  2127. </td></tr>
  2128. </tbody>
  2129. </table>
  2130. <?php
  2131. }
  2132. /**
  2133. * {@internal Missing Short Description}}
  2134. *
  2135. * @since unknown
  2136. *
  2137. * @param unknown_type $edit
  2138. * @param unknown_type $for_post
  2139. * @param unknown_type $tab_index
  2140. * @param unknown_type $multi
  2141. */
  2142. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
  2143. global $wp_locale, $post, $comment;
  2144. if ( $for_post )
  2145. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
  2146. $tab_index_attribute = '';
  2147. if ( (int) $tab_index > 0 )
  2148. $tab_index_attribute = " tabindex=\"$tab_index\"";
  2149. // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
  2150. $time_adj = current_time('timestamp');
  2151. $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
  2152. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
  2153. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
  2154. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
  2155. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
  2156. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
  2157. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
  2158. $cur_jj = gmdate( 'd', $time_adj );
  2159. $cur_mm = gmdate( 'm', $time_adj );
  2160. $cur_aa = gmdate( 'Y', $time_adj );
  2161. $cur_hh = gmdate( 'H', $time_adj );
  2162. $cur_mn = gmdate( 'i', $time_adj );
  2163. $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
  2164. for ( $i = 1; $i < 13; $i = $i +1 ) {
  2165. $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
  2166. if ( $i == $mm )
  2167. $month .= ' selected="selected"';
  2168. $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
  2169. }
  2170. $month .= '</select>';
  2171. $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  2172. $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
  2173. $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  2174. $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
  2175. echo '<div class="timestamp-wrap">';
  2176. /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
  2177. printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
  2178. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
  2179. if ( $multi ) return;
  2180. echo "\n\n";
  2181. foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
  2182. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
  2183. $cur_timeunit = 'cur_' . $timeunit;
  2184. echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
  2185. }
  2186. ?>
  2187. <p>
  2188. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
  2189. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
  2190. </p>
  2191. <?php
  2192. }
  2193. /**
  2194. * {@internal Missing Short Description}}
  2195. *
  2196. * @since unknown
  2197. *
  2198. * @param unknown_type $default
  2199. */
  2200. function page_template_dropdown( $default = '' ) {
  2201. $templates = get_page_templates();
  2202. ksort( $templates );
  2203. foreach (array_keys( $templates ) as $template )
  2204. : if ( $default == $templates[$template] )
  2205. $selected = " selected='selected'";
  2206. else
  2207. $selected = '';
  2208. echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
  2209. endforeach;
  2210. }
  2211. /**
  2212. * {@internal Missing Short Description}}
  2213. *
  2214. * @since unknown
  2215. *
  2216. * @param unknown_type $default
  2217. * @param unknown_type $parent
  2218. * @param unknown_type $level
  2219. * @return unknown
  2220. */
  2221. function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
  2222. global $wpdb, $post_ID;
  2223. $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
  2224. if ( $items ) {
  2225. foreach ( $items as $item ) {
  2226. // A page cannot be its own parent.
  2227. if (!empty ( $post_ID ) ) {
  2228. if ( $item->ID == $post_ID ) {
  2229. continue;
  2230. }
  2231. }
  2232. $pad = str_repeat( '&nbsp;', $level * 3 );
  2233. if ( $item->ID == $default)
  2234. $current = ' selected="selected"';
  2235. else
  2236. $current = '';
  2237. echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
  2238. parent_dropdown( $default, $item->ID, $level +1 );
  2239. }
  2240. } else {
  2241. return false;
  2242. }
  2243. }
  2244. /**
  2245. * {@internal Missing Short Description}}
  2246. *
  2247. * @since unknown
  2248. *
  2249. * @param unknown_type $id
  2250. * @return unknown
  2251. */
  2252. function the_attachment_links( $id = false ) {
  2253. $id = (int) $id;
  2254. $post = & get_post( $id );
  2255. if ( $post->post_type != 'attachment' )
  2256. return false;
  2257. $icon = wp_get_attachment_image( $post->ID, 'thumbnail', true );
  2258. $attachment_data = wp_get_attachment_metadata( $id );
  2259. $thumb = isset( $attachment_data['thumb'] );
  2260. ?>
  2261. <form id="the-attachment-links">
  2262. <table>
  2263. <col />
  2264. <col class="widefat" />
  2265. <tr>
  2266. <th scope="row"><?php _e( 'URL' ) ?></th>
  2267. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
  2268. </tr>
  2269. <?php if ( $icon ) : ?>
  2270. <tr>
  2271. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
  2272. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
  2273. </tr>
  2274. <tr>
  2275. <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
  2276. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
  2277. </tr>
  2278. <?php else : ?>
  2279. <tr>
  2280. <th scope="row"><?php _e( 'Link to file' ) ?></th>
  2281. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
  2282. </tr>
  2283. <tr>
  2284. <th scope="row"><?php _e( 'Link to page' ) ?></th>
  2285. <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
  2286. </tr>
  2287. <?php endif; ?>
  2288. </table>
  2289. </form>
  2290. <?php
  2291. }
  2292. /**
  2293. * Print out <option> html elements for role selectors based on $wp_roles
  2294. *
  2295. * @package WordPress
  2296. * @subpackage Administration
  2297. * @since 2.1
  2298. *
  2299. * @uses $wp_roles
  2300. * @param string $default slug for the role that should be already selected
  2301. */
  2302. function wp_dropdown_roles( $selected = false ) {
  2303. $p = '';
  2304. $r = '';
  2305. $editable_roles = get_editable_roles();
  2306. foreach ( $editable_roles as $role => $details ) {
  2307. $name = translate_user_role($details['name'] );
  2308. if ( $selected == $role ) // Make default first in list
  2309. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
  2310. else
  2311. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
  2312. }
  2313. echo $p . $r;
  2314. }
  2315. /**
  2316. * {@internal Missing Short Description}}
  2317. *
  2318. * @since unknown
  2319. *
  2320. * @param unknown_type $size
  2321. * @return unknown
  2322. */
  2323. function wp_convert_hr_to_bytes( $size ) {
  2324. $size = strtolower($size);
  2325. $bytes = (int) $size;
  2326. if ( strpos($size, 'k') !== false )
  2327. $bytes = intval($size) * 1024;
  2328. elseif ( strpos($size, 'm') !== false )
  2329. $bytes = intval($size) * 1024 * 1024;
  2330. elseif ( strpos($size, 'g') !== false )
  2331. $bytes = intval($size) * 1024 * 1024 * 1024;
  2332. return $bytes;
  2333. }
  2334. /**
  2335. * {@internal Missing Short Description}}
  2336. *
  2337. * @since unknown
  2338. *
  2339. * @param unknown_type $bytes
  2340. * @return unknown
  2341. */
  2342. function wp_convert_bytes_to_hr( $bytes ) {
  2343. $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
  2344. $log = log( $bytes, 1024 );
  2345. $power = (int) $log;
  2346. $size = pow(1024, $log - $power);
  2347. return $size . $units[$power];
  2348. }
  2349. /**
  2350. * {@internal Missing Short Description}}
  2351. *
  2352. * @since unknown
  2353. *
  2354. * @return unknown
  2355. */
  2356. function wp_max_upload_size() {
  2357. $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
  2358. $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
  2359. $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
  2360. return $bytes;
  2361. }
  2362. /**
  2363. * Outputs the form used by the importers to accept the data to be imported
  2364. *
  2365. * @since 2.0
  2366. *
  2367. * @param string $action The action attribute for the form.
  2368. */
  2369. function wp_import_upload_form( $action ) {
  2370. $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
  2371. $size = wp_convert_bytes_to_hr( $bytes );
  2372. $upload_dir = wp_upload_dir();
  2373. if ( ! empty( $upload_dir['error'] ) ) :
  2374. ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
  2375. <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
  2376. else :
  2377. ?>
  2378. <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
  2379. <p>
  2380. <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
  2381. <input type="file" id="upload" name="import" size="25" />
  2382. <input type="hidden" name="action" value="save" />
  2383. <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
  2384. </p>
  2385. <p class="submit">
  2386. <input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
  2387. </p>
  2388. </form>
  2389. <?php
  2390. endif;
  2391. }
  2392. /**
  2393. * {@internal Missing Short Description}}
  2394. *
  2395. * @since unknown
  2396. */
  2397. function wp_remember_old_slug() {
  2398. global $post;
  2399. $name = esc_attr($post->post_name); // just in case
  2400. if ( strlen($name) )
  2401. echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
  2402. }
  2403. /**
  2404. * Add a meta box to an edit form.
  2405. *
  2406. * @since 2.5.0
  2407. *
  2408. * @param string $id String for use in the 'id' attribute of tags.
  2409. * @param string $title Title of the meta box.
  2410. * @param string $callback Function that fills the box with the desired content. The function should echo its output.
  2411. * @param string $page The type of edit page on which to show the box (post, page, link).
  2412. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  2413. * @param string $priority The priority within the context where the boxes should show ('high', 'low').
  2414. */
  2415. function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
  2416. global $wp_meta_boxes;
  2417. if ( !isset($wp_meta_boxes) )
  2418. $wp_meta_boxes = array();
  2419. if ( !isset($wp_meta_boxes[$page]) )
  2420. $wp_meta_boxes[$page] = array();
  2421. if ( !isset($wp_meta_boxes[$page][$context]) )
  2422. $wp_meta_boxes[$page][$context] = array();
  2423. foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
  2424. foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
  2425. if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
  2426. continue;
  2427. // If a core box was previously added or removed by a plugin, don't add.
  2428. if ( 'core' == $priority ) {
  2429. // If core box previously deleted, don't add
  2430. if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
  2431. return;
  2432. // If box was added with default priority, give it core priority to maintain sort order
  2433. if ( 'default' == $a_priority ) {
  2434. $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
  2435. unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
  2436. }
  2437. return;
  2438. }
  2439. // If no priority given and id already present, use existing priority
  2440. if ( empty($priority) ) {
  2441. $priority = $a_priority;
  2442. // else if we're adding to the sorted priortiy, we don't know the title or callback. Glab them from the previously added context/priority.
  2443. } elseif ( 'sorted' == $priority ) {
  2444. $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
  2445. $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
  2446. $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
  2447. }
  2448. // An id can be in only one priority and one context
  2449. if ( $priority != $a_priority || $context != $a_context )
  2450. unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
  2451. }
  2452. }
  2453. if ( empty($priority) )
  2454. $priority = 'low';
  2455. if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
  2456. $wp_meta_boxes[$page][$context][$priority] = array();
  2457. $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
  2458. }
  2459. /**
  2460. * {@internal Missing Short Description}}
  2461. *
  2462. * @since unknown
  2463. *
  2464. * @param unknown_type $page
  2465. * @param unknown_type $context
  2466. * @param unknown_type $object
  2467. * @return int number of meta_boxes
  2468. */
  2469. function do_meta_boxes($page, $context, $object) {
  2470. global $wp_meta_boxes;
  2471. static $already_sorted = false;
  2472. //do_action('do_meta_boxes', $page, $context, $object);
  2473. $hidden = get_hidden_meta_boxes($page);
  2474. echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
  2475. $i = 0;
  2476. do {
  2477. // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
  2478. if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
  2479. foreach ( $sorted as $box_context => $ids )
  2480. foreach ( explode(',', $ids) as $id )
  2481. if ( $id )
  2482. add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
  2483. }
  2484. $already_sorted = true;
  2485. if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
  2486. break;
  2487. foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
  2488. if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
  2489. foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
  2490. if ( false == $box || ! $box['title'] )
  2491. continue;
  2492. $i++;
  2493. $style = '';
  2494. $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
  2495. echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
  2496. echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
  2497. echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
  2498. echo '<div class="inside">' . "\n";
  2499. call_user_func($box['callback'], $object, $box);
  2500. echo "</div>\n";
  2501. echo "</div>\n";
  2502. }
  2503. }
  2504. }
  2505. } while(0);
  2506. echo "</div>";
  2507. return $i;
  2508. }
  2509. /**
  2510. * Remove a meta box from an edit form.
  2511. *
  2512. * @since 2.6.0
  2513. *
  2514. * @param string $id String for use in the 'id' attribute of tags.
  2515. * @param string $page The type of edit page on which to show the box (post, page, link).
  2516. * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
  2517. */
  2518. function remove_meta_box($id, $page, $context) {
  2519. global $wp_meta_boxes;
  2520. if ( !isset($wp_meta_boxes) )
  2521. $wp_meta_boxes = array();
  2522. if ( !isset($wp_meta_boxes[$page]) )
  2523. $wp_meta_boxes[$page] = array();
  2524. if ( !isset($wp_meta_boxes[$page][$context]) )
  2525. $wp_meta_boxes[$page][$context] = array();
  2526. foreach ( array('high', 'core', 'default', 'low') as $priority )
  2527. $wp_meta_boxes[$page][$context][$priority][$id] = false;
  2528. }
  2529. /**
  2530. * {@internal Missing Short Description}}
  2531. *
  2532. * @since unknown
  2533. *
  2534. * @param unknown_type $screen
  2535. */
  2536. function meta_box_prefs($screen) {
  2537. global $wp_meta_boxes;
  2538. if ( is_string($screen) )
  2539. $screen = convert_to_screen($screen);
  2540. if ( empty($wp_meta_boxes[$screen->id]) )
  2541. return;
  2542. $hidden = get_hidden_meta_boxes($screen);
  2543. foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) {
  2544. foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) {
  2545. foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) {
  2546. if ( false == $box || ! $box['title'] )
  2547. continue;
  2548. // Submit box cannot be hidden
  2549. if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
  2550. continue;
  2551. $box_id = $box['id'];
  2552. echo '<label for="' . $box_id . '-hide">';
  2553. echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />';
  2554. echo "{$box['title']}</label>\n";
  2555. }
  2556. }
  2557. }
  2558. }
  2559. function get_hidden_meta_boxes($screen) {
  2560. if ( is_string($screen) )
  2561. $screen = convert_to_screen($screen);
  2562. $hidden = get_user_option( "metaboxhidden_$screen->id" );
  2563. // Hide slug boxes by default
  2564. if ( !is_array($hidden) )
  2565. $hidden = array('slugdiv');
  2566. return $hidden;
  2567. }
  2568. /**
  2569. * Add a new section to a settings page.
  2570. *
  2571. * Part of the Settings API. Use this to define new settings sections for an admin page.
  2572. * Show settings sections in your admin page callback function with do_settings_sections().
  2573. * Add settings fields to your section with add_settings_field()
  2574. *
  2575. * The $callback argument should be the name of a function that echos out any
  2576. * content you want to show at the top of the settings section before the actual
  2577. * fields. It can output nothing if you want.
  2578. *
  2579. * @since 2.7.0
  2580. *
  2581. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  2582. * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
  2583. * @param string $title Formatted title of the section. Shown as the heading for the section.
  2584. * @param string $callback Function that echo's out content for the section heading.
  2585. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
  2586. */
  2587. function add_settings_section($id, $title, $callback, $page) {
  2588. global $wp_settings_sections;
  2589. if ( 'misc' == $page ) {
  2590. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  2591. $page = 'general';
  2592. }
  2593. if ( !isset($wp_settings_sections) )
  2594. $wp_settings_sections = array();
  2595. if ( !isset($wp_settings_sections[$page]) )
  2596. $wp_settings_sections[$page] = array();
  2597. if ( !isset($wp_settings_sections[$page][$id]) )
  2598. $wp_settings_sections[$page][$id] = array();
  2599. $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
  2600. }
  2601. /**
  2602. * Add a new field to a section of a settings page
  2603. *
  2604. * Part of the Settings API. Use this to define a settings field that will show
  2605. * as part of a settings section inside a settings page. The fields are shown using
  2606. * do_settings_fields() in do_settings-sections()
  2607. *
  2608. * The $callback argument should be the name of a function that echoes out the
  2609. * html input tags for this setting field. Use get_option() to retrive existing
  2610. * values to show.
  2611. *
  2612. * @since 2.7.0
  2613. *
  2614. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  2615. *
  2616. * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
  2617. * @param string $title Formatted title of the field. Shown as the label for the field during output.
  2618. * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output.
  2619. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...).
  2620. * @param string $section The slug-name of the section of the settingss page in which to show the box (default, ...).
  2621. * @param array $args Additional arguments
  2622. */
  2623. function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
  2624. global $wp_settings_fields;
  2625. if ( 'misc' == $page ) {
  2626. _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) );
  2627. $page = 'general';
  2628. }
  2629. if ( !isset($wp_settings_fields) )
  2630. $wp_settings_fields = array();
  2631. if ( !isset($wp_settings_fields[$page]) )
  2632. $wp_settings_fields[$page] = array();
  2633. if ( !isset($wp_settings_fields[$page][$section]) )
  2634. $wp_settings_fields[$page][$section] = array();
  2635. $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
  2636. }
  2637. /**
  2638. * Prints out all settings sections added to a particular settings page
  2639. *
  2640. * Part of the Settings API. Use this in a settings page callback function
  2641. * to output all the sections and fields that were added to that $page with
  2642. * add_settings_section() and add_settings_field()
  2643. *
  2644. * @global $wp_settings_sections Storage array of all settings sections added to admin pages
  2645. * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections
  2646. * @since unknown
  2647. *
  2648. * @param string $page The slug name of the page whos settings sections you want to output
  2649. */
  2650. function do_settings_sections($page) {
  2651. global $wp_settings_sections, $wp_settings_fields;
  2652. if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
  2653. return;
  2654. foreach ( (array) $wp_settings_sections[$page] as $section ) {
  2655. echo "<h3>{$section['title']}</h3>\n";
  2656. call_user_func($section['callback'], $section);
  2657. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
  2658. continue;
  2659. echo '<table class="form-table">';
  2660. do_settings_fields($page, $section['id']);
  2661. echo '</table>';
  2662. }
  2663. }
  2664. /**
  2665. * Print out the settings fields for a particular settings section
  2666. *
  2667. * Part of the Settings API. Use this in a settings page to output
  2668. * a specific section. Should normally be called by do_settings_sections()
  2669. * rather than directly.
  2670. *
  2671. * @global $wp_settings_fields Storage array of settings fields and their pages/sections
  2672. *
  2673. * @since unknown
  2674. *
  2675. * @param string $page Slug title of the admin page who's settings fields you want to show.
  2676. * @param section $section Slug title of the settings section who's fields you want to show.
  2677. */
  2678. function do_settings_fields($page, $section) {
  2679. global $wp_settings_fields;
  2680. if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
  2681. return;
  2682. foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
  2683. echo '<tr valign="top">';
  2684. if ( !empty($field['args']['label_for']) )
  2685. echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
  2686. else
  2687. echo '<th scope="row">' . $field['title'] . '</th>';
  2688. echo '<td>';
  2689. call_user_func($field['callback'], $field['args']);
  2690. echo '</td>';
  2691. echo '</tr>';
  2692. }
  2693. }
  2694. /**
  2695. * Register a settings error to be displayed to the user
  2696. *
  2697. * Part of the Settings API. Use this to show messages to users about settings validation
  2698. * problems, missing settings or anything else.
  2699. *
  2700. * Settings errors should be added inside the $sanitize_callback function defined in
  2701. * register_setting() for a given setting to give feedback about the submission.
  2702. *
  2703. * By default messages will show immediately after the submission that generated the error.
  2704. * Additional calls to settings_errors() can be used to show errors even when the settings
  2705. * page is first accessed.
  2706. *
  2707. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  2708. *
  2709. * @param string $setting Slug title of the setting to which this error applies
  2710. * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
  2711. * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>)
  2712. * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'.
  2713. */
  2714. function add_settings_error( $setting, $code, $message, $type = 'error' ) {
  2715. global $wp_settings_errors;
  2716. if ( !isset($wp_settings_errors) )
  2717. $wp_settings_errors = array();
  2718. $new_error = array(
  2719. 'setting' => $setting,
  2720. 'code' => $code,
  2721. 'message' => $message,
  2722. 'type' => $type
  2723. );
  2724. $wp_settings_errors[] = $new_error;
  2725. }
  2726. /**
  2727. * Fetch settings errors registered by add_settings_error()
  2728. *
  2729. * Checks the $wp_settings_errors array for any errors declared during the current
  2730. * pageload and returns them.
  2731. *
  2732. * If changes were just submitted ($_GET['updated']) and settings errors were saved
  2733. * to the 'settings_errors' transient then those errors will be returned instead. This
  2734. * is used to pass errors back across pageloads.
  2735. *
  2736. * Use the $sanitize argument to manually re-sanitize the option before returning errors.
  2737. * This is useful if you have errors or notices you want to show even when the user
  2738. * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook)
  2739. *
  2740. * @global array $wp_settings_errors Storage array of errors registered during this pageload
  2741. *
  2742. * @param string $setting Optional slug title of a specific setting who's errors you want.
  2743. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  2744. * @return array Array of settings errors
  2745. */
  2746. function get_settings_errors( $setting = '', $sanitize = FALSE ) {
  2747. global $wp_settings_errors;
  2748. // If $sanitize is true, manually re-run the sanitizisation for this option
  2749. // This allows the $sanitize_callback from register_setting() to run, adding
  2750. // any settings errors you want to show by default.
  2751. if ( $sanitize )
  2752. sanitize_option( $setting, get_option($setting));
  2753. // If settings were passed back from options.php then use them
  2754. // Ignore transients if $sanitize is true, we dont' want the old values anyway
  2755. if ( isset($_GET['updated']) && $_GET['updated'] && get_transient('settings_errors') ) {
  2756. $settings_errors = get_transient('settings_errors');
  2757. delete_transient('settings_errors');
  2758. // Otherwise check global in case validation has been run on this pageload
  2759. } elseif ( count( $wp_settings_errors ) ) {
  2760. $settings_errors = $wp_settings_errors;
  2761. } else {
  2762. return;
  2763. }
  2764. // Filter the results to those of a specific setting if one was set
  2765. if ( $setting ) {
  2766. foreach ( (array) $settings_errors as $key => $details )
  2767. if ( $setting != $details['setting'] )
  2768. unset( $settings_errors[$key] );
  2769. }
  2770. return $settings_errors;
  2771. }
  2772. /**
  2773. * Display settings errors registered by add_settings_error()
  2774. *
  2775. * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors().
  2776. *
  2777. * This is called automatically after a settings page based on the Settings API is submitted.
  2778. * Errors should be added during the validation callback function for a setting defined in register_setting()
  2779. *
  2780. * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization
  2781. * on its current value.
  2782. *
  2783. * The $hide_on_update option will cause errors to only show when the settings page is first loaded.
  2784. * if the user has already saved new values it will be hidden to avoid repeating messages already
  2785. * shown in the default error reporting after submission. This is useful to show general errors like missing
  2786. * settings when the user arrives at the settings page.
  2787. *
  2788. * @param string $setting Optional slug title of a specific setting who's errors you want.
  2789. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
  2790. * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted.
  2791. * @return <type>
  2792. */
  2793. function settings_errors ( $setting = '', $sanitize = FALSE, $hide_on_update = FALSE ) {
  2794. if ($hide_on_update AND $_GET['updated']) return;
  2795. $settings_errors = get_settings_errors( $setting, $sanitize );
  2796. if ( !is_array($settings_errors) ) return;
  2797. $output = '';
  2798. foreach ( $settings_errors as $key => $details ) {
  2799. $css_id = 'setting-error-' . $details['code'];
  2800. $css_class = $details['type'] . ' settings-error';
  2801. $output .= "<div id='$css_id' class='$css_class'> \n";
  2802. $output .= "<p><strong>{$details['message']}</strong></p>";
  2803. $output .= "</div> \n";
  2804. }
  2805. echo $output;
  2806. }
  2807. /**
  2808. * {@internal Missing Short Description}}
  2809. *
  2810. * @since unknown
  2811. *
  2812. * @param unknown_type $page
  2813. */
  2814. function manage_columns_prefs($page) {
  2815. $columns = get_column_headers($page);
  2816. $hidden = get_hidden_columns($page);
  2817. foreach ( $columns as $column => $title ) {
  2818. // Can't hide these
  2819. if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'username' == $column || 'media' == $column || 'comment' == $column )
  2820. continue;
  2821. if ( empty($title) )
  2822. continue;
  2823. if ( 'comments' == $column )
  2824. $title = __('Comments');
  2825. $id = "$column-hide";
  2826. echo '<label for="' . $id . '">';
  2827. echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
  2828. echo "$title</label>\n";
  2829. }
  2830. }
  2831. /**
  2832. * {@internal Missing Short Description}}
  2833. *
  2834. * @since unknown
  2835. *
  2836. * @param unknown_type $found_action
  2837. */
  2838. function find_posts_div($found_action = '') {
  2839. ?>
  2840. <div id="find-posts" class="find-box" style="display:none;">
  2841. <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
  2842. <div class="find-box-inside">
  2843. <div class="find-box-search">
  2844. <?php if ( $found_action ) { ?>
  2845. <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
  2846. <?php } ?>
  2847. <input type="hidden" name="affected" id="affected" value="" />
  2848. <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
  2849. <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
  2850. <input type="text" id="find-posts-input" name="ps" value="" />
  2851. <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
  2852. <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
  2853. <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
  2854. <input type="radio" name="find-posts-what" id="find-posts-pages" value="pages" />
  2855. <label for="find-posts-pages"><?php _e( 'Pages' ); ?></label>
  2856. </div>
  2857. <div id="find-posts-response"></div>
  2858. </div>
  2859. <div class="find-box-buttons">
  2860. <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
  2861. <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
  2862. </div>
  2863. </div>
  2864. <?php
  2865. }
  2866. /**
  2867. * Display the post password.
  2868. *
  2869. * The password is passed through {@link esc_attr()} to ensure that it
  2870. * is safe for placing in an html attribute.
  2871. *
  2872. * @uses attr
  2873. * @since 2.7.0
  2874. */
  2875. function the_post_password() {
  2876. global $post;
  2877. if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
  2878. }
  2879. /**
  2880. * {@internal Missing Short Description}}
  2881. *
  2882. * @since unknown
  2883. */
  2884. function favorite_actions( $screen = null ) {
  2885. global $post_type_object;
  2886. $default_action = false;
  2887. if ( is_string($screen) )
  2888. $screen = convert_to_screen($screen);
  2889. if ( isset($post_type_object) ) {
  2890. switch ( $screen->id ) {
  2891. case $post_type_object->name:
  2892. $default_action = array('edit.php?post_type=' . $post_type_object->name => array(sprintf(__('Edit %s'), $post_type_object->label), $post_type_object->edit_type_cap));
  2893. break;
  2894. case "edit-{$post_type_object->name}":
  2895. $default_action = array('post-new.php?post_type=' . $post_type_object->name => array(sprintf(__('New %s'), $post_type_object->singular_label), $post_type_object->edit_type_cap));
  2896. break;
  2897. }
  2898. }
  2899. if ( !$default_action ) {
  2900. switch ( $screen->id ) {
  2901. case 'upload':
  2902. $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
  2903. break;
  2904. case 'media':
  2905. $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
  2906. break;
  2907. case 'link-manager':
  2908. $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
  2909. break;
  2910. case 'link-add':
  2911. $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
  2912. break;
  2913. case 'users':
  2914. $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
  2915. break;
  2916. case 'user':
  2917. $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
  2918. break;
  2919. case 'plugins':
  2920. $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
  2921. break;
  2922. case 'plugin-install':
  2923. $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
  2924. break;
  2925. case 'themes':
  2926. $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
  2927. break;
  2928. case 'theme-install':
  2929. $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
  2930. break;
  2931. default:
  2932. $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
  2933. break;
  2934. }
  2935. }
  2936. $actions = array(
  2937. 'post-new.php' => array(__('New Post'), 'edit_posts'),
  2938. 'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
  2939. 'post-new.php?post_type=page' => array(__('New Page'), 'edit_pages'),
  2940. 'media-new.php' => array(__('Upload'), 'upload_files'),
  2941. 'edit-comments.php' => array(__('Comments'), 'moderate_comments')
  2942. );
  2943. $default_key = array_keys($default_action);
  2944. $default_key = $default_key[0];
  2945. if ( isset($actions[$default_key]) )
  2946. unset($actions[$default_key]);
  2947. $actions = array_merge($default_action, $actions);
  2948. $actions = apply_filters('favorite_actions', $actions);
  2949. $allowed_actions = array();
  2950. foreach ( $actions as $action => $data ) {
  2951. if ( current_user_can($data[1]) )
  2952. $allowed_actions[$action] = $data[0];
  2953. }
  2954. if ( empty($allowed_actions) )
  2955. return;
  2956. $first = array_keys($allowed_actions);
  2957. $first = $first[0];
  2958. echo '<div id="favorite-actions">';
  2959. echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
  2960. echo '<div id="favorite-inside">';
  2961. array_shift($allowed_actions);
  2962. foreach ( $allowed_actions as $action => $label) {
  2963. echo "<div class='favorite-action'><a href='$action'>";
  2964. echo $label;
  2965. echo "</a></div>\n";
  2966. }
  2967. echo "</div></div>\n";
  2968. }
  2969. /**
  2970. * Get the post title.
  2971. *
  2972. * The post title is fetched and if it is blank then a default string is
  2973. * returned.
  2974. *
  2975. * @since 2.7.0
  2976. * @param int $id The post id. If not supplied the global $post is used.
  2977. *
  2978. */
  2979. function _draft_or_post_title($post_id = 0) {
  2980. $title = get_the_title($post_id);
  2981. if ( empty($title) )
  2982. $title = __('(no title)');
  2983. return $title;
  2984. }
  2985. /**
  2986. * Display the search query.
  2987. *
  2988. * A simple wrapper to display the "s" parameter in a GET URI. This function
  2989. * should only be used when {@link the_search_query()} cannot.
  2990. *
  2991. * @uses attr
  2992. * @since 2.7.0
  2993. *
  2994. */
  2995. function _admin_search_query() {
  2996. echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
  2997. }
  2998. /**
  2999. * Generic Iframe header for use with Thickbox
  3000. *
  3001. * @since 2.7.0
  3002. * @param string $title Title of the Iframe page.
  3003. * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
  3004. *
  3005. */
  3006. function iframe_header( $title = '', $limit_styles = false ) {
  3007. global $hook_suffix;
  3008. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3009. <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
  3010. <head>
  3011. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
  3012. <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
  3013. <?php
  3014. wp_enqueue_style( 'global' );
  3015. if ( ! $limit_styles )
  3016. wp_enqueue_style( 'wp-admin' );
  3017. wp_enqueue_style( 'colors' );
  3018. ?>
  3019. <script type="text/javascript">
  3020. //<![CDATA[
  3021. addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
  3022. function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
  3023. //]]>
  3024. </script>
  3025. <?php
  3026. do_action('admin_print_styles');
  3027. do_action('admin_print_scripts');
  3028. do_action('admin_head');
  3029. $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
  3030. ?>
  3031. </head>
  3032. <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="no-js <?php echo $admin_body_class; ?>">
  3033. <script type="text/javascript">
  3034. //<![CDATA[
  3035. (function(){
  3036. var c = document.body.className;
  3037. c = c.replace(/no-js/, 'js');
  3038. document.body.className = c;
  3039. })();
  3040. //]]>
  3041. </script>
  3042. <?php
  3043. }
  3044. /**
  3045. * Generic Iframe footer for use with Thickbox
  3046. *
  3047. * @since 2.7.0
  3048. *
  3049. */
  3050. function iframe_footer() {
  3051. //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
  3052. <div class="hidden">
  3053. <?php
  3054. do_action('admin_footer', '');
  3055. do_action('admin_print_footer_scripts'); ?>
  3056. </div>
  3057. <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
  3058. </body>
  3059. </html>
  3060. <?php
  3061. }
  3062. function _post_states($post) {
  3063. $post_states = array();
  3064. if ( isset($_GET['post_status']) )
  3065. $post_status = $_GET['post_status'];
  3066. else
  3067. $post_status = '';
  3068. if ( !empty($post->post_password) )
  3069. $post_states[] = __('Password protected');
  3070. if ( 'private' == $post->post_status && 'private' != $post_status )
  3071. $post_states[] = __('Private');
  3072. if ( 'draft' == $post->post_status && 'draft' != $post_status )
  3073. $post_states[] = __('Draft');
  3074. if ( 'pending' == $post->post_status && 'pending' != $post_status )
  3075. /* translators: post state */
  3076. $post_states[] = _x('Pending', 'post state');
  3077. if ( is_sticky($post->ID) )
  3078. $post_states[] = __('Sticky');
  3079. $post_states = apply_filters( 'display_post_states', $post_states );
  3080. if ( ! empty($post_states) ) {
  3081. $state_count = count($post_states);
  3082. $i = 0;
  3083. echo ' - ';
  3084. foreach ( $post_states as $state ) {
  3085. ++$i;
  3086. ( $i == $state_count ) ? $sep = '' : $sep = ', ';
  3087. echo "<span class='post-state'>$state$sep</span>";
  3088. }
  3089. }
  3090. }
  3091. // Convert a screen string to a screen object
  3092. function convert_to_screen( $screen ) {
  3093. $screen = str_replace('.php', '', $screen);
  3094. $screen = str_replace('-new', '', $screen);
  3095. $screen = str_replace('-add', '', $screen);
  3096. $screen = apply_filters('screen_meta_screen', $screen);
  3097. $screen = array('id' => $screen, 'base' => $screen);
  3098. return (object) $screen;
  3099. }
  3100. function screen_meta($screen) {
  3101. global $wp_meta_boxes, $_wp_contextual_help, $title;
  3102. if ( is_string($screen) )
  3103. $screen = convert_to_screen($screen);
  3104. $column_screens = get_column_headers($screen);
  3105. $meta_screens = array('index' => 'dashboard');
  3106. if ( isset($meta_screens[$screen->id]) ) {
  3107. $screen->id = $meta_screens[$screen->id];
  3108. $screen->base = $screen->id;
  3109. }
  3110. $show_screen = false;
  3111. if ( !empty($wp_meta_boxes[$screen->id]) || !empty($column_screens) )
  3112. $show_screen = true;
  3113. $screen_options = screen_options($screen);
  3114. if ( $screen_options )
  3115. $show_screen = true;
  3116. if ( !isset($_wp_contextual_help) )
  3117. $_wp_contextual_help = array();
  3118. $settings = apply_filters('screen_settings', '', $screen);
  3119. switch ( $screen->id ) {
  3120. case 'widgets':
  3121. $settings = '<p><a id="access-on" href="widgets.php?widgets-access=on">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off">' . __('Disable accessibility mode') . "</a></p>\n";
  3122. break;
  3123. }
  3124. if( $settings )
  3125. $show_screen = true;
  3126. ?>
  3127. <div id="screen-meta">
  3128. <?php
  3129. if ( $show_screen ) :
  3130. $default_text = __('Show on screen');
  3131. ?>
  3132. <div id="screen-options-wrap" class="hidden">
  3133. <form id="adv-settings" action="" method="post">
  3134. <?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
  3135. <h5><?php echo apply_filters('meta_box_prefs_header', $default_text); ?></h5>
  3136. <div class="metabox-prefs">
  3137. <?php meta_box_prefs($screen); ?>
  3138. <br class="clear" />
  3139. </div>
  3140. <?php endif;
  3141. if ( isset($column_screens) ) : ?>
  3142. <h5><?php echo apply_filters('columns_prefs_header', $default_text); ?></h5>
  3143. <div class="metabox-prefs">
  3144. <?php manage_columns_prefs($screen); ?>
  3145. <br class="clear" />
  3146. </div>
  3147. <?php endif;
  3148. echo screen_layout($screen);
  3149. echo $screen_options;
  3150. echo $settings; ?>
  3151. <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
  3152. </form>
  3153. </div>
  3154. <?php
  3155. endif;
  3156. $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
  3157. ?>
  3158. <div id="contextual-help-wrap" class="hidden">
  3159. <?php
  3160. $contextual_help = '';
  3161. if ( isset($_wp_contextual_help[$screen->id]) ) {
  3162. if ( !empty($title) )
  3163. $contextual_help .= '<h5>' . sprintf(__('Get help with &#8220;%s&#8221;'), $title) . '</h5>';
  3164. else
  3165. $contextual_help .= '<h5>' . __('Get help with this page') . '</h5>';
  3166. $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen->id] . "</div>\n";
  3167. $contextual_help .= '<h5>' . __('Other Help') . '</h5>';
  3168. } else {
  3169. $contextual_help .= '<h5>' . __('Help') . '</h5>';
  3170. }
  3171. $contextual_help .= '<div class="metabox-prefs">';
  3172. $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
  3173. $default_help .= '<br />';
  3174. $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
  3175. $contextual_help .= apply_filters('default_contextual_help', $default_help);
  3176. $contextual_help .= "</div>\n";
  3177. echo apply_filters('contextual_help', $contextual_help, $screen->id, $screen);
  3178. ?>
  3179. </div>
  3180. <div id="screen-meta-links">
  3181. <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
  3182. <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
  3183. </div>
  3184. <?php if ( $show_screen ) { ?>
  3185. <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
  3186. <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
  3187. </div>
  3188. <?php } ?>
  3189. </div>
  3190. </div>
  3191. <?php
  3192. }
  3193. /**
  3194. * Add contextual help text for a page
  3195. *
  3196. * @since 2.7.0
  3197. *
  3198. * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  3199. * @param string $help Arbitrary help text
  3200. */
  3201. function add_contextual_help($screen, $help) {
  3202. global $_wp_contextual_help;
  3203. if ( is_string($screen) )
  3204. $screen = convert_to_screen($screen);
  3205. if ( !isset($_wp_contextual_help) )
  3206. $_wp_contextual_help = array();
  3207. $_wp_contextual_help[$screen->id] = $help;
  3208. }
  3209. function drag_drop_help() {
  3210. return '
  3211. <p>' . __('Most of the modules on this screen can be moved. If you hover your mouse over the title bar of a module you&rsquo;ll notice the 4 arrow cursor appears to let you know it is movable. Click on it, hold down the mouse button and start dragging the module to a new location. As you drag the module, notice the dotted gray box that also moves. This box indicates where the module will be placed when you release the mouse button.') . '</p>
  3212. <p>' . __('The same modules can be expanded and collapsed by clicking once on their title bar and also completely hidden from the Screen Options tab.') . '</p>
  3213. ';
  3214. }
  3215. function plugins_search_help() {
  3216. return '
  3217. <p><strong>' . __('Search help') . '</strong></p>' .
  3218. '<p>' . __('You may search based on 3 criteria:') . '<br />' .
  3219. __('<strong>Term:</strong> Searches theme names and descriptions for the specified term.') . '<br />' .
  3220. __('<strong>Tag:</strong> Searches for themes tagged as such.') . '<br />' .
  3221. __('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') . '</p>
  3222. ';
  3223. }
  3224. function screen_layout($screen) {
  3225. global $screen_layout_columns;
  3226. if ( is_string($screen) )
  3227. $screen = convert_to_screen($screen);
  3228. $columns = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2);
  3229. // Add custom post types
  3230. foreach ( get_post_types( array('show_ui' => true) ) as $post_type )
  3231. $columns[$post_type] = 2;
  3232. $columns = apply_filters('screen_layout_columns', $columns, $screen->id, $screen);
  3233. if ( !isset($columns[$screen->id]) ) {
  3234. $screen_layout_columns = 0;
  3235. return '';
  3236. }
  3237. $screen_layout_columns = get_user_option("screen_layout_$screen->id");
  3238. $num = $columns[$screen->id];
  3239. if ( ! $screen_layout_columns )
  3240. $screen_layout_columns = 2;
  3241. $i = 1;
  3242. $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
  3243. while ( $i <= $num ) {
  3244. $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
  3245. ++$i;
  3246. }
  3247. $return .= "</div>\n";
  3248. return $return;
  3249. }
  3250. function screen_options($screen) {
  3251. if ( is_string($screen) )
  3252. $screen = convert_to_screen($screen);
  3253. switch ( $screen->base ) {
  3254. case 'edit':
  3255. case 'edit-pages':
  3256. $post_type = 'post';
  3257. if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
  3258. $post_type = $_GET['post_type'];
  3259. $post_type_object = get_post_type_object($post_type);
  3260. $per_page_label = $post_type_object->label;
  3261. break;
  3262. case 'ms-sites':
  3263. $per_page_label = __('Sites');
  3264. break;
  3265. case 'ms-users':
  3266. $per_page_label = __('Users');
  3267. break;
  3268. case 'edit-comments':
  3269. $per_page_label = __('Comments');
  3270. break;
  3271. case 'upload':
  3272. $per_page_label = __('Media items');
  3273. break;
  3274. case 'edit-tags':
  3275. global $tax;
  3276. $per_page_label = $tax->label;
  3277. break;
  3278. case 'plugins':
  3279. $per_page_label = __('Plugins');
  3280. break;
  3281. default:
  3282. return '';
  3283. }
  3284. $option = str_replace( '-', '_', "{$screen->id}_per_page" );
  3285. if ( 'edit_tags_per_page' == $option ) {
  3286. if ( 'category' == $tax->name )
  3287. $option = 'categories_per_page';
  3288. elseif ( 'post_tag' != $tax->name )
  3289. $option = 'edit_' . $tax->name . '_per_page';
  3290. }
  3291. $per_page = (int) get_user_option( $option );
  3292. if ( empty( $per_page ) || $per_page < 1 ) {
  3293. if ( 'plugins' == $screen->id )
  3294. $per_page = 999;
  3295. else
  3296. $per_page = 20;
  3297. }
  3298. if ( 'edit_comments_per_page' == $option )
  3299. $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
  3300. elseif ( 'categories_per_page' == $option )
  3301. $per_page = apply_filters( 'edit_categories_per_page', $per_page );
  3302. else
  3303. $per_page = apply_filters( $option, $per_page );
  3304. $return = "<div class='screen-options'>\n";
  3305. if ( !empty($per_page_label) )
  3306. $return .= "<input type='text' class='screen-per-page' name='wp_screen_options[value]' id='$option' maxlength='3' value='$per_page' /> <label for='$option'>$per_page_label</label>\n";
  3307. $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
  3308. $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
  3309. $return .= "</div>\n";
  3310. return $return;
  3311. }
  3312. function screen_icon($screen = '') {
  3313. global $current_screen;
  3314. if ( empty($screen) )
  3315. $screen = $current_screen;
  3316. elseif ( is_string($screen) )
  3317. $name = $screen;
  3318. if ( empty($name) ) {
  3319. if ( !empty($screen->parent_base) )
  3320. $name = $screen->parent_base;
  3321. else
  3322. $name = $screen->base;
  3323. if ( 'edit' == $name && isset($screen->post_type) && 'page' == $screen->post_type )
  3324. $name = 'edit-pages';
  3325. }
  3326. ?>
  3327. <div id="icon-<?php echo $name; ?>" class="icon32"><br /></div>
  3328. <?php
  3329. }
  3330. /**
  3331. * Test support for compressing JavaScript from PHP
  3332. *
  3333. * Outputs JavaScript that tests if compression from PHP works as expected
  3334. * and sets an option with the result. Has no effect when the current user
  3335. * is not an administrator. To run the test again the option 'can_compress_scripts'
  3336. * has to be deleted.
  3337. *
  3338. * @since 2.8.0
  3339. */
  3340. function compression_test() {
  3341. ?>
  3342. <script type="text/javascript">
  3343. /* <![CDATA[ */
  3344. var testCompression = {
  3345. get : function(test) {
  3346. var x;
  3347. if ( window.XMLHttpRequest ) {
  3348. x = new XMLHttpRequest();
  3349. } else {
  3350. try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
  3351. }
  3352. if (x) {
  3353. x.onreadystatechange = function() {
  3354. var r, h;
  3355. if ( x.readyState == 4 ) {
  3356. r = x.responseText.substr(0, 18);
  3357. h = x.getResponseHeader('Content-Encoding');
  3358. testCompression.check(r, h, test);
  3359. }
  3360. }
  3361. x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
  3362. x.send('');
  3363. }
  3364. },
  3365. check : function(r, h, test) {
  3366. if ( ! r && ! test )
  3367. this.get(1);
  3368. if ( 1 == test ) {
  3369. if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
  3370. this.get('no');
  3371. else
  3372. this.get(2);
  3373. return;
  3374. }
  3375. if ( 2 == test ) {
  3376. if ( '"wpCompressionTest' == r )
  3377. this.get('yes');
  3378. else
  3379. this.get('no');
  3380. }
  3381. }
  3382. };
  3383. testCompression.check();
  3384. /* ]]> */
  3385. </script>
  3386. <?php
  3387. }
  3388. /**
  3389. * Set the current screen object
  3390. *
  3391. * @since 3.0.0
  3392. *
  3393. * @uses $current_screen
  3394. *
  3395. * @param string $id Screen id, optional.
  3396. */
  3397. function set_current_screen( $id = '' ) {
  3398. global $current_screen, $hook_suffix, $typenow;
  3399. if ( empty($id) ) {
  3400. $current_screen = $hook_suffix;
  3401. $current_screen = str_replace('.php', '', $current_screen);
  3402. $current_screen = str_replace('-new', '', $current_screen);
  3403. $current_screen = str_replace('-add', '', $current_screen);
  3404. $current_screen = array('id' => $current_screen, 'base' => $current_screen);
  3405. } else {
  3406. if ( false !== strpos($id, '-') )
  3407. list( $id, $typenow ) = explode('-', $id, 2);
  3408. $current_screen = array('id' => $id, 'base' => $id);
  3409. }
  3410. $current_screen = (object) $current_screen;
  3411. // Map index to dashboard
  3412. if ( 'index' == $current_screen->base )
  3413. $current_screen->base = 'dashboard';
  3414. if ( 'index' == $current_screen->id )
  3415. $current_screen->id = 'dashboard';
  3416. if ( 'edit' == $current_screen->id ) {
  3417. if ( empty($typenow) )
  3418. $typenow = 'post';
  3419. $current_screen->id .= '-' . $typenow;
  3420. $current_screen->post_type = $typenow;
  3421. } elseif ( 'post' == $current_screen->id ) {
  3422. if ( empty($typenow) )
  3423. $typenow = 'post';
  3424. $current_screen->id = $typenow;
  3425. $current_screen->post_type = $typenow;
  3426. }
  3427. $current_screen = apply_filters('current_screen', $current_screen);
  3428. }
  3429. ?>