Changes to the module system

This commit is contained in:
Lucas Bartholemy 2014-06-25 17:43:16 +02:00
parent 78360b7824
commit d3c8fb44c2
58 changed files with 963 additions and 537 deletions

View File

@ -26,11 +26,13 @@ Yii::import('application.extensions.migrate-command.EMigrateCommand');
* @package humhub.commands * @package humhub.commands
* @since 0.5 * @since 0.5
*/ */
class ZMigrateCommand extends EMigrateCommand { class ZMigrateCommand extends EMigrateCommand
{
public $migrationTable = 'migration'; public $migrationTable = 'migration';
public static function AutoMigrate() { public static function AutoMigrate()
{
/** $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands'; /** $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
@ -52,7 +54,8 @@ class ZMigrateCommand extends EMigrateCommand {
return htmlentities(ob_get_clean(), null, Yii::app()->charset); return htmlentities(ob_get_clean(), null, Yii::app()->charset);
} }
public function init() { public function init()
{
print "Flushing Caches....\n"; print "Flushing Caches....\n";
Yii::app()->cache->flush(); Yii::app()->cache->flush();
@ -60,11 +63,14 @@ class ZMigrateCommand extends EMigrateCommand {
print "Autodetecting Modules....\n"; print "Autodetecting Modules....\n";
$modulePaths = array(); $modulePaths = array();
foreach (Yii::app()->moduleManager->getRegisteredModules() as $moduleId => $moduleInfo) { foreach (Yii::app()->moduleManager->getInstalledModules(true, true) as $moduleId => $classAlias) {
// Convert path.to.example.ExampleModule to path.to.example.migrations // Convert path.to.example.ExampleModule to path.to.example.migrations
$path = explode(".", $moduleInfo['class']); $path = explode(".", $classAlias);
array_pop($path); array_pop($path);
$path[] = $this->migrationSubPath; $path[] = $this->migrationSubPath;
$migrationPath = implode(".", $path); $migrationPath = implode(".", $path);
@ -77,7 +83,8 @@ class ZMigrateCommand extends EMigrateCommand {
$this->modulePaths = $modulePaths; $this->modulePaths = $modulePaths;
} }
protected function instantiateMigration($class) { protected function instantiateMigration($class)
{
$migration = new $class; $migration = new $class;
$migration->setDbConnection($this->getDbConnection()); $migration->setDbConnection($this->getDbConnection());
@ -88,7 +95,8 @@ class ZMigrateCommand extends EMigrateCommand {
return $migration; return $migration;
} }
public function run($args) { public function run($args)
{
$exitCode = parent::run($args); $exitCode = parent::run($args);
@ -96,7 +104,8 @@ class ZMigrateCommand extends EMigrateCommand {
ModuleManager::flushCache(); ModuleManager::flushCache();
} }
protected function getTemplate() { protected function getTemplate()
{
if ($this->templateFile !== null) { if ($this->templateFile !== null) {
return parent::getTemplate(); return parent::getTemplate();
} else { } else {

View File

@ -0,0 +1,248 @@
<?php
/**
* HumHub
* Copyright © 2014 The HumHub Project
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/
/**
* Base Class for Modules / Extensions
*
* @author luke
*/
class HWebModule extends CWebModule
{
/**
* Loaded Module JSON File
*
* @var Array
*/
private $_moduleInfo = null;
public function preinit()
{
$this->attachBehaviors($this->behaviors());
parent::preinit();
}
/**
* Add behaviors to this module
*
* You may want to enable one of these behavior to alos make this module
* available on space and/or user context.
*
* See related behaviors classes for more details.
*
* @return Array
*/
public function behaviors()
{
return array(
/*
'SpaceModuleBehavior' => array(
'class' => 'application.modules_core.space.SpaceModuleBehavior',
),
'UserModuleBehavior' => array(
'class' => 'application.modules_core.user.UserModuleBehavior',
),
*/
);
}
/**
* Returns modules name provided by module.json file
*
* @return string Description
*/
public function getName()
{
$info = $this->getModuleInfo();
if ($info['name']) {
return $info['name'];
}
return $this->getId();
}
/**
* Returns modules description provided by module.json file
*
* @return string Description
*/
public function getDescription()
{
$info = $this->getModuleInfo();
if ($info['description']) {
return $info['description'];
}
return "";
}
/**
* Returns modules version number provided by module.json file
*
* @return string Version Number
*/
public function getVersion()
{
$info = $this->getModuleInfo();
if ($info['version']) {
return $info['version'];
}
return "1.0";
}
/**
* Returns image url for this module
*
* @return String Image Url
*/
public function getImage()
{
return Yii::app()->baseUrl . '/uploads/profile_image/default_module.jpg';
}
/**
* Returns URL of configuration controller for this module.
*
* You may overwrite this method to provide advanced module configuration
* possibilities.
*
* @return string
*/
public function getConfigUrl()
{
return "";
}
/**
* Checks whether this module is enabled or not
*
* @return boolean
*/
public function isEnabled()
{
return Yii::app()->moduleManager->isEnabled($this->getId());
}
/**
* Enables this module
*/
public function enable()
{
if (!$this->isEnabled()) {
$moduleEnabled = ModuleEnabled::model()->findByPk($this->getId());
if ($moduleEnabled == null) {
$moduleEnabled = new ModuleEnabled();
$moduleEnabled->module_id = $this->getId();
$moduleEnabled->save();
// Auto Migrate (add module database changes)
Yii::import('application.commands.shell.ZMigrateCommand');
$migrate = ZMigrateCommand::AutoMigrate();
}
}
}
/**
*
* @todo also disable it on all spaces/users
*/
public function disable()
{
if ($this->isEnabled()) {
$moduleEnabled = ModuleEnabled::model()->findByPk($this->getId());
if ($moduleEnabled != null) {
$moduleEnabled->delete();
}
}
}
/**
* Reads module.json which contains basic module informations and
* returns it as array
*
* @return Array module.json content
*/
protected function getModuleInfo()
{
if ($this->_moduleInfo != null) {
return $this->_moduleInfo;
}
$moduleJson = file_get_contents($this->getPath() . DIRECTORY_SEPARATOR . 'module.json');
return CJSON::decode($moduleJson);
}
/**
* Returns Base Path of Module
*/
public function getPath()
{
$reflection = new ReflectionClass($this);
return dirname($reflection->getFileName());
}
/**
* Uninstalls a module
*
* Removes module folder from system.
* You may overwrite this method to add more cleanup stuff.
*/
public function uninstall()
{
if ($this->isEnabled()) {
$this->disable();
}
$this->removeModuleFolder();
}
/**
* Installs a module
*/
public function install()
{
print "Install called" . $this->getId();
}
/**
* Removes module folder in case of uninstall or update
*/
protected function removeModuleFolder()
{
$moduleBackupFolder = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . 'module_backups';
if (!is_dir($moduleBackupFolder)) {
mkdir($moduleBackupFolder);
}
$backupFolderName = $moduleBackupFolder . DIRECTORY_SEPARATOR . $this->getId() . "_" . time();
rename($this->getPath(), $backupFolderName);
}
}

View File

@ -19,156 +19,134 @@
*/ */
/** /**
* ModuleManager allows dynamic enabling/disabling of application modules. * Module Manager
* *
* Each module has a autostart.php which can register the module. * - Starts module autostart files
* * - Handles enabled modules
* Modules must register with a module definition, which holds all relevant * - Modules autostarts.php registers to it for events & co
* information about it. *
*
* Module Definition Array:
* id => mymodule (also folder name under /modules/...)
* title => My Module
* icon => cssClass
* description => someText (For Admin Manage Modules)
* isSpaceModule => true/FALSE (Is a workspace module)
* isCoreModule => true/FALSE (Is core module, always enabled)
* configRoute => 'mymodule/configure' (Configuration URL for SuperAdmin)
*
* @todo cache enabled modules - problem module manager started before caching
*
* @package humhub.components
* @since 0.5
*/ */
class ModuleManager extends CApplicationComponent { class ModuleManager extends CApplicationComponent
{
const AUTOSTART_CACHE_FILE_NAME = "cache_autostart.php"; const AUTOSTART_CACHE_FILE_NAME = "cache_autostart.php";
/** /**
* @var Array of all registered module definitions * List of all enabled module ids
*
* @var Array
*/ */
public $registeredModules; private $enabledModules = array();
/** /**
* @var Array of enabled module ids. * Array of installed modules populated on autostart.php register
*
* @var Array moduleId => moduleClass
*/ */
public $enabledModules; private $installedModules = array();
/** /**
* @var Array of registered content model classes. * Initializes the module manager
*/ */
public $registeredContentModels = array(); public function init()
{
/**
* Initializes the application component.
* This should also should check which module is enabled
*/
public function init() {
parent::init(); parent::init();
if (Yii::app()->params['installed']) if (Yii::app()->params['installed']) {
$this->loadEnabledModules();
// Load all enabled modules
$cacheId = "enabledModules";
$cacheValue = Yii::app()->cache->get($cacheId);
if ($cacheValue === false || !is_array($cacheValue)) {
foreach (ModuleEnabled::model()->findAll() as $em) {
$this->enabledModules[] = $em->module_id;
}
Yii::app()->cache->set($cacheId, $this->enabledModules, HSetting::Get('expireTime', 'cache'));
} else {
$this->enabledModules = $cacheValue;
}
}
// Intercept this controller // Intercept this controller
Yii::app()->interceptor->intercept($this); Yii::app()->interceptor->intercept($this);
} }
public function start() {
$this->executeAutoloaders();
#print "start";
#die();
}
/** /**
* Searches and executes all module autoloaders. * Starts module manager which executes all enabled autoloaders
*
* The module autoloaders are stored in a file "autostart.php" which can be
* placed in the root directory of the module.
*
* @todo Caching autostarts
* @todo Remove rendundant code
*/ */
private function executeAutoloaders() { public function start()
{
$cacheEnabled = (get_class(Yii::app()->cache) != 'CDummyCache'); $cacheEnabled = (get_class(Yii::app()->cache) != 'CDummyCache');
$cacheFileName = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . self::AUTOSTART_CACHE_FILE_NAME; $cacheFileName = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . self::AUTOSTART_CACHE_FILE_NAME;
// Fastlane, when cache enabled and cachefile exists
if ($cacheEnabled && file_exists($cacheFileName)) { if ($cacheEnabled && file_exists($cacheFileName)) {
require_once($cacheFileName); require_once($cacheFileName);
return; return;
} }
$fileNames = array(); $autostartFiles = array();
// Looking up 3rd party modules /*
// Recursively collect all module_core autostarts
$modulesCorePath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules_core';
$modules = scandir($modulesCorePath);
foreach ($modules as $moduleId) {
$autostartFiles[] = $modulesCorePath . DIRECTORY_SEPARATOR . $moduleId . DIRECTORY_SEPARATOR . 'autostart.php';
}
// Collect autostarts of enabled modules
$modulesCustomPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules';
foreach ($this->enabledModules as $moduleId) {
$autostartFiles[] = $modulesCustomPath . DIRECTORY_SEPARATOR . $moduleId . DIRECTORY_SEPARATOR . 'autostart.php';
}
*/
// Recursively collect all moodules / modules_core autostarts
$modulesPaths = array(Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules', Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules_core'); $modulesPaths = array(Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules', Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'modules_core');
foreach ($modulesPaths as $modulePath) {
$modules = scandir($modulePath);
foreach ($modules as $moduleId) {
$autostartFiles[] = $modulePath . DIRECTORY_SEPARATOR . $moduleId . DIRECTORY_SEPARATOR . 'autostart.php';
}
}
// Execute Autoloaders in each modules paths // Execute (and cache) found autostarts
foreach ($modulesPaths as $modulesPath) { $cacheFileContent = "";
foreach ($autostartFiles as $autoloadFile) {
if (is_file($autoloadFile)) {
// Scan Modules require_once($autoloadFile);
$modules = scandir($modulesPath);
foreach ($modules as $module) {
if ($module == '.' || $module == '..')
continue;
$moduleDir = $modulesPath . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR; // Cache content of autostart file
if ($cacheEnabled) {
if (is_dir($moduleDir) && is_file($moduleDir . 'autostart.php')) { $cacheFileContent .= file_get_contents($autoloadFile);
// Store Filename to Cache Content
$fileNames[] = $moduleDir . 'autostart.php';
// Execute Autoloader
require_once($moduleDir . 'autostart.php');
} }
} }
} }
if ($cacheEnabled) { if ($cacheEnabled) {
// Created a cache file which contains all autoloaders file_put_contents($cacheFileName, $cacheFileContent);
$content = "";
foreach ($fileNames as $fileName) {
$content .= file_get_contents($fileName);
}
file_put_contents($cacheFileName, $content);
} }
} }
/** /**
* Loads all enabled modules from the database. (Cached) * Flushes Module Managers Cache
*/ */
private function loadEnabledModules() { public static function flushCache()
{
$cacheId = "enabledModules"; // Delete Autoloader Cache File
$cacheValue = Yii::app()->cache->get($cacheId);
if ($cacheValue === false || !is_array($cacheValue)) {
$enabledModules = array();
foreach (ModuleEnabled::model()->findAll() as $em) {
$enabledModules[$em->module_id] = $em->module_id;
}
Yii::app()->cache->set($cacheId, $enabledModules, HSetting::Get('expireTime', 'cache'));
$this->enabledModules = $enabledModules;
} else {
$this->enabledModules = $cacheValue;
}
}
/**
* Flushes Module Managers cache
*/
public static function flushCache() {
// Autoloader Cache File
$cacheFileName = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . self::AUTOSTART_CACHE_FILE_NAME; $cacheFileName = Yii::app()->getRuntimePath() . DIRECTORY_SEPARATOR . self::AUTOSTART_CACHE_FILE_NAME;
if (file_exists($cacheFileName)) { if (file_exists($cacheFileName)) {
unlink($cacheFileName); unlink($cacheFileName);
} }
// Delete Enabled Modules List
$cacheId = "enabledModules"; $cacheId = "enabledModules";
Yii::app()->cache->delete($cacheId); Yii::app()->cache->delete($cacheId);
} }
@ -176,243 +154,145 @@ class ModuleManager extends CApplicationComponent {
/** /**
* Registers a module * Registers a module
* This is usally called in the autostart file of the module. * This is usally called in the autostart file of the module.
*
* - id
* - class Module Base Class
* - import Global Module Imports
* - events Events to catch
*
* - isCoreModule Core Modules only
* *
* @param Array $definition * @param Array $definition
*/ */
public function register($definition) { public function register($definition)
$id = $definition['id']; {
if (!isset($definition['isSpaceModule'])) if (!isset($definition['class']) || !isset($definition['id'])) {
$definition['isSpaceModule'] = false; throw new Exception("Register Module needs module Id and Class!");
}
if (!isset($definition['isCoreModule'])) $isCoreModule = (isset($definition['isCoreModule']) && $definition['isCoreModule']);
$definition['isCoreModule'] = false;
if (!isset($definition['configRoute'])) $this->installedModules[$definition['id']] = $definition['class'];
$definition['configRoute'] = '';
if (!isset($definition['spaceConfigRoute'])) // Not enabled and no core module
$definition['spaceConfigRoute'] = ''; if (!$isCoreModule && !in_array($definition['id'], $this->enabledModules)) {
return;
}
// Register Yii Module
Yii::app()->setModules(array(
$definition['id'] => array(
'class' => $definition['class']
),
));
$this->registeredModules[$id] = $definition; // Set Imports
if (isset($definition['import'])) {
Yii::app()->setImport($definition['import']);
}
// Check if module is enabled // Register Event Handlers
if (Yii::app()->moduleManager->isEnabled($id)) { if (isset($definition['events'])) {
foreach ($definition['events'] as $event) {
// Register Yii Module Yii::app()->interceptor->preattachEventHandler(
if (isset($definition['class'])) { $event['class'], $event['event'], $event['callback']
Yii::app()->setModules(array( );
$id => array(
'class' => $definition['class']
),
));
}
// Set Imports
if (isset($definition['import'])) {
Yii::app()->setImport($definition['import']);
}
// Register Event Handlers
if (isset($definition['events'])) {
foreach ($definition['events'] as $event) {
Yii::app()->interceptor->preattachEventHandler(
$event['class'], $event['event'], $event['callback']
);
}
} }
} }
} }
/** /**
* Checks if a module is enabled or not. * Returns Module Base Class of installed module neither when not enabled.
* *
* @param type $moduleId * @param String $id Module Id
* @return boolean * @return HWebModule
*/ */
public function isEnabled($moduleId) { public function getModule($id)
{
$definition = $this->getDefinition($moduleId); // When enabled, returned it directly
if (Yii::app()->getModule($id) != null) {
if ($definition['isCoreModule']) return Yii::app()->getModule($id);
return true;
// Core installed yet?
if (!Yii::app()->params['installed'])
return false;
if (in_array($moduleId, $this->enabledModules)) {
return true;
} }
#$moduleEnabled = ModuleEnabled::model()->findByPk($moduleId); // Not enabled, but installed - create it
#if ($moduleEnabled != null) { if (isset($this->installedModules[$id])) {
# return true; $class = $this->installedModules[$id];
#} return Yii::createComponent($class, $id, null);
return false;
}
/**
* Returns an array with all registered modules
* This contains all enabled & disabled modules.
* Key is the moduleId and value is the module definition
*
* @return type
*/
public function getRegisteredModules() {
return $this->registeredModules;
}
/**
* Returns an array with enabled modules
* Key of the array is the module id and value is the module definition.
*
* @return array
*/
public function getEnabledModules() {
$enabledModules = array();
foreach ($this->getRegisteredModules() as $moduleId => $definition) {
if ($this->isEnabled($moduleId)) {
$enabledModules[$moduleId] = $definition;
}
} }
return $enabledModules;
}
/**
* Enables a module by given module id.
*
* @param String $id
*/
public function enable($id) {
$definition = $this->getDefinition($id);
if ($definition != null) {
// Core Modules doesn´t need to enabled
if (!$definition['isCoreModule']) {
$moduleEnabled = ModuleEnabled::model()->findByPk($id);
if ($moduleEnabled == null) {
$moduleEnabled = new ModuleEnabled();
$moduleEnabled->module_id = $id;
$moduleEnabled->save();
// Auto Migrate (add module database changes)
Yii::import('application.commands.shell.ZMigrateCommand');
$migrate = ZMigrateCommand::AutoMigrate();
// Fire Event Disabled Event
if ($this->hasEventHandler('onEnable'))
$this->onEnable(new CEvent($this, $id));
}
}
}
ModuleManager::flushCache();
}
/**
* Disables a active module by given module id
*
* @param String $id
*/
public function disable($id) {
$definition = $this->getDefinition($id);
if ($definition != null) {
// Core Modules couldn´t disabled
if (!$definition['isCoreModule']) {
if (isset($definition['userModules']) && is_array($definition['userModules'])) {
$modulesToDisable = array_keys($definition['userModules']);
foreach (User::model()->findAll() as $user) {
foreach ($modulesToDisable as $userModuleId) {
if ($user->isModuleEnabled($userModuleId))
$user->uninstallModule($userModuleId);
}
}
}
if (isset($definition['spaceModules']) && is_array($definition['spaceModules'])) {
$modulesToDisable = array_keys($definition['spaceModules']);
foreach (Space::model()->findAll() as $space) {
foreach ($modulesToDisable as $spaceModuleId) {
if ($space->isModuleEnabled($spaceModuleId))
$space->uninstallModule($spaceModuleId);
}
}
}
// Get Enabled Module Record
$moduleEnabled = ModuleEnabled::model()->findByPk($id);
if ($moduleEnabled != null)
$moduleEnabled->delete();
// Fire Event Disabled Event
if ($this->hasEventHandler('onDisable'))
$this->onDisable(new CEvent($this, $id));
}
}
ModuleManager::flushCache();
}
/**
* This event is raised after disabling a module
*
* @param CEvent $event the event parameter
* @see disable
*/
public function onDisable($event) {
$this->raiseEvent('onDisable', $event);
}
/**
* This event is raised after enabling a module
*
* @param CEvent $event the event parameter
* @see enable
*/
public function onEnable($event) {
$this->raiseEvent('onEnable', $event);
}
/**
* Returns the definition array of a registered module
*
* @param type $id
* @return null
*/
public function getDefinition($id) {
if (isset($this->registeredModules[$id]))
return $this->registeredModules[$id];
return null; return null;
} }
/** /**
* Registers a new Content Model * Returns a list of all installed modules
* *
* @param String $className * @param boolean $includeCoreModules include also core modules
* @param boolean $returnClassName instead of instance
* @return Array of installed Modules
*/ */
public function registerContentModel($className) { public function getInstalledModules($includeCoreModules = false, $returnClassName = false)
$this->registeredContentModels[] = $className; {
$installed = array();
foreach ($this->installedModules as $moduleId => $className) {
if (!$includeCoreModules && strpos($className, 'application.modules_core') !== false) {
continue;
}
if ($returnClassName) {
$installed[] = $className;
} else {
$module = $this->getModule($moduleId);
if ($module != null) {
$installed[$moduleId] = $module;
}
}
}
return $installed;
} }
/** /**
* Returns a list of all registered content models * Returns a list of all enabled modules
*
* @return Array
*/ */
public function getContentModels() { public function getEnabledModules()
return $this->registeredContentModels; {
$modules = array();
foreach ($this->enabledModules as $moduleId) {
$module = $this->getModule($moduleId);
if ($module != null) {
$modules[] = $module;
}
}
return $modules;
}
/**
* Checks if a module is enabled.
*
* @param String $moduleId
* @return boolean
*/
public function isEnabled($moduleId)
{
return (in_array($moduleId, $this->enabledModules));
}
/**
* Checks if a module id is installed.
*
* @param String $moduleId
* @return boolean
*/
public function isInstalled($moduleId)
{
return (array_key_exists($moduleId, $this->installedModules));
} }
} }

View File

@ -6,9 +6,11 @@
* @package humhub.modules.mail * @package humhub.modules.mail
* @since 0.5 * @since 0.5
*/ */
class MailModule extends CWebModule { class MailModule extends HWebModule
{
public function init() { public function init()
{
$this->setImport(array( $this->setImport(array(
'mail.models.*', 'mail.models.*',
@ -23,7 +25,8 @@ class MailModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onUserDelete($event) { public static function onUserDelete($event)
{
Yii::import('application.modules.mail.models.*'); Yii::import('application.modules.mail.models.*');
@ -45,7 +48,8 @@ class MailModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onIntegrityCheck($event) { public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender; $integrityChecker = $event->sender;
#$integrityChecker->showTestHeadline("Validating Mail Module (" . Message::model()->count() . " entries)"); #$integrityChecker->showTestHeadline("Validating Mail Module (" . Message::model()->count() . " entries)");
@ -57,26 +61,21 @@ class MailModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onTopMenuInit($event) { public static function onTopMenuInit($event)
{
// Is Module enabled on this workspace? $event->sender->addItem(array(
if (Yii::app()->moduleManager->isEnabled('mail')) { 'label' => Yii::t('MailModule.base', 'Messages'),
$event->sender->addItem(array( 'url' => Yii::app()->createUrl('//mail/mail/index', array()),
'label' => Yii::t('MailModule.base', 'Messages'), 'icon' => 'mail',
'url' => Yii::app()->createUrl('//mail/mail/index', array()), 'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'mail'),
'icon' => 'mail', 'sortOrder' => 300,
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'mail'), ));
'sortOrder' => 300,
));
}
} }
public static function onNotificationAddonInit($event) { public static function onNotificationAddonInit($event)
{
// Is Module enabled on this workspace? $event->sender->addWidget('application.modules.mail.widgets.MailNotificationWidget', array(), array('sortOrder' => 90));
if (Yii::app()->moduleManager->isEnabled('mail')) {
$event->sender->addWidget('application.modules.mail.widgets.MailNotificationWidget', array(), array('sortOrder' => 90));
}
} }
} }

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'mail', 'id' => 'mail',
'title' => Yii::t('MailModule.base', 'Mail'),
'description' => Yii::t('MailModule.base', 'Adds the mailing core module.'),
'class' => 'application.modules.mail.MailModule', 'class' => 'application.modules.mail.MailModule',
'import' => array( 'import' => array(
'application.modules.mail.*', 'application.modules.mail.*',

View File

@ -0,0 +1,10 @@
{
"id": "mail",
"name": "Mail",
"description": "Simple user to user mailing system",
"keywords": ["mail", "messaging", "communication"],
"version": "0.4",
"humhub": {
"minVersion": "0.5"
}
}

View File

@ -9,12 +9,14 @@
* @since 0.5 * @since 0.5
* @author Luke * @author Luke
*/ */
class PollsModule extends CWebModule { class PollsModule extends HWebModule
{
/** /**
* Inits the Module * Inits the Module
*/ */
public function init() { public function init()
{
$this->setImport(array( $this->setImport(array(
'polls.models.*', 'polls.models.*',
@ -22,13 +24,24 @@ class PollsModule extends CWebModule {
)); ));
} }
public function behaviors()
{
return array(
'SpaceModuleBehavior' => array(
'class' => 'application.modules_core.space.SpaceModuleBehavior',
),
);
}
/** /**
* On build of a Space Navigation, check if this module is enabled. * On build of a Space Navigation, check if this module is enabled.
* When enabled add a menu item * When enabled add a menu item
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceMenuInit($event) { public static function onSpaceMenuInit($event)
{
$space = Yii::app()->getController()->getSpace(); $space = Yii::app()->getController()->getSpace();
@ -48,7 +61,8 @@ class PollsModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onUserDelete($event) { public static function onUserDelete($event)
{
foreach (Content::model()->findAllByAttributes(array('user_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) { foreach (Content::model()->findAllByAttributes(array('user_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) {
$content->delete(); $content->delete();
@ -66,7 +80,8 @@ class PollsModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceDelete($event) { public static function onSpaceDelete($event)
{
foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) { foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) {
$content->delete(); $content->delete();
} }
@ -78,7 +93,8 @@ class PollsModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceUninstallModule($event) { public static function onSpaceUninstallModule($event)
{
if ($event->params == 'polls') { if ($event->params == 'polls') {
foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) { foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Poll')) as $content) {
$content->delete(); $content->delete();
@ -92,7 +108,8 @@ class PollsModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onDisableModule($event) { public static function onDisableModule($event)
{
if ($event->params == 'polls') { if ($event->params == 'polls') {
foreach (Content::model()->findAllByAttributes(array('object_model' => 'Poll')) as $content) { foreach (Content::model()->findAllByAttributes(array('object_model' => 'Poll')) as $content) {
@ -106,10 +123,11 @@ class PollsModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onIntegrityCheck($event) { public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender; $integrityChecker = $event->sender;
$integrityChecker->showTestHeadline("Validating Polls Module (" . Poll::model()->count() . " entries)"); $integrityChecker->showTestHeadline("Validating Polls Module (" . Poll::model()->count() . " entries)");
} }
} }

View File

@ -3,8 +3,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'polls', 'id' => 'polls',
'class' => 'application.modules.polls.PollsModule', 'class' => 'application.modules.polls.PollsModule',
'title' => Yii::t('PollsModule.base', 'Polls'),
'description' => Yii::t('PollsModule.base', 'Adds polling features to spaces.'),
'import' => array( 'import' => array(
'application.modules.polls.models.*', 'application.modules.polls.models.*',
'application.modules.polls.behaviors.*', 'application.modules.polls.behaviors.*',
@ -20,12 +18,5 @@ Yii::app()->moduleManager->register(array(
array('class' => 'ModuleManager', 'event' => 'onDisable', 'callback' => array('PollsModule', 'onDisableModule')), array('class' => 'ModuleManager', 'event' => 'onDisable', 'callback' => array('PollsModule', 'onDisableModule')),
array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('PollsModule', 'onIntegrityCheck')), array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('PollsModule', 'onIntegrityCheck')),
), ),
'spaceModules' => array(
'polls' => array(
'title' => Yii::t('PollsModule.base', 'Polls'),
'description' => Yii::t('PollsModule.base', 'Adds polling features to your space.'),
),
),
'contentModels' => array('Poll'),
)); ));
?> ?>

View File

@ -0,0 +1,10 @@
{
"id": "polls",
"name": "Polling",
"description": "Simple polling system",
"keywords": ["poll", "votes"],
"version": "0.5",
"humhub": {
"minVersion": "0.5"
}
}

View File

@ -1,11 +1,13 @@
<?php <?php
class TasksModule extends CWebModule { class TasksModule extends HWebModule
{
/** /**
* Inits the Module * Inits the Module
*/ */
public function init() { public function init()
{
$this->setImport(array( $this->setImport(array(
'tasks.*', 'tasks.*',
'tasks.models.*', 'tasks.models.*',
@ -14,12 +16,23 @@ class TasksModule extends CWebModule {
)); ));
} }
public function behaviors()
{
return array(
'SpaceModuleBehavior' => array(
'class' => 'application.modules_core.space.SpaceModuleBehavior',
),
);
}
/** /**
* On User delete, also delete all tasks * On User delete, also delete all tasks
* *
* @param type $event * @param type $event
*/ */
public static function onUserDelete($event) { public static function onUserDelete($event)
{
foreach (Content::model()->findAllByAttributes(array('created_by' => $event->sender->id, 'object_model' => 'Task')) as $content) { foreach (Content::model()->findAllByAttributes(array('created_by' => $event->sender->id, 'object_model' => 'Task')) as $content) {
$content->delete(); $content->delete();
@ -44,7 +57,8 @@ class TasksModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceDelete($event) { public static function onSpaceDelete($event)
{
foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Task')) as $content) { foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Task')) as $content) {
$content->delete(); $content->delete();
} }
@ -56,10 +70,11 @@ class TasksModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceMenuInit($event) { public static function onSpaceMenuInit($event)
{
$space = Yii::app()->getController()->getSpace(); $space = Yii::app()->getController()->getSpace();
// Is Module enabled on this workspace? // Is Module enabled on this workspace?
if ($space->isModuleEnabled('tasks')) { if ($space->isModuleEnabled('tasks')) {
$event->sender->addItem(array( $event->sender->addItem(array(
@ -77,7 +92,8 @@ class TasksModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onSpaceUninstallModule($event) { public static function onSpaceUninstallModule($event)
{
if ($event->params == 'tasks') { if ($event->params == 'tasks') {
foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Task')) as $content) { foreach (Content::model()->findAllByAttributes(array('space_id' => $event->sender->id, 'object_model' => 'Task')) as $content) {
$content->delete(); $content->delete();
@ -91,7 +107,8 @@ class TasksModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onDisableModule($event) { public static function onDisableModule($event)
{
if ($event->params == 'tasks') { if ($event->params == 'tasks') {
foreach (Content::model()->findAllByAttributes(array('object_model' => 'Task')) as $content) { foreach (Content::model()->findAllByAttributes(array('object_model' => 'Task')) as $content) {
$content->delete(); $content->delete();
@ -104,10 +121,11 @@ class TasksModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onIntegrityCheck($event) { public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender; $integrityChecker = $event->sender;
$integrityChecker->showTestHeadline("Validating Tasks Module (" . Task::model()->count() . " entries)"); $integrityChecker->showTestHeadline("Validating Tasks Module (" . Task::model()->count() . " entries)");
} }
} }

View File

@ -3,8 +3,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'tasks', 'id' => 'tasks',
'class' => 'application.modules.tasks.TasksModule', 'class' => 'application.modules.tasks.TasksModule',
'title' => Yii::t('TasksModule.base', 'Tasks'),
'description' => Yii::t('TasksModule.base', 'Adds a taskmanager to your spaces. With this module you can create and assign tasks to users in spaces.'),
'import' => array( 'import' => array(
'application.modules.tasks.*', 'application.modules.tasks.*',
'application.modules.tasks.models.*', 'application.modules.tasks.models.*',
@ -19,12 +17,5 @@ Yii::app()->moduleManager->register(array(
array('class' => 'ModuleManager', 'event' => 'onDisable', 'callback' => array('TasksModule', 'onDisableModule')), array('class' => 'ModuleManager', 'event' => 'onDisable', 'callback' => array('TasksModule', 'onDisableModule')),
array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('TasksModule', 'onIntegrityCheck')), array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('TasksModule', 'onIntegrityCheck')),
), ),
'spaceModules' => array(
'tasks' => array(
'title' => Yii::t('TasksModule.base', 'Tasks'),
'description' => Yii::t('TasksModule.base', 'Adds a taskmanager to your spaces. With this module you can create and assign tasks to users in spaces.'),
),
),
'contentModels' => array('Task'),
)); ));
?> ?>

View File

@ -0,0 +1,11 @@
{
"id": "tasks",
"name": "Tasks",
"description": "Adds a taskmanager to your spaces. With this module you can create and assign tasks to users in spaces.",
"keywords": ["task", "todo"],
"version": "0.9",
"humhub": {
"minVersion": "0.5",
"maxVersion": "0.7"
}
}

View File

@ -1,6 +1,6 @@
<?php <?php
class YiiGiiModule extends CWebModule { class YiiGiiModule extends HWebModule {
public function init() { public function init() {
$this->setImport(array( $this->setImport(array(

View File

@ -0,0 +1,11 @@
{
"id": "yiigii",
"name": "Yii Gii Integration",
"description": "Integrates Yii Code Generator",
"keywords": ["yii", "gii", "development"],
"version": "0.9",
"humhub": {
"minVersion": "0.5",
"maxVersion": "0.7"
}
}

View File

@ -7,7 +7,7 @@
* @package humhub.modules_core.activity * @package humhub.modules_core.activity
* @since 0.5 * @since 0.5
*/ */
class ActivityModule extends CWebModule { class ActivityModule extends HWebModule {
/** /**
* Inits the activity module * Inits the activity module

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'activity', 'id' => 'activity',
'title' => Yii::t('ActivityModule.base', 'Activities'),
'description' => Yii::t('ActivityModule.base', 'Adds the activities core module.'),
'class' => 'application.modules_core.activity.ActivityModule', 'class' => 'application.modules_core.activity.ActivityModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(
@ -18,6 +16,5 @@ Yii::app()->moduleManager->register(array(
array('class' => 'HActiveRecord', 'event' => 'onBeforeDelete', 'callback' => array('ActivityModule', 'onActiveRecordDelete')), array('class' => 'HActiveRecord', 'event' => 'onBeforeDelete', 'callback' => array('ActivityModule', 'onActiveRecordDelete')),
array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('ActivityModule', 'onIntegrityCheck')), array('class' => 'IntegrityChecker', 'event' => 'onRun', 'callback' => array('ActivityModule', 'onIntegrityCheck')),
), ),
'contentModels' => array('Activity'),
)); ));
?> ?>

View File

@ -0,0 +1,9 @@
{
"id": "activity",
"name": "Activity",
"description": "Activity Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -4,7 +4,7 @@
* @package humhub.modules_core.admin * @package humhub.modules_core.admin
* @since 0.5 * @since 0.5
*/ */
class AdminModule extends CWebModule { class AdminModule extends HWebModule {
public function init() { public function init() {

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'admin', 'id' => 'admin',
'title' => Yii::t('AdminModule.base', 'Admin'),
'description' => Yii::t('AdminModule.base', 'Provides general admin functions.'),
'class' => 'application.modules_core.admin.AdminModule', 'class' => 'application.modules_core.admin.AdminModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "admin",
"name": "Admin",
"description": "Admin Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -6,7 +6,7 @@
* @package humhub.modules_core.comment * @package humhub.modules_core.comment
* @since 0.5 * @since 0.5
*/ */
class CommentModule extends CWebModule class CommentModule extends HWebModule
{ {
/** /**

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'comment', 'id' => 'comment',
'title' => Yii::t('CommentModule.base', 'Comments'),
'description' => Yii::t('CommentModule.base', 'Comments core module.'),
'class' => 'application.modules_core.comment.CommentModule', 'class' => 'application.modules_core.comment.CommentModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "comment",
"name": "Comment",
"description": "Comments Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -6,12 +6,14 @@
* @package humhub.modules_core.dashboard * @package humhub.modules_core.dashboard
* @since 0.5 * @since 0.5
*/ */
class DashboardModule extends CWebModule { class DashboardModule extends HWebModule
{
/** /**
* Inits the Module * Inits the Module
*/ */
public function init() { public function init()
{
$this->setImport(array( $this->setImport(array(
)); ));
@ -23,17 +25,16 @@ class DashboardModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onTopMenuInit($event) { public static function onTopMenuInit($event)
{
// Is Module enabled on this workspace? // Is Module enabled on this workspace?
if (Yii::app()->moduleManager->isEnabled('dashboard')) { $event->sender->addItem(array(
$event->sender->addItem(array( 'label' => Yii::t('DashboardModule.base', 'Dashboard'),
'label' => Yii::t('DashboardModule.base', 'Dashboard'), 'url' => Yii::app()->createUrl('//dashboard/dashboard'),
'url' => Yii::app()->createUrl('//dashboard/dashboard'), 'sortOrder' => 100,
'sortOrder' => 100, 'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'dashboard'),
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'dashboard'), ));
));
}
} }
} }

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'dashboard', 'id' => 'dashboard',
'title' => Yii::t('DashboardModule.base', 'Dashboard'),
'description' => Yii::t('DashboardModule.base', 'Dashboard at main navigation.'),
'class' => 'application.modules_core.dashboard.DashboardModule', 'class' => 'application.modules_core.dashboard.DashboardModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "dashboard",
"name": "Dashboard",
"description": "Dashboard Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -9,12 +9,14 @@
* @package humhub.modules_core.directory * @package humhub.modules_core.directory
* @since 0.5 * @since 0.5
*/ */
class DirectoryModule extends CWebModule { class DirectoryModule extends HWebModule
{
/** /**
* Inits the Module * Inits the Module
*/ */
public function init() { public function init()
{
$this->setImport(array( $this->setImport(array(
)); ));
@ -26,17 +28,15 @@ class DirectoryModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onTopMenuInit($event) { public static function onTopMenuInit($event)
{
// Is Module enabled on this workspace? $event->sender->addItem(array(
if (Yii::app()->moduleManager->isEnabled('directory')) { 'label' => Yii::t('DirectoryModule.base', 'Directory'),
$event->sender->addItem(array( 'url' => Yii::app()->createUrl('//directory/directory'),
'label' => Yii::t('DirectoryModule.base', 'Directory'), 'sortOrder' => 400,
'url' => Yii::app()->createUrl('//directory/directory'), 'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'directory'),
'sortOrder' => 400, ));
'isActive' => (Yii::app()->controller->module && Yii::app()->controller->module->id == 'directory'),
));
}
} }
} }

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'directory', 'id' => 'directory',
'title' => Yii::t('DirectoryModule.base', 'Directory'),
'description' => Yii::t('DirectoryModule.base', 'Adds an directory to the main navigation.'),
'class' => 'application.modules_core.directory.DirectoryModule', 'class' => 'application.modules_core.directory.DirectoryModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "directory",
"name": "Directory",
"description": "Directory Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -6,7 +6,7 @@
* @package humhub.modules_core.file * @package humhub.modules_core.file
* @since 0.5 * @since 0.5
*/ */
class FileModule extends CWebModule { class FileModule extends HWebModule {
/** /**
* Inits the Module * Inits the Module

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'file', 'id' => 'file',
'title' => Yii::t('FileModule.base', 'File'),
'description' => Yii::t('FileModule.base', 'Files core module.'),
'class' => 'application.modules_core.file.FileModule', 'class' => 'application.modules_core.file.FileModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -44,6 +44,7 @@ class FileController extends Controller {
foreach (CUploadedFile::getInstancesByName('files') as $cFile) { foreach (CUploadedFile::getInstancesByName('files') as $cFile) {
$files[] = $this->handleFileUpload($cFile); $files[] = $this->handleFileUpload($cFile);
} }
return $this->renderJson(array('files' => $files)); return $this->renderJson(array('files' => $files));
} }

View File

@ -0,0 +1,9 @@
{
"id": "file",
"name": "File",
"description": "File Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -24,7 +24,7 @@
* @package humhub.modules_core.installer * @package humhub.modules_core.installer
* @since 0.5 * @since 0.5
*/ */
class InstallerModule extends CWebModule { class InstallerModule extends HWebModule {
public function init() { public function init() {
$this->setLayoutPath(Yii::getPathOfAlias('installer.views')); $this->setLayoutPath(Yii::getPathOfAlias('installer.views'));

View File

@ -4,8 +4,6 @@
if (!Yii::app()->params['installed']) { if (!Yii::app()->params['installed']) {
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'installer', 'id' => 'installer',
'title' => Yii::t('InstallerModule.base', 'Installer'),
'description' => Yii::t('InstallerModule.base', 'Initial Installer.'),
'class' => 'application.modules_core.installer.InstallerModule', 'class' => 'application.modules_core.installer.InstallerModule',
'isCoreModule' => true, 'isCoreModule' => true,
)); ));

View File

@ -0,0 +1,9 @@
{
"id": "installer",
"name": "Installer",
"description": "Installer Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -7,9 +7,11 @@
* @package humhub.modules_core.like * @package humhub.modules_core.like
* @since 0.5 * @since 0.5
*/ */
class LikeModule extends CWebModule { class LikeModule extends HWebModule
{
public function init() { public function init()
{
// import the module-level models and components // import the module-level models and components
$this->setImport(array( $this->setImport(array(
'like.models.*', 'like.models.*',
@ -17,21 +19,13 @@ class LikeModule extends CWebModule {
)); ));
} }
/**
* Install some event listeners for the module
*/
public static function install() {
// Install Event Handler & Behaviors
Yii::app()->interceptor->preattachEventHandler('User', 'onBeforeDelete', array('LikeInterceptor', 'onUserDelete'));
}
/** /**
* On User delete, also delete all comments * On User delete, also delete all comments
* *
* @param type $event * @param type $event
*/ */
public static function onUserDelete($event) { public static function onUserDelete($event)
{
foreach (Like::model()->findAllByAttributes(array('created_by' => $event->sender->id)) as $like) { foreach (Like::model()->findAllByAttributes(array('created_by' => $event->sender->id)) as $like) {
$like->delete(); $like->delete();
@ -43,7 +37,8 @@ class LikeModule extends CWebModule {
/** /**
* On delete of a content object, also delete all corresponding likes * On delete of a content object, also delete all corresponding likes
*/ */
public static function onContentDelete($event) { public static function onContentDelete($event)
{
foreach (Like::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $like) { foreach (Like::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $like) {
$like->delete(); $like->delete();
@ -54,7 +49,8 @@ class LikeModule extends CWebModule {
* On delete of a content addon object, e.g. a comment * On delete of a content addon object, e.g. a comment
* also delete all likes * also delete all likes
*/ */
public static function onContentAddonDelete($event) { public static function onContentAddonDelete($event)
{
foreach (Like::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $like) { foreach (Like::model()->findAllByAttributes(array('object_id' => $event->sender->id, 'object_model' => get_class($event->sender))) as $like) {
$like->delete(); $like->delete();
@ -66,10 +62,11 @@ class LikeModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onIntegrityCheck($event) { public static function onIntegrityCheck($event)
{
$integrityChecker = $event->sender; $integrityChecker = $event->sender;
$integrityChecker->showTestHeadline("Validating Like Module (".Like::model()->count()." entries)"); $integrityChecker->showTestHeadline("Validating Like Module (" . Like::model()->count() . " entries)");
foreach (Like::model()->findAll() as $l) { foreach (Like::model()->findAll() as $l) {
if ($l->source === null) { if ($l->source === null) {
@ -85,7 +82,8 @@ class LikeModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onWallEntryLinksInit($event) { public static function onWallEntryLinksInit($event)
{
$event->sender->addWidget('application.modules_core.like.widgets.LikeLinkWidget', array('object' => $event->sender->object), array('sortOrder' => 10)); $event->sender->addWidget('application.modules_core.like.widgets.LikeLinkWidget', array('object' => $event->sender->object), array('sortOrder' => 10));
} }
@ -95,8 +93,9 @@ class LikeModule extends CWebModule {
* *
* @param type $event * @param type $event
*/ */
public static function onWallEntryAddonInit($event) { public static function onWallEntryAddonInit($event)
{
} }
} }

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'like', 'id' => 'like',
'title' => Yii::t('LikeModule.base', 'Likes'),
'description' => Yii::t('LikeModule.base', 'Likes core module.'),
'class' => 'application.modules_core.like.LikeModule', 'class' => 'application.modules_core.like.LikeModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "like",
"name": "Like",
"description": "Like Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -6,7 +6,7 @@
* @package humhub.modules_core.notification * @package humhub.modules_core.notification
* @since 0.5 * @since 0.5
*/ */
class NotificationModule extends CWebModule { class NotificationModule extends HWebModule {
public function init() { public function init() {
$this->setImport(array( $this->setImport(array(

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'notification', 'id' => 'notification',
'title' => Yii::t('NotificationModule.base', 'Notification'),
'description' => Yii::t('FeedbackModule.base', 'Basic subsystem for notifications.'),
'class' => 'application.modules_core.notification.NotificationModule', 'class' => 'application.modules_core.notification.NotificationModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "notification",
"name": "Notifications",
"description": "Notification Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -4,7 +4,7 @@
* @package humhub.modules_core.post * @package humhub.modules_core.post
* @since 0.5 * @since 0.5
*/ */
class PostModule extends CWebModule { class PostModule extends HWebModule {
public function init() { public function init() {

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'post', 'id' => 'post',
'title' => Yii::t('PostModule.base', 'Post'),
'description' => Yii::t('PostModule.base', 'Basic subsystem for workspace/user post.'),
'class' => 'application.modules_core.post.PostModule', 'class' => 'application.modules_core.post.PostModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -0,0 +1,9 @@
{
"id": "post",
"name": "Post",
"description": "Post Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -7,7 +7,7 @@
* @package humhub.modules_core.space * @package humhub.modules_core.space
* @since 0.5 * @since 0.5
*/ */
class SpaceModule extends CWebModule { class SpaceModule extends HWebModule {
public function init() { public function init() {
$this->setImport(array( $this->setImport(array(

View File

@ -0,0 +1,87 @@
<?php
/**
* HumHub
* Copyright © 2014 The HumHub Project
*
* The texts of the GNU Affero General Public License with an additional
* permission and of our proprietary license can be found at and
* in the LICENSE file you have received along with this program.
*
* According to our dual licensing model, this program can be used either
* under the terms of the GNU Affero General Public License, version 3,
* or under a proprietary license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/
/**
* This behavior should attached to a HWebModule when it provides a space module.
*
* @author luke
*/
class SpaceModuleBehavior extends CBehavior
{
/**
* Returns current space by context
*
* @return Space
*/
public function getSpace()
{
return Yii::app()->getController()->getSpace();
}
/**
* Checks if this module is enabled on given space.
*
* @param Space $space
* @return boolean
*/
public function isSpaceModuleEnabled(Space $space = null)
{
if ($space == null) {
$space = $this->getSpace();
}
return $space->isModuleEnabled($this->getOwner()->getId());
}
/**
* Returns module name for spaces of your module.
* You may want to overwrite it in your module.
*
* @return String
*/
public function getSpaceModuleName()
{
return $this->getOwner()->getName();
}
/**
* Returns module description for spaces of your module.
* You may want to overwrite it in your module.
*
* @return String
*/
public function getSpaceModuleDescription()
{
return $this->getOwner()->getDescription();
}
/**
* Returns module config url for spaces of your module.
* You may want to overwrite it in your module.
*
* @return String
*/
public function getSpaceModuleConfigUrl(Space $space)
{
return "";
}
}

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'space', 'id' => 'space',
'title' => Yii::t('SpaceModule.base', 'Spaces'),
'description' => Yii::t('SpaceModule.base', 'Spaces core'),
'class' => 'application.modules_core.space.SpaceModule', 'class' => 'application.modules_core.space.SpaceModule',
'import' => array( 'import' => array(
'application.modules_core.space.widgets.*', 'application.modules_core.space.widgets.*',

View File

@ -32,7 +32,8 @@
* @package humhub.modules_core.space.models * @package humhub.modules_core.space.models
* @since 0.5 * @since 0.5
*/ */
class Space extends HActiveRecordContentContainer implements ISearchable { class Space extends HActiveRecordContentContainer implements ISearchable
{
// Join Policies // Join Policies
const JOIN_POLICY_NONE = 0; // No Self Join Possible const JOIN_POLICY_NONE = 0; // No Self Join Possible
@ -54,7 +55,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return type * @return type
*/ */
public function behaviors() { public function behaviors()
{
return array( return array(
'HGuidBehavior' => array( 'HGuidBehavior' => array(
'class' => 'application.behaviors.HGuidBehavior', 'class' => 'application.behaviors.HGuidBehavior',
@ -67,21 +69,24 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param string $className active record class name. * @param string $className active record class name.
* @return Space the static model class * @return Space the static model class
*/ */
public static function model($className = __CLASS__) { public static function model($className = __CLASS__)
{
return parent::model($className); return parent::model($className);
} }
/** /**
* @return string the associated database table name * @return string the associated database table name
*/ */
public function tableName() { public function tableName()
{
return 'space'; return 'space';
} }
/** /**
* @return array validation rules for model attributes. * @return array validation rules for model attributes.
*/ */
public function rules() { public function rules()
{
$rules = array(); $rules = array();
@ -124,7 +129,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* @return array relational rules. * @return array relational rules.
*/ */
public function relations() { public function relations()
{
// NOTE: you may need to adjust the relation name and the related // NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below. // class name for the relations automatically generated below.
return array( return array(
@ -154,7 +160,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* @return array customized attribute labels (name=>label) * @return array customized attribute labels (name=>label)
*/ */
public function attributeLabels() { public function attributeLabels()
{
return array( return array(
'id' => 'ID', 'id' => 'ID',
'wall_id' => 'Wall', 'wall_id' => 'Wall',
@ -178,7 +185,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* Scopes * Scopes
* *
*/ */
public function scopes() { public function scopes()
{
return array( return array(
// Coming soon // Coming soon
'active' => array( 'active' => array(
@ -200,7 +208,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $limit * @param type $limit
* @return User * @return User
*/ */
public function recently($limit = 10) { public function recently($limit = 10)
{
$this->getDbCriteria()->mergeWith(array( $this->getDbCriteria()->mergeWith(array(
'order' => 'created_at DESC', 'order' => 'created_at DESC',
'limit' => $limit, 'limit' => $limit,
@ -212,7 +221,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* Retrieves a list of models based on the current search/filter conditions. * Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/ */
public function search() { public function search()
{
$criteria = new CDbCriteria; $criteria = new CDbCriteria;
$criteria->compare('id', $this->id); $criteria->compare('id', $this->id);
$criteria->compare('wall_id', $this->wall_id); $criteria->compare('wall_id', $this->wall_id);
@ -238,7 +248,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* After Save Addons * After Save Addons
*/ */
protected function afterSave() { protected function afterSave()
{
// Try To Delete Search Model // Try To Delete Search Model
HSearch::getInstance()->deleteModel($this); HSearch::getInstance()->deleteModel($this);
@ -254,13 +265,14 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Before deletion of a Space * Before deletion of a Space
*/ */
protected function beforeDelete() { protected function beforeDelete()
{
if (parent::beforeDelete()) { if (parent::beforeDelete()) {
foreach (SpaceSetting::model()->findAllByAttributes(array('space_id'=>$this->id)) as $spaceSetting) { foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) {
$spaceSetting->delete(); $spaceSetting->delete();
} }
HSearch::getInstance()->deleteModel($this); HSearch::getInstance()->deleteModel($this);
return true; return true;
} }
@ -270,7 +282,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* Delete a Space * Delete a Space
* *
*/ */
public function delete() { public function delete()
{
$this->getProfileImage()->delete(); $this->getProfileImage()->delete();
@ -314,7 +327,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return type * @return type
*/ */
public function insert($attributes = null) { public function insert($attributes = null)
{
if (parent::insert($attributes)) { if (parent::insert($attributes)) {
@ -340,7 +354,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param $userId User Id of User * @param $userId User Id of User
*/ */
public function isFollowedBy($userId = "") { public function isFollowedBy($userId = "")
{
// Take current userid if none is given // Take current userid if none is given
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -358,7 +373,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param $userId User Id of User * @param $userId User Id of User
*/ */
public function canJoin($userId = "") { public function canJoin($userId = "")
{
// Take current userid if none is given // Take current userid if none is given
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -379,7 +395,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param $userId User Id of User * @param $userId User Id of User
*/ */
public function canJoinFree($userId = "") { public function canJoinFree($userId = "")
{
// Take current userid if none is given // Take current userid if none is given
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -401,7 +418,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function canWrite($userId = "") { public function canWrite($userId = "")
{
// No writes allowed for archived workspaces // No writes allowed for archived workspaces
if ($this->status == Space::STATUS_ARCHIVED) if ($this->status == Space::STATUS_ARCHIVED)
@ -424,7 +442,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function isMember($userId = "") { public function isMember($userId = "")
{
// Take current userid if none is given // Take current userid if none is given
if ($userId == "") if ($userId == "")
@ -446,7 +465,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function isAdmin($userId = "") { public function isAdmin($userId = "")
{
if ($userId == 0) if ($userId == 0)
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -471,7 +491,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function setOwner($userId = "") { public function setOwner($userId = "")
{
if ($userId == 0) if ($userId == 0)
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -489,7 +510,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return type * @return type
*/ */
public function getOwner() { public function getOwner()
{
$user = User::model()->findByPk($this->created_by); $user = User::model()->findByPk($this->created_by);
return $user; return $user;
@ -501,7 +523,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function setAdmin($userId = "") { public function setAdmin($userId = "")
{
if ($userId == 0) if ($userId == 0)
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -521,7 +544,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function canInvite($userId = "") { public function canInvite($userId = "")
{
if ($userId == 0) if ($userId == 0)
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -545,7 +569,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @return type * @return type
*/ */
public function canShare($userId = "") { public function canShare($userId = "")
{
// There is no visibility for guests, so sharing is useless anyway. // There is no visibility for guests, so sharing is useless anyway.
if ($this->visibility != Space::VISIBILITY_ALL) if ($this->visibility != Space::VISIBILITY_ALL)
@ -567,7 +592,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* If none Record is found, null is given * If none Record is found, null is given
*/ */
public function getMembership($userId = "") { public function getMembership($userId = "")
{
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -586,7 +612,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Is given User owner of this Space * Is given User owner of this Space
*/ */
public function isOwner($userId = "") { public function isOwner($userId = "")
{
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -602,7 +629,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param $userId UserId of User to Remove * @param $userId UserId of User to Remove
*/ */
public function removeMember($userId = "") { public function removeMember($userId = "")
{
if ($userId == "") if ($userId == "")
$userId = Yii::app()->user->id; $userId = Yii::app()->user->id;
@ -656,7 +684,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param type $userId * @param type $userId
*/ */
public function addMember($userId) { public function addMember($userId)
{
$user = User::model()->findByPk($userId); $user = User::model()->findByPk($userId);
@ -718,7 +747,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @param type $originatorUserId * @param type $originatorUserId
*/ */
public function inviteMember($userId, $originatorUserId) { public function inviteMember($userId, $originatorUserId)
{
$membership = $this->getMembership($userId); $membership = $this->getMembership($userId);
@ -765,7 +795,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $email * @param type $email
* @param type $originatorUserId * @param type $originatorUserId
*/ */
public function inviteMemberByEMail($email, $originatorUserId) { public function inviteMemberByEMail($email, $originatorUserId)
{
// Invalid E-Mail // Invalid E-Mail
$validator = new CEmailValidator; $validator = new CEmailValidator;
@ -808,7 +839,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param type $userId * @param type $userId
* @param type $message * @param type $message
*/ */
public function requestMembership($userId, $message = "") { public function requestMembership($userId, $message = "")
{
// Add Membership // Add Membership
$membership = new SpaceMembership; $membership = new SpaceMembership;
@ -828,7 +860,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* Checks if there is already a wall created for this workspace. * Checks if there is already a wall created for this workspace.
* If not, a new wall will be created and automatically assigned. * If not, a new wall will be created and automatically assigned.
*/ */
public function checkWall() { public function checkWall()
{
// Check if wall exists // Check if wall exists
if ($this->wall == null) { if ($this->wall == null) {
@ -856,7 +889,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return Array * @return Array
*/ */
public function getSearchAttributes() { public function getSearchAttributes()
{
return array( return array(
// Assignment // Assignment
@ -876,14 +910,16 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Returns the Search Result Output * Returns the Search Result Output
*/ */
public function getSearchResult() { public function getSearchResult()
{
return Yii::app()->getController()->widget('application.modules_core.space.widgets.SpaceSearchResultWidget', array('space' => $this), true); return Yii::app()->getController()->widget('application.modules_core.space.widgets.SpaceSearchResultWidget', array('space' => $this), true);
} }
/** /**
* Returns the Admins of this Space * Returns the Admins of this Space
*/ */
public function getAdmins() { public function getAdmins()
{
$admins = array(); $admins = array();
@ -900,7 +936,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* Counts all Content Items related to this workspace except of Activities. * Counts all Content Items related to this workspace except of Activities.
* Additonally Comments (normally ContentAddon) will be included. * Additonally Comments (normally ContentAddon) will be included.
*/ */
public function countItems() { public function countItems()
{
$count = 0; $count = 0;
$count += Content::model()->countByAttributes(array('space_id' => $this->id), 'object_model != :activityModel', array(':activityModel' => 'Activity')); $count += Content::model()->countByAttributes(array('space_id' => $this->id), 'object_model != :activityModel', array(':activityModel' => 'Activity'));
@ -914,7 +951,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return Integer * @return Integer
*/ */
public function countPosts() { public function countPosts()
{
/* /*
$criteria = new CDbCriteria(); $criteria = new CDbCriteria();
$criteria->condition = "content.space_id=:space_id"; $criteria->condition = "content.space_id=:space_id";
@ -927,7 +965,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Sets Comments Count for this workspace * Sets Comments Count for this workspace
*/ */
public function getCommentCount() { public function getCommentCount()
{
$cacheId = "workspaceCommentCount_" . $this->id; $cacheId = "workspaceCommentCount_" . $this->id;
$cacheValue = Yii::app()->cache->get($cacheId); $cacheValue = Yii::app()->cache->get($cacheId);
@ -943,7 +982,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Returns an array with assigned Tags * Returns an array with assigned Tags
*/ */
public function getTags() { public function getTags()
{
// split tags string into individual tags // split tags string into individual tags
return preg_split("/[;,# ]+/", $this->tags); return preg_split("/[;,# ]+/", $this->tags);
@ -952,7 +992,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Archive this Space * Archive this Space
*/ */
public function archive() { public function archive()
{
$this->status = self::STATUS_ARCHIVED; $this->status = self::STATUS_ARCHIVED;
$this->save(); $this->save();
} }
@ -960,7 +1001,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Unarchive this Space * Unarchive this Space
*/ */
public function unarchive() { public function unarchive()
{
$this->status = self::STATUS_ENABLED; $this->status = self::STATUS_ENABLED;
$this->save(); $this->save();
} }
@ -971,32 +1013,29 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* @param array $parameters * @param array $parameters
* @return string url * @return string url
*/ */
public function getUrl($parameters = array()) { public function getUrl($parameters = array())
{
$parameters['sguid'] = $this->guid; $parameters['sguid'] = $this->guid;
return Yii::app()->createUrl('//space/space', $parameters); return Yii::app()->createUrl('//space/space', $parameters);
} }
/** /**
* Returns a list of available workspace modules * Collects a list of all modules which are available for this space
* *
* @return array * @return array
*/ */
public function getAvailableModules() { public function getAvailableModules()
{
$availableModules = array(); $modules = array();
// Loop over all enabled modules foreach (Yii::app()->moduleManager->getEnabledModules() as $moduleId => $module) {
foreach (Yii::app()->moduleManager->getEnabledModules() as $moduleId => $definition) { if (array_key_exists('SpaceModuleBehavior', $module->behaviors())) {
$modules[$module->getId()] = $module;
if (isset($definition['spaceModules']) && is_array($definition['spaceModules'])) {
foreach ($definition['spaceModules'] as $moduleId => $moduleInfo) {
$availableModules[$moduleId] = $moduleInfo;
}
} }
} }
return $availableModules; return $modules;
} }
/** /**
@ -1004,7 +1043,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @return array * @return array
*/ */
public function getEnabledModules() { public function getEnabledModules()
{
$modules = array(); $modules = array();
foreach (SpaceApplicationModule::model()->findAllByAttributes(array('space_id' => $this->id)) as $SpaceModule) { foreach (SpaceApplicationModule::model()->findAllByAttributes(array('space_id' => $this->id)) as $SpaceModule) {
@ -1014,6 +1054,7 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
$modules[] = $moduleId; $modules[] = $moduleId;
} }
} }
return $modules; return $modules;
} }
@ -1022,7 +1063,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
* *
* @param type $moduleId * @param type $moduleId
*/ */
public function isModuleEnabled($moduleId) { public function isModuleEnabled($moduleId)
{
// Not enabled globally // Not enabled globally
if (!array_key_exists($moduleId, $this->getAvailableModules())) { if (!array_key_exists($moduleId, $this->getAvailableModules())) {
@ -1041,7 +1083,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
/** /**
* Installs a Module * Installs a Module
*/ */
public function installModule($moduleId) { public function installModule($moduleId)
{
// Not enabled globally // Not enabled globally
if (!array_key_exists($moduleId, $this->getAvailableModules())) { if (!array_key_exists($moduleId, $this->getAvailableModules())) {
@ -1068,14 +1111,16 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
return true; return true;
} }
public function onInstallModule($event) { public function onInstallModule($event)
{
$this->raiseEvent('onInstallModule', $event); $this->raiseEvent('onInstallModule', $event);
} }
/** /**
* Uninstalls a Module * Uninstalls a Module
*/ */
public function uninstallModule($moduleId) { public function uninstallModule($moduleId)
{
// Not enabled globally // Not enabled globally
if (!array_key_exists($moduleId, $this->getAvailableModules())) { if (!array_key_exists($moduleId, $this->getAvailableModules())) {
@ -1098,7 +1143,8 @@ class Space extends HActiveRecordContentContainer implements ISearchable {
return true; return true;
} }
public function onUninstallModule($event) { public function onUninstallModule($event)
{
$this->raiseEvent('onUninstallModule', $event); $this->raiseEvent('onUninstallModule', $event);
} }

View File

@ -0,0 +1,9 @@
{
"id": "space",
"name": "Space",
"description": "Space Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -6,27 +6,27 @@
<?php echo Yii::t('SpaceModule.base', 'Enhance this space with modules.'); ?><br> <?php echo Yii::t('SpaceModule.base', 'Enhance this space with modules.'); ?><br>
<?php foreach ($this->getSpace()->getAvailableModules() as $moduleId => $moduleInfo): ?> <?php foreach ($this->getSpace()->getAvailableModules() as $moduleId => $module): ?>
<div class="media"> <div class="media">
<img class="media-object img-rounded pull-left" data-src="holder.js/64x64" alt="64x64" <img class="media-object img-rounded pull-left" data-src="holder.js/64x64" alt="64x64"
style="width: 64px; height: 64px;" style="width: 64px; height: 64px;"
src="<?php echo Yii::app()->baseUrl; ?>/uploads/profile_image/default_module.jpg"> src="<?php echo Yii::app()->baseUrl; ?>/uploads/profile_image/default_module.jpg">
<div class="media-body"> <div class="media-body">
<h4 class="media-heading"><?php echo $moduleInfo['title']; ?> <h4 class="media-heading"><?php echo $module->getSpaceModuleName(); ?>
<?php if ($this->getSpace()->isModuleEnabled($moduleId)) : ?> <?php if ($this->getSpace()->isModuleEnabled($moduleId)) : ?>
<small><span class="label label-success"><?php echo Yii::t('SpaceModule.base', 'Activated'); ?></span></small> <small><span class="label label-success"><?php echo Yii::t('SpaceModule.base', 'Activated'); ?></span></small>
<?php endif; ?> <?php endif; ?>
</h4> </h4>
<p><?php echo $moduleInfo['description']; ?></p> <p><?php echo $module->getSpaceModuleDescription(); ?></p>
<?php if ($this->getSpace()->isModuleEnabled($moduleId)) : ?> <?php if ($this->getSpace()->isModuleEnabled($moduleId)) : ?>
<?php echo CHtml::link(Yii::t('base', 'Disable'), array('//space/admin/disableModule', 'moduleId' => $moduleId, 'sguid' => $this->getSpace()->guid), array('class' => 'btn btn-sm btn-primary', 'onClick' => 'return moduleDisableWarning()')); ?> <?php echo CHtml::link(Yii::t('base', 'Disable'), array('//space/admin/disableModule', 'moduleId' => $moduleId, 'sguid' => $this->getSpace()->guid), array('class' => 'btn btn-sm btn-primary', 'onClick' => 'return moduleDisableWarning()')); ?>
<?php if (isset($moduleInfo['configRoute'])) : ?> <?php if ($module->getSpaceModuleConfigUrl($this->getSpace()) != "") : ?>
<?php <?php
echo CHtml::link( echo CHtml::link(
Yii::t('SpaceModule.base', 'Configure'), $this->createUrl($moduleInfo['configRoute'], array('sguid' => $this->getSpace()->guid)), array('class' => 'btn btn-default') Yii::t('SpaceModule.base', 'Configure'), $module->getSpaceModuleConfigUrl($this->getSpace()), array('class' => 'btn btn-default')
); );
?> ?>
<?php endif; ?> <?php endif; ?>

View File

@ -6,7 +6,7 @@
* @since 0.5 * @since 0.5
* @author Luke * @author Luke
*/ */
class UserModule extends CWebModule { class UserModule extends HWebModule {
public function init() { public function init() {
$this->setImport(array( $this->setImport(array(

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'user', 'id' => 'user',
'title' => Yii::t('UserModule.base', 'User'),
'description' => Yii::t('SpaceModule.base', 'Users core'),
'class' => 'application.modules_core.user.UserModule', 'class' => 'application.modules_core.user.UserModule',
'isCoreModule' => true, 'isCoreModule' => true,
'import' => array( 'import' => array(

View File

@ -24,9 +24,11 @@
* @package humhub.modules_core.user.controllers * @package humhub.modules_core.user.controllers
* @since 0.5 * @since 0.5
*/ */
class AuthController extends Controller { class AuthController extends Controller
{
public function actions() { public function actions()
{
return array( return array(
// captcha action renders the CAPTCHA image displayed on the password recovery page // captcha action renders the CAPTCHA image displayed on the password recovery page
'captcha' => array( 'captcha' => array(
@ -39,7 +41,8 @@ class AuthController extends Controller {
/** /**
* Displays the login page * Displays the login page
*/ */
public function actionLogin() { public function actionLogin()
{
// If user is already logged in, redirect him to the dashboard // If user is already logged in, redirect him to the dashboard
if (!Yii::app()->user->isGuest) { if (!Yii::app()->user->isGuest) {
@ -58,7 +61,7 @@ class AuthController extends Controller {
$model = new AccountLoginForm; $model = new AccountLoginForm;
//TODO: Solve this via events! //TODO: Solve this via events!
if (Yii::app()->moduleManager->isEnabled('zsso')) { if (Yii::app()->getModule('zsso') != null) {
ZSsoModule::beforeActionLogin(); ZSsoModule::beforeActionLogin();
} }
@ -130,7 +133,8 @@ class AuthController extends Controller {
* *
* @todo check local auth_mode * @todo check local auth_mode
*/ */
public function actionRecoverPassword() { public function actionRecoverPassword()
{
// Disable Sublayout // Disable Sublayout
$this->subLayout = ""; $this->subLayout = "";
@ -169,7 +173,8 @@ class AuthController extends Controller {
* *
* This action is called after e-mail validation. * This action is called after e-mail validation.
*/ */
public function actionCreateAccount() { public function actionCreateAccount()
{
$_POST = Yii::app()->input->stripClean($_POST); $_POST = Yii::app()->input->stripClean($_POST);
@ -212,7 +217,7 @@ class AuthController extends Controller {
'type' => (HSetting::Get('defaultUserGroup', 'authentication_internal')) ? 'hidden' : 'dropdownlist', 'type' => (HSetting::Get('defaultUserGroup', 'authentication_internal')) ? 'hidden' : 'dropdownlist',
'class' => 'form-control', 'class' => 'form-control',
'items' => CHtml::listData($groupModels, 'id', 'name'), 'items' => CHtml::listData($groupModels, 'id', 'name'),
'value' => (HSetting::Get('defaultUserGroup', 'authentication_internal')) ? HSetting::Get('defaultUserGroup', 'authentication_internal') : '', 'value' => (HSetting::Get('defaultUserGroup', 'authentication_internal')) ? HSetting::Get('defaultUserGroup', 'authentication_internal') : '',
), ),
), ),
); );
@ -287,7 +292,8 @@ class AuthController extends Controller {
* Logouts a User * Logouts a User
* *
*/ */
public function actionLogout() { public function actionLogout()
{
Yii::app()->user->logout(); Yii::app()->user->logout();
@ -302,7 +308,8 @@ class AuthController extends Controller {
* *
* Can also used as a kind of keep alive. * Can also used as a kind of keep alive.
*/ */
public function actionCheckSessionState() { public function actionCheckSessionState()
{
$out = array(); $out = array();
$out['loggedIn'] = false; $out['loggedIn'] = false;
@ -318,7 +325,8 @@ class AuthController extends Controller {
* Allows third party applications to convert a valid sessionId * Allows third party applications to convert a valid sessionId
* into a username. * into a username.
*/ */
public function actionGetSessionUserJson() { public function actionGetSessionUserJson()
{
$sessionId = Yii::app()->request->getQuery('sessionId'); $sessionId = Yii::app()->request->getQuery('sessionId');

View File

@ -0,0 +1,9 @@
{
"id": "user",
"name": "User",
"description": "User Core",
"keywords": [
"core"
],
"version": "1.0"
}

View File

@ -10,7 +10,7 @@
* @since 0.5 * @since 0.5
* @author Luke * @author Luke
*/ */
class WallModule extends CWebModule { class WallModule extends HWebModule {
/** /**
* Inits the wall module * Inits the wall module

View File

@ -2,8 +2,6 @@
Yii::app()->moduleManager->register(array( Yii::app()->moduleManager->register(array(
'id' => 'wall', 'id' => 'wall',
'title' => Yii::t('WallModule.base', 'Wall'),
'description' => Yii::t('WallModule.base', 'Adds the wall/streaming core module.'),
'class' => 'application.modules_core.wall.WallModule', 'class' => 'application.modules_core.wall.WallModule',
'import' => array( 'import' => array(
'application.modules_core.wall.*', 'application.modules_core.wall.*',

View File

@ -0,0 +1,9 @@
{
"id": "wall",
"name": "Wall",
"description": "Wall Core",
"keywords": [
"core"
],
"version": "1.0"
}