Пример #1
0
 /**
  * Dispatch a module view request.
  *
  * @return mixed
  */
 public function dispatch()
 {
     if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     // Get input.
     $moduleName = $this->request->getGet()->filter('_module', null, FILTER_SANITIZE_STRING);
     $pluginName = $this->request->getGet()->filter('_plugin', null, FILTER_SANITIZE_STRING);
     $action = $this->request->getGet()->filter('_action', null, FILTER_SANITIZE_STRING);
     // Load plugins.
     if (!$moduleName) {
         $type = 'SystemPlugin';
         PluginUtil::loadAllSystemPlugins();
     } else {
         $type = 'ModulePlugin';
         PluginUtil::loadAllModulePlugins();
     }
     if ($moduleName) {
         $serviceId = PluginUtil::getServiceId("{$type}_{$moduleName}_{$pluginName}_Plugin");
     } else {
         $serviceId = PluginUtil::getServiceId("{$type}_{$pluginName}_Plugin");
     }
     $this->throwNotFoundUnless($this->serviceManager->hasService($serviceId));
     $this->plugin = $this->serviceManager->getService($serviceId);
     // Sanity checks.
     $this->throwNotFoundUnless($this->plugin->isInstalled(), __f('Plugin "%s" is not installed', $this->plugin->getMetaDisplayName()));
     $this->throwForbiddenUnless($this->plugin instanceof Zikula_Plugin_ConfigurableInterface, __f('Plugin "%s" is not configurable', $this->plugin->getMetaDisplayName()));
     $this->pluginController = $this->plugin->getConfigurationController();
     $this->throwNotFoundUnless($this->pluginController->getReflection()->hasMethod($action));
     return $this->pluginController->{$action}();
 }
