]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1074 from kalvn/feature/dailymarkdown
authorArthurHoaro <arthur@hoa.ro>
Fri, 2 Feb 2018 18:23:26 +0000 (19:23 +0100)
committerGitHub <noreply@github.com>
Fri, 2 Feb 2018 18:23:26 +0000 (19:23 +0100)
Executes daily hooks before creating columns.

1  2 
index.php

diff --combined index.php
index c2aaf84a14959590279bb07d809459141e49c7e5,ae0ce8f0e738fa6204b12fbfca3b1ef99b403391..067b8fcb972c3d6517d3448d7895d9502fc618e6
+++ 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
      */
      $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.
          $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);
  
      // -------- 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) {
      }
  
      // -------- 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,
          '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,
      );