PageRenderTime 48ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

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