/web/system/ExtensionsModule/Controller/AdminController.php
PHP | 1383 lines | 968 code | 178 blank | 237 comment | 179 complexity | cc2777e2e7550eb6e3eb84e7c49e345d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MIT
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Copyright Zikula Foundation 2009 - Zikula Application Framework
- *
- * This work is contributed to the Zikula Foundation under one or more
- * Contributor Agreements and licensed to You under the following license:
- *
- * @license GNU/LGPLv3 (or at your option, any later version).
- * @package Zikula
- *
- * Please see the NOTICE file distributed with this source code for further
- * information regarding copyright and licensing.
- */
- namespace ExtensionsModule\Controller;
- use SecurityUtil, Zikula_View, ModUtil, LogUtil, ZLanguage, System, PluginUtil;
- use ExtensionsModule\Util as ExtensionsUtil;
- /**
- * Extensions_Controller_Admin class.
- */
- class AdminController extends \Zikula\Framework\Controller\AbstractController
- {
- /**
- * Post initialise.
- *
- * @return void
- */
- protected function postInitialize()
- {
- // In this controller we do not want caching.
- $this->view->setCaching(Zikula_View::CACHE_DISABLED);
- }
- /**
- * Extensions Module main admin function
- *
- * @return string HTML output string
- */
- public function indexAction()
- {
- // Security check will be done in view()
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view'));
- }
- /**
- * Extensions_admin_modify - modify a module.
- *
- * @return string HTML output string.
- */
- public function modifyAction()
- {
- $id = (int) $this->request->query->get('id', null);
- if (!is_numeric($id)) {
- return LogUtil::registerArgsError(ModUtil::url('Extensions', 'admin', 'view'));
- }
- $obj = ModUtil::getInfo($id);
- if (!isset($id) || $obj == false) {
- return LogUtil::registerError($this->__('Error! No such module ID exists.'),
- 404,
- ModUtil::url('Extensions', 'admin', 'modify', array('id' => $id)));
- }
- if (!SecurityUtil::checkPermission('Extensions::', "$obj[name]::$id", ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- $restore = (bool)$this->request->query->get('restore', false);
- if ($restore) {
- // load the version array
- $baseDir = ($obj['type'] == ModUtil::TYPE_SYSTEM) ? 'system' : 'modules';
- // load gettext domain for 3rd party modules
- if ($baseDir == 'modules' && is_dir("modules/$obj[directory]/locale")) {
- // This is required here since including pnversion automatically executes the pnversion code
- // this results in $this->__() caching the result before the domain is bounded. Will not occur in zOO
- // since loading is self contained in each zOO application.
- ZLanguage::bindModuleDomain($obj['directory']);
- }
- $modversion = ExtensionsUtil::getVersionMeta($obj['directory'], $baseDir);
- // load defaults
- $name = (isset($modversion['name']) ? $modversion['name'] : '');
- $displayname = (isset($modversion['displayname']) ? $modversion['displayname'] : $name);
- $url = (isset($modversion['url']) ? $modversion['url'] : $displayname);
- $description = (isset($modversion['description']) ? $modversion['description'] : '');
- $obj = array(
- 'id' => $id,
- 'displayname' => $displayname,
- 'url' => $url,
- 'description' => $description
- );
- }
- $this->view->assign($obj);
- // Return the output that has been generated by this function
- return $this->response($this->view->fetch('Admin/modify.tpl'));
- }
- /**
- * Extensions_admin_update - update a module
- * @return string HTML output string
- * @param int 'id' module id
- * @param string 'newdisplayname' new display name of the module
- * @param string 'newdescription' new description of the module
- */
- public function updateAction()
- {
- $this->checkCsrfToken();
- // Get parameters
- $id = (int) $this->request->request->get('id', null);
- $newdisplayname = $this->request->request->get('newdisplayname', null);
- $newdescription = $this->request->request->get('newdescription', null);
- $newurl = $this->request->request->get('newurl', null);
- // Pass to API
- if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'update', array(
- 'id' => $id,
- 'displayname' => $newdisplayname,
- 'description' => $newdescription,
- 'url' => $newurl))) {
- // Success
- LogUtil::registerStatus($this->__('Done! Saved module information.'));
- } else {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'modify', array('id' => $id)));
- }
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view'));
- }
- /**
- * Extensions_admin_view - list modules and current settings
- * @return string HTML output string
- */
- public function viewAction()
- {
- // Security check
- if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- $session = $this->request->getSession();
- // Get parameters from whatever input we need.
- $modinfo = $this->getModInfo();
- $startnum = (int) $this->request->query->get('startnum', null);
- $letter = $this->request->query->get('letter', null);
- $state = $this->request->query->get('state', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : $session->get('state', null));
- $sort = $this->request->query->get('sort', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : $session->get('sort', null));
- $sortdir = $this->request->query->get('sortdir', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : $session->get('sortdir', null));
- // parameter for used sort order
- if ($sort != 'name' && $sort != 'displayname') $sort = 'name';
- if ($sortdir != 'ASC' && $sortdir != 'DESC') $sortdir = 'ASC';
- // save the current values
- $session->set('state', $state);
- $session->set('sort', $sort);
- $session->set('sortdir', $sortdir);
- // do some clean up
- $session->remove('interactive_init');
- $session->remove('interactive_remove');
- $session->remove('interactive_upgrade');
- if ($this->container['multisites.enabled'] != 1 || ($this->container['multisites.mainsiteurl'] == $this->request->query->get('sitedns', null) && $this->container['multisites.based_on_domains'] == 0) || ($this->container['multisites.mainsiteurl'] == $_SERVER['HTTP_HOST'] && $this->container['multisites.based_on_domains'] == 1)) {
- // always regenerate modules list
- $filemodules = ModUtil::apiFunc('ExtensionsModule', 'admin', 'getfilemodules');
- $inconsistencies = ModUtil::apiFunc('ExtensionsModule', 'admin', 'checkconsistency', array('filemodules' => $filemodules));
- if (!(empty($inconsistencies['errors_modulenames']) && empty($inconsistencies['errors_displaynames']))) {
- $this->view->assign('errors_modulenames', $inconsistencies['errors_modulenames'])
- ->assign('errors_displaynames', $inconsistencies['errors_displaynames']);
- return $this->response($this->view->fetch('Admin/regenerate_errors.tpl'));
- }
- // No inconsistencies, so we can regenerate modules
- $defaults = (int) $this->request->query->get('defaults', false);
- if (!ModUtil::apiFunc('ExtensionsModule', 'admin', 'regenerate', array('filemodules' => $filemodules, 'defaults' => $defaults))) {
- LogUtil::registerError($this->__('Errors were detected regenerating the modules list from file system.'));
- }
- }
- // assign the state filter
- $this->view->assign('state', $state);
- // Get list of modules
- $mods = ModUtil::apiFunc('ExtensionsModule', 'admin', 'listmodules',
- array('startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state,
- 'numitems' => $this->getVar('itemsperpage'),
- 'sortdir' => $sortdir,
- 'sort' => $sort));
- // generate an auth key to use in urls
- $csrftoken = SecurityUtil::generateCsrfToken($this->container, true);
- $moduleinfo = array();
- if (!empty($mods)) {
- foreach ($mods as $mod) {
- $mod = $mod->toArray();
- // Add applicable actions
- $actions = array();
- if (SecurityUtil::checkPermission('Extensions::', "$mod[name]::$mod[id]", ACCESS_ADMIN)) {
- switch ($mod['state']) {
- case ModUtil::STATE_ACTIVE:
- if (!ModUtil::apiFunc('ExtensionsModule', 'admin', 'iscoremodule', array('modulename' => $mod['name']))) {
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'deactivate', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'csrftoken' => $csrftoken,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => 'folder_red.png',
- 'title' => $this->__f('Deactivate \'%s\' module', $mod['name']));
- }
- if (PluginUtil::hasModulePlugins($mod['name'])) {
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'viewPlugins', array(
- 'bymodule' => $mod['name'])),
- 'image' => 'blockdevice.png',
- 'title' => $this->__f('Plugins for \'%s\'', $mod['name']));
- }
- break;
- case ModUtil::STATE_INACTIVE:
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'activate', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'csrftoken' => $csrftoken,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => 'folder_green.png',
- 'title' => $this->__f('Activate \'%s\'', $mod['name']));
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'remove', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => '14_layer_deletelayer.png',
- 'title' => $this->__f('Uninstall \'%s\' module', $mod['name']));
- break;
- case ModUtil::STATE_MISSING:
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'remove', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => '14_layer_deletelayer.png',
- 'title' => $this->__f('Remove \'%s\' module', $mod['name']));
- break;
- case ModUtil::STATE_UPGRADED:
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'upgrade', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'csrftoken' => $csrftoken,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => 'folder_favorites.png',
- 'title' => $this->__f('Upgrade \'%s\'', $mod['name']));
- break;
- case ModUtil::STATE_INVALID:
- // nothing to do, remove manually
- // future wish list, allow removal if FS is writable
- /*
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'remove', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'authid' => $authid,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => '14_layer_deletelayer.png',
- 'title' => $this->__('Remove module')); */
- break;
- case ModUtil::STATE_NOTALLOWED:
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'remove', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'csrftoken' => $csrftoken,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => '14_layer_deletelayer.png',
- 'title' => $this->__f('Remove \'%s\' module', $mod['name']));
- break;
- case ModUtil::STATE_UNINITIALISED:
- default:
- if ($mod['state'] < 10) {
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'initialise', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'csrftoken' => $csrftoken,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => 'folder_new.png',
- 'title' => $this->__f('Install \'%s\'', $mod['name']));
- // if ($this->container['multisites.enabled'] != 1 || ($this->container['multisites.mainsiteurl'] == $this->request->query->get('sitedns', null) && $this->container['multisites.based_on_domains'] == 0) || ($this->container['multisites.mainsiteurl'] == $_SERVER['HTTP_HOST'] && $this->container['multisites.based_on_domains'] == 1)) {
- // $actions[] = array(
- // 'url' => ModUtil::url('Extensions', 'admin', 'remove', array(
- // 'id' => $mod['id'],
- // 'startnum' => $startnum,
- // 'authid' => $authid,
- // 'letter' => $letter,
- // 'state' => $state)),
- // 'image' => '14_layer_deletelayer.png',
- // 'title' => $this->__('Remove module'));
- // }
- } else {
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'compinfo', array(
- 'id' => $mod['id'],
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)),
- 'image' => 'documentinfo.png',
- 'title' => $this->__f('Incompatible version: \'%s\'', $mod['name']));
- }
- break;
- }
- // RNG: can't edit an invalid module
- if ($mod['state'] != ModUtil::STATE_INVALID) {
- $actions[] = array(
- 'url' => ModUtil::url('Extensions', 'admin', 'modify', array(
- 'id' => $mod['id'])),
- 'image' => 'xedit.png',
- 'title' => $this->__f('Edit \'%s\'', $mod['name']));
- }
- }
- // Translate state
- switch ($mod['state']) {
- case ModUtil::STATE_INACTIVE:
- $status = $this->__('Inactive');
- $statusimage = 'yellowled.png';
- break;
- case ModUtil::STATE_ACTIVE:
- $status = $this->__('Active');
- $statusimage = 'greenled.png';
- break;
- case ModUtil::STATE_MISSING:
- $status = $this->__('Files missing');
- $statusimage = 'redled.png';
- break;
- case ModUtil::STATE_UPGRADED:
- $status = $this->__('New version');
- $statusimage = 'redled.png';
- break;
- case ModUtil::STATE_INVALID:
- $status = $this->__('Invalid structure');
- $statusimage = 'redled.png';
- break;
- case ModUtil::STATE_NOTALLOWED:
- $status = $this->__('Not allowed');
- $statusimage = 'folder_red.png';
- break;
- case ModUtil::STATE_UNINITIALISED:
- default:
- if ($mod['state'] > 10) {
- $status = $this->__('Incompatible');
- $statusimage = 'folder_red.png';
- } else {
- $status = $this->__('Not installed');
- $statusimage = 'redled.png';
- }
- break;
- }
- // get new version number for ModUtil::STATE_UPGRADED
- if ($mod['state'] == ModUtil::STATE_UPGRADED) {
- $mod['newversion'] = $filemodules[$mod['directory']]['version'];
- }
- $moduleinfo[] = array(
- 'modinfo' => $mod,
- 'status' => $status,
- 'statusimage' => $statusimage,
- 'options' => $actions);
- }
- }
- $this->view->assign('multi', $this->container['multisites.enabled'])
- ->assign('sort', $sort)
- ->assign('sortdir', $sortdir)
- ->assign('modules', $moduleinfo);
- // Assign the values for the smarty plugin to produce a pager.
- $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('ExtensionsModule', 'admin', 'countitems', array('letter' => $letter, 'state' => $state)),
- 'itemsperpage' => $this->getVar('itemsperpage')));
- // Return the output that has been generated by this function
- return $this->response($this->view->fetch('Admin/view.tpl'));
- }
- /**
- * Extensions_admin_view - list modules and current settings
- *
- * This function is an alias to Admin/view as pnphpbb calls this
- * function name directly on the install
- *
- * @see Admin/view
- * @return string HTML output string
- */
- public function listviewAction()
- {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view'));
- }
- /**
- * Initialise a module.
- *
- * @param int 'id' module id
- * @return bool true
- */
- public function initialiseAction()
- {
- $csrftoken = $this->request->get('csrftoken');
- $this->checkCsrfToken($csrftoken);
- // Get parameters from whatever input we need
- $id = (int) $this->request->get('id', 0);
- $objectid = (int) $this->request->get('objectid', 0);
- $confirmation = (bool) $this->request->get('confirmation', false);
- $startnum = (int) $this->request->get('startnum');
- $letter = $this->request->get('letter');
- $state = (int)$this->request->get('state');
- if ($objectid) {
- $id = $objectid;
- }
- // assign any dependencies - filtering out non-active module dependents
- // when getting here without a valid id we are in interactive init mode and then
- // the dependencies checks have been done before already
- $fataldependency = false;
- if ($id != 0) {
- $dependencies = ModUtil::apiFunc('ExtensionsModule', 'admin', 'getdependencies', array('modid' => $id));
- $modulenotfound = false;
- if (!$confirmation && $dependencies) {
- foreach ($dependencies as $key => $dependency) {
- $dependencies[$key] = $dependency->toArray();
- $dependencies[$key]['insystem'] = true;
- $modinfo = ModUtil::getInfoFromName($dependency['modname']);
- $base = ($modinfo['type'] == ModUtil::TYPE_MODULE) ? 'modules' : 'system';
- if (is_dir("$base/$dependency[modname]")) {
- $minok = 0;
- $maxok = 0;
- $modversion = ExtensionsUtil::getVersionMeta($dependency['modname'], $base);
- if (!empty($dependency['minversion'])) {
- $minok = version_compare($modversion['version'], $dependency['minversion']);
- }
- if (!empty($dependency['maxversion'])) {
- $maxok = version_compare($dependency['maxversion'], $modversion['version']);
- }
- if ($minok == -1 || $maxok == -1) {
- if ($dependency['status'] == ModUtil::DEPENDENCY_REQUIRED) {
- $fataldependency = true;
- } else {
- unset($dependencies[$key]);
- }
- } else {
- $dependencies[$key] = array_merge($dependencies[$key], $modinfo);
- // if this module is already installed, don't display it in the list of dependencies.
- if (isset($dependencies[$key]['state']) && ($dependencies[$key]['state'] > ModUtil::STATE_UNINITIALISED && $dependencies[$key]['state'] < ModUtil::STATE_NOTALLOWED)) {
- unset($dependencies[$key]);
- }
- }
- } elseif (!empty($modinfo)) {
- $dependencies[$key] = array_merge($dependencies[$key], $modinfo);
- } else {
- $dependencies[$key]['insystem'] = false;
- $modulenotfound = true;
- if ($dependency['status'] == ModUtil::DEPENDENCY_REQUIRED) {
- $fataldependency = true;
- }
- }
- }
- $this->view->assign('fataldependency', $fataldependency);
- // we have some dependencies so let's warn the user about these
- if (!empty($dependencies)) {
- return $this->response($this->view->assign('id', $id)
- ->assign('dependencies', $dependencies)
- ->assign('modulenotfound', $modulenotfound)
- ->fetch('Admin/initialise.tpl'));
- }
- } else {
- $dependencies = (array)$this->request->request->get('dependencies', array());
- }
- }
- $session = $this->request->getSession();
- $interactive_init = $session->get('interactive_init');
- $interactive_init = (empty($interactive_init)) ? false : true;
- if ($interactive_init == false) {
- $session->set('modules_id', $id);
- $session->set('modules_startnum', $startnum);
- $session->set('modules_letter', $letter);
- $session->set('modules_state', $state);
- $activate = false;
- } else {
- $id = $session->get('modules_id');
- $startnum = $session->get('modules_startnum');
- $letter = $session->get('modules_letter');
- $state = $session->get('modules_state');
- $activate = (bool) $this->request->get('activate');
- }
- if (empty($id) || !is_numeric($id)) {
- return LogUtil::registerError($this->__('Error! No module ID provided.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- // initialise and activate any dependencies
- if (isset($dependencies) && is_array($dependencies)) {
- foreach ($dependencies as $dependency) {
- if (!ModUtil::apiFunc('ExtensionsModule', 'admin', 'initialise',
- array('id' => $dependency))) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- if (!ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate',
- array('id' => $dependency,
- 'state' => ModUtil::STATE_ACTIVE))) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- }
- }
- // Now we've initialised the dependencies initialise the main module
- $res = ModUtil::apiFunc('ExtensionsModule', 'admin', 'initialise',
- array('id' => $id,
- 'interactive_init' => $interactive_init));
- if (is_bool($res) && $res == true) {
- // Success
- $session->remove('modules_id');
- $session->remove('modules_startnum');
- $session->remove('modules_letter');
- $session->remove('modules_state');
- $session->remove('interactive_init');
- LogUtil::registerStatus($this->__('Done! Installed module.'));
- if ($activate == true) {
- if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate',
- array('id' => $id,
- 'state' => ModUtil::STATE_ACTIVE))) {
- // Success
- LogUtil::registerStatus($this->__('Done! Activated module.'));
- }
- }
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view',
- array('startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } elseif (is_bool($res)) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view',
- array('startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } else {
- return $res;
- }
- }
- /**
- * Activate a module
- * @param int 'id' module id
- * @return bool true
- */
- public function activateAction()
- {
- $csrftoken = $this->request->get('csrftoken');
- $this->checkCsrfToken($csrftoken);
- $id = (int) $this->request->query->get('id', null);
- $startnum = (int) $this->request->query->get('startnum', null);
- $letter = $this->request->query->get('letter', null);
- $state = $this->request->query->get('state', null);
- if (empty($id) || !is_numeric($id)) {
- return LogUtil::registerError($this->__('Error! No module ID provided.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- $moduleinfo = ModUtil::getInfo($id);
- if ($moduleinfo['state'] == 6) {
- LogUtil::registerError($this->__('Error! Module not allowed.'));
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- // Update state
- $setstate = ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $id, 'state' => ModUtil::STATE_ACTIVE));
- if ($setstate) {
- // Success
- LogUtil::registerStatus($this->__('Done! Activated module.'));
- }
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view',
- array('startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- /**
- * Upgrade a module
- * @param int 'id' module id
- * @return bool true
- */
- public function upgradeAction()
- {
- $csrftoken = $this->request->get('csrftoken');
- $this->checkCsrfToken($csrftoken);
- $session = $this->request->getSession();
- $interactive_upgrade = $session->get('interactive_upgrade');
- $interactive_upgrade = (empty($interactive_upgrade)) ? false : true;
- if ($interactive_upgrade == false) {
- $id = (int) $this->request->query->get('id', null);
- $startnum = (int) $this->request->query->get('startnum', null);
- $letter = $this->request->query->get('letter', null);
- $state = $this->request->query->get('state', null);
- $session->set('modules_id', $id);
- $session->set('modules_startnum', $startnum);
- $session->set('modules_letter', $letter);
- $session->set('modules_state', $state);
- $activate = false;
- } else {
- $id = $session->get('modules_id');
- $startnum = $session->get('modules_startnum');
- $letter = $session->get('modules_letter');
- $state = $session->get('modules_state');
- $activate = (bool) $this->request->request->get('activate', null);
- }
- if (empty($id) || !is_numeric($id)) {
- return LogUtil::registerError($this->__('Error! No module ID provided.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- // Upgrade module
- $res = ModUtil::apiFunc('ExtensionsModule', 'admin', 'upgrade',
- array('id' => $id,
- 'interactive_upgrade' => $interactive_upgrade));
- if (is_bool($res) && $res == true) {
- // Success
- $session->remove('modules_id');
- $session->remove('modules_startnum');
- $session->remove('modules_letter');
- $session->remove('modules_state');
- $session->set('interactive_upgrade', false);
- LogUtil::registerStatus($this->__('New version'));
- if ($activate == true) {
- if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate',
- array('id' => $id,
- 'state' => ModUtil::STATE_ACTIVE))) {
- // Success
- LogUtil::registerStatus($this->__('Activated'));
- }
- }
- // Clear the Zikula_View cached/compiled files and Themes cached/compiled/cssjs combination files
- $theme = \Zikula_View_Theme::getInstance('Theme');
- $theme->clear_compiled();
- $theme->clear_all_cache();
- $theme->clear_cssjscombinecache();
- $this->view->clear_compiled();
- $this->view->clear_all_cache();
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } elseif (is_bool($res)) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } else {
- return $res;
- }
- }
- /**
- * Deactivate a module
- * @param int 'id' module id
- * @return bool true
- */
- public function deactivateAction()
- {
- $csrftoken = $this->request->get('csrftoken');
- $this->checkCsrfToken($csrftoken);
- $id = (int) $this->request->query->get('id', null);
- $startnum = (int) $this->request->query->get('startnum', null);
- $letter = $this->request->query->get('letter', null);
- $state = $this->request->query->get('state', null);
- if (empty($id) || !is_numeric($id)) {
- return LogUtil::registerError($this->__('Error! No module ID provided.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- // check if the modules is the systems start module
- $modinfo = ModUtil::getInfo($id);
- if ($modinfo == false) {
- return LogUtil::registerError($this->__('Error! No such module ID exists.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- $startmod = System::getVar('startpage');
- if ($startmod == $modinfo['name']) {
- return LogUtil::registerError($this->__('Error! This module is currently set as the site\'s home page. You must choose another module for the home page before you can deactivate this one.'), null, ModUtil::url('Extensions', 'admin', 'view'));
- }
- if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'iscoremodule',array('modulename' => $modinfo['name']))) {
- return LogUtil::registerError($this->__('Error! You cannot deactivate this module. It is a mandatory core module, and is needed by the system.'), null, ModUtil::url('Extensions', 'admin', 'view'));
- }
- // Update state
- $setstate = ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $id, 'state' => ModUtil::STATE_INACTIVE));
- if ($setstate) {
- // Success
- LogUtil::registerStatus($this->__('Done! Deactivated module.'));
- }
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- /**
- * Remove a module
- * @param int 'id' module id
- * @return bool true if successful
- */
- public function removeAction()
- {
- // Get parameters from whatever input we need
- $id = (int) $this->request->get('id', 0);
- $objectid = (int) $this->request->get('objectid', 0);
- $confirmation = (bool) $this->request->get('confirmation', false);
- $dependents = (array) $this->request->get('dependents');
- $startnum = (int) $this->request->get('startnum');
- $letter = $this->request->get('letter');
- $state = $this->request->get('state');
- if ($objectid) {
- $id = $objectid;
- }
- $session = $this->request->getSession();
- $interactive_remove = $session->get('interactive_remove');
- $interactive_remove = (empty($interactive_remove)) ? false : true;
- if ($interactive_remove == false) {
- $session->set('modules_id', $id);
- $session->set('modules_startnum', $startnum);
- $session->set('modules_letter', $letter);
- $session->set('modules_state', $state);
- } else {
- $id = $session->get('modules_id');
- $startnum = $session->get('modules_startnum');
- $letter = $session->get('modules_letter');
- $state = $session->get('modules_state');
- $confirmation = 1;
- }
- if (empty($id) || !is_numeric($id) || !ModUtil::getInfo($id)) {
- return LogUtil::registerError($this->__('Error! No module ID provided.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- // Check for confirmation.
- if (empty($confirmation)) {
- // No confirmation yet
- // Add a hidden field for the item ID to the output
- $this->view->assign('id', $id);
- // assign any dependencies - filtering out non-active module dependents
- $dependents = ModUtil::apiFunc('ExtensionsModule', 'admin', 'getdependents', array('modid' => $id));
- foreach ($dependents as $key => $dependent) {
- $modinfo = ModUtil::getInfo($dependent['modid']);
- if (!ModUtil::available($modinfo['name'])) {
- unset($dependents[$key]);
- } else {
- $dependents[$key] = array_merge($dependents[$key], $modinfo);
- }
- }
- // check the blocks module for existing blocks
- $blocks = ModUtil::apiFunc('BlocksModule', 'user', 'getall', array('modid' => $id));
- $this->view->assign('hasBlocks', count($blocks));
- $this->view->assign('dependents', $dependents)
- ->assign('startnum', $startnum)
- ->assign('letter', $letter)
- ->assign('state', $state);
- // Return the output that has been generated by this function
- return $this->response($this->view->fetch('Admin/remove.tpl'));
- }
- // If we get here it means that the user has confirmed the action
- $csrftoken = $this->request->get('csrftoken');
- $this->checkCsrfToken($csrftoken);
- // remove dependent modules
- foreach ($dependents as $dependent) {
- $remove = ModUtil::apiFunc('ExtensionsModule', 'admin', 'remove', array('id' => $dependent));
- if (!$remove) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- }
- // remove the module blocks
- $blocks = ModUtil::apiFunc('BlocksModule', 'user', 'getall', array('modid' => $id));
- foreach ($blocks as $block) {
- $delete = ModUtil::apiFunc('BlocksModule', 'admin', 'delete', array('bid' => $block['bid']));
- if (!$delete) {
- LogUtil::registerError($this->__f('Error! Deleting the block %s .', $block['title']));
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- }
- }
- // Now we've removed dependents and associated blocks remove the main module
- $res = ModUtil::apiFunc('ExtensionsModule', 'admin', 'remove', array('id' => $id, 'interactive_remove' => $interactive_remove));
- if (is_bool($res) && $res == true) {
- // Success
- $session->remove('modules_id');
- $session->remove('modules_startnum');
- $session->remove('modules_letter');
- $session->remove('modules_state');
- $session->remove('interactive_remove');
- LogUtil::registerStatus($this->__('Done! Uninstalled module.'));
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } elseif (is_bool($res)) {
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view', array(
- 'startnum' => $startnum,
- 'letter' => $letter,
- 'state' => $state)));
- } else {
- return $res;
- }
- }
- /**
- * This is a standard function to modify the configuration parameters of the
- * module
- * @return string HTML string
- */
- public function modifyconfigAction()
- {
- // Security check
- if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- // assign all the module vars and return output
- return $this->response($this->view->assign($this->getVars())
- ->fetch('Admin/modifyconfig.tpl'));
- }
- /**
- * This is a standard function to update the configuration parameters of the
- * module given the information passed back by the modification form
- * @return bool true
- */
- public function updateconfigAction()
- {
- $this->checkCsrfToken();
- // Security check
- if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- // Update module variables.
- $itemsperpage = (int) $this->request->request->get('itemsperpage', 25);
- if (!is_integer($itemsperpage) || $itemsperpage < 1) {
- LogUtil::registerError($this->__("Warning! The 'Items per page' setting must be a positive integer. The value you entered was corrected."));
- $itemsperpage = (int) $itemsperpage;
- if ($itemsperpage < 1) {
- $itemsperpage = 25;
- }
- }
- $this->setVar('itemsperpage', $itemsperpage);
- // the module configuration has been updated successfuly
- LogUtil::registerStatus($this->__('Done! Saved module configuration.'));
- // This function generated no output, and so now it is complete we redirect
- // the user to an appropriate page for them to carry on their work
- return $this->redirect(ModUtil::url('Extensions', 'admin', 'view'));
- }
- /**
- * Display information of a module compatibility with the version of the core
- * @param int 'id' identity of the module
- * @return string HTML output string
- */
- public function compinfoAction()
- {
- // get our input
- $id = (int) $this->request->get('id', null);
- $startnum = (int) $this->request->get('startnum');
- $letter = $this->request->get('letter');
- $state = (int) $this->request->get('state');
- // check the input
- if (!is_numeric($id)) {
- return LogUtil::registerArgsError(ModUtil::url('Extensions', 'admin', 'view'));
- }
- // get the modules information from the data base
- $modinfo = ModUtil::getInfo($id);
- if ($modinfo == false) {
- return LogUtil::registerError($this->__('Error! No such module ID exists.'), 404, ModUtil::url('Extensions', 'admin', 'view'));
- }
- if (!SecurityUtil::checkPermission('Extensions::', "$modinfo[name]::$id", ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- // get the module information from the files system
- $moduleInfo = ModUtil::apiFunc('ExtensionsModule', 'admin', 'getfilemodules',
- array('name' => $modinfo['name']));
- // assign the module information and other variables to the template
- $this->view->assign('moduleInfo', $moduleInfo)
- ->assign('id', $id)
- ->assign('startnum', $startnum)
- ->assign('letter', $letter)
- ->assign('state', $state);
- // Return the output that has been generated by this function
- return $this->response($this->view->fetch('Admin/compinfo.tpl'));
- }
- /**
- * Lists all plugins.
- * @return string HTML output string
- */
- public function viewPluginsAction()
- {
- // Security check
- if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
- throw new \Zikula\Framework\Exception\ForbiddenException();
- }
- $state = $this->request->get('state', -1);
- $sort = $this->request->get('sort', null);
- $module = $this->request->get('bymodule', null);
- $systemplugins = $this->request->get('systemplugins', false)? true : null;
- $this->view->assign('state', $state);
- // generate an auth key to use in urls
- $csrfToken = SecurityUtil::generateCsrfToken($this->container, true);
- $plugins = array();
- $pluginClasses = ($systemplugins) ? PluginUtil::loadAllSystemPlugins() : PluginUtil::loadAllModulePlugins();
- foreach ($pluginClasses as $className) {
- $instance = PluginUtil::loadPlugin($className);
- $pluginstate = PluginUtil::getState($instance->getServiceId(), PluginUtil::getDefaultState());
- // Tweak UI if the plugin is AlwaysOn
- if ($instance instanceof \Zikula_Plugin_AlwaysOnInterface) {
- $pluginstate['state'] = PluginUtil::ENABLED;
- $pluginstate['version'] = $instance->getMetaVersion();
- }
- // state filer
- if ($state >= 0 && $pluginstate['state'] != $state) {
- continue;
- }
- // module filter
- if (!empty($module) && $instance->getModuleName() != $module) {
- continue;
- }
- $actions = array();
- // Translate state
- switch ($pluginstate['state']) {
- case PluginUtil::NOTINSTALLED:
- $status = $this->__('Not installed');
- $statusimage = 'redled.png';
- $actions[] = array('url' => ModUtil::url('Extensions', 'admin', 'initialisePlugin',
- array('plugin' => $className,
- 'state' => $state,
- 'bymodule' => $module,
- 'sort' => $sort,
- 'systemplugins' => $systemplugins,
- 'csrftoken' => $csrfToken)
- ),
- 'image' => 'folder_new.png',
- 'title' => $this->__('Install'));
- break;
- case PluginUtil::ENABLED:
- $status = $this->__('Active');
- $statusimage = 'greenled.png';
- $pluginLink = array();
- if (!$systemplugins) {
- $pluginLink['_module'] = $instance->getModuleName();
- }
- $pluginLink['_plugin'] = $instance->getPluginName();
- $pluginLink['_action'] = 'configure';
- if ($instance instanceof \Zikula_Plugin_ConfigurableInterface) {
- $actions[] = array('url' => ModUtil::url('Extensions', 'adminplugin', 'dispatch', $pluginLink),
- 'image' => 'configure.png',
- 'title' => $this->__('Configure plugin'));
- }
- // Dont allow to disable/uninstall plugins that are AlwaysOn
- if (!$instance instanceof \Zikula_Plugin_AlwaysOnInterface) {
- $actions[] = array('url' => ModUtil::url('Extensions', 'admin', 'deactivatePlugin',
- array('plugin' => $className,
- 'state' => $state,
- 'bymodule' => $module,
- 'sort' => $sort,
- 'systemplugins' => $systemplugins,
- 'csrftoken' => $csrfToken)
- ),
- 'image' => 'folder_re…
Large files files are truncated, but you can click here to view the full file