Пример #1
0
 /**
  * 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));
 }
 protected function compile()
 {
     global $objPage;
     // Get the current faq item
     $objFaqItem = FaqModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->faq_categories);
     if ($objFaqItem === null) {
         parent::compile();
     }
     $objPage->canonicalType = $objFaqItem->canonicalType;
     $objPage->canonicalJumpTo = $objFaqItem->canonicalJumpTo;
     $objPage->canonicalWebsite = $objFaqItem->canonicalWebsite;
     if ($objFaqItem->canonicalType == 'self') {
         $objPage->canonicalType = 'external';
         $objPage->canonicalWebsite = Environment::get('url') . TL_PATH . '/' . Environment::get('request');
     }
     parent::compile();
 }
 /**
  * @inheritdoc
  */
 protected function findPublishedBy(array $columns, array $values = array(), array $options = array())
 {
     return FaqModel::findOneBy($this->addPublishedConditions($columns, FaqModel::getTable(), false), $values, $options);
 }
Пример #4
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     /** @var PageModel $objPage */
     global $objPage;
     $arrFaqs = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         /** @var FaqModel $objFaq */
         $objTemp = (object) $objFaq->row();
         // Clean the RTE output
         $objTemp->answer = \StringUtil::toHtml5($objFaq->answer);
         $objTemp->answer = \StringUtil::encodeEmail($objTemp->answer);
         $objTemp->addImage = false;
         // Add an image
         if ($objFaq->addImage && $objFaq->singleSRC != '') {
             $objModel = \FilesModel::findByUuid($objFaq->singleSRC);
             if ($objModel !== null && 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;
                 $strLightboxId = 'lightbox[' . substr(md5('mod_faqpage_' . $objFaq->id), 0, 6) . ']';
                 // see #5810
                 $this->addImageToTemplate($objTemp, $arrFaq, null, $strLightboxId);
             }
         }
         $objTemp->enclosure = array();
         // Add enclosure
         if ($objFaq->addEnclosure) {
             $this->addEnclosuresToTemplate($objTemp, $objFaq->row());
         }
         /** @var UserModel $objAuthor */
         $objAuthor = $objFaq->getRelated('author');
         $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $objAuthor->name);
         /** @var FaqCategoryModel $objPid */
         $objPid = $objFaq->getRelated('pid');
         // Order by PID
         $arrFaqs[$objFaq->pid]['items'][] = $objTemp;
         $arrFaqs[$objFaq->pid]['headline'] = $objPid->headline;
         $arrFaqs[$objFaq->pid]['title'] = $objPid->title;
     }
     $arrFaqs = array_values(array_filter($arrFaqs));
     $limit_i = count($arrFaqs) - 1;
     // Add classes first, last, even and odd
     for ($i = 0; $i <= $limit_i; $i++) {
         $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
         $arrFaqs[$i]['class'] = trim($class);
         $limit_j = count($arrFaqs[$i]['items']) - 1;
         for ($j = 0; $j <= $limit_j; $j++) {
             $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd');
             $arrFaqs[$i]['items'][$j]->class = trim($class);
         }
     }
     $this->Template->faq = $arrFaqs;
     $this->Template->request = \Environment::get('indexFreeRequest');
     $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop'];
 }
 /**
  * Generate missing translation warning for faq child records.
  *
  * @param array $args
  * @param mixed $previousResult
  *
  * @return string
  */
 public function onFaqChildRecords(array $args, $previousResult = null)
 {
     $row = $args[0];
     $label = (string) $previousResult;
     $category = FaqCategoryModel::findByPk($row['pid']);
     if ($category->master && (!$row['languageMain'] || null === FaqModel::findByPk($row['languageMain']))) {
         return preg_replace('#</div>#', $this->generateLabelWithWarning('', 'position:absolute;top:6px') . '</div>', $label, 1);
     }
     return $label;
 }
Пример #6
0
 /**
  * Create links and remember pages that have been processed
  *
  * @param FaqModel $objFaq
  *
  * @return string
  *
  * @throws \Exception
  */
 protected function generateFaqLink($objFaq)
 {
     /** @var FaqCategoryModel $objCategory */
     $objCategory = $objFaq->getRelated('pid');
     $jumpTo = intval($objCategory->jumpTo);
     // A jumpTo page is not mandatory for FAQ categories (see #6226) but required for the FAQ list module
     if ($jumpTo < 1) {
         throw new \Exception("FAQ categories without redirect page cannot be used in an FAQ list");
     }
     // Get the URL from the jumpTo page of the category
     if (!isset($this->arrTargets[$jumpTo])) {
         $this->arrTargets[$jumpTo] = ampersand(\Environment::get('request'), true);
         if ($jumpTo > 0 && ($objTarget = \PageModel::findByPk($jumpTo)) !== null) {
             /** @var PageModel $objTarget */
             $this->arrTargets[$jumpTo] = ampersand($objTarget->getFrontendUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s'));
         }
     }
     return sprintf($this->arrTargets[$jumpTo], $objFaq->alias ?: $objFaq->id);
 }
Пример #7
0
 /**
  * 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) {
         throw new PageNotFoundException('Page not found');
     }
     // 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 the RTE output
     $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 && 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);
     $bundles = \System::getContainer()->getParameter('kernel.bundles');
     // HOOK: comments extension required
     if ($objFaq->noComments || !isset($bundles['ContaoCommentsBundle'])) {
         $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);
 }