aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php205
1 files changed, 126 insertions, 79 deletions
diff --git a/index.php b/index.php
index 8e1552c1..bf0b99e0 100644
--- a/index.php
+++ b/index.php
@@ -11,7 +11,8 @@
11date_default_timezone_set('UTC'); 11date_default_timezone_set('UTC');
12 12
13// ----------------------------------------------------------------------------------------------- 13// -----------------------------------------------------------------------------------------------
14// Hardcoded parameter (These parameters can be overwritten by creating the file /data/options.php) 14// Hardcoded parameter (These parameters can be overwritten by editing the file /data/config.php)
15// You should not touch any code below (or at your own risks!)
15$GLOBALS['config']['DATADIR'] = 'data'; // Data subdirectory 16$GLOBALS['config']['DATADIR'] = 'data'; // Data subdirectory
16$GLOBALS['config']['CONFIG_FILE'] = $GLOBALS['config']['DATADIR'].'/config.php'; // Configuration file (user login/password) 17$GLOBALS['config']['CONFIG_FILE'] = $GLOBALS['config']['DATADIR'].'/config.php'; // Configuration file (user login/password)
17$GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php'; // Data storage file. 18$GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php'; // Data storage file.
@@ -36,10 +37,6 @@ $GLOBALS['config']['ARCHIVE_ORG'] = false; // For each link, add a link to an ar
36$GLOBALS['config']['ENABLE_RSS_PERMALINKS'] = true; // Enable RSS permalinks by default. This corresponds to the default behavior of shaarli before this was added as an option. 37$GLOBALS['config']['ENABLE_RSS_PERMALINKS'] = true; // Enable RSS permalinks by default. This corresponds to the default behavior of shaarli before this was added as an option.
37$GLOBALS['config']['HIDE_PUBLIC_LINKS'] = false; 38$GLOBALS['config']['HIDE_PUBLIC_LINKS'] = false;
38// ----------------------------------------------------------------------------------------------- 39// -----------------------------------------------------------------------------------------------
39// You should not touch below (or at your own risks!)
40// Optional config file.
41if (is_file($GLOBALS['config']['DATADIR'].'/options.php')) require($GLOBALS['config']['DATADIR'].'/options.php');
42
43define('shaarli_version','0.0.45beta'); 40define('shaarli_version','0.0.45beta');
44// http://server.com/x/shaarli --> /shaarli/ 41// http://server.com/x/shaarli --> /shaarli/
45define('WEB_PATH', substr($_SERVER["REQUEST_URI"], 0, 1+strrpos($_SERVER["REQUEST_URI"], '/', 0))); 42define('WEB_PATH', substr($_SERVER["REQUEST_URI"], 0, 1+strrpos($_SERVER["REQUEST_URI"], '/', 0)));
@@ -66,9 +63,15 @@ checkphpversion();
66error_reporting(E_ALL^E_WARNING); // See all error except warnings. 63error_reporting(E_ALL^E_WARNING); // See all error except warnings.
67//error_reporting(-1); // See all errors (for debugging only) 64//error_reporting(-1); // See all errors (for debugging only)
68 65
66// User configuration
67if (is_file($GLOBALS['config']['CONFIG_FILE'])) {
68 require_once $GLOBALS['config']['CONFIG_FILE'];
69}
70
69// Shaarli library 71// Shaarli library
70require_once 'application/LinkDB.php'; 72require_once 'application/LinkDB.php';
71require_once 'application/Utils.php'; 73require_once 'application/Utils.php';
74require_once 'application/Config.php';
72 75
73include "inc/rain.tpl.class.php"; //include Rain TPL 76include "inc/rain.tpl.class.php"; //include Rain TPL
74raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory 77raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory
@@ -100,15 +103,15 @@ if (empty($GLOBALS['title'])) $GLOBALS['title']='Shared links on '.escape(indexU
100if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get(); 103if (empty($GLOBALS['timezone'])) $GLOBALS['timezone']=date_default_timezone_get();
101if (empty($GLOBALS['redirector'])) $GLOBALS['redirector']=''; 104if (empty($GLOBALS['redirector'])) $GLOBALS['redirector']='';
102if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false; 105if (empty($GLOBALS['disablesessionprotection'])) $GLOBALS['disablesessionprotection']=false;
103if (empty($GLOBALS['disablejquery'])) $GLOBALS['disablejquery']=false;
104if (empty($GLOBALS['privateLinkByDefault'])) $GLOBALS['privateLinkByDefault']=false; 106if (empty($GLOBALS['privateLinkByDefault'])) $GLOBALS['privateLinkByDefault']=false;
105if (empty($GLOBALS['titleLink'])) $GLOBALS['titleLink']='?'; 107if (empty($GLOBALS['titleLink'])) $GLOBALS['titleLink']='?';
106// I really need to rewrite Shaarli with a proper configuation manager. 108// I really need to rewrite Shaarli with a proper configuation manager.
107 109
108// Run config screen if first run: 110// Run config screen if first run:
109if (!is_file($GLOBALS['config']['CONFIG_FILE'])) install(); 111if (! is_file($GLOBALS['config']['CONFIG_FILE'])) {
112 install();
113}
110 114
111require $GLOBALS['config']['CONFIG_FILE']; // Read login/password hash into $GLOBALS.
112$GLOBALS['title'] = !empty($GLOBALS['title']) ? escape($GLOBALS['title']) : ''; 115$GLOBALS['title'] = !empty($GLOBALS['title']) ? escape($GLOBALS['title']) : '';
113$GLOBALS['titleLink'] = !empty($GLOBALS['titleLink']) ? escape($GLOBALS['titleLink']) : ''; 116$GLOBALS['titleLink'] = !empty($GLOBALS['titleLink']) ? escape($GLOBALS['titleLink']) : '';
114$GLOBALS['redirector'] = !empty($GLOBALS['redirector']) ? escape($GLOBALS['redirector']) : ''; 117$GLOBALS['redirector'] = !empty($GLOBALS['redirector']) ? escape($GLOBALS['redirector']) : '';
@@ -856,15 +859,18 @@ function showATOM()
856// Daily RSS feed: 1 RSS entry per day giving all the links on that day. 859// Daily RSS feed: 1 RSS entry per day giving all the links on that day.
857// Gives the last 7 days (which have links). 860// Gives the last 7 days (which have links).
858// This RSS feed cannot be filtered. 861// This RSS feed cannot be filtered.
859function showDailyRSS() 862function showDailyRSS() {
860{
861 // Cache system 863 // Cache system
862 $query = $_SERVER["QUERY_STRING"]; 864 $query = $_SERVER["QUERY_STRING"];
863 $cache = new pageCache(pageUrl(),startsWith($query,'do=dailyrss') && !isLoggedIn()); 865 $cache = new pageCache(pageUrl(), startsWith($query, 'do=dailyrss') && !isLoggedIn());
864 $cached = $cache->cachedVersion(); if (!empty($cached)) { echo $cached; exit; } 866 $cached = $cache->cachedVersion();
865 // If cached was not found (or not usable), then read the database and build the response: 867 if (!empty($cached)) {
868 echo $cached;
869 exit;
870 }
866 871
867// Read links from database (and filter private links if used it not logged in). 872 // If cached was not found (or not usable), then read the database and build the response:
873 // Read links from database (and filter private links if used it not logged in).
868 $LINKSDB = new LinkDB( 874 $LINKSDB = new LinkDB(
869 $GLOBALS['config']['DATASTORE'], 875 $GLOBALS['config']['DATASTORE'],
870 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'], 876 isLoggedIn() || $GLOBALS['config']['OPEN_SHAARLI'],
@@ -874,60 +880,75 @@ function showDailyRSS()
874 /* Some Shaarlies may have very few links, so we need to look 880 /* Some Shaarlies may have very few links, so we need to look
875 back in time (rsort()) until we have enough days ($nb_of_days). 881 back in time (rsort()) until we have enough days ($nb_of_days).
876 */ 882 */
877 $linkdates=array(); foreach($LINKSDB as $linkdate=>$value) { $linkdates[]=$linkdate; } 883 $linkdates = array();
884 foreach ($LINKSDB as $linkdate => $value) {
885 $linkdates[] = $linkdate;
886 }
878 rsort($linkdates); 887 rsort($linkdates);
879 $nb_of_days=7; // We take 7 days. 888 $nb_of_days = 7; // We take 7 days.
880 $today=Date('Ymd'); 889 $today = Date('Ymd');
881 $days=array(); 890 $days = array();
882 foreach($linkdates as $linkdate) 891
883 { 892 foreach ($linkdates as $linkdate) {
884 $day=substr($linkdate,0,8); // Extract day (without time) 893 $day = substr($linkdate, 0, 8); // Extract day (without time)
885 if (strcmp($day,$today)<0) 894 if (strcmp($day,$today) < 0) {
886 { 895 if (empty($days[$day])) {
887 if (empty($days[$day])) $days[$day]=array(); 896 $days[$day] = array();
888 $days[$day][]=$linkdate; 897 }
898 $days[$day][] = $linkdate;
899 }
900
901 if (count($days) > $nb_of_days) {
902 break; // Have we collected enough days?
889 } 903 }
890 if (count($days)>$nb_of_days) break; // Have we collected enough days?
891 } 904 }
892 905
893 // Build the RSS feed. 906 // Build the RSS feed.
894 header('Content-Type: application/rss+xml; charset=utf-8'); 907 header('Content-Type: application/rss+xml; charset=utf-8');
895 $pageaddr=escape(indexUrl()); 908 $pageaddr = escape(indexUrl());
896 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">'; 909 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
897 echo '<channel><title>Daily - '.$GLOBALS['title'].'</title><link>'.$pageaddr.'</link>'; 910 echo '<channel>';
898 echo '<description>Daily shared links</description><language>en-en</language><copyright>'.$pageaddr.'</copyright>'."\n"; 911 echo '<title>Daily - '. $GLOBALS['title'] . '</title>';
899 912 echo '<link>'. $pageaddr .'</link>';
900 foreach($days as $day=>$linkdates) // For each day. 913 echo '<description>Daily shared links</description>';
901 { 914 echo '<language>en-en</language>';
902 $daydate = utf8_encode(strftime('%A %d, %B %Y',linkdate2timestamp($day.'_000000'))); // Full text date 915 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
916
917 // For each day.
918 foreach ($days as $day => $linkdates) {
919 $daydate = linkdate2timestamp($day.'_000000'); // Full text date
903 $rfc822date = linkdate2rfc822($day.'_000000'); 920 $rfc822date = linkdate2rfc822($day.'_000000');
904 $absurl=escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 921 $absurl = escape(indexUrl().'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
905 echo '<item><title>'.$GLOBALS['title'].' - '.$daydate.'</title><guid>'.$absurl.'</guid><link>'.$absurl.'</link>';
906 echo '<pubDate>'.escape($rfc822date)."</pubDate>";
907 922
908 // Build the HTML body of this RSS entry. 923 // Build the HTML body of this RSS entry.
909 $html=''; 924 $html = '';
910 $href=''; 925 $href = '';
911 $links=array(); 926 $links = array();
927
912 // We pre-format some fields for proper output. 928 // We pre-format some fields for proper output.
913 foreach($linkdates as $linkdate) 929 foreach ($linkdates as $linkdate) {
914 {
915 $l = $LINKSDB[$linkdate]; 930 $l = $LINKSDB[$linkdate];
916 $l['formatedDescription']=nl2br(keepMultipleSpaces(text2clickable($l['description']))); 931 $l['formatedDescription'] = nl2br(keepMultipleSpaces(text2clickable($l['description'])));
917 $l['thumbnail'] = thumbnail($l['url']); 932 $l['thumbnail'] = thumbnail($l['url']);
918 $l['timestamp'] = linkdate2timestamp($l['linkdate']); 933 $l['timestamp'] = linkdate2timestamp($l['linkdate']);
919 if (startsWith($l['url'],'?')) $l['url']=indexUrl().$l['url']; // make permalink URL absolute 934 if (startsWith($l['url'], '?')) {
920 $links[$linkdate]=$l; 935 $l['url'] = indexUrl() . $l['url']; // make permalink URL absolute
936 }
937 $links[$linkdate] = $l;
921 } 938 }
939
922 // Then build the HTML for this day: 940 // Then build the HTML for this day:
923 $tpl = new RainTPL; 941 $tpl = new RainTPL;
924 $tpl->assign('links',$links); 942 $tpl->assign('title', $GLOBALS['title']);
925 $html = $tpl->draw('dailyrss',$return_string=true); 943 $tpl->assign('daydate', $daydate);
926 echo "\n"; 944 $tpl->assign('absurl', $absurl);
927 echo '<description><![CDATA['.$html.']]></description>'."\n</item>\n\n"; 945 $tpl->assign('links', $links);
946 $tpl->assign('rfc822date', escape($rfc822date));
947 $html = $tpl->draw('dailyrss', $return_string=true);
928 948
949 echo $html . PHP_EOL;
929 } 950 }
930 echo '</channel></rss><!-- Cached version of '.escape(pageUrl()).' -->'; 951 echo '</channel></rss><!-- Cached version of '. escape(pageUrl()) .' -->';
931 952
932 $cache->cache(ob_get_contents()); 953 $cache->cache(ob_get_contents());
933 ob_end_flush(); 954 ob_end_flush();
@@ -1106,7 +1127,11 @@ function renderPage()
1106 1127
1107 // Check if this tag is already in the search query and ignore it if it is. 1128 // Check if this tag is already in the search query and ignore it if it is.
1108 // Each tag is always separated by a space 1129 // Each tag is always separated by a space
1109 $current_tags = explode(' ', $params['searchtags']); 1130 if (isset($params['searchtags'])) {
1131 $current_tags = explode(' ', $params['searchtags']);
1132 } else {
1133 $current_tags = array();
1134 }
1110 $addtag = true; 1135 $addtag = true;
1111 foreach ($current_tags as $value) { 1136 foreach ($current_tags as $value) {
1112 if ($value === $_GET['addtag']) { 1137 if ($value === $_GET['addtag']) {
@@ -1229,7 +1254,19 @@ function renderPage()
1229 // Save new password 1254 // Save new password
1230 $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless. 1255 $GLOBALS['salt'] = sha1(uniqid('',true).'_'.mt_rand()); // Salt renders rainbow-tables attacks useless.
1231 $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); 1256 $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']);
1232 writeConfig(); 1257 try {
1258 writeConfig($GLOBALS, isLoggedIn());
1259 }
1260 catch(Exception $e) {
1261 error_log(
1262 'ERROR while writing config file after changing password.' . PHP_EOL .
1263 $e->getMessage()
1264 );
1265
1266 // TODO: do not handle exceptions/errors in JS.
1267 echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do=tools\';</script>';
1268 exit;
1269 }
1233 echo '<script>alert("Your password has been changed.");document.location=\'?do=tools\';</script>'; 1270 echo '<script>alert("Your password has been changed.");document.location=\'?do=tools\';</script>';
1234 exit; 1271 exit;
1235 } 1272 }
@@ -1258,12 +1295,23 @@ function renderPage()
1258 $GLOBALS['titleLink']=$_POST['titleLink']; 1295 $GLOBALS['titleLink']=$_POST['titleLink'];
1259 $GLOBALS['redirector']=$_POST['redirector']; 1296 $GLOBALS['redirector']=$_POST['redirector'];
1260 $GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']); 1297 $GLOBALS['disablesessionprotection']=!empty($_POST['disablesessionprotection']);
1261 $GLOBALS['disablejquery']=!empty($_POST['disablejquery']);
1262 $GLOBALS['privateLinkByDefault']=!empty($_POST['privateLinkByDefault']); 1298 $GLOBALS['privateLinkByDefault']=!empty($_POST['privateLinkByDefault']);
1263 $GLOBALS['config']['ENABLE_RSS_PERMALINKS']= !empty($_POST['enableRssPermalinks']); 1299 $GLOBALS['config']['ENABLE_RSS_PERMALINKS']= !empty($_POST['enableRssPermalinks']);
1264 $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']); 1300 $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']);
1265 $GLOBALS['config']['HIDE_PUBLIC_LINKS'] = !empty($_POST['hidePublicLinks']); 1301 $GLOBALS['config']['HIDE_PUBLIC_LINKS'] = !empty($_POST['hidePublicLinks']);
1266 writeConfig(); 1302 try {
1303 writeConfig($GLOBALS, isLoggedIn());
1304 }
1305 catch(Exception $e) {
1306 error_log(
1307 'ERROR while writing config file after configuration update.' . PHP_EOL .
1308 $e->getMessage()
1309 );
1310
1311 // TODO: do not handle exceptions/errors in JS.
1312 echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do=tools\';</script>';
1313 exit;
1314 }
1267 echo '<script>alert("Configuration was saved.");document.location=\'?do=tools\';</script>'; 1315 echo '<script>alert("Configuration was saved.");document.location=\'?do=tools\';</script>';
1268 exit; 1316 exit;
1269 } 1317 }
@@ -1345,6 +1393,7 @@ function renderPage()
1345 { 1393 {
1346 if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away! 1394 if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away!
1347 $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces. 1395 $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces.
1396 $tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates.
1348 $linkdate=$_POST['lf_linkdate']; 1397 $linkdate=$_POST['lf_linkdate'];
1349 $url = trim($_POST['lf_url']); 1398 $url = trim($_POST['lf_url']);
1350 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:')) 1399 if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:'))
@@ -1714,7 +1763,7 @@ function buildLinkList($PAGE,$LINKSDB)
1714 { 1763 {
1715 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 1764 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1716 echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.'; 1765 echo '<h1>404 Not found.</h1>Oh crap. The link you are trying to reach does not exist or has been deleted.';
1717 echo '<br>You would mind <a href="?">clicking here</a>?'; 1766 echo '<br>Would you mind <a href="?">clicking here</a>?';
1718 exit; 1767 exit;
1719 } 1768 }
1720 $search_type='permalink'; 1769 $search_type='permalink';
@@ -2020,7 +2069,19 @@ function install()
2020 $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']); 2069 $GLOBALS['hash'] = sha1($_POST['setpassword'].$GLOBALS['login'].$GLOBALS['salt']);
2021 $GLOBALS['title'] = (empty($_POST['title']) ? 'Shared links on '.escape(indexUrl()) : $_POST['title'] ); 2070 $GLOBALS['title'] = (empty($_POST['title']) ? 'Shared links on '.escape(indexUrl()) : $_POST['title'] );
2022 $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']); 2071 $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']);
2023 writeConfig(); 2072 try {
2073 writeConfig($GLOBALS, isLoggedIn());
2074 }
2075 catch(Exception $e) {
2076 error_log(
2077 'ERROR while writing config file after installation.' . PHP_EOL .
2078 $e->getMessage()
2079 );
2080
2081 // TODO: do not handle exceptions/errors in JS.
2082 echo '<script>alert("'. $e->getMessage() .'");document.location=\'?\';</script>';
2083 exit;
2084 }
2024 echo '<script>alert("Shaarli is now configured. Please enter your login/password and start shaaring your links!");document.location=\'?do=login\';</script>'; 2085 echo '<script>alert("Shaarli is now configured. Please enter your login/password and start shaaring your links!");document.location=\'?do=login\';</script>';
2025 exit; 2086 exit;
2026 } 2087 }
@@ -2134,30 +2195,7 @@ if (!function_exists('json_encode')) {
2134 } 2195 }
2135} 2196}
2136 2197
2137// Re-write configuration file according to globals. 2198
2138// Requires some $GLOBALS to be set (login,hash,salt,title).
2139// If the config file cannot be saved, an error message is displayed and the user is redirected to "Tools" menu.
2140// (otherwise, the function simply returns.)
2141function writeConfig()
2142{
2143 if (is_file($GLOBALS['config']['CONFIG_FILE']) && !isLoggedIn()) die('You are not authorized to alter config.'); // Only logged in user can alter config.
2144 $config='<?php $GLOBALS[\'login\']='.var_export($GLOBALS['login'],true).'; $GLOBALS[\'hash\']='.var_export($GLOBALS['hash'],true).'; $GLOBALS[\'salt\']='.var_export($GLOBALS['salt'],true).'; ';
2145 $config .='$GLOBALS[\'timezone\']='.var_export($GLOBALS['timezone'],true).'; date_default_timezone_set('.var_export($GLOBALS['timezone'],true).'); $GLOBALS[\'title\']='.var_export($GLOBALS['title'],true).';';
2146 $config .= '$GLOBALS[\'titleLink\']='.var_export($GLOBALS['titleLink'],true).'; ';
2147 $config .= '$GLOBALS[\'redirector\']='.var_export($GLOBALS['redirector'],true).'; ';
2148 $config .= '$GLOBALS[\'disablesessionprotection\']='.var_export($GLOBALS['disablesessionprotection'],true).'; ';
2149 $config .= '$GLOBALS[\'disablejquery\']='.var_export($GLOBALS['disablejquery'],true).'; ';
2150 $config .= '$GLOBALS[\'privateLinkByDefault\']='.var_export($GLOBALS['privateLinkByDefault'],true).'; ';
2151 $config .= '$GLOBALS[\'config\'][\'ENABLE_RSS_PERMALINKS\']='.var_export($GLOBALS['config']['ENABLE_RSS_PERMALINKS'], true).'; ';
2152 $config .= '$GLOBALS[\'config\'][\'ENABLE_UPDATECHECK\']='.var_export($GLOBALS['config']['ENABLE_UPDATECHECK'], true).'; ';
2153 $config .= '$GLOBALS[\'config\'][\'HIDE_PUBLIC_LINKS\']='.var_export($GLOBALS['config']['HIDE_PUBLIC_LINKS'], true).'; ';
2154 $config .= ' ?>';
2155 if (!file_put_contents($GLOBALS['config']['CONFIG_FILE'],$config) || strcmp(file_get_contents($GLOBALS['config']['CONFIG_FILE']),$config)!=0)
2156 {
2157 echo '<script>alert("Shaarli could not create the config file. Please make sure Shaarli has the right to write in the folder is it installed in.");document.location=\'?\';</script>';
2158 exit;
2159 }
2160}
2161 2199
2162/* Because some f*cking services like flickr require an extra HTTP request to get the thumbnail URL, 2200/* Because some f*cking services like flickr require an extra HTTP request to get the thumbnail URL,
2163 I have deported the thumbnail URL code generation here, otherwise this would slow down page generation. 2201 I have deported the thumbnail URL code generation here, otherwise this would slow down page generation.
@@ -2386,6 +2424,15 @@ function invalidateCaches()
2386 pageCache::purgeCache(); // Purge page cache shared by sessions. 2424 pageCache::purgeCache(); // Purge page cache shared by sessions.
2387} 2425}
2388 2426
2427try {
2428 mergeDeprecatedConfig($GLOBALS, isLoggedIn());
2429} catch(Exception $e) {
2430 error_log(
2431 'ERROR while merging deprecated options.php file.' . PHP_EOL .
2432 $e->getMessage()
2433 );
2434}
2435
2389if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. 2436if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database.
2390if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } 2437if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
2391if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } 2438if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }