[ Root ] [ Index ]

PHP Cross Reference of WordPress 2.9

Provided by Yoast

title

Body

[close]

/wp-admin/includes/ -> template.php (source)

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


Generated: Wed Jan 27 21:34:27 2010 Cross-referenced by PHPXref 0.7