b2evolution PHP Cross Reference Blogging Systems

Source: /htsrv/viewfile.php - 315 lines - 9755 bytes - Summary - Text - Print

Description: This file implements the UI for file viewing. 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 UI for file viewing.
   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   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * Daniel HAHLER grants Francois PLANQUE the right to license
  22   * Daniel HAHLER's contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package admin
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author blueyed: Daniel HAHLER.
  30   * @author fplanque: Francois PLANQUE.
  31   *
  32   * @todo skin compliant header!
  33   *
  34   * @version $Id: viewfile.php 6136 2014-03-08 07:59:48Z manuel $
  35   */
  36  
  37  /**
  38   * Load config, init and get the {@link $mode mode param}.
  39   */
  40  require_once dirname(__FILE__).'/../conf/_config.php';
  41  require_once $inc_path.'/_main.inc.php';
  42  
  43  
  44  if( ! isset($GLOBALS['files_Module']) )
  45  {
  46      debug_die( 'Files module is disabled or missing!' );
  47  }
  48  
  49  // Check permission (#1):
  50  if( ! isset($current_User) )
  51  {
  52      debug_die( 'No permissions to view file (not logged in)!' );
  53  }
  54  
  55  // We need this param early to check blog perms, if possible
  56  param( 'root', 'string', true, true ); // the root directory from the dropdown box (user_X or blog_X; X is ID - 'user' for current user (default))
  57  if( preg_match( '/^collection_(\d+)$/', $root, $perm_blog ) )
  58  {    // OK, we got a blog ID:
  59      $perm_blog = $perm_blog[1];
  60  }
  61  else
  62  {    // No blog ID, we will check the global group perm
  63      $perm_blog = NULL;
  64  }
  65  //pre_dump( $perm_blog );
  66  
  67  // Check permission (#2):
  68  $current_User->check_perm( 'files', 'view', true, $perm_blog );
  69  
  70  
  71  // Load the other params:
  72  param( 'viewtype', 'string', true, true );
  73  param( 'path', 'string', true, true );
  74  
  75  if ( false !== strpos( urldecode( $path ), '..' ) )
  76  {
  77      debug_die( 'Relative pathnames not allowed!' );
  78  }
  79  
  80  // Load fileroot infos
  81  $FileRootCache = & get_FileRootCache();
  82  $FileRoot = & $FileRootCache->get_by_ID( $root );
  83  
  84  // Create file object
  85  $selected_File = new File( $FileRoot->type , $FileRoot->in_type_ID, $path, true );
  86  
  87  $action = param_action();
  88  switch( $action )
  89  {
  90      case 'rotate_90_left':
  91      case 'rotate_180':
  92      case 'rotate_90_right':
  93          // Check that this action request is not a CSRF hacked request:
  94          $Session->assert_received_crumb( 'image' );
  95  
  96          load_funcs( 'files/model/_image.funcs.php' );
  97  
  98          switch( $action )
  99          {
 100              case 'rotate_90_left':
 101                  $degrees = 90;
 102                  break;
 103              case 'rotate_180':
 104                  $degrees = 180;
 105                  break;
 106              case 'rotate_90_right':
 107                  $degrees = 270;
 108                  break;
 109          }
 110  
 111          if( rotate_image( $selected_File, $degrees ) )
 112          {    // Image was rotated successfully
 113              header_redirect( regenerate_url( 'action,crumb_image', 'action=reload_parent', '', '&' ) );
 114          }
 115          break;
 116  
 117      case 'reload_parent':
 118          // Reload parent window to update rotated image
 119          $JS_additional = 'window.opener.location.reload(true);';
 120          break;
 121  }
 122  
 123  // Add CSS:
 124  require_css( 'basic_styles.css', 'rsc_url' ); // the REAL basic styles
 125  require_css( 'basic.css', 'rsc_url' ); // Basic styles
 126  require_css( 'viewfile.css', 'rsc_url' );
 127  
 128  headers_content_mightcache( 'text/html' );        // In most situations, you do NOT want to cache dynamic content!
 129  ?>
 130  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 131  <html xml:lang="<?php locale_lang() ?>" lang="<?php locale_lang() ?>">
 132  <head>
 133      <title><?php echo $selected_File->dget('name').' ('.T_('Preview').')'; ?></title>
 134      <?php include_headlines() /* Add javascript and css files included by plugins and skin */ ?>
 135  <?php if( isset( $JS_additional ) ) { ?>
 136      <script type="text/javascript"><?php echo $JS_additional; ?></script>
 137  <?php } ?>
 138  </head>
 139  
 140  <body>
 141      <?php
 142  
 143  switch( $viewtype )
 144  {
 145      case 'image':
 146          /*
 147           * Image file view:
 148           */
 149          echo '<div class="img_preview content-type-image">';
 150  
 151          if( $imgSize = $selected_File->get_image_size( 'widthheight' ) )
 152          {
 153              echo '<img ';
 154              if( $alt = $selected_File->dget( 'alt', 'htmlattr' ) )
 155              {
 156                  echo 'alt="'.$alt.'" ';
 157              }
 158              if( $title = $selected_File->dget( 'title', 'htmlattr' ) )
 159              {
 160                  echo 'title="'.$title.'" ';
 161              }
 162              echo 'src="'.$selected_File->get_url().'"'
 163                          .' width="'.$imgSize[0].'" height="'.$imgSize[1].'" />';
 164  
 165              $url_rotate_90_left = regenerate_url( '', 'action=rotate_90_left'.'&'.url_crumb('image') );
 166              $url_rotate_180 = regenerate_url( '', 'action=rotate_180'.'&'.url_crumb('image') );
 167              $url_rotate_90_right = regenerate_url( '', 'action=rotate_90_right'.'&'.url_crumb('image') );
 168  
 169              echo '<div class="center">';
 170              echo action_icon( T_('Rotate this picture 90&deg; to the left'), 'rotate_left', $url_rotate_90_left, '', 0, 0, array( 'style' => 'margin-right:4px' ) );
 171              echo action_icon( T_('Rotate this picture 180&deg;'), 'rotate_180', $url_rotate_180, '', 0, 0, array( 'style' => 'margin-right:4px' ) );
 172              echo action_icon( T_('Rotate this picture 90&deg; to the right'), 'rotate_right', $url_rotate_90_right, '', 0, 0 );
 173              echo '</div>';
 174  
 175              echo '<div class="subline">';
 176              echo '<p><strong>'.$selected_File->dget( 'title' ).'</strong></p>';
 177              echo '<p>'.$selected_File->dget( 'desc' ).'</p>';
 178              echo '<p>'.$selected_File->dget('name').' &middot; ';
 179              echo $selected_File->get_image_size().' &middot; ';
 180              echo $selected_File->get_size_formatted().'</p>';
 181              echo '</div>';
 182  
 183          }
 184          else
 185          {
 186              echo 'error';
 187          }
 188          echo '&nbsp;</div>';
 189          break;
 190  
 191      case 'text':
 192          echo '<div class="content-type-text">';
 193           /*
 194           * Text file view:
 195           */
 196          if( ($buffer = @file( $selected_File->get_full_path() )) !== false )
 197          { // Display raw file
 198              param( 'showlinenrs', 'integer', 0 );
 199  
 200              $buffer_lines = count( $buffer );
 201  
 202              echo '<div class="fileheader">';
 203  
 204              echo '<p>';
 205              echo T_('File').': <strong>'.$selected_File->dget('name').'</strong>';
 206              echo ' &middot; ';
 207              echo T_('Title').': <strong>'.$selected_File->dget( 'title' ).'</strong>';
 208              echo '</p>';
 209  
 210               echo '<p>';
 211              echo T_('Description').': '.$selected_File->dget( 'desc' );
 212              echo '</p>';
 213  
 214  
 215              if( !$buffer_lines )
 216              {
 217                  echo '<p>** '.T_('Empty file!').' ** </p></div>';
 218              }
 219              else
 220              {
 221                  echo '<p>';
 222                  printf( T_('%d lines'), $buffer_lines );
 223  
 224                  $linenr_width = strlen( $buffer_lines+1 );
 225  
 226                  echo ' [';
 227                  ?>
 228                  <noscript type="text/javascript">
 229                      <a href="<?php echo $selected_File->get_url().'&amp;showlinenrs='.(1-$showlinenrs); ?>">
 230  
 231                      <?php echo $showlinenrs ? T_('Hide line numbers') : T_('Show line numbers');
 232                      ?></a>
 233                  </noscript>
 234                  <script type="text/javascript">
 235                      <!--
 236                      document.write('<a id="togglelinenrs" href="javascript:toggle_linenrs()">toggle</a>');
 237  
 238                      showlinenrs = <?php var_export( !$showlinenrs ); ?>;
 239  
 240                      toggle_linenrs();
 241  
 242  					function toggle_linenrs()
 243                      {
 244                          if( showlinenrs )
 245                          {
 246                              var replace = document.createTextNode('<?php echo TS_('Show line numbers') ?>');
 247                              showlinenrs = false;
 248                              var text = document.createTextNode( '' );
 249                              for( var i = 0; i<document.getElementsByTagName("span").length; i++ )
 250                              {
 251                                  if( document.getElementsByTagName("span")[i].hasChildNodes() )
 252                                      document.getElementsByTagName("span")[i].firstChild.data = '';
 253                                  else
 254                                  {
 255                                      document.getElementsByTagName("span")[i].appendChild( text );
 256                                  }
 257                              }
 258                          }
 259                          else
 260                          {
 261                              var replace = document.createTextNode('<?php echo TS_('Hide line numbers') ?>');
 262                              showlinenrs = true;
 263                              for( var i = 0; i<document.getElementsByTagName("span").length; i++ )
 264                              {
 265                                  var text = String(i+1);
 266                                  var upto = <?php echo $linenr_width ?>-text.length;
 267                                  for( var j=0; j<upto; j++ ){ text = ' '+text; }
 268                                  if( document.getElementsByTagName("span")[i].hasChildNodes() )
 269                                      document.getElementsByTagName("span")[i].firstChild.data = ' '+text+' ';
 270                                  else
 271                                      document.getElementsByTagName("span")[i].appendChild( document.createTextNode( ' '+text+' ' ) );
 272                              }
 273                          }
 274  
 275                          document.getElementById('togglelinenrs').replaceChild(replace, document.getElementById( 'togglelinenrs' ).firstChild);
 276                      }
 277                      -->
 278                  </script>
 279                  <?php
 280  
 281                  echo ']</p>';
 282                  echo '</div>';
 283  
 284                  echo '<pre class="rawcontent">';
 285  
 286                  for( $i = 0; $i < $buffer_lines; $i++ )
 287                  {
 288                      echo '<span name="linenr" class="linenr">';
 289                      if( $showlinenrs )
 290                      {
 291                          echo ' '.str_pad($i+1, $linenr_width, ' ', STR_PAD_LEFT).' ';
 292                      }
 293                      echo '</span>'.htmlspecialchars( str_replace( "\t", '  ', $buffer[$i] ) );  // TODO: customize tab-width
 294                  }
 295  
 296                echo '</pre>';
 297  
 298                  echo '<div class="eof">** '.T_('End Of File').' **</div>';
 299              }
 300          }
 301          else
 302          {
 303              echo '<p class="error">'.sprintf( T_('The file &laquo;%s&raquo; could not be accessed!'), $selected_File->get_rdfs_rel_path( $selected_File ) ).'</p>';
 304          }
 305          echo '</div>';
 306          break;
 307  
 308      default:
 309          echo '<p class="error">'.sprintf( T_('The file &laquo;%s&raquo; could not be accessed!'), $selected_File->dget('name') ).'</p>';
 310          break;
 311  }
 312  ?>
 313  
 314  </body>
 315  </html>

title

Description

title

Description

title

Description

title

title

Body