X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=84282b8dc6c6ecc41dd67cae0eae0e9c3fdf883a;hb=f5f6a4b7e21f39c916fda11eebb1c8df17e1ad4a;hp=1f148d781e225cd402fa6454aeceb849bf4febf4;hpb=e0dd77c37e433d71462f87c8e8c75196aa958940;p=github%2Fshaarli%2FShaarli.git
diff --git a/index.php b/index.php
index 1f148d78..84282b8d 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
/shaarli/
define('WEB_PATH', substr($_SERVER['REQUEST_URI'], 0, 1+strrpos($_SERVER['REQUEST_URI'], '/', 0)));
@@ -45,6 +45,16 @@ error_reporting(E_ALL^E_WARNING);
// 3rd-party libraries
+if (! file_exists(__DIR__ . '/vendor/autoload.php')) {
+ header('Content-Type: text/plain; charset=utf-8');
+ echo "Error: missing Composer configuration\n\n"
+ ."If you installed Shaarli through Git or using the development branch,\n"
+ ."please refer to the installation documentation to install PHP"
+ ." dependencies using Composer:\n"
+ ."- https://github.com/shaarli/Shaarli/wiki/Server-requirements\n"
+ ."- https://github.com/shaarli/Shaarli/wiki/Download-and-Installation";
+ exit;
+}
require_once 'inc/rain.tpl.class.php';
require_once __DIR__ . '/vendor/autoload.php';
@@ -322,8 +332,17 @@ include $conf->get('resource.ban_file', 'data/ipbans.php');
function ban_loginFailed($conf)
{
$ip = $_SERVER['REMOTE_ADDR'];
+ $trusted = $conf->get('security.trusted_proxies', array());
+ if (in_array($ip, $trusted)) {
+ $ip = getIpAddressFromProxy($_SERVER, $trusted);
+ if (!$ip) {
+ return;
+ }
+ }
$gb = $GLOBALS['IPBANS'];
- if (!isset($gb['FAILURES'][$ip])) $gb['FAILURES'][$ip]=0;
+ if (! isset($gb['FAILURES'][$ip])) {
+ $gb['FAILURES'][$ip]=0;
+ }
$gb['FAILURES'][$ip]++;
if ($gb['FAILURES'][$ip] > ($conf->get('security.ban_after') - 1))
{
@@ -587,8 +606,6 @@ function showDailyRSS($conf) {
$absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
// Build the HTML body of this RSS entry.
- $html = '';
- $href = '';
$links = array();
// We pre-format some fields for proper output.
@@ -759,6 +776,7 @@ function renderPage($conf, $pluginManager)
$PAGE = new PageBuilder($conf);
$PAGE->assign('linkcount', count($LINKSDB));
$PAGE->assign('privateLinkcount', count_private($LINKSDB));
+ $PAGE->assign('plugin_errors', $pluginManager->getErrors());
// Determine which page will be rendered.
$query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '';
@@ -813,7 +831,7 @@ function renderPage($conf, $pluginManager)
// Get only links which have a thumbnail.
foreach($links as $link)
{
- $permalink='?'.escape(smallhash($link['linkdate']));
+ $permalink='?'.escape(smallHash($link['linkdate']));
$thumb=lazyThumbnail($conf, $link['url'],$permalink);
if ($thumb!='') // Only output links which have a thumbnail.
{
@@ -847,7 +865,7 @@ function renderPage($conf, $pluginManager)
$maxcount = max($maxcount, $value);
}
- // Sort tags alphabetically: case insensitive, support locale if avalaible.
+ // Sort tags alphabetically: case insensitive, support locale if available.
uksort($tags, function($a, $b) {
// Collator is part of PHP intl.
if (class_exists('Collator')) {
@@ -1193,7 +1211,7 @@ function renderPage($conf, $pluginManager)
$value['tags']=trim(implode(' ',$tags));
$LINKSDB[$key]=$value;
}
- $LINKSDB->savedb($conf->get('resource.page_cache'));
+ $LINKSDB->save($conf->get('resource.page_cache'));
echo '';
exit;
}
@@ -1210,7 +1228,7 @@ function renderPage($conf, $pluginManager)
$value['tags']=trim(implode(' ',$tags));
$LINKSDB[$key]=$value;
}
- $LINKSDB->savedb($conf->get('resource.page_cache')); // Save to disk.
+ $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
echo '';
exit;
}
@@ -1226,6 +1244,9 @@ function renderPage($conf, $pluginManager)
// -------- User clicked the "Save" button when editing a link: Save link to database.
if (isset($_POST['save_edit']))
{
+ $linkdate = $_POST['lf_linkdate'];
+ $updated = isset($LINKSDB[$linkdate]) ? strval(date('Ymd_His')) : false;
+
// Go away!
if (! tokenOk($_POST['token'])) {
die('Wrong token.');
@@ -1236,7 +1257,7 @@ function renderPage($conf, $pluginManager)
$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:')
@@ -1251,6 +1272,7 @@ function renderPage($conf, $pluginManager)
'description' => $_POST['lf_description'],
'private' => (isset($_POST['lf_private']) ? 1 : 0),
'linkdate' => $linkdate,
+ 'updated' => $updated,
'tags' => str_replace(',', ' ', $tags)
);
// If title is empty, use the URL as title.
@@ -1261,7 +1283,7 @@ function renderPage($conf, $pluginManager)
$pluginManager->executeHooks('save_link', $link);
$LINKSDB[$linkdate] = $link;
- $LINKSDB->savedb($conf->get('resource.page_cache'));
+ $LINKSDB->save($conf->get('resource.page_cache'));
pubsubhub($conf);
// If we are called from the bookmarklet, we must close the popup:
@@ -1303,7 +1325,7 @@ function renderPage($conf, $pluginManager)
$pluginManager->executeHooks('delete_link', $LINKSDB[$linkdate]);
unset($LINKSDB[$linkdate]);
- $LINKSDB->savedb('resource.page_cache'); // save to disk
+ $LINKSDB->save('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 ''; exit; }
@@ -1614,6 +1636,12 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
$link['class'] = $link['private'] == 0 ? $classLi : 'private';
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
$link['timestamp'] = $date->getTimestamp();
+ if (! empty($link['updated'])) {
+ $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['updated']);
+ $link['updated_timestamp'] = $date->getTimestamp();
+ } else {
+ $link['updated_timestamp'] = '';
+ }
$taglist = explode(' ', $link['tags']);
uasort($taglist, 'strcasecmp');
$link['taglist'] = $taglist;
@@ -1640,8 +1668,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
$next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl;
}
- $token = isLoggedIn() ? getToken($conf) : '';
-
// Fill all template fields.
$data = array(
'previous_page_url' => $previous_page_url,