Пример #1
0
/**
 * Zikula_View function to display a preview image from a theme
 *
 * Available parameters:
 *  - name       name of the theme to display the preview image for
 *  - name       if set, the id assigned to the image
 *  - size         if set, the size of the image to use from small, medium, large (optional: default 'medium')
 *  - assign     if set, the title will be assigned to this variable
 *
 * Example
 * {previewimage name=andreas08 size=large}
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @see    function.title.php::smarty_function_previewimage()
 *
 * @return string The markup to display the theme image.
 */
function smarty_function_previewimage($params, Zikula_View $view)
{
    if (!isset($params['name'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('previewimage', 'name')));
        return false;
    }
    if (!isset($params['size']) || !in_array($params['size'], array('large', 'medium', 'small'))) {
        $params['size'] = 'medium';
    }
    $idstring = '';
    if (isset($params['id'])) {
        $idstring = " id=\"{$params['id']}\"";
    }
    $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($params['name']));
    $theme = ThemeUtil::getTheme($themeinfo['name']);
    $themePath = null === $theme ? "themes/{$themeinfo['directory']}/images" : $theme->getRelativePath() . '/Resources/public/images';
    if (file_exists("{$themePath}/preview_{$params['size']}.png")) {
        $filesrc = "{$themePath}/preview_{$params['size']}.png";
    } else {
        $filesrc = "system/ThemeModule/Resources/public/images/preview_{$params['size']}.png";
    }
    $markup = "<img{$idstring} src=\"{$filesrc}\" alt=\"\" />";
    if (isset($params['assign'])) {
        $view->assign($params['assign'], $markup);
    } else {
        return $markup;
    }
}
 public function __construct()
 {
     $themeName = \UserUtil::getTheme();
     $theme = \ThemeUtil::getTheme($themeName);
     if (null !== $theme && is_readable($path = $theme->getConfigPath() . '/overrides.yml')) {
         // bundle type theme
         $this->overrideMap = Yaml::parse(file_get_contents($path));
     } elseif (is_readable("themes/{$themeName}/templates/overrides.yml")) {
         // pre-1.4.0 style theme
         $this->_overrideMap = Yaml::parse(file_get_contents("themes/{$themeName}/templates/overrides.yml"));
     }
 }
Пример #3
0
 /**
  * Configure a theme's variables based on provided .yml definitions for each field.
  * @Route("/admin/var/{themeName}")
  * @todo change route name to /admin/variable/{themeName} when similar named is removed?
  * @Theme("admin")
  *
  * @param Request $request
  * @param string $themeName
  * @return mixed
  * @throws \InvalidArgumentException if theme type is not twig-based
  */
 public function varAction(Request $request, $themeName)
 {
     $themeBundle = \ThemeUtil::getTheme($themeName);
     if (!$themeBundle->isTwigBased()) {
         throw new NotFoundHttpException('Theme type must be twig-based in ' . __FILE__ . ' at line ' . __LINE__ . '.');
     }
     $themeVarsPath = $themeBundle->getConfigPath() . '/variables.yml';
     if (!file_exists($themeVarsPath)) {
         $this->addFlash('warning', $this->__f('%theme% has no configuration.', array('%theme%' => $themeName)));
         return $this->redirect($this->generateUrl('zikulathememodule_admin_view'));
     }
     $variableDefinitions = Yaml::parse(file_get_contents($themeVarsPath));
     /** @var \Symfony\Component\Form\FormBuilder $formBuilder */
     $formBuilder = $this->createFormBuilder($themeBundle->getThemeVars());
     foreach ($variableDefinitions as $fieldName => $definitions) {
         $options = isset($definitions['options']) ? $definitions['options'] : [];
         if (isset($definitions['type'])) {
             $formBuilder->add($fieldName, $definitions['type'], $options);
         }
     }
     $formBuilder->add('save', 'submit', array('label' => $this->__('Save'), 'icon' => 'fa-check fa-lg', 'attr' => array('class' => "btn btn-success")))->add('toDefault', 'submit', array('label' => $this->__('Set to defaults'), 'icon' => 'fa-refresh fa-lg', 'attr' => array('class' => "btn btn-primary")))->add('cancel', 'submit', array('label' => $this->__('Cancel'), 'icon' => 'fa-times fa-lg', 'attr' => array('class' => "btn btn-danger")));
     $form = $formBuilder->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         if ($form->get('save')->isClicked()) {
             // pseudo-hack to save theme vars in to modvars table
             \ModUtil::setVars($themeName, $form->getData());
             $this->addFlash('status', $this->__('Done! Theme configuration updated.'));
         } elseif ($form->get('toDefault')->isClicked()) {
             \ModUtil::setVars($themeName, $themeBundle->getDefaultThemeVars());
             $this->addFlash('status', $this->__('Done! Theme configuration updated to default values.'));
         } elseif ($form->get('cancel')->isClicked()) {
             $this->addFlash('status', $this->__('Operation cancelled.'));
         }
         return $this->redirect($this->generateUrl('zikulathememodule_admin_view'));
     }
     return $this->render('ZikulaThemeModule:Admin:var.html.twig', ['themeName' => $themeName, 'form' => $form->createView()]);
 }
