Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
authorDan
Thu, 09 Aug 2007 12:31:24 -0400
changeset 9 ebd7003e73c6
parent 8 8490ce0cdd8c
child 10 b38afb86dcad
Snapr now works with Enano's HTML/gzip optimization switches (1.0 compatibility broken, need 1.0.1 now)
plugins/Gallery.php
plugins/gallery/browser.php
plugins/gallery/fetcher.php
plugins/gallery/viewimage.php
--- a/plugins/gallery/browser.php	Thu Jul 26 14:43:45 2007 -0400
+++ b/plugins/gallery/browser.php	Thu Aug 09 12:31:24 2007 -0400
@@ -352,7 +352,8 @@
   {
     if ( !isset($first_row['folder_id']) )
     {
-      $first_row['folder_id'] =& $first_row['img_id'];
+      // $first_row['folder_id'] =& $first_row['img_id'];
+      $first_row['folder_id'] = 'NULL';
     }
     if ( !isset($first_row['folder_id']) )
     {
@@ -488,8 +489,21 @@
   
   $per_page = $rows_in_browser * 5;
   
-  $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', true), $start, $per_page, $callers, '<table border="0" cellspacing="8"><tr>', '</tr></table>');
-  echo $html;
+  if ( $db->numrows($img_query) < 1 )
+  {
+    $html = '';
+    if ( $session->user_level >= USER_LEVEL_ADMIN )
+    {
+      $html .= '<p><a href="' . makeUrlNS('Special', 'GalleryUpload', 'folder=' . $first_row['img_id'], true) . '">Upload an image</a></p>';
+    }
+    
+    echo '<p>There are no items in this folder.</p>' . $html;
+  }
+  else
+  {
+    $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', true), $start, $per_page, $callers, '<table border="0" cellspacing="8"><tr>', '</tr></table>');
+    echo $html;
+  }
   
   if ( $session->user_level >= USER_LEVEL_ADMIN )
   {
--- a/plugins/gallery/fetcher.php	Thu Jul 26 14:43:45 2007 -0400
+++ b/plugins/gallery/fetcher.php	Thu Aug 09 12:31:24 2007 -0400
@@ -50,7 +50,7 @@
     $type = 'preview';
   }
   
-  $q = $db->sql_query('SELECT img_filename, img_time_mod, is_folder FROM '.table_prefix.'gallery WHERE img_id=' . $id . ';');
+  $q = $db->sql_query('SELECT img_title, img_filename, img_time_mod, is_folder FROM '.table_prefix.'gallery WHERE img_id=' . $id . ';');
   if ( !$q )
     $db->_die();
   
@@ -64,10 +64,12 @@
     case 'thumb':
       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-thumb.jpg';
       $mimetype = 'image/jpeg';
+      $ext = "jpg";
       break;
     case 'preview':
       $filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . '-preview.jpg';
       $mimetype = 'image/jpeg';
+      $ext = "jpg";
       break;
     case 'full':
       $filename = ENANO_ROOT . '/files/' . $row['img_filename'];
@@ -109,8 +111,23 @@
   header('Content-length: ' . strlen($contents));
   header('Last-Modified: '  . date('r', $row['img_time_mod']));
   
+  if ( isset($_GET['download']) )
+  {
+    // determine an appropriate non-revealing filename
+    $filename = str_replace(' ', '_', $row['img_title']);
+    $filename = preg_replace('/([^\w\._-]+)/', '-', $filename);
+    $filename = trim($filename, '-');
+    $filename .= ".$ext";
+    header('Content-disposition: attachment; filename=' . $filename);
+  }
+  
   echo $contents;
   
+  gzip_output();
+  
+  $db->close();
+  exit;
+  
 }
 
 ?>
--- a/plugins/gallery/viewimage.php	Thu Jul 26 14:43:45 2007 -0400
+++ b/plugins/gallery/viewimage.php	Thu Aug 09 12:31:24 2007 -0400
@@ -36,7 +36,7 @@
     $img_id = intval($page->page_id);
     if ( !$img_id )
       return false;
-    $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, folder_parent FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';');
+    $q = $db->sql_query('SELECT img_id, img_title, img_desc, print_sizes, img_time_upload, img_time_mod, img_filename, folder_parent FROM '.table_prefix.'gallery WHERE img_id=' . $img_id . ';');
     if ( !$q )
       $db->_die();
   }
@@ -61,7 +61,7 @@
     
     $folders = array_reverse($folders);
     // This is one of the best MySQL tricks on the market. We're going to reverse-travel a folder path using LEFT JOIN and the incredible power of metacoded SQL
-    $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.folder_parent FROM '.table_prefix.'gallery AS g0';
+    $sql = 'SELECT g0.img_id, g0.img_title, g0.img_desc, g0.print_sizes, g0.img_time_upload, g0.img_time_mod, g0.img_filename, g0.folder_parent FROM '.table_prefix.'gallery AS g0';
     $where = "\n  " . 'WHERE g0.img_title=\'' . $db->escape($folders[0]) . '\'';
     foreach ( $folders as $i => $folder )
     {
@@ -257,9 +257,14 @@
   // By the time I got to this point, it was 1:32AM (I was on vacation) and my 5-hour playlist on my iPod had been around about 3 times today.
   // So I'm glad this is like the last thing on the list tonight.
   
+  $ext = get_file_extension($row['img_filename']);
+  $ext = strtoupper($ext);
+  
   echo '<tr><th colspan="2">Image details</th></tr>';
   echo '<tr><td class="row2">Uploaded:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_upload']) . '</td></tr>';
   echo '<tr><td class="row2">Last modified:</td><td class="row1">' . date('F d, Y h:i a', $row['img_time_mod']) . '</td></tr>';
+  echo '<tr><td class="row2">Original format:</td><td class="row1">' . $ext . '</td></tr>';
+  echo '<tr><td class="row3" colspan="2" style="text-align: center;"><a href="' . makeUrlNS('Special', 'GalleryFetcher/full/' . $img_id, 'download', 'true') . '">Download image</a></td></tr>';
           
   echo '</table></div>';