if (isset($_POST['returnurl'])) {
// Prevent loops over login screen.
if (strpos($_POST['returnurl'], 'do=login') === false) {
- header('Location: '. escape($_POST['returnurl']));
+ header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST']));
exit;
}
}
}
try {
- $linksToDisplay = $LINKSDB->filter(LinkFilter::$FILTER_DAY, $day);
+ $linksToDisplay = $LINKSDB->filterDay($day);
} catch (Exception $exc) {
error_log($exc);
$linksToDisplay = array();
if ($targetPage == Router::$PAGE_PICWALL)
{
// Optionally filter the results:
- $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
- $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
- if (! empty($searchtags) && ! empty($searchterm)) {
- $links = $LINKSDB->filter(
- LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
- array($searchtags, $searchterm)
- );
- }
- elseif ($searchtags) {
- $links = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $searchtags);
- }
- elseif ($searchterm) {
- $links = $LINKSDB->filter(LinkFilter::$FILTER_TEXT, $searchterm);
- }
- else {
- $links = $LINKSDB;
- }
-
+ $links = $LINKSDB->filterSearch($_GET);
$linksToDisplay = array();
// Get only links which have a thumbnail.
// Delete a tag:
if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) {
- $needle=trim($_POST['fromtag']);
+ $needle = trim($_POST['fromtag']);
// True for case-sensitive tag search.
- $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true);
+ $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
foreach($linksToAlter as $key=>$value)
{
$tags = explode(' ',trim($value['tags']));
// Rename a tag:
if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) {
- $needle=trim($_POST['fromtag']);
+ $needle = trim($_POST['fromtag']);
// True for case-sensitive tag search.
- $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true);
+ $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
foreach($linksToAlter as $key=>$value)
{
$tags = explode(' ',trim($value['tags']));
// -------- User want to post a new link: Display link edit form.
if (isset($_GET['post'])) {
- $url = cleanup_url(escape($_GET['post']));
+ $url = cleanup_url($_GET['post']);
$link_is_new = false;
// Check if URL is not already in database (in this case, we will edit the existing link)
// Extract title.
$title = html_extract_title($content);
// Re-encode title in utf-8 if necessary.
- if (! empty($title) && $charset != 'utf-8') {
- $title = mb_convert_encoding($title, $charset, 'utf-8');
+ if (! empty($title) && strtolower($charset) != 'utf-8') {
+ $title = mb_convert_encoding($title, 'utf-8', $charset);
}
}
}
$url = '?' . smallHash($linkdate);
$title = 'Note: ';
}
+ $url = escape($url);
+ $title = escape($title);
$link = array(
'linkdate' => $linkdate,
}
}
-// -----------------------------------------------------------------------------------------------
-// Template for the list of links (<div id="linklist">)
-// This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
+/**
+ * Template for the list of links (<div id="linklist">)
+ * 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.
+ // Used in templates
$searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
- $searchterm = !empty($_GET['searchterm']) ? escape(trim($_GET['searchterm'])) : '';
- $privateonly = !empty($_SESSION['privateonly']) ? true : false;
-
- // Search tags + fullsearch.
- if (! empty($searchtags) && ! empty($searchterm)) {
- $linksToDisplay = $LINKSDB->filter(
- LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
- array($searchtags, $searchterm),
- false,
- $privateonly
- );
- }
- // Search by tags.
- elseif (! empty($searchtags)) {
- $linksToDisplay = $LINKSDB->filter(
- LinkFilter::$FILTER_TAG,
- $searchtags,
- false,
- $privateonly
- );
- }
- // Fulltext search.
- elseif (! empty($searchterm)) {
- $linksToDisplay = $LINKSDB->filter(
- LinkFilter::$FILTER_TEXT,
- $searchterm,
- false,
- $privateonly
- );
- }
- // Detect smallHashes in URL.
- elseif (! empty($_SERVER['QUERY_STRING'])
- && preg_match('/[a-zA-Z0-9-_@]{6}(&.+?)?/', $_SERVER['QUERY_STRING'])
- ) {
- $linksToDisplay = $LINKSDB->filter(
- LinkFilter::$FILTER_HASH,
- substr(trim($_SERVER["QUERY_STRING"], '/'), 0, 6)
- );
+ $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
- if (count($linksToDisplay) == 0) {
- $PAGE->render404('The link you are trying to reach does not exist or has been deleted.');
+ // 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.