|
Member
Offline
Posts: 4
|
Re: SEARCH
Posted on: 17th April, 2010, 11:34:30 AM
Yes, fails with empty search strings, but I made some changes/fixes. Hope it works out for you.
VISUAL DIFFS: http://i41.tinypic.com/28velj7.jpg
@BASE/search/custom_page.php
Code:
<?php
/* eoCMS © 2007 - 2010, a Content Management System
by James Mortemore, Ryan Matthews
http://www.eocms.com
is licenced under a Creative Commons
Attribution-Share Alike 2.0 UK: England & Wales Licence.
Permissions beyond the scope of this licence
may be available at http://creativecommons.org/licenses/by-sa/2.0/uk/.
Additional licence terms at http://eocms.com/licence.html
*/
$buttons[] = '<input type="radio" name="where" id="custom pages" value="custom_page"' . (isset($_GET['where']) && $_GET['where'] == 'custom_page' ? ' checked="checked"' : '') . ' /><label for="custom pages">Custom Pages</label>';
if (isset($search2) && trim($search2 !== '')) {
if (isset($_GET['where']) && $_GET['where'] == 'custom_page') {
$sql = sql_query("SELECT * FROM pages " . (isset($_GET['what']) && $_GET['what'] == 'message' ? "WHERE content LIKE " . $search2 . "" : (isset($_GET['what']) && $_GET['what'] == 'title' ? "WHERE pagename LIKE " . $search2 . "" : "WHERE pagename LIKE " . $search2 . " OR content LIKE " . $search2 . "")) . " LIMIT $offset, $rowsPerPage");
$sqlnum2 = "SELECT COUNT(id) AS numrows FROM pages " . (isset($_GET['what']) && $_GET['what'] == 'message' ? "WHERE content LIKE " . $search2 . "" : (isset($_GET['what']) && $_GET['what'] == 'title' ? "WHERE pagename LIKE " . $search2 . "" : "WHERE pagename LIKE " . $search2 . " OR content LIKE " . $search2 . ""));
while ($fetch = call('sql_fetch_array', $sql)) {
$results .= '<div class="bbcode_quote"><div class="bbcode_quote_head"><a href="'.$settings['site_url'].'/index.php?act=page&id=' . $fetch['id'] . '" target="_blank">' . ($_GET['what'] == 'both' || $_GET['what'] == 'title' ? call('highlight_words', $_GET['search'], $fetch['pagename']) : $fetch['pagename']) . '</a><br /></div><div class="bbcode_quote_body">' . ($_GET['what'] == 'both' || $_GET['what'] == 'message' ? call('highlight_words', $_GET['search'], substr(call('strip_html_bbcode', $fetch['content']), 0, 50)) . "..." : substr(call('strip_html_bbcode', $fetch['content']), 0, 50)) . "..." . '</div></div>';
}
}
$pagination = call('pagination', $pageNum, $rowsPerPage, $sqlnum2, '?act=search&search='.$_GET['search'].'&method='.$_GET['method'].'&order='.$_GET['order'].'&what='.$_GET['what'].'&where='.$_GET['where'].'&page=', 3);
}
?>
Note: Conditional added before search process.
VISUAL DIFFS: http://i44.tinypic.com/33aujyq.jpg
@BASE/search/forum.php
Code:
<?php
/* eoCMS © 2007 - 2010, a Content Management System
by James Mortemore, Ryan Matthews
http://www.eocms.com
is licenced under a Creative Commons
Attribution-Share Alike 2.0 UK: England & Wales Licence.
Permissions beyond the scope of this licence
may be available at http://creativecommons.org/licenses/by-sa/2.0/uk/.
Additional licence terms at http://eocms.com/licence.html
*/
$boards = sql_query("SELECT * FROM forum_boards", 'cache');
$option = '';
foreach ($boards as $fetch) {
if (call('visiblecheck', $user['membergroup_id'], $fetch['visible']))
$option .= '<option value="' . $fetch['id'] . '"' . (isset($_GET['forum']) && $_GET['forum'] == $fetch['id'] ? ' selected="selected"' : '') . '>' . $fetch['board_name'] . '</option>';
}
$buttons[] = '<input type="radio" name="where" id="forum" value="forum"' . ((isset($_GET['where']) && $_GET['where'] == 'forum') || !isset($_GET['where']) ? ' checked="checked"' : '') . ' /><label for="forum">Forums:</label> <select name="forum"><option value="all"' . (isset($_GET['forum']) && $_GET['forum'] == 'all' ? ' selected="selected"' : '') . '>All Boards</option>' . $option . '</select>';
if (isset($search2) && trim($search2 !== '')) {
if (isset($_GET['where']) && $_GET['where'] == 'forum') {
$sql = sql_query("SELECT p.id AS id, p.topic_id AS topic_id, p.subject AS subject, p.message AS message, b.visible AS visible, p.author_id AS author_id, p.post_time AS post_time, b.id AS board_id, b.board_name AS board_name, t.replies AS replies FROM forum_posts p LEFT JOIN forum_boards b ON b.id = p.board_id LEFT JOIN forum_topics t ON p.topic_id = t.topic_id " . (isset($_GET['what']) && $_GET['what'] == 'message' ? "WHERE p.message LIKE " . $search2 . "" : (isset($_GET['what']) && $_GET['what'] == 'title' ? "WHERE p.subject LIKE " . $search2 . "" : isset($_GET['what']) && $_GET['what'] == 'both' ? "WHERE p.message LIKE " . $search2 . " OR p.subject LIKE " . $search2 . "" : isset($_GET['what']) && $_GET['what'] == 'message' ? "WHERE p.message LIKE " . $search2 . "" : '')) . " " . ($_GET['forum'] != 'all' && is_numeric($_GET['forum']) ? "AND b.id = " . $_GET['forum'] . "" : '') . " " . ($_GET['order'] == 'old' ? "ORDER BY p.post_time ASC" : "ORDER BY p.post_time DESC") . " LIMIT $offset, $rowsPerPage");
$sqlnum2 = "SELECT COUNT(p.id) AS numrows FROM forum_posts p LEFT JOIN forum_boards b ON b.id = p.board_id LEFT JOIN forum_topics t ON p.topic_id = t.topic_id " . (isset($_GET['what']) && $_GET['what'] == 'message' ? "WHERE p.message LIKE " . $search2 . "" : (isset($_GET['what']) && $_GET['what'] == 'title' ? "WHERE p.subject LIKE " . $search2 . "" : "WHERE p.message LIKE " . $search2 . " OR p.message LIKE " . $search2 . "")) . " " . ($_GET['forum'] != 'all' && is_numeric($_GET['forum']) ? "AND b.id = " . $_GET['forum'] . "" : '');
while ($fetch = call('sql_fetch_array', $sql)) {
if (call('visiblecheck', $user['membergroup_id'], $fetch['visible'])) {
$results .= '<div class="bbcode_quote"><div class="bbcode_quote_head"><a href="'.$settings['site_url'].'/index.php?act=viewtopic&id=' . $fetch['topic_id'] . '" target="_blank">' . ($_GET['what'] == 'both' || $_GET['what'] == 'title' ? call('highlight_words', $_GET['search'], $fetch['subject']) : $fetch['subject']) . '</a> by ' . call('userprofilelink', $fetch['author_id']) . ' on ' . call('dateformat', $fetch['post_time']) . '<br /><span class="small-text">in <a href="'.$settings['site_url'].'/index.php?act=viewboard&id=' . $fetch['board_id'] . '" target="_blank">' . $fetch['board_name'] . '</a></span><br /></div><div class="bbcode_quote_body">' . ($_GET['what'] == 'both' || $_GET['what'] == 'message' ? call('highlight_words', $_GET['search'], call('strip_html_bbcode', substr($fetch['message'], 0, 50))) . "..." : call('strip_html_bbcode', substr($fetch['message'], 0, 50))) . '</div></div>';
}
}
}
$pagination = call('pagination', $pageNum, $rowsPerPage, (isset($sqlnum2) ? $sqlnum2 : ''), '?act=search&search=' . $_GET['search'] . '&method=' . $_GET['method'] . '&order=' . $_GET['order'] . '&what=' . $_GET['what'] . '&where=' . $_GET['where'] . (isset($_GET['forum']) ? '&forum=' . $_GET['forum'] . '' : '') . '&page=', 3);
}
?>
Note: Conditional added before search process.
Note: sqlnum2 sanitize check under pagination call.
VISUAL DIFFS: http://i40.tinypic.com/qrgf83.jpg
@BASE/Layouts/Search.php
Code:
<?php
/* eoCMS © 2007 - 2010, a Content Management System
by James Mortemore, Ryan Matthews
http://www.eocms.com
is licenced under a Creative Commons
Attribution-Share Alike 2.0 UK: England & Wales Licence.
Permissions beyond the scope of this licence
may be available at http://creativecommons.org/licenses/by-sa/2.0/uk/.
Additional licence terms at http://eocms.com/licence.html
Language added - 04/06/09 - Paul Wratt
*/
if(!(defined("IN_ECMS"))) die("Hacking Attempt...");
$title = $SEARCH_LANG["title"];
$pageNum = (isset($_GET['page']) ? $_GET['page'] : 1);
// how many rows to show per page
$rowsPerPage = 20;
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$body = theme('title', $SEARCH_LANG["theme_title"]) . theme('start_content');
$body .= '<form method="get" action=""><table>
<tr><td>'.$SEARCH_LANG["search_for"].' <input type="text" name="search" size="40" onFocus="this.value=''" ' . (isset($_GET['search']) ? 'value="' . $_GET['search'] . '"' : '') . '/></td><td align="right"><select name="method"><option value="all"' . (isset($_GET['method']) && $_GET['method'] == 'all' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_match_all"].'</option><option value="any"' . (isset($_GET['method']) && $_GET['method'] == 'any' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_match_any"].'</option></select></td></tr><tr><td>';
if (!empty($_GET['search']) & isset($_GET['where'])) {
$search = explode(" ", $_GET['search']);
$search2 = '';
for ($i = 0; $i < count($search); $i++) {
$search2 .= (isset($_GET['method']) && $_GET['method'] == 'all' && $i != 0 ? 'AND ' : (isset($_GET['method']) && $_GET['method'] == 'any' && $i != 0 ? 'OR ' : '')) . '"%' . $search[$i] . '%" ';
}
}
//set the buttons as an array
$buttons = array();
//lets set the resutls string
$results = '';
//open the search directory and include all the search files
$dir = opendir('search');
while (false !== ($read = readdir($dir))) {
if ($read != "." && $read != ".." && $read != ".svn") {
include('search/' . $read);
}
}
closedir($dir);
$body .= '<table>';
//right lets start by displaying all the buttons
foreach ($buttons as $button) {
$body .= '<tr><td>' . $button . '</td></tr>';
}
//output all the search optuons
$body .= '</table></td><td><table><tr><td align="right">'.$SEARCH_LANG["order_by"].': <select name="order"><option value="old"' . (isset($_GET['order']) && $_GET['order'] == 'old' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_old"].'</option><option value="new"' . (isset($_GET['order']) && $_GET['order'] == 'new' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_new"].'</option></select></td></tr>';
$body .= '<tr><td align="right">'.$SEARCH_LANG["search"].' <select name="what"><option value="both"' . (isset($_GET['what']) && $_GET['what'] == 'both' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_both"].'</option><option value="message"' . (isset($_GET['what']) && $_GET['what'] == 'message' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_message"].'</option><option value="title"' . (isset($_GET['what']) && $_GET['what'] == 'title' ? ' selected="selected"' : '') . '>'.$SEARCH_LANG["o_title"].'</option></select></td></tr></table></td></tr>
<tr><td align="center" colspan="2"><input type="hidden" name="act" value="search" /><input type="submit" value="'.$SEARCH_LANG["btn_search"].'" /></td></tr></table></form>';
$body .= theme('end_content');
//check if there is a search
if (!empty($_GET['search']) & isset($_GET['where'])) {
//theres a search so lets show the table
$body .= theme('title', $SEARCH_LANG["theme_title_results"]) . theme('start_content');
$sqlnum = call('sql_num_rows', $sql);
if ($sqlnum == 0) {
//no results, hate it when that happens
$body .= $SEARCH_LANG["body_content"].'<br />';
} else {
//there are results lets show them
$body .= $sqlnum . ' '.$SEARCH_LANG["results_found"].': ' . $_GET['search'] . '<br />'.$results;
}
//check to make sure there are results
if ($sqlnum != 0) {
//display the pages
$body .= (isset($_GET['search']) ? $pagination : '');
}
}
$body .= theme('end_content');
?>
Note: onFocus empty added.
It works for me!
What about you?
Last Edit: 17th April, 2010, 02:13:02 PM by Ion
|