floorToMinute() public static method

Round a UNIX timestamp to the full minute
public static floorToMinute ( integer $intTime = null ) : integer
$intTime integer The timestamp
return integer The rounded timestamp
Exemplo n.º 1
0
 /**
  * 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) {
         throw new PageNotFoundException('Page not found');
     }
     $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);
     // 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)) {
         $objTemplate->prevHref = $this->strUrl . '?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))) {
         $objTemplate->nextHref = $this->strUrl . '?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();
 }
 public function scopeActive(Builder $query)
 {
     $time = Date::floorToMinute();
     return $query->where('disable', '')->where(function (Builder $query) use($time) {
         return $query->where('start', '')->orWhere('start', '<=', $time);
     })->where(function (Builder $query) use($time) {
         return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
     });
 }
 public function scopePublished(Builder $query, $ignoreFePreview = false)
 {
     // mimic behavior of contao models who never apply the pusblished filter when Backenduser is logged in
     if ($ignoreFePreview || BE_USER_LOGGED_IN) {
         return $query;
     }
     $time = Date::floorToMinute();
     return $query->where('published', 1)->where(function (Builder $query) use($time) {
         return $query->where('start', '')->orWhere('start', '<=', $time);
     })->where(function (Builder $query) use($time) {
         return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
     });
 }
 /**
  * Run the test
  *
  * @param array  $data
  * @param string $table
  *
  * @throws ErrorException
  * @throws WarningException
  */
 public function run(array $data, $table)
 {
     switch ($table) {
         case 'tl_calendar_events':
         case 'tl_news':
             $this->check($data['teaser']);
             break;
         case 'tl_page':
             $time = Date::floorToMinute();
             if ($data['type'] === 'regular' && $data['robots'] !== 'noindex,nofollow' && $data['published'] && (!$data['start'] || $data['start'] <= $time) && (!$data['stop'] || $data['stop'] > $time)) {
                 $this->check($data['description']);
             }
             break;
     }
 }
