diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 207 |
1 files changed, 112 insertions, 95 deletions
@@ -62,6 +62,7 @@ require_once 'application/CachedPage.php'; | |||
62 | require_once 'application/config/ConfigPlugin.php'; | 62 | require_once 'application/config/ConfigPlugin.php'; |
63 | require_once 'application/FeedBuilder.php'; | 63 | require_once 'application/FeedBuilder.php'; |
64 | require_once 'application/FileUtils.php'; | 64 | require_once 'application/FileUtils.php'; |
65 | require_once 'application/History.php'; | ||
65 | require_once 'application/HttpUtils.php'; | 66 | require_once 'application/HttpUtils.php'; |
66 | require_once 'application/Languages.php'; | 67 | require_once 'application/Languages.php'; |
67 | require_once 'application/LinkDB.php'; | 68 | require_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 | */ | ||
233 | function 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. | ||
479 | function 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) | ||
493 | function 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...). |
506 | if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session. | 458 | if (!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 | */ |
735 | function renderPage($conf, $pluginManager, $LINKSDB) | 689 | function 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; |
@@ -1694,7 +1707,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) | |||
1694 | 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '', | 1707 | 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '', |
1695 | 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. | 1708 | 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. |
1696 | 'links' => $linkDisp, | 1709 | 'links' => $linkDisp, |
1697 | 'tags' => $LINKSDB->allTags(), | ||
1698 | ); | 1710 | ); |
1699 | 1711 | ||
1700 | // If there is only a single link, we change on-the-fly the title of the page. | 1712 | // If there is only a single link, we change on-the-fly the title of the page. |
@@ -1980,16 +1992,10 @@ function install($conf) | |||
1980 | exit; | 1992 | exit; |
1981 | } | 1993 | } |
1982 | 1994 | ||
1983 | // Display config form: | ||
1984 | list($timezone_form, $timezone_js) = generateTimeZoneForm(); | ||
1985 | $timezone_html = ''; | ||
1986 | if ($timezone_form != '') { | ||
1987 | $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>'; | ||
1988 | } | ||
1989 | |||
1990 | $PAGE = new PageBuilder($conf); | 1995 | $PAGE = new PageBuilder($conf); |
1991 | $PAGE->assign('timezone_html',$timezone_html); | 1996 | list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get()); |
1992 | $PAGE->assign('timezone_js',$timezone_js); | 1997 | $PAGE->assign('continents', $continents); |
1998 | $PAGE->assign('cities', $cities); | ||
1993 | $PAGE->renderPage('install'); | 1999 | $PAGE->renderPage('install'); |
1994 | exit; | 2000 | exit; |
1995 | } | 2001 | } |
@@ -2233,16 +2239,27 @@ $linkDb = new LinkDB( | |||
2233 | $conf->get('redirector.encode_url') | 2239 | $conf->get('redirector.encode_url') |
2234 | ); | 2240 | ); |
2235 | 2241 | ||
2242 | try { | ||
2243 | $history = new History($conf->get('resource.history')); | ||
2244 | } catch(Exception $e) { | ||
2245 | die($e->getMessage()); | ||
2246 | } | ||
2247 | |||
2236 | $container = new \Slim\Container(); | 2248 | $container = new \Slim\Container(); |
2237 | $container['conf'] = $conf; | 2249 | $container['conf'] = $conf; |
2238 | $container['plugins'] = $pluginManager; | 2250 | $container['plugins'] = $pluginManager; |
2251 | $container['history'] = $history; | ||
2239 | $app = new \Slim\App($container); | 2252 | $app = new \Slim\App($container); |
2240 | 2253 | ||
2241 | // REST API routes | 2254 | // REST API routes |
2242 | $app->group('/api/v1', function() { | 2255 | $app->group('/api/v1', function() { |
2243 | $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo'); | 2256 | $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo'); |
2244 | $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks'); | 2257 | $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks'); |
2245 | $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink'); | 2258 | $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink'); |
2259 | $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink'); | ||
2260 | $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink'); | ||
2261 | $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink'); | ||
2262 | $this->get('/history', '\Shaarli\Api\Controllers\History:getHistory')->setName('getHistory'); | ||
2246 | })->add('\Shaarli\Api\ApiMiddleware'); | 2263 | })->add('\Shaarli\Api\ApiMiddleware'); |
2247 | 2264 | ||
2248 | $response = $app->run(true); | 2265 | $response = $app->run(true); |
@@ -2251,7 +2268,7 @@ $response = $app->run(true); | |||
2251 | if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { | 2268 | if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { |
2252 | // We use UTF-8 for proper international characters handling. | 2269 | // We use UTF-8 for proper international characters handling. |
2253 | header('Content-Type: text/html; charset=utf-8'); | 2270 | header('Content-Type: text/html; charset=utf-8'); |
2254 | renderPage($conf, $pluginManager, $linkDb); | 2271 | renderPage($conf, $pluginManager, $linkDb, $history); |
2255 | } else { | 2272 | } else { |
2256 | $app->respond($response); | 2273 | $app->respond($response); |
2257 | } | 2274 | } |