setGet() публичный статический Метод

Set a $_GET variable
public static setGet ( string $strKey, mixed $varValue, boolean $blnAddUnused = false )
$strKey string The variable name
$varValue mixed The variable value
$blnAddUnused boolean If true, the value usage will be checked
Пример #1
0
 /**
  * @param $intId
  * @param $blnVisible
  * @param DataContainer|null $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     // Check the field access
     if (!$this->User->hasAccess('tl_api_client::disable', 'alexf')) {
         throw new AccessDeniedException('Not enough permissions to activate/deactivate member ID ' . $intId . '.');
     }
     $objVersions = new Versions('tl_api_client', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_api_client']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_api_client']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     $time = time();
     // Update the database
     $this->Database->prepare("UPDATE tl_api_client SET tstamp={$time}, disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_api_client.id=' . $intId . '" has been created' . $this->getParentEntries('tl_api_client', $intId), __METHOD__, TL_GENERAL);
 }
Пример #2
0
 /**
  * Display a wildcard in the back end
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['eventreader'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     // Set the item from the auto_item parameter
     if (!isset($_GET['events']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) {
         \Input::setGet('events', \Input::get('auto_item'));
     }
     // Do not index or cache the page if no event has been specified
     if (!\Input::get('events')) {
         /** @var PageModel $objPage */
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         return '';
     }
     $this->cal_calendar = $this->sortOutProtected(\StringUtil::deserialize($this->cal_calendar));
     // Do not index or cache the page if there are no calendars
     if (!is_array($this->cal_calendar) || empty($this->cal_calendar)) {
         /** @var PageModel $objPage */
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         return '';
     }
     return parent::generate();
 }
Пример #3
0
 /**
  *
  */
 public function generate()
 {
     // backend view
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . $this->name . ' ###';
         $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     $this->import('FrontendUser', 'User');
     // set fe view id
     $this->feViewID = md5($this->id);
     // change template
     if (TL_MODE == 'FE' && $this->fm_addMap) {
         $this->strTemplate = 'mod_fmodule_map';
     }
     //auto_page Attribute
     if (!isset($_GET['item']) && Config::get('useAutoItem') && isset($_GET['auto_item'])) {
         Input::setGet('item', Input::get('auto_item'));
     }
     return parent::generate();
 }
Пример #4
0
 /**
  * Return a pagination menu to browse results
  *
  * @return string
  */
 protected function paginationMenu()
 {
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     $filter = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 ? $this->strTable . '_' . CURRENT_ID : $this->strTable;
     list($offset, $limit) = explode(',', $this->limit);
     // Set the limit filter based on the page number
     if (isset($_GET['lp'])) {
         $lp = intval(\Input::get('lp')) - 1;
         if ($lp >= 0 && $lp < ceil($this->total / $limit)) {
             $session['filter'][$filter]['limit'] = $lp * $limit . ',' . $limit;
             $objSessionBag->replace($session);
         }
         $this->redirect(preg_replace('/&(amp;)?lp=[^&]+/i', '', \Environment::get('request')));
     }
     if ($limit) {
         \Input::setGet('lp', $offset / $limit + 1);
     }
     $objPagination = new \Pagination($this->total, $limit, 7, 'lp', new \BackendTemplate('be_pagination'), true);
     return $objPagination->generate();
 }