Пример #2
0
 function isActive()
 {
     // check for the availability of the ZFeed systemplugin that provides SimplePie
     if (PluginUtil::isAvailable(PluginUtil::getServiceId('SystemPlugin_ZFeed_Plugin'))) {
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  * Find the editor title when provided with editorname
  * 
  * @param array $args
  * @return string 
  */
 public function getEditorTitle($args)
 {
     if (!PluginUtil::isAvailable('moduleplugin.scribite.' . strtolower($args['editorname']))) {
         return '';
     }
     $className = 'ModulePlugin_Scribite_' . $args['editorname'] . '_Plugin';
     $instance = PluginUtil::loadPlugin($className);
     return $instance->getMetaDisplayName();
 }
Пример #4
0
 /**
  * boot the controller
  * 
  * @param AbstractBundle $bundle            
  */
 public function boot(AbstractBundle $bundle)
 {
     // load optional bootstrap
     $bootstrap = $bundle->getPath() . "/bootstrap.php";
     if (file_exists($bootstrap)) {
         include_once $bootstrap;
     }
     // load any plugins
     // @todo adjust this when Namespaced plugins are implemented
     \PluginUtil::loadPlugins($bundle->getPath() . "/plugins", "ModulePlugin_{$this->name}");
 }
Пример #5
0
    private function _setup()
    {
        $this->className = get_class($this);
        $this->serviceId = PluginUtil::getServiceId($this->className);
        $this->baseDir = dirname($this->getReflection()->getFileName());

        $this->moduleName = 'zikula';
        $this->pluginName = 'Doctrine';
        $this->pluginType = self::TYPE_SYSTEM;
        $this->domain = 'systemplugin_doctrine';

        $this->meta = $this->getMeta();
    }
Пример #6
0
 public function uninstall()
 {
     // delete editor plugins
     $classes = PluginUtil::loadAllModulePlugins();
     foreach ($classes as $class) {
         if (strpos($class, 'Scribite') !== false) {
             try {
                 PluginUtil::uninstall($class);
             } catch (Exception $e) {
                 LogUtil::registerError($e->getMessage());
             }
         }
     }
     // delete module variables
     $this->delVars();
     // remove hook
     HookUtil::unregisterProviderBundles($this->version->getHookProviderBundles());
     // deletion successful
     return true;
 }
Пример #7
0
 /**
  * Whether or not the plugin is enabled.
  *
  * @return boolean
  */
 public function isEnabled()
 {
     if ($this instanceof \Zikula\Framework\Plugin\AlwaysOnInterface) {
         return true;
     }
     $plugin = \PluginUtil::getState($this->serviceId, \PluginUtil::getDefaultState());
     return $plugin['state'] === PluginUtil::ENABLED ? true : false;
 }
Пример #8
0
 /**
  * Load system plugins.
  *
  * Implements 'core.init' event when Zikula_Core::STAGE_TABLES.
  *
  * @param Zikula_Event $event The event handler.
  *
  * @return void
  */
 public function systemPlugins(Zikula_Event $event)
 {
     if ($event['stage'] & Zikula_Core::STAGE_TABLES) {
         if (!System::isInstalling()) {
             ServiceUtil::loadPersistentServices();
             PluginUtil::loadPlugins(realpath(realpath('.') . '/plugins'), "SystemPlugin");
             EventUtil::loadPersistentEvents();
         }
     }
 }
Пример #9
0
 /**
  * Initialize object oriented module.
  *
  * @param string $moduleName Module name.
  *
  * @return boolean
  */
 public static function initOOModule($moduleName)
 {
     if (self::isInitialized($moduleName)) {
         return true;
     }
     $modinfo = self::getInfo(self::getIdFromName($moduleName));
     if (!$modinfo) {
         return false;
     }
     $modpath = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules';
     $osdir = DataUtil::formatForOS($modinfo['directory']);
     ZLoader::addAutoloader($moduleName, realpath("{$modpath}/{$osdir}/lib"));
     // load optional bootstrap
     $bootstrap = "{$modpath}/{$osdir}/bootstrap.php";
     if (file_exists($bootstrap)) {
         include_once $bootstrap;
     }
     // register any event handlers.
     // module handlers must be attached from the bootstrap.
     if (is_dir("config/EventHandlers/{$osdir}")) {
         EventUtil::attachCustomHandlers("config/EventHandlers/{$osdir}");
     }
     // load any plugins
     PluginUtil::loadPlugins("{$modpath}/{$osdir}/plugins", "ModulePlugin_{$osdir}");
     self::$ooModules[$moduleName]['initialized'] = true;
     return true;
 }
Пример #10
0
 * information regarding copyright and licensing.
 */
ini_set('mbstring.internal_encoding', 'UTF-8');
ini_set('default_charset', 'UTF-8');
mb_regex_encoding('UTF-8');
ini_set('memory_limit', '64M');
ini_set('max_execution_time', 86400);
include 'lib/bootstrap.php';
ZLoader::addAutoloader('Users', 'system/Users/lib', '_');
include_once __DIR__ . '/plugins/Doctrine/Plugin.php';
// check if the config.php was renewed
if (!isset($GLOBALS['ZConfig']['Log']['log.to_debug_toolbar'])) {
    echo __('It seems to be that your config.php is outdated. Please check the release notes for more information.');
    die;
}
PluginUtil::loadPlugin('SystemPlugin_Doctrine_Plugin');
$eventManager = $core->getEventManager();
$eventManager->attach('core.init', 'upgrade_suppressErrors');
// load zikula core
define('_ZINSTALLVER', Zikula_Core::VERSION_NUM);
define('_Z_MINUPGVER', '1.2.0');
// Signal that upgrade is running.
$GLOBALS['_ZikulaUpgrader'] = array();
// include config file for retrieving name of temporary directory
$GLOBALS['ZConfig']['System']['multilingual'] = true;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_ATTRIBUTION'] = false;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_LOGGING'] = false;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_META'] = false;
// Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet)
$dbEvent = new Zikula_Event('doctrine.init_connection', null, array('lazy' => true));
$connection = $eventManager->notify($dbEvent)->getData();
Пример #11
0
    /**
     * Whether or not the plugin is installed.
     *
     * @return boolean
     */
    public function isInstalled()
    {
        if ($this instanceof Zikula_Plugin_AlwaysOnInterface) {
            return true;
        }

        $plugin = PluginUtil::getState($this->serviceId, PluginUtil::getDefaultState());
        return ($plugin['state'] === PluginUtil::NOTINSTALLED) ? false : true;
    }
Пример #12
0
    /**
     * Upgrade a plugin
     * @return bool true
     */
    public function upgradePlugin()
    {
        $csrftoken = FormUtil::getPassedValue('csrftoken');
        $this->checkCsrfToken($csrftoken);

        // Security and sanity checks
        if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }

        // Get parameters from whatever input we need
        $plugin = FormUtil::getPassedValue('plugin', null);
        $state = FormUtil::getPassedValue('state', -1);
        $sort = FormUtil::getPassedValue('sort', null);
        $module = FormUtil::getPassedValue('bymodule', null);
        $systemplugins = FormUtil::getPassedValue('systemplugins', false)? true : null;

        if (empty($plugin)) {
            return LogUtil::registerError($this->__('Error! No plugin class provided.'), 404, ModUtil::url('Extensions', 'admin', 'viewPlugins'));
        }

        PluginUtil::loadAllPlugins();
        if (PluginUtil::upgrade($plugin)) {
            LogUtil::registerStatus($this->__('Done! Upgraded plugin.'));
        }

        $this->redirect(ModUtil::url('Extensions', 'admin', 'viewPlugins', array('state' => $state,
                                                                              'sort'  => $sort,
                                                                              'bymodule' => $module,
                                                                              'systemplugins' => $systemplugins)));
    }
