b2evolution PHP Cross Reference Blogging Systems

Source: /inc/chapters/views/_chapter_list.view.php - 330 lines - 10602 bytes - Summary - Text - Print

Description: This file implements the recursive chapter list. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the recursive chapter list.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * @package admin
  20   *
  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22   * @author fplanque: Francois PLANQUE.
  23   *
  24   * @version $Id: _chapter_list.view.php 6136 2014-03-08 07:59:48Z manuel $
  25   */
  26  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  27  //____________________ Callbacks functions to display categories list _____________________
  28  
  29  /**
  30   * @var Blog
  31   */
  32  global $Blog;
  33  
  34  global $Settings;
  35  
  36  global $GenericCategoryCache;
  37  
  38  global $line_class;
  39  
  40  global $permission_to_edit;
  41  
  42  global $subset_ID;
  43  
  44  global $current_default_cat_ID;
  45  
  46  global $Session;
  47  
  48  $result_fadeout = $Session->get( 'fadeout_array' );
  49  
  50  $current_default_cat_ID = $Blog->get_setting('default_cat_ID');
  51  
  52  $line_class = 'odd';
  53  
  54  
  55  /**
  56   * Generate category line when it has children
  57   *
  58   * @param Chapter generic category we want to display
  59   * @param int level of the category in the recursive tree
  60   * @return string HTML
  61   */
  62  function cat_line( $Chapter, $level )
  63  {
  64      global $line_class, $permission_to_edit, $current_User, $Settings;
  65      global $GenericCategoryCache, $current_default_cat_ID;
  66      global $number_of_posts_in_cat;
  67  
  68      global $Session;
  69      $result_fadeout = $Session->get( 'fadeout_array' );
  70  
  71      $line_class = $line_class == 'even' ? 'odd' : 'even';
  72  
  73      // ID
  74      $r = '<tr id="tr-'.$Chapter->ID.'"class="'.$line_class.
  75                      ' chapter_parent_'.( $Chapter->parent_ID ? $Chapter->parent_ID : '0' ).
  76                      // Fadeout?
  77                      ( isset($result_fadeout) && in_array( $Chapter->ID, $result_fadeout ) ? ' fadeout-ffff00': '' ).'">
  78                      <td class="firstcol shrinkwrap">'.
  79                          $Chapter->ID.'
  80                  </td>';
  81  
  82      // Default
  83      if( $current_default_cat_ID == $Chapter->ID )
  84      {
  85          $makedef_icon = get_icon( 'enabled', 'imgtag', array( 'title' => format_to_output( T_( 'This is the default category' ), 'htmlattr' ) ) );
  86      }
  87      else
  88      {
  89          $makedef_url = regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action=make_default&amp;'.url_crumb('element') );
  90          $makedef_title = format_to_output( T_('Click to make this the default category'), 'htmlattr' );
  91          $makedef_icon = '<a href="'.$makedef_url.'" title="'.$makedef_title.'">'.get_icon( 'disabled', 'imgtag', array( 'title' => $makedef_title ) ).'</a>';
  92      }
  93      $r .= '<td class="center">'.$makedef_icon.'</td>';
  94  
  95      // Name
  96      if( $permission_to_edit )
  97      {    // We have permission permission to edit:
  98          $edit_url = regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action=edit' );
  99          $r .= '<td>
 100                          <strong style="padding-left: '.($level).'em;"><a href="'.$edit_url.'" title="'.T_('Edit...').'">'.$Chapter->dget('name').'</a></strong>
 101                       </td>';
 102      }
 103      else
 104      {
 105          $r .= '<td>
 106                           <strong style="padding-left: '.($level).'em;">'.$Chapter->dget('name').'</strong>
 107                       </td>';
 108      }
 109  
 110      // URL "slug"
 111      $edit_url = regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action=edit' );
 112      $r .= '<td><a href="'.htmlspecialchars($Chapter->get_permanent_url()).'">'.$Chapter->dget('urlname').'</a></td>';
 113  
 114      // Order
 115      if( $Settings->get('chapter_ordering') == 'manual' )
 116      {
 117          $r .= '<td class="center">'.$Chapter->dget('order').'</td>';
 118      }
 119  
 120      if( $permission_to_edit )
 121      {    // We have permission permission to edit, so display these columns:
 122  
 123          if( $Chapter->meta )
 124          {
 125              $makemeta_icon = 'enabled';
 126              $makemeta_title = format_to_output( T_('Click to revert this from meta category'), 'htmlattr' );
 127              $action = 'unset_meta';
 128          }
 129          else
 130          {
 131              $makemeta_icon = 'disabled';
 132              $makemeta_title = format_to_output( T_('Click to make this as meta category'), 'htmlattr' );
 133              $action = 'set_meta';
 134          }
 135          // Meta
 136          $makemeta_url = regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action='.$action.'&amp;'.url_crumb('element') );
 137          $r .= '<td class="center"><a href="'.$makemeta_url.'" title="'.$makemeta_title.'">'.get_icon( $makemeta_icon, 'imgtag', array( 'title' => $makemeta_title ) ).'</a></td>';
 138  
 139          // Lock
 140          if( $Chapter->lock )
 141          {
 142              $makelock_icon = 'file_not_allowed';
 143              $makelock_title = format_to_output( T_('Unlock category'), 'htmlattr' );
 144              $action = 'unlock';
 145          }
 146          else
 147          {
 148              $makelock_icon = 'file_allowed';
 149              $makelock_title = format_to_output( T_('Lock category'), 'htmlattr' );
 150              $action = 'lock';
 151          }
 152          $makelock_url = regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action='.$action.'&amp;'.url_crumb('element') );
 153          $r .= '<td class="center"><a href="'.$makelock_url.'" title="'.$makelock_title.'">'.get_icon( $makelock_icon, 'imgtag', array( 'title' => $makelock_title ) ).'</a></td>';
 154      }
 155  
 156      // Posts
 157      if( isset($number_of_posts_in_cat[$Chapter->ID]) )
 158      {
 159          $r .= '<td class="center">'.(int)$number_of_posts_in_cat[$Chapter->ID].'</td>';
 160      }
 161      else
 162      {    // no posts in this category
 163          $r .= '<td class="center"> - </td>';
 164      }
 165  
 166      // Actions
 167      $r .= '<td class="lastcol shrinkwrap">';
 168      if( $permission_to_edit )
 169      {    // We have permission permission to edit, so display action column:
 170          $r .= action_icon( T_('Edit...'), 'edit', $edit_url );
 171          if( $Settings->get('allow_moving_chapters') )
 172          { // If moving cats between blogs is allowed:
 173              $r .= action_icon( T_('Move to a different blog...'), 'file_move', regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action=move' ), T_('Move') );
 174          }
 175          $r .= action_icon( T_('New...'), 'new', regenerate_url( 'action,cat_ID,cat_parent_ID', 'cat_parent_ID='.$Chapter->ID.'&amp;action=new' ) )
 176                      .action_icon( T_('Delete...'), 'delete', regenerate_url( 'action,cat_ID', 'cat_ID='.$Chapter->ID.'&amp;action=delete&amp;'.url_crumb('element') ) );
 177      }
 178      $r .= '</td>';
 179      $r .=    '</tr>';
 180  
 181      return $r;
 182  }
 183  
 184  
 185  /**
 186   * Generate category line when it has no children
 187   *
 188   * @param Chapter generic category we want to display
 189   * @param int level of the category in the recursive tree
 190   * @return string HTML
 191   */
 192  function cat_no_children( $Chapter, $level )
 193  {
 194      return '';
 195  }
 196  
 197  
 198  /**
 199   * Generate code when entering a new level
 200   *
 201   * @param int level of the category in the recursive tree
 202   * @return string HTML
 203   */
 204  function cat_before_level( $level )
 205  {
 206      return '';
 207  }
 208  
 209  /**
 210   * Generate code when exiting from a level
 211   *
 212   * @param int level of the category in the recursive tree
 213   * @return string HTML
 214   */
 215  function cat_after_level( $level )
 216  {
 217      return '';
 218  }
 219  
 220  
 221  $callbacks = array(
 222      'line'                   => 'cat_line',
 223      'no_children'  => 'cat_no_children',
 224      'before_level' => 'cat_before_level',
 225      'after_level'     => 'cat_after_level'
 226  );
 227  
 228  //____________________________________ Display generic categories _____________________________________
 229  
 230  $Table = new Table();
 231  
 232  $Table->title = sprintf( T_('Categories for blog: %s'), $Blog->get_maxlen_name( 50 ) );
 233  
 234  $Table->global_icon( T_('Create a new category...'), 'new', regenerate_url( 'action,'.$GenericCategoryCache->dbIDname, 'action=new' ), T_('New category').' &raquo;', 3, 4  );
 235  
 236  $Table->cols[] = array(
 237                          'th' => T_('ID'),
 238                      );
 239  $Table->cols[] = array(
 240                          'th' => T_('Default'),
 241                          'th_class' => 'shrinkwrap',
 242                      );
 243  $Table->cols[] = array(
 244                          'th' => T_('Name'),
 245                      );
 246  $Table->cols[] = array(
 247                          'th' => T_('URL "slug"'),
 248                      );
 249  if( $Settings->get('chapter_ordering') == 'manual' )
 250  {
 251      $Table->cols[] = array(
 252                              'th' => T_('Order'),
 253                              'th_class' => 'shrinkwrap',
 254                          );
 255  }
 256  if( $permission_to_edit )
 257  {    // We have permission permission to edit, so display these columns:
 258      $Table->cols[] = array(
 259                          'th' => T_('Meta'),
 260                          'th_class' => 'shrinkwrap',
 261                      );
 262  
 263      $Table->cols[] = array(
 264                          'th' => T_('Lock'),
 265                          'th_class' => 'shrinkwrap',
 266                      );
 267  }
 268  
 269  // TODO: dh> would be useful to sort by this
 270  $Table->cols[] = array(
 271                          'th' => T_('Posts'),
 272                          'th_class' => 'shrinkwrap',
 273                      );
 274  
 275  if( $permission_to_edit )
 276  {    // We have permission permission to edit, so display action column:
 277      $Table->cols[] = array(
 278                              'th' => T_('Actions'),
 279                          );
 280  }
 281  
 282  // Get # of posts for each category
 283  global $number_of_posts_in_cat;
 284  $number_of_posts_in_cat = $DB->get_assoc('
 285      SELECT cat_ID, count(postcat_post_ID) c
 286      FROM T_categories LEFT JOIN T_postcats ON postcat_cat_ID = cat_id
 287      WHERE cat_blog_ID = '.$DB->quote($subset_ID).'
 288      GROUP BY cat_ID');
 289  
 290  $Table->display_init( NULL, $result_fadeout );
 291  
 292  // add an id for jquery to hook into
 293  // TODO: fp> Awfully dirty. This should be handled by the Table object
 294  $Table->params['list_start'] = str_replace( '<table', '<table id="chapter_list"', $Table->params['list_start'] );
 295  
 296  $Table->display_head();
 297  
 298  echo $Table->params['content_start'];
 299  
 300  $Table->display_list_start();
 301  
 302      $Table->display_col_headers();
 303  
 304      $Table->display_body_start();
 305  
 306      echo $GenericCategoryCache->recurse( $callbacks, $subset_ID );
 307  
 308      $Table->display_body_end();
 309  
 310  $Table->display_list_end();
 311  
 312  
 313  /* fp> TODO: maybe... (a general group move of posts would be more useful actually)
 314  echo '<p class="note">'.T_('<strong>Note:</strong> Deleting a category does not delete posts from that category. It will just assign them to the parent category. When deleting a root category, posts will be assigned to the oldest remaining category in the same collection (smallest category number).').'</p>';
 315  */
 316  
 317  global $Settings, $dispatcher;
 318  
 319  echo '<p class="note">'.sprintf( T_('<strong>Note:</strong> Ordering of categories is currently set to %s in the %sblogs settings%s.'),
 320      $Settings->get('chapter_ordering') == 'manual' ? /* TRANS: Manual here = "by hand" */ T_('Manual ') : T_('Alphabetical'), '<a href="'.$dispatcher.'?ctrl=collections&tab=settings#categories">', '</a>' ).'</p> ';
 321  
 322  if( ! $Settings->get('allow_moving_chapters') )
 323  { // TODO: check perm
 324      echo '<p class="note">'.sprintf( T_('<strong>Note:</strong> Moving categories across blogs is currently disabled in the %sblogs settings%s.'), '<a href="'.$dispatcher.'?ctrl=collections&tab=settings#categories">', '</a>' ).'</p> ';
 325  }
 326  
 327  //Flush fadeout
 328  $Session->delete( 'fadeout_array');
 329  
 330  ?>

title

Description

title

Description

title

Description

title

title

Body