Пример #5
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $blnClearInput = false;
     $intYear = \Input::get('year');
     $intMonth = \Input::get('month');
     $intDay = \Input::get('day');
     // Jump to the current period
     if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) {
         switch ($this->cal_format) {
             case 'cal_year':
                 $intYear = date('Y');
                 break;
             case 'cal_month':
                 $intMonth = date('Ym');
                 break;
             case 'cal_day':
                 $intDay = date('Ymd');
                 break;
         }
         $blnClearInput = true;
     }
     $blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year'));
     // Create the date object
     try {
         if ($blnDynamicFormat && $intYear) {
             $this->Date = new \Date($intYear, 'Y');
             $this->cal_format = 'cal_year';
             $this->headline .= ' ' . date('Y', $this->Date->tstamp);
         } elseif ($blnDynamicFormat && $intMonth) {
             $this->Date = new \Date($intMonth, 'Ym');
             $this->cal_format = 'cal_month';
             $this->headline .= ' ' . \Date::parse('F Y', $this->Date->tstamp);
         } elseif ($blnDynamicFormat && $intDay) {
             $this->Date = new \Date($intDay, 'Ymd');
             $this->cal_format = 'cal_day';
             $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $this->Date->tstamp);
         } else {
             $this->Date = new \Date();
         }
     } catch (\OutOfBoundsException $e) {
         throw new PageNotFoundException('Page not found');
     }
     list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format);
     // Get all events
     $arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd);
     $sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort';
     // Sort the days
     $sort($arrAllEvents);
     // Sort the events
     foreach (array_keys($arrAllEvents) as $key) {
         $sort($arrAllEvents[$key]);
     }
     $arrEvents = array();
     $dateBegin = date('Ymd', $strBegin);
     $dateEnd = date('Ymd', $strEnd);
     // Remove events outside the scope
     foreach ($arrAllEvents as $key => $days) {
         if ($key < $dateBegin || $key > $dateEnd) {
             continue;
         }
         foreach ($days as $day => $events) {
             foreach ($events as $event) {
                 $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)];
                 $event['firstDate'] = \Date::parse($objPage->dateFormat, $day);
                 $arrEvents[] = $event;
             }
         }
     }
     unset($arrAllEvents);
     $total = count($arrEvents);
     $limit = $total;
     $offset = 0;
     // Overall limit
     if ($this->cal_limit > 0) {
         $total = min($this->cal_limit, $total);
         $limit = $total;
     }
     // Pagination
     if ($this->perPage > 0) {
         $id = 'page_e' . $this->id;
         $page = \Input::get($id) !== null ? \Input::get($id) : 1;
         // Do not index or cache the page if the page number is outside the range
         if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
             throw new PageNotFoundException('Page not found');
         }
         $offset = ($page - 1) * $this->perPage;
         $limit = min($this->perPage + $offset, $total);
         $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     $strMonth = '';
     $strDate = '';
     $strEvents = '';
     $dayCount = 0;
     $eventCount = 0;
     $headerCount = 0;
     $imgSize = false;
     // Override the default image size
     if ($this->imgSize != '') {
         $size = deserialize($this->imgSize);
         if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
             $imgSize = $this->imgSize;
         }
     }
     // Parse events
     for ($i = $offset; $i < $limit; $i++) {
         $event = $arrEvents[$i];
         $blnIsLastEvent = false;
         // Last event on the current day
         if ($i + 1 == $limit || !isset($arrEvents[$i + 1]['firstDate']) || $event['firstDate'] != $arrEvents[$i + 1]['firstDate']) {
             $blnIsLastEvent = true;
         }
         /** @var FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate($this->cal_template);
         $objTemplate->setData($event);
         // Month header
         if ($strMonth != $event['month']) {
             $objTemplate->newMonth = true;
             $strMonth = $event['month'];
         }
         // Day header
         if ($strDate != $event['firstDate']) {
             $headerCount = 0;
             $objTemplate->header = true;
             $objTemplate->classHeader = ($dayCount % 2 == 0 ? ' even' : ' odd') . ($dayCount == 0 ? ' first' : '') . ($event['firstDate'] == $arrEvents[$limit - 1]['firstDate'] ? ' last' : '');
             $strDate = $event['firstDate'];
             ++$dayCount;
         }
         // Show the teaser text of redirect events (see #6315)
         if (is_bool($event['details'])) {
             $objTemplate->hasDetails = false;
         }
         // Add the template variables
         $objTemplate->classList = $event['class'] . ($headerCount % 2 == 0 ? ' even' : ' odd') . ($headerCount == 0 ? ' first' : '') . ($blnIsLastEvent ? ' last' : '') . ' cal_' . $event['parent'];
         $objTemplate->classUpcoming = $event['class'] . ($eventCount % 2 == 0 ? ' even' : ' odd') . ($eventCount == 0 ? ' first' : '') . ($offset + $eventCount + 1 >= $limit ? ' last' : '') . ' cal_' . $event['parent'];
         $objTemplate->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $event['title']));
         $objTemplate->more = $GLOBALS['TL_LANG']['MSC']['more'];
         $objTemplate->locationLabel = $GLOBALS['TL_LANG']['MSC']['location'];
         // Short view
         if ($this->cal_noSpan) {
             $objTemplate->day = $event['day'];
             $objTemplate->date = $event['date'];
         } else {
             $objTemplate->day = $event['firstDay'];
             $objTemplate->date = $event['firstDate'];
         }
         $objTemplate->addImage = false;
         // Add an image
         if ($event['addImage'] && $event['singleSRC'] != '') {
             $objModel = \FilesModel::findByUuid($event['singleSRC']);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 if ($imgSize) {
                     $event['size'] = $imgSize;
                 }
                 $event['singleSRC'] = $objModel->path;
                 $this->addImageToTemplate($objTemplate, $event);
             }
         }
         $objTemplate->enclosure = array();
         // Add enclosure
         if ($event['addEnclosure']) {
             $this->addEnclosuresToTemplate($objTemplate, $event);
         }
         $strEvents .= $objTemplate->parse();
         ++$eventCount;
         ++$headerCount;
     }
     // No events found
     if ($strEvents == '') {
         $strEvents = "\n" . '<div class="empty">' . $strEmpty . '</div>' . "\n";
     }
     // See #3672
     $this->Template->headline = $this->headline;
     $this->Template->events = $strEvents;
     // Clear the $_GET array (see #2445)
     if ($blnClearInput) {
         \Input::setGet('year', null);
         \Input::setGet('month', null);
         \Input::setGet('day', null);
     }
 }
Пример #6
0
 /**
  * @param $intId
  * @param $blnVisible
  * @param null $dc
  */
 public function toggleVisibility($intId, $blnVisible, $dc = null)
 {
     $table = Input::get('table');
     // Check permissions to edit
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA'][$table]['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$table]['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE " . $table . " SET tstamp=" . time() . ", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
 }
Пример #7
0
 /**
  * Split the current request into fragments, strip the URL suffix, recreate the $_GET array and return the page ID
  *
  * @return mixed
  */
 public static function getPageIdFromUrl()
 {
     $strRequest = \Environment::get('relativeRequest');
     if ($strRequest == '') {
         return null;
     }
     // Get the request without the query string
     list($strRequest) = explode('?', $strRequest, 2);
     // URL decode here (see #6232)
     $strRequest = rawurldecode($strRequest);
     // The request string must not contain "auto_item" (see #4012)
     if (strpos($strRequest, '/auto_item/') !== false) {
         return false;
     }
     // Remove the URL suffix if not just a language root (e.g. en/) is requested
     if ($strRequest != '' && (!\Config::get('addLanguageToUrl') || !preg_match('@^[a-z]{2}(-[A-Z]{2})?/$@', $strRequest))) {
         $intSuffixLength = strlen(\Config::get('urlSuffix'));
         // Return false if the URL suffix does not match (see #2864)
         if ($intSuffixLength > 0) {
             if (substr($strRequest, -$intSuffixLength) != \Config::get('urlSuffix')) {
                 return false;
             }
             $strRequest = substr($strRequest, 0, -$intSuffixLength);
         }
     }
     // Extract the language
     if (\Config::get('addLanguageToUrl')) {
         $arrMatches = array();
         // Use the matches instead of substr() (thanks to Mario Müller)
         if (preg_match('@^([a-z]{2}(-[A-Z]{2})?)/(.*)$@', $strRequest, $arrMatches)) {
             \Input::setGet('language', $arrMatches[1]);
             // Trigger the root page if only the language was given
             if ($arrMatches[3] == '') {
                 return null;
             }
             $strRequest = $arrMatches[3];
         } else {
             return false;
             // Language not provided
         }
     }
     $arrFragments = null;
     // Use folder-style URLs
     if (\Config::get('folderUrl') && strpos($strRequest, '/') !== false) {
         $strAlias = $strRequest;
         $arrOptions = array($strAlias);
         // Compile all possible aliases by applying dirname() to the request (e.g. news/archive/item, news/archive, news)
         while ($strAlias != '/' && strpos($strAlias, '/') !== false) {
             $strAlias = dirname($strAlias);
             $arrOptions[] = $strAlias;
         }
         // Check if there are pages with a matching alias
         $objPages = \PageModel::findByAliases($arrOptions);
         if ($objPages !== null) {
             $arrPages = array();
             // Order by domain and language
             while ($objPages->next()) {
                 /** @var PageModel $objModel */
                 $objModel = $objPages->current();
                 $objPage = $objModel->loadDetails();
                 $domain = $objPage->domain ?: '*';
                 $arrPages[$domain][$objPage->rootLanguage][] = $objPage;
                 // Also store the fallback language
                 if ($objPage->rootIsFallback) {
                     $arrPages[$domain]['*'][] = $objPage;
                 }
             }
             $strHost = \Environment::get('host');
             // Look for a root page whose domain name matches the host name
             if (isset($arrPages[$strHost])) {
                 $arrLangs = $arrPages[$strHost];
             } else {
                 $arrLangs = $arrPages['*'] ?: array();
                 // empty domain
             }
             $arrAliases = array();
             // Use the first result (see #4872)
             if (!\Config::get('addLanguageToUrl')) {
                 $arrAliases = current($arrLangs);
             } elseif (($lang = \Input::get('language')) != '' && isset($arrLangs[$lang])) {
                 $arrAliases = $arrLangs[$lang];
             }
             // Return if there are no matches
             if (empty($arrAliases)) {
                 return false;
             }
             $objPage = $arrAliases[0];
             // The request consists of the alias only
             if ($strRequest == $objPage->alias) {
                 $arrFragments = array($strRequest);
             } else {
                 $arrFragments = explode('/', substr($strRequest, strlen($objPage->alias) + 1));
                 array_unshift($arrFragments, $objPage->alias);
             }
         }
     }
     // If folderUrl is deactivated or did not find a matching page
     if ($arrFragments === null) {
         if ($strRequest == '/') {
             return false;
         } else {
             $arrFragments = explode('/', $strRequest);
         }
     }
     // Add the second fragment as auto_item if the number of fragments is even
     if (\Config::get('useAutoItem') && count($arrFragments) % 2 == 0) {
         array_insert($arrFragments, 1, array('auto_item'));
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getPageIdFromUrl']) && is_array($GLOBALS['TL_HOOKS']['getPageIdFromUrl'])) {
         foreach ($GLOBALS['TL_HOOKS']['getPageIdFromUrl'] as $callback) {
             $arrFragments = static::importStatic($callback[0])->{$callback[1]}($arrFragments);
         }
     }
     // Return if the alias is empty (see #4702 and #4972)
     if ($arrFragments[0] == '' && count($arrFragments) > 1) {
         return false;
     }
     // Add the fragments to the $_GET array
     for ($i = 1, $c = count($arrFragments); $i < $c; $i += 2) {
         // Skip key value pairs if the key is empty (see #4702)
         if ($arrFragments[$i] == '') {
             continue;
         }
         // Return false if there is a duplicate parameter (duplicate content) (see #4277)
         if (isset($_GET[$arrFragments[$i]])) {
             return false;
         }
         // Return false if the request contains an auto_item keyword (duplicate content) (see #4012)
         if (\Config::get('useAutoItem') && in_array($arrFragments[$i], $GLOBALS['TL_AUTO_ITEM'])) {
             return false;
         }
         \Input::setGet(urldecode($arrFragments[$i]), urldecode($arrFragments[$i + 1]), true);
     }
     return $arrFragments[0] ?: null;
 }
Пример #8
0
 /**
  * @param $q
  * @param $tablename
  * @return array
  */
 private function getFilterFields($q, $tablename)
 {
     $notSupportedTypes = array('legend_start', 'legend_end', 'fulltext_search', 'widget');
     $notSupportedID = array('orderBy', 'sorting_fields', 'sorting_fields', 'pagination');
     parse_str($q, $qRow);
     $qArr = array();
     foreach ($qRow as $k => $v) {
         $qArr[$k] = $v;
     }
     if (empty($qArr)) {
         return array();
     }
     $allFiltersDB = $this->Database->prepare('SELECT tl_fmodules.id AS moduleID, tl_fmodules.*, tl_fmodules_filters.*  FROM tl_fmodules LEFT JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY tl_fmodules_filters.sorting')->execute($tablename);
     $arrFilter = array();
     while ($allFiltersDB->next()) {
         $tname = $allFiltersDB->fieldID;
         if (in_array($tname, $notSupportedID) || in_array($allFiltersDB->type, $notSupportedTypes)) {
             continue;
         }
         if ($qArr[$tname] || $allFiltersDB->type == 'toggle_field') {
             $arrFilter[$tname] = $allFiltersDB->row();
             $arrFilter[$tname]['value'] = $qArr[$tname];
             $arrFilter[$tname]['enable'] = true;
             $arrFilter[$tname]['operator'] = $qArr[$tname . '_int'] ? $qArr[$tname . '_int'] : '';
         }
         if ($allFiltersDB->type == 'wrapper_field' && $allFiltersDB->from_field == $allFiltersDB->to_field) {
             $fname = $allFiltersDB->from_field . '_btw';
             Input::setGet($fname, $qArr[$fname]);
         }
         if ($allFiltersDB->type == 'toggle_field' && !$qArr[$tname]) {
             $arrFilter[$tname]['value'] = '';
         }
     }
     return $arrFilter;
 }
 /**
  *
  * @Route("/layout")
  */
 public function layoutAction()
 {
     $this->validateRequest();
     $objPage = PageModel::findOneByType('phpbb_forum');
     // Set the correct current page for navigation
     Environment::set('relativeRequest', $this->container->get('phpbb_bridge.connector')->getBridgeConfig('forum_pageId') . $GLOBALS['TL_CONFIG']['urlSuffix']);
     $response = $this->frontendIndex->run();
     if ($objPage instanceof PageModel) {
         $page = new Forum();
         Input::setGet('format', 'json');
         $response = $page->getResponse($objPage);
     }
     return $response;
 }