// 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!)
//);
$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'] = '';
// a token depending of deployment salt, user password, and the current ip
define('STAY_SIGNED_IN_TOKEN', sha1($GLOBALS['hash'].$_SERVER["REMOTE_ADDR"].$GLOBALS['salt']));
-autoLocale(); // Sniff browser language and set date format accordingly.
+autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); // Sniff browser language and set date format accordingly.
header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling.
//==================================================================================================
}
$userIsLoggedIn = setup_login_state();
-
-// ------------------------------------------------------------------------------------------
-// Sniff browser language to display dates in the right format automatically.
-// (Note that is may not work on your server if the corresponding local is not installed.)
-function autoLocale()
-{
- $attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE
- if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
- { // (It's a bit crude, but it works very well. Preferred language is always presented first.)
- if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) {
- $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
- $attempts = array($loc.'.UTF-8', $loc, str_replace('_', '-', $loc).'.UTF-8', str_replace('_', '-', $loc),
- $loc . '_' . strtoupper($loc).'.UTF-8', $loc . '_' . strtoupper($loc),
- $loc . '_' . $loc.'.UTF-8', $loc . '_' . $loc, $loc . '-' . strtoupper($loc).'.UTF-8',
- $loc . '-' . strtoupper($loc), $loc . '-' . $loc.'.UTF-8', $loc . '-' . $loc);
- }
- }
- setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only.
-}
-
// ------------------------------------------------------------------------------------------
// PubSubHubbub protocol support (if enabled) [UNTESTED]
// (Source: http://aldarone.fr/les-flux-rss-shaarli-et-pubsubhubbub/ )
// 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) {
// 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);
}
// -------- User clicked the "Save" button when editing a link: Save link to database.
if (isset($_POST['save_edit']))
{
- if (!tokenOk($_POST['token'])) die('Wrong token.'); // Go away!
- $tags = trim(preg_replace('/\s\s+/',' ', $_POST['lf_tags'])); // Remove multiple spaces.
- $tags = implode(' ', array_unique(explode(' ', $tags))); // Remove duplicates.
- $linkdate=$_POST['lf_linkdate'];
+ // Go away!
+ if (! tokenOk($_POST['token'])) {
+ die('Wrong token.');
+ }
+ // 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'];
$url = trim($_POST['lf_url']);
- if (!startsWith($url,'http:') && !startsWith($url,'https:') && !startsWith($url,'ftp:') && !startsWith($url,'magnet:') && !startsWith($url,'?') && !startsWith($url,'javascript:'))
- $url = 'http://'.$url;
- $link = array('title'=>trim($_POST['lf_title']),'url'=>$url,'description'=>trim($_POST['lf_description']),'private'=>(isset($_POST['lf_private']) ? 1 : 0),
- 'linkdate'=>$linkdate,'tags'=>str_replace(',',' ',$tags));
- if ($link['title']=='') $link['title']=$link['url']; // If title is empty, use the URL as title.
+ if (! startsWith($url, 'http:') && ! startsWith($url, 'https:')
+ && ! startsWith($url, 'ftp:') && ! startsWith($url, 'magnet:')
+ && ! startsWith($url, '?') && ! startsWith($url, 'javascript:')
+ ) {
+ $url = 'http://' . $url;
+ }
+
+ $link = array(
+ 'title' => trim($_POST['lf_title']),
+ 'url' => $url,
+ 'description' => trim($_POST['lf_description']),
+ 'private' => (isset($_POST['lf_private']) ? 1 : 0),
+ 'linkdate' => $linkdate,
+ 'tags' => str_replace(',', ' ', $tags)
+ );
+ // If title is empty, use the URL as title.
+ if ($link['title'] == '') {
+ $link['title'] = $link['url'];
+ }
$pluginManager->executeHooks('save_link', $link);
$LINKSDB[$linkdate] = $link;
- $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']); // Save to disk.
+ $LINKSDB->savedb($GLOBALS['config']['PAGECACHE']);
pubsubhub();
// If we are called from the bookmarklet, we must close the popup:
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'));
- $location .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited.
- header('Location: '. $location); // After saving the link, redirect to the page the user was on.
+ // Scroll to the link which has been edited.
+ $location .= '#' . smallHash($_POST['lf_linkdate']);
+ // After saving the link, redirect to the page the user was on.
+ header('Location: '. $location);
exit;
}
);
// TODO: do not handle exceptions/errors in JS.
- echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do=pluginsadmin\';</script>';
+ echo '<script>alert("'. $e->getMessage() .'");document.location=\'?do='. Router::$PAGE_PLUGINSADMIN .'\';</script>';
exit;
}
header('Location: ?do='. Router::$PAGE_PLUGINSADMIN);