Added search functionality (WiP); removed stray .marks file
authorDan
Wed, 25 Jul 2007 18:15:14 -0400
changeset 2 88c954d2846c
parent 1 94af07c8f2f3
child 3 10d663f5ed88
Added search functionality (WiP); removed stray .marks file
plugins/Gallery.php
plugins/gallery/.upload.php.marks
plugins/gallery/browser.php
plugins/gallery/search.php
plugins/gallery/upload.php
plugins/gallery/viewimage.php
--- a/plugins/Gallery.php	Wed Jul 25 16:43:47 2007 -0400
+++ b/plugins/Gallery.php	Wed Jul 25 18:15:14 2007 -0400
@@ -34,9 +34,12 @@
                         img_time_mod int(12) NOT NULL DEFAULT 0,
                         PRIMARY KEY ( img_id )
                       );');
+  
   if ( !$q )
     $db->_die();
   
+  $q = $db->sql_query('CREATE FULLTEXT INDEX '.table_prefix.'gal_idx ON '.table_prefix.'gallery(img_title, img_desc);');
+  
   setConfig('gallery_version', GALLERY_VERSION);
 }
 
@@ -46,5 +49,6 @@
 require( ENANO_ROOT . '/plugins/gallery/browser.php' );
 require( ENANO_ROOT . '/plugins/gallery/upload.php' );
 require( ENANO_ROOT . '/plugins/gallery/fetcher.php' );
+require( ENANO_ROOT . '/plugins/gallery/search.php' );
 
 ?>
--- a/plugins/gallery/.upload.php.marks	Wed Jul 25 16:43:47 2007 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-!u;8818;8818
-!e;12994;12994
-!z;22686;22686
-!f;35274;35274
--- a/plugins/gallery/browser.php	Wed Jul 25 16:43:47 2007 -0400
+++ b/plugins/gallery/browser.php	Wed Jul 25 18:15:14 2007 -0400
@@ -163,8 +163,9 @@
   $breadcrumb_urlcache = '';
   
   // CSS for gallery browser
-  $template->add_header('<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/browser.css" type="text/css" />');
-  $template->add_header('<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/dropdown.css" type="text/css" />');
+  // Moved to search.php
+  //$template->add_header('<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/browser.css" type="text/css" />');
+  //$template->add_header('<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/dropdown.css" type="text/css" />');
   
   $header = $template->getHeader();
   
@@ -226,6 +227,45 @@
     //   1) The folder doesn't exist
     //   2) The folder exists but doesn't have any images in it
     
+    if ( sizeof($folders) < 1 )
+    {
+      // Nothing in the root folder
+      
+      $first_row['folder_id'] = 'NULL';
+      if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) && isset($first_row['folder_id']) )
+      {
+        if ( empty($_POST['create_folder']) )
+        {
+          $f_errors[] = 'Please enter a folder name.';
+        }
+        if ( $_POST['create_folder'] == '_id' )
+        {
+          $f_errors[] = 'The name "_id" is reserved for internal functions and cannot be used on any image or folder.';
+        }
+        if ( count($f_errors) < 1 )
+        {
+          $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title, is_folder, folder_parent) VALUES(\'' . $db->escape($_POST['create_folder']) . '\', 1, ' . $first_row['folder_id'] . ');');
+          if ( !$q )
+            $db->_die();
+          redirect(makeUrl($paths->fullpage), 'Folder created', 'The folder "' . htmlspecialchars($_POST['create_folder']) . '" has been created. Redirecting to last viewed folder...', 2);
+        }
+      }
+      
+      $html = '';
+      if ( $session->user_level >= USER_LEVEL_ADMIN )
+      {
+        $html .= '<p><a href="' . makeUrlNS('Special', 'GalleryUpload') . '">Upload an image</a></p>';
+        $html .= '<div class="select-outer">Create new folder';
+        $html .= '<div class="select-inner" style="padding-top: 4px;">';
+        $html .= '<form action="' . makeUrl($paths->fullpage) . '" method="post">';
+        $html .= '<input type="text" name="create_folder" size="30" /> <input type="submit" value="Create" />';
+        $html .= '</form></div>';
+        $html .= '</div><div class="select-pad">&nbsp;</div><br />';
+      }
+      
+      die_friendly('No images', '<p>No images have been uploaded to the gallery yet.</p>' . $html);
+    }
+    
     /*
     $folders_old = $folders;
     $folders = array(
@@ -303,8 +343,16 @@
   
   $f_errors = array();
   
-  if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) && isset($first_row['folder_id']) )
+  if ( $session->user_level >= USER_LEVEL_ADMIN && isset($_POST['create_folder']) )
   {
+    if ( !isset($first_row['folder_id']) )
+    {
+      $first_row['folder_id'] =& $first_row['img_id'];
+    }
+    if ( !isset($first_row['folder_id']) )
+    {
+      $f_errors[] = 'Internal error getting parent folder ID';
+    }
     if ( empty($_POST['create_folder']) )
     {
       $f_errors[] = 'Please enter a folder name.';
@@ -435,7 +483,7 @@
   
   $per_page = $rows_in_browser * 5;
   
-  $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'start=%s', true), $start, $per_page, $callers, '<table border="0" cellspacing="8"><tr>', '</tr></table>');
+  $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 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/gallery/search.php	Wed Jul 25 18:15:14 2007 -0400
@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * Snapr
+ * Version 0.1 beta 1
+ * Copyright (C) 2007 Dan Fuhry
+ *
+ * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ */
+ 
+//
+// Search results hook
+//
+
+$plugins->attachHook('search_results', 'gal_searcher($q, $offset);');
+
+$plugins->attachHook('compile_template', '
+  // CSS for gallery browser
+  $template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/browser.css" type="text/css" />\');
+  $template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/dropdown.css" type="text/css" />\');
+  ');
+
+function gal_searcher($q, $offset)
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  
+  $fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)';
+  $sql = "SELECT img_id, img_title, img_desc, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery
+              WHERE $fulltext_col > 0
+                AND is_folder=0
+              ORDER BY score DESC;";
+  if ( !$db->sql_unbuffered_query($sql) )
+  {
+    echo $db->get_error();
+    return false;
+  }
+  echo "<h3>Image results</h3>";
+  if ( $row = $db->fetchrow() )
+  {
+    echo '<table border="0" cellspacing="8"><tr>';
+    $renderer = new SnaprFormatter();
+    do
+    {
+      echo $renderer->render(false, $row, false);
+    }
+    while ( $row = $db->fetchrow() );
+    echo '</tr></table>';
+  }
+  else
+  {
+    echo '<p>No image results.</p>';
+  }
+}
+
+?>
--- a/plugins/gallery/upload.php	Wed Jul 25 16:43:47 2007 -0400
+++ b/plugins/gallery/upload.php	Wed Jul 25 18:15:14 2007 -0400
@@ -41,6 +41,26 @@
   $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/gallery/dropdown.css" />');
   $template->add_header('<script type="text/javascript" src="' . scriptPath . '/plugins/gallery/gallery-bits.js"></script>');
   
