Esempio n. 1
0
 /**
  * Add FAQs to the indexer
  *
  * @param array   $arrPages
  * @param integer $intRoot
  * @param boolean $blnIsSitemap
  *
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $arrProcessed = array();
     $time = \Date::floorToMinute();
     // Get all categories
     $objFaq = \FaqCategoryModel::findAll();
     // Walk through each category
     if ($objFaq !== null) {
         while ($objFaq->next()) {
             // Skip FAQs without target page
             if (!$objFaq->jumpTo) {
                 continue;
             }
             // Skip FAQs outside the root nodes
             if (!empty($arrRoot) && !in_array($objFaq->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objFaq->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objFaq->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 // The target page has not been published (see #5520)
                 if (!$objParent->published || $objParent->start != '' && $objParent->start > $time || $objParent->stop != '' && $objParent->stop <= $time + 60) {
                     continue;
                 }
                 if ($blnIsSitemap) {
                     // The target page is protected (see #8416)
                     if ($objParent->protected) {
                         continue;
                     }
                     // The target page is exempt from the sitemap (see #6418)
                     if ($objParent->sitemap == 'map_never') {
                         continue;
                     }
                 }
                 // Generate the URL
                 $arrProcessed[$objFaq->jumpTo] = $objParent->getAbsoluteUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s');
             }
             $strUrl = $arrProcessed[$objFaq->jumpTo];
             // Get the items
             $objItems = \FaqModel::findPublishedByPid($objFaq->id);
             if ($objItems !== null) {
                 while ($objItems->next()) {
                     $arrPages[] = sprintf($strUrl, $objItems->alias ?: $objItems->id);
                 }
             }
         }
     }
     return $arrPages;
 }
Esempio n. 2
0
 /**
  * Add FAQs to the indexer
  *
  * @param array   $arrPages
  * @param integer $intRoot
  * @param boolean $blnIsSitemap
  *
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $arrProcessed = array();
     $time = \Date::floorToMinute();
     // Get all categories
     $objFaq = \FaqCategoryModel::findAll();
     // Walk through each category
     if ($objFaq !== null) {
         while ($objFaq->next()) {
             // Skip FAQs without target page
             if (!$objFaq->jumpTo) {
                 continue;
             }
             // Skip FAQs outside the root nodes
             if (!empty($arrRoot) && !in_array($objFaq->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objFaq->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objFaq->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 // The target page has not been published (see #5520)
                 if (!$objParent->published || $objParent->start != '' && $objParent->start > $time || $objParent->stop != '' && $objParent->stop <= $time + 60) {
                     continue;
                 }
                 // The target page is exempt from the sitemap (see #6418)
                 if ($blnIsSitemap && $objParent->sitemap == 'map_never') {
                     continue;
                 }
                 // Generate the URL
                 $feUrl = $objParent->getFrontendUrl(\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/%s' : '/items/%s');
                 if (strncmp($feUrl, 'http://', 7) !== 0 && strncmp($feUrl, 'https://', 8) !== 0) {
                     $feUrl = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . TL_PATH . '/' . $feUrl;
                 }
                 $arrProcessed[$objFaq->jumpTo] = $feUrl;
             }
             $strUrl = $arrProcessed[$objFaq->jumpTo];
             // Get the items
             $objItems = \FaqModel::findPublishedByPid($objFaq->id);
             if ($objItems !== null) {
                 while ($objItems->next()) {
                     $arrPages[] = sprintf($strUrl, $objItems->alias != '' && !\Config::get('disableAlias') ? $objItems->alias : $objItems->id);
                 }
             }
         }
     }
     return $arrPages;
 }
Esempio n. 3
0
 /**
  * Add FAQs to the indexer
  * @param array
  * @param integer
  * @param boolean
  * @return array
  */
 public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
 {
     $arrRoot = array();
     if ($intRoot > 0) {
         $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page');
     }
     $arrProcessed = array();
     // Get all categories
     $objFaq = \FaqCategoryModel::findAll();
     // Walk through each category
     if ($objFaq !== null) {
         while ($objFaq->next()) {
             // Skip FAQs without target page
             if (!$objFaq->jumpTo) {
                 continue;
             }
             // Skip FAQs outside the root nodes
             if (!empty($arrRoot) && !in_array($objFaq->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objFaq->jumpTo])) {
                 $domain = \Environment::get('base');
                 $objParent = $this->getPageDetails($objFaq->jumpTo);
                 // The target page does not exist
                 if ($objParent === null) {
                     continue;
                 }
                 if ($objParent->domain != '') {
                     $domain = (\Environment::get('ssl') ? 'https://' : 'http://') . $objParent->domain . TL_PATH . '/';
                 }
                 $arrProcessed[$objFaq->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), $GLOBALS['TL_CONFIG']['useAutoItem'] ? '/%s' : '/items/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objFaq->jumpTo];
             // Get the items
             $objItems = \FaqModel::findByPid($objFaq->id, array('order' => 'sorting'));
             if ($objItems !== null) {
                 while ($objItems->next()) {
                     $arrPages[] = sprintf($strUrl, $objItems->alias != '' && !$GLOBALS['TL_CONFIG']['disableAlias'] ? $objItems->alias : $objItems->id);
                 }
             }
         }
     }
     return $arrPages;
 }
 /**
  * prepare
  */
 public function prepare()
 {
     // check if the faq module is active
     if (in_array('faq', $this->Config->getActiveModules())) {
         // load backend user
         $this->import('BackendUser', 'User');
         // check permission
         if ($this->User->isAdmin || $this->User->hasAccess('faq', 'modules') && isset($this->User->faqs) && is_array($this->User->faqs)) {
             // check if table exists
             if (!$this->Database->tableExists('tl_faq')) {
                 return;
             }
             // get all faq categories
             $objFaq = \FaqCategoryModel::findAll(array('order' => 'title'));
             // there are at minimum one faq category
             if (!is_null($objFaq) && $objFaq->count()) {
                 // prepare directentry array
                 $arrDirectEntry = array();
                 // set counter
                 $intCounter = 1;
                 // do this foreach page
                 while ($objFaq->next()) {
                     // check page permission
                     if ($this->User->isAdmin || in_array($objFaq->id, $this->User->faqs)) {
                         // set the icon url and title
                         $arrDirectEntry[$intCounter]['icons']['page']['url'] = 'contao/main.php?do=faq&table=tl_faq&id=' . $objFaq->id;
                         $arrDirectEntry[$intCounter]['icons']['page']['title'] = 'faq';
                         $arrDirectEntry[$intCounter]['icons']['page']['icon'] = 'system/modules/faq/assets/icon.gif';
                         // set the page url and title
                         $arrDirectEntry[$intCounter]['name']['url'] = 'contao/main.php?do=faq&table=tl_faq&id=' . $objFaq->id;
                         $arrDirectEntry[$intCounter]['name']['title'] = $objFaq->title;
                         $arrDirectEntry[$intCounter]['name']['link'] = strlen($objFaq->title) > 17 ? substr($objFaq->title, 0, 15) . '...' : $objFaq->title;
                         // add one to counter
                         $intCounter++;
                     }
                 }
                 // add to direcentries service
                 $this->import('DirectEntries');
                 $this->DirectEntries->addDirectEntry('content', 'faq', $arrDirectEntry);
             }
         }
     }
 }