/**
* Shaarli v0.7.0 - Shaare your links...
*
- * The personal, minimalist, super-fast, no-database Delicious clone.
+ * The personal, minimalist, super-fast, database free, bookmarking service.
*
* Friendly fork by the Shaarli community:
* - https://github.com/shaarli/Shaarli
$conf = new ConfigManager();
$conf->setEmpty('general.timezone', date_default_timezone_get());
$conf->setEmpty('general.title', 'Shared links on '. escape(index_url($_SERVER)));
-RainTPL::$tpl_dir = $conf->get('path.raintpl_tpl'); // template directory
-RainTPL::$cache_dir = $conf->get('path.raintpl_tmp'); // cache directory
+RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl'); // template directory
+RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
$pluginManager = new PluginManager($conf);
$pluginManager->load($conf->get('general.enabled_plugins'));
*/
function setup_login_state($conf)
{
- if ($conf->get('extras.open_shaarli')) {
+ if ($conf->get('security.open_shaarli')) {
return true;
}
$userIsLoggedIn = false; // By default, we do not consider the user as logged in;
if ($login == $conf->get('credentials.login') && $hash == $conf->get('credentials.hash'))
{ // Login/password is correct.
fillSessionInfo($conf);
- logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], 'Login successful');
+ logm($conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], 'Login successful');
return true;
}
- logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], 'Login failed for user '.$login);
+ logm($conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], 'Login failed for user '.$login);
return false;
}
// ------------------------------------------------------------------------------------------
// Brute force protection system
// Several consecutive failed logins will ban the IP address for 30 minutes.
-if (!is_file($conf->get('path.ban_file', 'data/ipbans.php'))) {
+if (!is_file($conf->get('resource.ban_file', 'data/ipbans.php'))) {
// FIXME! globals
file_put_contents(
- $conf->get('path.ban_file', 'data/ipbans.php'),
+ $conf->get('resource.ban_file', 'data/ipbans.php'),
"<?php\n\$GLOBALS['IPBANS']=".var_export(array('FAILURES'=>array(),'BANS'=>array()),true).";\n?>"
);
}
-include $conf->get('path.ban_file', 'data/ipbans.php');
+include $conf->get('resource.ban_file', 'data/ipbans.php');
/**
* Signal a failed login. Will ban the IP if too many failures:
*
if ($gb['FAILURES'][$ip] > ($conf->get('security.ban_after') - 1))
{
$gb['BANS'][$ip] = time() + $conf->get('security.ban_after', 1800);
- logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], 'IP address banned from login');
+ logm($conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], 'IP address banned from login');
}
$GLOBALS['IPBANS'] = $gb;
file_put_contents(
- $conf->get('path.ban_file', 'data/ipbans.php'),
+ $conf->get('resource.ban_file', 'data/ipbans.php'),
"<?php\n\$GLOBALS['IPBANS']=".var_export($gb,true).";\n?>"
);
}
unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]);
$GLOBALS['IPBANS'] = $gb;
file_put_contents(
- $conf->get('path.ban_file', 'data/ipbans.php'),
+ $conf->get('resource.ban_file', 'data/ipbans.php'),
"<?php\n\$GLOBALS['IPBANS']=".var_export($gb,true).";\n?>"
);
}
// User is banned. Check if the ban has expired:
if ($gb['BANS'][$ip]<=time())
{ // Ban expired, user can try to login again.
- logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], 'Ban lifted.');
+ logm($conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], 'Ban lifted.');
unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]);
file_put_contents(
- $conf->get('path.ban_file', 'data/ipbans.php'),
+ $conf->get('resource.ban_file', 'data/ipbans.php'),
"<?php\n\$GLOBALS['IPBANS']=".var_export($gb,true).";\n?>"
);
return true; // Ban has expired, user can login.
// If cached was not found (or not usable), then read the database and build the response:
// Read links from database (and filter private links if used it not logged in).
$LINKSDB = new LinkDB(
- $conf->get('path.datastore'),
+ $conf->get('resource.datastore'),
isLoggedIn(),
- $conf->get('extras.hide_public_links'),
- $conf->get('extras.redirector'),
- $conf->get('extras.redirector_encode_url')
+ $conf->get('privacy.hide_public_links'),
+ $conf->get('redirector.url'),
+ $conf->get('redirector.encode_url')
);
/* Some Shaarlies may have very few links, so we need to look
// We pre-format some fields for proper output.
foreach ($linkdates as $linkdate) {
$l = $LINKSDB[$linkdate];
- $l['formatedDescription'] = format_description($l['description'], $conf->get('extras.redirector'));
+ $l['formatedDescription'] = format_description($l['description'], $conf->get('redirector.url'));
$l['thumbnail'] = thumbnail($conf, $l['url']);
$l_date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $l['linkdate']);
$l['timestamp'] = $l_date->getTimestamp();
$tpl->assign('absurl', $absurl);
$tpl->assign('links', $links);
$tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS)));
- $tpl->assign('hide_timestamps', $conf->get('extras.hide_timestamps', false));
+ $tpl->assign('hide_timestamps', $conf->get('privacy.hide_timestamps', false));
$html = $tpl->draw('dailyrss', $return_string=true);
echo $html . PHP_EOL;
$taglist = explode(' ',$link['tags']);
uasort($taglist, 'strcasecmp');
$linksToDisplay[$key]['taglist']=$taglist;
- $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('extras.redirector'));
+ $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url'));
$linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']);
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
$linksToDisplay[$key]['timestamp'] = $date->getTimestamp();
function renderPage($conf, $pluginManager)
{
$LINKSDB = new LinkDB(
- $conf->get('path.datastore'),
+ $conf->get('resource.datastore'),
isLoggedIn(),
- $conf->get('extras.hide_public_links'),
- $conf->get('extras.redirector'),
- $conf->get('extras.redirector_encode_url')
+ $conf->get('privacy.hide_public_links'),
+ $conf->get('redirector.url'),
+ $conf->get('redirector.encode_url')
);
$updater = new Updater(
- read_updates_file($conf->get('path.updates')),
+ read_updates_file($conf->get('resource.updates')),
$LINKSDB,
$conf,
isLoggedIn()
$newUpdates = $updater->update();
if (! empty($newUpdates)) {
write_updates_file(
- $conf->get('path.updates'),
+ $conf->get('resource.updates'),
$updater->getDoneUpdates()
);
}
// -------- Display login form.
if ($targetPage == Router::$PAGE_LOGIN)
{
- if ($conf->get('extras.open_shaarli')) { header('Location: ?'); exit; } // No need to login for open Shaarli
+ if ($conf->get('security.open_shaarli')) { header('Location: ?'); exit; } // No need to login for open Shaarli
$token=''; if (ban_canLogin($conf)) $token=getToken($conf); // Do not waste token generation if not useful.
$PAGE->assign('token',$token);
if (isset($_GET['username'])) {
// -------- User wants to logout.
if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout'))
{
- invalidateCaches($conf->get('path.page_cache'));
+ invalidateCaches($conf->get('resource.page_cache'));
logout();
header('Location: ?');
exit;
// Cache system
$query = $_SERVER['QUERY_STRING'];
$cache = new CachedPage(
- $conf->get('path.page_cache'),
+ $conf->get('resource.page_cache'),
page_url($_SERVER),
startsWith($query,'do='. $targetPage) && !isLoggedIn()
);
// Generate data.
$feedGenerator = new FeedBuilder($LINKSDB, $feedType, $_SERVER, $_GET, isLoggedIn());
$feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0)));
- $feedGenerator->setHideDates($conf->get('extras.hide_timestamps') && !isLoggedIn());
- $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$conf->get('general.rss_permalinks'));
+ $feedGenerator->setHideDates($conf->get('privacy.hide_timestamps') && !isLoggedIn());
+ $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$conf->get('feed.rss_permalinks'));
$pshUrl = $conf->get('config.PUBSUBHUB_URL');
if (!empty($pshUrl)) {
$feedGenerator->setPubsubhubUrl($pshUrl);
// -------- User wants to change his/her password.
if ($targetPage == Router::$PAGE_CHANGEPASSWORD)
{
- if ($conf->get('extras.open_shaarli')) {
+ if ($conf->get('security.open_shaarli')) {
die('You are not supposed to change a password on an Open Shaarli.');
}
$conf->set('general.timezone', $tz);
$conf->set('general.title', escape($_POST['title']));
$conf->set('general.header_link', escape($_POST['titleLink']));
- $conf->set('extras.redirector', escape($_POST['redirector']));
+ $conf->set('redirector.url', escape($_POST['redirector']));
$conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection']));
- $conf->set('general.default_private_links', !empty($_POST['privateLinkByDefault']));
- $conf->set('general.rss_permalinks', !empty($_POST['enableRssPermalinks']));
- $conf->set('general.check_updates', !empty($_POST['updateCheck']));
- $conf->set('extras.hide_public_links', !empty($_POST['hidePublicLinks']));
+ $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault']));
+ $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks']));
+ $conf->set('updates.check_updates', !empty($_POST['updateCheck']));
+ $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks']));
try {
$conf->write(isLoggedIn());
}
{
$PAGE->assign('token',getToken($conf));
$PAGE->assign('title', $conf->get('general.title'));
- $PAGE->assign('redirector', $conf->get('extras.redirector'));
+ $PAGE->assign('redirector', $conf->get('redirector.url'));
list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone'));
$PAGE->assign('timezone_form', $timezone_form);
$PAGE->assign('timezone_js',$timezone_js);
- $PAGE->assign('private_links_default', $conf->get('general.default_private_links', false));
- $PAGE->assign('enable_rss_permalinks', $conf->get('general.rss_permalinks', false));
- $PAGE->assign('enable_update_check', $conf->get('general.check_updates', true));
- $PAGE->assign('hide_public_links', $conf->get('extras.hide_public_links', false));
+ $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false));
+ $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false));
+ $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false));
+ $PAGE->assign('enable_update_check', $conf->get('updates.check_updates', true));
+ $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false));
$PAGE->renderPage('configure');
exit;
}
$value['tags']=trim(implode(' ',$tags));
$LINKSDB[$key]=$value;
}
- $LINKSDB->savedb($conf->get('path.page_cache'));
+ $LINKSDB->savedb($conf->get('resource.page_cache'));
echo '<script>alert("Tag was removed from '.count($linksToAlter).' links.");document.location=\'?\';</script>';
exit;
}
$value['tags']=trim(implode(' ',$tags));
$LINKSDB[$key]=$value;
}
- $LINKSDB->savedb($conf->get('path.page_cache')); // Save to disk.
+ $LINKSDB->savedb($conf->get('resource.page_cache')); // Save to disk.
echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>';
exit;
}
$pluginManager->executeHooks('save_link', $link);
$LINKSDB[$linkdate] = $link;
- $LINKSDB->savedb($conf->get('path.page_cache'));
+ $LINKSDB->savedb($conf->get('resource.page_cache'));
pubsubhub($conf);
// If we are called from the bookmarklet, we must close the popup:
$pluginManager->executeHooks('delete_link', $LINKSDB[$linkdate]);
unset($LINKSDB[$linkdate]);
- $LINKSDB->savedb('path.page_cache'); // save to disk
+ $LINKSDB->savedb('resource.page_cache'); // save to disk
// If we are called from the bookmarklet, we must close the popup:
if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
}
}
}
- $LINKSDB->savedb($conf->get('path.page_cache'));
+ $LINKSDB->savedb($conf->get('resource.page_cache'));
echo '<script>alert("File '.json_encode($filename).' ('.$filesize.' bytes) was successfully processed: '.$import_count.' links imported.");document.location=\'?\';</script>';
}
$keys[] = $key;
}
- // If there is only a single link, we change on-the-fly the title of the page.
- if (count($linksToDisplay) == 1) {
- $conf->set('pagetitle', $linksToDisplay[$keys[0]]['title'] .' - '. $conf->get('general.title'));
- }
+
// Select articles according to paging.
$pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']);
while ($i<$end && $i<count($keys))
{
$link = $linksToDisplay[$keys[$i]];
- $link['description'] = format_description($link['description'], $conf->get('extras.redirector'));
+ $link['description'] = format_description($link['description'], $conf->get('redirector.url'));
$classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight';
$link['class'] = $link['private'] == 0 ? $classLi : 'private';
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
'result_count' => count($linksToDisplay),
'search_term' => $searchterm,
'search_tags' => $searchtags,
- 'redirector' => $conf->get('extras.redirector'), // Optional redirector URL.
+ 'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
'token' => $token,
'links' => $linkDisp,
'tags' => $LINKSDB->allTags(),
);
- // FIXME! temporary fix - see #399.
- if ($conf->exists('pagetitle') && count($linkDisp) == 1) {
- $data['pagetitle'] = $conf->get('pagetitle');
+
+ // If there is only a single link, we change on-the-fly the title of the page.
+ if (count($linksToDisplay) == 1) {
+ $data['pagetitle'] = $linksToDisplay[$keys[0]]['title'] .' - '. $conf->get('general.title');
}
$pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn()));
*/
function computeThumbnail($conf, $url, $href = false)
{
- if (!$conf->get('general.enable_thumbnails')) return array();
+ if (!$conf->get('thumbnail.enable_thumbnails')) return array();
if ($href==false) $href=$url;
// For most hosts, the URL of the thumbnail can be easily deduced from the URL of the link.
// So we deport the thumbnail generation in order not to slow down page generation
// (and we also cache the thumbnail)
- if (! $conf->get('general.enable_localcache')) return array(); // If local cache is disabled, no thumbnails for services which require the use a local cache.
+ if (! $conf->get('thumbnail.enable_localcache')) return array(); // If local cache is disabled, no thumbnails for services which require the use a local cache.
if ($domain=='flickr.com' || endsWith($domain,'.flickr.com')
|| $domain=='vimeo.com'
} else {
$conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER)));
}
- $conf->set('general.check_updates', !empty($_POST['updateCheck']));
+ $conf->set('updates.check_updates', !empty($_POST['updateCheck']));
try {
// Everything is ok, let's create config file.
$conf->write(isLoggedIn());
$sign = hash_hmac('sha256', $_GET['url'], $conf->get('credentials.salt'));
if ($sign!=$_GET['hmac']) die('Naughty boy!');
- $cacheDir = $conf->get('path.thumbnails_cache', 'cache');
+ $cacheDir = $conf->get('resource.thumbnails_cache', 'cache');
// Let's see if we don't already have the image for this URL in the cache.
$thumbname=hash('sha1',$_GET['url']).'.jpg';
if (is_file($cacheDir .'/'. $thumbname))