function highlight_search($ori_string, $hl_words) { if (is_array($hl_words)) { foreach ($hl_words as $hl) { $ori_string = highlight_search($ori_string, $hl); } } $h = strtoupper($ori_string); $n = strtoupper($hl_words); $pos = strpos($h, $n); if ($pos !== false) { $var = substr($ori_string, 0, $pos) . "<span class=\"highlight\">" . substr($ori_string, $pos, strlen($hl_words)) . "</span>"; $var .= substr($ori_string, $pos + strlen($hl_words)); $ori_string = $var; } return $ori_string; }
$device = device_by_id_cache($port['device_id']); echo '<li class="divider" style="margin: 0px;"></li>'; echo '<li>'; echo '<a href="' . generate_port_url($port) . '">'; $descr = $device['hostname'] . ' | ' . rewrite_ifname($port['label']); $name = $result['ipv4_address'] . '/' . $result['ipv4_prefixlen']; if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } /// FIXME: once we have alerting, colour this to the sensor's status $tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions? echo '<dl style="border-left: 10px solid ' . $tab_colour . '; " class="dl-horizontal dl-search"> <dt style="padding-left: 10px; text-align: center;"> <i class="oicon-magnifier-zoom-actual"></i></dt> <dd><strong>' . highlight_search(htmlentities($name)) . '<br /> <small>' . htmlentities($descr) . '</small></strong></dd> </dl>'; } echo "</a></li>"; } if (!$found) { echo '<li class="nav-header">No search results.</li>'; } } // There is a queryString. } else { echo '<li class="nav-header">There should be no direct access to this script! Please reload the page.</li>'; } // DOCME needs phpdoc block // TESTME needs unit testing
$query_limit--; foreach ($search_results as $results) { $display_count = count($results['results']); // If there are more results than query_limit (can happen, as we ++'d above), cut array to desired size and add + to counter if (count($results['results']) > $query_limit) { $results['results'] = array_slice($results['results'], 0, $query_limit); $display_count = count($results['results']) . '+'; } echo '<li class="nav-header">' . $results['descr'] . ': ' . $display_count . '</li>' . PHP_EOL; foreach ($results['results'] as $result) { echo '<li class="divider" style="margin: 0px;"></li>' . PHP_EOL; echo '<li style="margin: 0px;">' . PHP_EOL . ' <a href="' . $result['url'] . '">' . PHP_EOL; echo ' <dl style="border-left: 10px solid ' . $result['colour'] . '; " class="dl-horizontal dl-search">' . PHP_EOL; echo ' <dt style="width: 64px; text-align: center; line-height: 41.5px;">' . $result['icon'] . '</dt>' . PHP_EOL; echo ' <dd>' . PHP_EOL; echo ' <strong>' . highlight_search(escape_html($result['name'])) . PHP_EOL; echo ' <small>' . implode($result['data'], '<br />') . '</small>' . PHP_EOL; echo ' </strong>' . PHP_EOL; echo ' </dd>' . PHP_EOL; echo '</dl>' . PHP_EOL; echo ' </a>' . PHP_EOL; echo '</li>' . PHP_EOL; } } if (!count($search_results)) { echo '<li class="nav-header">No search results.</li>'; } } } else { // There is no queryString, we shouldn't get here. echo '<li class="nav-header">There should be no direct access to this script! Please reload the page.</li>';
* Observium * * This file is part of Observium. * * @package observium * @subpackage search * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ /// SEARCH PORTS $results = dbFetchRows("SELECT * FROM `ports`\n LEFT JOIN `devices` USING (`device_id`)\n WHERE (`ifAlias` LIKE ? OR `ifDescr` LIKE ?) {$query_permitted_port}\n ORDER BY `ifDescr` LIMIT {$query_limit}", array($query_param, $query_param)); if (count($results)) { foreach ($results as $result) { humanize_port($result); $name = rewrite_ifname($result['ifDescr']); if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } $description = $result['ifAlias']; if (strlen($description) > 80) { $description = substr($description, 0, 80) . "..."; } $type = rewrite_iftype($result['ifType']); if ($description) { $type .= ' | '; } $port_search_results[] = array('url' => generate_port_url($result), 'name' => $name, 'colour' => $result['table_tab_colour'], 'icon' => '<img src="images/icons/' . $result['icon'] . '.png" />', 'data' => array(escape_html($result['hostname']), $type . highlight_search(escape_html($description)))); } $search_results['ports'] = array('descr' => 'Ports found', 'results' => $port_search_results); } // EOF
$posts[$pn]["ratio"] = intval($arr['downloaded']) > 0 ? number_format($arr['uploaded'] / $arr['downloaded'], 2) : "---"; $sql = get_result("SELECT COUNT(*) as posts FROM {$TABLE_PREFIX}posts p INNER JOIN {$TABLE_PREFIX}users u ON p.userid = u.id WHERE u.id = " . $arr["userid"], true); $posts[$pn]["posts"] = intval(0 + $sql[0]["posts"]); $posts[$pn]["id"] = $arr["id"]; $posts[$pn]["post_number"] = $post_number; $posts[$pn]["actions"] = ""; if ($user_can_write) { $posts[$pn]["actions"] .= "<a href=\"index.php?page=forum&action=quotepost&topicid={$topicid}&postid=" . $arr["id"] . "\">" . image_or_link($STYLEPATH . "/images/f_quote.png", "", "[" . $language["QUOTE"] . "]") . "</a>"; } if ($CURUSER["uid"] == $posterid && !$locked && $posterid > 1 || $CURUSER["edit_forum"] == "yes") { $posts[$pn]["actions"] .= " <a href=\"index.php?page=forum&action=editpost&postid=" . $arr["id"] . "\">" . image_or_link($STYLEPATH . "/images/f_edit.png", "", "[" . $language["EDIT"] . "]") . "</a>"; } if ($CURUSER["delete_forum"] == "yes") { $posts[$pn]["actions"] .= " <a onclick=\"return confirm('" . AddSlashes($language["DELETE_CONFIRM"]) . "')\" href=\"index.php?page=forum&action=deletepost&postid=" . $arr["id"] . "&forumid={$forumid}\">" . image_or_link($STYLEPATH . "/images/f_delete.png", "", "[" . $language["DELETE"] . "]") . "</a>"; } $posts[$pn]["body"] = $hl == "" ? format_comment($arr["body"]) : highlight_search(format_comment($arr["body"]), explode(" ", $hl)); $posts[$pn]["msglink"] = "index.php?page=forum&action=viewtopic&topicid={$topicid}&msg=" . $arr["id"] . "#" . $arr["id"]; $posts[$pn]["new"] = $new_id == $arr["id"] || $new_id == "last" && $pn == $pc ? "<a name=\"new\" />" : ""; if (is_valid_id($arr['editedby'])) { $posts[$pn]["body"] .= "<p><font size=\"1\">" . $language["LAST_EDITED_BY"] . " <a href=\"index.php?page=userdetails&id=" . $arr["editedby"] . "\"><b>" . $arr["editor"] . "</b></a> at " . get_date_time($arr['editedat']) . "</font></p>\n"; } $posts[$pn]["pm"] = $CURUSER["uid"] > 1 ? "<a href=\"index.php?page=usercp&do=pm&action=edit&uid={$userid}&what=new&to=" . urlencode($arr["username"]) . "\">" . image_or_link("{$STYLEPATH}/images/pm.png", "", $language["PM"]) . "</a>" : ""; $posts[$pn]["top"] = image_or_link("{$STYLEPATH}/images/top.gif", "", $language["TOP"]); ++$pn; ++$post_number; } unset($arr); unset($res); $forumtpl->set("topic_title", $subject); $forumtpl->set("forum_pager", $pagertop); $forumtpl->set("posts", $posts);
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage search * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ /// SEARCH STATUS $results = dbFetchRows("SELECT * FROM `status`\n LEFT JOIN `devices` USING (`device_id`)\n WHERE `status_descr` LIKE ? {$query_permitted_device}\n ORDER BY `status_descr` LIMIT {$query_limit}", array($query_param)); if (count($results)) { foreach ($results as $result) { $name = $result['status_descr']; if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } /// FIXME: once we have alerting, colour this to the sensor's status $tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions? $status_search_results[] = array('url' => 'graphs/type=status_graph/id=' . $result['status_id'] . '/', 'name' => $name, 'colour' => $tab_colour, 'icon' => '<i class="oicon-traffic-light"></i>', 'data' => array(escape_html($result['hostname']), highlight_search(escape_html($result['location'])) . ' | ' . nicecase($result['status_class']) . ' sensor')); } $search_results['status'] = array('descr' => 'Status Indicators found', 'results' => $status_search_results); } // EOF
$arr = mysqli_fetch_row($res); $hits = intval(0 + $arr[0]); if ($hits == 0) { $forumtpl->set("NO_TOPICS", true, true); } else { $forumtpl->set("NO_TOPICS", false, true); list($pagertop, $pagerbottom, $limit) = forum_pager($perpage, $hits, "index.php?page=forum&action=search&keywords=" . htmlspecialchars($keywords) . "&"); $res = get_result("SELECT p.*, t.subject, f.id as forumid, f.name as forumname, u.username, p.added, MATCH (p.body) AGAINST ({$ekeywords} IN BOOLEAN MODE) as score FROM {$TABLE_PREFIX}posts p" . " LEFT JOIN {$TABLE_PREFIX}users u ON p.userid=u.id INNER JOIN {$TABLE_PREFIX}topics t ON p.topicid=t.id" . " INNER JOIN {$TABLE_PREFIX}forums f ON t.forumid=f.id" . " WHERE IFNULL(f.minclassread,999)<=" . $CURUSER["id_level"] . " AND MATCH (p.body) AGAINST ({$ekeywords} IN BOOLEAN MODE)" . " ORDER BY score, added DESC {$limit}", true, $btit_settings['cache_duration']); $search = array(); $i = 0; foreach ($res as $id => $sr) { if ($sr["forumname"] == "") { continue; } $search[$i]["match"] = $sr["score"]; $search[$i]["postid"] = $sr["id"]; $search[$i]["topic"] = "<a href=\"index.php?page=forum&action=viewtopic&topicid=" . $sr["topicid"] . "&hl=" . urlencode($keywords) . "&msg=" . $sr["id"] . "#" . $sr["id"] . "\">" . unesc(htmlspecialchars($sr["subject"])) . "</a>"; $search[$i]["forum"] = "<a href=\"index.php?page=forum&action=viewforum&forumid=" . $sr["forumid"] . "\">" . unesc(htmlspecialchars($sr["forumname"])) . "</a>"; $search[$i]["author"] = get_date_time($sr["added"]) . " " . $language["AT"] . " " . ($sr["username"] == "" ? "unknown[" . $sr["userid"] . "]" : "<a href=\"index.php?page=userdetails&id=" . $sr["userid"] . "\">" . unesc(htmlspecialchars($sr["username"])) . "</a>"); $search[$i]["body"] = highlight_search(cut_string($sr["body"], 200), explode(" ", $keywords)); $i++; } $forumtpl->set("topics", $search); } $forumtpl->set("forum_pager", $pagertop); $forumtpl->set("results", true, true); $forumtpl->set("search_hits", $i); } else { $forumtpl->set("results", false, true); } $forumtpl->set("search_keywords", $keywords);
echo '<li class="nav-header">Sensors found: ' . count($results) . '</li>'; foreach ($results as $result) { echo '<li class="divider" style="margin: 0px;"></li>'; echo '<li>'; echo '<a href="graphs/type=sensor_' . $result['sensor_class'] . '/id=' . $result['sensor_id'] . '/">'; $name = $result['sensor_descr']; if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } /// FIXME: once we have alerting, colour this to the sensor's status $tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions? echo '<dl style="border-left: 10px solid ' . $tab_colour . '; " class="dl-horizontal dl-search"> <dt style="padding-left: 10px; text-align: center;"> <i class="' . $config['sensor_types'][$result['sensor_class']]['icon'] . '"></i></dt> <dd><h5>' . highlight_search($name) . '</h5> <small>' . $result['hostname'] . '<br /> ' . $result['location'] . ' | ' . ucfirst($result['sensor_class']) . ' sensor</small></dd> </dl>'; } echo "</a></li>"; } } // There is a queryString. } else { echo 'There should be no direct access to this script!'; } function highlight_search($text) { global $queryString; return preg_replace("/" . preg_quote($queryString, "/") . "/i", "<em class=text-error>\$0</em>", $text);
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage search * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ /// SEARCH SENSORS $results = dbFetchRows("SELECT * FROM `sensors`\n LEFT JOIN `devices` USING (`device_id`)\n WHERE `sensor_descr` LIKE ? {$query_permitted_device}\n ORDER BY `sensor_descr` LIMIT {$query_limit}", array($query_param)); if (count($results)) { foreach ($results as $result) { $name = $result['sensor_descr']; if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } /// FIXME: once we have alerting, colour this to the sensor's status $tab_colour = '#194B7F'; // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions? $sensor_search_results[] = array('url' => 'graphs/type=sensor_' . $result['sensor_class'] . '/id=' . $result['sensor_id'] . '/', 'name' => $name, 'colour' => $tab_colour, 'icon' => '<i class="' . $config['sensor_types'][$result['sensor_class']]['icon'] . '"></i>', 'data' => array(escape_html($result['hostname']), highlight_search(escape_html($result['location'])) . ' | ' . nicecase($result['sensor_class']) . ' sensor')); } $search_results['sensors'] = array('descr' => 'Sensors found', 'results' => $sensor_search_results); } // EOF
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage search * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ /// SEARCH DEVICES $results = dbFetchRows("SELECT * FROM `devices`\n WHERE (`hostname` LIKE ? OR `location` LIKE ?) {$query_permitted_device}\n ORDER BY `hostname` LIMIT {$query_limit}", array($query_param, $query_param)); if (count($results)) { foreach ($results as $result) { humanize_device($result); $name = $result['hostname']; if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } $num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id'])); $device_search_results[] = array('url' => generate_device_url($result), 'name' => $name, 'colour' => $result['html_tab_colour'], 'icon' => get_device_icon($result), 'data' => array(escape_html($result['hardware'] . ' | ' . $config['os'][$result['os']]['text'] . ' ' . $result['version']), highlight_search(escape_html($result['location'])) . ' | ' . $num_ports . ' ports')); } $search_results['devices'] = array('descr' => 'Devices found', 'results' => $device_search_results); } // EOF