aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php80
1 files changed, 57 insertions, 23 deletions
diff --git a/index.php b/index.php
index 67290f6f..4382bd80 100644
--- a/index.php
+++ b/index.php
@@ -44,6 +44,9 @@ $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
@@ -64,7 +67,6 @@ $GLOBALS['config']['CACHEDIR'] = 'cache';
64// Atom & RSS feed cache directory 67// Atom & RSS feed cache directory
65$GLOBALS['config']['PAGECACHE'] = 'pagecache'; 68$GLOBALS['config']['PAGECACHE'] = 'pagecache';
66 69
67
68/* 70/*
69 * Global configuration 71 * Global configuration
70 */ 72 */
@@ -163,6 +165,7 @@ require_once 'application/Utils.php';
163require_once 'application/Config.php'; 165require_once 'application/Config.php';
164require_once 'application/PluginManager.php'; 166require_once 'application/PluginManager.php';
165require_once 'application/Router.php'; 167require_once 'application/Router.php';
168require_once 'application/Updater.php';
166 169
167// Ensure the PHP version is supported 170// Ensure the PHP version is supported
168try { 171try {
@@ -1114,6 +1117,25 @@ function renderPage()
1114 $GLOBALS['redirector'] 1117 $GLOBALS['redirector']
1115 ); 1118 );
1116 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
1117 $PAGE = new pageBuilder; 1139 $PAGE = new pageBuilder;
1118 1140
1119 // Determine which page will be rendered. 1141 // Determine which page will be rendered.
@@ -1530,21 +1552,40 @@ function renderPage()
1530 // -------- User clicked the "Save" button when editing a link: Save link to database. 1552 // -------- User clicked the "Save" button when editing a link: Save link to database.
1531 if (isset($_POST['save_edit'])) 1553 if (isset($_POST['save_edit']))
1532 { 1554 {
1533 if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away! 1555 // Go away!
1534 $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. 1556 if (! tokenOk($_POST['token'])) {
1535 $tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates. 1557 die('Wrong token.');
1536 $linkdate=$_POST['lf_linkdate']; 1558 }
1559 // Remove multiple spaces.
1560 $tags = trim(preg_replace('/\s\s+/', ' ', $_POST['lf_tags']));
1561 // Remove duplicates.
1562 $tags = implode(' ', array_unique(explode(' ', $tags)));
1563 $linkdate = $_POST['lf_linkdate'];
1537 $url = trim($_POST['lf_url']); 1564 $url = trim($_POST['lf_url']);
1538 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:')) 1565 if (! startsWith($url, 'http:') && ! startsWith($url, 'https:')
1539 $url = 'http://'.$url; 1566 && ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:')
1540 $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0), 1567 && ! startsWith($url, '?') && ! startsWith($url, 'javascript:')
1541 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags)); 1568 ) {
1542 if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title. 1569 $url = 'http://' . $url;
1570 }
1571
1572 $link = array(
1573 'title' => trim($_POST['lf_title']),
1574 'url' => $url,
1575 'description' => trim($_POST['lf_description']),
1576 'private' => (isset($_POST['lf_private']) ? 1 : 0),
1577 'linkdate' => $linkdate,
1578 'tags' => str_replace(',', ' ', $tags)
1579 );
1580 // If title is empty, use the URL as title.
1581 if ($link['title'] == '') {
1582 $link['title'] = $link['url'];
1583 }
1543 1584
1544 $pluginManager->executeHooks('save_link', $link); 1585 $pluginManager->executeHooks('save_link', $link);
1545 1586
1546 $LINKSDB[$linkdate] = $link; 1587 $LINKSDB[$linkdate] = $link;
1547 $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk. 1588 $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']);
1548 pubsubhub(); 1589 pubsubhub();
1549 1590
1550 // If we are called from the bookmarklet, we must close the popup: 1591 // If we are called from the bookmarklet, we must close the popup:
@@ -1553,10 +1594,12 @@ function renderPage()
1553 exit; 1594 exit;
1554 } 1595 }
1555 1596
1556 $returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?'; 1597 $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?';
1557 $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); 1598 $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
1558 $location .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited. 1599 // Scroll to the link which has been edited.
1559 header('Location: '. $location); // After saving the link, redirect to the page the user was on. 1600 $location .= '#' . smallHash($_POST['lf_linkdate']);
1601 // After saving the link, redirect to the page the user was on.
1602 header('Location: '. $location);
1560 exit; 1603 exit;
1561 } 1604 }
1562 1605
@@ -2519,15 +2562,6 @@ function resizeImage($filepath)
2519 return true; 2562 return true;
2520} 2563}
2521 2564
2522try {
2523 mergeDeprecatedConfig($GLOBALS, isLoggedIn());
2524} catch(Exception $e) {
2525 error_log(
2526 'ERROR while merging deprecated options.php file.' . PHP_EOL .
2527 $e->getMessage()
2528 );
2529}
2530
2531if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. 2565if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
2532if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } 2566if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
2533if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } 2567if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }