/** * Generate ajax */ public function generateAjax() { if (!\Environment::get('isAjaxRequest')) { return; } if ($this->iso_searchAutocomplete && \Input::get('iso_autocomplete') == $this->id) { $objProducts = Product::findPublishedByCategories($this->findCategories(), array('order' => 'c.sorting')); if (null === $objProducts) { $objResponse = new JsonResponse(array()); $objResponse->send(); } $objResponse = new JsonResponse(array_values($objProducts->fetchEach($this->iso_searchAutocomplete))); $objResponse->send(); } }
/** * Adds the product urls to the array so they get indexed when search index is rebuilt in the maintenance module * * @param array $arrPages Absolute page urls * @param int $intRoot Root page id * @param bool $blnIsSitemap True if it's a sitemap module call (= treat differently when page is protected etc.) * * @return array Extended array of absolute page urls */ public function addProductsToSearchIndex($arrPages, $intRoot = 0, $blnIsSitemap = false) { $t = \PageModel::getTable(); $time = \Date::floorToMinute(); $arrValue = array(); $arrColumn = array("{$t}.type='root'", "{$t}.published='1'", "({$t}.start='' OR {$t}.start<'{$time}')", "({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "')"); if ($intRoot > 0) { $arrColumn[] = "{$t}.id=?"; $arrValue[] = $intRoot; } $objRoots = \PageModel::findBy($arrColumn, $arrValue); if (null !== $objRoots) { foreach ($objRoots as $objRoot) { $arrPageIds = \Database::getInstance()->getChildRecords($objRoot->id, $t, false); $arrPageIds[] = $intRoot; $objProducts = Product::findPublishedByCategories($arrPageIds); if (null !== $objProducts) { foreach ($objProducts as $objProduct) { // Find the categories in the current root $arrCategories = array_intersect($objProduct->getCategories(), $arrPageIds); $intRemaining = count($arrCategories); foreach ($arrCategories as $intPage) { $objPage = \PageModel::findByPk($intPage); --$intRemaining; // The target page does not exist if ($objPage === null) { continue; } // The target page has not been published if (!$objPage->published || $objPage->start != '' && $objPage->start > $time || $objPage->stop != '' && $objPage->stop < $time + 60) { continue; } // The target page is exempt from the sitemap if ($blnIsSitemap && $objPage->sitemap == 'map_never') { continue; } // Do not generate a reader for the index page, except if it is the only one if ($intRemaining > 0 && $objPage->alias == 'index') { continue; } // Generate the domain $strDomain = $objRoot->useSSL ? 'https://' : 'http://'; $strDomain .= ($objRoot->dns ?: \Environment::get('host')) . TL_PATH . '/'; // Pass root language to page object $objPage->language = $objRoot->language; $arrPages[] = $strDomain . $objProduct->generateUrl($objPage); // Only take the first category because this is our primary one // Having multiple reader pages in the sitemap XML would mean duplicate content break; } } } } } return array_unique($arrPages); }