Пример #1
0
 /**
  * Fetch the application template of a content page.
  * @param \Cx\Core\ContentManager\Model\Entity\Page $page The page object of which to fetch the application template from
  * @param String $component Optional argument to specify the component to load the template from, instead of using the page's module-attribute
  * @param String $themeType Optional argument to specify the output channel
  * @return String The content of the application template
  */
 public static function getContentTemplateOfPage($page, $component = null, $themeType = \Cx\Core\View\Model\Entity\Theme::THEME_TYPE_WEB)
 {
     try {
         $component = empty($component) ? $page->getModule() : $component;
         $cmd = !$page->getCmd() ? 'Default' : ucfirst($page->getCmd());
         $customAppTemplate = !$page->getApplicationTemplate() ? $cmd . '.html' : $page->getApplicationTemplate();
         $moduleFolderName = contrexx_isCoreModule($page->getModule()) ? 'core_modules' : 'modules';
         $themeFolderName = \Env::get('init')->getCurrentThemesPath();
         // use application template for all output channels
         if ($page->getUseCustomApplicationTemplateForAllChannels() && $page->getSkin()) {
             $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository();
             $themeFolderName = $themeRepo->findById($page->getSkin())->getFoldername();
         }
         // use default theme in case a custom set theme is no longer available
         if (empty($themeFolderName)) {
             $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository();
             $themeFolderName = $themeRepo->getDefaultTheme($themeType, $page->getLang())->getFoldername();
         }
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         // load custom application template from page's theme
         $themePath = $cx->getClassLoader()->getFilePath($cx->getWebsiteThemesPath() . '/' . $themeFolderName . '/' . $moduleFolderName . '/' . $component . '/Template/Frontend/' . $customAppTemplate);
         if ($themePath) {
             return file_get_contents($themePath);
         }
         // load default application template from page's theme
         if ($customAppTemplate != $cmd . '.html') {
             $themePath = $cx->getClassLoader()->getFilePath($cx->getWebsiteThemesPath() . '/' . $themeFolderName . '/' . $moduleFolderName . '/' . $component . '/Template/Frontend/' . $cmd . '.html');
             if ($themePath) {
                 return file_get_contents($themePath);
             }
         }
         // load default application template from component
         $modulePath = $cx->getClassLoader()->getFilePath($cx->getCodeBaseDocumentRootPath() . '/' . $moduleFolderName . '/' . $component . '/View/Template/Frontend/' . $cmd . '.html');
         if ($modulePath) {
             return file_get_contents($modulePath);
         }
         return;
     } catch (\Exception $e) {
         throw new \Exception('Error fetching the content template:' . $e);
     }
 }
Пример #2
0
 private function moduleExists($module)
 {
     if (empty($module)) {
         return true;
     }
     if (contrexx_isCoreModule($module)) {
         return true;
     } else {
         return contrexx_isModuleInstalled($module);
     }
 }
