Exemplo n.º 1
0
 /**
  * Load the component data from component.yml file
  * 
  * @param \Cx\Core\View\Model\Entity\Theme $theme
  */
 public function loadComponentData(\Cx\Core\View\Model\Entity\Theme &$theme)
 {
     $websiteFilePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $codeBaseFilePath = \Env::get('cx')->getCodeBaseThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $filePath = file_exists($websiteFilePath) ? $websiteFilePath : (file_exists($codeBaseFilePath) ? $codeBaseFilePath : '');
     if ($filePath) {
         try {
             $objYaml = new \Symfony\Component\Yaml\Yaml();
             $objFile = new \Cx\Lib\FileSystem\File($filePath);
             $themeInformation = $objYaml->load($objFile->getData());
             $theme->setComponentData($themeInformation['DlcInfo']);
         } catch (\Exception $e) {
             \DBG::log($e->getMessage());
         }
     }
 }
Exemplo n.º 2
0
 function changeNestedNavigationCss($directory)
 {
     if ($handle = opendir($directory)) {
         while (($file = readdir($handle)) !== false) {
             if (!in_array($file, array('.', '..', '.svn'))) {
                 $file = $directory . '/' . $file;
                 if (is_dir($file)) {
                     changeNestedNavigationCss($file);
                 } else {
                     if (substr($file, -4) == '.css') {
                         try {
                             $objFile = new \Cx\Lib\FileSystem\File($file);
                             if (($data = $objFile->getData()) && !empty($data)) {
                                 $objFile->write(preg_replace('/#menu_level_(\\d+)(?!([\\w-_]+))/i', '.menu_level_\\1', $data));
                             }
                         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                             \DBG::msg($e->getMessage());
                             return false;
                         }
                     }
                 }
             }
         }
         closedir($handle);
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param Cx\Core_Modules\Listing\Model\ImportInterface $importInterface
  * @param type $filename
  * @throws \Cx\Lib\FileSystem\FileSystemException
  * @return type 
  */
 public static function importFromFile(\Cx\Core_Modules\Listing\Model\Entity\Importable $importInterface, $filename)
 {
     try {
         $objFile = new \Cx\Lib\FileSystem\File($filename);
         return self::import($importInterface, $objFile->getData());
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
         throw new DataSetException("Failed to load data from file {$filename}!");
     }
 }
 /**
  * Get update websiteDetailsFromYml
  * 
  * @param string $file yml file name
  * 
  * @return array website details
  */
 public function getUpdateWebsiteDetailsFromYml($file)
 {
     if (!file_exists($file)) {
         return;
     }
     $objFile = new \Cx\Lib\FileSystem\File($file);
     $yaml = new \Symfony\Component\Yaml\Yaml();
     return $yaml->load($objFile->getData());
 }
Exemplo n.º 5
0
 protected function fetchResponse($license, $_CONFIG, $forceTemplate, $_CORELANG)
 {
     $v = preg_split('#\\.#', $_CONFIG['coreCmsVersion']);
     $e = $_CONFIG['coreCmsEdition'];
     $version = current($v);
     unset($v[key($v)]);
     foreach ($v as $part) {
         $version *= 100;
         $version += $part;
     }
     $srvUri = 'updatesrv1.contrexx.com';
     $srvPath = '/';
     $data = array('installationId' => $license->getInstallationId(), 'licenseKey' => $license->getLicenseKey(), 'edition' => $license->getEditionName(), 'version' => $this->coreCmsVersion, 'versionstate' => $this->coreCmsStatus, 'domainName' => $this->domainUrl, 'sendTemplate' => $forceTemplate);
     if (true) {
         try {
             $objFile = new \Cx\Lib\FileSystem\File(ASCMS_INSTANCE_PATH . ASCMS_INSTANCE_OFFSET . '/config/License.lic');
             $rawData = $objFile->getData();
             $response = json_decode(base64_decode($rawData));
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             $license->setState(License::LICENSE_ERROR);
             $license->setGrayzoneMessages(array(\FWLanguage::getLanguageCodeById(LANG_ID) => new Message(\FWLanguage::getLanguageCodeById(LANG_ID), $_CORELANG['TXT_LICENSE_COMMUNICATION_ERROR'])));
             $license->check();
             throw $e;
         }
         return $response;
     }
     $a = $_SERVER['REMOTE_ADDR'];
     $r = 'http://';
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
         $r = 'https://';
     }
     $r .= $_SERVER['SERVER_NAME'] . ASCMS_INSTANCE_OFFSET;
     $request = new \HTTP_Request2('http://' . $srvUri . $srvPath . '?v=' . $version, \HTTP_Request2::METHOD_POST);
     $request->setHeader('X-Edition', $e);
     $request->setHeader('X-Remote-Addr', $a);
     $request->setHeader('Referer', $r);
     $jd = new \Cx\Core\Json\JsonData();
     $request->addPostParameter('data', $jd->json($data));
     try {
         $objResponse = $request->send();
         if ($objResponse->getStatus() !== 200) {
             $license->setState(License::LICENSE_ERROR);
             $license->setGrayzoneMessages(array(\FWLanguage::getLanguageCodeById(LANG_ID) => new Message(\FWLanguage::getLanguageCodeById(LANG_ID), $_CORELANG['TXT_LICENSE_COMMUNICATION_ERROR'])));
             $license->check();
             return null;
         } else {
             \DBG::dump($objResponse->getBody());
             $response = json_decode($objResponse->getBody());
         }
     } catch (\HTTP_Request2_Exception $objException) {
         $license->setState(License::LICENSE_ERROR);
         $license->setGrayzoneMessages(array(\FWLanguage::getLanguageCodeById(LANG_ID) => new Message(\FWLanguage::getLanguageCodeById(LANG_ID), $_CORELANG['TXT_LICENSE_COMMUNICATION_ERROR'])));
         $license->check();
         throw $objException;
     }
     return $response;
 }
Exemplo n.º 6
0
 /**
  * Imports a DataSet from a file using an import interface
  *
  * @param Cx\Core_Modules\Listing\Model\Entity\Importable $importInterface
  * @param string $filename
  * @param boolean $useCache Wether to try to load the file from cache or not
  * @throws \Cx\Lib\FileSystem\FileSystemException
  * @return \Cx\Core_Modules\Listing\Model\Entity\DataSet
  */
 public static function importFromFile(\Cx\Core_Modules\Listing\Model\Entity\Importable $importInterface, $filename, $useCache = true)
 {
     if ($useCache) {
         $cache = \Cx\Core\Core\Controller\Cx::instanciate()->getComponent('Cache');
         if (!$cache) {
             $useCache = false;
         }
     }
     if ($useCache) {
         // try to load imported from cache
         $objImport = $cache->fetch($filename);
         if ($objImport) {
             return $objImport;
         }
     }
     try {
         $objFile = new \Cx\Lib\FileSystem\File($filename);
         $objImport = self::import($importInterface, $objFile->getData());
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
         throw new DataSetException("Failed to load data from file {$filename}!");
     }
     if ($useCache) {
         // store imported to cache
         $cache->save($filename, $objImport);
     }
     return $objImport;
 }
Exemplo n.º 7
0
 /**
  * Set the component's name in frontend and backend language files
  * @param string $baseDir Directory in which the recursive replace should be done
  */
 public function setComponentName($baseDir)
 {
     $componentNamePlaceholder = '{COMPONENT_NAME}';
     $directoryIterator = new \RecursiveDirectoryIterator($baseDir);
     $iterator = new \RecursiveIteratorIterator($directoryIterator);
     $files = new \RegexIterator($iterator, '/^.+(frontend|backend)\\.php$/i', \RegexIterator::GET_MATCH);
     // recursive foreach frontend.php and backend.php file
     foreach ($files as $file) {
         // prepare data
         $file = current($file);
         // file_get_contents()
         $objFile = new \Cx\Lib\FileSystem\File($file);
         $content = $objFile->getData();
         $content = preg_replace('/' . preg_quote($componentNamePlaceholder) . '/', preg_quote($this->componentName), $content);
         echo 'Replace ' . $componentNamePlaceholder . ' by ' . $this->componentName . ' in ' . $file . "\n";
         $objFile->write($content);
     }
 }
Exemplo n.º 8
0
/**
 * This should only be executed when updating from version 2.2.6 or older
 * Fix for the following tickets:
 * http://bugs.contrexx.com/contrexx/ticket/1412
 * http://bugs.contrexx.com/contrexx/ticket/1043
 * @see http://helpdesk.comvation.com/131276-Die-Navigation-meiner-Seite-wird-nicht-mehr-korrekt-angezeigt
 *
 * Adds placeholder {LEVELS_FULL} to all non-empty subnavbars
 * Adds placeholder {LEVELS_BRANCH} to all navbars having a block named 'navigation' but none 'level_1'
 */
function _updateNavigations()
{
    global $objDatabase, $_CORELANG;
    $navbars = array('navbar', 'navbar2', 'navbar3');
    $subnavbars = array('subnavbar', 'subnavbar2', 'subnavbar3');
    // Find all themes
    $result = $objDatabase->Execute('SELECT `themesname`, `foldername` FROM `' . DBPREFIX . 'skins`');
    if ($result->EOF) {
        \DBG::msg('No themes, really?');
        return false;
    }
    // Update navigations for all themes
    $errorMessages = '';
    while (!$result->EOF) {
        if (!is_dir(ASCMS_THEMES_PATH . '/' . $result->fields['foldername'])) {
            \DBG::msg('Skipping theme "' . $result->fields['themesname'] . '"; No such folder!');
            $errorMessages .= '<div class="message-warning">' . sprintf($_CORELANG['TXT_CSS_UPDATE_MISSING_FOLDER'], $result->fields['themesname']) . '</div>';
            $result->moveNext();
            continue;
        }
        \DBG::msg('Updating navigations for theme "' . $result->fields['themesname'] . '" (' . $type . ')');
        // add {LEVELS_FULL} to all non-empty subnavbars
        foreach ($subnavbars as $subnavbar) {
            try {
                $objFile = new \Cx\Lib\FileSystem\File(ASCMS_THEMES_PATH . '/' . $result->fields['foldername'] . '/' . $subnavbar . '.html');
                $content = $objFile->getData();
            } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                \DBG::msg($e->getMessage());
                continue;
            }
            if (trim($content) == '') {
                continue;
            }
            $content = '{LEVELS_FULL}' . "\r\n" . $content;
            try {
                $objFile->write($content);
            } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                \DBG::msg($e->getMessage());
                continue;
            }
            \DBG::msg('Updated file ' . $subnavbar . '.html for theme ' . $result->fields['themesname']);
        }
        // add {LEVELS_BRANCH} to all navbars matching the following criterias:
        // 1. blockExists('navigation')
        // 2. !blockExists('level_1')
        foreach ($navbars as $navbar) {
            try {
                $objFile = new \Cx\Lib\FileSystem\File(ASCMS_THEMES_PATH . '/' . $result->fields['foldername'] . '/' . $navbar . '.html');
                $content = $objFile->getData();
            } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                \DBG::msg($e->getMessage());
                continue;
            }
            if (trim($content) == '') {
                continue;
            }
            $template = new \Cx\Core\Html\Sigma('.');
            $template->setTemplate($content);
            if (!$template->blockExists('navigation')) {
                continue;
            }
            if ($template->blockExists('level_1')) {
                continue;
            }
            $content = '{LEVELS_BRANCH}' . "\r\n" . $content;
            try {
                $objFile->write($content);
            } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
                \DBG::msg($e->getMessage());
                continue;
            }
            \DBG::msg('Updated file ' . $navbar . '.html for theme ' . $result->fields['themesname']);
        }
        $result->moveNext();
    }
    if (!empty($errorMessages)) {
        setUpdateMsg($errorMessages, 'msg');
        setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_CONTINUE_UPDATE'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
        $_SESSION['contrexx_update']['update']['done'][] = 'navigations';
        return false;
    }
    return true;
}
Exemplo n.º 9
0
 /**
  * Checks if file exists, if not - creates new one with metadata
  * 
  * @param string $filename
  * @param array $unique_keys
  * @param string $identifier
  * @return boolean
  * @throws \Cx\Core\Setting\Controller\SettingException
  */
 protected function prepareFile($filename, $unique_keys = array(), $identifier)
 {
     if ($this->fileExistsAndNotEmpty($filename)) {
         return true;
     }
     \DBG::log('Creating new file');
     try {
         $file = new \Cx\Lib\FileSystem\File($filename);
         $file->touch();
         $data = trim($file->getData());
         if (empty($data)) {
             $inidata = "meta:\n" . "   auto_increment: 1\n";
             if (!empty($identifier)) {
                 $inidata .= "   identifier: {$identifier}\n";
             }
             if (!empty($unique_keys)) {
                 $inidata .= "   unique_keys:\n";
                 foreach ($unique_keys as $key) {
                     $inidata .= "        - {$key}";
                 }
             }
             $file->write($inidata);
         }
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::log('EX ' . $e->getMessage());
         throw new \Cx\Core\Setting\Controller\YamlRepositoryException($e->getMessage());
     }
 }
