/** * Find the first published root page by its host name and language * * @param string $strHost The host name * @param mixed $varLanguage An ISO language code or an array of ISO language codes * @param array $arrOptions An optional options array * * @return static The model or null if there is no matching root page */ public static function findFirstPublishedRootByHostAndLanguage($strHost, $varLanguage, array $arrOptions = array()) { $t = static::$strTable; $objDatabase = \Database::getInstance(); $strWhereFindHostInDns = $objDatabase->findInSet('\'' . $strHost . '\'', "{$t}.dns", true); if (is_array($varLanguage)) { $arrColumns = array("{$t}.type='root' AND ({$strWhereFindHostInDns} OR {$t}.dns='')"); if (!empty($varLanguage)) { $arrColumns[] = "({$t}.language IN('" . implode("','", $varLanguage) . "') OR {$t}.fallback='1')"; } else { $arrColumns[] = "{$t}.fallback='1'"; } //@todo this needs a rework as it is equal with the parent's code if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.dns DESC" . (!empty($varLanguage) ? ", " . $objDatabase->findInSet("{$t}.language", array_reverse($varLanguage)) . " DESC" : "") . ", {$t}.sorting"; } if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findOneBy($arrColumns, array(), $arrOptions); } else { $arrColumns = array("{$t}.type='root' AND ({$strWhereFindHostInDns} OR {$t}.dns='') AND ({$t}.language=? OR {$t}.fallback='1')"); $arrValues = array($varLanguage); //@todo this needs a rework as it is equal with the parent's code if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.dns DESC, {$t}.fallback"; } if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findOneBy($arrColumns, $arrValues, $arrOptions); } }
protected function compile() { $time = \Date::floorToMinute(); $intStart = null; $intStop = null; // overwrite start from related entity, but only if selected entity period is between if ($this->objRelation !== null && $this->objRelation->limitSubmissionPeriod) { $intStart = $this->objRelation->submissionStart; $intStop = $this->objRelation->submissionStop; } if ($this->limitSubmissionPeriod) { if ($this->submissionStart != '') { $intStart = $intStart != '' && $intStart >= $this->submissionStart ? $intStart : $this->submissionStart; } if ($this->submissionStop != '') { $intStop = $intStop != '' && $intStop <= $this->submissionStop ? $intStop : $this->submissionStop; } } $blnInPeriod = false; if (($intStart == '' || $intStart <= $time) && ($intStop == '' || $time + 60 <= $intStop)) { $blnInPeriod = true; } // render submission form only within period if ($blnInPeriod) { return parent::compile(); } }
/** * Show a warning if there is no language fallback page * * @return string */ public function languageFallback() { $arrRoots = array(); $time = \Date::floorToMinute(); $objRoots = $this->Database->execute("SELECT fallback, dns FROM tl_page WHERE type='root' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY dns"); while ($objRoots->next()) { $strDns = $objRoots->dns ?: '*'; if (isset($arrRoots[$strDns]) && $arrRoots[$strDns] == 1) { continue; } $arrRoots[$strDns] = $objRoots->fallback; } $arrReturn = array(); foreach ($arrRoots as $k => $v) { if ($v != '') { continue; } if ($k == '*') { $arrReturn[] = '<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['noFallbackEmpty'] . '</p>'; } else { $arrReturn[] = '<p class="tl_error">' . sprintf($GLOBALS['TL_LANG']['ERR']['noFallbackDns'], $k) . '</p>'; } } return implode("\n", $arrReturn); }
/** * Find active user by id * * @param int $intId * @param array $arrOptions * * @return \UserModel|\UserModel[]|\Model\Collection|null */ public static function findActiveById($intId, array $arrOptions = array()) { $t = static::$strTable; $time = \Date::floorToMinute(); $arrColumns = array("({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.disable=''"); $arrColumns[] = "{$t}.id = ?"; return static::findOneBy($arrColumns, $intId, $arrOptions); }
/** * 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; }
public static function findByPublished(array $arrOptions = array()) { $t = static::$strTable; if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findBy($arrColumns, array(), $arrOptions); }
public static function findPublishedByPids(array $arrPids, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("{$t}.pid IN(" . implode(',', array_map('intval', $arrPids)) . ")"); if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findBy($arrColumns, array(), $arrOptions); }
/** * Add an image to each record * * @param array $row * @param string $label * * @return string */ public function addIcon($row, $label) { $image = 'mgroup'; $time = \Date::floorToMinute(); $disabled = $row['start'] !== '' && $row['start'] > $time || $row['stop'] !== '' && $row['stop'] < $time; if ($row['disable'] || $disabled) { $image .= '_'; } return sprintf('<div class="list_icon" style="background-image:url(\'%ssystem/themes/%s/icons/%s.svg\')" data-icon="%s.svg" data-icon-disabled="%s.svg">%s</div>', TL_ASSETS_URL, Backend::getTheme(), $image, $disabled ? $image : rtrim($image, '_'), rtrim($image, '_') . '_', $label); }
/** * Find categories by product id if the respective page is published * * @param int $intProduct * @param array $arrOptions * * @return \Model\Collection|null */ public static function findByPidForPublishedPages($intProduct, array $arrOptions = array()) { $arrOptions['eager'] = true; $arrOptions['having'] = "page_id__type!='error_403' AND page_id__type!='error_404'"; if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrOptions['having'] .= " AND (page_id__start='' OR page_id__start<'{$time}') AND (page_id__stop='' OR page_id__stop>'" . ($time + 60) . "') AND page_id__published='1'"; } return parent::findBy('pid', $intProduct, $arrOptions); }
/** * Find a published article with additional conditions. * * @param array $columns * @param array $values * @param array $options * * @return \ArticleModel|null */ private function findPublishedArticle(array $columns, array $values = array(), array $options = array()) { if (true !== BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $columns[] = "(tl_article.start='' OR tl_article.start<='{$time}')"; $columns[] = "(tl_article.stop='' OR tl_article.stop>'" . ($time + 60) . "')"; $columns[] = "tl_article.published='1'"; } return ArticleModel::findOneBy($columns, $values, $options); }
/** * Find published modal items by their ID or alias * * @param mixed $varId The numeric ID or alias name * @param array $arrOptions An optional options array * * @return static The ModalModel or null if there are no modals */ public static function findPublishedByIdOrAlias($varId, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("({$t}.id=? OR {$t}.alias=?)"); if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findBy($arrColumns, array(is_numeric($varId) ? $varId : 0, $varId), $arrOptions); }
/** * 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; }
/** * Gets the options for the query for the "findByPidForPublishedPages" method. * * @param $intProduct * @param array $arrOptions * * @return array */ public static function getFindByPidForPublishedPagesOptions($intProduct, array $arrOptions = array()) { $t = static::getTable(); $having = "page_id__type!='error_403' AND page_id__type!='error_404'"; if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $having .= " AND (page_id__start='' OR page_id__start<'{$time}') AND (page_id__stop='' OR page_id__stop>'" . ($time + 60) . "') AND page_id__published='1'"; } $arrOptions = array_merge(array('column' => array("{$t}.pid=?"), 'value' => array($intProduct), 'eager' => true, 'having' => $having, 'return' => 'Collection'), $arrOptions); return $arrOptions; }
/** * Find pages linked with modal * * @param array $arrOptions An optional options array * * @return \Model\Collection|\PageModel[]|\PageModel|null A collection of models or null if there is no matching pages */ public static function findAllPublishedLinkedWithModal(array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("{$t}.linkModal = 1 AND {$t}.modal > 0"); // Check the publication status (see #4652) if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::findBy($arrColumns, null, $arrOptions); }
/** * Add an image to each record * * @param array $row * @param string $label * @param DataContainer $dc * @param array $args * * @return string */ public function addIcon($row, $label, DataContainer $dc, $args) { $image = $row['admin'] ? 'admin' : 'user'; $time = \Date::floorToMinute(); $disabled = $row['start'] !== '' && $row['start'] > $time || $row['stop'] !== '' && $row['stop'] < $time; if ($row['disable'] || $disabled) { $image .= '_'; } $args[0] = sprintf('<div class="list_icon_new" style="background-image:url(\'%ssystem/themes/%s/images/%s.gif\')" data-icon="%s.gif" data-icon-disabled="%s.gif"> </div>', TL_ASSETS_URL, Backend::getTheme(), $image, $disabled ? $image : rtrim($image, '_'), rtrim($image, '_') . '_'); return $args; }
/** * Adds publishing conditions to Model query columns if backend user is not logged in. * * @param array $columns * @param string $table * @param bool $addStartStop * * @return array */ protected function addPublishedConditions(array $columns, $table, $addStartStop = true) { if (true !== BE_USER_LOGGED_IN) { $columns[] = "{$table}.published='1'"; if ($addStartStop) { $time = \Date::floorToMinute(); $columns[] = "({$table}.start='' OR {$table}.start<='{$time}')"; $columns[] = "({$table}.stop='' OR {$table}.stop>'" . ($time + 60) . "')"; } } return $columns; }
/** * Find active members by given member groups * * @param array $arrGroups * @param array $arrOptions * * @return \MemberModel|\MemberModel[]|\Model\Collection|null */ public static function findActiveByGroups(array $arrGroups, array $arrOptions = array()) { if (empty($arrGroups)) { return null; } $t = static::$strTable; $time = \Date::floorToMinute(); $arrColumns = array("{$t}.login='******' AND ({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.disable=''"); if (!empty(array_filter($arrGroups))) { $arrColumns[] = QueryHelper::createWhereForSerializedBlob('groups', array_filter($arrGroups)); } return static::findBy($arrColumns, null, $arrOptions); }
/** * Find all published fieldpalette elements by their parent ID and parent table * * @param integer $intPid The article ID * @param string $strParentTable The parent table name * @param string $strParentField The parent field name * @param array $arrOptions An optional options array * * @return \Model\Collection|\ContentModel|null A collection of models or null if there are no fieldpalette elements */ public static function findPublishedByPidAndTableAndField($intPid, $strParentTable, $strParentField, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("{$t}.pid=? AND {$t}.ptable=? AND {$t}.pfield=?"); if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.sorting"; } return static::findBy($arrColumns, array($intPid, $strParentTable, $strParentField), $arrOptions); }
public static function findPublishedByPidAndTable($intPid, $strParentTable, array $arrOptions = array()) { $t = static::$strTable; if ($arrOptions['fview'] == 'list') { $arrColumns = array("{$t}.pid=? AND {$t}.ptable=? AND fview='list'"); } else { $arrColumns = array("{$t}.pid=? AND {$t}.ptable=? AND fview='detail'"); } if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.invisible=''"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.sorting"; } return static::findBy($arrColumns, array($intPid, $strParentTable), $arrOptions); }
/** * Returns an array of attribute values found in the product table * * @param string $attribute * @param array $categories * @param string $newFilter * @param string $sqlWhere * * @return array */ protected function getUsedValuesForAttribute($attribute, array $categories, $newFilter = '', $sqlWhere = '') { $attributeTypes = $this->getProductTypeIdsByAttribute($attribute); $variantTypes = $this->getProductTypeIdsByAttribute($attribute, true); if (empty($attributeTypes) && empty($variantTypes)) { return array(); } $values = array(); $typeConditions = array(); $join = ''; $categoryWhere = ''; $published = ''; $time = \Date::floorToMinute(); if ('' != $sqlWhere) { $sqlWhere = " AND " . $sqlWhere; } // Apply new/old product filter if ($newFilter == self::FILTER_NEW) { $sqlWhere .= " AND p1.dateAdded>=" . Isotope::getConfig()->getNewProductLimit(); } elseif ($newFilter == self::FILTER_OLD) { $sqlWhere .= " AND p1.dateAdded<" . Isotope::getConfig()->getNewProductLimit(); } if (BE_USER_LOGGED_IN !== true) { $published = "\n AND p1.published='1'\n AND (p1.start='' OR p1.start<'{$time}')\n AND (p1.stop='' OR p1.stop>'" . ($time + 60) . "')\n "; } if (!empty($attributeTypes)) { $typeConditions[] = "p1.type IN (" . implode(',', $attributeTypes) . ")"; } if (!empty($variantTypes)) { $typeConditions[] = "p2.type IN (" . implode(',', $variantTypes) . ")"; $join = "LEFT OUTER JOIN tl_iso_product p2 ON p1.pid=p2.id"; $categoryWhere = "OR p1.pid IN (\n SELECT pid\n FROM tl_iso_product_category\n WHERE page_id IN (" . implode(',', $categories) . ")\n )"; if (BE_USER_LOGGED_IN !== true) { $published .= " AND (\n p1.pid=0 OR (\n p2.published='1'\n AND (p2.start='' OR p2.start<'{$time}')\n AND (p2.stop='' OR p2.stop>'" . ($time + 60) . "')\n )\n )"; } } $result = \Database::getInstance()->execute("\n SELECT DISTINCT p1.{$attribute} AS options\n FROM tl_iso_product p1\n {$join}\n WHERE\n p1.language=''\n AND p1.{$attribute}!=''\n " . $published . "\n AND (\n p1.id IN (\n SELECT pid\n FROM tl_iso_product_category\n WHERE page_id IN (" . implode(',', $categories) . ")\n )\n {$categoryWhere}\n )\n AND (\n " . implode(' OR ', $typeConditions) . "\n )\n {$sqlWhere}\n "); while ($result->next()) { if ($this->isCsv($attribute)) { $values = array_merge($values, explode(',', $result->options)); } else { $values = array_merge($values, deserialize($result->options, true)); } } return $values; }
/** * Find all published content elements by their parent ID and parent table and content types with limit and offset parameter * * @param integer $intPid The article ID * @param string $strParentTable The parent table name * @param array $arrTypes Content types as array * @param integer $intLimit Limit items * @param integer $intOffset Offset for limiting items * @param array $arrOptions An optional options array * * @return \Model\Collection|\ContentModel|null A collection of models or null if there are no content elements */ public static function findPublishedByPidAndTypes($intPid, $arrTypes = array(), $intLimit = 0, $intOffset = 0, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("{$t}.pid=? AND {$t}.ptable=?"); if (is_array($arrTypes) && !empty($arrTypes)) { $arrColumns[] = "{$t}.type IN('" . implode("','", $arrTypes) . "')"; } if (!BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.invisible=''"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.sorting"; } $arrOptions['limit'] = $intLimit; $arrOptions['offset'] = $intOffset; return static::findBy($arrColumns, array($intPid, 'tl_listgrid'), $arrOptions); }
/** * Find published news items by their parent ID * * @param array $arrPids An array of news archive IDs * @param boolean $blnFeatured If true, return only featured news, if false, return only unfeatured news * @param integer $intLimit An optional limit * @param integer $intOffset An optional offset * @param array $arrOptions An optional options array * * @return \Model\Collection|\NewsModel[]|\NewsModel|null A collection of models or null if there are no news */ public static function findPublishedByPids($arrPids, $blnFeatured = null, $intLimit = 0, $intOffset = 0, array $arrOptions = array()) { if (!is_array($arrPids) || empty($arrPids)) { return null; } $t = static::$strTable; $arrColumns = array("{$t}.pid IN(" . implode(',', array_map('intval', $arrPids)) . ")"); // Add only items with podcasts $arrColumns[] = "{$t}.addPodcast='1'"; // Never return unpublished elements in the back end, so they don't end up in the RSS feed if (!BE_USER_LOGGED_IN || TL_MODE == 'BE') { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "{$t}.date DESC"; } $arrOptions['limit'] = $intLimit; $arrOptions['offset'] = $intOffset; return static::findBy($arrColumns, null, $arrOptions); }
/** * Prepares the default DataCollector instance based on the configuration. * * @param \Database\Result $config * @param array|null $ids * * @return DataCollector */ protected function prepareDefaultDataCollector($config, $ids = null) { $dataCollector = new DataCollector($config->master); // Limit the fields if ('fields' === $config->export) { $limitFields = array(); foreach ($config->fields as $fieldsConfig) { $limitFields[] = $fieldsConfig['field']; } $dataCollector->setFieldIds($limitFields); } if (null !== $ids) { $dataCollector->setLeadDataIds($ids); } $this->newLastRun = \Date::floorToMinute(); if ($config->skipLastRun) { $dataCollector->setFrom($config->lastRun); $dataCollector->setTo($this->newLastRun - 1); } return $dataCollector; }
/** * Get all searchable pages and return them as array * * @param integer $pid * @param string $domain * @param boolean $blnIsSitemap * @param string $strLanguage * * @return array */ public static function findSearchablePages($pid = 0, $domain = '', $blnIsSitemap = false, $strLanguage = '') { $time = \Date::floorToMinute(); $objDatabase = \Database::getInstance(); // Get published pages $objPages = $objDatabase->prepare("SELECT * FROM tl_page WHERE pid=? AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY sorting")->execute($pid); if ($objPages->numRows < 1) { return array(); } // Fallback domain if ($domain == '') { $domain = \Environment::get('base'); } $arrPages = array(); // Recursively walk through all subpages while ($objPages->next()) { // Set domain if ($objPages->type == 'root') { if ($objPages->dns != '') { $domain = ($objPages->useSSL ? 'https://' : 'http://') . $objPages->dns . TL_PATH . '/'; } else { $domain = \Environment::get('base'); } $strLanguage = $objPages->language; } elseif ($objPages->type == 'regular') { // Searchable and not protected if ((!$objPages->noSearch || $blnIsSitemap) && (!$objPages->protected || \Config::get('indexProtected') && (!$blnIsSitemap || $objPages->sitemap == 'map_always')) && (!$blnIsSitemap || $objPages->sitemap != 'map_never')) { // Published if ($objPages->published && ($objPages->start == '' || $objPages->start <= $time) && ($objPages->stop == '' || $objPages->stop > $time + 60)) { $arrPages[] = $domain . static::generateFrontendUrl($objPages->row(), null, $strLanguage); // Get articles with teaser $objArticle = $objDatabase->prepare("SELECT * FROM tl_article WHERE pid=? AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' AND showTeaser='1' ORDER BY sorting")->execute($objPages->id); while ($objArticle->next()) { $arrPages[] = $domain . static::generateFrontendUrl($objPages->row(), '/articles/' . ($objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id), $strLanguage); } } } } // Get subpages if ((!$objPages->protected || \Config::get('indexProtected')) && ($arrSubpages = static::findSearchablePages($objPages->id, $domain, $blnIsSitemap, $strLanguage)) != false) { $arrPages = array_merge($arrPages, $arrSubpages); } } return $arrPages; }
/** * Generate the module */ protected function compile() { // Create the date object try { if (\Input::get('month')) { $this->Date = new \Date(\Input::get('month'), 'Ym'); } elseif (\Input::get('day')) { $this->Date = new \Date(\Input::get('day'), 'Ymd'); } else { $this->Date = new \Date(); } } catch (\OutOfBoundsException $e) { /** @var \PageModel $objPage */ global $objPage; /** @var \PageError404 $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id); } $time = \Date::floorToMinute(); // Find the boundaries $objMinMax = $this->Database->query("SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN(" . implode(',', array_map('intval', $this->cal_calendar)) . ")" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'" : "")); /** @var \FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->cal_ctemplate ? $this->cal_ctemplate : 'cal_default'); // Store year and month $intYear = date('Y', $this->Date->tstamp); $intMonth = date('m', $this->Date->tstamp); $objTemplate->intYear = $intYear; $objTemplate->intMonth = $intMonth; // Previous month $prevMonth = $intMonth == 1 ? 12 : $intMonth - 1; $prevYear = $intMonth == 1 ? $intYear - 1 : $intYear; $lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear; $intPrevYm = intval($prevYear . str_pad($prevMonth, 2, 0, STR_PAD_LEFT)); // Only generate a link if there are events (see #4160) if ($objMinMax->dateFrom !== null && $intPrevYm >= date('Ym', $objMinMax->dateFrom) || $intPrevYm >= date('Ym')) { $objTemplate->prevHref = $this->strUrl . (\Config::get('disableAlias') ? '?id=' . \Input::get('id') . '&' : '?') . 'month=' . $intPrevYm; $objTemplate->prevTitle = specialchars($lblPrevious); $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious; $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous']; } // Current month $objTemplate->current = $GLOBALS['TL_LANG']['MONTHS'][date('m', $this->Date->tstamp) - 1] . ' ' . date('Y', $this->Date->tstamp); // Next month $nextMonth = $intMonth == 12 ? 1 : $intMonth + 1; $nextYear = $intMonth == 12 ? $intYear + 1 : $intYear; $lblNext = $GLOBALS['TL_LANG']['MONTHS'][$nextMonth - 1] . ' ' . $nextYear; $intNextYm = $nextYear . str_pad($nextMonth, 2, 0, STR_PAD_LEFT); // Only generate a link if there are events (see #4160) if ($objMinMax->dateTo !== null && $intNextYm <= date('Ym', max($objMinMax->dateTo, $objMinMax->repeatUntil)) || $intNextYm <= date('Ym')) { $objTemplate->nextHref = $this->strUrl . (\Config::get('disableAlias') ? '?id=' . \Input::get('id') . '&' : '?') . 'month=' . $intNextYm; $objTemplate->nextTitle = specialchars($lblNext); $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next']; $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next']; } // Set the week start day if (!$this->cal_startDay) { $this->cal_startDay = 0; } $objTemplate->days = $this->compileDays(); $objTemplate->weeks = $this->compileWeeks(); $objTemplate->substr = $GLOBALS['TL_LANG']['MSC']['dayShortLength']; $this->Template->calendar = $objTemplate->parse(); }
/** * Add an image to each page in the tree * * @param array $row * @param string $label * * @return string */ public function addIcon($row, $label) { $time = \Date::floorToMinute(); $published = $row['published'] && ($row['start'] == '' || $row['start'] <= $time) && ($row['stop'] == '' || $row['stop'] > $time + 60); return '<a href="contao/main.php?do=feRedirect&page=' . $row['pid'] . '&article=' . ($row['alias'] ?: $row['id']) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['view']) . '" target="_blank">' . Image::getHtml('articles' . ($published ? '' : '_') . '.gif', '', 'data-icon="articles.gif" data-icon-disabled="articles_.gif"') . '</a> ' . $label; }
/** * Add an image to each page in the tree * * @param array $row * @param string $label * * @return string */ public function addIcon($row, $label) { $image = 'articles'; $time = \Date::floorToMinute(); $unpublished = $row['start'] != '' && $row['start'] > $time || $row['stop'] != '' && $row['stop'] < $time; if (!$row['published'] || $unpublished) { $image .= '_'; } return '<a href="contao/main.php?do=feRedirect&page=' . $row['pid'] . '&article=' . ($row['alias'] != '' && !Config::get('disableAlias') ? $row['alias'] : $row['id']) . '" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['view']) . '" target="_blank">' . Image::getHtml($image . '.gif', '', 'data-icon="' . ($unpublished ? $image : rtrim($image, '_')) . '.gif" data-icon-disabled="' . rtrim($image, '_') . '_.gif"') . '</a> ' . $label; }
/** * Count all published news items of a certain period of time by their parent ID * * @param integer $intFrom The start date as Unix timestamp * @param integer $intTo The end date as Unix timestamp * @param array $arrPids An array of news archive IDs * @param array $arrOptions An optional options array * * @return integer The number of news items */ public static function countPublishedFromToByPids($intFrom, $intTo, $arrPids, array $arrOptions = array()) { if (!is_array($arrPids) || empty($arrPids)) { return null; } $t = static::$strTable; $arrColumns = array("{$t}.date>=? AND {$t}.date<=? AND {$t}.pid IN(" . implode(',', array_map('intval', $arrPids)) . ")"); if (isset($arrOptions['ignoreFePreview']) || !BE_USER_LOGGED_IN) { $time = \Date::floorToMinute(); $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'"; } return static::countBy($arrColumns, array($intFrom, $intTo), $arrOptions); }
protected function isVisible(&$objChild) { $time = \Date::floorToMinute(); $currentLang = array('', $GLOBALS['TL_LANGUAGE']); if (!in_array($objChild->language, $currentLang)) { return false; } $arrPages = deserialize($objChild->pages); /** * Filter out pages * (exclude == display module not on this page) * (include == display module only on this page) */ if (is_array($arrPages) && count($arrPages) > 0) { // add nested pages to the filter if ($objChild->addPageDepth) { $arrPages = array_merge($arrPages, \Database::getInstance()->getChildRecords($arrPages, 'tl_page')); } $check = $objChild->addVisibility == 'exclude' ? true : false; if (in_array($this->objPage->id, $arrPages) == $check) { return false; } } // filter out modules by keywords if (strlen($objChild->keywords) > 0) { $arrKeywords = preg_split('/\\s*,\\s*/', trim($objChild->keywords), -1, PREG_SPLIT_NO_EMPTY); if (is_array($arrKeywords) && !empty($arrKeywords)) { foreach ($arrKeywords as $keyword) { $negate = substr($keyword, 0, 1) == '!'; $keyword = $negate ? substr($keyword, 1, strlen($keyword)) : $keyword; if ($this->Input->get($keyword) != $negate) { return false; } } } } // filter out by feature if ($objChild->feature) { $start = $objChild->feature_start; $stop = $objChild->feature_stop; // check if in time $blnFeatureActive = ($start == '' || $start <= $time) && ($stop == '' || $stop > $time + 60); $blnFeatureCookie = $objChild->feature_count > 0; if ($blnFeatureActive && $blnFeatureCookie) { $cookieCount = \Input::cookie($objChild->feature_cookie_name); $displayCount = $cookieCount == null ? 0 : intval($cookieCount); if ($cookieCount === null && session_status() == PHP_SESSION_DISABLED) { $blnFeatureActive = true; } else { if ($displayCount < $objChild->feature_count) { setcookie($objChild->feature_cookie_name, ++$displayCount, $time + $objChild->feature_cookie_expire, '/'); $blnFeatureActive = true; } else { $blnFeatureActive = false; } } } $objChild->featureActive = $blnFeatureActive; return $blnFeatureActive; } return true; }
/** * Get the details of a page including inherited parameters * * @return static The page model */ public function loadDetails() { // Loaded already if ($this->blnDetailsLoaded) { return $this; } // Set some default values $this->protected = (bool) $this->protected; $this->groups = $this->protected ? deserialize($this->groups) : false; $this->layout = $this->includeLayout ? $this->layout : false; $this->mobileLayout = $this->includeLayout ? $this->mobileLayout : false; $this->cache = $this->includeCache ? $this->cache : false; $pid = $this->pid; $type = $this->type; $alias = $this->alias; $name = $this->title; $title = $this->pageTitle ?: $this->title; $folderUrl = ''; $palias = ''; $pname = ''; $ptitle = ''; $trail = array($this->id, $pid); // Inherit the settings if ($this->type == 'root') { $objParentPage = $this; // see #4610 } else { // Load all parent pages $objParentPage = \PageModel::findParentsById($pid); if ($objParentPage !== null) { while ($pid > 0 && $type != 'root' && $objParentPage->next()) { $pid = $objParentPage->pid; $type = $objParentPage->type; // Parent title if ($ptitle == '') { $palias = $objParentPage->alias; $pname = $objParentPage->title; $ptitle = $objParentPage->pageTitle ?: $objParentPage->title; } // Page title if ($type != 'root') { $alias = $objParentPage->alias; $name = $objParentPage->title; $title = $objParentPage->pageTitle ?: $objParentPage->title; $folderUrl = basename($alias) . '/' . $folderUrl; $trail[] = $objParentPage->pid; } // Cache if ($objParentPage->includeCache && $this->cache === false) { $this->cache = $objParentPage->cache; } // Layout if ($objParentPage->includeLayout) { if ($this->layout === false) { $this->layout = $objParentPage->layout; } if ($this->mobileLayout === false) { $this->mobileLayout = $objParentPage->mobileLayout; } } // Protection if ($objParentPage->protected && $this->protected === false) { $this->protected = true; $this->groups = deserialize($objParentPage->groups); } } } // Set the titles $this->mainAlias = $alias; $this->mainTitle = $name; $this->mainPageTitle = $title; $this->parentAlias = $palias; $this->parentTitle = $pname; $this->parentPageTitle = $ptitle; $this->folderUrl = $folderUrl; } // Set the root ID and title if ($objParentPage !== null && $objParentPage->type == 'root') { $this->rootId = $objParentPage->id; $this->rootAlias = $objParentPage->alias; $this->rootTitle = $objParentPage->title; $this->rootPageTitle = $objParentPage->pageTitle ?: $objParentPage->title; $this->domain = $objParentPage->dns; $this->rootLanguage = $objParentPage->language; $this->language = $objParentPage->language; $this->staticFiles = $objParentPage->staticFiles; $this->staticPlugins = $objParentPage->staticPlugins; $this->dateFormat = $objParentPage->dateFormat; $this->timeFormat = $objParentPage->timeFormat; $this->datimFormat = $objParentPage->datimFormat; $this->adminEmail = $objParentPage->adminEmail; // Store whether the root page has been published $time = \Date::floorToMinute(); $this->rootIsPublic = $objParentPage->published && ($objParentPage->start == '' || $objParentPage->start <= $time) && ($objParentPage->stop == '' || $objParentPage->stop > $time + 60); $this->rootIsFallback = true; $this->rootUseSSL = $objParentPage->useSSL; $this->rootFallbackLanguage = $objParentPage->language; // Store the fallback language (see #6874) if (!$objParentPage->fallback) { $this->rootIsFallback = false; $this->rootFallbackLanguage = null; $objFallback = static::findPublishedFallbackByHostname($objParentPage->dns); if ($objFallback !== null) { $this->rootFallbackLanguage = $objFallback->language; } } } elseif (TL_MODE == 'FE' && $this->type != 'root') { header('HTTP/1.1 404 Not Found'); \System::log('Page ID "' . $this->id . '" does not belong to a root page', __METHOD__, TL_ERROR); die_nicely('be_no_root', 'No root page found'); } $this->trail = array_reverse($trail); // Do not cache protected pages if ($this->protected) { $this->cache = 0; } // Use the global date format if none is set (see #6104) if ($this->dateFormat == '') { $this->dateFormat = \Config::get('dateFormat'); } if ($this->timeFormat == '') { $this->timeFormat = \Config::get('timeFormat'); } if ($this->datimFormat == '') { $this->datimFormat = \Config::get('datimFormat'); } // Prevent saving (see #6506 and #7199) $this->preventSaving(); $this->blnDetailsLoaded = true; return $this; }