Пример #3
0
function contentManagerUpdates()
{
    //Database migration
    try {
        //update module name
        \Cx\Lib\UpdateUtil::sql("INSERT INTO `" . DBPREFIX . "modules` (`id`, `name`, `distributor`, `description_variable`, `status`, `is_required`, `is_core`, `is_active`, `is_licensed`) VALUES ('72', 'ContentManager', 'DEV', 'TXT_CONTENTMANAGER_MODULE_DESCRIPTION', 'n', '0', '1', '1', '1')");
        //update navigation url
        \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=ContentManager&act=new' WHERE `area_id` = 5");
        \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=ContentManager' WHERE `area_id` = 6");
        \Cx\Lib\UpdateUtil::sql("UPDATE `" . DBPREFIX . "backend_areas` SET `uri` = 'index.php?cmd=ContentManager' WHERE `area_id` = 161");
        //Alter the content_page table structure
        \Cx\Lib\UpdateUtil::table(DBPREFIX . 'content_page', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'node_id' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'id'), 'nodeIdShadowed' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'node_id'), 'lang' => array('type' => 'INT(11)', 'after' => 'nodeIdShadowed'), 'type' => array('type' => 'VARCHAR(16)', 'after' => 'lang'), 'caching' => array('type' => 'TINYINT(1)', 'after' => 'type'), 'updatedAt' => array('type' => 'timestamp', 'after' => 'caching'), 'updatedBy' => array('type' => 'CHAR(40)', 'after' => 'updatedAt'), 'title' => array('type' => 'VARCHAR(255)', 'after' => 'updatedBy'), 'linkTarget' => array('type' => 'VARCHAR(16)', 'notnull' => false, 'after' => 'title'), 'contentTitle' => array('type' => 'VARCHAR(255)', 'after' => 'linkTarget'), 'slug' => array('type' => 'VARCHAR(255)', 'after' => 'contentTitle'), 'content' => array('type' => 'longtext', 'after' => 'slug'), 'sourceMode' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'content'), 'customContent' => array('type' => 'VARCHAR(64)', 'notnull' => false, 'after' => 'sourceMode'), 'useCustomContentForAllChannels' => array('type' => 'INT(2)', 'notnull' => false, 'after' => 'customContent'), 'applicationTemplate' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'after' => 'useCustomContentForAllChannels'), 'useCustomApplicationTemplateForAllChannels' => array('type' => 'TINYINT(2)', 'after' => 'applicationTemplate'), 'cssName' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'useCustomApplicationTemplateForAllChannels'), 'cssNavName' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'cssName'), 'skin' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'cssNavName'), 'useSkinForAllChannels' => array('type' => 'INT(2)', 'notnull' => false, 'after' => 'skin'), 'metatitle' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'useSkinForAllChannels'), 'metadesc' => array('type' => 'text', 'after' => 'metatitle'), 'metakeys' => array('type' => 'text', 'after' => 'metadesc'), 'metarobots' => array('type' => 'VARCHAR(7)', 'notnull' => false, 'after' => 'metakeys'), 'start' => array('type' => 'timestamp', 'after' => 'metarobots'), 'end' => array('type' => 'timestamp', 'after' => 'start'), 'editingStatus' => array('type' => 'VARCHAR(16)', 'after' => 'end'), 'protection' => array('type' => 'INT(11)', 'after' => 'editingStatus'), 'frontendAccessId' => array('type' => 'INT(11)', 'after' => 'protection'), 'backendAccessId' => array('type' => 'INT(11)', 'after' => 'frontendAccessId'), 'display' => array('type' => 'TINYINT(1)', 'after' => 'backendAccessId'), 'active' => array('type' => 'TINYINT(1)', 'after' => 'display'), 'target' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'active'), 'module' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'target'), 'cmd' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => '', 'after' => 'module')), array('node_id' => array('fields' => array('node_id', 'lang'), 'type' => 'UNIQUE'), 'IDX_D8E86F54460D9FD7' => array('fields' => array('node_id'))), 'InnoDB', '', array('node_id' => array('table' => DBPREFIX . 'content_node', 'column' => 'id', 'onDelete' => 'SET NULL', 'onUpdate' => 'NO ACTION')));
    } catch (\Cx\Lib\UpdateException $e) {
        return "Error: {$e->sql}";
    }
    $virtualComponents = array('Agb', 'Ids', 'Imprint', 'Privacy');
    //migrating custom application template
    $pageRepo = \Env::get('em')->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
    $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository();
    $pages = $pageRepo->findBy(array('type' => \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION));
    foreach ($pages as $page) {
        try {
            //virtual components do not migrating custom application template
            if (in_array(ucfirst($page->getModule()), $virtualComponents)) {
                continue;
            }
            $designTemplateName = $page->getSkin() ? $themeRepo->findById($page->getSkin())->getFoldername() : $themeRepo->getDefaultTheme()->getFoldername();
            $cmd = !$page->getCmd() ? 'Default' : ucfirst($page->getCmd());
            $moduleFolderName = contrexx_isCoreModule($page->getModule()) ? 'core_modules' : 'modules';
            $themesPath = ASCMS_THEMES_PATH . '/' . $designTemplateName;
            //check common module or core_module folder exists
            if (!file_exists($themesPath . '/' . $moduleFolderName)) {
                \Cx\Lib\FileSystem\FileSystem::make_folder($themesPath . '/' . $moduleFolderName);
            }
            //check module's folder exists
            if (!file_exists($themesPath . '/' . $moduleFolderName . '/' . $page->getModule())) {
                \Cx\Lib\FileSystem\FileSystem::make_folder($themesPath . '/' . $moduleFolderName . '/' . $page->getModule());
            }
            //check module's template folder exists
            if (!file_exists($themesPath . '/' . $moduleFolderName . '/' . $page->getModule() . '/Template')) {
                \Cx\Lib\FileSystem\FileSystem::make_folder($themesPath . '/' . $moduleFolderName . '/' . $page->getModule() . '/Template');
            }
            //check module's Frontend folder exists
            if (!file_exists($themesPath . '/' . $moduleFolderName . '/' . $page->getModule() . '/Template/Frontend')) {
                \Cx\Lib\FileSystem\FileSystem::make_folder($themesPath . '/' . $moduleFolderName . '/' . $page->getModule() . '/Template/Frontend');
            }
            $targetPath = $themesPath . '/' . $moduleFolderName . '/' . $page->getModule() . '/Template/Frontend';
            $applicationTemplateName = getFilename($targetPath, $cmd . '_custom_' . FWLanguage::getLanguageCodeById($page->getLang()));
            if (file_exists($targetPath)) {
                //create a application template file
                $file = new \Cx\Lib\FileSystem\File($targetPath . '/' . $applicationTemplateName);
                $file->write($page->getContent());
            }
            //update application template
            $page->setContent('{APPLICATION_DATA}');
            $page->setApplicationTemplate($applicationTemplateName);
            $page->setUseCustomApplicationTemplateForAllChannels(1);
            \Env::get('em')->persist($page);
            \Env::get('em')->flush();
        } catch (\Exception $e) {
            throw new \Exception('Error :' . $e);
        }
    }
    return 'Application template migrated successfully.';
}
Пример #4
0
 /**
  * load the application template based on the application, cmd and theme name
  * 
  * @return array
  */
 public function loadApplicationTemplate()
 {
     $application = isset($_GET['app']) ? contrexx_input2raw($_GET['app']) : '';
     $section = preg_match('#^Media\\d+# i', $application) ? 'Media' : $application;
     $cmd = isset($_GET['area']) && $_GET['area'] != '' ? contrexx_input2raw($_GET['area']) : 'default';
     $template = isset($_GET['template']) ? contrexx_input2raw($_GET['template']) : '';
     $result = array('files' => array(), 'area' => '', 'path' => '');
     $themeRepo = new \Cx\Core\View\Model\Repository\ThemeRepository();
     if (!empty($section)) {
         if ($template > 0) {
             $theme = $themeRepo->findOneBy(array('id' => $template));
         } else {
             $theme = $themeRepo->getDefaultTheme();
         }
         $themeFolderName = $theme->getFoldername();
         $moduleFolderName = contrexx_isCoreModule($application) ? 'core_modules' : 'modules';
         $themePath = ASCMS_THEMES_PATH . '/' . $themeFolderName . '/' . $moduleFolderName . '/' . $section . '/Template/Frontend';
         if (file_exists($themePath)) {
             $templateFiles = $this->readDirs($themePath);
             foreach ($templateFiles as $templateFile) {
                 if (preg_match('#^' . ucfirst($cmd) . '_custom_# i', $templateFile) && preg_match('#\\.html# i', $templateFile)) {
                     $result['files'][] = $templateFile;
                 }
             }
         }
         $result['area'] = ucfirst($cmd);
         $result['path'] = '/themes/' . $themeFolderName . '/' . $moduleFolderName . '/' . $section . '/Template/Frontend';
         $additionalArguments = new \Cx\Core\Model\RecursiveArrayAccess(array());
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         $evm = $cx->getEvents();
         $evm->triggerEvent('wysiwygCssReload', array(array('skin' => $template), $additionalArguments));
         $result['wysiwygCssReload'] = $additionalArguments->toArray();
     }
     return $result;
 }