/** * Start the site search * * @param array $keys The search keys as string (string) * @param string $page Page to show (integer) * @param string $type The content type to show * * @return void */ function search($keys, $page, $type) { global $imSettings; $html = ""; $content = ""; $emptyResultsHtml = "<div style=\"margin-top: 15px; text-align: center; font-weight: bold;\">" . l10n('search_empty') . "</div>\n"; $html .= "<div class=\"imPageSearchField\"><form method=\"get\" action=\"imsearch.php\">"; $html .= "<input style=\"width: 200px; font: 8pt Tahoma; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); padding: 3px; border: 1px solid rgb(0, 0, 0); vertical-align: middle;\" class=\"search_field\" value=\"" . htmlspecialchars($keys, ENT_COMPAT, 'UTF-8') . "\" type=\"text\" name=\"search\" />"; $html .= "<input style=\"height: 21px; font: 8pt Tahoma; color: rgb(0, 0, 0); background-color: rgb(211, 211, 211); margin-left: 6px; padding: 3px 3px; border: 1px solid rgb(0, 0, 0); vertical-align: middle; cursor: pointer;\" type=\"submit\" value=\"" . l10n('search_search') . "\">"; $html .= "</form></div>\n"; // Exit if no search query was given if (trim($keys) == "" || $keys == null) { $html .= $emptyResultsHtml; return $html; } $search = trim(imstrtolower($keys)); $this->page = $page; $queries = explode(" ", $search); // Search everywhere to populate the results numbers shown in the sidebar menu // Pages $pages = $this->searchPages($queries); // Fallback on the selection if there are no pages if ($pages['count'] == 0 && $type == "pages") { $type = "blog"; } // Blog if (isset($imSettings['blog']) && is_array($imSettings['blog']['posts']) && count($imSettings['blog']['posts']) > 0) { $blog = $this->searchBlog($queries); } else { $blog = array("count" => 0); } // Fallback on the selection if there is no blog if ($blog['count'] == 0 && $type == "blog") { $type = "products"; } // Products if (is_array($imSettings['search']['products']) && count($imSettings['search']['products']) > 0) { $products = $this->searchProducts($queries); } else { $products = array("count" => 0); } // Fallback on the selection if there are no products if ($products['count'] == 0 && $type == "products") { $type = "images"; } // Images if (is_array($imSettings['search']['images']) && count($imSettings['search']['images']) > 0) { $images = $this->searchImages($queries); } else { $images = array("count" => 0); } // Fallback on the selection if there are no images if ($images['count'] == 0 && $type == "images") { $type = "videos"; } // Videos if (is_array($imSettings['search']['videos']) && count($imSettings['search']['videos']) > 0) { $videos = $this->searchVideos($queries); } else { $videos = array("count" => 0); } // Fallback on the selection if there are no videos if ($videos['count'] == 0 && $type == "videos") { $type = "pages"; } // Show only the requested content type switch ($type) { case "pages": if ($pages['count'] > 0) { $content .= "<div>" . $pages['content'] . "</div>\n"; } $results_count = $pages['count']; break; case "blog": if ($blog['count'] > 0) { $content .= "<div>" . $blog['content'] . "</div>\n"; } $results_count = $blog['count']; break; case "products": if ($products['count'] > 0) { $content .= "<div>" . $products['content'] . "</div>\n"; } $results_count = $products['count']; break; case "images": if ($images['count'] > 0) { $content .= "<div>" . $images['content'] . "</div>\n"; } $results_count = $images['count']; break; case "videos": if ($videos['count'] > 0) { $content .= "<div>" . $videos['content'] . "</div>\n"; } $results_count = $videos['count']; break; } // Exit if there are no results if (!$results_count) { $html .= $emptyResultsHtml; return $html; } $sidebar = "<ul>\n"; if ($pages['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"imsearch.php?search=" . urlencode($keys) . "&type=pages\">" . l10n('search_pages') . " (" . $pages['count'] . ")</a></span></li>\n"; } if ($blog['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"imsearch.php?search=" . urlencode($keys) . "&type=blog\">" . l10n('search_blog') . " (" . $blog['count'] . ")</a></span></li>\n"; } if ($products['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"imsearch.php?search=" . urlencode($keys) . "&type=products\">" . l10n('search_products') . " (" . $products['count'] . ")</a></span></li>\n"; } if ($images['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"imsearch.php?search=" . urlencode($keys) . "&type=images\">" . l10n('search_images') . " (" . $images['count'] . ")</a></span></li>\n"; } if ($videos['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"imsearch.php?search=" . urlencode($keys) . "&type=videos\">" . l10n('search_videos') . " (" . $videos['count'] . ")</a></span></li>\n"; } $sidebar .= "</ul>\n"; $html .= "<div id=\"imSearchResults\">\n"; if ($imSettings['search']['general']['menu_position'] == "left") { $html .= "\t<div id=\"imSearchSideBar\" style=\"float: left;\">" . $sidebar . "</div>\n"; $html .= "\t<div id=\"imSearchContent\" style=\"float: right;\">" . $content . "</div>\n"; } else { $html .= "\t<div id=\"imSearchContent\" style=\"float: left;\">" . $content . "</div>\n"; $html .= "\t<div id=\"imSearchSideBar\" style=\"float: right;\">" . $sidebar . "</div>\n"; } $html .= "</div>\n"; // Pagination if ($results_count > $this->results_per_page) { $html .= "<div style=\"text-align: center; clear: both;\">"; // Back if ($page > 0) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . ($page - 1) . "&type=" . $type . "\"><<</a> "; } // Central pages $start = max($page - 5, 0); $end = min($page + 10 - $start, ceil($results_count / $this->results_per_page)); for ($i = $start; $i < $end; $i++) { if ($i != $this->page) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . $i . "&type=" . $type . "\">" . ($i + 1) . "</a> "; } else { $html .= $i + 1 . " "; } } // Next if ($results_count > ($page + 1) * $this->results_per_page) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . ($page + 1) . "&type=" . $type . "\">>></a>"; } $html .= "</div>"; } return $html; }
/** * Start the site search * * @param array $keys The search keys as string (string) * @param string $page Page to show (integer) * * @return void */ function search($keys, $page = 0) { global $imSettings; $html = ""; $content = ""; //$html .= "<h2 id=\"imPgTitle\" class=\"searchPageTitle\">" . l10n('search_results') . "</h2>\n"; $html .= "<div class=\"searchPageContainer\">"; $html .= "<div class=\"imPageSearchField\"><form method=\"get\" action=\"imsearch.php\">"; $html .= "<input style=\"width: 200px; font: 8pt Tahoma; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); padding: 3px; border: 1px solid rgb(0, 0, 0); vertical-align: middle;\" class=\"search_field\" value=\"" . $keys . "\" type=\"text\" name=\"search\" />"; $html .= "<input style=\"height: 21px; font: 8pt Tahoma; color: rgb(0, 0, 0); background-color: rgb(211, 211, 211); margin-left: 6px; padding: 3px 3px; border: 1px solid rgb(0, 0, 0); vertical-align: middle; cursor: pointer;\" type=\"submit\" value=\"" . l10n('search_search') . "\">"; $html .= "</form></div>\n"; if ($keys == "" || $keys == null) { $html .= "<div style=\"margin-top: 15px; text-align: center; font-weight: bold;\">" . l10n('search_empty') . "</div>\n"; echo $html; return false; } $search = trim(imstrtolower($keys)); $this->page = $page; if ($search != "") { $queries = explode(" ", $search); $blog = array("count" => 0); $products = array("count" => 0); $images = array("count" => 0); $videos = array("count" => 0); // Pages $pages = $this->searchPages($queries); if ($pages['count'] > 0) { $content .= "<div id=\"imSearchWebPages\">" . $pages['content'] . "</div>\n"; } // Blog if (isset($imSettings['blog']) && is_array($imSettings['blog']['posts']) && count($imSettings['blog']['posts']) > 0) { $blog = $this->searchBlog($queries); if ($blog['count'] > 0) { $content .= "<div id=\"imSearchBlog\">" . $blog['content'] . "</div>\n"; } } // Products if (is_array($imSettings['search']['products']) && count($imSettings['search']['products']) > 0) { $products = $this->searchProducts($queries); if ($products['count'] > 0) { $content .= "<div id=\"imSearchProducts\">" . $products['content'] . "</div>\n"; } } // Images if (is_array($imSettings['search']['images']) && count($imSettings['search']['images']) > 0) { $images = $this->searchImages($queries); if ($images['count'] > 0) { $content .= "<div id=\"imSearchImages\">" . $images['content'] . "</div>\n"; } } // Videos if (is_array($imSettings['search']['videos']) && count($imSettings['search']['videos']) > 0) { $videos = $this->searchVideos($queries); if ($videos['count'] > 0) { $content .= "<div id=\"imSearchVideos\">" . $videos['content'] . "</div>\n"; } } $results_count = max($pages['count'], $blog['count'], $products['count'], $images['count'], $videos['count']); if ($pages['count'] == 0 && $blog['count'] == 0 && $products['count'] == 0 && $images['count'] == 0 && $videos['count'] == 0) { $html .= "<div style=\"text-align: center; font-weight: bold;\">" . l10n('search_empty') . "</div>\n"; } else { $sidebar = "<ul>\n"; if ($pages['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"#imSearchWebPages\" onclick=\"return x5engine.imSearch.Show('#imSearchWebPages')\">" . l10n('search_pages') . " (" . $pages['count'] . ")</a></span></li>\n"; } if ($blog['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"#imSearchBlog\" onclick=\"return x5engine.imSearch.Show('#imSearchBlog')\">" . l10n('search_blog') . " (" . $blog['count'] . ")</a></span></li>\n"; } if ($products['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"#imSearchProducts\" onclick=\"return x5engine.imSearch.Show('#imSearchProducts')\">" . l10n('search_products') . " (" . $products['count'] . ")</a></span></li>\n"; } if ($images['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"#imSearchImages\" onclick=\"return x5engine.imSearch.Show('#imSearchImages')\">" . l10n('search_images') . " (" . $images['count'] . ")</a></span></li>\n"; } if ($videos['count'] > 0) { $sidebar .= "\t<li><span class=\"imScMnTxt\"><a href=\"#imSearchVideos\" onclick=\"return x5engine.imSearch.Show('#imSearchVideos')\">" . l10n('search_videos') . " (" . $videos['count'] . ")</a></span></li>\n"; } $sidebar .= "</ul>\n"; $html .= "<div id=\"imSearchResults\">\n"; if ($imSettings['search']['general']['menu_position'] == "left") { $html .= "\t<div id=\"imSearchSideBar\" style=\"float: left;\">" . $sidebar . "</div>\n"; $html .= "\t<div id=\"imSearchContent\" style=\"float: right;\">" . $content . "</div>\n"; } else { $html .= "\t<div id=\"imSearchContent\" style=\"float: left;\">" . $content . "</div>\n"; $html .= "\t<div id=\"imSearchSideBar\" style=\"float: right;\">" . $sidebar . "</div>\n"; } $html .= "</div>\n"; } // Pagination if ($results_count > $this->results_per_page) { $html .= "<div style=\"text-align: center; clear: both;\">"; // Back if ($page > 0) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . ($page - 1) . "\"><<</a> "; } // Central pages $start = max($page - 5, 0); $end = min($page + 10 - $start, ceil($results_count / $this->results_per_page)); for ($i = $start; $i < $end; $i++) { if ($i != $this->page) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . $i . "\">" . ($i + 1) . "</a> "; } else { $html .= $i + 1 . " "; } } // Next if ($results_count > ($page + 1) * $this->results_per_page) { $html .= "<a href=\"imsearch.php?search=" . implode("+", $queries) . "&page=" . ($page + 1) . "\">>></a>"; } $html .= "</div>"; } } else { $html .= "<div style=\"margin-top: 15px; text-align: center; font-weight: bold;\">" . l10n('search_empty') . "</div>\n"; } $html .= "</div>"; echo $html; }