plugins/gallery/search.php
author Dan Fuhry <dan@enanocms.org>
Sat, 21 Aug 2010 23:35:20 -0400
changeset 43 7df4993be0b0
parent 42 7c6e2e97aa08
permissions -rw-r--r--
Some minimal no-javascript safety for the uploader
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
31
3e8d2acd7388 Fixed a minor offset issue in search hook
Dan
parents: 16
diff changeset
    19
$plugins->attachHook('search_results', 'if ( !isset($offset) ) $offset =& $start; gal_searcher($q, $offset);');
13
f6ca7cead82c Updated with support for Enano's new search API
Dan
parents: 4
diff changeset
    20
$plugins->attachHook('search_global_inner', 'snapr_search_new_api($query, $query_phrase, $scores, $page_data, $case_sensitive, $word_list);');
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    21
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    22
$plugins->attachHook('compile_template', '
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    23
	// CSS for gallery browser
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    24
	$template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/browser.css" type="text/css" />\');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    25
	$template->add_header(\'<link rel="stylesheet" href="' . scriptPath . '/plugins/gallery/dropdown.css" type="text/css" />\');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    26
	');
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    27
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    28
function gal_searcher($q, $offset)
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    29
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    30
	global $db, $session, $paths, $template, $plugins; // Common objects
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    31
	if ( defined('SNAPR_SEARCH_USING_NEW_API') || version_compare(enano_version(true), '1.0.2', '>=') )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    32
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    33
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    34
	$fulltext_col = 'MATCH(img_title, img_desc) AGAINST (\'' . $db->escape($q) . '\' IN BOOLEAN MODE)';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    35
	$sql = "SELECT img_id, img_title, img_desc, is_folder, $fulltext_col AS score, CHAR_LENGTH(img_desc) AS length FROM ".table_prefix."gallery
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    36
							WHERE $fulltext_col > 0
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    37
								AND ( ( is_folder=1 AND folder_parent IS NULL ) OR is_folder!=1 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    38
							ORDER BY is_folder DESC, score DESC, img_title ASC;";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    39
	if ( !$db->sql_unbuffered_query($sql) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    40
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    41
		echo $db->get_error();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    42
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    43
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    44
	echo "<h3>Image results</h3>";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    45
	if ( $row = $db->fetchrow() )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    46
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    47
		echo '<ul class="snapr-gallery">';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    48
		$renderer = new SnaprFormatter();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    49
		$fullpage = $paths->fullpage;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    50
		$paths->fullpage = $paths->nslist['Special'] . 'Gallery';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    51
		do
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    52
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    53
			echo $renderer->render(false, $row, false);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    54
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    55
		while ( $row = $db->fetchrow() );
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    56
		$paths->fullpage = $fullpage;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    57
		echo '</ul><span class="menuclear"></span>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    58
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    59
	else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    60
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    61
		echo '<p>No image results.</p>';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    62
	}
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    63
}
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
    64
13
f6ca7cead82c Updated with support for Enano's new search API
Dan
parents: 4
diff changeset
    65
function snapr_search_new_api(&$query, &$query_phrase, &$scores, &$page_data, &$case_sensitive, &$word_list)
f6ca7cead82c Updated with support for Enano's new search API
Dan
parents: 4
diff changeset
    66
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    67
	global $db, $session, $paths, $template, $plugins; // Common objects
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    68
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    69
	if ( !defined('SNAPR_SEARCH_USING_NEW_API') )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    70
		define('SNAPR_SEARCH_USING_NEW_API', 1);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    71
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    72
	// Let's do this all in one query
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    73
	$terms = array(
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    74
			'any' => array_merge($query['any'], $query_phrase['any']),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    75
			'req' => array_merge($query['req'], $query_phrase['req']),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    76
			'not' => $query['not']
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    77
		);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    78
	$where = array('any' => array(), 'req' => array(), 'not' => array());
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    79
	$where_any =& $where['any'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    80
	$where_req =& $where['req'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    81
	$where_not =& $where['not'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    82
	$title_col = ( $case_sensitive ) ? 'img_title' : 'lcase(img_title)';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    83
	$desc_col = ( $case_sensitive ) ? 'img_desc' : 'lcase(img_desc)';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    84
	foreach ( $terms['any'] as $term )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    85
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    86
		$term = escape_string_like($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    87
		if ( !$case_sensitive )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    88
			$term = strtolower($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    89
		$where_any[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    90
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    91
	foreach ( $terms['req'] as $term )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    92
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    93
		$term = escape_string_like($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    94
		if ( !$case_sensitive )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    95
			$term = strtolower($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    96
		$where_req[] = "( $title_col LIKE '%{$term}%' OR $desc_col LIKE '%{$term}%' )";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    97
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    98
	foreach ( $terms['not'] as $term )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
    99
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   100
		$term = escape_string_like($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   101
		if ( !$case_sensitive )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   102
			$term = strtolower($term);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   103
		$where_not[] = "$title_col NOT LIKE '%{$term}%' AND $desc_col NOT LIKE '%{$term}%'";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   104
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   105
	if ( empty($where_any) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   106
		unset($where_any, $where['any']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   107
	if ( empty($where_req) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   108
		unset($where_req, $where['req']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   109
	if ( empty($where_not) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   110
		unset($where_not, $where['not']);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   111
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   112
	$where_any = '(' . implode(' OR ', $where_any) . '' . ( isset($where['req']) || isset($where['not']) ? ' OR 1 = 1' : '' ) . ')';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   113
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   114
	if ( isset($where_req) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   115
		$where_req = implode(' AND ', $where_req);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   116
	if ( isset($where_not) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   117
	$where_not = implode( 'AND ', $where_not);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   118
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   119
	$where = implode(' AND ', $where);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   120
	$sql = "SELECT img_id, img_title, img_desc FROM " . table_prefix . "gallery WHERE ( $where ) AND is_folder = 0;";
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   121
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   122
	if ( !($q = $db->sql_unbuffered_query($sql)) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   123
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   124
		$db->_die('Error is in auto-generated SQL query in the Snapr plugin search module');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   125
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   126
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   127
	if ( $row = $db->fetchrow() )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   128
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   129
		do
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   130
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   131
			$idstring = 'ns=Gallery;pid=' . $row['img_id'];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   132
			foreach ( $word_list as $term )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   133
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   134
				if ( $case_sensitive )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   135
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   136
					if ( strstr($row['img_title'], $term) || strstr($row['img_desc'], $term) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   137
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   138
						( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   139
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   140
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   141
				else
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   142
				{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   143
					if ( strstr(strtolower($row['img_title']), strtolower($term)) || strstr(strtolower($row['img_desc']), strtolower($term)) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   144
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   145
						( isset($scores[$idstring]) ) ? $scores[$idstring]++ : $scores[$idstring] = 1;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   146
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   147
				}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   148
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   149
			// Generate text...
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   150
			$text = highlight_and_clip_search_result(htmlspecialchars($row['img_desc']), $word_list);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   151
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   152
			$preview_and_text = '
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   153
				<table border="0" width="100%" cellspacing="0" cellpadding="0">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   154
					<tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   155
						<td valign="top">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   156
							' . $text . '
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   157
						</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   158
						<td valign="top" style="text-align: right; width: 80px; padding-left: 10px;">
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   159
							<a href="' . makeUrlNS('Gallery', $row['img_id']) . '"><img alt="[thumbnail]" src="' . makeUrlNS('Special', "GalleryFetcher/thumb/{$row['img_id']}") . '" /></a>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   160
						</td>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   161
					</tr>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   162
				</table>
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   163
			';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   164
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   165
			// Inject result
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   166
			
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   167
			if ( isset($scores[$idstring]) )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   168
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   169
				// echo('adding image "' . $row['img_title'] . '" to results<br />');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   170
				$page_data[$idstring] = array(
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   171
					'page_name' => highlight_search_result(htmlspecialchars($row['img_title']), $word_list),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   172
					'page_text' => $preview_and_text,
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   173
					'score' => $scores[$idstring],
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   174
					'page_note' => '[Gallery image]',
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   175
					'page_id' => strval($row['img_id']),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   176
					'namespace' => 'Gallery',
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   177
					'page_length' => strlen($row['img_desc']),
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   178
				);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   179
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   180
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   181
		while ( $row = $db->fetchrow() );
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   182
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 31
diff changeset
   183
	}
13
f6ca7cead82c Updated with support for Enano's new search API
Dan
parents: 4
diff changeset
   184
}
f6ca7cead82c Updated with support for Enano's new search API
Dan
parents: 4
diff changeset
   185
2
88c954d2846c Added search functionality (WiP); removed stray .marks file
Dan
parents:
diff changeset
   186
?>