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?)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     1
<?php
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     3
/*
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     4
 * Snapr
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     5
 * Version 0.1 beta 1
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     6
 * Copyright (C) 2007 Dan Fuhry
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     7
 *
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    10
 *
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    13
 */
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    14
 
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    15
//
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    16
// Search results hook
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    17
//
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    18
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    19
$plugins->attachHook('search_results', 'gal_searcher($q, $offset);');
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    20
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    21
$plugins->attachHook('compile_template', '
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    22
  // CSS for gallery browser
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    23
  $template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/browser.css" type="text/css" />\');
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    24
  $template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/dropdown.css" type="text/css" />\');
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    25
  ');
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    26
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    27
function gal_searcher($q, $offset)
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    28
{
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    29
  global $db, $session, $paths, $template, $plugins; // Common objects
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    30
  
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    31
  $fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    32
  $sql = "SELECT img_id, img_title, img_desc, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    33
              WHERE $fulltext_col > 0
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    34
                AND is_folder=0
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    35
              ORDER BY score DESC;";
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    36
  if ( !$db->sql_unbuffered_query($sql) )
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    37
  {
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    38
    echo $db->get_error();
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    39
    return false;
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    40
  }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    41
  echo "<h3>Image results</h3>";
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    42
  if ( $row = $db->fetchrow() )
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    43
  {
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    44
    echo '<table border="0" cellspacing="8"><tr>';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    45
    $renderer = new SnaprFormatter();
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    46
    do
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    47
    {
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    48
      echo $renderer->render(false, $row, false);
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    49
    }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    50
    while ( $row = $db->fetchrow() );
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    51
    echo '</tr></table>';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    52
  }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    53
  else
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    54
  {
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    55
    echo '<p>No image results.</p>';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    56
  }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    57
}
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    58
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    59
?>