/** * Return wrong permissions * * @return array */ protected function getWrongPermissions() { if (!isset($this->wrongPermissions)) { $wrongEntries = array('files' => array(), 'dirs' => array()); $common = $this->getCommonFolders(); foreach ($this->getUpgradeEntries() as $entry) { foreach ($entry->getWrongPermissions() as $path) { foreach ($common as $folder => $processed) { if (false !== strpos($path, $folder)) { if (\Includes\Utils\FileManager::isDir($path) && !$processed['dirs']) { $this->wrongPermissions[] = 'find ' . $folder . ' -type d -execdir chmod 777 "{}" \\;;'; $common[$folder]['dirs'] = true; } elseif (\Includes\Utils\FileManager::isFile($path) && !$processed['files']) { $this->wrongPermissions[] = 'find ' . $folder . ' -type f -execdir chmod 666 "{}" \\;;'; $common[$folder]['files'] = true; } continue 2; } } if (\Includes\Utils\FileManager::isDir($path)) { $wrongEntries['dirs'][] = $path; } else { $wrongEntries['files'][] = $path; } } } foreach ($wrongEntries as $type => $paths) { if ($paths) { $permission = $type == 'dirs' ? '777' : '666'; $this->wrongPermissions[] = 'chmod ' . $permission . ' ' . implode(' ', array_unique($paths)) . ';'; } } } return $this->wrongPermissions; }
/** * Get Access Key * * @return string */ public static function getAccessKey() { if (!\Includes\Utils\FileManager::isFile(static::getAccessKeyFileName())) { static::regenerateAccessKey(); } return \Includes\Utils\FileManager::read(static::getAccessKeyFileName()); }
/** * Return resource structure from the file cache * * @param string $type File type of resource (js/css) * @param array $resources Resources for caching * @param array $paramsForCache Parameters of file cache (directory structure path to file) * @param string $prepareCacheFileMethod Method of $this object to read one resource entity and do some inner work if it is necessary * * @return array */ protected function getResourceFromCache($type, array $resources, array $paramsForCache, $prepareCacheFileMethod) { $pathToCacheDir = static::getResourceCacheDir($paramsForCache); \Includes\Utils\FileManager::mkdirRecursive($pathToCacheDir); $file = hash('sha256', serialize($resources)) . '.' . $type; $filePath = $pathToCacheDir . $file; if (!\Includes\Utils\FileManager::isFile($filePath)) { foreach ($resources as $resource) { \Includes\Utils\FileManager::write($filePath, $this->{$prepareCacheFileMethod}($resource['file']), FILE_APPEND); } } return array('file' => $filePath, 'url' => \XLite::getInstance()->getShopURL(str_replace(LC_DS, '/', substr($filePath, strlen(LC_DIR_ROOT))), \XLite\Core\Request::getInstance()->isHTTPS())); }
/** * Get file with an upgrade note * * @param string $type Note type * @param string $majorVersion Major version to upgrade to * @param string $minorVersion Minor version to upgrade to * @param string $languageCode Language code OPTIONAL * * @return string */ protected function getUpgradeNoteFile($type, $majorVersion, $minorVersion, $languageCode = null) { $file = null; $path = $this->getUpgradeHelpersDir(); if ($path) { $language = isset($languageCode) ? '.' . $languageCode : ''; $file = $majorVersion . LC_DS . $minorVersion . LC_DS . $type . $language . '.txt'; if (\Includes\Utils\FileManager::isFile($path . $file)) { $file = $this->getUpgradeHelpersDir(false) . $file; } else { $file = null; } } return $file; }
/** * Clean up the cache validity indicators * * @return void */ public static function cleanupCacheIndicators() { foreach (static::getCacheStateFiles() as $file) { if (\Includes\Utils\FileManager::isFile($file) && !\Includes\Utils\FileManager::deleteFile($file)) { \Includes\ErrorHandler::fireError('Unable to delete "' . $file . '" file. Please correct the permissions'); } } // "Step is running" indicator static::cleanupRebuildIndicator(); }
/** * Check - resized icon is available or not * * @param string $path Resized image path * * @return boolean */ protected function isResizedIconAvailable($path) { return \Includes\Utils\FileManager::isFile($path) && $this->getDate() <= filemtime($path); }
/** * Get file with an upgrade helper function * * @param string $type Helper type * @param string $majorVersion Major version to upgrade to * @param string $minorVersion Minor version to upgrade to * * @return string */ protected function getUpgradeHelperFile($type, $majorVersion, $minorVersion) { $file = null; if ($path = $this->getUpgradeHelpersDir()) { $file = $majorVersion . LC_DS . $minorVersion . LC_DS . $type . '.php'; if (\Includes\Utils\FileManager::isFile($path . $file)) { $file = $this->getUpgradeHelpersDir(false) . $file; } else { $file = null; } } return $file; }
/** * Load service YAML * * @param string $path File path * * @return mixed */ public static function loadServiceYAML($path) { $data = null; if (\Includes\Utils\FileManager::isFile($path)) { $data = \Symfony\Component\Yaml\Yaml::parse($path); } return $data; }
/** * Check if LC is installed * * @return void */ public static function checkIsLCInstalled() { if (!\Includes\Utils\ConfigParser::getOptions(array('database_details', 'database'))) { $message = 'Probably LC is not installed. Try to run '; $url = '<strong>install.php</strong>'; $link = \Includes\Utils\URLManager::getShopURL('install.php'); if (\Includes\Utils\FileManager::isFile($link)) { $url = '<a href="' . $link . '">' . $url . '</a>'; } static::showErrorPage('ERROR_LC_NOT_INSTALLED', $message . $url, LC_ERROR_PAGE_MESSAGE); } }