plugins/gallery/search.php
author Dan
Thu, 26 Jul 2007 10:37:10 -0400
changeset 5 c0c324f0eeb5
parent 4 ad3b061a1c76
child 13 f6ca7cead82c
permissions -rw-r--r--
Added the Random Image sidebar block
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)';
4
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    32
  $sql = "SELECT img_id, img_title, img_desc, is_folder, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    33
              WHERE $fulltext_col > 0
4
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    34
                AND ( ( is_folder=1 AND folder_parent IS NULL ) OR is_folder!=1 )
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    35
              ORDER BY is_folder DESC, score DESC, img_title ASC;";
2
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();
4
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    46
    $fullpage = $paths->fullpage;
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    47
    $paths->fullpage = $paths->nslist['Special'] . 'Gallery';
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    48
    do
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
      echo $renderer->render(false, $row, false);
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    51
    }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    52
    while ( $row = $db->fetchrow() );
4
ad3b061a1c76 A few minor bugfixes and visual enhancements for admins
Dan
parents: 2
diff changeset
    53
    $paths->fullpage = $fullpage;
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    54
    echo '</tr></table>';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    55
  }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    56
  else
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
    echo '<p>No image results.</p>';
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    59
  }
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    60
}
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    61
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    62
?>