Example #1
0
 public function testPutGetCache()
 {
     $file = $this->getPath('putgetcache.txt');
     $content = ['test', 'key' => 'value'];
     $this->assertTrue(rex_file::putCache($file, $content), 'putCache() returns true on success');
     $this->assertEquals($content, rex_file::getCache($file), 'getCache() returns content of file');
 }
Example #2
0
 /**
  * Loads the properties of package.yml.
  */
 private function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::cache('packages.cache'));
     }
     $id = $this->getPackageId();
     $file = $this->getPath(self::FILE_PACKAGE);
     if (!file_exists($file)) {
         $this->propertiesLoaded = true;
         return;
     }
     if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) {
         $properties = $cache[$id]['data'];
     } else {
         $properties = rex_file::getConfig($file);
         $cache[$id]['timestamp'] = filemtime($file);
         $cache[$id]['data'] = $properties;
         static $registeredShutdown = false;
         if (!$registeredShutdown) {
             $registeredShutdown = true;
             register_shutdown_function(function () use(&$cache) {
                 foreach ($cache as $package => $_) {
                     if (!rex_package::exists($package)) {
                         unset($cache[$package]);
                     }
                 }
                 rex_file::putCache(rex_path::cache('packages.cache'), $cache);
             });
         }
     }
     foreach ($properties as $key => $value) {
         if (!isset($this->properties[$key])) {
             $this->properties[$key] = rex_i18n::translateArray($value, false, [$this, 'i18n']);
         }
     }
     $this->propertiesLoaded = true;
 }
Example #3
0
 /**
  * Schreibt Spracheigenschaften in die Datei include/clang.php.
  *
  * @throws rex_exception
  */
 public static function generateCache()
 {
     $lg = rex_sql::factory();
     $lg->setQuery('select * from ' . rex::getTablePrefix() . 'clang order by priority');
     $clangs = [];
     foreach ($lg as $lang) {
         $id = $lang->getValue('id');
         foreach ($lg->getFieldnames() as $field) {
             $clangs[$id][$field] = $lang->getValue($field);
         }
     }
     $file = rex_path::coreCache('clang.cache');
     if (rex_file::putCache($file, $clangs) === false) {
         throw new rex_exception('Clang cache file could not be generated');
     }
 }
Example #4
0
 private static function setCache($path, $data)
 {
     self::$cache[$path]['stamp'] = time();
     self::$cache[$path]['data'] = $data;
     rex_file::putCache(rex_path::addonCache('install', 'webservice.cache'), self::$cache);
 }
Example #5
0
 /**
  * Generiert eine Liste mit den Kindkategorien einer Kategorie.
  *
  * @param int $category_id Id der Kategorie
  *
  * @return bool TRUE bei Erfolg, sonst FALSE
  */
 public static function generateCategoryList($category_id)
 {
     // sanity check
     if ($category_id < 0) {
         return false;
     }
     $query = 'SELECT id, cast( name AS SIGNED ) AS sort FROM ' . rex::getTable('media_category') . ' WHERE parent_id = ' . $category_id . ' ORDER BY sort, name';
     $sql = rex_sql::factory();
     //$sql->setDebug();
     $sql->setQuery($query);
     $cacheArray = [];
     for ($i = 0; $i < $sql->getRows(); ++$i) {
         $cacheArray[] = $sql->getValue('id');
         $sql->next();
     }
     $list_file = rex_path::addonCache('mediapool', $category_id . '.mclist');
     if (rex_file::putCache($list_file, $cacheArray)) {
         return true;
     }
     return false;
 }
