protected function compile() { \Contao\ModuleFaqReader::compile(); $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories); if (null !== $objFaq) { $objFaq->viewcount++; $objFaq->save(); } }
/** * Generate the module */ protected function compile() { global $objPage; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->Template->referer = 'javascript:history.go(-1)'; $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories); if ($objFaq === null) { // Do not index or cache the page $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); $this->Template->error = '<p class="error">' . sprintf($GLOBALS['TL_LANG']['MSC']['invalidPage'], \Input::get('items')) . '</p>'; return; } // Overwrite the page title and description if ($objFaq->question != '') { $objPage->pageTitle = strip_insert_tags($objFaq->question); $objPage->description = $this->prepareMetaDescription($objFaq->question); } $this->Template->question = $objFaq->question; // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $objFaq->answer = \String::toXhtml($objFaq->answer); } else { $objFaq->answer = \String::toHtml5($objFaq->answer); } $this->Template->answer = \String::encodeEmail($objFaq->answer); $this->Template->addImage = false; // Add image if ($objFaq->addImage && $objFaq->singleSRC != '') { if (!is_numeric($objFaq->singleSRC)) { $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } else { $objModel = \FilesModel::findByPk($objFaq->singleSRC); if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) { $objFaq->singleSRC = $objModel->path; $this->addImageToTemplate($this->Template, $objFaq->row()); } } } $this->Template->enclosure = array(); // Add enclosure if ($objFaq->addEnclosure) { $this->addEnclosuresToTemplate($this->Template, $objFaq->row()); } $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], $this->parseDate($objPage->dateFormat, $objFaq->tstamp), $objFaq->getRelated('author')->name); // HOOK: comments extension required if ($objFaq->noComments || !in_array('comments', $this->Config->getActiveModules())) { $this->Template->allowComments = false; return; } $objCategory = $objFaq->getRelated('pid'); // Check whether comments are allowed if (!$objCategory->allowComments) { $this->Template->allowComments = false; return; } $this->Template->allowComments = true; // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCategory->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCategory->notify != 'notify_admin') { if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCategory->perPage; $objConfig->order = $objCategory->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCategory->requireLogin; $objConfig->disableCaptcha = $objCategory->disableCaptcha; $objConfig->bbcode = $objCategory->bbcode; $objConfig->moderate = $objCategory->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies); }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack']; $this->Template->referer = 'javascript:history.go(-1)'; $objFaq = \FaqModel::findPublishedByParentAndIdOrAlias(\Input::get('items'), $this->faq_categories); if (null === $objFaq) { /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } // Overwrite the page title and description (see #2853 and #4955) if ($objFaq->question != '') { $objPage->pageTitle = strip_tags(strip_insert_tags($objFaq->question)); $objPage->description = $this->prepareMetaDescription($objFaq->question); } $this->Template->question = $objFaq->question; // Clean RTE output if ($objPage->outputFormat == 'xhtml') { $objFaq->answer = \StringUtil::toXhtml($objFaq->answer); } else { $objFaq->answer = \StringUtil::toHtml5($objFaq->answer); } $this->Template->answer = \StringUtil::encodeEmail($objFaq->answer); $this->Template->addImage = false; // Add image if ($objFaq->addImage && $objFaq->singleSRC != '') { $objModel = \FilesModel::findByUuid($objFaq->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($objFaq->singleSRC)) { $this->Template->answer = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { // Do not override the field now that we have a model registry (see #6303) $arrFaq = $objFaq->row(); $arrFaq['singleSRC'] = $objModel->path; $this->addImageToTemplate($this->Template, $arrFaq); } } $this->Template->enclosure = array(); // Add enclosure if ($objFaq->addEnclosure) { $this->addEnclosuresToTemplate($this->Template, $objFaq->row()); } $strAuthor = ''; // Add the author if (($objAuthor = $objFaq->getRelated('author')) !== null) { $strAuthor = $objAuthor->name; } $this->Template->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $strAuthor); // HOOK: comments extension required if ($objFaq->noComments || !in_array('comments', \ModuleLoader::getActive())) { $this->Template->allowComments = false; return; } /** @var \FaqCategoryModel $objCategory */ $objCategory = $objFaq->getRelated('pid'); $this->Template->allowComments = $objCategory->allowComments; // Comments are not allowed if (!$objCategory->allowComments) { return; } // Adjust the comments headline level $intHl = min(intval(str_replace('h', '', $this->hl)), 5); $this->Template->hlc = 'h' . ($intHl + 1); $this->import('Comments'); $arrNotifies = array(); // Notify the system administrator if ($objCategory->notify != 'notify_author') { $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL']; } // Notify the author if ($objCategory->notify != 'notify_admin') { /** @var \UserModel $objAuthor */ if (($objAuthor = $objFaq->getRelated('author')) !== null && $objAuthor->email != '') { $arrNotifies[] = $objAuthor->email; } } $objConfig = new \stdClass(); $objConfig->perPage = $objCategory->perPage; $objConfig->order = $objCategory->sortOrder; $objConfig->template = $this->com_template; $objConfig->requireLogin = $objCategory->requireLogin; $objConfig->disableCaptcha = $objCategory->disableCaptcha; $objConfig->bbcode = $objCategory->bbcode; $objConfig->moderate = $objCategory->moderate; $this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_faq', $objFaq->id, $arrNotifies); }