aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php142
1 files changed, 5 insertions, 137 deletions
diff --git a/index.php b/index.php
index 1eaf70ce..5b8384ba 100644
--- a/index.php
+++ b/index.php
@@ -162,6 +162,7 @@ require_once 'application/LinkDB.php';
162require_once 'application/LinkFilter.php'; 162require_once 'application/LinkFilter.php';
163require_once 'application/LinkUtils.php'; 163require_once 'application/LinkUtils.php';
164require_once 'application/NetscapeBookmarkUtils.php'; 164require_once 'application/NetscapeBookmarkUtils.php';
165require_once 'application/PageBuilder.php';
165require_once 'application/TimeZone.php'; 166require_once 'application/TimeZone.php';
166require_once 'application/Url.php'; 167require_once 'application/Url.php';
167require_once 'application/Utils.php'; 168require_once 'application/Utils.php';
@@ -563,128 +564,6 @@ function tokenOk($token)
563} 564}
564 565
565// ------------------------------------------------------------------------------------------ 566// ------------------------------------------------------------------------------------------
566/* This class is in charge of building the final page.
567 (This is basically a wrapper around RainTPL which pre-fills some fields.)
568 p = new pageBuilder;
569 p.assign('myfield','myvalue');
570 p.renderPage('mytemplate');
571
572*/
573class pageBuilder
574{
575 private $tpl; // RainTPL template
576
577 function __construct()
578 {
579 $this->tpl = false;
580 }
581
582 /**
583 * Initialize all default tpl tags.
584 */
585 private function initialize()
586 {
587 $this->tpl = new RainTPL;
588
589 try {
590 $version = ApplicationUtils::checkUpdate(
591 shaarli_version,
592 $GLOBALS['config']['UPDATECHECK_FILENAME'],
593 $GLOBALS['config']['UPDATECHECK_INTERVAL'],
594 $GLOBALS['config']['ENABLE_UPDATECHECK'],
595 isLoggedIn(),
596 $GLOBALS['config']['UPDATECHECK_BRANCH']
597 );
598 $this->tpl->assign('newVersion', escape($version));
599 $this->tpl->assign('versionError', '');
600
601 } catch (Exception $exc) {
602 logm($GLOBALS['config']['LOG_FILE'], $_SERVER['REMOTE_ADDR'], $exc->getMessage());
603 $this->tpl->assign('newVersion', '');
604 $this->tpl->assign('versionError', escape($exc->getMessage()));
605 }
606
607 $this->tpl->assign('feedurl', escape(index_url($_SERVER)));
608 $searchcrits = ''; // Search criteria
609 if (!empty($_GET['searchtags'])) {
610 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
611 }
612 if (!empty($_GET['searchterm'])) {
613 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
614 }
615 $this->tpl->assign('searchcrits', $searchcrits);
616 $this->tpl->assign('source', index_url($_SERVER));
617 $this->tpl->assign('version', shaarli_version);
618 $this->tpl->assign('scripturl', index_url($_SERVER));
619 $this->tpl->assign('pagetitle', 'Shaarli');
620 $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
621 if (!empty($GLOBALS['title'])) {
622 $this->tpl->assign('pagetitle', $GLOBALS['title']);
623 }
624 if (!empty($GLOBALS['titleLink'])) {
625 $this->tpl->assign('titleLink', $GLOBALS['titleLink']);
626 }
627 if (!empty($GLOBALS['pagetitle'])) {
628 $this->tpl->assign('pagetitle', $GLOBALS['pagetitle']);
629 }
630 $this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']);
631 if (!empty($GLOBALS['plugin_errors'])) {
632 $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']);
633 }
634 }
635
636 // The following assign() method is basically the same as RainTPL (except that it's lazy)
637 public function assign($what,$where)
638 {
639 if ($this->tpl===false) $this->initialize(); // Lazy initialization
640 $this->tpl->assign($what,$where);
641 }
642
643 /**
644 * Assign an array of data to the template builder.
645 *
646 * @param array $data Data to assign.
647 *
648 * @return false if invalid data.
649 */
650 public function assignAll($data)
651 {
652 // Lazy initialization
653 if ($this->tpl === false) {
654 $this->initialize();
655 }
656
657 if (empty($data) || !is_array($data)){
658 return false;
659 }
660
661 foreach ($data as $key => $value) {
662 $this->assign($key, $value);
663 }
664 }
665
666 // Render a specific page (using a template).
667 // e.g. pb.renderPage('picwall')
668 public function renderPage($page)
669 {
670 if ($this->tpl===false) $this->initialize(); // Lazy initialization
671 $this->tpl->draw($page);
672 }
673
674 /**
675 * Render a 404 page (uses the template : tpl/404.tpl)
676 *
677 * usage : $PAGE->render404('The link was deleted')
678 * @param string $message A messate to display what is not found
679 */
680 public function render404($message='The page you are trying to reach does not exist or has been deleted.') {
681 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
682 $this->tpl->assign('error_message', $message);
683 $this->renderPage('404');
684 }
685}
686
687// ------------------------------------------------------------------------------------------
688// Daily RSS feed: 1 RSS entry per day giving all the links on that day. 567// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
689// Gives the last 7 days (which have links). 568// Gives the last 7 days (which have links).
690// This RSS feed cannot be filtered. 569// This RSS feed cannot be filtered.
@@ -857,7 +736,6 @@ function showDaily($pageBuilder, $LINKSDB)
857 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); 736 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
858 $data = array( 737 $data = array(
859 'linksToDisplay' => $linksToDisplay, 738 'linksToDisplay' => $linksToDisplay,
860 'linkcount' => count($LINKSDB),
861 'cols' => $columns, 739 'cols' => $columns,
862 'day' => $dayDate->getTimestamp(), 740 'day' => $dayDate->getTimestamp(),
863 'previousday' => $previousday, 741 'previousday' => $previousday,
@@ -912,7 +790,9 @@ function renderPage()
912 die($e->getMessage()); 790 die($e->getMessage());
913 } 791 }
914 792
915 $PAGE = new pageBuilder; 793 $PAGE = new PageBuilder();
794 $PAGE->assign('linkcount', count($LINKSDB));
795 $PAGE->assign('privateLinkcount', count_private($LINKSDB));
916 796
917 // Determine which page will be rendered. 797 // Determine which page will be rendered.
918 $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; 798 $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '';
@@ -979,7 +859,6 @@ function renderPage()
979 } 859 }
980 860
981 $data = array( 861 $data = array(
982 'linkcount' => count($LINKSDB),
983 'linksToDisplay' => $linksToDisplay, 862 'linksToDisplay' => $linksToDisplay,
984 ); 863 );
985 $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn())); 864 $pluginManager->executeHooks('render_picwall', $data, array('loggedin' => isLoggedIn()));
@@ -1029,7 +908,6 @@ function renderPage()
1029 } 908 }
1030 909
1031 $data = array( 910 $data = array(
1032 'linkcount' => count($LINKSDB),
1033 'tags' => $tagList, 911 'tags' => $tagList,
1034 ); 912 );
1035 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); 913 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
@@ -1217,7 +1095,6 @@ function renderPage()
1217 if ($targetPage == Router::$PAGE_TOOLS) 1095 if ($targetPage == Router::$PAGE_TOOLS)
1218 { 1096 {
1219 $data = array( 1097 $data = array(
1220 'linkcount' => count($LINKSDB),
1221 'pageabsaddr' => index_url($_SERVER), 1098 'pageabsaddr' => index_url($_SERVER),
1222 ); 1099 );
1223 $pluginManager->executeHooks('render_tools', $data); 1100 $pluginManager->executeHooks('render_tools', $data);
@@ -1262,7 +1139,6 @@ function renderPage()
1262 } 1139 }
1263 else // show the change password form. 1140 else // show the change password form.
1264 { 1141 {
1265 $PAGE->assign('linkcount',count($LINKSDB));
1266 $PAGE->assign('token',getToken()); 1142 $PAGE->assign('token',getToken());
1267 $PAGE->renderPage('changepassword'); 1143 $PAGE->renderPage('changepassword');
1268 exit; 1144 exit;
@@ -1310,7 +1186,6 @@ function renderPage()
1310 } 1186 }
1311 else // Show the configuration form. 1187 else // Show the configuration form.
1312 { 1188 {
1313 $PAGE->assign('linkcount',count($LINKSDB));
1314 $PAGE->assign('token',getToken()); 1189 $PAGE->assign('token',getToken());
1315 $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] ); 1190 $PAGE->assign('title', empty($GLOBALS['title']) ? '' : $GLOBALS['title'] );
1316 $PAGE->assign('redirector', empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] ); 1191 $PAGE->assign('redirector', empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'] );
@@ -1326,7 +1201,6 @@ function renderPage()
1326 if ($targetPage == Router::$PAGE_CHANGETAG) 1201 if ($targetPage == Router::$PAGE_CHANGETAG)
1327 { 1202 {
1328 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { 1203 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) {
1329 $PAGE->assign('linkcount', count($LINKSDB));
1330 $PAGE->assign('token', getToken()); 1204 $PAGE->assign('token', getToken());
1331 $PAGE->assign('tags', $LINKSDB->allTags()); 1205 $PAGE->assign('tags', $LINKSDB->allTags());
1332 $PAGE->renderPage('changetag'); 1206 $PAGE->renderPage('changetag');
@@ -1375,7 +1249,6 @@ function renderPage()
1375 // -------- User wants to add a link without using the bookmarklet: Show form. 1249 // -------- User wants to add a link without using the bookmarklet: Show form.
1376 if ($targetPage == Router::$PAGE_ADDLINK) 1250 if ($targetPage == Router::$PAGE_ADDLINK)
1377 { 1251 {
1378 $PAGE->assign('linkcount',count($LINKSDB));
1379 $PAGE->renderPage('addlink'); 1252 $PAGE->renderPage('addlink');
1380 exit; 1253 exit;
1381 } 1254 }
@@ -1501,7 +1374,6 @@ function renderPage()
1501 $link = $LINKSDB[$_GET['edit_link']]; // Read database 1374 $link = $LINKSDB[$_GET['edit_link']]; // Read database
1502 if (!$link) { header('Location: ?'); exit; } // Link not found in database. 1375 if (!$link) { header('Location: ?'); exit; } // Link not found in database.
1503 $data = array( 1376 $data = array(
1504 'linkcount' => count($LINKSDB),
1505 'link' => $link, 1377 'link' => $link,
1506 'link_is_new' => false, 1378 'link_is_new' => false,
1507 'token' => getToken(), 1379 'token' => getToken(),
@@ -1569,7 +1441,6 @@ function renderPage()
1569 } 1441 }
1570 1442
1571 $data = array( 1443 $data = array(
1572 'linkcount' => count($LINKSDB),
1573 'link' => $link, 1444 'link' => $link,
1574 'link_is_new' => $link_is_new, 1445 'link_is_new' => $link_is_new,
1575 'token' => getToken(), // XSRF protection. 1446 'token' => getToken(), // XSRF protection.
@@ -1591,7 +1462,6 @@ function renderPage()
1591 // Export links as a Netscape Bookmarks file 1462 // Export links as a Netscape Bookmarks file
1592 1463
1593 if (empty($_GET['selection'])) { 1464 if (empty($_GET['selection'])) {
1594 $PAGE->assign('linkcount',count($LINKSDB));
1595 $PAGE->renderPage('export'); 1465 $PAGE->renderPage('export');
1596 exit; 1466 exit;
1597 } 1467 }
@@ -1650,7 +1520,6 @@ function renderPage()
1650 // -------- Show upload/import dialog: 1520 // -------- Show upload/import dialog:
1651 if ($targetPage == Router::$PAGE_IMPORT) 1521 if ($targetPage == Router::$PAGE_IMPORT)
1652 { 1522 {
1653 $PAGE->assign('linkcount',count($LINKSDB));
1654 $PAGE->assign('token',getToken()); 1523 $PAGE->assign('token',getToken());
1655 $PAGE->assign('maxfilesize',getMaxFileSize()); 1524 $PAGE->assign('maxfilesize',getMaxFileSize());
1656 $PAGE->renderPage('import'); 1525 $PAGE->renderPage('import');
@@ -1882,7 +1751,6 @@ function buildLinkList($PAGE,$LINKSDB)
1882 1751
1883 // Fill all template fields. 1752 // Fill all template fields.
1884 $data = array( 1753 $data = array(
1885 'linkcount' => count($LINKSDB),
1886 'previous_page_url' => $previous_page_url, 1754 'previous_page_url' => $previous_page_url,
1887 'next_page_url' => $next_page_url, 1755 'next_page_url' => $next_page_url,
1888 'page_current' => $page, 1756 'page_current' => $page,
@@ -2157,7 +2025,7 @@ function install()
2157 $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; 2025 $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
2158 } 2026 }
2159 2027
2160 $PAGE = new pageBuilder; 2028 $PAGE = new PageBuilder();
2161 $PAGE->assign('timezone_html',$timezone_html); 2029 $PAGE->assign('timezone_html',$timezone_html);
2162 $PAGE->assign('timezone_js',$timezone_js); 2030 $PAGE->assign('timezone_js',$timezone_js);
2163 $PAGE->renderPage('install'); 2031 $PAGE->renderPage('install');