plugins/gallery/search.php
author Dan
Wed, 25 Jul 2007 18:25:24 -0400
changeset 3 10d663f5ed88
parent 2 88c954d2846c
child 4 ad3b061a1c76
permissions -rw-r--r--
Added check in upload wizard to prevent folders from being added to one of their children or to themselves (fatal error: maximum execution time of 600 seconds exceeded anyone?)

<?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>';
  }
}

?>