aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php91
1 files changed, 48 insertions, 43 deletions
diff --git a/index.php b/index.php
index 6eaa56c2..02fe2577 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';
@@ -473,34 +474,6 @@ if (isset($_POST['login']))
473} 474}
474 475
475// ------------------------------------------------------------------------------------------ 476// ------------------------------------------------------------------------------------------
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 477// Token management for XSRF protection
505// Token should be used in any form which acts on data (create,update,delete,import...). 478// 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. 479if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session.
@@ -755,6 +728,12 @@ function renderPage($conf, $pluginManager, $LINKSDB)
755 die($e->getMessage()); 728 die($e->getMessage());
756 } 729 }
757 730
731 try {
732 $history = new History($conf->get('resource.history'));
733 } catch(Exception $e) {
734 die($e->getMessage());
735 }
736
758 $PAGE = new PageBuilder($conf); 737 $PAGE = new PageBuilder($conf);
759 $PAGE->assign('linkcount', count($LINKSDB)); 738 $PAGE->assign('linkcount', count($LINKSDB));
760 $PAGE->assign('privateLinkcount', count_private($LINKSDB)); 739 $PAGE->assign('privateLinkcount', count_private($LINKSDB));
@@ -1153,6 +1132,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1153 $conf->set('api.secret', escape($_POST['apiSecret'])); 1132 $conf->set('api.secret', escape($_POST['apiSecret']));
1154 try { 1133 try {
1155 $conf->write(isLoggedIn()); 1134 $conf->write(isLoggedIn());
1135 $history->updateSettings();
1156 invalidateCaches($conf->get('resource.page_cache')); 1136 invalidateCaches($conf->get('resource.page_cache'));
1157 } 1137 }
1158 catch(Exception $e) { 1138 catch(Exception $e) {
@@ -1174,9 +1154,12 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1174 $PAGE->assign('theme', $conf->get('resource.theme')); 1154 $PAGE->assign('theme', $conf->get('resource.theme'));
1175 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl'))); 1155 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl')));
1176 $PAGE->assign('redirector', $conf->get('redirector.url')); 1156 $PAGE->assign('redirector', $conf->get('redirector.url'));
1177 list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); 1157 list($continents, $cities) = generateTimeZoneData(
1178 $PAGE->assign('timezone_form', $timezone_form); 1158 timezone_identifiers_list(),
1179 $PAGE->assign('timezone_js',$timezone_js); 1159 $conf->get('general.timezone')
1160 );
1161 $PAGE->assign('continents', $continents);
1162 $PAGE->assign('cities', $cities);
1180 $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false)); 1163 $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false));
1181 $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false)); 1164 $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false));
1182 $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); 1165 $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false));
@@ -1184,6 +1167,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1184 $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false)); 1167 $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false));
1185 $PAGE->assign('api_enabled', $conf->get('api.enabled', true)); 1168 $PAGE->assign('api_enabled', $conf->get('api.enabled', true));
1186 $PAGE->assign('api_secret', $conf->get('api.secret')); 1169 $PAGE->assign('api_secret', $conf->get('api.secret'));
1170 $history->updateSettings();
1187 $PAGE->renderPage('configure'); 1171 $PAGE->renderPage('configure');
1188 exit; 1172 exit;
1189 } 1173 }
@@ -1213,6 +1197,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1213 unset($tags[array_search($needle,$tags)]); // Remove tag. 1197 unset($tags[array_search($needle,$tags)]); // Remove tag.
1214 $value['tags']=trim(implode(' ',$tags)); 1198 $value['tags']=trim(implode(' ',$tags));
1215 $LINKSDB[$key]=$value; 1199 $LINKSDB[$key]=$value;
1200 $history->updateLink($LINKSDB[$key]);
1216 } 1201 }
1217 $LINKSDB->save($conf->get('resource.page_cache')); 1202 $LINKSDB->save($conf->get('resource.page_cache'));
1218 echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>'; 1203 echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?do=changetag\';</script>';
@@ -1230,6 +1215,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1230 $tags[array_search($needle, $tags)] = trim($_POST['totag']); 1215 $tags[array_search($needle, $tags)] = trim($_POST['totag']);
1231 $value['tags'] = implode(' ', array_unique($tags)); 1216 $value['tags'] = implode(' ', array_unique($tags));
1232 $LINKSDB[$key] = $value; 1217 $LINKSDB[$key] = $value;
1218 $history->updateLink($LINKSDB[$key]);
1233 } 1219 }
1234 $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk. 1220 $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
1235 echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>'; 1221 echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>';
@@ -1264,11 +1250,13 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1264 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1250 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1265 $updated = new DateTime(); 1251 $updated = new DateTime();
1266 $shortUrl = $LINKSDB[$id]['shorturl']; 1252 $shortUrl = $LINKSDB[$id]['shorturl'];
1253 $new = false;
1267 } else { 1254 } else {
1268 // New link 1255 // New link
1269 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate); 1256 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1270 $updated = null; 1257 $updated = null;
1271 $shortUrl = link_small_hash($created, $id); 1258 $shortUrl = link_small_hash($created, $id);
1259 $new = true;
1272 } 1260 }
1273 1261
1274 // Remove multiple spaces. 1262 // Remove multiple spaces.
@@ -1307,6 +1295,11 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1307 1295
1308 $LINKSDB[$id] = $link; 1296 $LINKSDB[$id] = $link;
1309 $LINKSDB->save($conf->get('resource.page_cache')); 1297 $LINKSDB->save($conf->get('resource.page_cache'));
1298 if ($new) {
1299 $history->addLink($link);
1300 } else {
1301 $history->updateLink($link);
1302 }
1310 1303
1311 // If we are called from the bookmarklet, we must close the popup: 1304 // If we are called from the bookmarklet, we must close the popup:
1312 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { 1305 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
@@ -1357,6 +1350,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1357 $pluginManager->executeHooks('delete_link', $link); 1350 $pluginManager->executeHooks('delete_link', $link);
1358 unset($LINKSDB[$id]); 1351 unset($LINKSDB[$id]);
1359 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk 1352 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1353 $history->deleteLink($link);
1360 1354
1361 // If we are called from the bookmarklet, we must close the popup: 1355 // If we are called from the bookmarklet, we must close the popup:
1362 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } 1356 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
@@ -1517,7 +1511,22 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1517 1511
1518 if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { 1512 if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) {
1519 // Show import dialog 1513 // Show import dialog
1520 $PAGE->assign('maxfilesize', getMaxFileSize()); 1514 $PAGE->assign(
1515 'maxfilesize',
1516 get_max_upload_size(
1517 ini_get('post_max_size'),
1518 ini_get('upload_max_filesize'),
1519 false
1520 )
1521 );
1522 $PAGE->assign(
1523 'maxfilesizeHuman',
1524 get_max_upload_size(
1525 ini_get('post_max_size'),
1526 ini_get('upload_max_filesize'),
1527 true
1528 )
1529 );
1521 $PAGE->renderPage('import'); 1530 $PAGE->renderPage('import');
1522 exit; 1531 exit;
1523 } 1532 }
@@ -1527,7 +1536,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1527 // The file is too big or some form field may be missing. 1536 // The file is too big or some form field may be missing.
1528 echo '<script>alert("The file you are trying to upload is probably' 1537 echo '<script>alert("The file you are trying to upload is probably'
1529 .' bigger than what this webserver can accept (' 1538 .' bigger than what this webserver can accept ('
1530 .getMaxFileSize().' bytes).' 1539 .get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize')).').'
1531 .' Please upload in smaller chunks.");document.location=\'?do=' 1540 .' Please upload in smaller chunks.");document.location=\'?do='
1532 .Router::$PAGE_IMPORT .'\';</script>'; 1541 .Router::$PAGE_IMPORT .'\';</script>';
1533 exit; 1542 exit;
@@ -1539,7 +1548,8 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1539 $_POST, 1548 $_POST,
1540 $_FILES, 1549 $_FILES,
1541 $LINKSDB, 1550 $LINKSDB,
1542 $conf 1551 $conf,
1552 $history
1543 ); 1553 );
1544 echo '<script>alert("'.$status.'");document.location=\'?do=' 1554 echo '<script>alert("'.$status.'");document.location=\'?do='
1545 .Router::$PAGE_IMPORT .'\';</script>'; 1555 .Router::$PAGE_IMPORT .'\';</script>';
@@ -1568,6 +1578,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1568 1578
1569 // Plugin administration form action 1579 // Plugin administration form action
1570 if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) { 1580 if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) {
1581 $history->updateSettings();
1571 try { 1582 try {
1572 if (isset($_POST['parameters_form'])) { 1583 if (isset($_POST['parameters_form'])) {
1573 unset($_POST['parameters_form']); 1584 unset($_POST['parameters_form']);
@@ -1982,16 +1993,10 @@ function install($conf)
1982 exit; 1993 exit;
1983 } 1994 }
1984 1995
1985 // Display config form:
1986 list($timezone_form, $timezone_js) = generateTimeZoneForm();
1987 $timezone_html = '';
1988 if ($timezone_form != '') {
1989 $timezone_html = '<tr><td><b>Timezone:</b></td><td>'.$timezone_form.'</td></tr>';
1990 }
1991
1992 $PAGE = new PageBuilder($conf); 1996 $PAGE = new PageBuilder($conf);
1993 $PAGE->assign('timezone_html',$timezone_html); 1997 list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get());
1994 $PAGE->assign('timezone_js',$timezone_js); 1998 $PAGE->assign('continents', $continents);
1999 $PAGE->assign('cities', $cities);
1995 $PAGE->renderPage('install'); 2000 $PAGE->renderPage('install');
1996 exit; 2001 exit;
1997} 2002}