Example #6
0
// add core lang directory to rex_i18n
rex_i18n::addDirectory(rex_path::core('lang'));
// add core base-fragmentpath to fragmentloader
rex_fragment::addDirectory(rex_path::core('fragments/'));
// ----------------- FUNCTIONS
require_once rex_path::core('functions/function_rex_globals.php');
require_once rex_path::core('functions/function_rex_other.php');
// ----------------- VERSION
rex::setProperty('version', '5.0.0-alpha7');
$cacheFile = rex_path::cache('config.yml.cache');
$configFile = rex_path::data('config.yml');
if (file_exists($cacheFile) && file_exists($configFile) && filemtime($cacheFile) >= filemtime($configFile)) {
    $config = rex_file::getCache($cacheFile);
} else {
    $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile));
    rex_file::putCache($cacheFile, $config);
}
foreach ($config as $key => $value) {
    if (in_array($key, ['fileperm', 'dirperm'])) {
        $value = octdec($value);
    }
    rex::setProperty($key, $value);
}
date_default_timezone_set(rex::getProperty('timezone', 'Europe/Berlin'));
if (!rex::isSetup()) {
    rex_error_handler::register();
}
// ----------------- REX PERMS
rex_complex_perm::register('clang', 'rex_clang_perm');
// ----- SET CLANG
if (!rex::isSetup()) {
Example #7
0
 /**
  * save config to file-cache.
  */
 private static function generateCache()
 {
     if (rex_file::putCache(REX_CONFIG_FILE_CACHE, self::$data) <= 0) {
         throw new rex_exception('rex-config: unable to write cache file ' . REX_CONFIG_FILE_CACHE);
     }
 }
Example #8
0
 /**
  * Saves the cache.
  */
 public static function saveCache()
 {
     if (!self::$cacheChanged) {
         return;
     }
     if (!is_writable(dirname(self::$cacheFile))) {
         throw new Exception("Unable to write autoload cachefile '" . self::$cacheFile . "'!");
     }
     // remove obsolete dirs from cache
     foreach (self::$dirs as $dir => $files) {
         if (!in_array($dir, self::$addedDirs)) {
             unset(self::$dirs[$dir]);
         }
     }
     rex_file::putCache(self::$cacheFile, [self::$classes, self::$dirs]);
     self::$cacheChanged = false;
 }
Example #9
0
 public function sendMedia($sourceCacheFilename, $headerCacheFilename, $save = false)
 {
     if ($this->asImage) {
         $src = $this->getImageSource();
     } else {
         $src = rex_file::get($this->getMediapath());
     }
     $this->setHeader('Content-Length', rex_string::size($src));
     $header = $this->getHeader();
     if (!array_key_exists('Content-Type', $header)) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $content_type = finfo_file($finfo, $this->getMediapath());
         if ($content_type != '') {
             $this->setHeader('Content-Type', $content_type);
         }
     }
     if (!array_key_exists('Content-Disposition', $header)) {
         $this->setHeader('Content-Disposition', 'inline; filename="' . $this->getMediaFilename() . '";');
     }
     if (!array_key_exists('Last-Modified', $header)) {
         $this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s T'));
     }
     rex_response::cleanOutputBuffers();
     foreach ($this->header as $t => $c) {
         header($t . ': ' . $c);
     }
     echo $src;
     if ($save) {
         rex_file::putCache($headerCacheFilename, $this->header);
         rex_file::put($sourceCacheFilename, $src);
     }
 }
Example #10
0
 /**
  * Loads the properties of package.yml.
  */
 public function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::coreCache('packages.cache'));
     }
     $id = $this->getPackageId();
     $file = $this->getPath(self::FILE_PACKAGE);
     if (!file_exists($file)) {
         $this->propertiesLoaded = true;
         return;
     }
     if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) {
         $properties = $cache[$id]['data'];
     } else {
         try {
             $properties = rex_file::getConfig($file);
             $cache[$id]['timestamp'] = filemtime($file);
             $cache[$id]['data'] = $properties;
             static $registeredShutdown = false;
             if (!$registeredShutdown) {
                 $registeredShutdown = true;
                 register_shutdown_function(function () use(&$cache) {
                     foreach ($cache as $package => $_) {
                         if (!rex_package::exists($package)) {
                             unset($cache[$package]);
                         }
                     }
                     rex_file::putCache(rex_path::coreCache('packages.cache'), $cache);
                 });
             }
         } catch (rex_yaml_parse_exception $exception) {
             if ($this->isInstalled()) {
                 throw $exception;
             }
             $properties = [];
         }
     }
     $this->properties = array_intersect_key($this->properties, ['install' => null, 'status' => null]);
     if ($properties) {
         foreach ($properties as $key => $value) {
             if (isset($this->properties[$key])) {
                 continue;
             }
             if ('supportpage' !== $key) {
                 $value = rex_i18n::translateArray($value, false, [$this, 'i18n']);
             } elseif (!preg_match('@^https?://@i', $value)) {
                 $value = 'http://' . $value;
             }
             $this->properties[$key] = $value;
         }
     }
     $this->propertiesLoaded = true;
 }
Example #11
0
 /**
  * Generiert alle *.alist u. *.clist Dateien einer Kategorie/eines Artikels.
  *
  * @param int $parent_id KategorieId oder ArtikelId, die erneuert werden soll
  *
  * @return bool TRUE wenn der Artikel gelöscht wurde, sonst eine Fehlermeldung
  */
 public static function generateLists($parent_id)
 {
     // sanity check
     if ($parent_id < 0) {
         return false;
     }
     // --------------------------------------- ARTICLE LIST
     $GC = rex_sql::factory();
     // $GC->setDebug();
     $GC->setQuery('select * from ' . rex::getTablePrefix() . 'article where clang_id=:clang AND ((parent_id=:id and startarticle=0) OR (id=:id and startarticle=1)) order by priority,name', ['id' => $parent_id, 'clang' => rex_clang::getStartId()]);
     $cacheArray = [];
     foreach ($GC as $row) {
         $cacheArray[] = (int) $row->getValue('id');
     }
     $article_list_file = rex_path::addonCache('structure', $parent_id . '.alist');
     if (rex_file::putCache($article_list_file, $cacheArray) === false) {
         return rex_i18n::msg('article_could_not_be_generated') . ' ' . rex_i18n::msg('check_rights_in_directory') . rex_path::addonCache('structure');
     }
     // --------------------------------------- CAT LIST
     $GC = rex_sql::factory();
     $GC->setQuery('select * from ' . rex::getTablePrefix() . 'article where parent_id=:id and clang_id=:clang and startarticle=1 order by catpriority,name', ['id' => $parent_id, 'clang' => rex_clang::getStartId()]);
     $cacheArray = [];
     foreach ($GC as $row) {
         $cacheArray[] = (int) $row->getValue('id');
     }
     $article_categories_file = rex_path::addonCache('structure', $parent_id . '.clist');
     if (rex_file::putCache($article_categories_file, $cacheArray) === false) {
         return rex_i18n::msg('article_could_not_be_generated') . ' ' . rex_i18n::msg('check_rights_in_directory') . rex_path::addonCache('structure');
     }
     return true;
 }
