Handle errors raised by plugins in template. fixes #370

This commit is contained in:
ArthurHoaro 2015-11-08 13:22:44 +01:00
parent 89dfc37b0a
commit 056107ab4e
4 changed files with 48 additions and 22 deletions

View file

@ -1126,3 +1126,8 @@ div.dailyNoEntry {
.center {
text-align: center;
}
ul.errors {
color: red;
float: left;
}

View file

@ -55,8 +55,7 @@ $GLOBALS['config']['HIDE_PUBLIC_LINKS'] = false;
$GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode');
// Default plugins, default config - will be overriden by config.php and then plugin's config.php file.
$GLOBALS['plugins']['READITYOUSELF_URL'] = 'http://someurl.com';
$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/';
//$GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/';
// -----------------------------------------------------------------------------------------------
define('shaarli_version', '0.5.4');
// http://server.com/x/shaarli --> /shaarli/
@ -580,28 +579,43 @@ class pageBuilder
function __construct()
{
$this->tpl=false;
$this->tpl = false;
}
/**
* Initialize all default tpl tags.
*/
private function initialize()
{
$this->tpl = new RainTPL;
$this->tpl->assign('newversion',escape(checkUpdate()));
$this->tpl->assign('feedurl',escape(index_url($_SERVER)));
$searchcrits=''; // Search criteria
if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.urlencode($_GET['searchtags']);
elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.urlencode($_GET['searchterm']);
$this->tpl->assign('searchcrits',$searchcrits);
$this->tpl->assign('source',index_url($_SERVER));
$this->tpl->assign('version',shaarli_version);
$this->tpl->assign('scripturl',index_url($_SERVER));
$this->tpl->assign('pagetitle','Shaarli');
$this->tpl->assign('privateonly',!empty($_SESSION['privateonly'])); // Show only private links?
if (!empty($GLOBALS['title'])) $this->tpl->assign('pagetitle',$GLOBALS['title']);
if (!empty($GLOBALS['titleLink'])) $this->tpl->assign('titleLink',$GLOBALS['titleLink']);
if (!empty($GLOBALS['pagetitle'])) $this->tpl->assign('pagetitle',$GLOBALS['pagetitle']);
$this->tpl->assign('shaarlititle',empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title'] );
return;
$this->tpl->assign('newversion', escape(checkUpdate()));
$this->tpl->assign('feedurl', escape(index_url($_SERVER)));
$searchcrits = ''; // Search criteria
if (!empty($_GET['searchtags'])) {
$searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
}
elseif (!empty($_GET['searchterm'])) {
$searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
}
$this->tpl->assign('searchcrits', $searchcrits);
$this->tpl->assign('source', index_url($_SERVER));
$this->tpl->assign('version', shaarli_version);
$this->tpl->assign('scripturl', index_url($_SERVER));
$this->tpl->assign('pagetitle', 'Shaarli');
$this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
if (!empty($GLOBALS['title'])) {
$this->tpl->assign('pagetitle', $GLOBALS['title']);
}
if (!empty($GLOBALS['titleLink'])) {
$this->tpl->assign('titleLink', $GLOBALS['titleLink']);
}
if (!empty($GLOBALS['pagetitle'])) {
$this->tpl->assign('pagetitle', $GLOBALS['pagetitle']);
}
$this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']);
if (!empty($GLOBALS['plugins']['errors'])) {
$this->tpl->assign('plugin_errors', $GLOBALS['plugins']['errors']);
}
}
// The following assign() method is basically the same as RainTPL (except that it's lazy)

View file

@ -14,9 +14,9 @@ if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) {
}
if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
$GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '.
'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '.
'in "plugins/wallabag/config.php" or in your Shaarli config.php file.';
$GLOBALS['plugins']['errors'][] = 'Readityourself plugin error: '.
'Please define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" '.
'in "plugins/readityourself/config.php" or in your Shaarli config.php file.';
}
/**

View file

@ -40,6 +40,13 @@
</ul>
</div>
{if="!empty($plugin_errors) && isLoggedIn()"}
<ul class="errors">
{loop="plugin_errors"}
<li>{$value}</li>
{/loop}
</ul>
{/if}
<div class="clear"></div>