protected static function handleRequest(\Curry_Request $request) { ob_start(); $app = \Curry_Application::getInstance(); $app->handle($request); return ob_get_clean(); }
/** * Render a page and return content. * * @param array $vars * @param array $options * @return string */ public function render(array $vars = array(), array $options = array()) { $twig = Curry_Twig_Template::getSharedEnvironment(); // Todo: Rename curry to app? $appVars = Curry_Application::getInstance()->getGlobalVariables(); if (isset($vars['curry'])) { Curry_Array::extend($appVars, $vars['curry']); } $vars['curry'] = Curry_Array::extend($appVars, $this->getGlobals()); foreach ($vars as $k => $v) { $twig->addGlobal($k, $v); } $moduleContent = $this->generate($options); if (isset($options['pageModuleId'])) { $pageModuleId = $options['pageModuleId']; $pageModuleWrappers = $this->getPageModuleWrappers(); if (isset($pageModuleWrappers[$pageModuleId])) { $pageModuleWrapper = $pageModuleWrappers[$pageModuleId]; return $moduleContent[$pageModuleWrapper->getTarget()]; } else { throw new Exception('PageModule with id = ' . $pageModuleId . ' not found on page.'); } } $template = $this->getTemplateObject(); return $this->renderTemplate($template, $moduleContent); }
/** {@inheritdoc} */ protected function postGeneration() { parent::postGeneration(); if ($this->inlineAdmin) { $this->adminPanel(); } else { if (Curry_Core::$config->curry->liveEdit && User::getUser()) { // Add button to toggle live edit $url = json_encode(url('', $_GET)->add(array('curry_inline_admin' => 1))->remove('curry_force_show')->getAbsolute()); $htmlHead = $this->getHtmlHead(); $htmlHead->addInlineScript(<<<JS document.addEventListener('DOMContentLoaded', function() { \tvar el = document.createElement('a'); \tel.id = 'curry-enable-live-edit'; \tel.href = {$url}; \tel.textContent = 'Live edit'; \tel.style.display = 'block'; \tel.style.position = 'fixed'; \tel.style.right = '5px'; \tel.style.top = '5px'; \tel.style.backgroundColor = 'black'; \tel.style.color = 'white'; \tel.style.padding = '5px'; \tel.style.zIndex = 1000; \tel.style.textDecoration = 'none'; \tdocument.body.appendChild(el); }); JS ); } } $appVars = Curry_Application::getInstance()->getGlobalVariables(); $appVars->HtmlHead = $this->htmlHead->getContent(); }
/** * Create a mail from a URL, Page or PageRevision. * * @param string|Page|PageRevision $page * @param Curry_Request $request * @param array $variables Additional template variables. * @return Curry_Mail */ public static function createFromPage($page, $request = null, array $variables = array()) { $app = Curry_Application::getInstance(); // If a URL is provided, attempt to find page using route if (is_string($page)) { $r = new Curry_Request('GET', (string) url($page)); $page = $app->findPage($r); if (!$request) { $request = $r; } } // Find PageRevision if ($page instanceof PageRevision) { $pageRevision = $page; } elseif ($page instanceof Page) { $pageRevision = $page->getPageRevision(); if (!$pageRevision) { throw new Exception('Page has no active revision.'); } } else { throw new Exception('$page is of invalid type, expected Page or PageRevision.'); } // Create Curry_Request object if not provided $oldVal = Curry_URL::setPreventRedirect(true); if (!$request) { $url = (string) url($pageRevision->getPage()->getUrl()); $request = new Curry_Request('GET', $url); } // Generate page $pageGenerator = $app->createPageGenerator($pageRevision, $request); $content = $pageGenerator->render($variables); // Create email $mail = new Curry_Mail(); $mail->setBodyHtml($content); $mail->setBodyText(strip_tags($content)); // restore redirect status Curry_URL::setPreventRedirect($oldVal); return $mail; }