aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php92
1 files changed, 63 insertions, 29 deletions
diff --git a/index.php b/index.php
index 7df6d819..fb00a9fa 100644
--- a/index.php
+++ b/index.php
@@ -583,20 +583,29 @@ function showDailyRSS($conf) {
583 */ 583 */
584function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) 584function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
585{ 585{
586 $day=date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. 586 $day = date('Ymd', strtotime('-1 day')); // Yesterday, in format YYYYMMDD.
587 if (isset($_GET['day'])) $day=$_GET['day']; 587 if (isset($_GET['day'])) {
588 $day = $_GET['day'];
589 }
588 590
589 $days = $LINKSDB->days(); 591 $days = $LINKSDB->days();
590 $i = array_search($day,$days); 592 $i = array_search($day, $days);
591 if ($i===false) { $i=count($days)-1; $day=$days[$i]; } 593 if ($i === false && count($days)) {
592 $previousday=''; 594 // no links for day, but at least one day with links
593 $nextday=''; 595 $i = count($days) - 1;
594 if ($i!==false) 596 $day = $days[$i];
595 {
596 if ($i>=1) $previousday=$days[$i-1];
597 if ($i<count($days)-1) $nextday=$days[$i+1];
598 } 597 }
598 $previousday = '';
599 $nextday = '';
599 600
601 if ($i !== false) {
602 if ($i >= 1) {
603 $previousday=$days[$i - 1];
604 }
605 if ($i < count($days) - 1) {
606 $nextday = $days[$i + 1];
607 }
608 }
600 try { 609 try {
601 $linksToDisplay = $LINKSDB->filterDay($day); 610 $linksToDisplay = $LINKSDB->filterDay($day);
602 } catch (Exception $exc) { 611 } catch (Exception $exc) {
@@ -605,9 +614,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
605 } 614 }
606 615
607 // We pre-format some fields for proper output. 616 // We pre-format some fields for proper output.
608 foreach($linksToDisplay as $key=>$link) 617 foreach($linksToDisplay as $key => $link) {
609 {
610
611 $taglist = explode(' ',$link['tags']); 618 $taglist = explode(' ',$link['tags']);
612 uasort($taglist, 'strcasecmp'); 619 uasort($taglist, 'strcasecmp');
613 $linksToDisplay[$key]['taglist']=$taglist; 620 $linksToDisplay[$key]['taglist']=$taglist;
@@ -621,21 +628,22 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
621 so I manually spread entries with a simple method: I roughly evaluate the 628 so I manually spread entries with a simple method: I roughly evaluate the
622 height of a div according to title and description length. 629 height of a div according to title and description length.
623 */ 630 */
624 $columns=array(array(),array(),array()); // Entries to display, for each column. 631 $columns = array(array(), array(), array()); // Entries to display, for each column.
625 $fill=array(0,0,0); // Rough estimate of columns fill. 632 $fill = array(0, 0, 0); // Rough estimate of columns fill.
626 foreach($linksToDisplay as $key=>$link) 633 foreach($linksToDisplay as $key => $link) {
627 {
628 // Roughly estimate length of entry (by counting characters) 634 // Roughly estimate length of entry (by counting characters)
629 // Title: 30 chars = 1 line. 1 line is 30 pixels height. 635 // Title: 30 chars = 1 line. 1 line is 30 pixels height.
630 // Description: 836 characters gives roughly 342 pixel height. 636 // Description: 836 characters gives roughly 342 pixel height.
631 // This is not perfect, but it's usually OK. 637 // This is not perfect, but it's usually OK.
632 $length=strlen($link['title'])+(342*strlen($link['description']))/836; 638 $length = strlen($link['title']) + (342 * strlen($link['description'])) / 836;
633 if ($link['thumbnail']) $length +=100; // 1 thumbnails roughly takes 100 pixels height. 639 if ($link['thumbnail']) {
640 $length += 100; // 1 thumbnails roughly takes 100 pixels height.
641 }
634 // Then put in column which is the less filled: 642 // Then put in column which is the less filled:
635 $smallest=min($fill); // find smallest value in array. 643 $smallest = min($fill); // find smallest value in array.
636 $index=array_search($smallest,$fill); // find index of this smallest value. 644 $index = array_search($smallest, $fill); // find index of this smallest value.
637 array_push($columns[$index],$link); // Put entry in this column. 645 array_push($columns[$index], $link); // Put entry in this column.
638 $fill[$index]+=$length; 646 $fill[$index] += $length;
639 } 647 }
640 648
641 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); 649 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
@@ -710,6 +718,23 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
710 $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; 718 $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '';
711 $targetPage = Router::findPage($query, $_GET, isLoggedIn()); 719 $targetPage = Router::findPage($query, $_GET, isLoggedIn());
712 720
721 if (
722 // if the user isn't logged in
723 !isLoggedIn() &&
724 // and Shaarli doesn't have public content...
725 $conf->get('privacy.hide_public_links') &&
726 // and is configured to enforce the login
727 $conf->get('privacy.force_login') &&
728 // and the current page isn't already the login page
729 $targetPage !== Router::$PAGE_LOGIN &&
730 // and the user is not requesting a feed (which would lead to a different content-type as expected)
731 $targetPage !== Router::$PAGE_FEED_ATOM &&
732 $targetPage !== Router::$PAGE_FEED_RSS
733 ) {
734 // force current page to be the login page
735 $targetPage = Router::$PAGE_LOGIN;
736 }
737
713 // Call plugin hooks for header, footer and includes, specifying which page will be rendered. 738 // Call plugin hooks for header, footer and includes, specifying which page will be rendered.
714 // Then assign generated data to RainTPL. 739 // Then assign generated data to RainTPL.
715 $common_hooks = array( 740 $common_hooks = array(
@@ -737,6 +762,8 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
737 $PAGE->assign('username', escape($_GET['username'])); 762 $PAGE->assign('username', escape($_GET['username']));
738 } 763 }
739 $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); 764 $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
765 // add default state of the 'remember me' checkbox
766 $PAGE->assign('remember_user_default', $conf->get('privacy.remember_user_default'));
740 $PAGE->renderPage('loginform'); 767 $PAGE->renderPage('loginform');
741 exit; 768 exit;
742 } 769 }
@@ -1055,10 +1082,10 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
1055 // -------- Display the Tools menu if requested (import/export/bookmarklet...) 1082 // -------- Display the Tools menu if requested (import/export/bookmarklet...)
1056 if ($targetPage == Router::$PAGE_TOOLS) 1083 if ($targetPage == Router::$PAGE_TOOLS)
1057 { 1084 {
1058 $data = array( 1085 $data = [
1059 'pageabsaddr' => index_url($_SERVER), 1086 'pageabsaddr' => index_url($_SERVER),
1060 'sslenabled' => !empty($_SERVER['HTTPS']) 1087 'sslenabled' => is_https($_SERVER),
1061 ); 1088 ];
1062 $pluginManager->executeHooks('render_tools', $data); 1089 $pluginManager->executeHooks('render_tools', $data);
1063 1090
1064 foreach ($data as $key => $value) { 1091 foreach ($data as $key => $value) {
@@ -1320,10 +1347,17 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
1320 die('Wrong token.'); 1347 die('Wrong token.');
1321 } 1348 }
1322 1349
1323 if (strpos($_GET['lf_linkdate'], ' ') !== false) { 1350 $ids = trim($_GET['lf_linkdate']);
1324 $ids = array_values(array_filter(preg_split('/\s+/', escape($_GET['lf_linkdate'])))); 1351 if (strpos($ids, ' ') !== false) {
1352 // multiple, space-separated ids provided
1353 $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
1325 } else { 1354 } else {
1326 $ids = [$_GET['lf_linkdate']]; 1355 // only a single id provided
1356 $ids = [$ids];
1357 }
1358 // assert at least one id is given
1359 if(!count($ids)){
1360 die('no id provided');
1327 } 1361 }
1328 foreach ($ids as $id) { 1362 foreach ($ids as $id) {
1329 $id = (int) escape($id); 1363 $id = (int) escape($id);