/** * @param string $name * * @return null|self */ public static function get($name) { if (!$name) { return null; } return self::getInstance($name, function ($name) { $media_path = rex_path::addonCache('mediapool', $name . '.media'); if (!file_exists($media_path)) { rex_media_cache::generate($name); } if (file_exists($media_path)) { $cache = rex_file::getCache($media_path); $aliasMap = ['filename' => 'name', 'filetype' => 'type', 'filesize' => 'size']; $media = new self(); foreach ($cache as $key => $value) { if (array_key_exists($key, $aliasMap)) { $var_name = $aliasMap[$key]; } else { $var_name = $key; } $media->{$var_name} = $value; } $media->category = null; return $media; } return null; }); }
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'); }
/** * 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; }
public function execute() { if (!rex::getUser()->isAdmin()) { throw new rex_api_exception('You do not have the permission!'); } $installAddon = rex_addon::get('install'); $versions = self::getVersions(); $versionId = rex_request('version_id', 'int'); if (!isset($versions[$versionId])) { return null; } $version = $versions[$versionId]; if (!rex_string::versionCompare($version['version'], rex::getVersion(), '>')) { throw new rex_api_exception(sprintf('Existing version of Core (%s) is newer than %s', rex::getVersion(), $version['version'])); } try { $archivefile = rex_install_webservice::getArchive($version['path']); } catch (rex_functional_exception $e) { throw new rex_api_exception($e->getMessage()); } $message = ''; $temppath = rex_path::coreCache('.new.core/'); try { if ($version['checksum'] != md5_file($archivefile)) { throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_checksum')); } if (!rex_install_archive::extract($archivefile, $temppath)) { throw new rex_functional_exception($installAddon->i18n('warning_core_zip_not_extracted')); } if (!is_dir($temppath . 'core')) { throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_format')); } $coreAddons = []; /** @var rex_addon[] $updateAddons */ $updateAddons = []; if (is_dir($temppath . 'addons')) { foreach (rex_finder::factory($temppath . 'addons')->dirsOnly() as $dir) { $addonkey = $dir->getBasename(); $addonPath = $dir->getRealPath() . '/'; if (!file_exists($addonPath . rex_package::FILE_PACKAGE)) { continue; } $config = rex_file::getConfig($addonPath . rex_package::FILE_PACKAGE); if (!isset($config['version']) || rex_addon::exists($addonkey) && rex_string::versionCompare($config['version'], rex_addon::get($addonkey)->getVersion(), '<')) { continue; } $coreAddons[$addonkey] = $addonkey; if (rex_addon::exists($addonkey)) { $updateAddons[$addonkey] = rex_addon::get($addonkey); $updateAddonsConfig[$addonkey] = $config; } } } //$config = rex_file::getConfig($temppath . 'core/default.config.yml'); //foreach ($config['system_addons'] as $addonkey) { // if (is_dir($temppath . 'addons/' . $addonkey) && rex_addon::exists($addonkey)) { // $updateAddons[$addonkey] = rex_addon::get($addonkey); // } //} $this->checkRequirements($temppath, $version['version'], $updateAddonsConfig); if (file_exists($temppath . 'core/update.php')) { include $temppath . 'core/update.php'; } foreach ($updateAddons as $addonkey => $addon) { if ($addon->isInstalled() && file_exists($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) { try { $addon->includeFile($file); if ($msg = $addon->getProperty('updatemsg', '')) { throw new rex_functional_exception($msg); } if (!$addon->getProperty('update', true)) { throw new rex_functional_exception(rex_i18n::msg('package_no_reason')); } } catch (rex_functional_exception $e) { throw new rex_functional_exception($addonkey . ': ' . $e->getMessage(), $e); } catch (rex_sql_exception $e) { throw new rex_functional_exception($addonkey . ': SQL error: ' . $e->getMessage(), $e); } } } // create backup $installConfig = rex_file::getCache($installAddon->getDataPath('config.json')); if (isset($installConfig['backups']) && $installConfig['backups']) { rex_dir::create($installAddon->getDataPath()); $archive = $installAddon->getDataPath(strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', rex::getVersion())) . '.zip'); rex_install_archive::copyDirToArchive(rex_path::core(), $archive); foreach ($updateAddons as $addonkey => $addon) { rex_install_archive::copyDirToArchive($addon->getPath(), $archive, 'addons/' . $addonkey); } } // copy plugins to new addon dirs foreach ($updateAddons as $addonkey => $addon) { foreach ($addon->getRegisteredPlugins() as $plugin) { $pluginPath = $temppath . 'addons/' . $addonkey . '/plugins/' . $plugin->getName(); if (!is_dir($pluginPath)) { rex_dir::copy($plugin->getPath(), $pluginPath); } elseif ($plugin->isInstalled() && is_dir($pluginPath . '/assets')) { rex_dir::copy($pluginPath . '/assets', $plugin->getAssetsPath()); } } } // move temp dirs to permanent destination rex_dir::delete(rex_path::core()); rename($temppath . 'core', rex_path::core()); if (is_dir(rex_path::core('assets'))) { rex_dir::copy(rex_path::core('assets'), rex_path::coreAssets()); } foreach ($coreAddons as $addonkey) { if (isset($updateAddons[$addonkey])) { rex_dir::delete(rex_path::addon($addonkey)); } rename($temppath . 'addons/' . $addonkey, rex_path::addon($addonkey)); if (is_dir(rex_path::addon($addonkey, 'assets'))) { rex_dir::copy(rex_path::addon($addonkey, 'assets'), rex_path::addonAssets($addonkey)); } } } catch (rex_functional_exception $e) { $message = $e->getMessage(); } catch (rex_sql_exception $e) { $message = 'SQL error: ' . $e->getMessage(); } rex_file::delete($archivefile); rex_dir::delete($temppath); if ($message) { $message = $installAddon->i18n('warning_core_not_updated') . '<br />' . $message; $success = false; } else { $message = $installAddon->i18n('info_core_updated'); $success = true; rex_delete_cache(); rex_install_webservice::deleteCache('core'); } $result = new rex_api_result($success, $message); if ($success) { $result->setRequiresReboot(true); } return $result; }
/** * @param int $parentId * @param string $listType * @param bool $ignoreOfflines * @param int $clang * * @return static[] */ protected static function getChildElements($parentId, $listType, $ignoreOfflines = false, $clang = null) { $parentId = (int) $parentId; // for $parentId=0 root elements will be returned, so abort here for $parentId<0 only if (0 > $parentId) { return []; } if (!$clang) { $clang = rex_clang::getCurrentId(); } $class = get_called_class(); return static::getInstanceList([$parentId, $listType], function ($id) use($class, $ignoreOfflines, $clang) { if ($instance = $class::get($id, $clang)) { return !$ignoreOfflines || $instance->isOnline() ? $instance : null; } return null; }, function ($parentId, $listType) { $listFile = rex_path::addonCache('structure', $parentId . '.' . $listType); if (!file_exists($listFile)) { rex_article_cache::generateLists($parentId); } return rex_file::getCache($listFile); }); }
private static function loadCache() { if (self::$cache === null) { foreach ((array) rex_file::getCache(rex_path::addonCache('install', 'webservice.cache')) as $path => $cache) { if ($cache['stamp'] > time() - self::REFRESH_CACHE) { self::$cache[$path] = $cache; } } } }
/** * Loads the cache if not already loaded. */ private static function checkCache() { if (self::$cacheLoaded) { return; } $file = rex_path::cache('clang.cache'); if (!file_exists($file)) { rex_clang_service::generateCache(); } foreach (rex_file::getCache($file) as $id => $clang) { self::$clangs[$id] = new self($id, $clang['code'], $clang['name'], $clang['priority']); } self::$cacheLoaded = true; }
rex::setProperty('timer', new rex_timer($_SERVER['REQUEST_TIME_FLOAT'])); // add backend flag to rex rex::setProperty('redaxo', $REX['REDAXO']); // 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
/** * load the config-data from a file-cache. * * @return bool Returns TRUE, if the data was successfully loaded from the file-cache, otherwise FALSE. */ private static function loadFromFile() { // delete cache-file, will be regenerated on next request if (file_exists(REX_CONFIG_FILE_CACHE)) { self::$data = rex_file::getCache(REX_CONFIG_FILE_CACHE); return true; } return false; }
/** * 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; }
public function sendMedia() { $headerCacheFilename = $this->getHeaderCacheFilename(); $CacheFilename = $this->getCacheFilename(); if ($this->isCached()) { $header = rex_file::getCache($headerCacheFilename); if (isset($header['Last-Modified'])) { rex_response::sendLastModified(strtotime($header['Last-Modified'])); } foreach ($header as $t => $c) { header($t . ': ' . $c); } readfile($CacheFilename); } else { $this->media->sendMedia($CacheFilename, $headerCacheFilename, $this->use_cache); } exit; }
/** * @return rex_media[] */ public function getMedia() { return self::getInstanceList([$this->getId(), 'media'], 'rex_media::get', function ($id) { $list_path = rex_path::addonCache('mediapool', $id . '.mlist'); if (!file_exists($list_path)) { rex_media_cache::generateList($id); } return rex_file::getCache($list_path); }); }
public function doAction() { $path = rex_path::addon($this->addonkey); $temppath = rex_path::addon('.new.' . $this->addonkey); if (($msg = $this->extractArchiveTo($temppath)) !== true) { return $msg; } // ---- check package.yml $packageFile = $temppath . rex_package::FILE_PACKAGE; if (!file_exists($packageFile)) { return rex_i18n::msg('package_missing_yml_file'); } try { $config = rex_file::getConfig($packageFile); } catch (rex_yaml_parse_exception $e) { return rex_i18n::msg('package_invalid_yml_file') . ' ' . $e->getMessage(); } if ($this->addon->isAvailable() && ($msg = $this->checkRequirements($config)) !== true) { return $msg; } // ---- include update.php if ($this->addon->isInstalled() && file_exists($temppath . rex_package::FILE_UPDATE)) { try { $this->addon->includeFile('../.new.' . $this->addonkey . '/' . rex_package::FILE_UPDATE); } catch (rex_functional_exception $e) { return $e->getMessage(); } catch (rex_sql_exception $e) { return 'SQL error: ' . $e->getMessage(); } if (($msg = $this->addon->getProperty('updatemsg', '')) != '') { return $msg; } if (!$this->addon->getProperty('update', true)) { return rex_i18n::msg('package_no_reason'); } } // ---- backup $assets = $this->addon->getAssetsPath(); $installConfig = rex_file::getCache(rex_addon::get('install')->getDataPath('config.json')); if (isset($installConfig['backups']) && $installConfig['backups']) { $archivePath = rex_path::addonData('install', $this->addonkey . '/'); rex_dir::create($archivePath); $archive = $archivePath . strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', $this->addon->getVersion('0'))) . '.zip'; rex_install_archive::copyDirToArchive($path, $archive); if (is_dir($assets)) { rex_install_archive::copyDirToArchive($assets, $archive, 'assets'); } } // ---- copy plugins to new addon dir foreach ($this->addon->getRegisteredPlugins() as $plugin) { $pluginPath = $temppath . '/plugins/' . $plugin->getName(); if (!is_dir($pluginPath)) { rex_dir::copy($plugin->getPath(), $pluginPath); } elseif ($plugin->isInstalled() && is_dir($pluginPath . '/assets')) { rex_dir::copy($pluginPath . '/assets', $plugin->getAssetsPath()); } } // ---- update main addon dir rex_dir::delete($path); rename($temppath, $path); // ---- update assets $origAssets = $this->addon->getPath('assets'); if ($this->addon->isInstalled() && is_dir($origAssets)) { rex_dir::copy($origAssets, $assets); } // ---- update package order if ($this->addon->isAvailable()) { $this->addon->loadProperties(); foreach ($this->addon->getAvailablePlugins() as $plugin) { $plugin->loadProperties(); } rex_package_manager::generatePackageOrder(); } $this->addon->setProperty('version', $this->file['version']); rex_install_packages::updatedPackage($this->addonkey, $this->fileId); }
<?php /** @var rex_addon $this */ $panel = ''; $configFile = $this->getDataPath('config.json'); $config = array_merge(['backups' => false, 'api_login' => null, 'api_key' => null], rex_file::getCache($configFile)); $newConfig = rex_post('settings', [['backups', 'bool', false], ['api_login', 'string'], ['api_key', 'string']], null); if (is_array($newConfig)) { $config = $newConfig; rex_file::putCache($configFile, $config); echo rex_view::success($this->i18n('settings_saved')); rex_install_webservice::deleteCache(); } $panel .= ' <fieldset> <legend>' . $this->i18n('settings_general') . '</legend>'; $formElements = []; $n = []; $n['reverse'] = true; $n['label'] = '<label>' . $this->i18n('settings_backups') . '</label>'; $n['field'] = '<input type="checkbox" name="settings[backups]" value="1" ' . ($config['backups'] ? 'checked="checked" ' : '') . '/>'; $formElements[] = $n; $fragment = new rex_fragment(); $fragment->setVar('elements', $formElements, false); $panel .= $fragment->parse('core/form/checkbox.php'); $panel .= ' </fieldset> <fieldset> <legend>' . $this->i18n('settings_myredaxo_account') . '</legend>'; $formElements = []; $n = [];
public static function readPathFile() { if (!file_exists(self::$pathfile)) { self::generatePathFile([]); } self::$paths = rex_file::getCache(self::$pathfile); }
/** * Loads the cache if not already loaded. */ private static function checkCache() { if (self::$cacheLoaded) { return; } $file = rex_path::coreCache('clang.cache'); if (!file_exists($file)) { rex_clang_service::generateCache(); } foreach (rex_file::getCache($file) as $id => $data) { $clang = new self(); foreach ($data as $key => $value) { $clang->{$key} = $value; } self::$clangs[$id] = $clang; } self::$cacheLoaded = true; }