+  $max_size = @ini_get('upload_max_filesize');
+  $max_size_field = '';
+  if ( $max_size )
+  {
+    if ( preg_match('/M$/i', $max_size) )
+    {
+      $max_size = intval($max_size) * 1048576;
+    }
+    else if ( preg_match('/K$/i', $max_size) )
+    {
+      $max_size = intval($max_size) * 1024;
+    }
+    else if ( preg_match('/G$/i', $max_size) )
+    {
+      $max_size = intval($max_size) * 1048576 * 1024;
+    }
+    $max_size = intval($max_size);
+    $max_size_field = "\n" . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max_size . '" />' . "\n";
+  }
+  
   if ( isset($_GET['edit_img']) )
   {
     $edit_parms = $_GET['edit_img'];
@@ -284,6 +304,8 @@
     
     echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'edit_img=' . $edit_parms, true) . '" method="post" enctype="multipart/form-data">';
     
+    echo $max_size_field;
+    
     if ( $row = $db->fetchrow($e) )
     {
       
@@ -486,7 +508,7 @@
                 echo gallery_hier_formfield('override_folder', false);
               ?>
               <br />
-              <a href="#" onclick="gal_unset_radios('override_folder'); return false;">Unselect folder override field</a>
+              <a href="#" onclick="gal_unset_radios('override_folder'); return false;">Unselect field</a>
             </div>
           </div>
         </td>
@@ -594,6 +616,7 @@
       $template->header();
       
       echo '<form action="' . makeUrlNS('Special', 'GalleryUpload', 'rm=' . $rm_id, true) . '" method="post" enctype="multipart/form-data">';
+      echo $max_size_field;
       
       echo '<h3>Are you sure you want to delete this item?</h3>';
       echo '<p>If you continue, this item will be permanently deleted from the gallery &ndash; no rollbacks.</p>';
@@ -954,6 +977,7 @@
   <?php
   
   echo '<form action="' . makeUrlNS('Special', 'GalleryUpload') . '" enctype="multipart/form-data" method="post">';
+  echo $max_size_field;
   if ( count($errors) > 0 )
   {
     echo '<div class="error-box">
--- a/plugins/gallery/viewimage.php	Wed Jul 25 16:43:47 2007 -0400
+++ b/plugins/gallery/viewimage.php	Wed Jul 25 18:15:14 2007 -0400
@@ -200,7 +200,7 @@
   
   if ( $perms->get_permissions('gal_full_res') )
   {
-    echo '<a href="' . $img_href . '" title="Click to view this image at full resolution, right click to save image" onclick="window.open(this.href, \'\', \'toolbar=no,address=no,menus=no,status=no\'); return false;">';
+    echo '<a href="' . $img_href . '" title="Click to view this image at full resolution, right click to save image" onclick="window.open(this.href, \'\', \'toolbar=no,address=no,menus=no,status=no,scrollbars=yes\'); return false;">';
   }
   
   echo '<img alt="Image preview (640px max width)" src="' . $img_url . '" style="border-width: 0; margin-bottom: 5px; display: block;" />';