[ Index ]

PHP Cross Reference of Wordpress 2.9.1

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          $comment_url = esc_url(get_comment_link($comment->comment_ID));
2118          $approve_url = esc_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2119          $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
2120          $spam_url = esc_url( "comment.php?action=spamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2121          $unspam_url = esc_url( "comment.php?action=unspamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2122          $trash_url = esc_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2123          $untrash_url = esc_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2124          $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
2125      }
2126  
2127      echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
2128      $columns = get_column_headers('edit-comments');
2129      $hidden = get_hidden_columns('edit-comments');
2130      foreach ( $columns as $column_name => $column_display_name ) {
2131          $class = "class=\"$column_name column-$column_name\"";
2132  
2133          $style = '';
2134          if ( in_array($column_name, $hidden) )
2135              $style = ' style="display:none;"';
2136  
2137          $attributes = "$class$style";
2138  
2139          switch ($column_name) {
2140              case 'cb':
2141                  if ( !$checkbox ) break;
2142                  echo '<th scope="row" class="check-column">';
2143                  if ( $user_can ) echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
2144                  echo '</th>';
2145                  break;
2146              case 'comment':
2147                  echo "<td $attributes>";
2148                  echo '<div id="submitted-on">';
2149                  printf(__('Submitted on <a href="%1$s">%2$s at %3$s</a>'), $comment_url, get_comment_date(__('Y/m/d')), get_comment_date(__('g:ia')));
2150                  echo '</div>';
2151                  comment_text();
2152                  if ( $user_can ) { ?>
2153                  <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
2154                  <textarea class="comment" rows="1" cols="1"><?php echo htmlspecialchars( apply_filters('comment_edit_pre', $comment->comment_content), ENT_QUOTES ); ?></textarea>
2155                  <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
2156                  <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
2157                  <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
2158                  <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
2159                  </div>
2160                  <?php
2161                  }
2162  
2163                  if ( $user_can ) {
2164                      // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
2165                      $actions = array(
2166                          'approve' => '', 'unapprove' => '',
2167                          'reply' => '',
2168                          'quickedit' => '',
2169                          'edit' => '',
2170                          'spam' => '', 'unspam' => '',
2171                          'trash' => '', 'untrash' => '', 'delete' => ''
2172                      );
2173  
2174                      if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
2175                          if ( 'approved' == $the_comment_status )
2176                              $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
2177                          else if ( 'unapproved' == $the_comment_status )
2178                              $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
2179                      } else {
2180                          $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
2181                          $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
2182                      }
2183  
2184                      if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
2185                          $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
2186                      } elseif ( 'spam' == $the_comment_status ) {
2187                          $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>';
2188                      } elseif ( 'trash' == $the_comment_status ) {
2189                          $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
2190                      }
2191  
2192                      if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
2193                          $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>';
2194                      } else {
2195                          $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
2196                      }
2197  
2198                      if ( 'trash' != $the_comment_status ) {
2199                          $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
2200                          $actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.esc_attr__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
2201                          if ( 'spam' != $the_comment_status )
2202                              $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
2203                      }
2204  
2205                      $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
2206  
2207                      $i = 0;
2208                      echo '<div class="row-actions">';
2209                      foreach ( $actions as $action => $link ) {
2210                          ++$i;
2211                          ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
2212  
2213                          // Reply and quickedit need a hide-if-no-js span when not added with ajax
2214                          if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
2215                              $action .= ' hide-if-no-js';
2216                          elseif ( ($action == 'untrash' && $the_comment_status == 'trash') || ($action == 'unspam' && $the_comment_status == 'spam') ) {
2217                              if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
2218                                  $action .= ' approve';
2219                              else
2220                                  $action .= ' unapprove';
2221                          }
2222  
2223                          echo "<span class='$action'>$sep$link</span>";
2224                      }
2225                      echo '</div>';
2226                  }
2227  
2228                  echo '</td>';
2229                  break;
2230              case 'author':
2231                  echo "<td $attributes><strong>"; comment_author(); echo '</strong><br />';
2232                  if ( !empty($author_url) )
2233                      echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
2234                  if ( $user_can ) {
2235                      if ( !empty($comment->comment_author_email) ) {
2236                          comment_author_email_link();
2237                          echo '<br />';
2238                      }
2239                      echo '<a href="edit-comments.php?s=';
2240                      comment_author_IP();
2241                      echo '&amp;mode=detail';
2242                      if ( 'spam' == $comment_status )
2243                          echo '&amp;comment_status=spam';
2244                      echo '">';
2245                      comment_author_IP();
2246                      echo '</a>';
2247                  } //current_user_can
2248                  echo '</td>';
2249                  break;
2250              case 'date':
2251                  echo "<td $attributes>" . get_comment_date(__('Y/m/d \a\t g:ia')) . '</td>';
2252                  break;
2253              case 'response':
2254                  if ( 'single' !== $mode ) {
2255                      if ( isset( $_comment_pending_count[$post->ID] ) ) {
2256                          $pending_comments = absint( $_comment_pending_count[$post->ID] );
2257                      } else {
2258                          $_comment_pending_count_temp = (array) get_pending_comments_num( array( $post->ID ) );
2259                          $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
2260                      }
2261                      if ( $user_can ) {
2262                          $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>";
2263                          $post_link .= get_the_title($post->ID) . '</a>';
2264                      } else {
2265                          $post_link = get_the_title($post->ID);
2266                      }
2267                      echo "<td $attributes>\n";
2268                      echo '<div class="response-links"><span class="post-com-count-wrapper">';
2269                      echo $post_link . '<br />';
2270                      $pending_phrase = esc_attr(sprintf( __('%s pending'), number_format( $pending_comments ) ));
2271                      if ( $pending_comments )
2272                          echo '<strong>';
2273                      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>');
2274                      if ( $pending_comments )
2275                          echo '</strong>';
2276                      echo '</span> ';
2277                      echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
2278                      echo '</div>';
2279                      if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) )
2280                          echo $thumb;
2281                      echo '</td>';
2282                  }
2283                  break;
2284              default:
2285                  echo "<td $attributes>\n";
2286                  do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
2287                  echo "</td>\n";
2288                  break;
2289          }
2290      }
2291      echo "</tr>\n";
2292  }
2293  
2294  /**
2295   * {@internal Missing Short Description}}
2296   *
2297   * @since unknown
2298   *
2299   * @param unknown_type $position
2300   * @param unknown_type $checkbox
2301   * @param unknown_type $mode
2302   */
2303  function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
2304      global $current_user;
2305  
2306      // allow plugin to replace the popup content
2307      $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
2308  
2309      if ( ! empty($content) ) {
2310          echo $content;
2311          return;
2312      }
2313  
2314      $columns = get_column_headers('edit-comments');
2315      $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns('edit-comments') ) );
2316      $col_count = count($columns) - count($hidden);
2317  
2318  ?>
2319  <form method="get" action="">
2320  <?php if ( $table_row ) : ?>
2321  <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $col_count; ?>">
2322  <?php else : ?>
2323  <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
2324  <?php endif; ?>
2325      <div id="replyhead" style="display:none;"><?php _e('Reply to Comment'); ?></div>
2326  
2327      <div id="edithead" style="display:none;">
2328          <div class="inside">
2329          <label for="author"><?php _e('Name') ?></label>
2330          <input type="text" name="newcomment_author" size="50" value="" tabindex="101" id="author" />
2331          </div>
2332  
2333          <div class="inside">
2334          <label for="author-email"><?php _e('E-mail') ?></label>
2335          <input type="text" name="newcomment_author_email" size="50" value="" tabindex="102" id="author-email" />
2336          </div>
2337  
2338          <div class="inside">
2339          <label for="author-url"><?php _e('URL') ?></label>
2340          <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" tabindex="103" />
2341          </div>
2342          <div style="clear:both;"></div>
2343      </div>
2344  
2345      <div id="replycontainer"><textarea rows="8" cols="40" name="replycontent" tabindex="104" id="replycontent"></textarea></div>
2346  
2347      <p id="replysubmit" class="submit">
2348      <a href="#comments-form" class="cancel button-secondary alignleft" tabindex="106"><?php _e('Cancel'); ?></a>
2349      <a href="#comments-form" class="save button-primary alignright" tabindex="104">
2350      <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span>
2351      <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a>
2352      <img class="waiting" style="display:none;" src="images/wpspin_light.gif" alt="" />
2353      <span class="error" style="display:none;"></span>
2354      <br class="clear" />
2355      </p>
2356  
2357      <input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" />
2358      <input type="hidden" name="action" id="action" value="" />
2359      <input type="hidden" name="comment_ID" id="comment_ID" value="" />
2360      <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />
2361      <input type="hidden" name="status" id="status" value="" />
2362      <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" />
2363      <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" />
2364      <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" />
2365      <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce', false ); ?>
2366      <?php wp_comment_form_unfiltered_html_nonce(); ?>
2367  <?php if ( $table_row ) : ?>
2368  </td></tr></tbody></table>
2369  <?php else : ?>
2370  </div></div>
2371  <?php endif; ?>
2372  </form>
2373  <?php
2374  }
2375  
2376  /**
2377   * Output 'undo move to trash' text for comments
2378   *
2379   * @since 2.9.0
2380   */
2381  function wp_comment_trashnotice() {
2382  ?>
2383  <div class="hidden" id="trash-undo-holder">
2384      <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>
2385  </div>
2386  <div class="hidden" id="spam-undo-holder">
2387      <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>
2388  </div>
2389  <?php
2390  }
2391  
2392  /**
2393   * {@internal Missing Short Description}}
2394   *
2395   * @since unknown
2396   *
2397   * @param unknown_type $currentcat
2398   * @param unknown_type $currentparent
2399   * @param unknown_type $parent
2400   * @param unknown_type $level
2401   * @param unknown_type $categories
2402   * @return unknown
2403   */
2404  function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
2405      if (!$categories )
2406          $categories = get_categories( array('hide_empty' => 0) );
2407  
2408      if ( $categories ) {
2409          foreach ( $categories as $category ) {
2410              if ( $currentcat != $category->term_id && $parent == $category->parent) {
2411                  $pad = str_repeat( '&#8211; ', $level );
2412                  $category->name = esc_html( $category->name );
2413                  echo "\n\t<option value='$category->term_id'";
2414                  if ( $currentparent == $category->term_id )
2415                      echo " selected='selected'";
2416                  echo ">$pad$category->name</option>";
2417                  wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
2418              }
2419          }
2420      } else {
2421          return false;
2422      }
2423  }
2424  
2425  /**
2426   * {@internal Missing Short Description}}
2427   *
2428   * @since unknown
2429   *
2430   * @param unknown_type $meta
2431   */
2432  function list_meta( $meta ) {
2433      // Exit if no meta
2434      if ( ! $meta ) {
2435          echo '
2436  <table id="list-table" style="display: none;">
2437      <thead>
2438      <tr>
2439          <th class="left">' . __( 'Name' ) . '</th>
2440          <th>' . __( 'Value' ) . '</th>
2441      </tr>
2442      </thead>
2443      <tbody id="the-list" class="list:meta">
2444      <tr><td></td></tr>
2445      </tbody>
2446  </table>'; //TBODY needed for list-manipulation JS
2447          return;
2448      }
2449      $count = 0;
2450  ?>
2451  <table id="list-table">
2452      <thead>
2453      <tr>
2454          <th class="left"><?php _e( 'Name' ) ?></th>
2455          <th><?php _e( 'Value' ) ?></th>
2456      </tr>
2457      </thead>
2458      <tbody id='the-list' class='list:meta'>
2459  <?php
2460      foreach ( $meta as $entry )
2461          echo _list_meta_row( $entry, $count );
2462  ?>
2463      </tbody>
2464  </table>
2465  <?php
2466  }
2467  
2468  /**
2469   * {@internal Missing Short Description}}
2470   *
2471   * @since unknown
2472   *
2473   * @param unknown_type $entry
2474   * @param unknown_type $count
2475   * @return unknown
2476   */
2477  function _list_meta_row( $entry, &$count ) {
2478      static $update_nonce = false;
2479      if ( !$update_nonce )
2480          $update_nonce = wp_create_nonce( 'add-meta' );
2481  
2482      $r = '';
2483      ++ $count;
2484      if ( $count % 2 )
2485          $style = 'alternate';
2486      else
2487          $style = '';
2488      if ('_' == $entry['meta_key'] { 0 } )
2489          $style .= ' hidden';
2490  
2491      if ( is_serialized( $entry['meta_value'] ) ) {
2492          if ( is_serialized_string( $entry['meta_value'] ) ) {
2493              // this is a serialized string, so we should display it
2494              $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
2495          } else {
2496              // this is a serialized array/object so we should NOT display it
2497              --$count;
2498              return;
2499          }
2500      }
2501  
2502      $entry['meta_key'] = esc_attr($entry['meta_key']);
2503      $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
2504      $entry['meta_id'] = (int) $entry['meta_id'];
2505  
2506      $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
2507  
2508      $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
2509      $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']}' />";
2510  
2511      $r .= "\n\t\t<div class='submit'><input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
2512      $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='". esc_attr__( 'Delete' ) ."' />";
2513      $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>";
2514      $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
2515      $r .= "</td>";
2516  
2517      $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>";
2518      return $r;
2519  }
2520  
2521  /**
2522   * {@internal Missing Short Description}}
2523   *
2524   * @since unknown
2525   */
2526  function meta_form() {
2527      global $wpdb;
2528      $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
2529      $keys = $wpdb->get_col( "
2530          SELECT meta_key
2531          FROM $wpdb->postmeta
2532          GROUP BY meta_key
2533          HAVING meta_key NOT LIKE '\_%'
2534          ORDER BY LOWER(meta_key)
2535          LIMIT $limit" );
2536      if ( $keys )
2537          natcasesort($keys);
2538  ?>
2539  <p><strong><?php _e( 'Add new custom field:' ) ?></strong></p>
2540  <table id="newmeta">
2541  <thead>
2542  <tr>
2543  <th class="left"><label for="metakeyselect"><?php _e( 'Name' ) ?></label></th>
2544  <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
2545  </tr>
2546  </thead>
2547  
2548  <tbody>
2549  <tr>
2550  <td id="newmetaleft" class="left">
2551  <?php if ( $keys ) { ?>
2552  <select id="metakeyselect" name="metakeyselect" tabindex="7">
2553  <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
2554  <?php
2555  
2556      foreach ( $keys as $key ) {
2557          $key = esc_attr( $key );
2558          echo "\n<option value='" . esc_attr($key) . "'>$key</option>";
2559      }
2560  ?>
2561  </select>
2562  <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2563  <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
2564  <span id="enternew"><?php _e('Enter new'); ?></span>
2565  <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
2566  <?php } else { ?>
2567  <input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
2568  <?php } ?>
2569  </td>
2570  <td><textarea id="metavalue" name="metavalue" rows="2" cols="25" tabindex="8"></textarea></td>
2571  </tr>
2572  
2573  <tr><td colspan="2" class="submit">
2574  <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php esc_attr_e( 'Add Custom Field' ) ?>" />
2575  <?php wp_nonce_field( 'add-meta', '_ajax_nonce', false ); ?>
2576  </td></tr>
2577  </tbody>
2578  </table>
2579  <?php
2580  
2581  }
2582  
2583  /**
2584   * {@internal Missing Short Description}}
2585   *
2586   * @since unknown
2587   *
2588   * @param unknown_type $edit
2589   * @param unknown_type $for_post
2590   * @param unknown_type $tab_index
2591   * @param unknown_type $multi
2592   */
2593  function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
2594      global $wp_locale, $post, $comment;
2595  
2596      if ( $for_post )
2597          $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;
2598  
2599      $tab_index_attribute = '';
2600      if ( (int) $tab_index > 0 )
2601          $tab_index_attribute = " tabindex=\"$tab_index\"";
2602  
2603      // 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 />';
2604  
2605      $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
2606      $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
2607      $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
2608      $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
2609      $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
2610      $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
2611      $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
2612      $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
2613  
2614      $cur_jj = gmdate( 'd', $time_adj );
2615      $cur_mm = gmdate( 'm', $time_adj );
2616      $cur_aa = gmdate( 'Y', $time_adj );
2617      $cur_hh = gmdate( 'H', $time_adj );
2618      $cur_mn = gmdate( 'i', $time_adj );
2619  
2620      $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n";
2621      for ( $i = 1; $i < 13; $i = $i +1 ) {
2622          $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
2623          if ( $i == $mm )
2624              $month .= ' selected="selected"';
2625          $month .= '>' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
2626      }
2627      $month .= '</select>';
2628  
2629      $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2630      $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />';
2631      $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2632      $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
2633  
2634      echo '<div class="timestamp-wrap">';
2635      /* translators: 1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input */
2636      printf(__('%1$s%2$s, %3$s @ %4$s : %5$s'), $month, $day, $year, $hour, $minute);
2637  
2638      echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
2639  
2640      if ( $multi ) return;
2641  
2642      echo "\n\n";
2643      foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) {
2644          echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
2645          $cur_timeunit = 'cur_' . $timeunit;
2646          echo '<input type="hidden" id="'. $cur_timeunit . '" name="'. $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n";
2647      }
2648  ?>
2649  
2650  <p>
2651  <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a>
2652  <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js"><?php _e('Cancel'); ?></a>
2653  </p>
2654  <?php
2655  }
2656  
2657  /**
2658   * {@internal Missing Short Description}}
2659   *
2660   * @since unknown
2661   *
2662   * @param unknown_type $default
2663   */
2664  function page_template_dropdown( $default = '' ) {
2665      $templates = get_page_templates();
2666      ksort( $templates );
2667      foreach (array_keys( $templates ) as $template )
2668          : if ( $default == $templates[$template] )
2669              $selected = " selected='selected'";
2670          else
2671              $selected = '';
2672      echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
2673      endforeach;
2674  }
2675  
2676  /**
2677   * {@internal Missing Short Description}}
2678   *
2679   * @since unknown
2680   *
2681   * @param unknown_type $default
2682   * @param unknown_type $parent
2683   * @param unknown_type $level
2684   * @return unknown
2685   */
2686  function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
2687      global $wpdb, $post_ID;
2688      $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) );
2689  
2690      if ( $items ) {
2691          foreach ( $items as $item ) {
2692              // A page cannot be its own parent.
2693              if (!empty ( $post_ID ) ) {
2694                  if ( $item->ID == $post_ID ) {
2695                      continue;
2696                  }
2697              }
2698              $pad = str_repeat( '&nbsp;', $level * 3 );
2699              if ( $item->ID == $default)
2700                  $current = ' selected="selected"';
2701              else
2702                  $current = '';
2703  
2704              echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";
2705              parent_dropdown( $default, $item->ID, $level +1 );
2706          }
2707      } else {
2708          return false;
2709      }
2710  }
2711  
2712  /**
2713   * {@internal Missing Short Description}}
2714   *
2715   * @since unknown
2716   */
2717  function browse_happy() {
2718      $getit = __( 'WordPress recommends a better browser' );
2719      echo '
2720          <div id="bh"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></div>
2721  ';
2722  }
2723  
2724  /**
2725   * {@internal Missing Short Description}}
2726   *
2727   * @since unknown
2728   *
2729   * @param unknown_type $id
2730   * @return unknown
2731   */
2732  function the_attachment_links( $id = false ) {
2733      $id = (int) $id;
2734      $post = & get_post( $id );
2735  
2736      if ( $post->post_type != 'attachment' )
2737          return false;
2738  
2739      $icon = get_attachment_icon( $post->ID );
2740      $attachment_data = wp_get_attachment_metadata( $id );
2741      $thumb = isset( $attachment_data['thumb'] );
2742  ?>
2743  <form id="the-attachment-links">
2744  <table>
2745      <col />
2746      <col class="widefat" />
2747      <tr>
2748          <th scope="row"><?php _e( 'URL' ) ?></th>
2749          <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
2750      </tr>
2751  <?php if ( $icon ) : ?>
2752      <tr>
2753          <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
2754          <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>
2755      </tr>
2756      <tr>
2757          <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
2758          <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>
2759      </tr>
2760  <?php else : ?>
2761      <tr>
2762          <th scope="row"><?php _e( 'Link to file' ) ?></th>
2763          <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>
2764      </tr>
2765      <tr>
2766          <th scope="row"><?php _e( 'Link to page' ) ?></th>
2767          <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>
2768      </tr>
2769  <?php endif; ?>
2770  </table>
2771  </form>
2772  <?php
2773  }
2774  
2775  
2776  /**
2777   * Print out <option> html elements for role selectors based on $wp_roles
2778   *
2779   * @package WordPress
2780   * @subpackage Administration
2781   * @since 2.1
2782   *
2783   * @uses $wp_roles
2784   * @param string $default slug for the role that should be already selected
2785   */
2786  function wp_dropdown_roles( $selected = false ) {
2787      global $wp_roles;
2788      $p = '';
2789      $r = '';
2790  
2791      $editable_roles = get_editable_roles();
2792  
2793      foreach( $editable_roles as $role => $details ) {
2794          $name = translate_user_role($details['name'] );
2795          if ( $selected == $role ) // Make default first in list
2796              $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
2797          else
2798              $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
2799      }
2800      echo $p . $r;
2801  }
2802  
2803  /**
2804   * {@internal Missing Short Description}}
2805   *
2806   * @since unknown
2807   *
2808   * @param unknown_type $size
2809   * @return unknown
2810   */
2811  function wp_convert_hr_to_bytes( $size ) {
2812      $size = strtolower($size);
2813      $bytes = (int) $size;
2814      if ( strpos($size, 'k') !== false )
2815          $bytes = intval($size) * 1024;
2816      elseif ( strpos($size, 'm') !== false )
2817          $bytes = intval($size) * 1024 * 1024;
2818      elseif ( strpos($size, 'g') !== false )
2819          $bytes = intval($size) * 1024 * 1024 * 1024;
2820      return $bytes;
2821  }
2822  
2823  /**
2824   * {@internal Missing Short Description}}
2825   *
2826   * @since unknown
2827   *
2828   * @param unknown_type $bytes
2829   * @return unknown
2830   */
2831  function wp_convert_bytes_to_hr( $bytes ) {
2832      $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
2833      $log = log( $bytes, 1024 );
2834      $power = (int) $log;
2835      $size = pow(1024, $log - $power);
2836      return $size . $units[$power];
2837  }
2838  
2839  /**
2840   * {@internal Missing Short Description}}
2841   *
2842   * @since unknown
2843   *
2844   * @return unknown
2845   */
2846  function wp_max_upload_size() {
2847      $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
2848      $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
2849      $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
2850      return $bytes;
2851  }
2852  
2853  /**
2854   * Outputs the form used by the importers to accept the data to be imported
2855   *
2856   * @since 2.0
2857   *
2858   * @param string $action The action attribute for the form.
2859   */
2860  function wp_import_upload_form( $action ) {
2861      $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
2862      $size = wp_convert_bytes_to_hr( $bytes );
2863      $upload_dir = wp_upload_dir();
2864      if ( ! empty( $upload_dir['error'] ) ) :
2865          ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
2866          <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php
2867      else :
2868  ?>
2869  <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
2870  <p>
2871  <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
2872  <input type="file" id="upload" name="import" size="25" />
2873  <input type="hidden" name="action" value="save" />
2874  <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
2875  </p>
2876  <p class="submit">
2877  <input type="submit" class="button" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
2878  </p>
2879  </form>
2880  <?php
2881      endif;
2882  }
2883  
2884  /**
2885   * {@internal Missing Short Description}}
2886   *
2887   * @since unknown
2888   */
2889  function wp_remember_old_slug() {
2890      global $post;
2891      $name = esc_attr($post->post_name); // just in case
2892      if ( strlen($name) )
2893          echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
2894  }
2895  
2896  /**
2897   * Add a meta box to an edit form.
2898   *
2899   * @since 2.5.0
2900   *
2901   * @param string $id String for use in the 'id' attribute of tags.
2902   * @param string $title Title of the meta box.
2903   * @param string $callback Function that fills the box with the desired content. The function should echo its output.
2904   * @param string $page The type of edit page on which to show the box (post, page, link).
2905   * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
2906   * @param string $priority The priority within the context where the boxes should show ('high', 'low').
2907   */
2908  function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
2909      global $wp_meta_boxes;
2910  
2911      if ( !isset($wp_meta_boxes) )
2912          $wp_meta_boxes = array();
2913      if ( !isset($wp_meta_boxes[$page]) )
2914          $wp_meta_boxes[$page] = array();
2915      if ( !isset($wp_meta_boxes[$page][$context]) )
2916          $wp_meta_boxes[$page][$context] = array();
2917  
2918      foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) {
2919      foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
2920          if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) )
2921              continue;
2922  
2923          // If a core box was previously added or removed by a plugin, don't add.
2924          if ( 'core' == $priority ) {
2925              // If core box previously deleted, don't add
2926              if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] )
2927                  return;
2928              // If box was added with default priority, give it core priority to maintain sort order
2929              if ( 'default' == $a_priority ) {
2930                  $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id];
2931                  unset($wp_meta_boxes[$page][$a_context]['default'][$id]);
2932              }
2933              return;
2934          }
2935          // If no priority given and id already present, use existing priority
2936          if ( empty($priority) ) {
2937              $priority = $a_priority;
2938          // 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.
2939          } elseif ( 'sorted' == $priority ) {
2940              $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
2941              $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
2942              $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
2943          }
2944          // An id can be in only one priority and one context
2945          if ( $priority != $a_priority || $context != $a_context )
2946              unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]);
2947      }
2948      }
2949  
2950      if ( empty($priority) )
2951          $priority = 'low';
2952  
2953      if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
2954          $wp_meta_boxes[$page][$context][$priority] = array();
2955  
2956      $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
2957  }
2958  
2959  /**
2960   * {@internal Missing Short Description}}
2961   *
2962   * @since unknown
2963   *
2964   * @param unknown_type $page
2965   * @param unknown_type $context
2966   * @param unknown_type $object
2967   * @return int number of meta_boxes
2968   */
2969  function do_meta_boxes($page, $context, $object) {
2970      global $wp_meta_boxes;
2971      static $already_sorted = false;
2972  
2973      //do_action('do_meta_boxes', $page, $context, $object);
2974  
2975      $hidden = get_hidden_meta_boxes($page);
2976  
2977      echo "<div id='$context-sortables' class='meta-box-sortables'>\n";
2978  
2979      $i = 0;
2980      do {
2981          // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
2982          if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page", 0, false ) ) {
2983              foreach ( $sorted as $box_context => $ids )
2984                  foreach ( explode(',', $ids) as $id )
2985                      if ( $id )
2986                          add_meta_box( $id, null, null, $page, $box_context, 'sorted' );
2987          }
2988          $already_sorted = true;
2989  
2990          if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
2991              break;
2992  
2993          foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
2994              if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
2995                  foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
2996                      if ( false == $box || ! $box['title'] )
2997                          continue;
2998                      $i++;
2999                      $style = '';
3000                      if ( in_array($box['id'], $hidden) )
3001                          $style = 'style="display:none;"';
3002                      echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '" ' . $style . '>' . "\n";
3003                      echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
3004                      echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
3005                      echo '<div class="inside">' . "\n";
3006                      call_user_func($box['callback'], $object, $box);
3007                      echo "</div>\n";
3008                      echo "</div>\n";
3009                  }
3010              }
3011          }
3012      } while(0);
3013  
3014      echo "</div>";
3015  
3016      return $i;
3017  
3018  }
3019  
3020  /**
3021   * Remove a meta box from an edit form.
3022   *
3023   * @since 2.6.0
3024   *
3025   * @param string $id String for use in the 'id' attribute of tags.
3026   * @param string $page The type of edit page on which to show the box (post, page, link).
3027   * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
3028   */
3029  function remove_meta_box($id, $page, $context) {
3030      global $wp_meta_boxes;
3031  
3032      if ( !isset($wp_meta_boxes) )
3033          $wp_meta_boxes = array();
3034      if ( !isset($wp_meta_boxes[$page]) )
3035          $wp_meta_boxes[$page] = array();
3036      if ( !isset($wp_meta_boxes[$page][$context]) )
3037          $wp_meta_boxes[$page][$context] = array();
3038  
3039      foreach ( array('high', 'core', 'default', 'low') as $priority )
3040          $wp_meta_boxes[$page][$context][$priority][$id] = false;
3041  }
3042  
3043  /**
3044   * {@internal Missing Short Description}}
3045   *
3046   * @since unknown
3047   *
3048   * @param unknown_type $page
3049   */
3050  function meta_box_prefs($page) {
3051      global $wp_meta_boxes;
3052  
3053      if ( empty($wp_meta_boxes[$page]) )
3054          return;
3055  
3056      $hidden = get_hidden_meta_boxes($page);
3057  
3058      foreach ( array_keys($wp_meta_boxes[$page]) as $context ) {
3059          foreach ( array_keys($wp_meta_boxes[$page][$context]) as $priority ) {
3060              foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
3061                  if ( false == $box || ! $box['title'] )
3062                      continue;
3063                  // Submit box cannot be hidden
3064                  if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] )
3065                      continue;
3066                  $box_id = $box['id'];
3067                  echo '<label for="' . $box_id . '-hide">';
3068                  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"' : '') . ' />';
3069                  echo "{$box['title']}</label>\n";
3070              }
3071          }
3072      }
3073  }
3074  
3075  function get_hidden_meta_boxes($page) {
3076      $hidden = (array) get_user_option( "meta-box-hidden_$page", 0, false );
3077  
3078      // Hide slug boxes by default
3079      if ( empty($hidden[0]) ) {
3080          $hidden = array('slugdiv');
3081      }
3082  
3083      return $hidden;
3084  }
3085  
3086  /**
3087   * Add a new section to a settings page.
3088   *
3089   * @since 2.7.0
3090   *
3091   * @param string $id String for use in the 'id' attribute of tags.
3092   * @param string $title Title of the section.
3093   * @param string $callback Function that fills the section with the desired content. The function should echo its output.
3094   * @param string $page The type of settings page on which to show the section (general, reading, writing, ...).
3095   */
3096  function add_settings_section($id, $title, $callback, $page) {
3097      global $wp_settings_sections;
3098  
3099      if ( !isset($wp_settings_sections) )
3100          $wp_settings_sections = array();
3101      if ( !isset($wp_settings_sections[$page]) )
3102          $wp_settings_sections[$page] = array();
3103      if ( !isset($wp_settings_sections[$page][$id]) )
3104          $wp_settings_sections[$page][$id] = array();
3105  
3106      $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
3107  }
3108  
3109  /**
3110   * Add a new field to a settings page.
3111   *
3112   * @since 2.7.0
3113   *
3114   * @param string $id String for use in the 'id' attribute of tags.
3115   * @param string $title Title of the field.
3116   * @param string $callback Function that fills the field with the desired content. The function should echo its output.
3117   * @param string $page The type of settings page on which to show the field (general, reading, writing, ...).
3118   * @param string $section The section of the settingss page in which to show the box (default, ...).
3119   * @param array $args Additional arguments
3120   */
3121  function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) {
3122      global $wp_settings_fields;
3123  
3124      if ( !isset($wp_settings_fields) )
3125          $wp_settings_fields = array();
3126      if ( !isset($wp_settings_fields[$page]) )
3127          $wp_settings_fields[$page] = array();
3128      if ( !isset($wp_settings_fields[$page][$section]) )
3129          $wp_settings_fields[$page][$section] = array();
3130  
3131      $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args);
3132  }
3133  
3134  /**
3135   * {@internal Missing Short Description}}
3136   *
3137   * @since unknown
3138   *
3139   * @param unknown_type $page
3140   */
3141  function do_settings_sections($page) {
3142      global $wp_settings_sections, $wp_settings_fields;
3143  
3144      if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
3145          return;
3146  
3147      foreach ( (array) $wp_settings_sections[$page] as $section ) {
3148          echo "<h3>{$section['title']}</h3>\n";
3149          call_user_func($section['callback'], $section);
3150          if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
3151              continue;
3152          echo '<table class="form-table">';
3153          do_settings_fields($page, $section['id']);
3154          echo '</table>';
3155      }
3156  }
3157  
3158  /**
3159   * {@internal Missing Short Description}}
3160   *
3161   * @since unknown
3162   *
3163   * @param unknown_type $page
3164   * @param unknown_type $section
3165   */
3166  function do_settings_fields($page, $section) {
3167      global $wp_settings_fields;
3168  
3169      if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
3170          return;
3171  
3172      foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
3173          echo '<tr valign="top">';
3174          if ( !empty($field['args']['label_for']) )
3175              echo '<th scope="row"><label for="' . $field['args']['label_for'] . '">' . $field['title'] . '</label></th>';
3176          else
3177              echo '<th scope="row">' . $field['title'] . '</th>';
3178          echo '<td>';
3179          call_user_func($field['callback'], $field['args']);
3180          echo '</td>';
3181          echo '</tr>';
3182      }
3183  }
3184  
3185  /**
3186   * {@internal Missing Short Description}}
3187   *
3188   * @since unknown
3189   *
3190   * @param unknown_type $page
3191   */
3192  function manage_columns_prefs($page) {
3193      $columns = get_column_headers($page);
3194  
3195      $hidden = get_hidden_columns($page);
3196  
3197      foreach ( $columns as $column => $title ) {
3198          // Can't hide these
3199          if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'username' == $column || 'media' == $column || 'comment' == $column )
3200              continue;
3201          if ( empty($title) )
3202              continue;
3203  
3204          if ( 'comments' == $column )
3205              $title = __('Comments');
3206          $id = "$column-hide";
3207          echo '<label for="' . $id . '">';
3208          echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
3209          echo "$title</label>\n";
3210      }
3211  }
3212  
3213  /**
3214   * {@internal Missing Short Description}}
3215   *
3216   * @since unknown
3217   *
3218   * @param unknown_type $found_action
3219   */
3220  function find_posts_div($found_action = '') {
3221  ?>
3222      <div id="find-posts" class="find-box" style="display:none;">
3223          <div id="find-posts-head" class="find-box-head"><?php _e('Find Posts or Pages'); ?></div>
3224          <div class="find-box-inside">
3225              <div class="find-box-search">
3226                  <?php if ( $found_action ) { ?>
3227                      <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" />
3228                  <?php } ?>
3229  
3230                  <input type="hidden" name="affected" id="affected" value="" />
3231                  <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
3232                  <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
3233                  <input type="text" id="find-posts-input" name="ps" value="" />
3234                  <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
3235  
3236                  <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
3237                  <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
3238                  <input type="radio" name="find-posts-what" id="find-posts-pages" value="pages" />
3239                  <label for="find-posts-pages"><?php _e( 'Pages' ); ?></label>
3240              </div>
3241              <div id="find-posts-response"></div>
3242          </div>
3243          <div class="find-box-buttons">
3244              <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
3245              <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
3246          </div>
3247      </div>
3248  <?php
3249  }
3250  
3251  /**
3252   * Display the post password.
3253   *
3254   * The password is passed through {@link esc_attr()} to ensure that it
3255   * is safe for placing in an html attribute.
3256   *
3257   * @uses attr
3258   * @since 2.7.0
3259   */
3260  function the_post_password() {
3261      global $post;
3262      if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password );
3263  }
3264  
3265  /**
3266   * {@internal Missing Short Description}}
3267   *
3268   * @since unknown
3269   */
3270  function favorite_actions( $screen = null ) {
3271      switch ( $screen ) {
3272          case 'post-new.php':
3273              $default_action = array('edit.php' => array(__('Edit Posts'), 'edit_posts'));
3274              break;
3275          case 'edit-pages.php':
3276              $default_action = array('page-new.php' => array(__('New Page'), 'edit_pages'));
3277              break;
3278          case 'page-new.php':
3279              $default_action = array('edit-pages.php' => array(__('Edit Pages'), 'edit_pages'));
3280              break;
3281          case 'upload.php':
3282              $default_action = array('media-new.php' => array(__('New Media'), 'upload_files'));
3283              break;
3284          case 'media-new.php':
3285              $default_action = array('upload.php' => array(__('Edit Media'), 'upload_files'));
3286              break;
3287          case 'link-manager.php':
3288              $default_action = array('link-add.php' => array(__('New Link'), 'manage_links'));
3289              break;
3290          case 'link-add.php':
3291              $default_action = array('link-manager.php' => array(__('Edit Links'), 'manage_links'));
3292              break;
3293          case 'users.php':
3294              $default_action = array('user-new.php' => array(__('New User'), 'create_users'));
3295              break;
3296          case 'user-new.php':
3297              $default_action = array('users.php' => array(__('Edit Users'), 'edit_users'));
3298              break;
3299          case 'plugins.php':
3300              $default_action = array('plugin-install.php' => array(__('Install Plugins'), 'install_plugins'));
3301              break;
3302          case 'plugin-install.php':
3303              $default_action = array('plugins.php' => array(__('Manage Plugins'), 'activate_plugins'));
3304              break;
3305          case 'themes.php':
3306              $default_action = array('theme-install.php' => array(__('Install Themes'), 'install_themes'));
3307              break;
3308          case 'theme-install.php':
3309              $default_action = array('themes.php' => array(__('Manage Themes'), 'switch_themes'));
3310              break;
3311          default:
3312              $default_action = array('post-new.php' => array(__('New Post'), 'edit_posts'));
3313              break;
3314      }
3315  
3316      $actions = array(
3317          'post-new.php' => array(__('New Post'), 'edit_posts'),
3318          'edit.php?post_status=draft' => array(__('Drafts'), 'edit_posts'),
3319          'page-new.php' => array(__('New Page'), 'edit_pages'),
3320          'media-new.php' => array(__('Upload'), 'upload_files'),
3321          'edit-comments.php' => array(__('Comments'), 'moderate_comments')
3322          );
3323  
3324      $default_key = array_keys($default_action);
3325      $default_key = $default_key[0];
3326      if ( isset($actions[$default_key]) )
3327          unset($actions[$default_key]);
3328      $actions = array_merge($default_action, $actions);
3329      $actions = apply_filters('favorite_actions', $actions);
3330  
3331      $allowed_actions = array();
3332      foreach ( $actions as $action => $data ) {
3333          if ( current_user_can($data[1]) )
3334              $allowed_actions[$action] = $data[0];
3335      }
3336  
3337      if ( empty($allowed_actions) )
3338          return;
3339  
3340      $first = array_keys($allowed_actions);
3341      $first = $first[0];
3342      echo '<div id="favorite-actions">';
3343      echo '<div id="favorite-first"><a href="' . $first . '">' . $allowed_actions[$first] . '</a></div><div id="favorite-toggle"><br /></div>';
3344      echo '<div id="favorite-inside">';
3345  
3346      array_shift($allowed_actions);
3347  
3348      foreach ( $allowed_actions as $action => $label) {
3349          echo "<div class='favorite-action'><a href='$action'>";
3350          echo $label;
3351          echo "</a></div>\n";
3352      }
3353      echo "</div></div>\n";
3354  }
3355  
3356  /**
3357   * Get the post title.
3358   *
3359   * The post title is fetched and if it is blank then a default string is
3360   * returned.
3361   *
3362   * @since 2.7.0
3363   * @param int $id The post id. If not supplied the global $post is used.
3364   *
3365   */
3366  function _draft_or_post_title($post_id = 0)
3367  {
3368      $title = get_the_title($post_id);
3369      if ( empty($title) )
3370          $title = __('(no title)');
3371      return $title;
3372  }
3373  
3374  /**
3375   * Display the search query.
3376   *
3377   * A simple wrapper to display the "s" parameter in a GET URI. This function
3378   * should only be used when {@link the_search_query()} cannot.
3379   *
3380   * @uses attr
3381   * @since 2.7.0
3382   *
3383   */
3384  function _admin_search_query() {
3385      echo isset($_GET['s']) ? esc_attr( stripslashes( $_GET['s'] ) ) : '';
3386  }
3387  
3388  /**
3389   * Generic Iframe header for use with Thickbox
3390   *
3391   * @since 2.7.0
3392   * @param string $title Title of the Iframe page.
3393   * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued).
3394   *
3395   */
3396  function iframe_header( $title = '', $limit_styles = false ) {
3397  ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3398  <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
3399  <head>
3400  <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
3401  <title><?php bloginfo('name') ?> &rsaquo; <?php echo $title ?> &#8212; <?php _e('WordPress'); ?></title>
3402  <?php
3403  wp_enqueue_style( 'global' );
3404  if ( ! $limit_styles )
3405      wp_enqueue_style( 'wp-admin' );
3406  wp_enqueue_style( 'colors' );
3407  ?>
3408  <script type="text/javascript">
3409  //<![CDATA[
3410  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();}}};
3411  function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
3412  //]]>
3413  </script>
3414  <?php
3415  do_action('admin_print_styles');
3416  do_action('admin_print_scripts');
3417  do_action('admin_head');
3418  ?>
3419  </head>
3420  <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
3421  <?php
3422  }
3423  
3424  /**
3425   * Generic Iframe footer for use with Thickbox
3426   *
3427   * @since 2.7.0
3428   *
3429   */
3430  function iframe_footer() {
3431      //We're going to hide any footer output on iframe pages, but run the hooks anyway since they output Javascript or other needed content. ?>
3432      <div class="hidden">
3433  <?php
3434      do_action('admin_footer', '');
3435      do_action('admin_print_footer_scripts'); ?>
3436      </div>
3437  <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script>
3438  </body>
3439  </html>
3440  <?php
3441  }
3442  
3443  function _post_states($post) {
3444      $post_states = array();
3445      if ( isset($_GET['post_status']) )
3446          $post_status = $_GET['post_status'];
3447      else
3448          $post_status = '';
3449  
3450      if ( !empty($post->post_password) )
3451          $post_states[] = __('Password protected');
3452      if ( 'private' == $post->post_status && 'private' != $post_status )
3453          $post_states[] = __('Private');
3454      if ( 'draft' == $post->post_status && 'draft' != $post_status )
3455          $post_states[] = __('Draft');
3456      if ( 'pending' == $post->post_status && 'pending' != $post_status )
3457          /* translators: post state */
3458          $post_states[] = _x('Pending', 'post state');
3459      if ( is_sticky($post->ID) )
3460          $post_states[] = __('Sticky');
3461  
3462      $post_states = apply_filters( 'display_post_states', $post_states );
3463  
3464      if ( ! empty($post_states) ) {
3465          $state_count = count($post_states);
3466          $i = 0;
3467          echo ' - ';
3468          foreach ( $post_states as $state ) {
3469              ++$i;
3470              ( $i == $state_count ) ? $sep = '' : $sep = ', ';
3471              echo "<span class='post-state'>$state$sep</span>";
3472          }
3473      }
3474  }
3475  
3476  function screen_meta($screen) {
3477      global $wp_meta_boxes, $_wp_contextual_help;
3478  
3479      $screen = str_replace('.php', '', $screen);
3480      $screen = str_replace('-new', '', $screen);
3481      $screen = str_replace('-add', '', $screen);
3482      $screen = apply_filters('screen_meta_screen', $screen);
3483  
3484      $column_screens = get_column_headers($screen);
3485      $meta_screens = array('index' => 'dashboard');
3486  
3487      if ( isset($meta_screens[$screen]) )
3488          $screen = $meta_screens[$screen];
3489      $show_screen = false;
3490      $show_on_screen = false;
3491      if ( !empty($wp_meta_boxes[$screen]) || !empty($column_screens) ) {
3492          $show_screen = true;
3493          $show_on_screen = true;
3494      }
3495  
3496      $screen_options = screen_options($screen);
3497      if ( $screen_options )
3498          $show_screen = true;
3499  
3500      if ( !isset($_wp_contextual_help) )
3501          $_wp_contextual_help = array();
3502  
3503      $settings = '';
3504  
3505      switch ( $screen ) {
3506          case 'post':
3507              if ( !isset($_wp_contextual_help['post']) ) {
3508                  $help = drag_drop_help();
3509                  $help .= '<p>' . __('<a href="http://codex.wordpress.org/Writing_Posts" target="_blank">Writing Posts</a>') . '</p>';
3510                  $_wp_contextual_help['post'] = $help;
3511              }
3512              break;
3513          case 'page':
3514              if ( !isset($_wp_contextual_help['page']) ) {
3515                  $help = drag_drop_help();
3516                  $_wp_contextual_help['page'] = $help;
3517              }
3518              break;
3519          case 'dashboard':
3520              if ( !isset($_wp_contextual_help['dashboard']) ) {
3521                  $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";
3522                  $help .= drag_drop_help();
3523                  $_wp_contextual_help['dashboard'] = $help;
3524              }
3525              break;
3526          case 'link':
3527              if ( !isset($_wp_contextual_help['link']) ) {
3528                  $help = drag_drop_help();
3529                  $_wp_contextual_help['link'] = $help;
3530              }
3531              break;
3532          case 'options-general':
3533              if ( !isset($_wp_contextual_help['options-general']) )
3534                  $_wp_contextual_help['options-general'] = __('<a href="http://codex.wordpress.org/Settings_General_SubPanel" target="_blank">General Settings</a>');
3535              break;
3536          case 'theme-install':
3537          case 'plugin-install':
3538              if ( ( !isset($_GET['tab']) || 'dashboard' == $_GET['tab'] ) && !isset($_wp_contextual_help[$screen]) ) {
3539                  $help = plugins_search_help();
3540                  $_wp_contextual_help[$screen] = $help;
3541              }
3542              break;
3543          case 'widgets':
3544              if ( !isset($_wp_contextual_help['widgets']) ) {
3545                  $help = widgets_help();
3546                  $_wp_contextual_help['widgets'] = $help;
3547              }
3548              $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";
3549              $show_screen = true;
3550              break;
3551      }
3552  ?>
3553  <div id="screen-meta">
3554  <?php
3555      if ( $show_screen ) :
3556  ?>
3557  <div id="screen-options-wrap" class="hidden">
3558      <form id="adv-settings" action="" method="post">
3559  <?php if ( $show_on_screen ) : ?>
3560      <h5><?php _e('Show on screen') ?></h5>
3561      <div class="metabox-prefs">
3562  <?php
3563      if ( !meta_box_prefs($screen) && isset($column_screens) ) {
3564          manage_columns_prefs($screen);
3565      }
3566  ?>
3567      <br class="clear" />
3568      </div>
3569  <?php endif; ?>
3570  <?php echo screen_layout($screen); ?>
3571  <?php echo $screen_options; ?>
3572  <?php echo $settings; ?>
3573  <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div>
3574  </form>
3575  </div>
3576  
3577  <?php
3578      endif;
3579  
3580      global $title;
3581  
3582      $_wp_contextual_help = apply_filters('contextual_help_list', $_wp_contextual_help, $screen);
3583      ?>
3584      <div id="contextual-help-wrap" class="hidden">
3585      <?php
3586      $contextual_help = '';
3587      if ( isset($_wp_contextual_help[$screen]) ) {
3588          if ( !empty($title) )
3589              $contextual_help .= '<h5>' . sprintf(__('Get help with &#8220;%s&#8221;'), $title) . '</h5>';
3590          else
3591              $contextual_help .= '<h5>' . __('Get help with this page') . '</h5>';
3592          $contextual_help .= '<div class="metabox-prefs">' . $_wp_contextual_help[$screen] . "</div>\n";
3593  
3594          $contextual_help .= '<h5>' . __('Other Help') . '</h5>';
3595      } else {
3596          $contextual_help .= '<h5>' . __('Help') . '</h5>';
3597      }
3598  
3599      $contextual_help .= '<div class="metabox-prefs">';
3600      $default_help = __('<a href="http://codex.wordpress.org/" target="_blank">Documentation</a>');
3601      $default_help .= '<br />';
3602      $default_help .= __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>');
3603      $contextual_help .= apply_filters('default_contextual_help', $default_help);
3604      $contextual_help .= "</div>\n";
3605      echo apply_filters('contextual_help', $contextual_help, $screen);
3606      ?>
3607      </div>
3608  
3609  <div id="screen-meta-links">
3610  <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">
3611  <a href="#contextual-help" id="contextual-help-link" class="show-settings"><?php _e('Help') ?></a>
3612  </div>
3613  <?php if ( $show_screen ) { ?>
3614  <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
3615  <a href="#screen-options" id="show-settings-link" class="show-settings"><?php _e('Screen Options') ?></a>
3616  </div>
3617  <?php } ?>
3618  </div>
3619  </div>
3620  <?php
3621  }
3622  
3623  /**
3624   * Add contextual help text for a page
3625   *
3626   * @since 2.7.0
3627   *
3628   * @param string $screen The handle for the screen to add help to.  This is usually the hook name returned by the add_*_page() functions.
3629   * @param string $help Arbitrary help text
3630   */
3631  function add_contextual_help($screen, $help) {
3632      global $_wp_contextual_help;
3633  
3634      if ( !isset($_wp_contextual_help) )
3635          $_wp_contextual_help = array();
3636  
3637      $_wp_contextual_help[$screen] = $help;
3638  }
3639  
3640  function drag_drop_help() {
3641      return '
3642      <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>
3643      <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>
3644  ';
3645  }
3646  
3647  function plugins_search_help() {
3648      return '
3649      <p><strong>' . __('Search help') . '</strong></p>' .
3650      '<p>' . __('You may search based on 3 criteria:') . '<br />' .
3651      __('<strong>Term:</strong> Searches theme names and descriptions for the specified term.') . '<br />' .
3652      __('<strong>Tag:</strong> Searches for themes tagged as such.') . '<br />' .
3653      __('<strong>Author:</strong> Searches for themes created by the Author, or which the Author contributed to.') . '</p>
3654  ';
3655  }
3656  
3657  function widgets_help() {
3658      return '
3659      <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>
3660      <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>
3661      <p>' . __('To remove a widget from a sidebar <em>and keep its configuration</em>, drag it to Inactive Widgets.') . '</p>
3662      <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>
3663  ';
3664  }
3665  
3666  function screen_layout($screen) {
3667      global $screen_layout_columns;
3668  
3669      $columns = array('dashboard' => 4, 'post' => 2, 'page' => 2, 'link' => 2);
3670      $columns = apply_filters('screen_layout_columns', $columns, $screen);
3671  
3672      if ( !isset($columns[$screen]) ) {
3673          $screen_layout_columns = 0;
3674          return '';
3675       }
3676  
3677      $screen_layout_columns = get_user_option("screen_layout_$screen");
3678      $num = $columns[$screen];
3679  
3680      if ( ! $screen_layout_columns )
3681              $screen_layout_columns = 2;
3682  
3683      $i = 1;
3684      $return = '<h5>' . __('Screen Layout') . "</h5>\n<div class='columns-prefs'>" . __('Number of Columns:') . "\n";
3685      while ( $i <= $num ) {
3686          $return .= "<label><input type='radio' name='screen_columns' value='$i'" . ( ($screen_layout_columns == $i) ? " checked='checked'" : "" ) . " /> $i</label>\n";
3687          ++$i;
3688      }
3689      $return .= "</div>\n";
3690      return $return;
3691  }
3692  
3693  function screen_options($screen) {
3694      switch ( $screen ) {
3695          case 'edit':
3696              $per_page_label = __('Posts per page:');
3697              break;
3698          case 'edit-pages':
3699              $per_page_label = __('Pages per page:');
3700              break;
3701          case 'edit-comments':
3702              $per_page_label = __('Comments per page:');
3703              break;
3704          case 'upload':
3705              $per_page_label = __('Media items per page:');
3706              break;
3707          case 'categories':
3708              $per_page_label = __('Categories per page:');
3709              break;
3710          case 'edit-tags':
3711              $per_page_label = __('Tags per page:');
3712              break;
3713          case 'plugins':
3714              $per_page_label = __('Plugins per page:');
3715              break;
3716          default:
3717              return '';
3718      }
3719  
3720      $option = str_replace( '-', '_', "$screen}_per_page" );
3721      $per_page = (int) get_user_option( $option, 0, false );
3722      if ( empty( $per_page ) || $per_page < 1 ) {
3723          if ( 'plugins' == $screen )
3724              $per_page = 999;
3725          else
3726              $per_page = 20;
3727      }
3728      if ( 'edit_comments_per_page' == $option )
3729          $per_page = apply_filters( 'comments_per_page', $per_page, isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all' );
3730      elseif ( 'categories' == $option )
3731          $per_page = apply_filters( 'edit_categories_per_page', $per_page );
3732      else
3733          $per_page = apply_filters( $option, $per_page );
3734  
3735      $return = '<h5>' . __('Options') . "</h5>\n";
3736      $return .= "<div class='screen-options'>\n";
3737      if ( !empty($per_page_label) )
3738          $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";
3739      $return .= "<input type='submit' class='button' value='" . esc_attr__('Apply') . "' />";
3740      $return .= "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />";
3741      $return .= "</div>\n";
3742      return $return;
3743  }
3744  
3745  function screen_icon($name = '') {
3746      global $parent_file, $hook_suffix;
3747  
3748      if ( empty($name) ) {
3749          if ( isset($parent_file) && !empty($parent_file) )
3750              $name = substr($parent_file, 0, -4);
3751          else
3752              $name = str_replace(array('.php', '-new', '-add'), '', $hook_suffix);
3753      }
3754  ?>
3755      <div id="icon-<?php echo $name; ?>" class="icon32"><br /></div>
3756  <?php
3757  }
3758  
3759  /**
3760   * Test support for compressing JavaScript from PHP
3761   *
3762   * Outputs JavaScript that tests if compression from PHP works as expected
3763   * and sets an option with the result. Has no effect when the current user
3764   * is not an administrator. To run the test again the option 'can_compress_scripts'
3765   * has to be deleted.
3766   *
3767   * @since 2.8.0
3768   */
3769  function compression_test() {
3770  ?>
3771      <script type="text/javascript">
3772      /* <![CDATA[ */
3773      var testCompression = {
3774          get : function(test) {
3775              var x;
3776              if ( window.XMLHttpRequest ) {
3777                  x = new XMLHttpRequest();
3778              } else {
3779                  try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}
3780              }
3781  
3782              if (x) {
3783                  x.onreadystatechange = function() {
3784                      var r, h;
3785                      if ( x.readyState == 4 ) {
3786                          r = x.responseText.substr(0, 18);
3787                          h = x.getResponseHeader('Content-Encoding');
3788                          testCompression.check(r, h, test);
3789                      }
3790                  }
3791  
3792                  x.open('GET', 'admin-ajax.php?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true);
3793                  x.send('');
3794              }
3795          },
3796  
3797          check : function(r, h, test) {
3798              if ( ! r && ! test )
3799                  this.get(1);
3800  
3801              if ( 1 == test ) {
3802                  if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) )
3803                      this.get('no');
3804                  else
3805                      this.get(2);
3806  
3807                  return;
3808              }
3809  
3810              if ( 2 == test ) {
3811                  if ( '"wpCompressionTest' == r )
3812                      this.get('yes');
3813                  else
3814                      this.get('no');
3815              }
3816          }
3817      };
3818      testCompression.check();
3819      /* ]]> */
3820      </script>
3821  <?php
3822  }
3823  
3824  ?>


Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7