Пример #4
0
/**
 * Zikula_View function to provide easy access to an image
 *
 * This function provides an easy way to include an image. The function will return the
 * full source path to the image. It will as well provite the width and height attributes
 * if none are set.
 *
 * Available parameters:
 *   - src            The file name of the image
 *   - modname        The well-known name of a module (default: the current module)
 *   - modplugin      The name of the plugin in the passed module
 *   - sysplugin      The name of the system plugin
 *   - width, height  If set, they will be passed. If none is set, they are obtained from the image
 *   - alt            If not set, an empty string is being assigned
 *   - title          If set it will be passed as a title attribute
 *   - assign         If set, the results are assigned to the corresponding variable instead of printed out
 *   - optional       If set then the plugin will not return an error if an image is not found
 *   - default        If set then a default image is used should the requested image not be found (Note: full path required)
 *   - set            If modname is 'core' then the set parameter is set to define the directory in /images/
 *   - nostoponerror  If set and error ocurs (image not found or src is no image), do not trigger_error, but return false
 *   - retval         If set indicated the field to return instead the array of values (src, width, etc.)
 *   - fqurl          If set the image path is absolute, if not relative
 *   - all remaining parameters are passed to the image tag
 *
 * Example: {img src='heading.png'}
 * Output:  <img src="modules/Example/images/en/heading.png" alt="" width="261" height="69" />
 *
 * Example: {img src='heading.png' width='100' border='1' __alt='foobar'}
 * Output:  <img src="modules/Example/images/en/heading.png" width="100" border="1" alt="foobar" />
 *
 * Example: {img src='xhtml11.png' modname='core' set='powered'}
 * Output:  <img src="themes/Theme/images/powered/xhtml11.png" alt="" width="88" height="31" />
 *
 * Example: {img src='iconX.png' modname='ModName' modplugin='Plug1' set='icons'}
 * Output:  <img src="modules/ModName/plugins/Plug1/images/icons/iconX.png" alt="" width="16" height="16" />
 *
 * Example: {img src='iconY.png' sysplugin='Plug2' set='icons/small'}
 * Output:  <img src="plugins/Plug2/images/icons/small/iconY.png" alt="" width="16" height="16" />
 *
 * If the parameter assign is set, the results are assigned as an array. The components of
 * this array are the same as the attributes of the img tag; additionally an entry 'imgtag' is
 * set to the complete image tag.
 *
 * Example:
 * {img src="heading.png" assign="myvar"}
 * {$myvar.src}
 * {$myvar.width}
 * {$myvar.imgtag}
 *
 * Output:
 * modules/Example/images/en/heading.gif
 * 261
 * <img src="modules/Example/images/en/heading.gif" alt="" width="261" height="69"  />
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string|void The img tag, null if $params['nostoponerror'] true and there is an error.
 */
