)
-// 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.
@@ -2022,32 +1736,28 @@ 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(
- 'linkcount' => count($LINKSDB),
'previous_page_url' => $previous_page_url,
'next_page_url' => $next_page_url,
'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,
@@ -2279,10 +1989,10 @@ function install()
if (!empty($_POST['setlogin']) && !empty($_POST['setpassword']))
{
$tz = 'UTC';
- if (!empty($_POST['continent']) && !empty($_POST['city'])) {
- if (isTimeZoneValid($_POST['continent'], $_POST['city'])) {
- $tz = $_POST['continent'].'/'.$_POST['city'];
- }
+ if (!empty($_POST['continent']) && !empty($_POST['city'])
+ && isTimeZoneValid($_POST['continent'], $_POST['city'])
+ ) {
+ $tz = $_POST['continent'].'/'.$_POST['city'];
}
$GLOBALS['timezone'] = $tz;
// Everything is ok, let's create config file.
@@ -2315,7 +2025,7 @@ function install()
$timezone_html = '
Timezone: | '.$timezone_form.' |
';
}
- $PAGE = new pageBuilder;
+ $PAGE = new PageBuilder();
$PAGE->assign('timezone_html',$timezone_html);
$PAGE->assign('timezone_js',$timezone_js);
$PAGE->renderPage('install');
@@ -2365,7 +2075,7 @@ function genThumbnail()
// Is this a link to an image, or to a flickr page ?
$imageurl='';
- if (endswith(parse_url($url,PHP_URL_PATH),'.jpg'))
+ if (endsWith(parse_url($url, PHP_URL_PATH), '.jpg'))
{ // This is a direct link to an image. e.g. http://farm1.staticflickr.com/5/5921913_ac83ed27bd_o.jpg
preg_match('!(http://farm\d+\.staticflickr\.com/\d+/\d+_\w+_)\w.jpg!',$url,$matches);
if (!empty($matches[1])) $imageurl=$matches[1].'m.jpg';
@@ -2542,10 +2252,8 @@ function resizeImage($filepath)
return true;
}
-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($_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=dailyrss')) { showDailyRSS(); exit; }
if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['config']['LINKS_PER_PAGE'];
renderPage();
?>