Example #12
0
<?php

/** @var rex_addon $this */
if (rex_string::versionCompare($this->getVersion(), '2.0.1', '<') && rex_config::has('install')) {
    rex_file::putCache($this->getDataPath('config.json'), rex_config::get('install'));
    rex_config::removeNamespace('install');
}
Example #13
0
 public static function generatePathFile($params)
 {
     $setDomain = function (rex_yrewrite_domain &$domain, &$path, rex_structure_element $element) {
         $id = $element->getId();
         $clang = $element->getClang();
         if (isset(rex_yrewrite::$domainsByMountId[$id][$clang])) {
             $domain = rex_yrewrite::$domainsByMountId[$id][$clang];
             $path = rex_yrewrite::$scheme->getClang($clang, $domain);
         }
     };
     $setPath = function (rex_yrewrite_domain $domain, $path, rex_article $art) use($setDomain) {
         $setDomain($domain, $path, $art);
         if (($redirection = rex_yrewrite::$scheme->getRedirection($art, $domain)) instanceof rex_structure_element) {
             rex_yrewrite::$paths['redirections'][$art->getId()][$art->getClang()] = ['id' => $redirection->getId(), 'clang' => $redirection->getClang()];
             unset(rex_yrewrite::$paths['paths'][$domain->getName()][$art->getId()][$art->getClang()]);
             return;
         }
         unset(rex_yrewrite::$paths['redirections'][$art->getId()][$art->getClang()]);
         $url = rex_yrewrite::$scheme->getCustomUrl($art, $domain);
         if (!is_string($url)) {
             $url = rex_yrewrite::$scheme->appendArticle($path, $art, $domain);
         }
         rex_yrewrite::$paths['paths'][$domain->getName()][$art->getId()][$art->getClang()] = ltrim($url, '/');
     };
     $generatePaths = function (rex_yrewrite_domain $domain, $path, rex_category $cat) use(&$generatePaths, $setDomain, $setPath) {
         $path = rex_yrewrite::$scheme->appendCategory($path, $cat, $domain);
         $setDomain($domain, $path, $cat);
         foreach ($cat->getChildren() as $child) {
             $generatePaths($domain, $path, $child);
         }
         foreach ($cat->getArticles() as $art) {
             $setPath($domain, $path, $art);
         }
     };
     $ep = isset($params['extension_point']) ? $params['extension_point'] : '';
     switch ($ep) {
         // clang and id specific update
         case 'CAT_DELETED':
         case 'ART_DELETED':
             foreach (self::$paths['paths'] as $domain => $c) {
                 unset(self::$paths['paths'][$domain][$params['id']]);
             }
             unset(self::$paths['redirections'][$params['id']]);
             if (0 == $params['re_id']) {
                 break;
             }
             $params['id'] = $params['re_id'];
             // no break
         // no break
         case 'CAT_ADDED':
         case 'CAT_UPDATED':
         case 'CAT_STATUS':
         case 'ART_ADDED':
         case 'ART_UPDATED':
         case 'ART_STATUS':
             rex_article_cache::delete($params['id']);
             $domain = self::$domainsByMountId[0][$params['clang']];
             $path = self::$scheme->getClang($params['clang'], $domain);
             $art = rex_article::get($params['id'], $params['clang']);
             $tree = $art->getParentTree();
             if ($art->isStartArticle()) {
                 $cat = array_pop($tree);
             }
             foreach ($tree as $parent) {
                 $path = self::$scheme->appendCategory($path, $parent, $domain);
                 $setDomain($domain, $path, $parent);
                 $setPath($domain, $path, rex_article::get($parent->getId(), $parent->getClang()));
             }
             if ($art->isStartArticle()) {
                 $generatePaths($domain, $path, $cat);
             } else {
                 $setPath($domain, $path, $art);
             }
             break;
             // update all
         // update all
         case 'CLANG_DELETED':
         case 'CLANG_ADDED':
         case 'CLANG_UPDATED':
             //case 'ALL_GENERATED':
         //case 'ALL_GENERATED':
         default:
             self::$paths = ['paths' => [], 'redirections' => []];
             foreach (rex_clang::getAllIds() as $clangId) {
                 $domain = self::$domainsByMountId[0][$clangId];
                 $path = self::$scheme->getClang($clangId, $domain);
                 foreach (rex_category::getRootCategories(false, $clangId) as $cat) {
                     $generatePaths($domain, $path, $cat);
                 }
                 foreach (rex_article::getRootArticles(false, $clangId) as $art) {
                     $setPath($domain, $path, $art);
                 }
             }
             break;
     }
     rex_file::putCache(self::$pathfile, self::$paths);
 }