/** * @param MacroNode $node * @param PhpWriter $writer * @return string */ public function macroIncludeBlock(MacroNode $node, PhpWriter $writer) { $node->args = $this->moduleHelpers->expandPath($node->args, 'Resources/layouts'); $node->tokenizer = new MacroTokenizer($node->args); $writer = new PhpWriter($node->tokenizer); return parent::macroIncludeBlock($node, $writer); }
public function onHeadBegin(\CmsModule\Events\RenderArgs $args) { if ($args->getPresenter() instanceof AdminPresenter) { $this->jsFileCollection->addRemoteFile($args->getPresenter()->template->basePath . '/' . $this->moduleHelpers->expandResource('@ckeditorModule/ckeditor/ckeditor.js')); $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@ckeditorModule/editor.js')); } }
public function onHeadBegin(\CmsModule\Events\RenderArgs $args) { if ($args->getPresenter() instanceof AdminPresenter) { $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@aceModule/ace/ace.js')); $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@aceModule/code.js')); } }
public function onHeadBegin(RenderArgs $args) { if ($args->getPresenter() instanceof PagePresenter) { $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@lightboxModule/fancybox/jquery.mousewheel-3.0.4.pack.js')); $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@lightboxModule/fancybox/jquery.fancybox-1.3.4.pack.js')); $this->jsFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@lightboxModule/loader.js')); $this->cssFileCollection->addFile($this->wwwDir . '/' . $this->moduleHelpers->expandResource('@lightboxModule/fancybox/jquery.fancybox-1.3.4.css')); } }
protected function applyDefaults(ExtendedElementEntity $entity, $defaults) { if (isset($defaults['image']) && is_string($defaults['image'])) { $file = $this->moduleHelpers->expandPath($defaults['image'], 'Resources/public'); if (!file_exists($file)) { throw new InvalidArgumentException("Path '{$defaults['image']}' does not exist."); } $entity->image = new FileEntity(); $entity->image->setFile(new \SplFileInfo($file)); unset($defaults['image']); } parent::applyDefaults($entity, $defaults); }
public function handleSuccess(Form $form) { if ($form->isSubmitted() === $form->getSaveButton()) { $values = $form->values; if ($values['type'] == 'component') { $file = $this->getFileByClass($values['component']); $baseName = $file->getBasename('.php') . '.latte'; $template = $file->getPath() . '/' . $baseName; $target = $this->moduleHelpers->expandPath('@' . $values['target'] . 'Module', 'Resources/layouts'); if ($values['layout']) { $target .= '/' . $values['layout']; } $target .= '/' . $baseName; } else { $presenter = explode(':', $values['presenter']); $module = lcfirst($presenter[0]); $page = lcfirst($presenter[2]); $presenter = lcfirst($presenter[3]); $template = $this->moduleHelpers->expandPath('@' . $module . 'Module/@' . $page . '.' . $presenter . '.latte', 'Resources/layouts'); $target = $this->moduleHelpers->expandPath('@' . $values['target'] . 'Module/' . ($values['layout'] ? $values['layout'] . '/' : '') . '@' . $page . '.' . $presenter . '.latte', 'Resources/layouts'); } if (!copy($template, $target)) { $form->addError("Unable to copy file '{$template}' to '{$target}'."); } } }
public function filter(\Nette\Latte\MacroNode $node, \Nette\Latte\PhpWriter $writer) { $path = $node->tokenizer->fetchWord(); $params = $writer->formatArray(); $path = $this->moduleHelpers->expandPath($path, 'Resources/public'); if (!$this->debugMode) { $sass = new \SassParser(); $file = new \SplFileInfo($path); $targetFile = $file->getBasename() . '-' . md5($path . filemtime($path)) . '.css'; $targetDir = $this->wwwCacheDir . '/sass'; $target = $targetDir . '/' . $targetFile; $targetUrl = substr($target, strlen($this->wwwDir)); if (!file_exists($targetDir)) { umask(00); mkdir($targetDir, 0777, true); } $css = $sass->toCss($path); file_put_contents($target, $css); return '$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet("' . $targetUrl . '", ' . $params . '); '; } else { return ' $_sass_file = new \\SplFileInfo("' . $path . '"); $_sass_targetFile = $_sass_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-\' . md5(\'' . $path . '\' . filemtime("' . $path . '")) . \'.css\'; $_sass_targetDir = \'' . $this->wwwCacheDir . '/sass\'; $_sass_target = $_sass_targetDir . \'/\' . $_sass_targetFile; $_sass_targetUrl = substr($_sass_target, strlen(\'' . $this->wwwDir . '\')); if (!file_exists($_sass_target)) { $_sass = new \\SassParser(); if (!file_exists($_sass_targetDir)) { umask(0000); mkdir($_sass_targetDir, 0777, true); } // Remove old files foreach (\\Nette\\Utils\\Finder::findFiles($_sass_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-*\')->from($_sass_targetDir) as $_sass_old) { unlink($_sass_old->getPathname()); } $_sass_css = $_sass->toCss(\'' . $path . '\', $_sass_target); file_put_contents($_sass_target, $_sass_css); } $control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet($_sass_targetUrl, ' . $params . '); '; } }
protected function startup() { parent::startup(); if ($this->key) { $this->currentLayout = $this->layoutRepository->find($this->key); $file = $this->moduleHelpers->expandPath($this->currentLayout->file, 'Resources/layouts'); foreach ($this->layoutManager->getElementsByFile($file) as $key => $type) { if ($this->elementRepository->findOneBy(array('layout' => $this->currentLayout->id, 'nameRaw' => $key))) { continue; } $component = $this->context->cms->elementManager->createInstance($type); $component->setLayout($this->currentLayout); $component->setName($key); $component->getEntity(); } } }
public function filter(\Nette\Latte\MacroNode $node, PhpWriter $writer) { $files = array(); $pos = 0; while ($file = $node->tokenizer->fetchWord()) { if (strpos($file, '=>') !== FALSE) { $node->tokenizer->position = $pos; break; } $files[] = $this->wwwDir . '/' . $this->moduleHelpers->expandResource($file); $pos = $node->tokenizer->position; } if (!count($files)) { throw new CompileException("Missing file name in {js}"); } eval('$args = ' . $writer->formatArray() . ';'); return "\$_control['js']->render('" . join('\', \'', $files) . "', array('config' => " . var_export($args, TRUE) . "));"; }
/** * @secured(privilege="remove") */ public function handleDelete($key) { $path = $this->moduleHelpers->expandPath($key, 'Resources/layouts'); unlink($path); if (substr($path, -14) === '/@layout.latte') { File::rmdir(dirname($path), TRUE); $this->flashMessage($this->translator->translate('Layout has been removed.'), 'success'); } else { $this->flashMessage($this->translator->translate('Template has been removed.'), 'success'); } if (!$this->isAjax()) { $this->redirect('this', array('key' => NULL)); } $this->invalidateControl('content'); $this['panel']->invalidateControl('content'); $this->payload->url = $this->link('this', array('key' => NULL)); }
public function handleSuccess(Form $form) { $values = $form->getValues(); $oldPath = $this->moduleHelpers->expandPath($form->data, 'Resources/layouts'); $form->data = $this->getKeyByValues($values); $path = $this->moduleHelpers->expandPath($form->data, 'Resources/layouts'); umask(00); if (!file_exists(dirname($path))) { if (!@mkdir(dirname($path), 0777, TRUE)) { $form->addError("File '{$path}' is not writable."); } } file_put_contents($path, $values['text']); if ($oldPath && $oldPath !== $path) { @unlink($oldPath); } }
/** * Get layout path. * * @return null|string */ public function getLayoutFile() { $data = $this->loadRouteCache(); if (!array_key_exists('layout', $data)) { $layout = NULL; if (!$this->getRoute()->layout) { $data['layout'] = $layout; } else { if ($this->websiteManager->theme) { $extendedLayout = explode('/', $this->getRoute()->getLayout()->getFile(), 2); $extendedLayout = '@' . $this->websiteManager->theme . 'Module/' . $extendedLayout[1]; $layout = $this->moduleHelpers->expandPath($extendedLayout, 'Resources/layouts'); } if ($layout == NULL || !file_exists($layout)) { $layout = $this->moduleHelpers->expandPath($this->getRoute()->getLayout()->getFile(), 'Resources/layouts'); } $data['layout'] = $layout; } $this->saveRouteCache($data); } return $data['layout']; }