public function languageLabels($row, $label, $dc = null, $imageAttribute = '', $blnReturnImage = false, $blnProtected = false) { // generate the default label $objDcaClass = null; if (in_array('cacheicon', ModuleLoader::getActive())) { $objDcaClass = new tl_page_cacheicon(); } elseif (in_array('Avisota', ModuleLoader::getActive())) { $objDcaClass = new tl_page_avisota(); } else { $objDcaClass = new tl_page(); } $label = $objDcaClass->addIcon($row, $label, $dc, $imageAttribute, $blnReturnImage, $blnProtected); // return the label for root or folder page if ($row['type'] == 'root' || $row['type'] == 'folder') { return $label; } // load the current page $objPage = PageModel::findWithDetails($row['id']); // prepare alternate pages $objAlternates = null; if ($objPage->languageMain) { // get all pages referencing the same fallback page $t = \PageModel::getTable(); $objAlternates = PageModel::findBy(array("{$t}.languageMain = ? OR {$t}.id = ?"), array($objPage->languageMain, $objPage->languageMain)); } else { // get all pages referencing the current page as its fallback $objAlternates = PageModel::findByLanguageMain($objPage->id); } // check if alternates were found if ($objAlternates !== null) { $label .= '<ul class="tl_page_language_alternates">'; // go through each page and add link while ($objAlternates->next()) { if ($objAlternates->id == $objPage->id) { continue; } $objAlternates->current()->loadDetails(); $label .= '<li><a href="contao/main.php?do=page&node=' . $objAlternates->id . '&ref=' . TL_REFERER_ID . '">' . $objAlternates->language . '</a></li>'; } $label .= '</ul>'; } return $label; }
public function collectItems(CollectItemsEvent $event) { $item = $event->getParentItem(); if ($item->getType() == 'page') { $table = \PageModel::getTable(); $columns = array("{$table}.pid=?"); if (!BE_USER_LOGGED_IN) { $time = time(); $columns[] = "({$table}.start='' OR {$table}.start<{$time}) AND ({$table}.stop='' OR {$table}.stop>{$time}) AND {$table}.published=1"; } $pages = \PageModel::findBy($columns, array($item->getExtra('id')), array('order' => 'sorting')); if ($pages) { $factory = $event->getFactory(); foreach ($pages as $page) { $factory->createItem('page', $page->id, $item); } } } if ($item->getType() == 'pages') { $ids = explode(',', $item->getName()); $ids = array_filter($ids); $table = \PageModel::getTable(); $columns = array('(' . implode(' OR ', array_fill(0, count($ids), "{$table}.id=?")) . ')'); $sorting = "FIELD({$table}.id, " . implode(', ', array_fill(0, count($ids), "?")) . ")"; if (!BE_USER_LOGGED_IN) { $time = time(); $columns[] = "({$table}.start='' OR {$table}.start<{$time}) AND ({$table}.stop='' OR {$table}.stop>{$time}) AND {$table}.published=1"; } $pages = \PageModel::findBy($columns, array_merge($ids, $ids), array('order' => $sorting)); if ($pages) { $factory = $event->getFactory(); foreach ($pages as $page) { $factory->createItem('page', $page->id, $item); } } } }
/** * 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); }
/** * Retreives all available domains in this installation (plus empty selection) * * @return array */ public function getDomains() { // options array $options = array('' => $GLOBALS['TL_LANG']['tl_short_urls']['noDomain']); // get the root pages and their dns settings if (version_compare(VERSION, '3.5', '>=')) { if (($objPages = \PageModel::findPublishedRootPages()) !== null) { while ($objPages->next()) { if ($objPages->dns) { $options[$objPages->id] = $objPages->dns; } } } } else { $t = \PageModel::getTable(); $arrColumns = array("{$t}.type=?"); if (!BE_USER_LOGGED_IN) { $time = time(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } $objPages = \PageModel::findBy($arrColumns, 'root'); if ($objPages !== null) { while ($objPages->next()) { if ($objPages->dns) { $options[$objPages->id] = $objPages->dns; } } } } // return the options return $options; }
/** * The ids of all pages we take care of. This is what should later be used eg. for filter data. * * @return array */ protected function findCategories() { if (null === $this->arrCategories) { if ($this->defineRoot && $this->rootPage > 0) { $objPage = \PageModel::findWithDetails($this->rootPage); } else { global $objPage; } $t = \PageModel::getTable(); $arrCategories = null; $arrUnpublished = array(); $strWhere = "{$t}.type!='error_403' AND {$t}.type!='error_404'"; if (!BE_USER_LOGGED_IN) { $time = time(); $objUnpublished = \PageModel::findBy(array("({$t}.start!='' AND {$t}.start>{$time}) OR ({$t}.stop!='' AND {$t}.stop<{$time}) OR {$t}.published=?"), array('')); $arrUnpublished = $objUnpublished->fetchEach('id'); //$strWhere .= " AND ($t.start='' OR $t.start<$time) AND ($t.stop='' OR $t.stop>$time) AND $t.published='1'"; } switch ($this->iso_category_scope) { case 'global': $arrCategories = array($objPage->rootId); $arrCategories = \Database::getInstance()->getChildRecords($objPage->rootId, 'tl_page', false, $arrCategories, $strWhere); $arrCategories = array_diff($arrCategories, $arrUnpublished); break; case 'current_and_first_child': $arrCategories = \Database::getInstance()->execute("SELECT id FROM tl_page WHERE pid={$objPage->id} AND {$strWhere}")->fetchEach('id'); $arrCategories[] = $objPage->id; break; case 'current_and_all_children': $arrCategories = array($objPage->id); $arrCategories = \Database::getInstance()->getChildRecords($objPage->id, 'tl_page', false, $arrCategories, $strWhere); $arrCategories = array_diff($arrCategories, $arrUnpublished); break; case 'parent': $arrCategories = array($objPage->pid); break; case 'product': /** @var \Isotope\Model\Product\Standard $objProduct */ $objProduct = Product_Model::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product')); if ($objProduct !== null) { $arrCategories = $objProduct->getCategories(true); } else { $arrCategories = array(0); } break; case 'article': $arrCategories = array($GLOBALS['ISO_CONFIG']['current_article']['pid'] ?: $objPage->id); break; case '': case 'current_category': $arrCategories = array($objPage->id); break; default: if (isset($GLOBALS['ISO_HOOKS']['findCategories']) && is_array($GLOBALS['ISO_HOOKS']['findCategories'])) { foreach ($GLOBALS['ISO_HOOKS']['findCategories'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrCategories = $objCallback->{$callback}[1]($this); if ($arrCategories !== false) { break; } } } break; } $this->arrCategories = empty($arrCategories) ? array(0) : $arrCategories; } return $this->arrCategories; }
/** * Adds canonical product URLs to the document * @param IsotopeProduct */ protected function addCanonicalProductUrls(IsotopeProduct $objProduct) { global $objPage; $arrPageIds = \Database::getInstance()->getChildRecords($objPage->rootId, \PageModel::getTable()); $arrPageIds[] = $objPage->rootId; // Find the categories in the current root $arrCategories = array_intersect($objProduct->getCategories(), $arrPageIds); foreach ($arrCategories as $intPage) { // Do not use the index page as canonical link if ($objPage->alias == 'index' && count($arrCategories) > 1) { continue; } // Current page is the primary one, do not generate canonical link if ($intPage == $objPage->id) { break; } if (($objJumpTo = \PageModel::findWithDetails($intPage)) !== null) { $strDomain = \Environment::get('base'); // Overwrite the domain if ($objJumpTo->dns != '') { $strDomain = ($objJumpTo->useSSL ? 'https://' : 'http://') . $objJumpTo->dns . TL_PATH . '/'; } $GLOBALS['TL_HEAD'][] = sprintf('<link rel="canonical" href="%s">', $strDomain . $objProduct->generateUrl($objJumpTo)); break; } } }