# HG changeset patch
# User Dan
# Date 1195676533 18000
# Node ID f6ca7cead82cf2c217af2d288bd93fe659469233
# Parent b38afb86dcad6761b751168ee2cc353124dea31c
Updated with support for Enano's new search API
diff -r b38afb86dcad -r f6ca7cead82c plugins/gallery/browser.css
--- a/plugins/gallery/browser.css Thu Aug 09 12:34:39 2007 -0400
+++ b/plugins/gallery/browser.css Wed Nov 21 15:22:13 2007 -0500
@@ -11,6 +11,8 @@
display: table;
margin: 0 auto;
padding: 4px;
+ width: 80px;
+ white-space: nowrap;
}
div.gallery_icon:hover {
@@ -20,5 +22,28 @@
div.gallery_icon img.gallery_thumb {
display: block;
border-width: 0;
- margin: 0 auto 6px auto;
+ margin: auto auto 6px auto;
+}
+
+ul.snapr-gallery {
+ list-style-type: none !important;
+ list-style-image: none !important;
+ margin-left: 0;
+ padding-left: 0;
}
+
+ul.snapr-gallery li.snapr-icon {
+ float: left;
+ list-style-type: none !important;
+ list-style-image: none !important;
+ width: 80px;
+ margin-right: 15px;
+}
+
+a.snapr-imagelink {
+ display: block;
+ height: 80px;
+ vertical-align: middle;
+}
+
+
diff -r b38afb86dcad -r f6ca7cead82c plugins/gallery/browser.php
--- a/plugins/gallery/browser.php Thu Aug 09 12:34:39 2007 -0400
+++ b/plugins/gallery/browser.php Wed Nov 21 15:22:13 2007 -0500
@@ -37,20 +37,6 @@
{
/**
- * Counter for how many cells we've printed out in this row.
- * @var int
- */
-
- var $cell_count = 0;
-
- /**
- * Icons to print per row.
- * @var int
- */
-
- var $icons_per_row = 5;
-
- /**
* Main render method, called from pagination function
* @access private
*/
@@ -59,14 +45,7 @@
{
global $db, $session, $paths, $template, $plugins; // Common objects
- $out = '';
-
- if ( $this->cell_count == $this->icons_per_row )
- {
- $out .= '
';
- $this->cell_count = 0;
- }
- $this->cell_count++;
+ $out = '';
$title_safe = $row['img_title'];
$title_safe = htmlspecialchars($title_safe);
@@ -94,18 +73,17 @@
$image_url_js = addslashes($image_link);
$jsclick = ( $session->user_level < USER_LEVEL_ADMIN ) ? ' onclick="window.location=\'' . $image_url_js . '\'"' : '';
- $out .= '
- ';
+ $out .= ' ';
- $out .= ' ';
+ $out .= ' ';
if ( $session->user_level < USER_LEVEL_ADMIN )
{
- $out .= $title_safe . ( isset($row['score']) ? " Relevance: {$row['score']}" : '' );
+ $out .= ' ' . $title_safe . ( isset($row['score']) ? " Relevance: {$row['score']}" : '' ) . '';
}
else if ( $session->user_level >= USER_LEVEL_ADMIN )
{
- $out .= ' | ';
+ $out .= '';
return $out;
}
@@ -486,9 +464,9 @@
$start = intval($_GET['start']);
}
- $per_page = $rows_in_browser * 5;
+ $per_page = 25;
- $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', false), $start, $per_page, $callers, '');
+ $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', false), $start, $per_page, $callers, '');
echo $html;
if ( $session->user_level >= USER_LEVEL_ADMIN )
diff -r b38afb86dcad -r f6ca7cead82c plugins/gallery/search.php
--- a/plugins/gallery/search.php Thu Aug 09 12:34:39 2007 -0400
+++ b/plugins/gallery/search.php Wed Nov 21 15:22:13 2007 -0500
@@ -17,6 +17,7 @@
//
$plugins->attachHook('search_results', 'gal_searcher($q, $offset);');
+$plugins->attachHook('search_global_inner', 'snapr_search_new_api($query, $query_phrase, $scores, $page_data, $case_sensitive, $word_list);');
$plugins->attachHook('compile_template', '
// CSS for gallery browser
@@ -27,6 +28,8 @@
function gal_searcher($q, $offset)
{
global $db, $session, $paths, $template, $plugins; // Common objects
+ if ( defined('SNAPR_SEARCH_USING_NEW_API') )
+ return false;
$fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)';
$sql = "SELECT img_id, img_title, img_desc, is_folder, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery
@@ -41,7 +44,7 @@
echo "Image results
";
if ( $row = $db->fetchrow() )
{
- echo '';
+ echo '';
$renderer = new SnaprFormatter();
$fullpage = $paths->fullpage;
$paths->fullpage = $paths->nslist['Special'] . 'Gallery';
@@ -51,7 +54,7 @@
}
while ( $row = $db->fetchrow() );
$paths->fullpage = $fullpage;
- echo '
';
+ echo '';
}
else
{
@@ -59,4 +62,125 @@
}
}
+function snapr_search_new_api(&$query, &$query_phrase, &$scores, &$page_data, &$case_sensitive, &$word_list)
+{
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( !defined('SNAPR_SEARCH_USING_NEW_API') )
+ define('SNAPR_SEARCH_USING_NEW_API', 1);
+
+ // Let's do this all in one query
+ $terms = array(
+ 'any' => array_merge($query['any'], $query_phrase['any']),
+ 'req' => array_merge($query['req'], $query_phrase['req']),
+ 'not' => $query['not']
+ );
+ $where = array('any' => array(), 'req' => array(), 'not' => array());
+ $where_any =& $where['any'];
+ $where_req =& $where['req'];
+ $where_not =& $where['not'];
+ $title_col = ( $case_sensitive ) ? 'img_title' : 'lcase(img_title)';
+ $desc_col = ( $case_sensitive ) ? 'img_desc' : 'lcase(img_desc)';
+ foreach ( $terms['any'] as $term )
+ {
+ $term = escape_string_like($term);
+ if ( !$case_sensitive )
+ $term = strtolower($term);
+ $where_any[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )";
+ }
+ foreach ( $terms['req'] as $term )
+ {
+ $term = escape_string_like($term);
+ if ( !$case_sensitive )
+ $term = strtolower($term);
+ $where_req[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )";
+ }
+ foreach ( $terms['not'] as $term )
+ {
+ $term = escape_string_like($term);
+ if ( !$case_sensitive )
+ $term = strtolower($term);
+ $where_not[] = "$title_col NOT LIKE '%{$term}%' AND $desc_col NOT LIKE '%{$term}%'";
+ }
+ if ( empty($where_any) )
+ unset($where_any, $where['any']);
+ if ( empty($where_req) )
+ unset($where_req, $where['req']);
+ if ( empty($where_not) )
+ unset($where_not, $where['not']);
+
+ $where_any = '(' . implode(' OR ', $where_any) . '' . ( isset($where['req']) || isset($where['not']) ? ' OR 1 = 1' : '' ) . ')';
+
+ if ( isset($where_req) )
+ $where_req = implode(' AND ', $where_req);
+ if ( isset($where_not) )
+ $where_not = implode( 'AND ', $where_not);
+
+ $where = implode(' AND ', $where);
+ $sql = "SELECT img_id, img_title, img_desc FROM " . table_prefix . "gallery WHERE ( $where ) AND is_folder = 0;";
+
+ if ( !($q = $db->sql_unbuffered_query($sql)) )
+ {
+ $db->_die('Error is in auto-generated SQL query in the Snapr plugin search module');
+ }
+
+ if ( $row = $db->fetchrow() )
+ {
+ do
+ {
+ $idstring = 'ns=Image;pid=' . $row['img_id'];
+ foreach ( $word_list as $term )
+ {
+ if ( $case_sensitive )
+ {
+ if ( strstr($row['img_title'], $term) || strstr($row['img_desc'], $term) )
+ {
+ ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1;
+ }
+ }
+ else
+ {
+ if ( strstr(strtolower($row['img_title']), strtolower($term)) || strstr(strtolower($row['img_desc']), strtolower($term)) )
+ {
+ ( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1;
+ }
+ }
+ }
+ // Generate text...
+ $text = highlight_and_clip_search_result(htmlspecialchars($row['img_desc']), $word_list);
+
+ $preview_and_text = '
+
+
+
+ ' . $text . '
+ |
+
+
+ |
+
+
+ ';
+
+ // Inject result
+
+ if ( isset($scores[$idstring]) )
+ {
+ // echo('adding image "' . $row['img_title'] . '" to results
');
+ $page_data[$idstring] = array(
+ 'page_name' => highlight_search_result(htmlspecialchars($row['img_title']), $word_list),
+ 'page_text' => $preview_and_text,
+ 'score' => $scores[$idstring],
+ 'page_note' => '[Gallery image]',
+ 'page_id' => strval($row['img_id']),
+ 'namespace' => 'Image',
+ 'page_length' => strlen($row['img_desc']),
+ );
+ }
+ }
+ while ( $row = $db->fetchrow() );
+
+ }
+}
+
?>
diff -r b38afb86dcad -r f6ca7cead82c plugins/gallery/sidebar.php
--- a/plugins/gallery/sidebar.php Thu Aug 09 12:34:39 2007 -0400
+++ b/plugins/gallery/sidebar.php Wed Nov 21 15:22:13 2007 -0500
@@ -38,7 +38,7 @@
$rand = array_rand($images);
$image = $images[$rand];
$acl = $session->fetch_page_acl(strval($rand), 'Gallery');
- if ( $acl->get_permissions('read') )
+ if ( is_object($acl) && $acl->get_permissions('read') )
{
$my_image = $image;
break;