aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php207
1 files changed, 112 insertions, 95 deletions
diff --git a/index.php b/index.php
index c96d0136..92eb443b 100644
--- a/index.php
+++ b/index.php
@@ -62,6 +62,7 @@ require_once 'application/CachedPage.php';
62require_once 'application/config/ConfigPlugin.php'; 62require_once 'application/config/ConfigPlugin.php';
63require_once 'application/FeedBuilder.php'; 63require_once 'application/FeedBuilder.php';
64require_once 'application/FileUtils.php'; 64require_once 'application/FileUtils.php';
65require_once 'application/History.php';
65require_once 'application/HttpUtils.php'; 66require_once 'application/HttpUtils.php';
66require_once 'application/Languages.php'; 67require_once 'application/Languages.php';
67require_once 'application/LinkDB.php'; 68require_once 'application/LinkDB.php';
@@ -224,27 +225,6 @@ function setup_login_state($conf)
224} 225}
225$userIsLoggedIn = setup_login_state($conf); 226$userIsLoggedIn = setup_login_state($conf);
226 227
227/**
228 * PubSubHubbub protocol support (if enabled) [UNTESTED]
229 * (Source: http://aldarone.fr/les-flux-rss-shaarli-et-pubsubhubbub/ )
230 *
231 * @param ConfigManager $conf Configuration Manager instance.
232 */
233function pubsubhub($conf)
234{
235 $pshUrl = $conf->get('config.PUBSUBHUB_URL');
236 if (!empty($pshUrl))
237 {
238 include_once './publisher.php';
239 $p = new Publisher($pshUrl);
240 $topic_url = array (
241 index_url($_SERVER).'?do=atom',
242 index_url($_SERVER).'?do=rss'
243 );
244 $p->publish_update($topic_url);
245 }
246}
247
248// ------------------------------------------------------------------------------------------ 228// ------------------------------------------------------------------------------------------
249// Session management 229// Session management
250 230
@@ -473,34 +453,6 @@ if (isset($_POST['login']))
473} 453}
474 454
475// ------------------------------------------------------------------------------------------ 455// ------------------------------------------------------------------------------------------
476// Misc utility functions:
477
478// Convert post_max_size/upload_max_filesize (e.g. '16M') parameters to bytes.
479function return_bytes($val)
480{
481 $val = trim($val); $last=strtolower($val[strlen($val)-1]);
482 switch($last)
483 {
484 case 'g': $val *= 1024;
485 case 'm': $val *= 1024;
486 case 'k': $val *= 1024;
487 }
488 return $val;
489}
490
491// Try to determine max file size for uploads (POST).
492// Returns an integer (in bytes)
493function getMaxFileSize()
494{
495 $size1 = return_bytes(ini_get('post_max_size'));
496 $size2 = return_bytes(ini_get('upload_max_filesize'));
497 // Return the smaller of two:
498 $maxsize = min($size1,$size2);
499 // FIXME: Then convert back to readable notations ? (e.g. 2M instead of 2000000)
500 return $maxsize;
501}
502
503// ------------------------------------------------------------------------------------------
504// Token management for XSRF protection 456// Token management for XSRF protection
505// Token should be used in any form which acts on data (create,update,delete,import...). 457// Token should be used in any form which acts on data (create,update,delete,import...).
506if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session. 458if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session.
@@ -695,9 +647,11 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
695 647
696 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); 648 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
697 $data = array( 649 $data = array(
650 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false),
698 'linksToDisplay' => $linksToDisplay, 651 'linksToDisplay' => $linksToDisplay,
699 'cols' => $columns, 652 'cols' => $columns,
700 'day' => $dayDate->getTimestamp(), 653 'day' => $dayDate->getTimestamp(),
654 'dayDate' => $dayDate,
701 'previousday' => $previousday, 655 'previousday' => $previousday,
702 'nextday' => $nextday, 656 'nextday' => $nextday,
703 ); 657 );
@@ -732,7 +686,7 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) {
732 * @param PluginManager $pluginManager Plugin Manager instance, 686 * @param PluginManager $pluginManager Plugin Manager instance,
733 * @param LinkDB $LINKSDB 687 * @param LinkDB $LINKSDB
734 */ 688 */
735function renderPage($conf, $pluginManager, $LINKSDB) 689function renderPage($conf, $pluginManager, $LINKSDB, $history)
736{ 690{
737 $updater = new Updater( 691 $updater = new Updater(
738 read_updates_file($conf->get('resource.updates')), 692 read_updates_file($conf->get('resource.updates')),
@@ -753,7 +707,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
753 die($e->getMessage()); 707 die($e->getMessage());
754 } 708 }
755 709
756 $PAGE = new PageBuilder($conf); 710 $PAGE = new PageBuilder($conf, $LINKSDB);
757 $PAGE->assign('linkcount', count($LINKSDB)); 711 $PAGE->assign('linkcount', count($LINKSDB));
758 $PAGE->assign('privateLinkcount', count_private($LINKSDB)); 712 $PAGE->assign('privateLinkcount', count_private($LINKSDB));
759 $PAGE->assign('plugin_errors', $pluginManager->getErrors()); 713 $PAGE->assign('plugin_errors', $pluginManager->getErrors());
@@ -836,7 +790,9 @@ function renderPage($conf, $pluginManager, $LINKSDB)
836 // -------- Tag cloud 790 // -------- Tag cloud
837 if ($targetPage == Router::$PAGE_TAGCLOUD) 791 if ($targetPage == Router::$PAGE_TAGCLOUD)
838 { 792 {
839 $tags= $LINKSDB->allTags(); 793 $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all';
794 $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : [];
795 $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility);
840 796
841 // We sort tags alphabetically, then choose a font size according to count. 797 // We sort tags alphabetically, then choose a font size according to count.
842 // First, find max value. 798 // First, find max value.
@@ -845,17 +801,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
845 $maxcount = max($maxcount, $value); 801 $maxcount = max($maxcount, $value);
846 } 802 }
847 803
848 // Sort tags alphabetically: case insensitive, support locale if available. 804 alphabetical_sort($tags, true, true);
849 uksort($tags, function($a, $b) {
850 // Collator is part of PHP intl.
851 if (class_exists('Collator')) {
852 $c = new Collator(setlocale(LC_COLLATE, 0));
853 if (!intl_is_failure(intl_get_error_code())) {
854 return $c->compare($a, $b);
855 }
856 }
857 return strcasecmp($a, $b);
858 });
859 805
860 $tagList = array(); 806 $tagList = array();
861 foreach($tags as $key => $value) { 807 foreach($tags as $key => $value) {
@@ -870,6 +816,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
870 } 816 }
871 817
872 $data = array( 818 $data = array(
819 'search_tags' => implode(' ', $filteringTags),
873 'tags' => $tagList, 820 'tags' => $tagList,
874 ); 821 );
875 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); 822 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
@@ -878,7 +825,32 @@ function renderPage($conf, $pluginManager, $LINKSDB)
878 $PAGE->assign($key, $value); 825 $PAGE->assign($key, $value);
879 } 826 }
880 827
881 $PAGE->renderPage('tagcloud'); 828 $PAGE->renderPage('tag.cloud');
829 exit;
830 }
831
832 // -------- Tag cloud
833 if ($targetPage == Router::$PAGE_TAGLIST)
834 {
835 $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all';
836 $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : [];
837 $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility);
838
839 if (! empty($_GET['sort']) && $_GET['sort'] === 'alpha') {
840 alphabetical_sort($tags, false, true);
841 }
842
843 $data = [
844 'search_tags' => implode(' ', $filteringTags),
845 'tags' => $tags,
846 ];
847 $pluginManager->executeHooks('render_taglist', $data, ['loggedin' => isLoggedIn()]);
848
849 foreach ($data as $key => $value) {
850 $PAGE->assign($key, $value);
851 }
852
853 $PAGE->renderPage('tag.list');
882 exit; 854 exit;
883 } 855 }
884 856
@@ -1151,6 +1123,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1151 $conf->set('api.secret', escape($_POST['apiSecret'])); 1123 $conf->set('api.secret', escape($_POST['apiSecret']));
1152 try { 1124 try {
1153 $conf->write(isLoggedIn()); 1125 $conf->write(isLoggedIn());
1126 $history->updateSettings();
1154 invalidateCaches($conf->get('resource.page_cache')); 1127 invalidateCaches($conf->get('resource.page_cache'));
1155 } 1128 }
1156 catch(Exception $e) { 1129 catch(Exception $e) {
@@ -1172,9 +1145,12 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1172 $PAGE->assign('theme', $conf->get('resource.theme')); 1145 $PAGE->assign('theme', $conf->get('resource.theme'));
1173 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl'))); 1146 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl')));
1174 $PAGE->assign('redirector', $conf->get('redirector.url')); 1147 $PAGE->assign('redirector', $conf->get('redirector.url'));
1175 list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); 1148 list($continents, $cities) = generateTimeZoneData(
1176 $PAGE->assign('timezone_form', $timezone_form); 1149 timezone_identifiers_list(),
1177 $PAGE->assign('timezone_js',$timezone_js); 1150 $conf->get('general.timezone')
1151 );
1152 $PAGE->assign('continents', $continents);
1153 $PAGE->assign('cities', $cities);
1178 $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false)); 1154 $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false));
1179 $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false)); 1155 $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false));
1180 $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); 1156 $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false));
@@ -1191,7 +1167,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1191 if ($targetPage == Router::$PAGE_CHANGETAG) 1167 if ($targetPage == Router::$PAGE_CHANGETAG)
1192 { 1168 {
1193 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { 1169 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) {
1194 $PAGE->assign('tags', $LINKSDB->allTags()); 1170 $PAGE->assign('fromtag', ! empty($_GET['fromtag']) ? escape($_GET['fromtag']) : '');
1195 $PAGE->renderPage('changetag'); 1171 $PAGE->renderPage('changetag');
1196 exit; 1172 exit;
1197 } 1173 }
@@ -1211,6 +1187,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1211 unset($tags[array_search($needle,$tags)]); // Remove tag. 1187 unset($tags[array_search($needle,$tags)]); // Remove tag.
1212 $value['tags']=trim(implode(' ',$tags)); 1188 $value['tags']=trim(implode(' ',$tags));
1213 $LINKSDB[$key]=$value; 1189 $LINKSDB[$key]=$value;
1190 $history->updateLink($LINKSDB[$key]);
1214 } 1191 }
1215 $LINKSDB->save($conf->get('resource.page_cache')); 1192 $LINKSDB->save($conf->get('resource.page_cache'));
1216 echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>'; 1193 echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>';
@@ -1228,6 +1205,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1228 $tags[array_search($needle, $tags)] = trim($_POST['totag']); 1205 $tags[array_search($needle, $tags)] = trim($_POST['totag']);
1229 $value['tags'] = implode(' ', array_unique($tags)); 1206 $value['tags'] = implode(' ', array_unique($tags));
1230 $LINKSDB[$key] = $value; 1207 $LINKSDB[$key] = $value;
1208 $history->updateLink($LINKSDB[$key]);
1231 } 1209 }
1232 $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. 1210 $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
1233 echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>'; 1211 echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>';
@@ -1262,11 +1240,13 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1262 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1240 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1263 $updated = new DateTime(); 1241 $updated = new DateTime();
1264 $shortUrl = $LINKSDB[$id]['shorturl']; 1242 $shortUrl = $LINKSDB[$id]['shorturl'];
1243 $new = false;
1265 } else { 1244 } else {
1266 // New link 1245 // New link
1267 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1246 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1268 $updated = null; 1247 $updated = null;
1269 $shortUrl = link_small_hash($created, $id); 1248 $shortUrl = link_small_hash($created, $id);
1249 $new = true;
1270 } 1250 }
1271 1251
1272 // Remove multiple spaces. 1252 // Remove multiple spaces.
@@ -1305,6 +1285,11 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1305 1285
1306 $LINKSDB[$id] = $link; 1286 $LINKSDB[$id] = $link;
1307 $LINKSDB->save($conf->get('resource.page_cache')); 1287 $LINKSDB->save($conf->get('resource.page_cache'));
1288 if ($new) {
1289 $history->addLink($link);
1290 } else {
1291 $history->updateLink($link);
1292 }
1308 1293
1309 // If we are called from the bookmarklet, we must close the popup: 1294 // If we are called from the bookmarklet, we must close the popup:
1310 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { 1295 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
@@ -1342,19 +1327,23 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1342 // -------- User clicked the "Delete" button when editing a link: Delete link from database. 1327 // -------- User clicked the "Delete" button when editing a link: Delete link from database.
1343 if ($targetPage == Router::$PAGE_DELETELINK) 1328 if ($targetPage == Router::$PAGE_DELETELINK)
1344 { 1329 {
1345 // We do not need to ask for confirmation:
1346 // - confirmation is handled by JavaScript
1347 // - we are protected from XSRF by the token.
1348
1349 if (! tokenOk($_GET['token'])) { 1330 if (! tokenOk($_GET['token'])) {
1350 die('Wrong token.'); 1331 die('Wrong token.');
1351 } 1332 }
1352 1333
1353 $id = intval(escape($_GET['lf_linkdate'])); 1334 if (strpos($_GET['lf_linkdate'], ' ') !== false) {
1354 $link = $LINKSDB[$id]; 1335 $ids = array_values(array_filter(preg_split('/\s+/', escape($_GET['lf_linkdate']))));
1355 $pluginManager->executeHooks('delete_link', $link); 1336 } else {
1356 unset($LINKSDB[$id]); 1337 $ids = [$_GET['lf_linkdate']];
1338 }
1339 foreach ($ids as $id) {
1340 $id = (int) escape($id);
1341 $link = $LINKSDB[$id];
1342 $pluginManager->executeHooks('delete_link', $link);
1343 unset($LINKSDB[$id]);
1344 }
1357 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk 1345 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1346 $history->deleteLink($link);
1358 1347
1359 // If we are called from the bookmarklet, we must close the popup: 1348 // If we are called from the bookmarklet, we must close the popup:
1360 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } 1349 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
@@ -1384,7 +1373,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1384 'link' => $link, 1373 'link' => $link,
1385 'link_is_new' => false, 1374 'link_is_new' => false,
1386 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1375 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1387 'tags' => $LINKSDB->allTags(), 1376 'tags' => $LINKSDB->linksCountPerTag(),
1388 ); 1377 );
1389 $pluginManager->executeHooks('render_editlink', $data); 1378 $pluginManager->executeHooks('render_editlink', $data);
1390 1379
@@ -1453,7 +1442,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1453 'link_is_new' => $link_is_new, 1442 'link_is_new' => $link_is_new,
1454 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1443 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1455 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), 1444 'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
1456 'tags' => $LINKSDB->allTags(), 1445 'tags' => $LINKSDB->linksCountPerTag(),
1457 'default_private_links' => $conf->get('privacy.default_private_links', false), 1446 'default_private_links' => $conf->get('privacy.default_private_links', false),
1458 ); 1447 );
1459 $pluginManager->executeHooks('render_editlink', $data); 1448 $pluginManager->executeHooks('render_editlink', $data);
@@ -1515,7 +1504,22 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1515 1504
1516 if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { 1505 if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) {
1517 // Show import dialog 1506 // Show import dialog
1518 $PAGE->assign('maxfilesize', getMaxFileSize()); 1507 $PAGE->assign(
1508 'maxfilesize',
1509 get_max_upload_size(
1510 ini_get('post_max_size'),
1511 ini_get('upload_max_filesize'),
1512 false
1513 )
1514 );
1515 $PAGE->assign(
1516 'maxfilesizeHuman',
1517 get_max_upload_size(
1518 ini_get('post_max_size'),
1519 ini_get('upload_max_filesize'),
1520 true
1521 )
1522 );
1519 $PAGE->renderPage('import'); 1523 $PAGE->renderPage('import');
1520 exit; 1524 exit;
1521 } 1525 }
@@ -1525,7 +1529,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1525 // The file is too big or some form field may be missing. 1529 // The file is too big or some form field may be missing.
1526 echo '<script>alert("The file you are trying to upload is probably' 1530 echo '<script>alert("The file you are trying to upload is probably'
1527 .' bigger than what this webserver can accept (' 1531 .' bigger than what this webserver can accept ('
1528 .getMaxFileSize().' bytes).' 1532 .get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize')).').'
1529 .' Please upload in smaller chunks.");document.location=\'?do=' 1533 .' Please upload in smaller chunks.");document.location=\'?do='
1530 .Router::$PAGE_IMPORT .'\';</script>'; 1534 .Router::$PAGE_IMPORT .'\';</script>';
1531 exit; 1535 exit;
@@ -1537,7 +1541,8 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1537 $_POST, 1541 $_POST,
1538 $_FILES, 1542 $_FILES,
1539 $LINKSDB, 1543 $LINKSDB,
1540 $conf 1544 $conf,
1545 $history
1541 ); 1546 );
1542 echo '<script>alert("'.$status.'");document.location=\'?do=' 1547 echo '<script>alert("'.$status.'");document.location=\'?do='
1543 .Router::$PAGE_IMPORT .'\';</script>'; 1548 .Router::$PAGE_IMPORT .'\';</script>';
@@ -1577,6 +1582,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1577 $conf->set('general.enabled_plugins', save_plugin_config($_POST)); 1582 $conf->set('general.enabled_plugins', save_plugin_config($_POST));
1578 } 1583 }
1579 $conf->write(isLoggedIn()); 1584 $conf->write(isLoggedIn());
1585 $history->updateSettings();
1580 } 1586 }
1581 catch (Exception $e) { 1587 catch (Exception $e) {
1582 error_log( 1588 error_log(
@@ -1592,6 +1598,13 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1592 exit; 1598 exit;
1593 } 1599 }
1594 1600
1601 // Get a fresh token
1602 if ($targetPage == Router::$GET_TOKEN) {
1603 header('Content-Type:text/plain');
1604 echo getToken($conf);
1605 exit;
1606 }
1607
1595 // -------- Otherwise, simply display search form and links: 1608 // -------- Otherwise, simply display search form and links:
1596 showLinkList($PAGE, $LINKSDB, $conf, $pluginManager); 1609 showLinkList($PAGE, $LINKSDB, $conf, $pluginManager);
1597 exit; 1610 exit;
@@ -1706,7 +1719,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
1706 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '', 1719 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '',
1707 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. 1720 'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
1708 'links' => $linkDisp, 1721 'links' => $linkDisp,
1709 'tags' => $LINKSDB->allTags(),
1710 ); 1722 );
1711 1723
1712 // If there is only a single link, we change on-the-fly the title of the page. 1724 // If there is only a single link, we change on-the-fly the title of the page.
@@ -1992,16 +2004,10 @@ function install($conf)
1992 exit; 2004 exit;
1993 } 2005 }
1994 2006
1995 // Display config form:
1996 list($timezone_form, $timezone_js) = generateTimeZoneForm();
1997 $timezone_html = '';
1998 if ($timezone_form != '') {
1999 $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
2000 }
2001
2002 $PAGE = new PageBuilder($conf); 2007 $PAGE = new PageBuilder($conf);
2003 $PAGE->assign('timezone_html',$timezone_html); 2008 list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get());
2004 $PAGE->assign('timezone_js',$timezone_js); 2009 $PAGE->assign('continents', $continents);
2010 $PAGE->assign('cities', $cities);
2005 $PAGE->renderPage('install'); 2011 $PAGE->renderPage('install');
2006 exit; 2012 exit;
2007} 2013}
@@ -2245,16 +2251,27 @@ $linkDb = new LinkDB(
2245 $conf->get('redirector.encode_url') 2251 $conf->get('redirector.encode_url')
2246); 2252);
2247 2253
2254try {
2255 $history = new History($conf->get('resource.history'));
2256} catch(Exception $e) {
2257 die($e->getMessage());
2258}
2259
2248$container = new \Slim\Container(); 2260$container = new \Slim\Container();
2249$container['conf'] = $conf; 2261$container['conf'] = $conf;
2250$container['plugins'] = $pluginManager; 2262$container['plugins'] = $pluginManager;
2263$container['history'] = $history;
2251$app = new \Slim\App($container); 2264$app = new \Slim\App($container);
2252 2265
2253// REST API routes 2266// REST API routes
2254$app->group('/api/v1', function() { 2267$app->group('/api/v1', function() {
2255 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo'); 2268 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo');
2256 $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks'); 2269 $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
2257 $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink'); 2270 $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
2271 $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
2272 $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
2273 $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
2274 $this->get('/history', '\Shaarli\Api\Controllers\History:getHistory')->setName('getHistory');
2258})->add('\Shaarli\Api\ApiMiddleware'); 2275})->add('\Shaarli\Api\ApiMiddleware');
2259 2276
2260$response = $app->run(true); 2277$response = $app->run(true);
@@ -2263,7 +2280,7 @@ $response = $app->run(true);
2263if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { 2280if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) {
2264 // We use UTF-8 for proper international characters handling. 2281 // We use UTF-8 for proper international characters handling.
2265 header('Content-Type: text/html; charset=utf-8'); 2282 header('Content-Type: text/html; charset=utf-8');
2266 renderPage($conf, $pluginManager, $linkDb); 2283 renderPage($conf, $pluginManager, $linkDb, $history);
2267} else { 2284} else {
2268 $app->respond($response); 2285 $app->respond($response);
2269} 2286}