diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 92 |
1 files changed, 66 insertions, 26 deletions
@@ -44,12 +44,18 @@ $GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php' | |||
44 | // Banned IPs | 44 | // Banned IPs |
45 | $GLOBALS['config']['IPBANS_FILENAME'] = $GLOBALS['config']['DATADIR'].'/ipbans.php'; | 45 | $GLOBALS['config']['IPBANS_FILENAME'] = $GLOBALS['config']['DATADIR'].'/ipbans.php'; |
46 | 46 | ||
47 | // Processed updates file. | ||
48 | $GLOBALS['config']['UPDATES_FILE'] = $GLOBALS['config']['DATADIR'].'/updates.txt'; | ||
49 | |||
47 | // Access log | 50 | // Access log |
48 | $GLOBALS['config']['LOG_FILE'] = $GLOBALS['config']['DATADIR'].'/log.txt'; | 51 | $GLOBALS['config']['LOG_FILE'] = $GLOBALS['config']['DATADIR'].'/log.txt'; |
49 | 52 | ||
50 | // For updates check of Shaarli | 53 | // For updates check of Shaarli |
51 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; | 54 | $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; |
52 | 55 | ||
56 | // Set ENABLE_UPDATECHECK to disabled by default. | ||
57 | $GLOBALS['config']['ENABLE_UPDATECHECK'] = false; | ||
58 | |||
53 | // RainTPL cache directory (keep the trailing slash!) | 59 | // RainTPL cache directory (keep the trailing slash!) |
54 | $GLOBALS['config']['RAINTPL_TMP'] = 'tmp/'; | 60 | $GLOBALS['config']['RAINTPL_TMP'] = 'tmp/'; |
55 | // Raintpl template directory (keep the trailing slash!) | 61 | // Raintpl template directory (keep the trailing slash!) |
@@ -61,7 +67,6 @@ $GLOBALS['config']['CACHEDIR'] = 'cache'; | |||
61 | // Atom & RSS feed cache directory | 67 | // Atom & RSS feed cache directory |
62 | $GLOBALS['config']['PAGECACHE'] = 'pagecache'; | 68 | $GLOBALS['config']['PAGECACHE'] = 'pagecache'; |
63 | 69 | ||
64 | |||
65 | /* | 70 | /* |
66 | * Global configuration | 71 | * Global configuration |
67 | */ | 72 | */ |
@@ -111,7 +116,8 @@ $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400; | |||
111 | //); | 116 | //); |
112 | $GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode'); | 117 | $GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode'); |
113 | 118 | ||
114 | //$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/'; | 119 | // Initialize plugin parameters array. |
120 | $GLOBALS['plugins'] = array(); | ||
115 | 121 | ||
116 | // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. | 122 | // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. |
117 | $GLOBALS['config']['PUBSUBHUB_URL'] = ''; | 123 | $GLOBALS['config']['PUBSUBHUB_URL'] = ''; |
@@ -159,6 +165,7 @@ require_once 'application/Utils.php'; | |||
159 | require_once 'application/Config.php'; | 165 | require_once 'application/Config.php'; |
160 | require_once 'application/PluginManager.php'; | 166 | require_once 'application/PluginManager.php'; |
161 | require_once 'application/Router.php'; | 167 | require_once 'application/Router.php'; |
168 | require_once 'application/Updater.php'; | ||
162 | 169 | ||
163 | // Ensure the PHP version is supported | 170 | // Ensure the PHP version is supported |
164 | try { | 171 | try { |
@@ -1110,6 +1117,25 @@ function renderPage() | |||
1110 | $GLOBALS['redirector'] | 1117 | $GLOBALS['redirector'] |
1111 | ); | 1118 | ); |
1112 | 1119 | ||
1120 | $updater = new Updater( | ||
1121 | read_updates_file($GLOBALS['config']['UPDATES_FILE']), | ||
1122 | $GLOBALS, | ||
1123 | $LINKSDB, | ||
1124 | isLoggedIn() | ||
1125 | ); | ||
1126 | try { | ||
1127 | $newUpdates = $updater->update(); | ||
1128 | if (! empty($newUpdates)) { | ||
1129 | write_updates_file( | ||
1130 | $GLOBALS['config']['UPDATES_FILE'], | ||
1131 | $updater->getDoneUpdates() | ||
1132 | ); | ||
1133 | } | ||
1134 | } | ||
1135 | catch(Exception $e) { | ||
1136 | die($e->getMessage()); | ||
1137 | } | ||
1138 | |||
1113 | $PAGE = new pageBuilder; | 1139 | $PAGE = new pageBuilder; |
1114 | 1140 | ||
1115 | // Determine which page will be rendered. | 1141 | // Determine which page will be rendered. |
@@ -1119,9 +1145,9 @@ function renderPage() | |||
1119 | // Call plugin hooks for header, footer and includes, specifying which page will be rendered. | 1145 | // Call plugin hooks for header, footer and includes, specifying which page will be rendered. |
1120 | // Then assign generated data to RainTPL. | 1146 | // Then assign generated data to RainTPL. |
1121 | $common_hooks = array( | 1147 | $common_hooks = array( |
1148 | 'includes', | ||
1122 | 'header', | 1149 | 'header', |
1123 | 'footer', | 1150 | 'footer', |
1124 | 'includes', | ||
1125 | ); | 1151 | ); |
1126 | $pluginManager = PluginManager::getInstance(); | 1152 | $pluginManager = PluginManager::getInstance(); |
1127 | foreach($common_hooks as $name) { | 1153 | foreach($common_hooks as $name) { |
@@ -1540,21 +1566,42 @@ function renderPage() | |||
1540 | // -------- User clicked the "Save" button when editing a link: Save link to database. | 1566 | // -------- User clicked the "Save" button when editing a link: Save link to database. |
1541 | if (isset($_POST['save_edit'])) | 1567 | if (isset($_POST['save_edit'])) |
1542 | { | 1568 | { |
1543 | if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away! | 1569 | // Go away! |
1544 | $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. | 1570 | if (! tokenOk($_POST['token'])) { |
1545 | $tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates. | 1571 | die('Wrong token.'); |
1546 | $linkdate=$_POST['lf_linkdate']; | 1572 | } |
1573 | // Remove multiple spaces. | ||
1574 | $tags = trim(preg_replace('/\s\s+/', ' ', $_POST['lf_tags'])); | ||
1575 | // Remove first '-' char in tags. | ||
1576 | $tags = preg_replace('/(^| )\-/', '$1', $tags); | ||
1577 | // Remove duplicates. | ||
1578 | $tags = implode(' ', array_unique(explode(' ', $tags))); | ||
1579 | $linkdate = $_POST['lf_linkdate']; | ||
1547 | $url = trim($_POST['lf_url']); | 1580 | $url = trim($_POST['lf_url']); |
1548 | if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:')) | 1581 | if (! startsWith($url, 'http:') && ! startsWith($url, 'https:') |
1549 | $url = 'http://'.$url; | 1582 | && ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:') |
1550 | $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), | 1583 | && ! startsWith($url, '?') && ! startsWith($url, 'javascript:') |
1551 | 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); | 1584 | ) { |
1552 | if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. | 1585 | $url = 'http://' . $url; |
1586 | } | ||
1587 | |||
1588 | $link = array( | ||
1589 | 'title' => trim($_POST['lf_title']), | ||
1590 | 'url' => $url, | ||
1591 | 'description' => trim($_POST['lf_description']), | ||
1592 | 'private' => (isset($_POST['lf_private']) ? 1 : 0), | ||
1593 | 'linkdate' => $linkdate, | ||
1594 | 'tags' => str_replace(',', ' ', $tags) | ||
1595 | ); | ||
1596 | // If title is empty, use the URL as title. | ||
1597 | if ($link['title'] == '') { | ||
1598 | $link['title'] = $link['url']; | ||
1599 | } | ||
1553 | 1600 | ||
1554 | $pluginManager->executeHooks('save_link', $link); | 1601 | $pluginManager->executeHooks('save_link', $link); |
1555 | 1602 | ||
1556 | $LINKSDB[$linkdate] = $link; | 1603 | $LINKSDB[$linkdate] = $link; |
1557 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk. | 1604 | $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); |
1558 | pubsubhub(); | 1605 | pubsubhub(); |
1559 | 1606 | ||
1560 | // If we are called from the bookmarklet, we must close the popup: | 1607 | // If we are called from the bookmarklet, we must close the popup: |
@@ -1563,10 +1610,12 @@ function renderPage() | |||
1563 | exit; | 1610 | exit; |
1564 | } | 1611 | } |
1565 | 1612 | ||
1566 | $returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?'; | 1613 | $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?'; |
1567 | $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); | 1614 | $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); |
1568 | $location .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited. | 1615 | // Scroll to the link which has been edited. |
1569 | header('Location: '. $location); // After saving the link, redirect to the page the user was on. | 1616 | $location .= '#' . smallHash($_POST['lf_linkdate']); |
1617 | // After saving the link, redirect to the page the user was on. | ||
1618 | header('Location: '. $location); | ||
1570 | exit; | 1619 | exit; |
1571 | } | 1620 | } |
1572 | 1621 | ||
@@ -1825,7 +1874,7 @@ HTML; | |||
1825 | ); | 1874 | ); |
1826 | 1875 | ||
1827 | // TODO: do not handle exceptions/errors in JS. | 1876 | // TODO: do not handle exceptions/errors in JS. |
1828 | echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do=pluginsadmin\';</script>'; | 1877 | echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do='. Router::$PAGE_PLUGINSADMIN .'\';</script>'; |
1829 | exit; | 1878 | exit; |
1830 | } | 1879 | } |
1831 | header('Location: ?do='. Router::$PAGE_PLUGINSADMIN); | 1880 | header('Location: ?do='. Router::$PAGE_PLUGINSADMIN); |
@@ -2529,15 +2578,6 @@ function resizeImage($filepath) | |||
2529 | return true; | 2578 | return true; |
2530 | } | 2579 | } |
2531 | 2580 | ||
2532 | try { | ||
2533 | mergeDeprecatedConfig($GLOBALS, isLoggedIn()); | ||
2534 | } catch(Exception $e) { | ||
2535 | error_log( | ||
2536 | 'ERROR while merging deprecated options.php file.' . PHP_EOL . | ||
2537 | $e->getMessage() | ||
2538 | ); | ||
2539 | } | ||
2540 | |||
2541 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. | 2581 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. |
2542 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } | 2582 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } |
2543 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } | 2583 | if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } |