From: ArthurHoaro Date: Fri, 2 Feb 2018 18:22:37 +0000 (+0100) Subject: Merge pull request #1038 from ArthurHoaro/feature/public-only-filter X-Git-Tag: v0.10.0~57 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=bc3ce7ec2a652eec1441774958050cf83105560a;hp=-c;p=github%2Fshaarli%2FShaarli.git Merge pull request #1038 from ArthurHoaro/feature/public-only-filter Add a filter to only display public links --- bc3ce7ec2a652eec1441774958050cf83105560a diff --combined index.php index 2de9be0a,8770b669..c2aaf84a --- a/index.php +++ b/index.php @@@ -124,11 -124,6 +124,11 @@@ if (isset($_COOKIE['shaarli']) && !Sess $conf = new ConfigManager(); $sessionManager = new SessionManager($_SESSION, $conf); +// LC_MESSAGES isn't defined without php-intl, in this case use LC_COLLATE locale instead. +if (! defined('LC_MESSAGES')) { + define('LC_MESSAGES', LC_COLLATE); +} + // Sniff browser language and set date format accordingly. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); @@@ -287,7 -282,7 +287,7 @@@ function logout() unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); - unset($_SESSION['privateonly']); + unset($_SESSION['visibility']); unset($_SESSION['untaggedonly']); } setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); @@@ -441,7 -436,7 +441,7 @@@ if (isset($_POST['login']) else { ban_loginFailed($conf); - $redir = '&username='. $_POST['login']; + $redir = '&username='. urlencode($_POST['login']); if (isset($_GET['post'])) { $redir .= '&post=' . urlencode($_GET['post']); foreach (array('description', 'source', 'title', 'tags') as $param) { @@@ -805,7 -800,7 +805,7 @@@ function renderPage($conf, $pluginManag // -------- Tag cloud if ($targetPage == Router::$PAGE_TAGCLOUD) { - $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; + $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : []; $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility); @@@ -850,7 -845,7 +850,7 @@@ // -------- Tag list if ($targetPage == Router::$PAGE_TAGLIST) { - $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; + $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : []; $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility); foreach ($filteringTags as $tag) { @@@ -1016,15 -1011,26 +1016,26 @@@ } // -------- User wants to see only private links (toggle) - if (isset($_GET['privateonly'])) { - if (empty($_SESSION['privateonly'])) { - $_SESSION['privateonly'] = 1; // See only private links - } else { - unset($_SESSION['privateonly']); // See all links + if (isset($_GET['visibility'])) { + if ($_GET['visibility'] === 'private') { + // Visibility not set or not already private, set private, otherwise reset it + if (empty($_SESSION['visibility']) || $_SESSION['visibility'] !== 'private') { + // See only private links + $_SESSION['visibility'] = 'private'; + } else { + unset($_SESSION['visibility']); + } + } else if ($_GET['visibility'] === 'public') { + if (empty($_SESSION['visibility']) || $_SESSION['visibility'] !== 'public') { + // See only public links + $_SESSION['visibility'] = 'public'; + } else { + unset($_SESSION['visibility']); + } } if (! empty($_SERVER['HTTP_REFERER'])) { - $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('privateonly')); + $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('visibility')); } else { $location = '?'; } @@@ -1430,10 -1436,16 +1441,10 @@@ // If this is an HTTP(S) link, we try go get the page to extract the title (otherwise we will to straight to the edit form.) if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) { // Short timeout to keep the application responsive - list($headers, $content) = get_http_response($url, 4); - if (strpos($headers[0], '200 OK') !== false) { - // Retrieve charset. - $charset = get_charset($headers, $content); - // Extract title. - $title = html_extract_title($content); - // Re-encode title in utf-8 if necessary. - if (! empty($title) && strtolower($charset) != 'utf-8') { - $title = mb_convert_encoding($title, 'utf-8', $charset); - } + // The callback will fill $charset and $title with data from the downloaded page. + get_http_response($url, 25, 4194304, get_curl_download_callback($charset, $title)); + if (! empty($title) && strtolower($charset) != 'utf-8') { + $title = mb_convert_encoding($title, 'utf-8', $charset); } } @@@ -1666,7 -1678,7 +1677,7 @@@ function buildLinkList($PAGE,$LINKSDB, } } else { // Filter links according search parameters. - $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; + $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; $request = [ 'searchtags' => $searchtags, 'searchterm' => $searchterm, @@@ -1742,7 -1754,7 +1753,7 @@@ 'result_count' => count($linksToDisplay), 'search_term' => $searchterm, 'search_tags' => $searchtags, - 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '', + 'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '', 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. 'links' => $linkDisp, );