/** * Get all content elements and return them as array (content element alias) */ public function getAlias() { $arrPids = array(); $arrAlias = array(); if (!$this->User->isAdmin) { foreach ($this->User->pagemounts as $id) { $arrPids[] = $id; $arrPids = array_merge($arrPids, $this->Database->getChildRecords($id, 'tl_page')); } if (empty($arrPids)) { return $arrAlias; } $objAlias = $this->Database->prepare("SELECT c.id, c.pid, c.type, (CASE c.type WHEN 'module' THEN m.name WHEN 'form' THEN f.title WHEN 'table' THEN c.summary ELSE c.headline END) AS headline, c.text, a.title FROM tl_content c LEFT JOIN tl_page a ON a.id=c.pid LEFT JOIN tl_module m ON m.id=c.module LEFT JOIN tl_form f on f.id=c.form WHERE a.pid IN(" . implode(',', array_map('intval', array_unique($arrPids))) . ") AND (c.ptable='tl_page') AND c.id!=? ORDER BY a.title, c.sorting")->execute(Input::get('id')); } else { $objAlias = $this->Database->prepare("SELECT c.id, c.pid, c.type, (CASE c.type WHEN 'module' THEN m.name WHEN 'form' THEN f.title WHEN 'table' THEN c.summary ELSE c.headline END) AS headline, c.text, a.title FROM tl_content c LEFT JOIN tl_page a ON a.id=c.pid LEFT JOIN tl_module m ON m.id=c.module LEFT JOIN tl_form f on f.id=c.form WHERE (c.ptable='tl_page') AND c.id!=? ORDER BY a.title, c.sorting")->execute(Input::get('id')); } while ($objAlias->next()) { $arrHeadline = deserialize($objAlias->headline, true); if (isset($arrHeadline['value'])) { $headline = StringUtil::substr($arrHeadline['value'], 32); } else { $headline = StringUtil::substr(preg_replace('/[\\n\\r\\t]+/', ' ', $arrHeadline[0]), 32); } $text = StringUtil::substr(strip_tags(preg_replace('/[\\n\\r\\t]+/', ' ', $objAlias->text)), 32); $strText = $GLOBALS['TL_LANG']['CTE'][$objAlias->type][0] . ' ('; if ($headline != '') { $strText .= $headline . ', '; } elseif ($text != '') { $strText .= $text . ', '; } $key = $objAlias->title . ' (ID ' . $objAlias->pid . ')'; $arrAlias[$key][$objAlias->id] = $strText . 'ID ' . $objAlias->id . ')'; } return $arrAlias; }
/** * Generate the module * * @return string */ public function run() { if (!\Config::get('enableSearch')) { return ''; } $time = time(); /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_rebuild_index'); $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex']; $objTemplate->isActive = $this->isActive(); // Add the error message if ($_SESSION['REBUILD_INDEX_ERROR'] != '') { $objTemplate->indexMessage = $_SESSION['REBUILD_INDEX_ERROR']; $_SESSION['REBUILD_INDEX_ERROR'] = ''; } // Rebuild the index if (\Input::get('act') == 'index') { // Check the request token (see #4007) if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) { $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request')); $this->redirect('contao/confirm.php'); } $arrPages = $this->findSearchablePages(); // 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); } } // Return if there are no pages if (empty($arrPages)) { $_SESSION['REBUILD_INDEX_ERROR'] = $GLOBALS['TL_LANG']['tl_maintenance']['noSearchable']; $this->redirect($this->getReferer()); } // Truncate the search tables $this->import('Automator'); $this->Automator->purgeSearchTables(); // Hide unpublished elements $this->setCookie('FE_PREVIEW', 0, $time - 86400); // Calculate the hash $strHash = sha1(session_id() . (!\Config::get('disableIpCheck') ? \Environment::get('ip') : '') . 'FE_USER_AUTH'); // Remove old sessions $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute($time - \Config::get('sessionTimeout'), $strHash); // Log in the front end user if (is_numeric(\Input::get('user')) && \Input::get('user') > 0) { // Insert a new session $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute(\Input::get('user'), $time, 'FE_USER_AUTH', session_id(), \Environment::get('ip'), $strHash); // Set the cookie $this->setCookie('FE_USER_AUTH', $strHash, $time + \Config::get('sessionTimeout'), null, null, false, true); } else { // Unset the cookies $this->setCookie('FE_USER_AUTH', $strHash, $time - 86400, null, null, false, true); $this->setCookie('FE_AUTO_LOGIN', \Input::cookie('FE_AUTO_LOGIN'), $time - 86400, null, null, false, true); } $strBuffer = ''; $rand = rand(); // Display the pages for ($i = 0, $c = count($arrPages); $i < $c; $i++) { $strBuffer .= '<span class="page_url" data-url="' . $arrPages[$i] . '#' . $rand . $i . '">' . \StringUtil::substr($arrPages[$i], 100) . '</span><br>'; unset($arrPages[$i]); // see #5681 } $objTemplate->content = $strBuffer; $objTemplate->note = $GLOBALS['TL_LANG']['tl_maintenance']['indexNote']; $objTemplate->loading = $GLOBALS['TL_LANG']['tl_maintenance']['indexLoading']; $objTemplate->complete = $GLOBALS['TL_LANG']['tl_maintenance']['indexComplete']; $objTemplate->indexContinue = $GLOBALS['TL_LANG']['MSC']['continue']; $objTemplate->theme = \Backend::getTheme(); $objTemplate->isRunning = true; return $objTemplate->parse(); } $arrUser = array('' => '-'); // Get active front end users $objUser = $this->Database->execute("SELECT id, username FROM tl_member WHERE disable!='1' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') ORDER BY username"); while ($objUser->next()) { $arrUser[$objUser->id] = $objUser->username . ' (' . $objUser->id . ')'; } // Default variables $objTemplate->user = $arrUser; $objTemplate->indexLabel = $GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][0]; $objTemplate->indexHelp = \Config::get('showHelp') && strlen($GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][1]) ? $GLOBALS['TL_LANG']['tl_maintenance']['frontendUser'][1] : ''; $objTemplate->indexSubmit = $GLOBALS['TL_LANG']['tl_maintenance']['indexSubmit']; return $objTemplate->parse(); }
/** * Add a list of versions to a template * * @param \BackendTemplate|object $objTemplate */ public static function addToTemplate(\BackendTemplate $objTemplate) { $arrVersions = array(); $objUser = \BackendUser::getInstance(); $objDatabase = \Database::getInstance(); // Get the total number of versions $objTotal = $objDatabase->prepare("SELECT COUNT(*) AS count FROM tl_version WHERE version>1" . (!$objUser->isAdmin ? " AND userid=?" : ""))->execute($objUser->id); $intLast = ceil($objTotal->count / 30); $intPage = \Input::get('vp') !== null ? \Input::get('vp') : 1; $intOffset = ($intPage - 1) * 30; // Validate the page number if ($intPage < 1 || $intLast > 0 && $intPage > $intLast) { header('HTTP/1.1 404 Not Found'); } // Create the pagination menu $objPagination = new \Pagination($objTotal->count, 30, 7, 'vp', new \BackendTemplate('be_pagination')); $objTemplate->pagination = $objPagination->generate(); // Get the versions $objVersions = $objDatabase->prepare("SELECT pid, tstamp, version, fromTable, username, userid, description, editUrl, active FROM tl_version" . (!$objUser->isAdmin ? " WHERE userid=?" : "") . " ORDER BY tstamp DESC, pid, version DESC")->limit(30, $intOffset)->execute($objUser->id); while ($objVersions->next()) { $arrRow = $objVersions->row(); // Add some parameters $arrRow['from'] = max($objVersions->version - 1, 1); // see #4828 $arrRow['to'] = $objVersions->version; $arrRow['date'] = date(\Config::get('datimFormat'), $objVersions->tstamp); $arrRow['description'] = \StringUtil::substr($arrRow['description'], 32); $arrRow['shortTable'] = \StringUtil::substr($arrRow['fromTable'], 18); // see #5769 if ($arrRow['editUrl'] != '') { $arrRow['editUrl'] = preg_replace('/&(amp;)?rt=[a-f0-9]+/', '&rt=' . REQUEST_TOKEN, ampersand($arrRow['editUrl'])); } $arrVersions[] = $arrRow; } $intCount = -1; $arrVersions = array_values($arrVersions); // Add the "even" and "odd" classes foreach ($arrVersions as $k => $v) { $arrVersions[$k]['class'] = ++$intCount % 2 == 0 ? 'even' : 'odd'; try { // Mark deleted versions (see #4336) $objDeleted = $objDatabase->prepare("SELECT COUNT(*) AS count FROM " . $v['fromTable'] . " WHERE id=?")->execute($v['pid']); $arrVersions[$k]['deleted'] = $objDeleted->count < 1; } catch (\Exception $e) { // Probably a disabled module --$intCount; unset($arrVersions[$k]); } } $objTemplate->versions = $arrVersions; }
/** * Prepare a text to be used in the meta description tag * * @param string $strText * * @return string */ protected function prepareMetaDescription($strText) { $strText = $this->replaceInsertTags($strText, false); $strText = strip_tags($strText); $strText = str_replace("\n", ' ', $strText); $strText = \StringUtil::substr($strText, 180); return trim($strText); }
/** * @param \File $objCsvFile * @param $strTable * @param $strImportMode * @param null $arrSelectedFields * @param string $strFieldseparator * @param string $strFieldenclosure * @param string $strPrimaryKey * @param string $arrDelim */ public function importCsv(\File $objCsvFile, $strTable, $strImportMode, $arrSelectedFields = null, $strFieldseparator = ';', $strFieldenclosure = '', $strPrimaryKey = 'id', $arrDelim = '||', $blnTestMode = false) { // store sucess or failure message in the session $_SESSION['import_from_csv']['report'] = array(); // load language file \System::loadLanguageFile($strTable); // load dca $this->loadDataContainer($strTable); // store the options in $this->arrData $this->arrData = array('tablename' => $strTable, 'primaryKey' => $strPrimaryKey, 'importMode' => $strImportMode, 'selectedFields' => is_array($arrSelectedFields) ? $arrSelectedFields : array(), 'fieldSeparator' => $strFieldseparator, 'fieldEnclosure' => $strFieldenclosure); // truncate table if ($this->arrData['importMode'] == 'truncate_table') { $this->Database->execute('TRUNCATE TABLE `' . $strTable . '`'); } if (count($this->arrData['selectedFields']) < 1) { return; } // get content as array $arrFileContent = $objCsvFile->getContentAsArray(); $arrFieldnames = explode($this->arrData['fieldSeparator'], $arrFileContent[0]); // trim quotes in the first line and get the fieldnames $arrFieldnames = array_map(array($this, 'myTrim'), $arrFieldnames); // count rows $rows = 0; // count errors $insertError = 0; // store each line as an entry in the db foreach ($arrFileContent as $line => $lineContent) { $doNotSave = false; // line 0 contains the fieldnames if ($line == 0) { continue; } // count rows $rows++; // separate the line into the different fields $arrLine = explode($this->arrData['fieldSeparator'], $lineContent); // Set the associative Array with the line content $assocArrayLine = array(); foreach ($arrFieldnames as $k => $fieldname) { $assocArrayLine[$fieldname] = $arrLine[$k]; } $set = array(); foreach ($arrFieldnames as $k => $fieldname) { $blnCustomValidation = false; // continue if field is excluded from import if (!in_array($fieldname, $this->arrData['selectedFields'])) { continue; } // if entries are appended autoincrement id if ($this->arrData['importMode'] == 'append_entries' && strtolower($fieldname) == $this->arrData['primaryKey']) { continue; } // get the field content $fieldValue = $arrLine[$k]; // trim quotes $fieldValue = $this->myTrim($fieldValue); // convert variable to a string (see #2) $fieldValue = strval($fieldValue); // get the DCA of the current field $arrDCA =& $GLOBALS['TL_DCA'][$strTable]['fields'][$fieldname]; $arrDCA = is_array($arrDCA) ? $arrDCA : array(); // Prepare FormWidget object !set inputType to "text" if there is no definition $inputType = $arrDCA['inputType'] != '' ? $arrDCA['inputType'] : 'text'; // Map checkboxWizards to regular checkbox widgets if ($inputType == 'checkboxWizard') { $inputType = 'checkbox'; } $strClass =& $GLOBALS['TL_FFL'][$inputType]; // HOOK: add custom validation if (isset($GLOBALS['TL_HOOKS']['importFromCsv']) && is_array($GLOBALS['TL_HOOKS']['importFromCsv'])) { $arrCustomValidation = array('strTable' => $strTable, 'arrDCA' => $arrDCA, 'fieldname' => $fieldname, 'value' => $fieldValue, 'arrayLine' => $assocArrayLine, 'line' => $line, 'objCsvFile' => $objCsvFile, 'skipWidgetValidation' => false, 'hasErrors' => false, 'errorMsg' => null, 'doNotSave' => false, 'blnTestMode' => $blnTestMode); $blnCustomValidation = false; foreach ($GLOBALS['TL_HOOKS']['importFromCsv'] as $callback) { $this->import($callback[0]); $arrCustomValidation = $this->{$callback[0]}->{$callback[1]}($arrCustomValidation, $this); if (!is_array($arrCustomValidation)) { die('Als Rückgabewert wird ein Array erwartet. Fehler in ' . __FILE__ . ' in Zeile ' . __LINE__ . '.'); } $fieldValue = $arrCustomValidation['value']; // Check if widget-validation should be skipped if ($blnCustomValidation['skipWidgetValidation'] === true) { $blnCustomValidation = true; } } if ($arrCustomValidation['errorMsg'] != '') { $fieldValue = sprintf('<span class="errMsg">%s</span>', $arrCustomValidation['errorMsg']); } if ($arrCustomValidation['doNotSave']) { $doNotSave = true; } } // Continue if the class does not exist // Use form widgets for input validation if (class_exists($strClass) && $blnCustomValidation === false) { $objWidget = new $strClass($strClass::getAttributesFromDca($arrDCA, $fieldname, $fieldValue, '', '', $this)); $objWidget->storeValues = false; // Set post var, so the content can be validated \Input::setPost($fieldname, $fieldValue); if ($fieldname == 'password') { \Input::setPost('password_confirm', $fieldValue); } // add option values in the csv like this: value1||value2||value3 if ($inputType == 'radio' || $inputType == 'checkbox' || $inputType == 'select') { if ($arrDCA['eval']['multiple'] === true) { // Security issues in Contao #6695 if (version_compare(VERSION . BUILD, '3.2.5', '>=')) { $fieldValue = $fieldValue != '' ? explode($arrDelim, $fieldValue) : null; } \Input::setPost($fieldname, $fieldValue); $objWidget->value = $fieldValue; } } // validate input $objWidget->validate(); $fieldValue = $objWidget->value; // Convert date formats into timestamps $rgxp = $arrDCA['eval']['rgxp']; if (($rgxp == 'date' || $rgxp == 'time' || $rgxp == 'datim') && $fieldValue != '' && !$objWidget->hasErrors()) { try { $strTimeFormat = $GLOBALS['TL_CONFIG'][$rgxp . 'Format']; $objDate = new \Date($fieldValue, $strTimeFormat); $fieldValue = $objDate->tstamp; } catch (\OutOfBoundsException $e) { $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $fieldValue)); } } // Make sure that unique fields are unique if ($arrDCA['eval']['unique'] && $fieldValue != '' && !$this->Database->isUniqueValue($strTable, $fieldname, $fieldValue, null)) { $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrDCA['label'][0] ?: $fieldname)); } // Do not save the field if there are errors if ($objWidget->hasErrors()) { $doNotSave = true; $fieldValue = sprintf('"%s" => <span class="errMsg">%s</span>', $fieldValue, $objWidget->getErrorsAsString()); } else { // Set the correct empty value if ($fieldValue === '') { $fieldValue = $objWidget->getEmptyValue(); } } } $set[$fieldname] = is_array($fieldValue) ? serialize($fieldValue) : $fieldValue; } // insert data record if (!$doNotSave) { // insert tstamp if ($this->Database->fieldExists('tstamp', $strTable)) { if (!$set['tstamp'] > 0) { $set['tstamp'] = time(); } } // insert dateAdded (tl_member) if ($this->Database->fieldExists('dateAdded', $strTable)) { if (!$set['dateAdded'] > 0) { $set['dateAdded'] = time(); } } // add new member to newsletter recipient list if ($strTable == 'tl_member' && $set['email'] != '' && $set['newsletter'] != '') { foreach (deserialize($set['newsletter'], true) as $newsletterId) { // check for unique email-address $objRecipient = $this->Database->prepare("SELECT * FROM tl_newsletter_recipients WHERE email=? AND pid=(SELECT pid FROM tl_newsletter_recipients WHERE id=?) AND id!=?")->execute($set['email'], $newsletterId, $newsletterId); if (!$objRecipient->numRows) { $arrRecipient = array(); $arrRecipient['tstamp'] = time(); $arrRecipient['pid'] = $newsletterId; $arrRecipient['email'] = $set['email']; $arrRecipient['active'] = '1'; if ($blnTestMode !== true) { $this->Database->prepare('INSERT INTO tl_newsletter_recipients %s')->set($arrRecipient)->execute(); } } } } try { if ($blnTestMode !== true) { // insert entry into database $this->Database->prepare('INSERT INTO ' . $strTable . ' %s')->set($set)->execute(); } } catch (\Exception $e) { $set['insertError'] = $e->getMessage(); $doNotSave = true; } } // generate html markup for the import report table $htmlReport = ''; $cssClass = 'allOk'; if ($doNotSave) { $cssClass = 'error'; $htmlReport .= sprintf('<tr class="%s"><td class="tdTitle" colspan="2">#%s Datensatz konnte nicht angelegt werden!</td></tr>', $cssClass, $line); // increment error counter if necessary $insertError++; } else { $htmlReport .= sprintf('<tr class="%s"><td class="tdTitle" colspan="2">#%s Datensatz erfolgreich angelegt!</td></tr>', $cssClass, $line); } foreach ($set as $k => $v) { if (is_array($v)) { $v = serialize($v); } $htmlReport .= sprintf('<tr class="%s"><td>%s</td><td>%s</td></tr>', $cssClass, \StringUtil::substr($k, 30), \StringUtil::substrHtml($v, 90)); } $htmlReport .= '<tr class="delim"><td> </td><td> </td></tr>'; $_SESSION['import_from_csv']['report'][] = $htmlReport; } $_SESSION['import_from_csv']['status'] = array('blnTestMode' => $blnTestMode, 'rows' => $rows, 'success' => $rows - $insertError, 'errors' => $insertError); }
public function replaceInsertTagsHooks($strTag, $blnCache, $strCache, $flags, $tags, $arrCache, $index, $count) { $params = preg_split('/::/', $strTag); if (is_array($params) && !empty($params)) { if (strpos($params[0], 'small') === 0) { return '<small>'; } if (strpos($params[0], '/small') === 0) { return '</small>'; } if (strpos($params[0], 'u') === 0) { return '<u>'; } if (strpos($params[0], '/u') === 0) { return '</u>'; } if (strpos($params[0], 'i') === 0) { $strClass = $params[1] ? ' class="' . $params[1] . '"' : ''; return '<i' . $strClass . '>'; } if (strpos($params[0], '/i') === 0) { return '</i>'; } if (strpos($params[0], 'loremipsum') === 0) { $text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,'; // trim length if (is_numeric($params[1])) { $text = \StringUtil::substr($text, $params[1]); } return $text; } if (strpos($params[0], 'btn-dropdown') === 0) { $objTag = new \HeimrichHannot\Bootstrapper\BootstrapperButtonDropdown($strTag, $params); return $objTag->generate(); } if (strpos($params[0], 'btn') === 0) { $objTag = new \HeimrichHannot\Bootstrapper\BootstrapperButton($strTag, $params); return $objTag->generate(); } } return false; }
$count = \Netzmacht\Contao\Leaflet\Model\MarkerModel::countBy('pid', $row['id']); $label .= sprintf('<span class="tl_gray"> (%s %s)</span>', $count, $GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']); return $label; }), 'vectors' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/vectors.png', 'vectors' => true, 'boundsMode' => array('extend' => true), 'label' => function ($row, $label) { $count = \Netzmacht\Contao\Leaflet\Model\VectorModel::countBy('pid', $row['id']); $label .= sprintf('<span class="tl_gray"> (%s %s)</span>', $count, $GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']); return $label; }), 'reference' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/reference.png', 'label' => function ($row, $label) { $reference = \Netzmacht\Contao\Leaflet\Model\LayerModel::findByPk($row['reference']); if ($reference) { $label .= '<span class="tl_gray"> (' . $reference->title . ')</span>'; } return $label; }), 'markercluster' => array('children' => true, 'icon' => 'system/modules/leaflet/assets/img/cluster.png'), 'tile' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/tile.png'), 'overpass' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/overpass.png', 'label' => function ($row, $label) { if ($row['overpassQuery']) { $label .= '<span class="tl_gray"> ' . \StringUtil::substr($row['overpassQuery'], 50) . '</span>'; } return $label; }, 'boundsMode' => array('extend' => true, 'fit' => true))); /* * leaflet controls. * * Supported leaflet control types. Register your type for the database driven definition here. */ $GLOBALS['LEAFLET_CONTROLS'] = array('zoom', 'layers', 'scale', 'attribution', 'loading', 'fullscreen'); /* * Leaflet icons. * * Supported leaflet icon types. Register you type for the database driven definition here. */ $GLOBALS['LEAFLET_ICONS'] = array('image', 'div', 'extra');
/** * Generate the module * * @return string */ public function run() { $this->import('BackendUser', 'User'); $this->registerEvents(); $time = time(); /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_filecredits_sync'); $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->syncHeadline = $GLOBALS['TL_LANG']['tl_filecredit']['syncHeadline']; $objTemplate->isActive = $this->isActive(); $objTemplate->pageSelection = $this->generatePageSelection(); if (!\Config::get('headerAddXFrame') || !\Config::get('headerAllowOrigins')) { $objTemplate->originInfo = $GLOBALS['TL_LANG']['tl_filecredit']['originInfo']; } // Add the error message if ($_SESSION['REBUILD_FILECREDIT_ERROR'] != '') { $objTemplate->indexMessage = $_SESSION['REBUILD_FILECREDIT_ERROR']; $_SESSION['REBUILD_FILECREDIT_ERROR'] = ''; } // Rebuild the index if (\Input::get('act') == 'index') { // Check the request token (see #4007) if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) { $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request')); $this->redirect('contao/confirm.php'); } $arrPages = static::findFileCreditPages(); // HOOK: take additional pages (news, events…) 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); } } $blnTruncateTable = true; if (\Input::get('limitfilecreditpages')) { $arrSelectedPages = \Input::get('filecreditpages'); if (is_array($arrSelectedPages) && !empty($arrSelectedPages)) { $arrPages = array_keys(array_intersect(array_flip($arrPages), $arrSelectedPages)); $blnTruncateTable = false; } } // Return if there are no pages if (empty($arrPages)) { $_SESSION['REBUILD_FILECREDIT_ERROR'] = $GLOBALS['TL_LANG']['tl_filecredit']['noSearchable']; \Controller::redirect(\System::getReferer()); } // Truncate the search tables if ($blnTruncateTable) { Automator::purgeFileCreditTables(); } // Hide unpublished elements $this->setCookie('FE_PREVIEW', 0, $time - 86400); // Calculate the hash $strHash = sha1(session_id() . (!\Config::get('disableIpCheck') ? \Environment::get('ip') : '') . 'FE_USER_AUTH'); // Remove old sessions $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute($time - \Config::get('sessionTimeout'), $strHash); // Log in the front end user if (is_numeric(\Input::get('user')) && \Input::get('user') > 0) { // Insert a new session $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute(\Input::get('user'), $time, 'FE_USER_AUTH', session_id(), \Environment::get('ip'), $strHash); // Set the cookie $this->setCookie('FE_USER_AUTH', $strHash, $time + \Config::get('sessionTimeout'), null, null, false, true); } else { // Unset the cookies $this->setCookie('FE_USER_AUTH', $strHash, $time - 86400, null, null, false, true); $this->setCookie('FE_AUTO_LOGIN', \Input::cookie('FE_AUTO_LOGIN'), $time - 86400, null, null, false, true); } $strBuffer = ''; $rand = rand(); // Display the pages for ($i = 0, $c = count($arrPages); $i < $c; $i++) { if (!\Validator::isUrl($arrPages[$i])) { continue; } $strBuffer .= '<span class="page_url" data-url="' . $arrPages[$i] . '#' . $rand . $i . '">' . \StringUtil::substr($arrPages[$i], 100) . '</span><br>'; unset($arrPages[$i]); // see #5681 } $objTemplate->content = $strBuffer; $objTemplate->note = $GLOBALS['TL_LANG']['tl_filecredit']['indexNote']; $objTemplate->loading = $GLOBALS['TL_LANG']['tl_filecredit']['indexLoading']; $objTemplate->complete = $GLOBALS['TL_LANG']['tl_filecredit']['indexComplete']; $objTemplate->indexContinue = $GLOBALS['TL_LANG']['MSC']['continue']; $objTemplate->theme = \Backend::getTheme(); $objTemplate->isRunning = true; } // Default variables $objTemplate->indexSubmit = $GLOBALS['TL_LANG']['tl_filecredit']['syncSubmit']; $objTemplate->backHref = \System::getReferer(true); $objTemplate->backTitle = specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']); $objTemplate->backButton = $GLOBALS['TL_LANG']['MSC']['backBT']; return $objTemplate->parse(); }