From: ArthurHoaro Date: Fri, 2 Feb 2018 18:23:26 +0000 (+0100) Subject: Merge pull request #1074 from kalvn/feature/dailymarkdown X-Git-Tag: v0.10.0~56 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=a381c373b30ed04001ea31ff5c38e077edacaf18;hp=-c;p=github%2Fshaarli%2FShaarli.git Merge pull request #1074 from kalvn/feature/dailymarkdown Executes daily hooks before creating columns. --- a381c373b30ed04001ea31ff5c38e077edacaf18 diff --combined index.php index c2aaf84a,ae0ce8f0..067b8fcb --- 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); @@@ -616,6 -611,20 +616,20 @@@ function showDaily($pageBuilder, $LINKS $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); } + $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); + $data = array( + 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), + 'linksToDisplay' => $linksToDisplay, + 'day' => $dayDate->getTimestamp(), + 'dayDate' => $dayDate, + 'previousday' => $previousday, + 'nextday' => $nextday, + ); + + /* Hook is called before column construction so that plugins don't have + to deal with columns. */ + $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); + /* We need to spread the articles on 3 columns. I did not want to use a JavaScript lib like http://masonry.desandro.com/ so I manually spread entries with a simple method: I roughly evaluate the @@@ -623,7 -632,7 +637,7 @@@ */ $columns = array(array(), array(), array()); // Entries to display, for each column. $fill = array(0, 0, 0); // Rough estimate of columns fill. - foreach($linksToDisplay as $key => $link) { + foreach($data['linksToDisplay'] as $key => $link) { // Roughly estimate length of entry (by counting characters) // Title: 30 chars = 1 line. 1 line is 30 pixels height. // Description: 836 characters gives roughly 342 pixel height. @@@ -639,18 -648,7 +653,7 @@@ $fill[$index] += $length; } - $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); - $data = array( - 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), - 'linksToDisplay' => $linksToDisplay, - 'cols' => $columns, - 'day' => $dayDate->getTimestamp(), - 'dayDate' => $dayDate, - 'previousday' => $previousday, - 'nextday' => $nextday, - ); - - $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); + $data['cols'] = $columns; foreach ($data as $key => $value) { $pageBuilder->assign($key, $value); @@@ -805,7 -803,7 +808,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 -848,7 +853,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,26 -1014,15 +1019,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 = '?'; } @@@ -1677,7 -1664,7 +1680,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, @@@ -1753,7 -1740,7 +1756,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, );