includes/functions.php
changeset 481 07bf15b066bc
parent 479 192db6ac195b
child 500 455277559782
equal deleted inserted replaced
480:d5376271f96b 481:07bf15b066bc
   812   $selfn = $paths->page_id;
   812   $selfn = $paths->page_id;
   813   if ( substr($paths->cpage['name'], 0, strlen($paths->nslist['File'])) == $paths->nslist['File'])
   813   if ( substr($paths->cpage['name'], 0, strlen($paths->nslist['File'])) == $paths->nslist['File'])
   814   {
   814   {
   815     $selfn = substr($paths->page_id, strlen($paths->nslist['File']), strlen($paths->page_id));
   815     $selfn = substr($paths->page_id, strlen($paths->nslist['File']), strlen($paths->page_id));
   816   }
   816   }
   817   $q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;');
   817   $selfn = $db->escape($selfn);
       
   818   $q = $db->sql_query('SELECT f.mimetype,f.time_id,f.size,l.log_id FROM ' . table_prefix . "files AS f\n"
       
   819                     . "  LEFT JOIN " . table_prefix . "logs AS l\n"
       
   820                     . "    ON ( l.time_id = f.time_id AND ( l.action = 'reupload' OR l.action IS NULL ) )\n"
       
   821                     . "  WHERE f.page_id = '$selfn'\n"
       
   822                     . "    ORDER BY f.time_id DESC;");
   818   if ( !$q )
   823   if ( !$q )
   819   {
   824   {
   820     $db->_die('The file type could not be fetched.');
   825     $db->_die('The file type could not be fetched.');
   821   }
   826   }
   822   
   827   
   843   }
   848   }
   844   else if ( $r['size'] >= 1024 )
   849   else if ( $r['size'] >= 1024 )
   845   {
   850   {
   846     $size .= ' (' . ( round($r['size'] / 1024, 1) ) . ' ' . $lang->get('etc_unit_kilobytes_short') . ')';
   851     $size .= ' (' . ( round($r['size'] / 1024, 1) ) . ' ' . $lang->get('etc_unit_kilobytes_short') . ')';
   847   }
   852   }
   848           
   853   
   849   echo $lang->get('onpage_filebox_lbl_size', array('size' => $size));
   854   echo $lang->get('onpage_filebox_lbl_size', array('size' => $size));
   850   
   855   
   851   echo '<br />' . $lang->get('onpage_filebox_lbl_uploaded') . ' ' . $datestring . '</p>';
   856   echo '<br />' . $lang->get('onpage_filebox_lbl_uploaded') . ' ' . $datestring . '</p>';
   852   if ( substr($mimetype, 0, 6) != 'image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' ) )
   857   if ( substr($mimetype, 0, 6) != 'image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' ) )
   853   {
   858   {
   874           </a>';
   879           </a>';
   875   }
   880   }
   876   echo '</p>';
   881   echo '</p>';
   877   if ( $db->numrows() > 1 )
   882   if ( $db->numrows() > 1 )
   878   {
   883   {
       
   884     // requery, sql_result_seek() doesn't work on postgres
       
   885     $db->free_result();
       
   886     $q = $db->sql_query('SELECT f.mimetype,f.time_id,f.size,l.log_id FROM ' . table_prefix . "files AS f\n"
       
   887                     . "  LEFT JOIN " . table_prefix . "logs AS l\n"
       
   888                     . "    ON ( l.time_id = f.time_id AND ( l.action = 'reupload' OR l.action IS NULL ) )\n"
       
   889                     . "  WHERE f.page_id = '$selfn'\n"
       
   890                     . "    ORDER BY f.time_id DESC;");
       
   891     if ( !$q )
       
   892       $db->_die();
       
   893     
   879     echo '<h3>' . $lang->get('onpage_filebox_heading_history') . '</h3><p>';
   894     echo '<h3>' . $lang->get('onpage_filebox_heading_history') . '</h3><p>';
       
   895     $last_rollback_id = false;
   880     while ( $r = $db->fetchrow() )
   896     while ( $r = $db->fetchrow() )
   881     {
   897     {
   882       echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">' . $lang->get('onpage_filebox_btn_this_version') . '</a>) ';
   898       echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">' . $lang->get('onpage_filebox_btn_this_version') . '</a>) ';
   883       if ( $session->get_permissions('history_rollback') )
   899       if ( $session->get_permissions('history_rollback') && $last_rollback_id )
   884         echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">' . $lang->get('onpage_filebox_btn_revert') . '</a>) ';
   900         echo ' (<a href="#rollback:' . $last_rollback_id . '" onclick="ajaxRollback(\''.$last_rollback_id.'\'); return false;">' . $lang->get('onpage_filebox_btn_revert') . '</a>) ';
       
   901       else if ( $session->get_permissions('history_rollback') && !$last_rollback_id )
       
   902         echo ' (' . $lang->get('onpage_filebox_btn_current') . ') ';
       
   903       $last_rollback_id = $r['log_id'];
   885       $mimetype = $r['mimetype'];
   904       $mimetype = $r['mimetype'];
   886       $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']);
   905       $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']);
   887       
   906       
   888       echo $datestring.': '.$r['mimetype'].', ';
   907       echo $datestring.': '.$r['mimetype'].', ';
   889       
   908       
  4187 function get_line_count($string)
  4206 function get_line_count($string)
  4188 {
  4207 {
  4189   return ( get_char_count($string, "\n") ) + 1;
  4208   return ( get_char_count($string, "\n") ) + 1;
  4190 }
  4209 }
  4191 
  4210 
       
  4211 if ( !function_exists('sys_get_temp_dir') )
       
  4212 {
       
  4213     // Based on http://www.phpit.net/
       
  4214     // article/creating-zip-tar-archives-dynamically-php/2/
       
  4215     /**
       
  4216      * Attempt to get the system's temp directory.
       
  4217      * @return string or bool false on failure
       
  4218      */
       
  4219     
       
  4220     function sys_get_temp_dir()
       
  4221     {
       
  4222         // Try to get from environment variable
       
  4223         if ( !empty($_ENV['TMP']) )
       
  4224         {
       
  4225             return realpath( $_ENV['TMP'] );
       
  4226         }
       
  4227         else if ( !empty($_ENV['TMPDIR']) )
       
  4228         {
       
  4229             return realpath( $_ENV['TMPDIR'] );
       
  4230         }
       
  4231         else if ( !empty($_ENV['TEMP']) )
       
  4232         {
       
  4233             return realpath( $_ENV['TEMP'] );
       
  4234         }
       
  4235 
       
  4236         // Detect by creating a temporary file
       
  4237         else
       
  4238         {
       
  4239             // Try to use system's temporary directory
       
  4240             // as random name shouldn't exist
       
  4241             $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
       
  4242             if ( $temp_file )
       
  4243             {
       
  4244                 $temp_dir = realpath( dirname($temp_file) );
       
  4245                 unlink( $temp_file );
       
  4246                 return $temp_dir;
       
  4247             }
       
  4248             else
       
  4249             {
       
  4250                 return FALSE;
       
  4251             }
       
  4252         }
       
  4253     }
       
  4254 }
       
  4255 
  4192 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  4256 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  4193 
  4257 
  4194 ?>
  4258 ?>