aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php120
1 files changed, 79 insertions, 41 deletions
diff --git a/index.php b/index.php
index a9264cbb..6712f90e 100644
--- a/index.php
+++ b/index.php
@@ -603,7 +603,7 @@ class pageBuilder
603 if (!empty($_GET['searchtags'])) { 603 if (!empty($_GET['searchtags'])) {
604 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']); 604 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
605 } 605 }
606 elseif (!empty($_GET['searchterm'])) { 606 if (!empty($_GET['searchterm'])) {
607 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']); 607 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
608 } 608 }
609 $this->tpl->assign('searchcrits', $searchcrits); 609 $this->tpl->assign('searchcrits', $searchcrits);
@@ -689,11 +689,19 @@ function showRSS()
689 // Read links from database (and filter private links if user it not logged in). 689 // Read links from database (and filter private links if user it not logged in).
690 690
691 // Optionally filter the results: 691 // Optionally filter the results:
692 if (!empty($_GET['searchterm'])) { 692 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
693 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $_GET['searchterm']); 693 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
694 if (! empty($searchtags) && ! empty($searchterm)) {
695 $linksToDisplay = $LINKSDB->filter(
696 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
697 array($searchtags, $searchterm)
698 );
694 } 699 }
695 elseif (!empty($_GET['searchtags'])) { 700 elseif ($searchtags) {
696 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, trim($_GET['searchtags'])); 701 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags);
702 }
703 elseif ($searchterm) {
704 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm);
697 } 705 }
698 else { 706 else {
699 $linksToDisplay = $LINKSDB; 707 $linksToDisplay = $LINKSDB;
@@ -787,11 +795,19 @@ function showATOM()
787 ); 795 );
788 796
789 // Optionally filter the results: 797 // Optionally filter the results:
790 if (!empty($_GET['searchterm'])) { 798 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
791 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $_GET['searchterm']); 799 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
800 if (! empty($searchtags) && ! empty($searchterm)) {
801 $linksToDisplay = $LINKSDB->filter(
802 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
803 array($searchtags, $searchterm)
804 );
792 } 805 }
793 else if (!empty($_GET['searchtags'])) { 806 elseif ($searchtags) {
794 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, trim($_GET['searchtags'])); 807 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags);
808 }
809 elseif ($searchterm) {
810 $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm);
795 } 811 }
796 else { 812 else {
797 $linksToDisplay = $LINKSDB; 813 $linksToDisplay = $LINKSDB;
@@ -1145,11 +1161,19 @@ function renderPage()
1145 if ($targetPage == Router::$PAGE_PICWALL) 1161 if ($targetPage == Router::$PAGE_PICWALL)
1146 { 1162 {
1147 // Optionally filter the results: 1163 // Optionally filter the results:
1148 if (!empty($_GET['searchterm'])) { 1164 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
1149 $links = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $_GET['searchterm']); 1165 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
1166 if (! empty($searchtags) && ! empty($searchterm)) {
1167 $links = $LINKSDB->filter(
1168 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
1169 array($searchtags, $searchterm)
1170 );
1150 } 1171 }
1151 elseif (! empty($_GET['searchtags'])) { 1172 elseif ($searchtags) {
1152 $links = $LINKSDB->filter(LinkFilter::$FILTER_TAG, trim($_GET['searchtags'])); 1173 $links = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags);
1174 }
1175 elseif ($searchterm) {
1176 $links = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm);
1153 } 1177 }
1154 else { 1178 else {
1155 $links = $LINKSDB; 1179 $links = $LINKSDB;
@@ -1944,29 +1968,46 @@ function importFile()
1944// This function fills all the necessary fields in the $PAGE for the template 'linklist.html' 1968// This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
1945function buildLinkList($PAGE,$LINKSDB) 1969function buildLinkList($PAGE,$LINKSDB)
1946{ 1970{
1947 // ---- Filter link database according to parameters 1971 // Filter link database according to parameters.
1948 $search_type = ''; 1972 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
1949 $search_crits = ''; 1973 $searchterm = !empty($_GET['searchterm']) ? escape(trim($_GET['searchterm'])) : '';
1950 $privateonly = !empty($_SESSION['privateonly']) ? true : false; 1974 $privateonly = !empty($_SESSION['privateonly']) ? true : false;
1951 1975
1952 // Fulltext search 1976 // Search tags + fullsearch.
1953 if (isset($_GET['searchterm'])) { 1977 if (! empty($searchtags) && ! empty($searchterm)) {
1954 $search_crits = escape(trim($_GET['searchterm'])); 1978 $linksToDisplay = $LINKSDB->filter(
1955 $search_type = LinkFilter::$FILTER_TEXT; 1979 LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
1956 $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); 1980 array($searchtags, $searchterm),
1981 false,
1982 $privateonly
1983 );
1957 } 1984 }
1958 // Search by tag 1985 // Search by tags.
1959 elseif (isset($_GET['searchtags'])) { 1986 elseif (! empty($searchtags)) {
1960 $search_crits = explode(' ', escape(trim($_GET['searchtags']))); 1987 $linksToDisplay = $LINKSDB->filter(
1961 $search_type = LinkFilter::$FILTER_TAG; 1988 LinkFilter::$FILTER_TAG,
1962 $linksToDisplay = $LINKSDB->filter($search_type, $search_crits, false, $privateonly); 1989 $searchtags,
1990 false,
1991 $privateonly
1992 );
1993 }
1994 // Fulltext search.
1995 elseif (! empty($searchterm)) {
1996 $linksToDisplay = $LINKSDB->filter(
1997 LinkFilter::$FILTER_TEXT,
1998 $searchterm,
1999 false,
2000 $privateonly
2001 );
1963 } 2002 }
1964 // Detect smallHashes in URL. 2003 // Detect smallHashes in URL.
1965 elseif (isset($_SERVER['QUERY_STRING']) 2004 elseif (! empty($_SERVER['QUERY_STRING'])
1966 && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])) { 2005 && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])
1967 $search_type = LinkFilter::$FILTER_HASH; 2006 ) {
1968 $search_crits = substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6); 2007 $linksToDisplay = $LINKSDB->filter(
1969 $linksToDisplay = $LINKSDB->filter($search_type, $search_crits); 2008 LinkFilter::$FILTER_HASH,
2009 substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6)
2010 );
1970 2011
1971 if (count($linksToDisplay) == 0) { 2012 if (count($linksToDisplay) == 0) {
1972 $PAGE->render404('The link you are trying to reach does not exist or has been deleted.'); 2013 $PAGE->render404('The link you are trying to reach does not exist or has been deleted.');
@@ -2022,21 +2063,18 @@ function buildLinkList($PAGE,$LINKSDB)
2022 } 2063 }
2023 2064
2024 // Compute paging navigation 2065 // Compute paging navigation
2025 $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm']; 2066 $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags);
2026 $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags']; 2067 $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm);
2027 $previous_page_url = ''; 2068 $previous_page_url = '';
2028 if ($i != count($keys)) { 2069 if ($i != count($keys)) {
2029 $previous_page_url = '?page=' . ($page+1) . $searchterm . $searchtags; 2070 $previous_page_url = '?page=' . ($page+1) . $searchtermUrl . $searchtagsUrl;
2030 } 2071 }
2031 $next_page_url=''; 2072 $next_page_url='';
2032 if ($page>1) { 2073 if ($page>1) {
2033 $next_page_url = '?page=' . ($page-1) . $searchterm . $searchtags; 2074 $next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl;
2034 } 2075 }
2035 2076
2036 $token = ''; 2077 $token = isLoggedIn() ? getToken() : '';
2037 if (isLoggedIn()) {
2038 $token = getToken();
2039 }
2040 2078
2041 // Fill all template fields. 2079 // Fill all template fields.
2042 $data = array( 2080 $data = array(
@@ -2046,8 +2084,8 @@ function buildLinkList($PAGE,$LINKSDB)
2046 'page_current' => $page, 2084 'page_current' => $page,
2047 'page_max' => $pagecount, 2085 'page_max' => $pagecount,
2048 'result_count' => count($linksToDisplay), 2086 'result_count' => count($linksToDisplay),
2049 'search_type' => $search_type, 2087 'search_term' => $searchterm,
2050 'search_crits' => $search_crits, 2088 'search_tags' => $searchtags,
2051 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], // Optional redirector URL. 2089 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], // Optional redirector URL.
2052 'token' => $token, 2090 'token' => $token,
2053 'links' => $linkDisp, 2091 'links' => $linkDisp,