private function _checkPermissions($themeName) { $themeDir = FilesHelper::normalizePath(getThemeDir($themeName)); $previewDir = $themeDir . _PREVIEW_SUFFIX_; $dirs = array(_PS_OVERRIDE_DIR_, _PS_DOWNLOAD_DIR_, _PS_MODULE_DIR_, _PS_UPLOAD_DIR_, $themeDir, $previewDir); foreach ($dirs as $dir) { $rootOnly = strpos($dir, '/themes/') === FALSE; // check themes subdirectories only $check = FilesHelper::checkFiles($dir, true, true, $rootOnly); } return true; }
/** * @param $path * @param $recursive */ public static function checkFiles($path, $recursive = true, $check = false, $rootOnly = false, $names_only = false) { $files = array(); if (!is_dir($path)) { return $files; } if ($check && (is_dir($path) && !self::_checkDirPermissions($path) || !self::_checkFilePermissions($path))) { throw new PermissionsException('Please check permissions for: ' . $path); } if ($rootOnly) { return $files; } if ($handle = opendir($path)) { while (($name = readdir($handle)) !== false) { if (preg_match('#^\\.#', $name)) { continue; } if (is_dir($path . "/" . $name) && $recursive) { if ($check && !self::_checkDirPermissions($path)) { throw new PermissionsException('Please check permissions for: ' . $path); } $files = array_merge($files, FilesHelper::checkFiles($path . "/" . $name, $recursive, $check, $rootOnly, $names_only)); } else { if ($check && !self::_checkFilePermissions($path)) { throw new PermissionsException('Please check permissions for: ' . $path); } if ($names_only) { $files[] = $name; } else { $files[] = array('path' => $path . '/' . $name, 'name' => $name); } } } closedir($handle); } return $files; }
function rebuildTranslations($themeDir, $translations) { // CHECK: don't remove translation for files that doesn't store in theme - liveedit.tpl $files = FilesHelper::checkFiles($themeDir, true, false, false, true); foreach ($translations as $lang => $translation) { $out = <<<EOT <?php global \$_LANG; \$_LANG = array(); EOT; if (!empty($translation)) { foreach ($translation as $key => $value) { if (preg_match("/([^']+?)([^_]+\$)/", $key, $matches)) { $fileName = rtrim($matches[1], '_') . '.tpl'; // CHECK: don't remove translation for files that doesn't store in theme - liveedit.tpl if (in_array($fileName, $files)) { // file exists $quoteReplaced = preg_replace("/'/", "\\'", $value); $out .= <<<EOT \$_LANG['{$key}'] = '{$quoteReplaced}'; EOT; } } } } $out .= <<<EOT return \$_LANG; EOT; FilesHelper::writeFile($themeDir . '/lang/' . $lang . '.php', $out); } }