Exemplo n.º 5
0
 /**
  * Set all user properties from a database record
  */
 protected function setUserFromDb()
 {
     $this->intId = $this->id;
     // Unserialize values
     foreach ($this->arrData as $k => $v) {
         if (!is_numeric($v)) {
             $this->{$k} = deserialize($v);
         }
     }
     $GLOBALS['TL_USERNAME'] = $this->username;
     \System::getContainer()->get('request_stack')->getCurrentRequest()->setLocale($this->language);
     \System::getContainer()->get('translator')->setLocale($this->language);
     // Deprecated since Contao 4.0, to be removed in Contao 5.0
     $GLOBALS['TL_LANGUAGE'] = str_replace('_', '-', $this->language);
     \Config::set('showHelp', $this->showHelp);
     \Config::set('useRTE', $this->useRTE);
     \Config::set('useCE', $this->useCE);
     \Config::set('thumbnails', $this->thumbnails);
     \Config::set('backendTheme', $this->backendTheme);
     // Inherit permissions
     $always = array('alexf');
     $depends = array('modules', 'themes', 'pagemounts', 'alpty', 'filemounts', 'fop', 'forms', 'formp', 'imageSizes');
     // HOOK: Take custom permissions
     if (!empty($GLOBALS['TL_PERMISSIONS']) && is_array($GLOBALS['TL_PERMISSIONS'])) {
         $depends = array_merge($depends, $GLOBALS['TL_PERMISSIONS']);
     }
     // Overwrite user permissions if only group permissions shall be inherited
     if ($this->inherit == 'group') {
         foreach ($depends as $field) {
             $this->{$field} = array();
         }
     }
     // Merge permissions
     $inherit = in_array($this->inherit, array('group', 'extend')) ? array_merge($always, $depends) : $always;
     $time = \Date::floorToMinute();
     foreach ((array) $this->groups as $id) {
         $objGroup = $this->Database->prepare("SELECT * FROM tl_user_group WHERE id=? AND disable!='1' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "')")->limit(1)->execute($id);
         if ($objGroup->numRows > 0) {
             foreach ($inherit as $field) {
                 $value = deserialize($objGroup->{$field}, true);
                 // The new page/file picker can return integers instead of arrays, so use empty() instead of is_array() and deserialize(true) here
                 if (!empty($value)) {
                     $this->{$field} = array_merge(is_array($this->{$field}) ? $this->{$field} : ($this->{$field} != '' ? array($this->{$field}) : array()), $value);
                     $this->{$field} = array_unique($this->{$field});
                 }
             }
         }
     }
     // Make sure pagemounts and filemounts are set!
     if (!is_array($this->pagemounts)) {
         $this->pagemounts = array();
     } else {
         $this->pagemounts = array_filter($this->pagemounts);
     }
     if (!is_array($this->filemounts)) {
         $this->filemounts = array();
     } else {
         $this->filemounts = array_filter($this->filemounts);
     }
     // Store the numeric file mounts
     $this->arrFilemountIds = $this->filemounts;
     // Convert the file mounts into paths
     if (!$this->isAdmin && !empty($this->filemounts)) {
         $objFiles = \FilesModel::findMultipleByUuids($this->filemounts);
         if ($objFiles !== null) {
             $this->filemounts = $objFiles->fetchEach('path');
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Generate the Google XML sitemaps
  *
  * @param integer $intId The root page ID
  */
 public function generateSitemap($intId = 0)
 {
     $time = \Date::floorToMinute();
     $objDatabase = \Database::getInstance();
     $this->purgeXmlFiles();
     // Only root pages should have sitemap names
     $objDatabase->execute("UPDATE tl_page SET createSitemap='', sitemapName='' WHERE type!='root'");
     // Get a particular root page
     if ($intId > 0) {
         do {
             $objRoot = $objDatabase->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($intId);
             if ($objRoot->numRows < 1) {
                 break;
             }
             $intId = $objRoot->pid;
         } while ($objRoot->type != 'root' && $intId > 0);
         // Make sure the page is published
         if (!$objRoot->published || $objRoot->start != '' && $objRoot->start > $time || $objRoot->stop != '' && $objRoot->stop <= $time + 60) {
             return;
         }
         // Check the sitemap name
         if (!$objRoot->createSitemap || !$objRoot->sitemapName) {
             return;
         }
         $objRoot->reset();
     } else {
         $objRoot = $objDatabase->execute("SELECT id, language, sitemapName FROM tl_page WHERE type='root' AND createSitemap='1' AND sitemapName!='' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'");
     }
     // Return if there are no pages
     if ($objRoot->numRows < 1) {
         return;
     }
     // Create the XML file
     while ($objRoot->next()) {
         $objFile = new \File('web/share/' . $objRoot->sitemapName . '.xml');
         $objFile->truncate();
         $objFile->append('<?xml version="1.0" encoding="UTF-8"?>');
         $objFile->append('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">');
         // Find the searchable pages
         $arrPages = \Backend::findSearchablePages($objRoot->id, '', true);
         // HOOK: take additional pages
         if (isset($GLOBALS['TL_HOOKS']['getSearchablePages']) && is_array($GLOBALS['TL_HOOKS']['getSearchablePages'])) {
             foreach ($GLOBALS['TL_HOOKS']['getSearchablePages'] as $callback) {
                 $this->import($callback[0]);
                 $arrPages = $this->{$callback[0]}->{$callback[1]}($arrPages, $objRoot->id, true, $objRoot->language);
             }
         }
         // Add pages
         foreach ($arrPages as $strUrl) {
             $strUrl = rawurlencode($strUrl);
             $strUrl = str_replace(array('%2F', '%3F', '%3D', '%26', '%3A//'), array('/', '?', '=', '&', '://'), $strUrl);
             $strUrl = ampersand($strUrl, true);
             $objFile->append('  <url><loc>' . $strUrl . '</loc></url>');
         }
         $objFile->append('</urlset>');
         $objFile->close();
         // Add a log entry
         $this->log('Generated sitemap "' . $objRoot->sitemapName . '.xml"', __METHOD__, TL_CRON);
     }
 }
Exemplo n.º 7
0
 /**
  * Get the details of a page including inherited parameters
  *
  * @return PageModel The page model
  *
  * @throws NoRootPageFoundException If no root page is found
  */
 public function loadDetails()
 {
     // Loaded already
     if ($this->blnDetailsLoaded) {
         return $this;
     }
     // Set some default values
     $this->protected = (bool) $this->protected;
     $this->groups = $this->protected ? \StringUtil::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 = \StringUtil::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') {
         \System::log('Page ID "' . $this->id . '" does not belong to a root page', __METHOD__, TL_ERROR);
         throw new NoRootPageFoundException('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;
 }
Exemplo n.º 8
0
 /**
  * Generate the dayil menu
  */
 protected function compileDailyMenu()
 {
     $arrData = array();
     $time = \Date::floorToMinute();
     // Get the dates
     $objDates = $this->Database->query("SELECT FROM_UNIXTIME(date, '%Y%m%d') AS day, COUNT(*) AS count FROM tl_news WHERE pid IN(" . implode(',', array_map('intval', $this->news_archives)) . ")" . (!BE_USER_LOGGED_IN || TL_MODE == 'BE' ? " AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'" : "") . " GROUP BY day ORDER BY day DESC");
     while ($objDates->next()) {
         $arrData[$objDates->day] = $objDates->count;
     }
     // Sort the data
     krsort($arrData);
     // Create the date object
     try {
         $this->Date = \Input::get('day') ? new \Date(\Input::get('day'), 'Ymd') : new \Date();
     } catch (\OutOfBoundsException $e) {
         throw new PageNotFoundException('Page not found');
     }
     $intYear = date('Y', $this->Date->tstamp);
     $intMonth = date('m', $this->Date->tstamp);
     $this->Template->intYear = $intYear;
     $this->Template->intMonth = $intMonth;
     // Previous month
     $prevMonth = $intMonth == 1 ? 12 : $intMonth - 1;
     $prevYear = $intMonth == 1 ? $intYear - 1 : $intYear;
     $lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear;
     $this->Template->prevHref = $this->strUrl . '?day=' . $prevYear . (strlen($prevMonth) < 2 ? '0' : '') . $prevMonth . '01';
     $this->Template->prevTitle = specialchars($lblPrevious);
     $this->Template->prevLink = $GLOBALS['TL_LANG']['MSC']['news_previous'] . ' ' . $lblPrevious;
     $this->Template->prevLabel = $GLOBALS['TL_LANG']['MSC']['news_previous'];
     // Current month
     $this->Template->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;
     $this->Template->nextHref = $this->strUrl . '?day=' . $nextYear . (strlen($nextMonth) < 2 ? '0' : '') . $nextMonth . '01';
     $this->Template->nextTitle = specialchars($lblNext);
     $this->Template->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['news_next'];
     $this->Template->nextLabel = $GLOBALS['TL_LANG']['MSC']['news_next'];
     // Set week start day
     if (!$this->news_startDay) {
         $this->news_startDay = 0;
     }
     $this->Template->daily = true;
     $this->Template->days = $this->compileDays();
     $this->Template->weeks = $this->compileWeeks($arrData);
     $this->Template->showQuantity = $this->news_showQuantity != '' ? true : false;
 }
Exemplo n.º 9
0
 /**
  * Find ten matching usernames and return them as JSON
  */
 protected function getDatalistOptions()
 {
     if (!$this->User->isAdmin) {
         header('HTTP/1.1 400 Bad Request');
         die('You must be an administrator to use the script');
     }
     $arrUsers = array();
     $time = \Date::floorToMinute();
     // Get the active front end users
     $objUsers = $this->Database->prepare("SELECT username FROM tl_member WHERE username LIKE ? AND login='******' AND disable!='1' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') ORDER BY username")->limit(10)->execute(str_replace('%', '', \Input::post('value')) . '%');
     if ($objUsers->numRows) {
         $arrUsers = $objUsers->fetchEach('username');
     }
     header('Content-type: application/json');
     die(json_encode($arrUsers));
 }
Exemplo n.º 10
0
 /**
  * Add newsletters 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 channels
     $objNewsletter = \NewsletterChannelModel::findAll();
     // Walk through each channel
     if ($objNewsletter !== null) {
         while ($objNewsletter->next()) {
             if (!$objNewsletter->jumpTo) {
                 continue;
             }
             // Skip channels outside the root nodes
             if (!empty($arrRoot) && !in_array($objNewsletter->jumpTo, $arrRoot)) {
                 continue;
             }
             // Get the URL of the jumpTo page
             if (!isset($arrProcessed[$objNewsletter->jumpTo])) {
                 $objParent = \PageModel::findWithDetails($objNewsletter->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;
                 }
                 // Set the domain (see #6421)
                 $domain = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . \Environment::get('path') . '/';
                 // Generate the URL
                 $arrProcessed[$objNewsletter->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), \Config::get('useAutoItem') ? '/%s' : '/items/%s', $objParent->language);
             }
             $strUrl = $arrProcessed[$objNewsletter->jumpTo];
             // Get the items
             $objItem = \NewsletterModel::findSentByPid($objNewsletter->id);
             if ($objItem !== null) {
                 while ($objItem->next()) {
                     $arrPages[] = sprintf($strUrl, $objItem->alias ?: $objItem->id);
                 }
             }
         }
     }
     return $arrPages;
 }
Exemplo n.º 11
0
 /**
  * Check the account status and return true if it is active
  *
  * @return boolean True if the account is active
  */
 protected function checkAccountStatus()
 {
     $time = time();
     // Check whether the account is locked
     if ($this->locked + \Config::get('lockPeriod') > $time) {
         \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['accountLocked'], ceil(($this->locked + \Config::get('lockPeriod') - $time) / 60)));
         return false;
     } elseif ($this->disable) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         $this->log('The account has been disabled', __METHOD__, TL_ACCESS);
         return false;
     } elseif ($this instanceof FrontendUser && !$this->login) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
         $this->log('User "' . $this->username . '" is not allowed to log in', __METHOD__, TL_ACCESS);
         return false;
     } elseif ($this->start != '' || $this->stop != '') {
         $time = \Date::floorToMinute($time);
         if ($this->start != '' && $this->start > $time) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
             $this->log('The account was not active yet (activation date: ' . \Date::parse(\Config::get('dateFormat'), $this->start) . ')', __METHOD__, TL_ACCESS);
             return false;
         }
         if ($this->stop != '' && $this->stop <= $time + 60) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['invalidLogin']);
             $this->log('The account was not active anymore (deactivation date: ' . \Date::parse(\Config::get('dateFormat'), $this->stop) . ')', __METHOD__, TL_ACCESS);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 12
0
 /**
  * @param array  $columns
  * @param string $table
  */
 private function addPublishingConditions(array &$columns, $table)
 {
     if ('BE' !== TL_MODE && true !== BE_USER_LOGGED_IN) {
         $start = Date::floorToMinute();
         $stop = $start + 60;
         $columns[] = "{$table}.published='1'";
         $columns[] = "({$table}.start='' OR {$table}.start<{$start})";
         $columns[] = "({$table}.stop='' OR {$table}.stop>{$stop})";
     }
 }
Exemplo n.º 13
0
 /**
  * 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 . \Environment::get('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 ?: $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;
 }
Exemplo n.º 14
0
 /**
  * @param $arrPids
  * @param int $intLimit
  * @param $tablename
  * @return \Database\Result|null|object
  */
 public function findPublishedByPids($arrPids, $intLimit = 0, $tablename)
 {
     if (!is_array($arrPids) || empty($arrPids)) {
         return null;
     }
     if (!$tablename || $tablename == 'no-value') {
         return null;
     }
     $sql = 'SELECT * FROM ' . $tablename . ' WHERE ';
     $sql .= '' . $tablename . '.pid IN(' . implode(',', array_map('intval', $arrPids)) . ') ';
     if (!BE_USER_LOGGED_IN || TL_MODE == 'BE') {
         $time = Date::floorToMinute();
         $sql .= 'AND (' . $tablename . '.start="" OR ' . $tablename . '.start <= ' . $time . ') AND (' . $tablename . '.stop="" OR ' . $tablename . '.stop > ' . ($time + 60) . ') AND ' . $tablename . '.published = "1" ';
     }
     $sql .= 'ORDER BY ' . $tablename . '.date DESC ';
     if ($intLimit > 0) {
         $sql .= 'LIMIT ' . $intLimit . '';
     }
     $findBy = $this->Database->prepare($sql)->execute();
     return $findBy;
 }