public function listPackages() { $path = app_path() . '/Cms/Packages/Source/'; $files = \FilesHelper::filesInFolder($path); $packages = array_pluck($files, 'name'); return $packages; }
public function destroy($package) { \PackagesHelper::uninstallPackage($package); $path = app_path() . '/Cms/Packages/Source/' . $package; \FilesHelper::deleteDirectory($path); return \Redirect::route('dev.packages.index'); }
public function renderForms($themeName) { $themeDir = FilesHelper::normalizePath(getThemeDir($themeName)); $form = array(); $this->_renderTemplatesForm($form, $themeDir, $themeName); $this->_renderSlidersForms($form, $themeDir, $themeName); return $form; }
public function deleteView($view) { try { $view_path = public_path() . '/site/' . $view->name; \FilesHelper::deleteFile($view_path); } catch (\Exception $e) { } }
public function destroy($index) { $path = public_path() . '/uploads/files/'; $files = \FilesHelper::filesInFolder($path); $file = $files[$index]; $file_path = $path . $file['name']; \FilesHelper::deleteFile($file_path); return \Redirect::route('dev.files.index'); }
public function getThemeTemplates($themeName) { $path = FilesHelper::normalizePath(getThemeDir($themeName . _PREVIEW_SUFFIX_)) . '/templates/templates.php'; if (file_exists($path)) { // TODO: Maybe we have to store all html and parse them after each update or export operation for backward require_once $path; } else { $templates = getTemplates(); // backward with old themes which do not have templates.php file but plugin is already updated } $context = Context::getContext(); $link = $context->link; $controllers = getTemplateControllers(); $previewParam = 'theme_name=' . $themeName; $result = array(); foreach ($templates as $type => $template) { $controller = $controllers[$type]; $method = 'get' . $controller . 'Link'; if (method_exists($link, $method)) { $lower = strtolower($controller); $item = Designer::getFirstItem($lower); if ($item > 0) { $baseUrl = $link->{$method}($item); $pos = strpos($baseUrl, '?'); if ($pos !== FALSE) { // HACK: preview parameter must be first in URL in Debug mode $mainPart = substr($baseUrl, 0, $pos); $params = substr($baseUrl, $pos + 1); $templateUrl = $mainPart . '?' . $previewParam . '&' . $params; } else { $templateUrl = $baseUrl . '?' . $previewParam; } } else { $templateUrl = $link->getPageLink('index') . '?' . $previewParam . '&missingContent=' . $lower; } } else { $templateUrl = $link->getPageLink($controller); if (strpos($templateUrl, $previewParam) === FALSE) { // can be set in some case from Dispatcher.php $templateUrl .= (strpos($templateUrl, '?') !== FALSE ? '&' : '?') . $previewParam; } } if (is_array($template)) { // updated theme with templates.php file foreach ($template as $t) { $result[$t['name']] = $templateUrl . '&template=' . $type . '_' . $t['id']; // format as {templateName_id.tpl} } } else { // backward with old themes which do not have templates.php file but plugin is already updated $result[$type] = $templateUrl; } } return $result; }
public function replace($matches) { $path = $this->themeDir . '/' . $matches[3] . $matches[4]; if (file_exists($path)) { $content = FilesHelper::readFile($path); $pattern = '~(\\{assign var=hookName value=[\'"])(.*?)([\'"])([^\\}]*)(\\})~'; $result = preg_replace_callback($pattern, array($this, 'hookReplace'), $content); return $result; } return ''; }
public function install($theme_zip_file, $sandbox, $redirect = false) { if ($this->extractTheme($theme_zip_file, $sandbox)) { if ($theme_directory = $this->installTheme(self::UPLOADED_THEME_DIR_NAME, $sandbox, $redirect)) { FilesHelper::removeDir($sandbox); // To catch permission exceptions //Tools::deleteDirectory($sandbox); return true; } } return false; }
public function complete() { ProviderLog::start('Chunk complete'); $content = ''; for ($i = 1, $count = (int) $this->_lastChunk['total']; $i <= $count; $i++) { if (!file_exists($this->_chunkFolder . "/{$i}")) { trigger_error('Missing chunk #' . $i . ' : ' . implode(' / ', scandir($this->_chunkFolder)), E_USER_NOTICE); } $data = FilesHelper::readFile($this->_chunkFolder . "/{$i}"); if (!empty($this->_lastChunk['encode'])) { $data = base64_decode($data); } $content .= $data; } FilesHelper::removeDir($this->_chunkFolder); $content = empty($this->_lastChunk['encode']) ? $content : rawurldecode($content); ProviderLog::end('Chunk complete'); return $content; }
/** * Build theme layout files header.tpl, footer.tpl */ private function _buildTemplate($info, $content) { $dir = $info['dirname']; $name = $info['filename']; $content_before = $content; $content_after = ''; $id = 'center_column'; $searchable_content = '<div id="' . $id . '">{$HOOK_HOME}</div>'; $position = strpos($content, $searchable_content); if ($position !== FALSE) { $content_before = substr($content, 0, $position) . '<div id="' . $id . '">'; $content_after = '</div>' . substr($content, $position + strlen($searchable_content)); } $header_tpl_path = $dir . '/header_' . $name . '.tpl'; $footer_tpl_path = $dir . '/footer_' . $name . '.tpl'; FilesHelper::writeFile($header_tpl_path, $content_before); FilesHelper::writeFile($footer_tpl_path, $content_after); return array($header_tpl_path, $footer_tpl_path); }
private function _getKey($path) { $file = FilesHelper::normalizePath($path); if (substr($file, 0, strlen($this->_themeDir . '_preview')) == $this->_themeDir . '_preview') { $file = substr($file, strlen($this->_themeDir . '_preview')); } if (substr($file, 0, strlen($this->_themeDir)) == $this->_themeDir) { $file = substr($file, strlen($this->_themeDir)); } return $file; }
public function codeModelForEntity($entity) { $path = app_path() . '/models/Site/' . $entity->model_name . '.php'; $content = '<?php ' . \View::make('coder.models.entity', compact('entity')); \FilesHelper::overwriteFile($path, $content); }
public function codeRoutesForRoutesAndEntities($routes, $entities) { $content = \View::make('coder.routes.appjs', compact('routes', 'entities')); $path = public_path() . '/js/app.js'; \FilesHelper::overwriteFile($path, $content); }
public function chunkClear() { $chunk = new Chunk(); FilesHelper::removeDir($chunk->UPLOAD_PATH); }
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; }
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); } }
function save_config($src_dir, $dest_dir, $user_theme_name) { $config = '/designer/Export/Config.xml'; $content = preg_replace('/name="([^"]*?)" directory="([^"]*?)"/', 'name="' . $user_theme_name . '" directory="' . $user_theme_name . '"', FilesHelper::readFile($src_dir . $config)); FilesHelper::writeFile($dest_dir . $config, $content); }
function copyOrRename($src, $dest, $rename) { if (file_exists($src)) { if ($rename) { FilesHelper::renameFile($src, $dest); } else { FilesHelper::copyRecursive($src, $dest); } } }
public static function emptyDirRecursive($dir, $recursive = true) { foreach (FilesHelper::enumerateFiles($dir, $recursive) as $file) { FilesHelper::deleteFile($file['path']); } }
private function deleteFile($path) { \FilesHelper::deleteFile($path); }