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