Пример #13
0
function installmodules($lang = 'en')
{
    // This is a temporary hack for release 1.3.x to be able to install modules
    // load DoctrineExtensions plugin
    include_once __DIR__ . '/../plugins/DoctrineExtensions/Plugin.php';
    PluginUtil::loadPlugin('SystemPlugin_DoctrineExtensions_Plugin');
    // Lang validation
    $lang = DataUtil::formatForOS($lang);
    // create a result set
    $results = array();
    $sm = ServiceUtil::getManager();
    $coremodules = array('Extensions', 'Settings', 'Theme', 'Admin', 'Permissions', 'Groups', 'Blocks', 'Users');
    // manually install the modules module
    foreach ($coremodules as $coremodule) {
        $modpath = 'system';
        ZLoader::addModule($coremodule, $modpath);
        $bootstrap = __DIR__ . "/../{$modpath}/{$coremodule}/bootstrap.php";
        if (file_exists($bootstrap)) {
            include_once $bootstrap;
        }
        ModUtil::dbInfoLoad($coremodule, $coremodule);
        $className = "{$coremodule}_Installer";
        $instance = new $className($sm);
        if ($instance->install()) {
            $results[$coremodule] = true;
        }
    }
    // regenerate modules list
    $filemodules = ModUtil::apiFunc('ExtensionsModule', 'admin', 'getfilemodules');
    ModUtil::apiFunc('ExtensionsModule', 'admin', 'regenerate', array('filemodules' => $filemodules));
    // set each of the core modules to active
    reset($coremodules);
    foreach ($coremodules as $coremodule) {
        $mid = ModUtil::getIdFromName($coremodule, true);
        ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_INACTIVE));
        ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_ACTIVE));
    }
    // Add them to the appropriate category
    reset($coremodules);
    $coremodscat = array('Extensions' => __('System'), 'Permissions' => __('Users'), 'Groups' => __('Users'), 'Blocks' => __('Layout'), 'Users' => __('Users'), 'Theme' => __('Layout'), 'Admin' => __('System'), 'Settings' => __('System'));
    $categories = ModUtil::apiFunc('AdminModule', 'admin', 'getall');
    $modscat = array();
    foreach ($categories as $category) {
        $modscat[$category['name']] = $category['cid'];
    }
    foreach ($coremodules as $coremodule) {
        $category = $coremodscat[$coremodule];
        ModUtil::apiFunc('AdminModule', 'admin', 'addmodtocategory', array('module' => $coremodule, 'category' => $modscat[$category]));
    }
    // create the default blocks.
    $blockInstance = new Blocks_Installer($sm);
    $blockInstance->defaultdata();
    // install all the basic modules
    $modules = array(array('module' => 'SecurityCenter', 'category' => __('Security')), array('module' => 'Tour', 'category' => __('Content')), array('module' => 'Categories', 'category' => __('Content')), array('module' => 'Legal', 'category' => __('Content')), array('module' => 'Mailer', 'category' => __('System')), array('module' => 'Errors', 'category' => __('System')), array('module' => 'Theme', 'category' => __('Layout')), array('module' => 'Search', 'category' => __('Content')));
    foreach ($modules as $module) {
        // sanity check - check if module is already installed
        if (ModUtil::available($module['module'])) {
            continue;
        }
        $modpath = 'modules';
        //        ZLoader::addModule($module, $modpath);
        ZLoader::addAutoloader($module, "{$modpath}");
        $bootstrap = __DIR__ . "/../{$modpath}/{$module}/bootstrap.php";
        if (file_exists($bootstrap)) {
            include_once $bootstrap;
        }
        ZLanguage::bindModuleDomain($module);
        $results[$module['module']] = false;
        // #6048 - prevent trying to install modules which are contained in an install type, but are not available physically
        if (!file_exists('system/' . $module['module'] . '/') && !file_exists('modules/' . $module['module'] . '/')) {
            continue;
        }
        $mid = ModUtil::getIdFromName($module['module']);
        // init it
        if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'initialise', array('id' => $mid)) == true) {
            // activate it
            if (ModUtil::apiFunc('ExtensionsModule', 'admin', 'setstate', array('id' => $mid, 'state' => ModUtil::STATE_ACTIVE))) {
                $results[$module['module']] = true;
            }
            // Set category
            ModUtil::apiFunc('AdminModule', 'admin', 'addmodtocategory', array('module' => $module['module'], 'category' => $modscat[$module['category']]));
        }
    }
    System::setVar('language_i18n', $lang);
    return $results;
}
Пример #14
0
    /**
     * view items
     */
    public function view($args)
    {
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('Feeds::', "::", ACCESS_EDIT), LogUtil::getErrorMsgPermission());

        $startnum = FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : null, 'GET');
        $property = FormUtil::getPassedValue('feeds_property', isset($args['feeds_property']) ? $args['feeds_property'] : null, 'POST');
        $category = FormUtil::getPassedValue("feeds_{$property}_category", isset($args["feeds_{$property}_category"]) ? $args["feeds_{$property}_category"] : null, 'POST');
        $clear = FormUtil::getPassedValue('clear', false, 'POST');
        $purge = FormUtil::getPassedValue('purge', false, 'GET');

        if (!PluginUtil::isAvailable('systemplugin.simplepie')) {
            LogUtil::registerError($this->__('<strong>Fatal error: The required SimplePie system plugin is not available.</strong><br /><br />Zikula ships with the SimplePie plugin located in the docs/examples/plugins/ExampleSystemPlugin/SimplePie directory. It must be copied (or symlinked) from there and pasted into the /plugins directory. The plugin must then be installed. This is done via the Extensions module. Click on the System Plugins menu item and install the SimplePie plugin.'));
        }

        if ($purge) {
            if (ModUtil::apiFunc('Feeds', 'admin', 'purgepermalinks')) {
                LogUtil::registerStatus($this->__('Purging of the pemalinks was successful'));
            } else {
                LogUtil::registerError($this->__('Purging of the pemalinks has failed'));
            }
            return System::redirect(strpos(System::serverGetVar('HTTP_REFERER'), 'purge') ? ModUtil::url('Feeds', 'admin', 'view') : System::serverGetVar('HTTP_REFERER'));
        }
        if ($clear) {
            $property = null;
            $category = null;
        }

        // get module vars for later use
        $modvars = ModUtil::getVar('Feeds');

        if ($modvars['enablecategorization']) {
            // load the category registry util
            $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Feeds', 'feeds');
            $properties = array_keys($catregistry);

            // Validate and build the category filter - mateo
            if (!empty($property) && in_array($property, $properties) && !empty($category)) {
                $catFilter = array($property => $category);
            }

            // Assign a default property - mateo
            if (empty($property) || !in_array($property, $properties)) {
                $property = $properties[0];
            }

            // plan ahead for ML features
            $propArray = array();
            foreach ($properties as $prop) {
                $propArray[$prop] = $prop;
            }
        }

        // Get all the feeds
        $items = ModUtil::apiFunc('Feeds', 'user', 'getall', array('startnum' => $startnum,
                    'numitems' => $modvars['itemsperpage'],
                    'order' => 'fid',
                    'category' => isset($catFilter) ? $catFilter : null,
                    'catregistry' => isset($catregistry) ? $catregistry : null));

        $feedsitems = array();
        foreach ($items as $item) {
            if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_READ)) {
                // Options for the item
                $options = array();

                if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_EDIT)) {
                    $options[] = array('url' => ModUtil::url('Feeds', 'user', 'display', array('fid' => $item['fid'])),
                        'image' => 'kview.png',
                        'title' => $this->__('View'));

                    $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'modify', array('fid' => $item['fid'])),
                        'image' => 'xedit.png',
                        'title' => $this->__('Edit'));

                    if (SecurityUtil::checkPermission('Feeds::', "$item[name]::$item[fid]", ACCESS_DELETE)) {
                        $options[] = array('url' => ModUtil::url('Feeds', 'admin', 'delete', array('fid' => $item['fid'])),
                            'image' => '14_layer_deletelayer.png',
                            'title' => $this->__('Delete'));
                    }
                }
                $item['options'] = $options;
                $feedsitems[] = $item;
            }
        }

        // Assign the items and modvars to the template
        $this->view->assign('feedsitems', $feedsitems);
        $this->view->assign($modvars);

        // Assign the default language
        $this->view->assign('lang', ZLanguage::getLanguageCode());

        // Assign the categories information if enabled
        if ($modvars['enablecategorization']) {
            $this->view->assign('catregistry', $catregistry);
            $this->view->assign('numproperties', count($propArray));
            $this->view->assign('properties', $propArray);
            $this->view->assign('property', $property);
            $this->view->assign("category", $category);
        }

        // Assign the values for the smarty plugin to produce a pager
        $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Feeds', 'user', 'countitems', array('category' => isset($catFilter) ? $catFilter : null)),
            'itemsperpage' => $modvars['itemsperpage']));

        // Return the output that has been generated by this function
        return $this->view->fetch('admin/view.tpl');
    }
