Skip to content

Commit

Permalink
Plugin module support, first draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jan 12, 2015
1 parent f2195fb commit 555ae71
Show file tree
Hide file tree
Showing 30 changed files with 496 additions and 339 deletions.
2 changes: 1 addition & 1 deletion application/Psr4AutoloaderClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Psr4AutoloaderClass
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
spl_autoload_register(array($this, 'loadClass'), true, true);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@
),
'pluginManager' => [
'class' => "\\ls\\pluginmanager\\PluginManager",
'api' => "\\ls\\pluginmanager\\LimesurveyApi"

'api' => "\\ls\\pluginmanager\\LimesurveyApi",
'plugins' => require_once(__DIR__ . '/plugins.php')
]
)
),

);



$result = CMap::mergeArray($internalConfig, $userConfig);
/**
* Some workarounds for erroneous settings in user config.php.
Expand Down
21 changes: 21 additions & 0 deletions application/config/plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
return array (
'AuditLog' =>
array (
'name' => 'AuditLog',
'namespace' => '',
'description' => 'Core: Create an audit log of changes',
'type' => 'simple',
'dir' => '/home/sam/Projects/LimeSurvey/plugins/AuditLog',
'class' => '\\AuditLog',
),
'ModulePlugin' =>
array (
'name' => 'ModulePlugin',
'namespace' => '\\befound\\ls\\ModulePlugin',
'description' => 'Example plugin that uses a Yii module.',
'type' => 'module',
'dir' => '/home/sam/Projects/LimeSurvey/plugins/befound/ls/ModulePlugin',
'class' => '\\befound\\ls\\ModulePlugin\\ModulePlugin',
),
);
2 changes: 1 addition & 1 deletion application/controllers/PluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function _init()
public function accessRules()
{
$aRules = array(
array('allow', 'roles' => array('administrator')),
array('allow', 'roles' => array('superadmin')),
array('allow', 'actions' => array('direct')),
array('deny')
);
Expand Down
2 changes: 1 addition & 1 deletion application/core/LSHttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Description of HttpRequest
*
*
* Used in LSYii_Application.php
* Used in WebApplication.php
* <pre>
* 'request'=>array(
* 'class'=>'HttpRequest',
Expand Down
16 changes: 7 additions & 9 deletions application/core/LSWebUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ public function __construct()

public function checkAccess($operation, $params = array(), $allowCaching = true)
{
if ($operation == 'administrator')
{
return Permission::model()->hasGlobalPermission('superadmin', 'read');
}
else
{
return parent::checkAccess($operation, $params, $allowCaching);
}

$defaults = [
'entity' => 'global',
'entity_id' => 0,
'crud' => 'read'
];
$params = array_merge($defaults, $params);
return Permission::model()->hasPermission($params['entity_id'], $params['entity'], $operation, $params['crud']);
}

public function getStateKeyPrefix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
* Implements global config
* @property CLogRouter $log Log router component.
*/
class LSYii_Application extends CWebApplication
class WebApplication extends CWebApplication
{
public $loader;
protected $config = array();

/**
Expand All @@ -39,6 +40,20 @@ class LSYii_Application extends CWebApplication
*/
public function __construct($config = null)
{
/**
* Load Psr4 autoloader, should be replaced by composer autoloader at some point.
*/
require __DIR__ . '/../Psr4AutoloaderClass.php';
$this->loader = new Psr4AutoloaderClass();
$this->loader->register();
$this->loader->addNamespace('ls\\pluginmanager', __DIR__ . '/../libraries/PluginManager');
foreach($config['modules'] as $module) {
if (isset($module['namespace'], $module['dir'])) {
$this->loader->addNamespace($module['namespace'], $module['dir']);
}
class_exists($module['class']);
}

parent::__construct($config);
Yii::setPathOfAlias('bootstrap' , Yii::getPathOfAlias('ext.bootstrap'));
// Load the default and environmental settings from different files into self.
Expand Down Expand Up @@ -130,7 +145,7 @@ public function setConfig($name, $value)
*
* @param string $message
* @param string $type
* @return LSYii_Application Provides a fluent interface
* @return WebApplication Provides a fluent interface
*/
public function setFlashMessage($message,$type='default')
{
Expand Down Expand Up @@ -204,6 +219,6 @@ public function getPluginManager()
return $this->getComponent('pluginManager');
}


}

7 changes: 4 additions & 3 deletions application/core/plugins/AuthLDAP/AuthLDAP.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
use ls\pluginmanager\AuthPluginBase;
class AuthLDAP extends AuthPluginBase
{
protected $storage = 'DbStorage';
Expand Down Expand Up @@ -86,8 +87,8 @@ class AuthLDAP extends AuthPluginBase
)
);

public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
public function init()
{

/**
* Here you should handle subscribing to the events your plugin will handle
Expand Down Expand Up @@ -176,7 +177,7 @@ public function newUserSession()

if ($user === null && $this->autoCreate === false)
{
// If the user doesnt exist ín the LS database, he can not login
// If the user doesnt exist �n the LS database, he can not login
$this->setAuthFailure(self::ERROR_USERNAME_INVALID);
return;
}
Expand Down
5 changes: 1 addition & 4 deletions application/core/plugins/Authdb/Authdb.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use ls\pluginmanager\AuthPluginBase;
use ls\pluginmanager\PluginManager;

class Authdb extends AuthPluginBase
{
Expand All @@ -10,10 +9,8 @@ class Authdb extends AuthPluginBase
static protected $description = 'Core: Database authentication + exports';
static protected $name = 'LimeSurvey internal database';

public function __construct(PluginManager $manager, $id)
public function init()
{
parent::__construct($manager, $id);

/**
* Here you should handle subscribing to the events your plugin will handle
*/
Expand Down
7 changes: 4 additions & 3 deletions application/core/plugins/Authwebserver/Authwebserver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use ls\pluginmanager\AuthPluginBase;

class Authwebserver extends AuthPluginBase
{
protected $storage = 'DbStorage';
Expand All @@ -23,9 +25,8 @@ class Authwebserver extends AuthPluginBase
)
);

public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);

public function init()
{
/**
* Here you should handle subscribing to the events your plugin will handle
*/
Expand Down
6 changes: 4 additions & 2 deletions application/core/plugins/ExportR/ExportR.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php
use ls\pluginmanager\PluginBase;

class ExportR extends PluginBase {

protected $storage = 'DbStorage';

static protected $description = 'Core: R-export';
static protected $name = 'Export results to R';

public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
public function init()
{

/**
* Here you should handle subscribing to the events your plugin will handle
Expand Down
5 changes: 3 additions & 2 deletions application/core/plugins/ExportSTATAxml/ExportSTATAxml.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
use ls\pluginmanager\PluginBase;
class ExportSTATAxml extends PluginBase {

protected $storage = 'DbStorage';

static protected $description = 'Core: Export survey results to a STATA xml file';
static protected $name = 'STATA Export';

public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
public function init()
{

/**
* Here you should handle subscribing to the events your plugin will handle
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* Helper function to replace calls to Yii::app() and enable correct code completion.
* @return LSYii_Application
* @return WebApplication
*/
function App()
{
Expand Down

0 comments on commit 555ae71

Please sign in to comment.