b2evolution PHP Cross Reference Blogging Systems

Source: /inc/items/views/_item_history.view.php - 272 lines - 7933 bytes - Summary - Text - Print

Description: This file implements the Item history view This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the Item history view
   4   *
   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.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   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  11   *
  12   * @package admin
  13   *
  14   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  15   * @author fplanque: Francois PLANQUE.
  16   *
  17   * @version $Id: _item_history.view.php 6136 2014-03-08 07:59:48Z manuel $
  18   */
  19  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  20  
  21  /**
  22   * @var Blog
  23   */
  24  global $Blog;
  25  
  26  /**
  27   * @var Item
  28   */
  29  global $edited_Item;
  30  
  31  global $admin_url;
  32  
  33  if( $lastedit_User = & $edited_Item->get_lastedit_User() )
  34  {    // Get login of last edit user
  35      $lastedit_user_login = $lastedit_User->get( 'login' );
  36  }
  37  else
  38  {    // User was deleted
  39      $lastedit_user_login = T_('(deleted user)');
  40  }
  41  
  42  $sql_current_version = 'SELECT "C" AS iver_ID,
  43          "'.$edited_Item->datemodified.'" AS iver_edit_datetime,
  44          "'.$edited_Item->lastedit_user_ID.'" AS iver_edit_user_ID,
  45          "'.T_('Current version').'" AS action,
  46          "'.$edited_Item->status.'" AS iver_status,
  47          "'.$edited_Item->title.'" AS iver_title,
  48          "'.str_replace( '"', '\"', $lastedit_user_login ).'" AS user_login';
  49  $SQL = new SQL();
  50  $SQL->SELECT( 'iver_ID, iver_edit_datetime, iver_edit_user_ID, "'.T_('Archived version').'" AS action, iver_status, iver_title, user_login' );
  51  $SQL->FROM( 'T_items__version' );
  52  // LEFT JOIN users to display versions edited by already deleted users
  53  $SQL->FROM_add( 'LEFT JOIN T_users ON iver_edit_user_ID = user_ID' );
  54  $SQL->WHERE( 'iver_itm_ID = ' . $edited_Item->ID );
  55  // fp> not actually necessary:
  56  // UNION
  57  // SELECT "'.$edited_Item->datecreated.'" AS iver_edit_datetime, "'.$edited_Item->creator_user_ID.'" AS user_login, "First version" AS action';
  58  
  59  $CountSQL = new SQL();
  60  $CountSQL->SELECT( 'COUNT(*)+1' );
  61  $CountSQL->FROM( 'T_items__version' );
  62  $CountSQL->WHERE( $SQL->get_where( '' ) );
  63  
  64  $revisions_count = $DB->get_var( $CountSQL->get() );
  65  
  66  $default_order = $revisions_count > 1 ? '---D' : '-D';
  67  
  68  // Create result set:
  69  $Results = new Results( $sql_current_version . ' UNION ' . $SQL->get(), 'iver_', $default_order, NULL, $CountSQL->get() );
  70  
  71  $Results->title = T_('Item history (experimental) for:').' '.$edited_Item->get_title();
  72  
  73  /**
  74   * Get radio input to select a revision to compare
  75   *
  76   * @param integer Revision ID
  77   * @param string Input name
  78   * @param integer Number of selected revision
  79   * @param string Direction (up | down)
  80   */
  81  function iver_compare_selector( $revision_ID, $input_name, $selected, $direction = 'up' )
  82  {
  83      global $iver_compare_selector;
  84      if( !isset( $iver_compare_selector ) )
  85      {
  86          $iver_compare_selector = array();
  87      }
  88      if( !isset( $iver_compare_selector[ $input_name ] ) )
  89      {
  90          $iver_compare_selector[ $input_name ] = 0;
  91      }
  92      $iver_compare_selector[ $input_name ]++;
  93  
  94      $style = '';
  95      if( ( $iver_compare_selector[ $input_name ] < $selected && $direction == 'up' ) || 
  96          ( $iver_compare_selector[ $input_name ] > $selected && $direction == 'down' ) )
  97      {    // Hide inputs
  98          $style = ' style="display:none"';
  99      }
 100  
 101      $checked = '';
 102      if( $iver_compare_selector[ $input_name ] == $selected )
 103      {    // Select this input
 104          $checked = ' checked="checked"';
 105      }
 106  
 107      return '<input type="radio" name="'.$input_name.'" value="'.$revision_ID.'"'.$style.$checked.' />';
 108  }
 109  
 110  if( $revisions_count > 1 )
 111  {    // Dispay the selectors to compare the revisions
 112      $Results->cols[] = array(
 113                              'th' => '',
 114                              'th_class' => 'shrinkwrap',
 115                              'td_class' => 'shrinkwrap',
 116                              'td' => '%iver_compare_selector( #iver_ID#, "r1", 2 )%',
 117                          );
 118  
 119      $Results->cols[] = array(
 120                              'th' => '',
 121                              'th_class' => 'shrinkwrap',
 122                              'td_class' => 'shrinkwrap',
 123                              'td' => '%iver_compare_selector( #iver_ID#, "r2", 1, "down" )%',
 124                          );
 125  }
 126  
 127  $Results->cols[] = array(
 128                          'th' => T_('ID'),
 129                          'order' => 'iver_ID',
 130                          'th_class' => 'shrinkwrap',
 131                          'td_class' => 'shrinkwrap',
 132                          'td' => '$iver_ID$',
 133                      );
 134  
 135  $Results->cols[] = array(
 136                          'th' => T_('Date'),
 137                          'order' => 'iver_edit_datetime',
 138                          'default_dir' => 'D',
 139                          'th_class' => 'shrinkwrap',
 140                          'td_class' => 'shrinkwrap',
 141                          'td' => '%mysql2localedatetime_spans( #iver_edit_datetime#, "M-d" )%',
 142                      );
 143  
 144  /**
 145   * Get item version editor login with link to user profile
 146   * 
 147   * @param integer editor user ID
 148   * @return string user profile link or 'Deleted user' text if the user doesn't exist anymore
 149   */
 150  function iver_editor_login( $user_ID )
 151  {
 152      $r = get_user_identity_link( NULL, $user_ID );
 153      if( empty( $r ) )
 154      {
 155          return T_('(deleted user)');
 156      }
 157      return $r;
 158  }
 159  $Results->cols[] = array(
 160                          'th' => T_('User'),
 161                          'order' => 'user_login',
 162                          'th_class' => 'shrinkwrap',
 163                          'td_class' => 'shrinkwrap',
 164                          'td' => '%iver_editor_login( #iver_edit_user_ID# )%',
 165                      );
 166  
 167  /**
 168   * Get post status label from DB value
 169   *
 170   * @param string Status value
 171   * @return string Status label
 172   */
 173  function iver_status_label( $iver_status )
 174  {
 175      $statuses = get_visibility_statuses();
 176      return isset( $statuses[ $iver_status ] ) ? $statuses[ $iver_status ] : $iver_status;
 177  }
 178  $Results->cols[] = array(
 179                          'th' => T_('Status'),
 180                          'order' => 'iver_status',
 181                          'td' => '%iver_status_label( #iver_status# )%',
 182                          'th_class' => 'shrinkwrap',
 183                          'td_class' => 'shrinkwrap',
 184                      );
 185  
 186  $Results->cols[] = array(
 187                          'th' => T_('Note'),
 188                          'order' => 'action',
 189                          'td' => '<a href="'.url_add_param( $admin_url, 'ctrl=items&amp;action=history_details&amp;p='.$edited_Item->ID.'&amp;r=' ).'$iver_ID$">$action$</a>',
 190                      );
 191  
 192  $Results->cols[] = array(
 193                          'th' => T_('Title'),
 194                          'order' => 'title',
 195                          'td' => '$iver_title$',
 196                      );
 197  
 198  function history_td_actions( $iver_ID )
 199  {
 200      if( (int)$iver_ID == 0 )
 201      {    // Dont' display a restore link for current version
 202          return;
 203      }
 204  
 205      $restore_link = '<a href="'.regenerate_url( 'action', 'action=history_restore&amp;r='.$iver_ID.'&amp;'.url_crumb( 'item' ) ).'">'.T_('Restore').'</a>';
 206  
 207      return $restore_link;
 208  }
 209  
 210  $Results->cols[] = array(
 211                          'th' => T_('Actions'),
 212                          'td' => '%history_td_actions( #iver_ID# )%',
 213                          'td_class' => 'shrinkwrap',
 214                      );
 215  
 216  $Form = new Form();
 217  
 218  $Form->add_crumb( 'item' );
 219  $Form->hidden_ctrl();
 220  $Form->hidden( 'p', get_param( 'p' ) );
 221  
 222  $Form->begin_form();
 223  
 224  $Results->display();
 225  
 226  $Form->buttonsstart = '';
 227  $Form->buttonsend = '';
 228  
 229  $buttons = array();
 230  if( $revisions_count > 1 )
 231  {    // Button to compare the revisions
 232      $buttons = array( array( 'submit', 'actionArray[history_compare]', T_('Compare selected revisions'), 'SaveButton' ) );
 233      echo get_icon( 'multi_action', 'imgtag', array( 'style' => 'margin-left:18px;position:relative;top:-5px;') );
 234  }
 235  $Form->end_form( $buttons );
 236  
 237  if( $revisions_count > 2 )
 238  {    // Print JS code for selectors to compare the revisions
 239  ?>
 240  <script type="text/javascript">
 241  jQuery( document ).ready( function()
 242  {
 243      jQuery( 'input[name=r1]:eq(1)' ).attr( 'checked', 'checked' );
 244      jQuery( 'input[name=r2]:eq(0)' ).attr( 'checked', 'checked' );
 245      <?php /*jQuery( 'input[name=r1]:lt(1)' ).hide();
 246      jQuery( 'input[name=r2]:gt(0)' ).hide();*/ ?>
 247  } );
 248  jQuery( 'input[name=r1]' ).click( function()
 249  {
 250      var index = jQuery( 'input[name=r1]' ).index( jQuery( this ) );
 251      jQuery( 'input[name=r2]:lt(' + index + ')' ).show();
 252      jQuery( 'input[name=r2]:gt(' + ( index - 1 ) + ')' ).hide();
 253  } );
 254  
 255  jQuery( 'input[name=r2]' ).click( function()
 256  {
 257      var index = jQuery( 'input[name=r2]' ).index( jQuery( this ) );
 258      jQuery( 'input[name=r1]:gt(' + index + ')' ).show();
 259      jQuery( 'input[name=r1]:lt(' + ( index + 1 ) + ')' ).hide();
 260  } );
 261  </script>
 262  <noscript><?php /* Display all selectors for browsers withOUT JavaScript */ ?>
 263  <style>
 264  div.results td.shrinkwrap input {
 265      display: block !important;
 266  }
 267  </style>
 268  </noscript>
 269  <?php
 270  }
 271  
 272  ?>

title

Description

title

Description

title

Description

title

title

Body