public function build() { foreach (\Nette\Utils\Finder::findFiles('*.latte')->from($this->settings->template) as $template) { $destination = $this->settings->netteRoot . str_replace($this->settings->template, '', mb_substr($template, 0, -6)); if (mb_strpos($destination, '\\Module') !== FALSE) { $destination = str_replace('\\Module', $this->settings->module ? '\\' . $this->settings->module . 'Module' : '\\', $destination); } if (mb_strpos($destination, '\\NDBT') !== FALSE && $this->settings->target !== \Utils\Constants::TARGET_NETTE_DATABASE || mb_strpos($destination, '\\D2') !== FALSE && $this->settings->target !== \Utils\Constants::TARGET_DOCTRINE2) { continue; } else { $destination = str_replace(['\\NDBT', '\\D2'], '\\', $destination); } if (mb_strpos($destination, '\\Table') !== FALSE) { foreach ($this->settings->tables as $table) { $this->parameters['table'] = $table; $newDestination = str_replace('\\Table', "\\{$table->sanitizedName}", $destination); if (mb_strpos(basename($destination), '.') !== FALSE) { $this->saveTemplate($newDestination, $this->processTemplate($template, $this->parameters)); } else { $this->processTemplate($newDestination, $this->parameters); } } } else { if (mb_strpos(basename($destination), '.') !== FALSE) { $this->saveTemplate($destination, $this->processTemplate($template, $this->parameters)); } else { $this->processTemplate($template, $this->parameters); } } } foreach (\Nette\Utils\Finder::findFiles('*.*')->exclude('*.latte')->from($this->settings->template) as $template) { $destination = $this->settings->netteRoot . str_replace($this->settings->template, '', $template); \Nette\Utils\FileSystem::copy($template, $destination); } }
function init() { parent::init(); if (!$this->app->auth->isLoggedIn()) { return; } if (!$_GET['xepan-tool-to-clone']) { return $this->add('View')->set('Please select a tool'); } $tool = $this->add($_GET['xepan-tool-to-clone']); if (!$tool->teplateOverridable) { $this->add('View')->set('You cannot override template for this tool'); return; } $original_path = $tool->template->origin_filename; $tool->destroy(); $specific_path = substr($original_path, strpos($original_path, '/templates/') + strlen('/templates/')); $override_path = $this->app->pathfinder->base_location->base_path . '/websites/' . $this->app->current_website_name . '/www/' . $specific_path; if (file_exists($override_path)) { $this->add('View')->set('File allrealy overrided at "' . $specific_path . '", Please remove this file and click again to reset'); return; } $fs = \Nette\Utils\FileSystem::copy($original_path, $override_path, true); $this->add('View')->set('Tool template is overrided at "' . $specific_path . '", PLease use file manager in admin to edit file'); }
/** * @param string $source * @param string $destination * @return string */ public function save($source, $destination) { $path = Utils::normalizePath($this->basePath . '/' . $this->relativePath . '/' . $destination); Utils::makeDirectoryRecursive(dirname($path)); FileSystem::copy($source, $path); return $path; }
/** * @return Magic provides fluent interface */ public function cast() { Nette\Utils\FileSystem::createDir($this->fullPath); if (!file_exists($this->fullPath . '/copied')) { Nette\Utils\FileSystem::copy(__DIR__ . '/resources', $this->fullPath); } $this->useMagic = TRUE; return $this; }
/** * @param array $parameters * @throws DuplicationException */ public function generate(array $parameters) { $mandatoryParameters = ['Name' => 'name']; $this->checkParameters($parameters, $mandatoryParameters); $finalDir = $this->config['componentsDir'] . '/' . $parameters['name']; if (is_dir($finalDir)) { throw new DuplicationException(sprintf('Component `%s` already exists.', $finalDir)); } Nette\Utils\FileSystem::copy($this->config['templateDir'], $finalDir); $this->generateFiles($finalDir, $parameters); }
/** * @param \Venne\Packages\IPackage $package */ public function install(IPackage $package) { try { $name = $package->getName(); $configuration = $package->getConfiguration(); // create resources dir if ($package->getRelativePublicPath()) { $resourcesDir = $this->resourcesDir; $packageDir = $resourcesDir . '/' . $name; $targetDir = realpath($package->getPath() . $package->getRelativePublicPath()); if (!is_dir($packageDir) && is_dir($targetDir)) { umask(00); @mkdir(dirname($packageDir), 0777, true); if (!@symlink(Helpers::getRelativePath(dirname($packageDir), $targetDir), $packageDir) && !is_dir($packageDir)) { FileSystem::copy($targetDir, $packageDir); } $this->actions[] = function () use($resourcesDir) { if (is_link($resourcesDir)) { unlink($resourcesDir); } else { FileSystem::delete($resourcesDir); } }; } } // update main config.neon if (count($configuration) > 0) { $orig = $data = $this->loadConfig(); $data = array_merge_recursive($data, $configuration); $this->saveConfig($data); $this->actions[] = function ($self) use($orig) { $self->saveConfig($orig); }; } } catch (\Exception $e) { $actions = array_reverse($this->actions); try { foreach ($actions as $action) { $action($this); } } catch (\Exception $ex) { echo $ex->getMessage(); } throw $e; } }
public function save($sourceFile, $originalName, $path, $thumbs = array()) { if (!file_exists($this->root)) { throw new \Nette\IOException("FileBackend root doesn't exists '{$this->root}'"); } if (!file_exists($sourceFile)) { throw new \Nette\IOException("Source file '{$sourceFile}' doesn't exists "); } FileSystem::createDir($this->root . $path); $originalName = Strings::toAscii($originalName); $targetFile = $path . DIRECTORY_SEPARATOR . $originalName; $targetFullPath = $this->root . $targetFile; FileSystem::copy($sourceFile, $targetFullPath); foreach ($thumbs as $thumb => $thumbPath) { if (!file_exists($thumbPath)) { throw new \Nette\IOException("Thumb doesn't exists '{$thumbPath}'"); } $targetThumbPath = $this->root . $path . DIRECTORY_SEPARATOR . $thumb . '_' . $originalName; FileSystem::copy($thumbPath, $targetThumbPath); } return $path . DIRECTORY_SEPARATOR . $originalName; }
/** * @param array $params * @return IResponse */ public function execute(array $params = []) { $vars = $this->parameters['vars']; $theme = $this->parameters['theme']; $output = $this->parameters['output']; // Force create folder Helpers::purge($output); // Create Latte $template = $this->templateFactory->createTemplate(); // Convert all latte files to static html files foreach (Finder::find('*.latte')->in(implode(', ', (array) $theme['pages'])) as $file => $splfile) { /** @var \SplFileInfo $splfile */ $template->setFile($splfile->getRealPath()); $template->setParameters($params); $template->setParameters($vars); file_put_contents($output . DS . $splfile->getBasename('.latte') . '.html', $template->__toString()); } // Move all files/folders to output foreach ($theme['copy'] as $copy) { FileSystem::copy($copy, $output . DS . str_replace($theme['pages'], NULL, $copy), TRUE); } return new TextResponse("Generate: done"); }
function showMyTemplates() { $customer = $this->add('xepan\\commerce\\Model_Customer'); $customer->loadLoggedIn(); $template_grid = $this->add('xepan\\base\\Grid', null, 'my_template', ['view\\tool\\mytemplate']); $template_grid->setModel('xepan\\epanservices\\Model_MyTemplates'); $template_grid->addHook('formatRow', function ($g) { $item = $this->add('xepan\\commerce\\Model_Item')->load($g->model->id); $g->current_row_html['preview_image'] = $item['first_image']; $g->current_row_html['preview_url'] = 'http://' . $item['sku'] . '.epan.in'; }); $vp = $this->add('VirtualPage'); $vp->set(function ($p) { $item_id = $this->app->stickyGET('item_id'); $item = $p->add('xepan\\commerce\\Model_Item')->load($item_id); $template_name = $item['sku']; if (!file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/' . $template_name))) { throw new \Exception('Template not found: Folder do not exist in websites.'); } $customer = $p->add('xepan\\commerce\\Model_Customer'); $customer->loadLoggedIn(); $epan = $p->add('xepan\\epanservices\\Model_Epan'); $epan->addCondition('created_by_id', $customer->id); $form = $p->add('Form'); $form->addField('xepan\\commerce\\DropDown', 'epan')->setModel($epan); if ($form->isSubmitted()) { $model_epan = $p->add('xepan\\epanservices\\Model_Epan')->load($form['epan']); $folder_name = $model_epan['name']; if (!$model_epan->loaded()) { throw new \Exception("Epan model not loaded"); } // NUMBER OF TEMPLATES (NUMBER OF THIS TEMPLATE PURCHASED?) $epan_template = $this->add('xepan\\epanservices\\Model_MyTemplates'); $epan_template->addCondition('id', $item_id); $template_count = $epan_template->count()->getOne(); // NUMBER OF EPANS ON WHICH THIS TEMPLATE IS APPLIED $applied_count_epan = $this->add('xepan\\epanservices\\Model_Epan'); $applied_count_epan->addCondition('created_by_id', $customer->id); $applied_count_epan->addCondition('xepan_template_id', $item_id); $epan_count = $applied_count_epan->count()->getOne(); // NO MORE TEMPLATES LEFT TO APPLY if ($epan_count == $template_count) { return $form->error('epan', 'You have already applied this template. Please buy or use any other template'); } if (file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/' . $folder_name . '/www'))) { $fs = \Nette\Utils\FileSystem::delete('./websites/' . $folder_name . '/www'); } $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $folder_name . '/www'); $fs = \Nette\Utils\FileSystem::copy('./websites/' . $template_name, './websites/' . $folder_name . '/www', true); $model_epan['xepan_template_id'] = $item_id; $model_epan->save(); return $form->js()->univ()->successMessage('Template Applied')->execute(); } }); $template_grid->on('click', '.xepan-change-template', function ($js, $data) use($vp) { return $js->univ()->dialogURL("APPLY NEW TEMPLATE", $this->api->url($vp->getURL(), ['item_id' => $data['id']])); }); }
function createFolder($m) { if (file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/' . $this['name']))) { throw $this->exception('Epan cannot be created, folder already exists', 'ValidityCheck')->setField('name')->addMoreInfo('epan', $this['name']); } if (file_exists(realpath($this->app->pathfinder->base_location->base_path . '/websites/default/www'))) { $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $this['name']); $fs = \Nette\Utils\FileSystem::copy('./websites/default/www', './websites/' . $this['name'] . '/www', true); } else { $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $this['name']); $fs = \Nette\Utils\FileSystem::copy('./vendor/xepan/cms/templates/defaultlayout', './websites/' . $this['name'], true); } $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $this['name'] . '/assets'); $fs = \Nette\Utils\FileSystem::createDir('./websites/' . $this['name'] . '/upload'); }
/** * Copies a file or directory. * * @param string $source Source path * @param string $destination Destination path * @param bool $overwrite Allow override * * @return void */ public function copy($source, $destination, $overwrite = true) { \Nette\Utils\FileSystem::copy($source, $destination, $overwrite); }