Пример #15
0
 private function installPlugins()
 {
     $result = true;
     $systemPlugins = \PluginUtil::loadAllSystemPlugins();
     foreach ($systemPlugins as $plugin) {
         $result = $result && \PluginUtil::install($plugin);
     }
     return $result;
 }
Пример #16
0
    /**
     * Get Feeds via SimplePie
     *
     * @param integer fid feed id (not required if feed url is present)
     * @param string  furl feed url or urls for Multifeed request (not requred if feed id is present)
     * @param integer limit set how many items are returned per feed with Multifeeds (default is all)
     * @param integer cron  set to 1 to update all caches right now (default is 0, update cache only if needed)
     * @return mixed item array containing total item count, error information, and object with all the requested feeds
     */
    public function getfeed($args)
    {
        if (!PluginUtil::isAvailable('systemplugin.simplepie')) {
            throw new Exception(__('<strong>Fatal error: The required SimplePie system plugin is not available.</strong>'));
        }

        // Argument check
        if ((!isset($args['fid']) || !is_numeric($args['fid']))
                && (!isset($args['furl']) || (!is_string($args['furl']) && (!is_array($args['furl']))))) {
            return LogUtil::registerArgsError();
        }

        // Optional arguments.
        if (!isset($args['limit']) || !is_numeric($args['limit'])) {
            $args['limit'] = 0;  // 0 = don't set a limit
        }
        if (!isset($args['cron']) || !is_numeric($args['cron'])) {
            $args['cron'] = 0;  // not a cron job update
        } else {
            $args['cron'] = 1;  // it is a cron job update
        }

        // get all module vars for later use
        $modvars = $this->getVars();

        // check if the feed id is set, grab the feed from the db
        if (isset($args['fid'])) {
            $feed = ModUtil::apiFunc('Feeds', 'user', 'get', array('fid' => $args['fid']));
            $url = $feed['url'];
        } elseif(isset($args['furl'])) {
            $url = $args['furl'];
        }

        // Now setup SimplePie for the feed
        $theFeed = new SimplePieFeed();
        $theFeed->set_feed_url($url);
        $theFeed->set_cache_location(CacheUtil::getLocalDir($modvars['cachedirectory']));
        $theFeed->enable_order_by_date(true);

        // Get the charset used for the output, and tell SimplePie about it so it will try to use the same for its output
        $charset = ZLanguage::getDBCharset();
        if ($charset != '') {
            $theFeed->set_output_encoding($charset);
        }

        // Set the feed limits (note: this is a per feed limit that applies if multiple feeds are used)
        if ($args['limit'] > 0) {
            $theFeed->set_item_limit($args['limit']);
        }

        // Set Cache Duration
        if ($args['cron'] == 1) {
            $theFeed->set_cache_duration(0);          // force cache to update immediately (a cron job needs to do that)

        } elseif ($modvars['usingcronjob'] == 1) {   // Using a cron job to update the cache (but not this time), so per SimplePie docs...
            $theFeed->set_cache_duration(999999999);  // set to 999999999 to not update the cache with this request
            $theFeed->set_timeout(-1);                // set timeout to -1 to prevent SimplePie from retrying previous failed feeds

        } else {
            $theFeed->set_cache_duration($modvars['cacheinterval']);  // Use the specified cache interval.
        }

        // tell SimplePie to go and do its thing
        $theFeed->init();

        $returnFeed['count'] = $theFeed->get_item_quantity(); // total items returned
        $returnFeed['error'] = $theFeed->error();             // Return any errors
        $returnFeed['feed']  = $theFeed;                      // The feed information

        // Per SimplePie documentation, there is a bug in versions of PHP older than 5.3 where PHP doesn't release memory properly in certain cases.
        // This is the workaround
        $theFeed->__destruct();
        unset($theFeed);

        return $returnFeed;
    }
