Inheritance: extends Contao\CoreBundle\ContaoFrameworkInterface
 /**
  * Adds the Contao headers to the Symfony response.
  *
  * @param FilterResponseEvent $event The event object
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$this->contaoFramework->isInitialized()) {
         return;
     }
     $event->setResponse($this->mergeHttpHeaders($event->getResponse()));
 }
 /**
  * Renders an insert tag.
  *
  * @param string $insertTag
  *
  * @return Response
  */
 public function renderAction($insertTag)
 {
     $this->framework->initialize();
     /** @var InsertTags $it */
     $it = $this->framework->createInstance('Contao\\InsertTags');
     // Never cache these responses
     return (new Response($it->replace($insertTag, false)))->setPrivate();
 }
 /**
  * Returns the event model.
  *
  * @param Request $request The request object
  *
  * @return CalendarEventsModel|null The event model or null
  */
 private function getEventModel(Request $request)
 {
     if (!$request->query->has('calendar')) {
         return null;
     }
     /** @var CalendarEventsModel $adapter */
     $adapter = $this->framework->getAdapter('Contao\\CalendarEventsModel');
     return $adapter->findByPk($request->query->get('calendar'));
 }
 /**
  * Returns the news model.
  *
  * @param Request $request The request object
  *
  * @return NewsModel|null The news model or null
  */
 private function getNewsModel(Request $request)
 {
     if (!$request->query->has('news')) {
         return null;
     }
     /** @var NewsModel $adapter */
     $adapter = $this->framework->getAdapter('Contao\\NewsModel');
     return $adapter->findByPk($request->query->get('news'));
 }
 /**
  * Forwards the request to the Frontend class if there is a page object.
  *
  * @param PostResponseEvent $event
  */
 public function onKernelTerminate(PostResponseEvent $event)
 {
     if (!$this->framework->isInitialized()) {
         return;
     }
     /** @var Frontend $frontend */
     $frontend = $this->framework->getAdapter('Contao\\Frontend');
     $frontend->indexPageIfApplicable($event->getResponse());
 }
 /**
  * Adds the feed markup to the page header.
  *
  * @param Collection|NewsFeedModel[] $feeds
  */
 private function addFeedMarkupToPageHeader(Collection $feeds)
 {
     /** @var Template $template */
     $template = $this->framework->getAdapter(Template::class);
     /** @var Environment $environment */
     $environment = $this->framework->getAdapter(Environment::class);
     foreach ($feeds as $feed) {
         $GLOBALS['TL_HEAD'][] = $template->generateFeedTag(sprintf('%sshare/%s.xml', $feed->feedBase ?: $environment->get('base'), $feed->alias), $feed->format, $feed->title);
     }
 }
 /**
  * Generates the URL for an FAQ.
  *
  * @param FaqModel $faq
  *
  * @return string|false
  */
 private function generateUrl(FaqModel $faq)
 {
     /** @var PageModel $jumpTo */
     if (!($category = $faq->getRelated('pid')) instanceof FaqCategoryModel || !($jumpTo = $category->getRelated('jumpTo')) instanceof PageModel) {
         return false;
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     return $jumpTo->getFrontendUrl(($config->get('useAutoItem') ? '/' : '/items/') . ($faq->alias ?: $faq->id));
 }
 /**
  * Return the page picker wizard
  *
  * @param DataContainer $dc
  *
  * @return string
  */
 public function generatePagePicker(DataContainer $dc)
 {
     /**
      * @var \Contao\Image $imageAdapter
      * @var \Contao\Input $inputAdapter
      */
     $imageAdapter = $this->framework->getAdapter('Contao\\Image');
     $inputAdapter = $this->framework->getAdapter('Contao\\Input');
     return ' <a href="contao/page.php?do=' . $inputAdapter->get('do') . '&amp;table=' . $dc->table . '&amp;field=' . $dc->field . '&amp;value=' . str_replace(['{{link_url::', '}}'], '', $dc->value) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']) . '" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MOD']['page'][0])) . '\',\'url\':this.href,\'id\':\'' . $dc->field . '\',\'tag\':\'ctrl_' . $dc->field . ($inputAdapter->get('act') === 'editAll' ? '_' . $dc->id : '') . '\',\'self\':this});return false">' . $imageAdapter->getHtml('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>';
 }
 /**
  * Toggles the TL_VIEW cookie and redirects back to the referring page.
  *
  * @param GetResponseEvent $event The event object
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->isFrontendMasterRequest($event) || !$request->query->has('toggle_view')) {
         return;
     }
     $this->framework->initialize();
     $response = new RedirectResponse(System::getReferer(), 303);
     $response->headers->setCookie($this->getCookie($request->query->get('toggle_view'), $request->getBasePath()));
     $event->setResponse($response);
 }
 /**
  * Returns the page model for an FAQ.
  *
  * @param int $id
  *
  * @return PageModel|false|null
  */
 private function getPageForFaq($id)
 {
     $this->framework->initialize();
     /** @var FaqCategoryModel $categoryAdapter */
     $categoryAdapter = $this->framework->getAdapter(FaqCategoryModel::class);
     if (null === ($categoryModel = $categoryAdapter->findByPk($id))) {
         return false;
     }
     /** @var PageModel $pageModel */
     $pageModel = $categoryModel->getRelated('jumpTo');
     return $pageModel;
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     if (!$this->isCompleteInstallation()) {
         return;
     }
     $this->framework->initialize();
     $this->generateConfigCache($cacheDir);
     $this->generateDcaCache($cacheDir);
     $this->generateLanguageCache($cacheDir);
     $this->generateDcaExtracts($cacheDir);
     $this->generateTemplateMapper($cacheDir);
 }
 /**
  * Forwards the request to the Frontend class and sets the response if any.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (!$this->isFrontendMasterRequest($event)) {
         return;
     }
     $this->framework->initialize();
     /** @var Frontend $frontend */
     $frontend = $this->framework->getAdapter('Contao\\Frontend');
     if (null !== ($response = $frontend->getResponseFromCache())) {
         $event->setResponse($response);
     }
 }
 /**
  * {@inheritdoc}
  *
  * @return BackendUser|FrontendUser
  */
 public function loadUserByUsername($username)
 {
     if ($this->isBackendUsername($username)) {
         $this->framework->initialize();
         return BackendUser::getInstance();
     }
     if ($this->isFrontendUsername($username)) {
         $this->framework->initialize();
         return FrontendUser::getInstance();
     }
     throw new UsernameNotFoundException('Can only load user "frontend" or "backend".');
 }
 /**
  * Enable the Bootstrap features
  *
  * @param DataContainer $dc
  */
 public function enableBootstrapFeatures(DataContainer $dc)
 {
     if (!$dc->id) {
         return;
     }
     $layoutModel = $this->framework->getAdapter('Contao\\LayoutModel')->findByPk($dc->id);
     if ($layoutModel === null || !$layoutModel->cfg_bootstrap_enable) {
         return;
     }
     $this->extendPalettes();
     $this->replaceSubpalettes();
 }
 /**
  * Forwards the request to the Frontend class if there is a page object.
  *
  * @param PostResponseEvent $event
  */
 public function onKernelTerminate(PostResponseEvent $event)
 {
     if (!$this->framework->isInitialized()) {
         return;
     }
     // Do not index fragments
     if (preg_match('~(?:^|/)' . preg_quote($this->fragmentPath, '~') . '/~', $event->getRequest()->getPathInfo())) {
         return;
     }
     /** @var Frontend $frontend */
     $frontend = $this->framework->getAdapter(Frontend::class);
     $frontend->indexPageIfApplicable($event->getResponse());
 }
 /**
  * Runs the command scheduler.
  */
 public function onKernelTerminate()
 {
     if (!$this->framework->isInitialized()) {
         return;
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter('Contao\\Config');
     if ($config->get('disableCron')) {
         return;
     }
     /** @var FrontendCron $controller */
     $controller = $this->framework->createInstance('Contao\\FrontendCron');
     $controller->run();
 }
 /**
  * Update the particular page buffer
  *
  * @param string $buffer
  * @param int    $pageId
  *
  * @return string
  */
 public function updatePageBuffer($buffer, $pageId)
 {
     /**
      * @var HtmlInjectionModel   $adapter
      * @var HtmlInjectionModel[] $models
      */
     $adapter = $this->framework->getAdapter('Terminal42\\HtmlInjectionBundle\\Model\\HtmlInjectionModel');
     $models = $adapter->findByPage($pageId);
     if (null !== $models) {
         foreach ($models as $model) {
             $buffer = $this->injectCode($buffer, $model->code, $model->position);
         }
     }
     return $buffer;
 }
 /**
  * Returns the page model for a news item.
  *
  * @param int $id
  *
  * @return PageModel|false|null
  */
 private function getPageForNews($id)
 {
     $this->framework->initialize();
     /** @var NewsModel $newsAdapter */
     $newsAdapter = $this->framework->getAdapter(NewsModel::class);
     if (null === ($newsModel = $newsAdapter->findByPk($id))) {
         return false;
     }
     /** @var NewsArchiveModel $archiveModel */
     if (null === ($archiveModel = $newsModel->getRelated('pid'))) {
         return false;
     }
     /** @var PageModel $pageModel */
     $pageModel = $archiveModel->getRelated('jumpTo');
     return $pageModel;
 }
 /**
  * Returns the page model for an event.
  *
  * @param int $id
  *
  * @return PageModel|false|null
  */
 private function getPageForEvent($id)
 {
     $this->framework->initialize();
     /** @var CalendarEventsModel $eventsAdapter */
     $eventsAdapter = $this->framework->getAdapter(CalendarEventsModel::class);
     if (null === ($eventsModel = $eventsAdapter->findByPk($id))) {
         return false;
     }
     /** @var CalendarModel $calendarModel */
     if (null === ($calendarModel = $eventsModel->getRelated('pid'))) {
         return false;
     }
     /** @var PageModel $pageModel */
     $pageModel = $calendarModel->getRelated('jumpTo');
     return $pageModel;
 }
 /**
  * Loads the language strings.
  *
  * @return array|null The language strings or null
  */
 private function loadLanguageStrings()
 {
     $this->framework->initialize();
     System::loadLanguageFile('exception');
     if (!isset($GLOBALS['TL_LANG']['XPT'])) {
         return null;
     }
     return $GLOBALS['TL_LANG']['XPT'];
 }
 /**
  * Return true if the Bootstrap on the given page is enabled
  *
  * @return bool
  */
 private function isBootstrapEnabled()
 {
     /** @var \Contao\LayoutModel $layoutModel */
     $layoutModel = $this->framework->getAdapter('Contao\\LayoutModel')->findByPk($GLOBALS['objPage']->layout);
     if ($layoutModel === null) {
         return false;
     }
     return $layoutModel->cfg_bootstrap_enable ? true : false;
 }
Exemple #22
0
 /**
  * Fetches the important part from the database.
  *
  * @param string $path
  *
  * @return ImportantPart|null
  */
 private function createImportantPart($path)
 {
     /** @var FilesModel $filesModel */
     $filesModel = $this->framework->getAdapter(FilesModel::class);
     $file = $filesModel->findByPath($path);
     if (null === $file || !$file->importantPartWidth || !$file->importantPartHeight) {
         return null;
     }
     return new ImportantPart(new Point((int) $file->importantPartX, (int) $file->importantPartY), new Box((int) $file->importantPartWidth, (int) $file->importantPartHeight));
 }
 /**
  * Generates URL to a news item.
  *
  * @param NewsModel $news
  *
  * @return string
  */
 private function generateNewsReaderUrl(NewsModel $news)
 {
     /** @var PageModel $targetPage */
     if (!($archive = $news->getRelated('pid')) instanceof NewsArchiveModel || !($targetPage = $archive->getRelated('jumpTo')) instanceof PageModel) {
         return '';
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     return $targetPage->getFrontendUrl(($config->get('useAutoItem') ? '/' : '/items/') . ($news->alias ?: $news->id));
 }
 /**
  * Returns the template parameters.
  *
  * @param string                       $view       The name of the view
  * @param int                          $statusCode The HTTP status code
  * @param GetResponseForExceptionEvent $event      The event object
  *
  * @return array|null The template parameters or null
  */
 private function getTemplateParameters($view, $statusCode, GetResponseForExceptionEvent $event)
 {
     if (null === ($labels = $this->loadLanguageStrings())) {
         return null;
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter('Contao\\Config');
     $encoded = StringUtil::encodeEmail($config->get('adminEmail'));
     return ['statusCode' => $statusCode, 'statusName' => Response::$statusTexts[$statusCode], 'error' => $labels, 'template' => $view, 'base' => $event->getRequest()->getBasePath(), 'adminEmail' => '&#109;&#97;&#105;&#108;&#116;&#111;&#58;' . $encoded, 'exception' => $event->getException()->getMessage()];
 }
 /**
  * Generates URL to an event.
  *
  * @param CalendarEventsModel $event
  *
  * @return string
  */
 private function generateEventReaderUrl(CalendarEventsModel $event)
 {
     /** @var PageModel $targetPage */
     if (!($calendar = $event->getRelated('pid')) instanceof CalendarModel || !($targetPage = $calendar->getRelated('jumpTo')) instanceof PageModel) {
         return '';
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     return $targetPage->getFrontendUrl(($config->get('useAutoItem') ? '/' : '/events/') . ($event->alias ?: $event->id));
 }
 /**
  * Loads the options from the database.
  */
 private function loadOptions()
 {
     if (null !== $this->options) {
         return;
     }
     // The framework is required to have the TL_CROP options available
     $this->framework->initialize();
     $this->options = $GLOBALS['TL_CROP'];
     $rows = $this->connection->fetchAll('SELECT id, name, width, height FROM tl_image_size ORDER BY pid, name');
     foreach ($rows as $imageSize) {
         $this->options['image_sizes'][$imageSize['id']] = sprintf('%s (%sx%s)', $imageSize['name'], $imageSize['width'], $imageSize['height']);
     }
 }
Exemple #27
0
 /**
  * Creates a picture configuration.
  *
  * @param int|array|null $size
  *
  * @return array<PictureConfiguration,array>
  */
 private function createConfig($size)
 {
     if (!is_array($size)) {
         $size = [0, 0, $size];
     }
     $config = new PictureConfiguration();
     $attributes = [];
     if (!isset($size[2]) || !is_numeric($size[2])) {
         $resizeConfig = new ResizeConfiguration();
         if (isset($size[0]) && $size[0]) {
             $resizeConfig->setWidth($size[0]);
         }
         if (isset($size[1]) && $size[1]) {
             $resizeConfig->setHeight($size[1]);
         }
         if (isset($size[2]) && $size[2]) {
             $resizeConfig->setMode($size[2]);
         }
         $configItem = new PictureConfigurationItem();
         $configItem->setResizeConfig($resizeConfig);
         if ($this->defaultDensities) {
             $configItem->setDensities($this->defaultDensities);
         }
         $config->setSize($configItem);
         return [$config, $attributes];
     }
     /** @var ImageSizeModel $imageSizeModel */
     $imageSizeModel = $this->framework->getAdapter(ImageSizeModel::class);
     $imageSizes = $imageSizeModel->findByPk($size[2]);
     $config->setSize($this->createConfigItem($imageSizes));
     if ($imageSizes && $imageSizes->cssClass) {
         $attributes['class'] = $imageSizes->cssClass;
     }
     /** @var ImageSizeItemModel $imageSizeItemModel */
     $imageSizeItemModel = $this->framework->getAdapter(ImageSizeItemModel::class);
     $imageSizeItems = $imageSizeItemModel->findVisibleByPid($size[2], ['order' => 'sorting ASC']);
     if (null !== $imageSizeItems) {
         $configItems = [];
         foreach ($imageSizeItems as $imageSizeItem) {
             $configItems[] = $this->createConfigItem($imageSizeItem);
         }
         $config->setSizeItems($configItems);
     }
     return [$config, $attributes];
 }
Exemple #28
0
 /**
  * Adds the parameters to the alias.
  *
  * @param string $alias
  * @param array  $parameters
  *
  * @throws MissingMandatoryParametersException
  */
 private function prepareAlias($alias, array &$parameters)
 {
     if ('index' === $alias) {
         return;
     }
     $hasAutoItem = false;
     $autoItems = $this->getAutoItems($parameters);
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     $parameters['alias'] = preg_replace_callback('/\\{([^\\}]+)\\}/', function ($matches) use($alias, &$parameters, $autoItems, &$hasAutoItem, $config) {
         $param = $matches[1];
         if (!isset($parameters[$param])) {
             throw new MissingMandatoryParametersException(sprintf('Parameters "%s" is missing to generate a URL for "%s"', $param, $alias));
         }
         $value = $parameters[$param];
         unset($parameters[$param]);
         if (!$config->get('useAutoItem') || $hasAutoItem || !in_array($param, $autoItems, true)) {
             return $param . '/' . $value;
         }
         $hasAutoItem = true;
         return $value;
     }, $alias);
 }
 /**
  * Returns the event model.
  *
  * @param int $id The ID
  *
  * @return CalendarEventsModel|null
  */
 private function getEventModel($id)
 {
     /** @var CalendarEventsModel $adapter */
     $adapter = $this->framework->getAdapter(CalendarEventsModel::class);
     return $adapter->findByPk($id);
 }
 /**
  * Checks whether the controller can be run.
  *
  * @return bool
  */
 private function canRunController()
 {
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     return $config->isComplete() && !$config->get('disableCron') && $this->connection->getSchemaManager()->tablesExist(['tl_cron']);
 }