Exemple #1
0
    /**
     * Extensions_admin_view - list modules and current settings
     * @return string HTML output string
     */
    public function view()
    {
        // Security check
        if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }

        // Get parameters from whatever input we need.
        $modinfo = $this->getModInfo();
        $startnum = (int) FormUtil::getPassedValue('startnum', null, 'GET');
        $letter = FormUtil::getPassedValue('letter', null, 'GET');
        $state = FormUtil::getPassedValue('state', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : SessionUtil::getVar('state', null), 'GETPOST');
        $sort = FormUtil::getPassedValue('sort', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : SessionUtil::getVar('sort', null), 'GET');
        $sortdir = FormUtil::getPassedValue('sortdir', (!strstr(System::serverGetVar('HTTP_REFERER'), 'module='.$modinfo['url'])) ? null : SessionUtil::getVar('sortdir', null), 'GET');

        // parameter for used sort order
        if ($sort != 'name' && $sort != 'displayname') $sort = 'name';
        if ($sortdir != 'ASC' && $sortdir != 'DESC') $sortdir = 'ASC';

        // save the current values
        SessionUtil::setVar('state', $state);
        SessionUtil::setVar('sort', $sort);
        SessionUtil::setVar('sortdir', $sortdir);

        // do some clean up
        SessionUtil::delVar('interactive_init');
        SessionUtil::delVar('interactive_remove');
        SessionUtil::delVar('interactive_upgrade');

        if ($this->serviceManager['multisites.enabled'] != 1 || ($this->serviceManager['multisites.mainsiteurl'] == FormUtil::getPassedValue('sitedns', null, 'GET') && $this->serviceManager['multisites.based_on_domains'] == 0) || ($this->serviceManager['multisites.mainsiteurl'] == $_SERVER['HTTP_HOST'] && $this->serviceManager['multisites.based_on_domains'] == 1)) {
            // always regenerate modules list
            $filemodules = ModUtil::apiFunc('Extensions', 'admin', 'getfilemodules');
            $inconsistencies = ModUtil::apiFunc('Extensions', '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->view->fetch('extensions_admin_regenerate_errors.tpl');
            }

            // No inconsistencies, so we can regenerate modules
            $defaults = (int) FormUtil::getPassedValue('defaults', false, 'GET');
            if (!ModUtil::apiFunc('Extensions', '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('Extensions', '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->serviceManager, true);

        $moduleinfo = array();
        if (!empty($mods)) {
            foreach ($mods as $mod) {
                // 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('Extensions', '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 (System::isLegacyMode() && !ModUtil::isOO($mod['name'])) {
                                $actions[] = array(
                                        'url' => ModUtil::url('Extensions', 'admin', 'legacyhooks', array(
                                        'id' => $mod['id'])),
                                        'image' => 'attach.png',
                                        'title' => $this->__f('Legacy hook settings for \'%s\'', $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->serviceManager['multisites.enabled'] != 1 || ($this->serviceManager['multisites.mainsiteurl'] == FormUtil::getPassedValue('sitedns', null, 'GET') && $this->serviceManager['multisites.based_on_domains'] == 0) || ($this->serviceManager['multisites.mainsiteurl'] == $_SERVER['HTTP_HOST'] && $this->serviceManager['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->serviceManager['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('Extensions', 'admin', 'countitems', array('letter' => $letter, 'state' => $state)),
                                           'itemsperpage' => $this->getVar('itemsperpage')));

        // Return the output that has been generated by this function
        return $this->view->fetch('extensions_admin_view.tpl');
    }