Пример #17
0
/**
 * Install controller.
 *
 * @return void
 */
function install(Zikula_Core $core)
{
    define('_ZINSTALLVER', Zikula_Core::VERSION_NUM);
    $installbySQL = (file_exists('install/sql/custom.sql') ? true : false);

    $serviceManager = $core->getServiceManager();
    $eventManager = $core->getEventManager();

    // Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet)
    $dbEvent = new Zikula_Event('doctrine.init_connection', null, array('lazy' => true));
    $eventManager->notify($dbEvent);

    $core->init(Zikula_Core::STAGE_ALL & ~Zikula_Core::STAGE_THEME & ~Zikula_Core::STAGE_MODS & ~Zikula_Core::STAGE_LANGS & ~Zikula_Core::STAGE_DECODEURLS & ~Zikula_Core::STAGE_SESSIONS);

    // Power users might have moved the temp folder out of the root and changed the config.php
    // accordingly. Make sure we respect this security related settings
    $tempDir = (isset($GLOBALS['ZConfig']['System']['temp']) ? $GLOBALS['ZConfig']['System']['temp'] : 'ztemp');

    // define our smarty object
    $smarty = new Smarty();
    $smarty->caching = false;
    $smarty->compile_check = true;
    $smarty->left_delimiter = '{';
    $smarty->right_delimiter = '}';
    $smarty->compile_dir = $tempDir . '/view_compiled';
    $smarty->template_dir = 'install/templates';
    $smarty->plugins_dir = array(
            'plugins',
            'install/templates/plugins',
            );
    $smarty->clear_compiled_tpl();
    file_put_contents("$tempDir/view_compiled/index.html", '');

    $lang = FormUtil::getPassedValue('lang', '', 'GETPOST');
    $dbhost = FormUtil::getPassedValue('dbhost', '', 'GETPOST');
    $dbusername = FormUtil::getPassedValue('dbusername', '', 'GETPOST');
    $dbpassword = FormUtil::getPassedValue('dbpassword', '', 'GETPOST');
    $dbname = FormUtil::getPassedValue('dbname', '', 'GETPOST');
    $dbprefix = '';
    $dbdriver = FormUtil::getPassedValue('dbdriver', '', 'GETPOST');
    $dbtabletype = FormUtil::getPassedValue('dbtabletype', '', 'GETPOST');
    $username = FormUtil::getPassedValue('username', '', 'POST');
    $password = FormUtil::getPassedValue('password', '', 'POST');
    $repeatpassword = FormUtil::getPassedValue('repeatpassword', '', 'POST');
    $email = FormUtil::getPassedValue('email', '', 'GETPOST');
    $action = FormUtil::getPassedValue('action', '', 'GETPOST');

    $notinstalled = isset($_GET['notinstalled']);
    $installedState = (isset($GLOBALS['ZConfig']['System']['installed']) ? $GLOBALS['ZConfig']['System']['installed'] : 0);

    // If somehow we are browsing the not installed page but installed, redirect back to homepage
    if ($installedState && $notinstalled) {
        return System::redirect(System::getHomepageUrl());
    }

    // see if the language was already selected
    $languageAlreadySelected = ($lang) ? true : false;
    if (!$notinstalled && $languageAlreadySelected && empty($action)) {
        return System::redirect(System::getBaseUri() . "/install.php?action=requirements&lang=$lang");
    }

    // see if the language was already selected
    $languageAlreadySelected = ($lang) ? true : false;
    if (!$notinstalled && $languageAlreadySelected && empty($action)) {
        return System::redirect(System::getBaseUri() . "/install.php?action=requirements&lang=$lang");
    }

    // load the installer language files
    if (!$notinstalled && empty($lang)) {
        $available = ZLanguage::getInstalledLanguages();
        $detector = new ZLanguageBrowser($available);
        $lang = $detector->discover();
    } elseif ($notinstalled) {
        $installerConfig = array('language' => 'en');
        if (is_readable('config/installer.ini')) {
            $test = parse_ini_file('config/installer.ini');
            $installerConfig = isset($test['language']) ? $test : $installerConfig;
        }
        $lang = DataUtil::formatForDisplay($installerConfig['language']);
    }

    // setup multilingual
    $GLOBALS['ZConfig']['System']['language_i18n'] = $lang;
    $GLOBALS['ZConfig']['System']['multilingual'] = true;
    $GLOBALS['ZConfig']['System']['languageurl'] = true;
    $GLOBALS['ZConfig']['System']['language_detect'] = false;
    $serviceManager->loadArguments($GLOBALS['ZConfig']['System']);

    $_lang = ZLanguage::getInstance();
    $_lang->setup();

    $lang = ZLanguage::getLanguageCode();

    $smarty->assign('lang', $lang);
    $smarty->assign('installbySQL', $installbySQL);
    $smarty->assign('langdirection', ZLanguage::getDirection());
    $smarty->assign('charset', ZLanguage::getEncoding());

    // show not installed case
    if ($notinstalled) {
        header('HTTP/1.1 503 Service Unavailable');
        $smarty->display('notinstalled.tpl');
        $smarty->clear_compiled_tpl();
        file_put_contents("$tempDir/view_compiled/index.html", '');
        exit;
    }

    // assign the values from config.php
    $smarty->assign($GLOBALS['ZConfig']['System']);

    // if the system is already installed, halt.
    if ($GLOBALS['ZConfig']['System']['installed']) {
        _installer_alreadyinstalled($smarty);
    }

    // check for an empty action - if so then show the first installer page
    if (empty($action)) {
        $action = 'lang';
    }

    // perform tasks based on our action
    switch ($action) {
        case 'processBDInfo':
            $dbname = trim($dbname);
            $dbusername = trim($dbusername);
            if (empty($dbname) || empty($dbusername)) {
                $action = 'dbinformation';
                $smarty->assign('dbconnectmissing', true);
            } elseif (!preg_match('/^[\w-]*$/', $dbname) ||
                    strlen($dbname) > 64) {
                $action = 'dbinformation';
                $smarty->assign('dbinvalidname', true);
            } else {
                update_config_php($dbhost, $dbusername, $dbpassword, $dbname, $dbdriver, $dbtabletype);
                update_installed_status(0);
                try {
                    $dbh = new PDO("$dbdriver:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
                } catch (PDOException $e) {
                    $action = 'dbinformation';
                    $smarty->assign('reason', $e->getMessage());
                    $smarty->assign('dbconnectfailed', true);
                }
            }
            if ($action != 'dbinformation') {
                $action = 'createadmin';
            }
            break;

        case 'finish':
            if ((!$username) || preg_match('/[^\p{L}\p{N}_\.\-]/u', $username)) {
                $action = 'createadmin';
                $smarty->assign('uservalidatefailed', true);
                $smarty->assign(array(
                        'username' => $username,
                        'password' => $password,
                        'repeatpassword' => $repeatpassword,
                        'email' => $email));
            } elseif (mb_strlen($password) < 7) {
                $action = 'createadmin';
                $smarty->assign('badpassword', true);
                $smarty->assign(array(
                        'username' => $username,
                        'password' => $password,
                        'repeatpassword' => $repeatpassword,
                        'email' => $email));
            } elseif ($password !== $repeatpassword) {
                $action = 'createadmin';
                $smarty->assign('passwordcomparefailed', true);
                $smarty->assign(array(
                        'username' => $username,
                        'password' => $password,
                        'repeatpassword' => $repeatpassword,
                        'email' => $email));
            } elseif (!validateMail($email)) {
                $action = 'createadmin';
                $smarty->assign('emailvalidatefailed', true);
                $smarty->assign(array(
                        'username' => $username,
                        'password' => $password,
                        'repeatpassword' => $repeatpassword,
                        'email' => $email));
            } else {
                // if it is the distribution and the process have not failed in a previous step
                if ($installbySQL) {
                    // checks if exists a previous installation with the same prefix
                    $proceed = true;
                    $exec = ($dbdriver == 'mysql' || $dbdriver == 'mysqli') ?
                            "SHOW TABLES FROM `$dbname` LIKE '%'" :
                            "SHOW TABLES FROM $dbname LIKE '%'";
                    $tables = DBUtil::executeSQL($exec);
                    if ($tables->rowCount() > 0) {
                        $proceed = false;
                        $action = 'dbinformation';
                        $smarty->assign('dbexists', true);
                    }
                    if ($proceed) {
                        // set sql dump file path
                        $fileurl = 'install/sql/custom.sql';
                        // checks if file exists
                        if (!file_exists($fileurl)) {
                            $action = 'dbinformation';
                            $smarty->assign('dbdumpfailed', true);
                        } else {
                            // execute the SQL dump
                            $lines = file($fileurl);
                            $exec = '';
                            foreach ($lines as $line_num => $line) {
                                $line = trim($line);
                                if (empty($line) || strpos($line, '--') === 0)
                                        continue;
                                $exec .= $line;
                                if (strrpos($line, ';') === strlen($line) - 1) {
                                    if (!DBUtil::executeSQL($exec)) {
                                        $action = 'dbinformation';
                                        $smarty->assign('dbdumpfailed', true);
                                        break;
                                    }
                                    $exec = '';
                                }
                            }
                        }
                    }
                } else {
                    installmodules($lang);

                    // create our new site admin
                    // TODO: Email username/password to administrator email address.  Cannot use ModUtil::apiFunc for this.
                    createuser($username, $password, $email);
                    $serviceManager->getService('session')->start();

                    $authenticationInfo = array(
                        'login_id'  => $username,
                        'pass'      => $password
                    );
                    $authenticationMethod = array(
                        'modname'   => 'Users',
                        'method'    => 'uname',
                    );
                    UserUtil::loginUsing($authenticationMethod, $authenticationInfo);

                    // add admin email as site email
                    System::setVar('adminmail', $email);

                    if (!$installbySQL) {
                        Theme_Util::regenerate();
                    }

                    // set site status as installed and protect config.php file
                    update_installed_status(1);
                    @chmod('config/config.php', 0400);
                    if (!is_readable('config/config.php')) {
                        @chmod('config/config.php', 0440);
                        if (!is_readable('config/config.php')) {
                            @chmod('config/config.php', 0444);
                        }
                    }
                    // install all plugins
                    $systemPlugins = PluginUtil::loadAllSystemPlugins();
                    foreach ($systemPlugins as $plugin) {
                        PluginUtil::install($plugin);
                    }

                    LogUtil::registerStatus(__('Congratulations! Zikula has been successfullly installed.'));
                    System::redirect(ModUtil::url('Admin', 'admin', 'adminpanel'));
                    exit;
                }
            }
            break;

        case 'requirements':
            $checks = _check_requirements();
            $ok = true;

            foreach ($checks as $check) {
                if (!$check) {
                    $ok = false;
                    break;
                }
            }

            foreach ($checks['files'] as $check) {
                if (!$check['writable']) {
                    $ok = false;
                    break;
                }
            }
            if ($ok) {
                System::redirect(System::getBaseUri() . "/install.php?action=dbinformation&lang=$lang");
                exit;
            }

            $smarty->assign('checks', $checks);

            break;
    }

    // check our action template exists
    $action = DataUtil::formatForOS($action);
    if ($smarty->template_exists("installer_$action.tpl")) {
        $smarty->assign('action', $action);
        $templateName = "installer_$action.tpl";
    } else {
        $smarty->assign('action', 'error');
        $templateName = 'installer_error.tpl';
    }

    $smarty->assign('maincontent', $smarty->fetch($templateName));
    $smarty->display('installer_page.tpl');
    $smarty->clear_compiled_tpl();
    file_put_contents("$tempDir/view_compiled/index.html", '');
}