Exemplo n.º 10
0
 /**
  * import themes from archive
  * @access   private
  * @param    string   $themes
  */
 private function importFile()
 {
     global $_ARRAYLANG;
     $this->_cleantmp();
     switch ($_GET['import']) {
         case 'remote':
             $archiveFile = $this->_fetchRemoteFile($_POST['importremote']);
             if ($archiveFile === false) {
                 return false;
             }
             $archive = new \PclZip($archiveFile);
             //no break
         //no break
         case 'local':
             if (empty($archive)) {
                 if (($archiveFile = $this->checkUpload()) === false) {
                     return false;
                 }
                 $archive = new \PclZip($this->_archiveTempPath . $archiveFile);
             }
             $content = $archive->listContent();
             $themeName = '';
             $themeDirectory = '';
             $themeDirectoryFromArchive = '';
             $arrDirectories = array();
             // analyze theme archive
             if (!$this->validateArchiveStructure($content, $themeDirectory, $themeDirectoryFromArchive, $themeName, $arrDirectories, $archiveFile)) {
                 return false;
             }
             // prepare directory structure of new theme
             if (!$this->createDirectoryStructure($themeDirectory, $arrDirectories)) {
                 return false;
             }
             // try to get the theme name from yml
             $themeInfoContent = $archive->extract(PCLZIP_OPT_BY_NAME, $themeDirectoryFromArchive . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE, PCLZIP_OPT_EXTRACT_AS_STRING);
             if (!empty($themeInfoContent)) {
                 $yaml = new \Symfony\Component\Yaml\Yaml();
                 $themeInfo = $yaml->load($themeInfoContent[0]['content']);
                 $themeName = isset($themeInfo['DlcInfo']['name']) ? $themeInfo['DlcInfo']['name'] : $themeName;
             }
             //create database entry
             $this->validateThemeName($themeName);
             $theme = new \Cx\Core\View\Model\Entity\Theme();
             $theme->setThemesname($themeName);
             $theme->setFoldername($themeDirectory);
             //extract archive files
             $this->extractArchive($archive, $theme, $themeDirectoryFromArchive);
             $this->replaceThemeName($themeDirectoryFromArchive, $themeDirectory, $this->websiteThemesPath . $arrDirectories[0]);
             $this->insertSkinIntoDb($theme);
             \Message::add(contrexx_raw2xhtml($themeName) . ' (' . $themeDirectory . ') ' . $_ARRAYLANG['TXT_THEME_SUCCESSFULLY_IMPORTED']);
             break;
         case 'filesystem':
             $themeName = null;
             $existingThemeInFilesystem = !empty($_POST['existingdirName']) ? contrexx_input2raw($_POST['existingdirName']) : null;
             $themePath = file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem) ? \Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem : \Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem;
             if (!file_exists($themePath)) {
                 \Message::add($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS'], \Message::CLASS_ERROR);
                 return false;
             }
             $yamlFile = file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml') ? \Env::get('cx')->getWebsiteThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml' : (file_exists(\Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml') ? \Env::get('cx')->getCodeBaseThemesPath() . '/' . $existingThemeInFilesystem . '/component.yml' : '');
             if ($yamlFile) {
                 $objFile = new \Cx\Lib\FileSystem\File($yamlFile);
                 $yaml = new \Symfony\Component\Yaml\Yaml();
                 $themeInformation = $yaml->load($objFile->getData());
                 $themeName = $themeInformation['DlcInfo']['name'];
             }
             $themeName = $themeName ?: $existingThemeInFilesystem;
             if (empty($themeName) || empty($existingThemeInFilesystem)) {
                 \Message::add($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS'], \Message::CLASS_ERROR);
                 return false;
             }
             $this->validateThemeName($themeName);
             $theme = new \Cx\Core\View\Model\Entity\Theme();
             $theme->setThemesname($themeName);
             $theme->setFoldername($existingThemeInFilesystem);
             if ($this->insertSkinIntoDb($theme)) {
                 \Message::add(contrexx_raw2xhtml($themeName) . ' ' . $_ARRAYLANG['TXT_STATUS_SUCCESSFULLY_CREATE']);
             }
             break;
         default:
             //everything else should never be the case
             \Message::add("GET Request Error. 'import' should be either 'local' or 'remote'", \Message::CLASS_ERROR);
             return false;
             break;
     }
     // Theme build successfully
     \Cx\Core\Csrf\Controller\Csrf::redirect('index.php?cmd=ViewManager&act=templates&themes=' . $theme->getFoldername());
 }