From c0e13272880217d72b6db20be8c81714253d5dd9 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 6 Jun 2015 20:37:40 +0200 Subject: [PATCH] Move some stuff to separate Plugin initialize() function conflicted because of previously not static declaration of QvitterPlugin::settings --- QvitterPlugin.php | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/QvitterPlugin.php b/QvitterPlugin.php index b085f10..883dba3 100644 --- a/QvitterPlugin.php +++ b/QvitterPlugin.php @@ -38,6 +38,8 @@ const QVITTERDIR = __DIR__; class QvitterPlugin extends Plugin { + protected $hijack_ui = true; + static function settings($setting) { @@ -113,7 +115,25 @@ class QvitterPlugin extends Plugin { return false; } } - + + public function initialize() + { + // check if we should reroute UI to qvitter + $scoped = Profile::current(); + $qvitter_enabled_by_user = false; + $qvitter_disabled_by_user = false; + if ($scoped instanceof Profile) { + $qvitter_enabled_by_user = $scoped->getPref('qvitter', 'enable_qvitter', false); + $qvitter_disabled_by_user = $scoped->getPref('qvitter', 'disable_qvitter', false); + } + + $this->hijack_ui = (self::settings('enabledbydefault') && !$logged_in_user) + || (self::settings('enabledbydefault') && !$qvitter_disabled_by_user) + || (!self::settings('enabledbydefault') && $qvitter_enabled_by_user); + + // show qvitter link in the admin panel + common_config_append('admin', 'panels', 'qvitteradm'); + } // make sure we have a notifications table function onCheckSchema() @@ -163,31 +183,10 @@ class QvitterPlugin extends Plugin { array('action' => 'qvittersettings')); $m->connect('panel/qvitter', array('action' => 'qvitteradminsettings')); - common_config_append('admin', 'panels', 'qvitteradm'); $m->connect('main/qlogin', array('action' => 'qvitterlogin')); - // check if we should reroute UI to qvitter - $logged_in_user = common_current_user(); - $qvitter_enabled_by_user = false; - $qvitter_disabled_by_user = false; - if($logged_in_user) { - try { - $qvitter_enabled_by_user = Profile_prefs::getData($logged_in_user->getProfile(), 'qvitter', 'enable_qvitter'); - } catch (NoResultException $e) { - $qvitter_enabled_by_user = false; - } - try { - $qvitter_disabled_by_user = Profile_prefs::getData($logged_in_user->getProfile(), 'qvitter', 'disable_qvitter'); - } catch (NoResultException $e) { - $qvitter_disabled_by_user = false; - } - } - - if((self::settings('enabledbydefault') && !$logged_in_user) || - (self::settings('enabledbydefault') && !$qvitter_disabled_by_user) || - (!self::settings('enabledbydefault') && $qvitter_enabled_by_user)) { - + if ($this->hijack_ui) { $m->connect('', array('action' => 'qvitter')); $m->connect('main/all', array('action' => 'qvitter')); $m->connect('search/notice', array('action' => 'qvitter'));