function smarty_function_img($params, Zikula_View $view)
{
    $nostoponerror = isset($params['nostoponerror']) && $params['nostoponerror'] ? true : false;
    if (!isset($params['src']) || !$params['src']) {
        if (!$nostoponerror) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('img', 'src')));
            return;
        } else {
            return false;
        }
    }
    // process the image location
    $modname = isset($params['modname']) ? $params['modname'] : $view->toplevelmodule;
    $modplugin = isset($params['modplugin']) ? $params['modplugin'] : null;
    $sysplugin = isset($params['sysplugin']) ? $params['sysplugin'] : null;
    // process the image set
    $set = isset($params['set']) ? $params['set'] : null;
    $osset = DataUtil::formatForOS($set);
    // if the module name is 'core'
    if ($modname == 'core') {
        if (System::isLegacyMode() && (strpos($osset, 'icons/') !== false || strpos($osset, 'global/') !== false) && strpos($params['src'], '.gif')) {
            LogUtil::log(__f('Core image %s does not exist, please use the png format (called from %s).', array($params['src'], $view->getTemplatePath())), E_USER_DEPRECATED);
            $params['src'] = str_replace('.gif', '.png', $params['src']);
        }
    }
    // always provide an alt attribute.
    // if none is set, assign an empty one.
    $params['alt'] = isset($params['alt']) ? $params['alt'] : '';
    // prevent overwriting surrounding titles (#477)
    if (isset($params['title']) && empty($params['title'])) {
        unset($params['title']);
    }
    // language
    $lang = ZLanguage::transformFS(ZLanguage::getLanguageCode());
    if ($sysplugin) {
        $osplugdir = DataUtil::formatForOS($sysplugin);
        $pluglangpath = "plugins/{$osplugdir}/images/{$lang}";
        $plugpath = "plugins/{$osplugdir}/images";
        // form the array of paths
        $paths = array($pluglangpath, $plugpath);
    } else {
        // module directory
        if ($modname != 'core') {
            $modinfo = ModUtil::getInfoFromName($modname);
            $osmoddir = DataUtil::formatForOS($modinfo['directory']);
            $moduleDir = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules';
        }
        if ($modplugin) {
            $osmodplugdir = DataUtil::formatForOS($modplugin);
            $modpluglangpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images/{$lang}";
            $modplugpath = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/Resources/public/images";
            $modpluglangpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images/{$lang}";
            $modplugpathOld = "{$moduleDir}/{$osmoddir}/plugins/{$osmodplugdir}/images";
            // form the array of paths
            $paths = array($modpluglangpath, $modplugpath, $modpluglangpathOld, $modplugpathOld);
        } else {
            // theme directory
            $ostheme = DataUtil::formatForOS(UserUtil::getTheme());
            $theme = ThemeUtil::getTheme($ostheme);
            $themePath = null === $theme ? '' : $theme->getRelativePath() . '/Resources/public/images';
            $themepath = $themePath;
            $corethemepath = "themes/{$ostheme}/images";
            if ($modname == 'core') {
                $modpath = "images";
                $paths = array($themepath, $corethemepath, $modpath);
            } else {
                $osmodname = DataUtil::formatForOS($modname);
                $themelangpath = "{$themePath}/{$lang}";
                $themelangpathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images/{$lang}";
                $themepathOld = "themes/{$ostheme}/templates/modules/{$osmodname}/images";
                $module = ModUtil::getModule($modinfo['name']);
                $moduleBasePath = null === $module ? '' : $module->getRelativePath() . '/Resources/public/images';
                $modlangpath = "{$moduleBasePath}/{$lang}";
                $modpath = $moduleBasePath;
                $modlangpathOld = "{$moduleDir}/{$osmoddir}/images/{$lang}";
                $modpathOld = "{$moduleDir}/{$osmoddir}/images";
                $modlangpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages/{$lang}";
                $modpathOld2 = "{$moduleDir}/{$osmoddir}/pnimages";
                // form the array of paths
                if (preg_match('/^admin.(png|gif|jpg)$/', $params['src'])) {
                    // special processing for modules' admin icon
                    $paths = array($modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2);
                } else {
                    $paths = array($themelangpath, $themepath, $themelangpathOld, $themepathOld, $corethemepath, $modlangpath, $modpath, $modlangpathOld, $modpathOld, $modlangpathOld2, $modpathOld2);
                }
            }
        }
    }
    $ossrc = DataUtil::formatForOS($params['src']);
    // search for the image
    $imgsrc = '';
    foreach ($paths as $path) {
        $fullpath = $path . ($osset ? "/{$osset}/" : '/') . $ossrc;
        if (is_readable($fullpath)) {
            $imgsrc = $fullpath;
            break;
        }
    }
    if ($imgsrc == '' && isset($params['default'])) {
        $imgsrc = $params['default'];
    }
    // default for the optional flag
    $optional = isset($params['optional']) ? $params['optional'] : true;
    if ($imgsrc == '') {
        if ($optional) {
            if (!$nostoponerror) {
                $view->trigger_error(__f("%s: Image '%s' not found", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src']))));
                return;
            } else {
                return false;
            }
        }
        return;
    }
    // If neither width nor height is set, get these parameters.
    // If one of them is set, we do NOT obtain the real dimensions.
    // This way it is easy to scale the image to a certain dimension.
    if (!isset($params['width']) && !isset($params['height'])) {
        if (!($_image_data = @getimagesize($imgsrc))) {
            if (!$nostoponerror) {
                $view->trigger_error(__f("%s: Image '%s' is not a valid image file", array('img', DataUtil::formatForDisplay(($set ? "{$set}/" : '') . $params['src']))));
                return;
            } else {
                return false;
            }
        }
        $params['width'] = $_image_data[0];
        $params['height'] = $_image_data[1];
    }
    $basepath = isset($params['fqurl']) && $params['fqurl'] ? System::getBaseUrl() : System::getBaseUri();
    $params['src'] = $basepath . '/' . $imgsrc;
    $retval = isset($params['retval']) ? $params['retval'] : null;
    $assign = isset($params['assign']) ? $params['assign'] : null;
    unset($params['modname']);
    unset($params['retval']);
    unset($params['assign']);
    if (isset($params['altml'])) {
        // legacy
        unset($params['altml']);
    }
    if (isset($params['titleml'])) {
        // legacy
        unset($params['titleml']);
    }
    unset($params['optional']);
    unset($params['default']);
    unset($params['set']);
    unset($params['nostoponerror']);
    unset($params['fqurl']);
    $imgtag = '<img ';
    foreach ($params as $key => $value) {
        $imgtag .= $key . '="' . $value . '" ';
    }
    $imgtag .= '/>';
    if (!empty($retval) && isset($params[$retval])) {
        return $params[$retval];
    } elseif (!empty($assign)) {
        $params['imgtag'] = $imgtag;
        $view->assign($assign, $params);
    } else {
        return $imgtag;
    }
}
Пример #5
0
 /**
  * Assign template vars for base theme paths and other useful variables.
  *
  * @return void
  */
 private function _base_vars()
 {
     // identify the page type
     $this->pagetype = 'module';
     if (stristr(System::serverGetVar('PHP_SELF'), 'admin.php') || strtolower($this->type) == 'admin') {
         $this->pagetype = 'admin';
     } else {
         $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
         if (empty($module)) {
             $this->pagetype = 'home';
         }
     }
     // set some basic class variables from Zikula
     $this->isloggedin = UserUtil::isLoggedIn();
     $this->uid = UserUtil::getVar('uid');
     // assign the query string
     $this->qstring = System::serverGetVar('QUERY_STRING', '');
     // assign the current script
     $this->requesturi = System::getCurrentUri();
     // define the cache_id if not set yet
     if ($this->caching && !$this->cache_id) {
         // module / type / function / customargs|homepage/startpageargs / uid_X|guest
         $this->cache_id = $this->toplevelmodule . '/' . $this->type . '/' . $this->func . (!$this->homepage ? $this->_get_customargs() : '/homepage/' . str_replace(',', '/', System::getVar('startargs'))) . '/' . UserUtil::getUidCacheString();
     }
     // assign some basic paths for the engine
     $this->template_dir = $this->themepath . '/templates';
     // default directory for templates
     $this->themepath = 'themes/' . $this->directory;
     $theme = ThemeUtil::getTheme($this->name);
     if (null === $theme) {
         $this->imagepath = $this->themepath . '/images';
         $this->imagelangpath = $this->themepath . '/images/' . $this->language;
         $this->stylepath = $this->themepath . '/style';
         $this->scriptpath = $this->themepath . '/javascript';
     } else {
         $this->imagepath = $this->themepath . '/Resources/public/images';
         $this->imagelangpath = $this->themepath . '/Resources/public/images/' . $this->language;
         $this->stylepath = $this->themepath . '/Resources/public/css';
         $this->scriptpath = $this->themepath . '/Resources/public/js';
     }
     // make the base vars available to all templates
     $this->assign('module', $this->toplevelmodule)->assign('uid', $this->uid)->assign('loggedin', $this->isloggedin)->assign('pagetype', $this->pagetype)->assign('themepath', $this->themepath)->assign('imagepath', $this->imagepath)->assign('imagelangpath', $this->imagelangpath)->assign('stylepath', $this->stylepath)->assign('scriptpath', $this->scriptpath);
     // load the theme variables
     $variables = ModUtil::apiFunc('ZikulaThemeModule', 'user', 'getvariables', array('theme' => $this->name));
     $this->assign($variables['variables']);
 }
Пример #6
0
 /**
  * Procedure for managinig stylesheets.
  *
  * @param array   $stylesheets List of demanded stylesheets.
  * @param array   $themeinfo   array of info on current theme
  * @param boolean $isAdminController
  *
  * @return array List of stylesheets
  */
 public static function prepareStylesheets($stylesheets, $themeinfo = array(), $isAdminController = false)
 {
     if (ThemeUtil::getVar('noCoreCss', false)) {
         $initStyle = null;
     } else {
         $initStyle = array('style/core.css');
     }
     // Add generic stylesheet as the first stylesheet.
     $event = new \Zikula\Core\Event\GenericEvent('stylesheet', array(), $initStyle);
     $coreStyle = EventUtil::getManager()->dispatch('pageutil.addvar_filter', $event)->getData();
     if (!is_array($stylesheets)) {
         $stylesheets = array();
     }
     // Add legacy stylesheet
     if (System::isLegacyMode('1.4.0')) {
         array_unshift($stylesheets, 'style/legacy.css');
     }
     // Add core stylesheet
     array_unshift($stylesheets, $coreStyle[0]);
     // is theme a 1.4.0 type bundle?
     $theme = null;
     if (!empty($themeinfo)) {
         $theme = ThemeUtil::getTheme($themeinfo['name']);
     }
     // Add bootstrap stylesheet only for 1.4.x type themes or if an admin controller is in use
     if (isset($theme) || $isAdminController) {
         $overrideBootstrapPath = ThemeUtil::getVar('bootstrapPath', '');
         // allows for theme override of bootstrap css path
         if (empty($overrideBootstrapPath)) {
             $bootstrapFontAwesomePath = ServiceUtil::getManager()->getParameter('zikula.stylesheet.bootstrap-font-awesome.path');
             array_unshift($stylesheets, $bootstrapFontAwesomePath);
         }
         // Add font-awesome
         if (!empty($overrideBootstrapPath)) {
             $fontAwesomePath = ServiceUtil::getManager()->getParameter('zikula.stylesheet.fontawesome.min.path');
             array_unshift($stylesheets, $fontAwesomePath);
         }
         $stylesheets = array_unique(array_values($stylesheets));
     }
     $iehack = '<!--[if IE]><link rel="stylesheet" type="text/css" href="style/core_iehacks.css" media="print,projection,screen" /><![endif]-->';
     PageUtil::addVar('header', $iehack);
     return $stylesheets;
 }
Пример #7
0
 /**
  * Constructor.
  *
  * @param Zikula_ServiceManager $serviceManager ServiceManager.
  * @param string                $moduleName     Module name ("zikula" for system plugins).
  * @param integer|null          $caching        Whether or not to cache (Zikula_View::CACHE_*) or use config variable (null).
  */
 public function __construct(Zikula_ServiceManager $serviceManager, $moduleName = '', $caching = null)
 {
     $this->serviceManager = $serviceManager;
     $this->eventManager = $this->serviceManager->get('event_dispatcher');
     $this->request = \ServiceUtil::get('request');
     // set the error reporting level
     $this->error_reporting = isset($GLOBALS['ZConfig']['Debug']['error_reporting']) ? $GLOBALS['ZConfig']['Debug']['error_reporting'] : E_ALL;
     $this->error_reporting &= ~E_USER_DEPRECATED;
     $this->allow_php_tag = true;
     // get variables from input
     $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
     $type = FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
     $func = FormUtil::getPassedValue('func', 'main', 'GETPOST', FILTER_SANITIZE_STRING);
     // set vars based on the module structures
     $this->homepage = PageUtil::isHomepage();
     $this->type = strtolower(!$this->homepage ? $type : System::getVar('starttype'));
     $this->func = strtolower(!$this->homepage ? $func : System::getVar('startfunc'));
     // Initialize the module property with the name of
     // the topmost module. For Hooks, Blocks, API Functions and others
     // you need to set this property to the name of the respective module!
     $this->toplevelmodule = ModUtil::getName();
     if (!$moduleName) {
         $moduleName = $this->toplevelmodule;
     }
     $this->modinfo = ModUtil::getInfoFromName($moduleName);
     $this->module = array($moduleName => $this->modinfo);
     // initialise environment vars
     $this->language = ZLanguage::getLanguageCode();
     $this->baseurl = System::getBaseUrl();
     $this->baseuri = System::getBaseUri();
     // system info
     $this->themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
     $this->theme = $theme = $this->themeinfo['directory'];
     $themeBundle = ThemeUtil::getTheme($this->themeinfo['name']);
     //---- Plugins handling -----------------------------------------------
     // add plugin paths
     switch ($this->modinfo['type']) {
         case ModUtil::TYPE_MODULE:
             $mpluginPathNew = "modules/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "modules/" . $this->modinfo['directory'] . "/templates/plugins";
             break;
         case ModUtil::TYPE_SYSTEM:
             $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
             break;
         default:
             $mpluginPathNew = "system/" . $this->modinfo['directory'] . "/Resources/views/plugins";
             $mpluginPath = "system/" . $this->modinfo['directory'] . "/templates/plugins";
     }
     // add standard plugin search path
     $this->plugins_dir = array();
     $this->addPluginDir('config/plugins');
     // Official override
     $this->addPluginDir('lib/legacy/viewplugins');
     // Core plugins
     $this->addPluginDir(isset($themeBundle) ? $themeBundle->getRelativePath() . '/plugins' : "themes/{$theme}/plugins");
     // Theme plugins
     $this->addPluginDir('plugins');
     // Smarty core plugins
     $this->addPluginDir($mpluginPathNew);
     // Plugins for current module
     $this->addPluginDir($mpluginPath);
     // Plugins for current module
     // check if the 'type' parameter in the URL is admin or adminplugin
     $legacyControllerType = FormUtil::getPassedValue('lct', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
     if ($type === 'admin' || $type === 'adminplugin' || $legacyControllerType === 'admin') {
         // include plugins of the Admin module to the plugins_dir array
         if (!$this instanceof Zikula_View_Theme) {
             $this->addPluginDir('system/AdminModule/Resources/views/plugins');
         } else {
             $this->load_filter('output', 'admintitle');
         }
     }
     // theme plugins module overrides
     $themePluginsPath = isset($themeBundle) ? $themeBundle->getRelativePath() . '/modules/$moduleName/plugins' : "themes/{$theme}/templates/modules/{$moduleName}/plugins";
     $this->addPluginDir($themePluginsPath);
     //---- Cache handling -------------------------------------------------
     if ($caching && in_array((int) $caching, array(0, 1, 2))) {
         $this->caching = (int) $caching;
     } else {
         $this->caching = (int) ModUtil::getVar('ZikulaThemeModule', 'render_cache');
     }
     $this->compile_id = '';
     $this->cache_id = '';
     // template compilation
     $this->compile_dir = CacheUtil::getLocalDir('view_compiled');
     $this->compile_check = ModUtil::getVar('ZikulaThemeModule', 'render_compile_check');
     $this->force_compile = ModUtil::getVar('ZikulaThemeModule', 'render_force_compile');
     // template caching
     $this->cache_dir = CacheUtil::getLocalDir('view_cache');
     $this->cache_lifetime = ModUtil::getVar('ZikulaThemeModule', 'render_lifetime');
     $this->expose_template = ModUtil::getVar('ZikulaThemeModule', 'render_expose_template') == true ? true : false;
     // register resource type 'z' this defines the way templates are searched
     // during {include file='my_template.tpl'} this enables us to store selected module
     // templates in the theme while others can be kept in the module itself.
     $this->register_resource('z', array('Zikula_View_Resource', 'z_get_template', 'z_get_timestamp', 'z_get_secure', 'z_get_trusted'));
     // set 'z' as default resource type
     $this->default_resource_type = 'z';
     // process some plugins specially when Render cache is enabled
     if (!$this instanceof Zikula_View_Theme && $this->caching) {
         $this->register_nocache_plugins();
     }
     // register the 'nocache' block to allow dynamic zones caching templates
     $this->register_block('nocache', array('Zikula_View_Resource', 'block_nocache'), false);
     // For ajax requests we use the short urls filter to 'fix' relative paths
     if ($this->serviceManager->get('zikula')->getStage() & Zikula_Core::STAGE_AJAX && System::getVar('shorturls')) {
         $this->load_filter('output', 'shorturls');
     }
     // register prefilters
     $this->register_prefilter('z_prefilter_add_literal');
     $this->register_prefilter('z_prefilter_gettext_params');
     //$this->register_prefilter('z_prefilter_notifyfilters');
     // assign some useful settings
     $this->assign('homepage', $this->homepage)->assign('modinfo', $this->modinfo)->assign('module', $moduleName)->assign('toplevelmodule', $this->toplevelmodule)->assign('type', $this->type)->assign('func', $this->func)->assign('lang', $this->language)->assign('themeinfo', $this->themeinfo)->assign('themepath', isset($themeBundle) ? $themeBundle->getRelativePath() : $this->baseurl . 'themes/' . $theme)->assign('baseurl', $this->baseurl)->assign('baseuri', $this->baseuri)->assign('moduleBundle', ModUtil::getModule($moduleName))->assign('themeBundle', $themeBundle);
     if (isset($themeBundle)) {
         $stylePath = $themeBundle->getRelativePath() . "/Resources/public/css";
         $javascriptPath = $themeBundle->getRelativePath() . "/Resources/public/js";
         $imagePath = $themeBundle->getRelativePath() . "/Resources/public/images";
         $imageLangPath = $themeBundle->getRelativePath() . "/Resources/public/images/" . $this->language;
     } else {
         $stylePath = $this->baseurl . "themes/{$theme}/style";
         $javascriptPath = $this->baseurl . "themes/{$theme}/javascript";
         $imagePath = $this->baseurl . "themes/{$theme}/images";
         $imageLangPath = $this->baseurl . "themes/{$theme}/images/" . $this->language;
     }
     $this->assign('stylepath', $stylePath)->assign('scriptpath', $javascriptPath)->assign('imagepath', $imagePath)->assign('imagelangpath', $imageLangPath);
     // for {gt} template plugin to detect gettext domain
     if ($this->modinfo['type'] == ModUtil::TYPE_MODULE) {
         $this->domain = ZLanguage::getModuleDomain($this->modinfo['name']);
     }
     // make render object available to modifiers
     parent::assign('zikula_view', $this);
     // add ServiceManager, EventManager and others to all templates
     parent::assign('serviceManager', $this->serviceManager);
     parent::assign('eventManager', $this->eventManager);
     parent::assign('zikula_core', $this->serviceManager->get('zikula'));
     parent::assign('request', $this->request);
     $modvars = ModUtil::getModvars();
     // Get all modvars from any modules that have accessed their modvars at least once.
     // provide compatibility 'alias' array keys
     // @todo remove after v1.4.0
     if (isset($modvars['ZikulaAdminModule'])) {
         $modvars['Admin'] = $modvars['ZikulaAdminModule'];
     }
     if (isset($modvars['ZikulaBlocksModule'])) {
         $modvars['Blocks'] = $modvars['ZikulaBlocksModule'];
     }
     if (isset($modvars['ZikulaCategoriesModule'])) {
         $modvars['Categories'] = $modvars['ZikulaCategoriesModule'];
     }
     if (isset($modvars['ZikulaExtensionsModule'])) {
         $modvars['Extensions'] = $modvars['ZikulaExtensionsModule'];
     }
     if (isset($modvars['ZikulaGroupsModule'])) {
         $modvars['Groups'] = $modvars['ZikulaGroupsModule'];
     }
     if (isset($modvars['ZikulaMailerModule'])) {
         $modvars['Mailer'] = $modvars['ZikulaMailerModule'];
     }
     if (isset($modvars['ZikulaPageLockModule'])) {
         $modvars['PageLock'] = $modvars['ZikulaPageLockModule'];
     }
     if (isset($modvars['ZikulaPermissionsModule'])) {
         $modvars['Permissions'] = $modvars['ZikulaPermissionsModule'];
     }
     if (isset($modvars['ZikulaSearchModule'])) {
         $modvars['Search'] = $modvars['ZikulaSearchModule'];
     }
     if (isset($modvars['ZikulaSecurityCenterModule'])) {
         $modvars['SecurityCenter'] = $modvars['ZikulaSecurityCenterModule'];
     }
     if (isset($modvars['ZikulaSettingsModule'])) {
         $modvars['Settings'] = $modvars['ZikulaSettingsModule'];
     }
     if (isset($modvars['ZikulaThemeModule'])) {
         $modvars['Theme'] = $modvars['ZikulaThemeModule'];
     }
     if (isset($modvars['ZikulaUsersModule'])) {
         $modvars['Users'] = $modvars['ZikulaUsersModule'];
     }
     // end compatibility aliases
     parent::assign('modvars', $modvars);
     $this->add_core_data();
     // metadata for SEO
     if (!$this->serviceManager->hasParameter('zikula_view.metatags')) {
         $this->serviceManager->setParameter('zikula_view.metatags', new ArrayObject(array()));
     }
     parent::assign('metatags', $this->serviceManager->getParameter('zikula_view.metatags'));
     if (isset($themeBundle) && $themeBundle->isTwigBased()) {
         // correct asset urls when smarty output is wrapped by twig theme
         $this->load_filter('output', 'asseturls');
     }
     $event = new \Zikula\Core\Event\GenericEvent($this);
     $this->eventManager->dispatch('view.init', $event);
 }
Пример #8
0
 /**
  * Get theme domain.
  *
  * @param string $name Theme name.
  *
  * @return string
  */
 public static function getThemeDomain($name)
 {
     $theme = ThemeUtil::getTheme($name);
     return null === $theme ? strtolower("theme_{$name}") : $theme->getTranslationDomain();
 }