)
-// This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
+/**
+ * Template for the list of links (
)
+ * This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
+ *
+ * @param pageBuilder $PAGE pageBuilder instance.
+ * @param LinkDB $LINKSDB LinkDB instance.
+ */
function buildLinkList($PAGE,$LINKSDB)
{
- // ---- Filter link database according to parameters
- $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.');
+ // Used in templates
+ $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
+ $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
+
+ // Smallhash filter
+ if (! empty($_SERVER['QUERY_STRING'])
+ && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) {
+ try {
+ $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']);
+ } catch (LinkNotFoundException $e) {
+ $PAGE->render404($e->getMessage());
exit;
}
- }
- // Otherwise, display without filtering.
- else {
- $linksToDisplay = $LINKSDB->filter('', '', false, $privateonly);
+ } else {
+ // Filter links according search parameters.
+ $privateonly = !empty($_SESSION['privateonly']);
+ $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly);
}
// ---- Handle paging.
@@ -1982,7 +1842,8 @@ function buildLinkList($PAGE,$LINKSDB)
$link['description'] = format_description($link['description'], $GLOBALS['redirector']);
$classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight';
$link['class'] = $link['private'] == 0 ? $classLi : 'private';
- $link['timestamp'] = linkdate2timestamp($link['linkdate']);
+ $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
+ $link['timestamp'] = $date->getTimestamp();
$taglist = explode(' ', $link['tags']);
uasort($taglist, 'strcasecmp');
$link['taglist'] = $taglist;
@@ -1998,21 +1859,18 @@ function buildLinkList($PAGE,$LINKSDB)
}
// Compute paging navigation
- $searchterm = empty($_GET['searchterm']) ? '' : '&searchterm=' . $_GET['searchterm'];
- $searchtags = empty($_GET['searchtags']) ? '' : '&searchtags=' . $_GET['searchtags'];
+ $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags);
+ $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm);
$previous_page_url = '';
if ($i != count($keys)) {
- $previous_page_url = '?page=' . ($page+1) . $searchterm . $searchtags;
+ $previous_page_url = '?page=' . ($page+1) . $searchtermUrl . $searchtagsUrl;
}
$next_page_url='';
if ($page>1) {
- $next_page_url = '?page=' . ($page-1) . $searchterm . $searchtags;
+ $next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl;
}
- $token = '';
- if (isLoggedIn()) {
- $token = getToken();
- }
+ $token = isLoggedIn() ? getToken() : '';
// Fill all template fields.
$data = array(
@@ -2022,8 +1880,8 @@ function buildLinkList($PAGE,$LINKSDB)
'page_current' => $page,
'page_max' => $pagecount,
'result_count' => count($linksToDisplay),
- 'search_type' => $search_type,
- 'search_crits' => $search_crits,
+ 'search_term' => $searchterm,
+ 'search_tags' => $searchtags,
'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], // Optional redirector URL.
'token' => $token,
'links' => $linkDisp,
@@ -2518,18 +2376,7 @@ function resizeImage($filepath)
return true;
}
-try {
- mergeDeprecatedConfig($GLOBALS, isLoggedIn());
-} catch(Exception $e) {
- error_log(
- 'ERROR while merging deprecated options.php file.' . PHP_EOL .
- $e->getMessage()
- );
-}
-
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
-if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
-if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=dailyrss')) { showDailyRSS(); exit; }
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
renderPage();