X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=3a63319c63027fd3873896f9b1a3f12d9a5bd26a;hb=522b278b03280ed809025ebbeb3eac284b68bf81;hp=82a6abb343bee4a65ca6b0a8e015365fa66cc170;hpb=5a23950c953e3c8e232cdb69607f91d3e2fac5f5;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 82a6abb3..3a63319c 100644 --- a/index.php +++ b/index.php @@ -44,12 +44,18 @@ $GLOBALS['config']['DATASTORE'] = $GLOBALS['config']['DATADIR'].'/datastore.php' // Banned IPs $GLOBALS['config']['IPBANS_FILENAME'] = $GLOBALS['config']['DATADIR'].'/ipbans.php'; +// Processed updates file. +$GLOBALS['config']['UPDATES_FILE'] = $GLOBALS['config']['DATADIR'].'/updates.txt'; + // Access log $GLOBALS['config']['LOG_FILE'] = $GLOBALS['config']['DATADIR'].'/log.txt'; // For updates check of Shaarli $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; +// Set ENABLE_UPDATECHECK to disabled by default. +$GLOBALS['config']['ENABLE_UPDATECHECK'] = false; + // RainTPL cache directory (keep the trailing slash!) $GLOBALS['config']['RAINTPL_TMP'] = 'tmp/'; // Raintpl template directory (keep the trailing slash!) @@ -61,7 +67,6 @@ $GLOBALS['config']['CACHEDIR'] = 'cache'; // Atom & RSS feed cache directory $GLOBALS['config']['PAGECACHE'] = 'pagecache'; - /* * Global configuration */ @@ -111,7 +116,8 @@ $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400; //); $GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode'); -//$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/'; +// Initialize plugin parameters array. +$GLOBALS['plugins'] = array(); // PubSubHubbub support. Put an empty string to disable, or put your hub url here to enable. $GLOBALS['config']['PUBSUBHUB_URL'] = ''; @@ -159,6 +165,7 @@ require_once 'application/Utils.php'; require_once 'application/Config.php'; require_once 'application/PluginManager.php'; require_once 'application/Router.php'; +require_once 'application/Updater.php'; // Ensure the PHP version is supported try { @@ -1110,6 +1117,25 @@ function renderPage() $GLOBALS['redirector'] ); + $updater = new Updater( + read_updates_file($GLOBALS['config']['UPDATES_FILE']), + $GLOBALS, + $LINKSDB, + isLoggedIn() + ); + try { + $newUpdates = $updater->update(); + if (! empty($newUpdates)) { + write_updates_file( + $GLOBALS['config']['UPDATES_FILE'], + $updater->getDoneUpdates() + ); + } + } + catch(Exception $e) { + die($e->getMessage()); + } + $PAGE = new pageBuilder; // Determine which page will be rendered. @@ -1119,9 +1145,9 @@ function renderPage() // Call plugin hooks for header, footer and includes, specifying which page will be rendered. // Then assign generated data to RainTPL. $common_hooks = array( + 'includes', 'header', 'footer', - 'includes', ); $pluginManager = PluginManager::getInstance(); foreach($common_hooks as $name) { @@ -1203,11 +1229,25 @@ function renderPage() // We sort tags alphabetically, then choose a font size according to count. // First, find max value. - $maxcount=0; foreach($tags as $key=>$value) $maxcount=max($maxcount,$value); - ksort($tags); + $maxcount = 0; + foreach ($tags as $value) { + $maxcount = max($maxcount, $value); + } + + // Sort tags alphabetically: case insensitive, support locale if avalaible. + uksort($tags, function($a, $b) { + // Collator is part of PHP intl. + if (class_exists('Collator')) { + $c = new Collator(setlocale(LC_ALL, 0)); + return $c->compare($a, $b); + } else { + return strcasecmp($a, $b); + } + }); + $tagList=array(); foreach($tags as $key=>$value) - // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. + // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. { $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); } @@ -1532,6 +1572,8 @@ function renderPage() } // Remove multiple spaces. $tags = trim(preg_replace('/\s\s+/', ' ', $_POST['lf_tags'])); + // Remove first '-' char in tags. + $tags = preg_replace('/(^| )\-/', '$1', $tags); // Remove duplicates. $tags = implode(' ', array_unique(explode(' ', $tags))); $linkdate = $_POST['lf_linkdate']; @@ -1568,7 +1610,7 @@ function renderPage() exit; } - $returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?'; + $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?'; $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); // Scroll to the link which has been edited. $location .= '#' . smallHash($_POST['lf_linkdate']); @@ -1832,7 +1874,7 @@ HTML; ); // TODO: do not handle exceptions/errors in JS. - echo ''; + echo ''; exit; } header('Location: ?do='. Router::$PAGE_PLUGINSADMIN); @@ -2536,15 +2578,6 @@ function resizeImage($filepath) return true; } -try { - mergeDeprecatedConfig($GLOBALS, isLoggedIn()); -} catch(Exception $e) { - error_log( - 'ERROR while merging deprecated options.php file.' . PHP_EOL . - $e->getMessage() - ); -} - if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=genthumbnail')) { genThumbnail(); exit; } // Thumbnail generation/cache does not need the link database. if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } if (isset($_SERVER["QUERY_STRING"]) && startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }