- $linksToDisplay=array();
- $search_type='';
- $search_crits='';
- if (isset($_GET['searchterm'])) // Fulltext search
- {
- $linksToDisplay = $LINKSDB->filterFulltext(trim($_GET['searchterm']));
- $search_crits=escape(trim($_GET['searchterm']));
- $search_type='fulltext';
- }
- elseif (isset($_GET['searchtags'])) // Search by tag
- {
- $linksToDisplay = $LINKSDB->filterTags(trim($_GET['searchtags']));
- $search_crits=explode(' ',escape(trim($_GET['searchtags'])));
- $search_type='tags';
- }
- elseif (isset($_SERVER['QUERY_STRING']) && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/',$_SERVER['QUERY_STRING'])) // Detect smallHashes in URL
- {
- $linksToDisplay = $LINKSDB->filterSmallHash(substr(trim($_SERVER["QUERY_STRING"], '/'),0,6));
- if (count($linksToDisplay)==0)
- {
- header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
- echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.';
- echo '<br>Would you mind <a href="?">clicking here</a>?';
+ $search_type = '';
+ $search_crits = '';
+ $privateonly = !empty($_SESSION['privateonly']) ? true : false;
+
+ // Fulltext search
+ if (isset($_GET['searchterm'])) {
+ $search_crits = escape(trim($_GET['searchterm']));
+ $search_type = LinkFilter::$FILTER_TEXT;
+ $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly);
+ }
+ // Search by tag
+ elseif (isset($_GET['searchtags'])) {
+ $search_crits = explode(' ', escape(trim($_GET['searchtags'])));
+ $search_type = LinkFilter::$FILTER_TAG;
+ $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly);
+ }
+ // Detect smallHashes in URL.
+ elseif (isset($_SERVER['QUERY_STRING'])
+ && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) {
+ $search_type = LinkFilter::$FILTER_HASH;
+ $search_crits = substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6);
+ $linksToDisplay = $LINKSDB->filter($search_type, $search_crits);
+
+ if (count($linksToDisplay) == 0) {
+ $PAGE->render404('The link you are trying to reach does not exist or has been deleted.');