/** * Modify class source * * @param \Includes\Decorator\DataStructure\Graph\Classes $node Current node * * @return void */ protected function writeCallToSourceFile(\Includes\Decorator\DataStructure\Graph\Classes $node) { $path = \Includes\Decorator\ADecorator::getCacheClassesDir() . $node->getPath(); $content = \Includes\Utils\FileManager::read($path); $content .= PHP_EOL . '// Call static constructor' . PHP_EOL; $content .= '\\' . $node->getClass() . '::' . static::STATIC_CONSTRUCTOR_METHOD . '();'; \Includes\Utils\FileManager::write($path, $content); }
public static function getCounter() { $data = \Includes\Utils\FileManager::read(static::getFilePath()); if ($data) { $data = substr($data, strlen('; <' . '?php /*' . PHP_EOL), strlen('; */ ?' . '>') * -1); $data = unserialize($data); } return $data && is_array($data) && isset($data['count']) ? intval($data['count']) : 0; }
/** * Return classes tree * * @param boolean $create Flag OPTIONAL * * @return \Includes\Decorator\DataStructure\Graph\Classes */ public static function getClassesTree($create = true) { if (!isset(static::$classesTree) && $create) { if (\Includes\Utils\FileManager::isFileReadable(static::getClassesHashPath())) { $data = unserialize(\Includes\Utils\FileManager::read(static::getClassesHashPath())); static::$classesTree = array_pop($data); } else { static::$classesTree = \Includes\Decorator\Utils\Operator::createClassesTree(); } } return static::$classesTree; }
/** * Get schema * * @return array */ public static function getDBSchema() { if (!isset(static::$schema)) { $path = static::getDBSchemaFilePath(); if (\Includes\Utils\FileManager::isFileReadable($path)) { $content = \Includes\Utils\FileManager::read($path); if ($content) { static::$schema = explode(';', $content); } } } return static::$schema; }
/** * Return templates list * * @return array */ protected function getAnnotatedTemplates() { if (!isset(static::$annotatedTemplates)) { static::$annotatedTemplates = array(); static::$inheritedTemplates = array(); foreach ($this->getTemplateFileIterator()->getIterator() as $path => $data) { $data = \Includes\Decorator\Utils\Operator::getTags(\Includes\Utils\FileManager::read($path, true), array(static::TAG_LIST_CHILD, static::TAG_INHERITED_LIST_CHILD)); if (isset($data[static::TAG_LIST_CHILD])) { $this->addTags($data[static::TAG_LIST_CHILD], $path); } if (isset($data[static::TAG_INHERITED_LIST_CHILD])) { static::$inheritedTemplates[] = $path; } } } return static::$annotatedTemplates; }
/** * Return templates chain * * @return array */ protected function getChain() { $result = array(); /** @var \XLite\Core\Layout $layout */ $layout = \XLite\Core\Layout::getInstance(); $shortPath = $this->getValue(); $files = array(); foreach ($layout->getSkinPaths(\XLite::CUSTOMER_INTERFACE) as $path) { $fullPath = $path['fs'] . LC_DS . $shortPath; if (file_exists($fullPath) && is_file($fullPath)) { array_unshift($files, $fullPath); } } foreach ($files as $fullPath) { $result[substr($fullPath, strlen(LC_DIR_SKINS))] = htmlspecialchars(\Includes\Utils\FileManager::read($fullPath)); } return $result; }
/** * Uninstall module * * @return void */ protected function doActionUninstall() { $module = $this->getModule(); if ($module) { $pack = new \XLite\Core\Pack\Module($module); $dirs = $pack->getDirs(); $nonWritableDirs = array(); // Check permissions foreach ($dirs as $dir) { if (!\Includes\Utils\FileManager::isDirWriteable($dir)) { $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT); } } $params = array('name' => $module->getActualName()); if (empty($nonWritableDirs)) { $yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName())); // Remove from FS foreach ($dirs as $dir) { \Includes\Utils\FileManager::unlinkRecursive($dir); } // Disable this and depended modules \Includes\Utils\ModulesManager::disableModule($module->getActualName()); \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName()); // Remove from DB \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module); if ($module->getModuleID()) { $message = 'A DB error occured while uninstalling the module "{{name}}"'; $this->showError(__FUNCTION__, $message, $params); } else { if (!empty($yaml)) { \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml); } $message = 'The module "{{name}}" has been uninstalled successfully'; $this->showInfo(__FUNCTION__, $message, $params); } // To restore previous state \XLite\Core\Marketplace::getInstance()->saveAddonsList(0); // Flag to rebuild cache \XLite::setCleanUpCacheFlag(true); } else { $message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}'; $this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs))); } } }
/** * Prepares JS cache to use * * @param array $resource Array with JS file data * * @return string */ protected function prepareJSCache($resource) { $filePath = $resource['file']; $minFilePath = str_replace(LC_DIR_SKINS, static::getMinifiedCacheDir(static::RESOURCE_JS), $filePath); $minFilePath = dirname($minFilePath) . LC_DS . basename($minFilePath, '.js') . '.min.js'; $minified = false; // Get file content if (\Includes\Utils\FileManager::isFileReadable($minFilePath)) { $data = \Includes\Utils\FileManager::read($minFilePath); $minified = true; } else { $data = \Includes\Utils\FileManager::read($filePath); } $noMinify = !empty($resource['no_minify']) || !empty($resource['no-minify']); if (!$minified && !$noMinify && strpos(basename($filePath), '.min.js') == false) { // Minify js content $data = $this->minifyJS($data, $filePath); \Includes\Utils\FileManager::write($minFilePath, $data); } $data = trim($data); $data = preg_replace('/\\)$/S', ');', $data); return $data ? PHP_EOL . '/* AUTOGENERATED: ' . basename($filePath) . ' */' . PHP_EOL . $data . ';' : ''; }
/** * Send email notification to administrator about access key * * @param boolean $keyChanged is access key was changed * * @return void */ public static function sendNotification($keyChanged = false) { if (!\Includes\Decorator\Utils\CacheManager::isRebuildNeeded(\Includes\Decorator\Utils\CacheManager::STEP_THIRD)) { // Send email notification \XLite\Core\Mailer::sendSafeModeAccessKeyNotification(\Includes\Utils\FileManager::read(static::getAccessKeyFileName()), $keyChanged); } }
/** * Set new file for compile * * @param string $file Template to compile * * @return void */ protected function init($file) { $this->file = $file; $this->source = \Includes\Utils\FileManager::read($file); $this->urlRewrite = array('images' => array($this, 'rewriteImageURL')); }
/** * Download pack * * @param \XLite\Core\Pack\APack $pack Files to pack * @param boolean $compress Flag OPTIONAL * * @return void */ protected static function download(\XLite\Core\Pack\APack $pack, $compress = true) { if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) { \Includes\Utils\FileManager::mkdir(LC_DIR_TMP); } if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) { \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable'); } $path = LC_DIR_TMP . $pack->getName() . '.tar'; $phar = static::pack($path, $pack->getDirectoryIterator(), $pack->getMetadata(), $compress); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Length: ' . filesize($path)); echo \Includes\Utils\FileManager::read($path); \Includes\Utils\FileManager::deleteFile($path); exit(0); }
/** * Get file content * * @return string */ public function getFileContent() { return \Includes\Utils\FileManager::read($this->getFileName()); }
/** * Get LESSResourceHash * * @param array $lessFiles LESS files structures array * @param boolean $original Get original path OPTIONAL * * @return array */ protected function getLESSResourceHash($lessFiles, $original = false) { if (!isset($this->LESSResourceHash)) { $data = \Includes\Utils\FileManager::read(static::getHashFilePath()); if ($data) { $data = substr($data, strlen('; <' . '?php /*' . PHP_EOL), strlen('; */ ?' . '>') * -1); $data = unserialize($data); } $this->LESSResourceHash = $data && is_array($data) ? $data : array(); } $path = $this->getCSSResource($lessFiles, $original, true); return isset($this->LESSResourceHash[$path]) && is_array($this->LESSResourceHash[$path]) ? $this->LESSResourceHash[$path] : array(); }
/** * Retrieve property from the model object * * @param mixed $name Field/property name * * @return mixed */ protected function getModelObjectValue($name) { switch ($name) { case 'body': $value = ''; $localPath = ''; if (\XLite\Core\Request::getInstance()->template) { $localPath = \XLite\Core\Request::getInstance()->template; } elseif ($this->getModelObject()->getId()) { $localPath = $this->getModelObjectValue('template'); } if ($localPath) { $model = $this->getModelObject(); $fullPath = $this->getFullPathByLocalPath($localPath, $model->getId() ? 'theme_tweaker/default' : null); $value = \Includes\Utils\FileManager::read($fullPath); } break; default: $value = parent::getModelObjectValue($name); break; } return $value; }
/** * Get body * * @return string */ public function getBody() { if ($this->isURL()) { $body = \XLite\Core\Operator::getURLContent($this->getPath()); } else { $body = \Includes\Utils\FileManager::read($this->getStoragePath()); } return $body; }
/** * Read file from package * * @param string $relativePath File relative path in package * * @return string */ protected function getFileSource($relativePath) { $source = null; $path = \Includes\Utils\FileManager::getCanonicalDir($this->getRepositoryPath()); if (!empty($path)) { $path = \Includes\Utils\FileManager::getRealPath($this->getFullPath($relativePath, $path)); } if (!empty($path)) { $source = \Includes\Utils\FileManager::read($path); } return $source; }
/** * Return source code for regular node * * @return string */ protected function getRegularSource() { return \Includes\Utils\FileManager::read($this->getFile()); }
*/ // To avoid superflous checks define('XLITE_INSTALL_MODE', true); define('LC_DO_NOT_REBUILD_CACHE', true); require_once __DIR__ . DIRECTORY_SEPARATOR . 'top.inc.php'; if (isset($_REQUEST['target'])) { $path = null; switch ($_REQUEST['target']) { case 'module': if (!empty($_REQUEST['author']) && !empty($_REQUEST['name'])) { $image = isset($_REQUEST['image']) ? $_REQUEST['image'] : null; switch ($image) { case 'icon.png': default: $path = \Includes\Utils\ModulesManager::getModuleIconFile($_REQUEST['author'], $_REQUEST['name']); break; } } break; default: // ... } if (!empty($path)) { $type = 'png'; $data = \Includes\Utils\FileManager::read($path); $length = strlen($data); header('Content-Type: image/' . $type); header('Content-Length: ' . $length); echo $data; } }
/** * Get HASH of ENABLED registry structure * * @return string */ public static function getEnabledStructureHash() { return \Includes\Utils\FileManager::read(static::getEnabledStructureHashPath()); }
/** * Uninstall module * * @param \XLite\Model\Module $module Module object * @param array &$messages Messages list * * @return boolean */ public function uninstallModule(\XLite\Model\Module $module, &$messages) { $result = false; // Get module pack $pack = new \XLite\Core\Pack\Module($module); $dirs = $pack->getDirs(); $nonWritableDirs = array(); // Check module directories permissions foreach ($dirs as $dir) { if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) { $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT); } } $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName())); if (empty($nonWritableDirs)) { $yamlData = array(); $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName()); foreach ($yamlFiles as $yamlFile) { $yamlData[] = \Includes\Utils\FileManager::read($yamlFile); } if (!$module->checkModuleMainClass()) { $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass()); if (\Includes\Utils\FileManager::isFileReadable($classFile)) { require_once $classFile; } } // Call uninstall event method $r = $module->callModuleMethod('callUninstallEvent', 111); if (111 == $r) { \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called'); } // Remove from FS foreach ($dirs as $dir) { \Includes\Utils\FileManager::unlinkRecursive($dir); } \Includes\Utils\ModulesManager::disableModule($module->getActualName()); \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName()); // Remove module from DB try { // Refresh module entity as it was changed by disableModule() method above $module = $this->find($module->getModuleID()); $this->delete($module); } catch (\Exception $e) { $messages[] = $e->getMessage(); } if ($module->getModuleID()) { $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params); } else { if (!empty($yamlData)) { foreach ($yamlData as $yaml) { \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml); } } $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params); $result = true; } } else { $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs))); } return $result; }
/** * Return content of the error page file (.html) * * @return string */ protected static function getErrorPageFileContent($type = self::ERROR_PAGE_TYPE_ERROR) { return \Includes\Utils\FileManager::read(static::getErrorPageFile($type)) ?: LC_ERROR_PAGE_MESSAGE; }
/** * Prepares CSS cache to use * * @param string $filePath JS cache file path * * @return string */ protected function prepareJSCache($filePath) { return "\r\n" . '/***** AUTOGENERATED: ' . basename($filePath) . ' */' . "\r\n" . \Includes\Utils\FileManager::read($filePath); }
/** * Check and (if needed) remove the rebuild indicator file * * @return boolean */ public static function checkRebuildIndicatorState() { $name = static::getRebuildIndicatorFileName(); $content = \Includes\Utils\FileManager::read($name); // Only the process created the file can delete // :NOTE: do not change the operator to the "===" if (static::getRebuildIndicatorFileContent() == $content) { \Includes\Utils\FileManager::deleteFile($name); } return (bool) $content; }
/** * Show log file content * * @return void */ protected function doActionViewLogFile() { $path = \XLite\Upgrade\Logger::getInstance()->getLastLogFile(); if ($path) { header('Content-Type: text/plain', true); \Includes\Utils\Operator::flush(\Includes\Utils\FileManager::read($path)); exit(0); } else { \XLite\Core\TopMessage::addWarning('Log files not found'); } }
/** * Return content of the error page file (.html) * * @return string */ protected static function getErrorPageFileContent() { return \Includes\Utils\FileManager::read(static::getErrorPageFile()) ?: LC_ERROR_PAGE_MESSAGE; }