예제 #1
0
 /**
  * Compile the view
  */
 protected function compile()
 {
     if (!$this->getConfigAttribute('plain')) {
         if ($this->getConfigAttribute('table') === true) {
             $this->setConfigAttribute('table', $this->definition->getName());
         }
         if ($this->getConfigAttribute('id') === true) {
             $this->setConfigAttribute('id', \Input::get('id'));
         }
         $strHref = \Environment::get('script') . '?do=' . \Input::get('do');
         if ($this->view->getHref() != '') {
             $strHref .= '&' . $this->view->getHref();
         }
         $this->setConfigAttribute('rt', \RequestToken::get());
         $attributes = array();
         if ($this->getConfigAttribute('id')) {
             $attributes[] = 'id';
         }
         if ($this->getConfigAttribute('table')) {
             $attributes[] = 'table';
         }
         $attributes[] = 'rt';
         $strHref .= '&' . $this->buildHref($attributes);
         $this->view->setHref($strHref);
     }
 }
 protected function setRequestToken()
 {
     if (!\Config::get('disableRefererCheck')) {
         $token = \RequestToken::get();
         $this->builder->add('REQUEST_TOKEN', 'hidden', array('data' => $token));
     }
 }
 public function __construct($strTable, $arrModule = array())
 {
     parent::__construct();
     // Check the request token (see #4007)
     if (isset($_GET['act'])) {
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
     }
     $this->intId = \Input::get('id');
     // Check whether the table is defined
     if (!$strTable || !isset($GLOBALS['TL_DCA'][$strTable])) {
         $this->log('Could not load the data container configuration for "' . $strTable . '"', 'DC_Table __construct()', TL_ERROR);
         trigger_error('Could not load the data container configuration', E_USER_ERROR);
     }
     $this->strTable = $strTable;
     $this->arrModule = $arrModule;
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($this);
             }
         }
     }
 }
 /**
  * Get a request token
  * @return void
  */
 public function run()
 {
     if (AjaxInput::post('action') == 'getRequestToken') {
         $objResponse = new HtmlResponse(\RequestToken::get());
         $objResponse->send();
     }
 }
 /**
  * Get edit map link wizard.
  *
  * @param \DataContainer $dataContainer The dataContainer driver.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function getEditMapLink($dataContainer)
 {
     if ($dataContainer->value < 1) {
         return '';
     }
     $pattern = 'title="%s" style="padding-left: 3px" onclick="Backend.openModalIframe(';
     $pattern .= '{\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"';
     return sprintf('<a href="%s%s&amp;popup=1&amp;rt=%s" %s>%s</a>', 'contao/main.php?do=leaflet&amp;table=tl_leaflet_map&amp;act=edit&amp;id=', $dataContainer->value, \RequestToken::get(), sprintf($pattern, specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)), specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)))), \Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_content']['editalias'][0], 'style="vertical-align:top"'));
 }
예제 #6
0
 /**
  * Output data, encode to json and replace insert tags.
  *
  * @param string $buffer
  * @return string
  */
 protected function output($buffer)
 {
     $buffer = $this->replaceInsertTags($buffer);
     $buffer = str_replace(array('{{request_token}}', '[{]', '[}]'), array(REQUEST_TOKEN, '{{', '}}'), $buffer);
     $buffer = str_replace('{{request_token}}', \RequestToken::get(), $buffer);
     if (is_array($buffer) || is_object($buffer)) {
         $buffer = json_encode($buffer);
     }
     echo $buffer;
     exit;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function generate()
 {
     if (TL_MODE === 'BE') {
         $template = new \BackendTemplate('be_wildcard');
         $subform = \FormModel::findByPk($this->subform);
         $template->wildcard = sprintf('### %s ###', $GLOBALS['TL_LANG']['tl_form_field']['subform'][0]);
         $template->id = $this->id;
         $template->link = $subform->title;
         $template->href = sprintf('contao/main.php?do=form&table=tl_form_field&id=%s&rt=%s', $this->subform, \RequestToken::get());
         return $template->parse();
     }
     return '';
 }
예제 #8
0
 /**
  * This initializes the Contao Singleton object stack as it must be,
  * when using singletons within the config.php file of an Extension.
  *
  * @return void
  */
 protected static function initializeContaoObjectStack()
 {
     // all of these getInstance calls are neccessary to keep the instance stack intact
     // and therefore prevent an Exception in unknown on line 0.
     // Hopefully this will get fixed with Contao Reloaded or Contao 3.
     Config::getInstance();
     Environment::getInstance();
     Input::getInstance();
     // request token became available in 2.11
     if (version_compare(TL_VERSION, '2.11', '>=')) {
         RequestToken::getInstance();
     }
     self::getUser();
     Database::getInstance();
 }
예제 #9
0
 /**
  * Combine
  */
 protected function compileDefaultView()
 {
     if (!$this->getConfigAttribute('table')) {
         $this->setConfigAttribute('table', $this->model->getProviderName());
     }
     if (!$this->getConfigAttribute('id') && !$this->getConfigAttribute('id') !== false) {
         $this->setConfigAttribute('id', $this->model->getId());
     }
     $this->setConfigAttribute('rt', \RequestToken::get());
     $href = \Environment::get('script') . '?do=' . \Input::get('do');
     if ($this->getConfigAttribute('id') === false) {
         $add = $this->buildHref(array('table', 'rt'));
     } else {
         $add = $this->buildHref();
     }
     if ($this->view->getHref()) {
         $href .= '&amp;' . $this->view->getHref();
     }
     if ($add) {
         $href .= '&amp;' . $add;
     }
     $this->view->setHref($href);
 }
 protected function loadDcaConfig()
 {
     // in MB
     $this->maxFilesize = $this->maxUploadSize ?: $this->getMaximumUploadSize() / 1024 / 1024;
     $this->acceptedFiles = implode(',', array_map(function ($a) {
         return '.' . $a;
     }, trimsplit(',', strtolower($this->extensions ?: \Config::get('uploadTypes')))));
     // labels & messages
     $this->labels = $this->labels ?: $GLOBALS['TL_LANG']['MSC']['dropzone']['labels'];
     $this->messages = $this->messages ?: $GLOBALS['TL_LANG']['MSC']['dropzone']['messages'];
     foreach ($this->messages as $strKey => $strMessage) {
         $this->{$strKey} = $strMessage;
     }
     foreach ($this->labels as $strKey => $strMessage) {
         $this->{$strKey} = $strMessage;
     }
     $this->thumbnailWidth = $this->thumbnailWidth ?: 90;
     $this->thumbnailHeight = $this->thumbnailHeight ?: 90;
     $this->createImageThumbnails = $this->createImageThumbnails ?: true;
     $this->requestToken = \RequestToken::get();
     $this->previewsContainer = '#ctrl_' . $this->id . ' .dropzone-previews';
     $this->uploadMultiple = $this->fieldType == 'checkbox';
     $this->maxFiles = $this->uploadMultiple ? $this->maxFiles ?: null : 1;
 }
예제 #11
0
 /**
  * Return the current object instance (Singleton)
  * @return RequestToken
  */
 public static function getInstance()
 {
     if (!is_object(self::$objInstance)) {
         self::$objInstance = new self();
     }
     return self::$objInstance;
 }
예제 #12
0
 /**
  * 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();
 }
예제 #13
0
@set_exception_handler('__exception');
/**
 * Log PHP errors
 */
@ini_set('error_log', TL_ROOT . '/system/logs/error.log');
/**
 * Start the session
 */
@session_start();
/**
 * Load the basic classes
 */
$objConfig = Config::getInstance();
$objEnvironment = Environment::getInstance();
$objInput = Input::getInstance();
$objToken = RequestToken::getInstance();
/**
 * Set error_reporting
 */
@ini_set('display_errors', $GLOBALS['TL_CONFIG']['displayErrors'] ? 1 : 0);
error_reporting($GLOBALS['TL_CONFIG']['displayErrors'] || $GLOBALS['TL_CONFIG']['logErrors'] ? E_ALL | E_STRICT : 0);
/**
 * Set the timezone
 */
@ini_set('date.timezone', $GLOBALS['TL_CONFIG']['timeZone']);
@date_default_timezone_set($GLOBALS['TL_CONFIG']['timeZone']);
/**
 * Define the relativ path to the Contao installation
 */
if ($GLOBALS['TL_CONFIG']['websitePath'] === null) {
    $path = preg_replace('/\\/contao\\/[^\\/]*$/i', '', $objEnvironment->requestUri);
예제 #14
0
 /**
  * Render the form.
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function render()
 {
     $template = new \BackendTemplate($this->templateName);
     $template->submitLabel = $GLOBALS['TL_LANG']['MSC']['workflowSubmitLabel'];
     $template->name = $this->formName;
     $template->fieldsets = $this->renderSubForms();
     $template->requestToken = \RequestToken::get();
     return $template->parse();
 }
 public static function getGenerateButton($arrRow, $strKey, $strLabel, $strTitle)
 {
     $strHref = sprintf('contao/main.php?do=code_config&%s&id=%s&rt=%s', $strKey, $arrRow['id'], \RequestToken::get());
     return sprintf("<a href=\"%s\" title=\"%s\" onclick=\"count=prompt('%s', '');" . "if (count) {self.location.href='/%s&count=' + count;} return false;\"><img src=\"%s\"></a>", $strHref, $strTitle, $GLOBALS['TL_LANG']['MSC']['codeGenerator']['codesPrompt'], $strHref, 'system/modules/code_generator/assets/img/generate.png');
 }
예제 #16
0
 /**
  * Generate the adjust selection link.
  *
  * @param array $values The selected files.
  *
  * @return string
  */
 private function generateLink($values)
 {
     $inputProvider = $this->getEnvironment()->getInputProvider();
     // Contao passed File ids sinc 3.3.4
     // @see https://github.com/contao/core/commit/c1472209fdfd6e2446013430753ed65530b5a1d1
     if (version_compare(VERSION . '.' . BUILD, '3.3.4', '>=')) {
         $values = array_keys($values);
     } else {
         $values = array_map('String::binToUuid', $values);
     }
     return sprintf('contao/file.php?do=%s&amp;table=%s&amp;field=%s&amp;act=show&amp;id=%s&amp;value=%s&amp;rt=%s', $inputProvider->getParameter('do'), $this->getModel()->getProviderName(), $this->strField, $this->getModel()->getId(), implode(',', $values), \RequestToken::get());
 }
예제 #17
0
 /**
  * Generate the adjust selection link.
  *
  * @param array $values The selected files (string uuids).
  *
  * @return string
  */
 private function generateLink($values)
 {
     $inputProvider = $this->getEnvironment()->getInputProvider();
     return sprintf('contao/file.php?do=%s&amp;table=%s&amp;field=%s&amp;act=show&amp;id=%s&amp;value=%s&amp;rt=%s', $inputProvider->getParameter('do'), $this->getModel()->getProviderName(), $this->strField, $this->getModel()->getId(), implode(',', $values), \RequestToken::get());
 }
예제 #18
0
 protected function prepare()
 {
     if ($this->multiple) {
         $this->addAttribute('multiple', true);
         $this->strName .= '[]';
     } else {
         $this->addAttribute('data-max-tags', 1);
     }
     if ($this->submitOnChange) {
         unset($this->arrAttributes['onchange']);
         $this->addAttribute('data-submitonchange', true);
     }
     // add remote options or freeInput options
     $this->arrOptions = $this->getOptions(deserialize($this->varValue, true));
     // Add an empty option (XHTML) if there are none
     if (empty($this->arrOptions)) {
         $this->arrOptions = array(array('value' => '', 'label' => '-'));
     }
     foreach ($this->arrOptions as $strKey => $arrOption) {
         if (isset($arrOption['value'])) {
             $this->arrTags[] = $arrOption;
             // add only selected values as option
             if ($this->isSelected($arrOption)) {
                 $this->arrSelectedOptions[] = sprintf('<option value="%s"%s%s>%s</option>', is_numeric($arrOption['value']) ? $arrOption['value'] : specialchars($arrOption['label']), $arrOption['class'] != '' ? 'class="' . $arrOption['class'] . '"' : '', $arrOption['target'] != '' ? 'data-target="' . $arrOption['class'] . '"' : '', $arrOption['label']);
             }
         }
     }
     $this->addAttribute('data-items', htmlspecialchars(json_encode($this->arrTags), ENT_QUOTES, 'UTF-8'));
     $this->addAttribute('data-free-input', $this->canInputFree() !== false ? 'true' : 'false');
     $strMode = $this->arrConfiguration['mode'] ?: static::MODE_LOCAL;
     $this->addAttribute('data-mode', $strMode);
     switch ($strMode) {
         case static::MODE_REMOTE:
             $this->addAttribute('data-post-data', htmlspecialchars(json_encode(array('action' => static::ACTION_FETCH_REMOTE_OPTIONS, 'name' => $this->strId, 'REQUEST_TOKEN' => \RequestToken::get()))));
             break;
     }
     if ($this->arrConfiguration['placeholder']) {
         $this->addAttribute('data-placeholder', $this->arrConfiguration['placeholder']);
     }
 }
 /**
  * Compile buttons from the table configuration array and return them as HTML
  *
  * @param array   $arrRow
  * @param string  $strTable
  * @param array   $arrRootIds
  * @param boolean $blnCircularReference
  * @param array   $arrChildRecordIds
  * @param string  $strPrevious
  * @param string  $strNext
  *
  * @return string
  */
 protected function generateButtons($objRow, $arrRootIds = array(), $blnCircularReference = false, $arrChildRecordIds = null, $strPrevious = null, $strNext = null)
 {
     if (empty($this->arrDca['list']['operations'])) {
         return '';
     }
     $return = '';
     $dc = new DC_Table(\Config::get('fieldpalette_table'));
     $dc->id = $this->currentRecord;
     $dc->activeRecord = $objRow;
     foreach ($this->arrDca['list']['operations'] as $k => $v) {
         $v = is_array($v) ? $v : array($v);
         $id = specialchars(rawurldecode($objRow->id));
         $label = $v['label'][0] ?: $k;
         $title = sprintf($v['label'][1] ?: $k, $id);
         $attributes = $v['attributes'] != '' ? ltrim(sprintf($v['attributes'], $id, $id)) : '';
         $objButton = FieldPaletteButton::getInstance();
         $objButton->addOptions($this->arrButtonDefaults);
         $objButton->setType($k);
         $objButton->setId($objRow->id);
         $objButton->setModalTitle(sprintf($GLOBALS['TL_LANG']['tl_fieldpalette']['modalTitle'], $GLOBALS['TL_LANG'][$this->strTable][$this->strName][0] ?: $this->strName, sprintf($title, $objRow->id)));
         $objButton->setAttributes(array($attributes));
         $objButton->setLabel(\Image::getHtml($v['icon'], $label));
         $objButton->setTitle(specialchars($title));
         // Call a custom function instead of using the default button
         if (is_array($v['button_callback'])) {
             $this->import($v['button_callback'][0]);
             $return .= $this->{$v['button_callback'][0]}->{$v['button_callback'][1]}($objRow->row(), $objButton->getHref(), $label, $title, $v['icon'], $attributes, \Config::get('fieldpalette_table'), $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext, $dc);
             continue;
         } elseif (is_callable($v['button_callback'])) {
             $return .= $v['button_callback']($objRow->row(), $objButton->getHref(), $label, $title, $v['icon'], $attributes, \Config::get('fieldpalette_table'), $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext, $dc);
             continue;
         }
         // Generate all buttons except "move up" and "move down" buttons
         if ($k != 'move' && $v != 'move') {
             $return .= $objButton->generate();
             continue;
         }
         $arrDirections = array('up', 'down');
         $arrRootIds = is_array($arrRootIds) ? $arrRootIds : array($arrRootIds);
         foreach ($arrDirections as $dir) {
             $label = $GLOBALS['TL_LANG'][\Config::get('fieldpalette_table')][$dir][0] ?: $dir;
             $title = $GLOBALS['TL_LANG'][\Config::get('fieldpalette_table')][$dir][1] ?: $dir;
             $label = \Image::getHtml($dir . '.gif', $label);
             $href = $v['href'] ?: '&amp;act=move';
             if ($dir == 'up') {
                 $return .= (is_numeric($strPrevious) && (!in_array($objRow->id, $arrRootIds) || empty($this->arrDca['list']['sorting']['root'])) ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $objRow->id) . '&amp;sid=' . intval($strPrevious) . '" title="' . specialchars($title) . '"' . $attributes . '>' . $label . '</a> ' : \Image::getHtml('up_.gif')) . ' ';
                 continue;
             }
             $return .= (is_numeric($strNext) && (!in_array($objRow->id, $arrRootIds) || empty($this->arrDca['list']['sorting']['root'])) ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $objRow->id) . '&amp;sid=' . intval($strNext) . '" title="' . specialchars($title) . '"' . $attributes . '>' . $label . '</a> ' : \Image::getHtml('down_.gif')) . ' ';
         }
     }
     // Sort elements
     if (!$this->arrDca['config']['notSortable']) {
         $href = 'contao/main.php';
         $href .= '?do=' . \Input::get('do');
         $href .= '&amp;table=' . \Config::get('fieldpalette_table');
         $href .= '&amp;id=' . $objRow->id;
         $href .= '&amp;' . FieldPalette::$strTableRequestKey . '=' . $this->strTable;
         $href .= '&amp;' . FieldPalette::$strPaletteRequestKey . '=' . $this->strName;
         $href .= '&amp;rt=' . \RequestToken::get();
         $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG'][$this->strTable]['cut'][1], $objRow->id) . '" data-href="' . $href . '" data-id="' . $objRow->id . '" data-pid="' . $objRow->pid . '"');
     }
     return trim($return);
 }
 public static function getGenerateInternalCacheAction()
 {
     \RequestToken::initialize();
     return 'contao/main.php?do=maintenance&bic=1&rt=' . \RequestToken::get();
 }
예제 #21
0
};
/**
 * Contao Encryption class as a service.
 *
 * @return Encryption
 */
$container[Services::ENCRYPTION] = function () {
    return Encryption::getInstance();
};
/**
 * Request token as service.
 *
 * @return RequestToken
 */
$container[Services::REQUEST_TOKEN] = $container->share(function () {
    return RequestToken::getInstance();
});
// ---------------------------------------------------------------------------------------------------------------------
// Toolkit Dependency injection
//
// Toolkit provides an container implementation which based on container-interop/container-interop ContainerInterface.
// Instead of access Pimple in user land code it's recommend to depend on ContainerInterface. Since Contao 4.x is
// supported, an adapter to Symfony container based on ContainerInterface or the updated
// contao-community-alliance/dependency-injection implementation will be provided.
// ---------------------------------------------------------------------------------------------------------------------
/**
 * Get the container.
 *
 * @return ContainerInterface
 */
$container[Services::CONTAINER] = $container->share(function ($container) {
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $objTemplate = new \BackendTemplate('be_rsce_convert');
     $objTemplate->isActive = $this->isActive();
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex'];
     // Rebuild the index
     if (\Input::get('act') === 'rsce_convert') {
         // Check the request token
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
         $this->import('Database');
         $failedElements = array();
         $elementsCount = 0;
         $contentElements = \ContentModel::findBy(array(\ContentModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($contentElements && $contentElements->next()) {
             $html = $this->getHtmlFromElement($contentElements);
             if (!$html) {
                 $failedElements[] = array('content', $contentElements->id, $contentElements->type);
             } else {
                 $this->createInitialVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->Database->prepare('UPDATE ' . \ContentModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $contentElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->log('A new version of record "' . \ContentModel::getTable() . '.id=' . $contentElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $moduleElements = \ModuleModel::findBy(array(\ModuleModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($moduleElements && $moduleElements->next()) {
             $html = $this->getHtmlFromElement($moduleElements);
             if (!$html) {
                 $failedElements[] = array('module', $moduleElements->id, $moduleElements->type);
             } else {
                 $this->createInitialVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->Database->prepare('UPDATE ' . \ModuleModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $moduleElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->log('A new version of record "' . \ModuleModel::getTable() . '.id=' . $moduleElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $formElements = \FormFieldModel::findBy(array(\FormFieldModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($formElements && $formElements->next()) {
             $html = $this->getHtmlFromElement($formElements);
             if (!$html) {
                 $failedElements[] = array('form', $formElements->id, $formElements->type);
             } else {
                 $this->createInitialVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->Database->prepare('UPDATE ' . \FormFieldModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $formElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->log('A new version of record "' . \FormFieldModel::getTable() . '.id=' . $formElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         foreach ($failedElements as $element) {
             $this->log('Failed to convert ' . $element[0] . ' element ID ' . $element[1] . ' (' . $element[2] . ') to a standard HTML element', __METHOD__, TL_ERROR);
         }
         $this->log('Converted ' . $elementsCount . ' RockSolid Custom Elements to standard HTML elements', __METHOD__, TL_GENERAL);
         $objTemplate->elementsCount = $elementsCount;
         $objTemplate->failedElements = $failedElements;
     }
     $this->loadLanguageFile('rocksolid_custom_elements');
     return $objTemplate->parse();
 }
 public function processFormDataHook($arrSubmitted, $arrData, $arrFiles, $arrLabels, $objForm)
 {
     $formId = $objForm->formID != '' ? 'auto_' . $objForm->formID : 'auto_form_' . $objForm->id;
     // Get all form fields
     $arrFields = array();
     $objFields = \FormFieldModel::findPublishedByPid($objForm->id);
     // default order by sorting
     $strReturn = null;
     if ($objFields !== null) {
         $start = false;
         while ($objFields->next()) {
             if ($objFields->successType == 'successStart') {
                 $start = true;
             }
             if ($start || !$objForm->hideFormOnSuccess) {
                 $arrFields[] = $objFields->current();
             }
             if ($objFields->successType == 'successStop') {
                 $start = false;
                 // hideFormOnSuccess: do not render other fields than successStart, fields inside and successStop
                 if ($objForm->hideFormOnSuccess) {
                     break;
                 }
             }
         }
     }
     if (!empty($arrFields) && is_array($arrFields)) {
         $row = 0;
         $max_row = count($arrFields);
         foreach ($arrFields as $objField) {
             $strClass = $GLOBALS['TL_FFL'][$objField->type];
             // Continue if the class is not defined
             if (!class_exists($strClass)) {
                 continue;
             }
             $arrData = $objField->row();
             $arrData['decodeEntities'] = true;
             $arrData['allowHtml'] = $objForm->allowTags;
             $arrData['rowClass'] = 'row_' . $row . ($row == 0 ? ' row_first' : ($row == $max_row - 1 ? ' row_last' : '')) . ($row % 2 == 0 ? ' even' : ' odd');
             $arrData['tableless'] = $objForm->tableless;
             // Increase the row count if its a password field
             if ($objField->type == 'password') {
                 ++$row;
                 ++$max_row;
                 $arrData['rowClassConfirm'] = 'row_' . $row . ($row == $max_row - 1 ? ' row_last' : '') . ($row % 2 == 0 ? ' even' : ' odd');
             }
             // Submit buttons do not use the name attribute
             if ($objField->type == 'submit') {
                 $arrData['name'] = '';
             }
             // Unset the default value depending on the field type (see #4722)
             if (!empty($arrData['value'])) {
                 if (!in_array('value', trimsplit('[,;]', $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$objField->type]))) {
                     $arrData['value'] = '';
                 }
             }
             $objWidget = new $strClass($arrData);
             $objWidget->required = $objField->mandatory ? true : false;
             // HOOK: load form field callback
             if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) {
                 foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) {
                     $this->import($callback[0]);
                     $objWidget = $this->{$callback}[0]->{$callback}[1]($objWidget, $formId, $arrData, $objForm);
                 }
             }
             $strReturn .= $objWidget->parse();
             ++$row;
         }
     }
     if ($objForm->isAjaxForm && !is_null($strReturn)) {
         $strReturn .= '<input type="hidden" name="FORM_SUBMIT" value="' . $formId . '">';
         $strReturn .= '<input type="hidden" name="REQUEST_TOKEN" value="' . \RequestToken::get() . '">';
         die(\Controller::replaceInsertTags($strReturn));
     }
 }
예제 #24
0
파일: DC_Folder.php 프로젝트: eknoes/core
 /**
  * Initialize the object
  *
  * @param string $strTable
  */
 public function __construct($strTable)
 {
     parent::__construct();
     // Check the request token (see #4007)
     if (isset($_GET['act'])) {
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
     }
     $this->intId = \Input::get('id', true);
     // Clear the clipboard
     if (isset($_GET['clipboard'])) {
         $this->Session->set('CLIPBOARD', array());
         $this->redirect($this->getReferer());
     }
     // Check whether the table is defined
     if ($strTable == '' || !isset($GLOBALS['TL_DCA'][$strTable])) {
         $this->log('Could not load data container configuration for "' . $strTable . '"', __METHOD__, TL_ERROR);
         trigger_error('Could not load data container configuration', E_USER_ERROR);
     }
     // Check permission to create new folders
     if (\Input::get('act') == 'paste' && \Input::get('mode') == 'create' && isset($GLOBALS['TL_DCA'][$strTable]['list']['new'])) {
         $this->log('Attempt to create a new folder although the method has been overwritten in the data container', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     // Set IDs and redirect
     if (\Input::post('FORM_SUBMIT') == 'tl_select') {
         $ids = \Input::post('IDS');
         if (empty($ids) || !is_array($ids)) {
             $this->reload();
         }
         // Decode the values (see #5764)
         $ids = array_map('rawurldecode', $ids);
         $session = $this->Session->getData();
         $session['CURRENT']['IDS'] = $ids;
         $this->Session->setData($session);
         if (isset($_POST['edit'])) {
             $this->redirect(str_replace('act=select', 'act=editAll', \Environment::get('request')));
         } elseif (isset($_POST['delete'])) {
             $this->redirect(str_replace('act=select', 'act=deleteAll', \Environment::get('request')));
         } elseif (isset($_POST['cut']) || isset($_POST['copy'])) {
             $arrClipboard = $this->Session->get('CLIPBOARD');
             $arrClipboard[$strTable] = array('id' => $ids, 'mode' => isset($_POST['cut']) ? 'cutAll' : 'copyAll');
             $this->Session->set('CLIPBOARD', $arrClipboard);
             $this->redirect($this->getReferer());
         }
     }
     $this->strTable = $strTable;
     $this->blnIsDbAssisted = $GLOBALS['TL_DCA'][$strTable]['config']['databaseAssisted'];
     // Check for valid file types
     if ($GLOBALS['TL_DCA'][$this->strTable]['config']['validFileTypes']) {
         $this->arrValidFileTypes = trimsplit(',', strtolower($GLOBALS['TL_DCA'][$this->strTable]['config']['validFileTypes']));
     }
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($this);
             } elseif (is_callable($callback)) {
                 $callback($this);
             }
         }
     }
     // Get all filemounts (root folders)
     if (is_array($GLOBALS['TL_DCA'][$strTable]['list']['sorting']['root'])) {
         $this->arrFilemounts = $this->eliminateNestedPaths($GLOBALS['TL_DCA'][$strTable]['list']['sorting']['root']);
     }
 }
예제 #25
0
파일: initialize.php 프로젝트: rikaix/core
        }
    }
    unset($v);
}
/**
 * Include the custom initialization file
 */
if (file_exists(TL_ROOT . '/system/config/initconfig.php')) {
    include TL_ROOT . '/system/config/initconfig.php';
}
/**
 * Check the request token upon POST requests
 */
if ($_POST && !$GLOBALS['TL_CONFIG']['disableRefererCheck'] && !defined('BYPASS_TOKEN_CHECK')) {
    // Exit if the token cannot be validated
    if (!RequestToken::validate(Input::post('REQUEST_TOKEN'))) {
        // Force JavaScript redirect upon Ajax requests (IE requires absolute link)
        if (Environment::get('isAjaxRequest')) {
            echo '<script>location.replace("' . Environment::get('base') . 'contao/index.php")</script>';
        } else {
            // Send an error 400 header if it is not an Ajax request
            header('HTTP/1.1 400 Bad Request');
            if (file_exists(TL_ROOT . '/templates/be_referer.html5')) {
                include TL_ROOT . '/templates/be_referer.html5';
            } elseif (file_exists(TL_ROOT . '/system/modules/core/templates/be_referer.html5')) {
                include TL_ROOT . '/system/modules/core/templates/be_referer.html5';
            } else {
                echo 'Invalid request token. Please <a href="javascript:window.location.href=window.location.href">go back</a> and try again.';
            }
        }
        exit;
 protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     $strAction = $this->defaultAction ?: \Input::get('act');
     $this->arrEditable = deserialize($this->formHybridEditable, true);
     $this->strToken = $this->strToken ?: \Input::get('token');
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->classes) && is_array($this->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->classes);
     }
     $this->addDefaultArchive();
     // at first check for the correct request token to be set
     if (!$this->deactivateTokens && !\RequestToken::validate($this->strToken)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Url::replaceParameterInUri(Url::getUrl(), 'token', \RequestToken::get())), $this->id, 'requestTokenExpired');
         }
         return;
     }
     if ($this->formHybridAllowIdAsGetParameter) {
         $intId = \Input::get($this->formHybridIdGetParameter);
         if (is_numeric($intId)) {
             $this->intId = $intId;
         }
     }
     $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
     // get id from share
     if ($strShare = \Input::get('share')) {
         if (($objItem = $strItemClass::findByShareToken($strShare)) !== null && !FormHybridList::shareTokenExpiredOrEmpty($objItem, time())) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (isset($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior']) && is_array($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'])) {
             foreach ($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'] as $arrCallback) {
                 $this->import($arrCallback[0]);
                 if ($this->{$arrCallback}[0]->{$arrCallback}[1]($this) === false) {
                     return;
                 }
             }
         }
         if ($this->noIdBehavior == 'error') {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
             }
             return;
         } elseif ($this->noIdBehavior == 'redirect' || $this->noIdBehavior == 'create_until') {
             $arrConditions = deserialize($this->existanceConditions, true);
             if ($this->existanceConditions && !empty($arrConditions)) {
                 $arrColumns = array();
                 $arrValues = array();
                 foreach ($arrConditions as $arrCondition) {
                     if (!$arrCondition['field']) {
                         continue;
                     }
                     $arrColumns[] = $arrCondition['field'] . '=?';
                     $arrValues[] = $this->replaceInsertTags($arrCondition['value']);
                 }
                 if (!empty($arrColumns) && ($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) {
                     $this->intId = $objItem->id;
                 }
             }
         }
         if (!$this->intId) {
             if ($this->noIdBehavior == 'redirect') {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
                 }
                 return;
             } else {
                 $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id);
                 // get id from FormSession
                 if ($_POST) {
                     if ($intId = FormSession::getSubmissionId($strFormId)) {
                         $this->intId = $intId;
                     }
                 }
                 if (!$this->intId) {
                     // if no id is given a new instance is initiated
                     $objConfiguration = new FormConfiguration($this->arrData);
                     // ajax handling, required in this manor, as we have no real ajax controller in contao and ajax request not related to this module
                     // might trigger this module beforhand and new submission will be created after the submission was transfered to the user and id wont match any more
                     if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null) {
                         if ($intId = FormSession::getSubmissionId($strFormId)) {
                             $this->intId = $intId;
                         } else {
                             $objConfiguration->forceCreate = true;
                         }
                     }
                     $this->objForm = new $this->strFormClass($objConfiguration, $this->arrSubmitCallbacks, $this->intId ?: 0, $this);
                     if ($intId = $this->objForm->getId()) {
                         $this->intId = $intId;
                     }
                 }
             }
         }
     }
     // intId is set at this point!
     if (!$this->checkEntityExists($this->intId)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
         }
         if (Ajax::isRelated(Form::FORMHYBRID_NAME)) {
             $objResponse = new ResponseError();
             $objResponse->setResult(StatusMessage::generate($this->id));
             $objResponse->output();
         }
         return;
     }
     // page title
     if ($this->setPageTitle) {
         global $objPage;
         if (($objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId)) !== null) {
             $objPage->pageTitle = $objItem->{$this->pageTitleField};
         }
     }
     if ($strAction == FRONTENDEDIT_ACT_DELETE) {
         if ($this->checkDeletePermission($this->intId)) {
             $blnResult = $this->deleteItem($this->intId);
             if (\Environment::get('isAjaxRequest')) {
                 die($blnResult);
             }
             // return to the list
             \Controller::redirect(Url::removeQueryString(array('act', 'id', 'token'), Url::getUrl()));
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     } else {
         if ($this->checkUpdatePermission($this->intId)) {
             // create a new lock if necessary
             if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) {
                 if (\HeimrichHannot\EntityLock\EntityLockModel::isLocked($this->formHybridDataContainer, $this->intId, $this)) {
                     $objLock = \HeimrichHannot\EntityLock\EntityLockModel::findActiveLock($this->formHybridDataContainer, $this->intId, $this);
                     $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                     if (!$this->blnSilentMode) {
                         $strMessage = \HeimrichHannot\EntityLock\EntityLock::generateErrorMessage($this->formHybridDataContainer, $this->intId, $this);
                         if ($this->allowLockDeletion) {
                             $strUnlockForm = $this->generateUnlockForm($objItem, $objLock);
                             $strMessage .= $strUnlockForm;
                         }
                         StatusMessage::addError($strMessage, $this->id, 'locked');
                     }
                     if ($this->readOnlyOnLocked) {
                         $this->formHybridViewMode = FORMHYBRID_VIEW_MODE_READONLY;
                         $this->formHybridReadonlyTemplate = 'formhybridreadonly_default';
                     } else {
                         return;
                     }
                 } else {
                     \HeimrichHannot\EntityLock\EntityLockModel::create($this->formHybridDataContainer, $this->intId, $this);
                 }
             }
             if ($this->objForm === null) {
                 $this->objForm = new $this->strFormClass(new FormConfiguration($this->arrData), $this->arrSubmitCallbacks, $this->intId, $this);
             }
             $this->Template->form = $this->objForm->generate();
             $this->Template->item = $this->objForm->activeRecord;
             if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal') {
                 $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                 $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap');
                 if ($objItem !== null) {
                     $objModalWrapper->setData($objItem->row());
                 }
                 $objModalWrapper->module = Arrays::arrayToObject($this->arrData);
                 $objModalWrapper->item = $this->replaceInsertTags($this->Template->parse());
                 die($objModalWrapper->parse());
             }
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     }
 }
예제 #27
0
 /**
  * Initialize the object
  *
  * @param string $strTable
  * @param array  $arrModule
  */
 public function __construct($strTable, $arrModule = array())
 {
     parent::__construct();
     // Check the request token (see #4007)
     if (isset($_GET['act'])) {
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
     }
     $this->intId = \Input::get('id');
     // Clear the clipboard
     if (isset($_GET['clipboard'])) {
         $this->Session->set('CLIPBOARD', array());
         $this->redirect($this->getReferer());
     }
     // Check whether the table is defined
     if ($strTable == '' || !isset($GLOBALS['TL_DCA'][$strTable])) {
         $this->log('Could not load the data container configuration for "' . $strTable . '"', __METHOD__, TL_ERROR);
         trigger_error('Could not load the data container configuration', E_USER_ERROR);
     }
     // Set IDs and redirect
     if (\Input::post('FORM_SUBMIT') == 'tl_select') {
         $ids = \Input::post('IDS');
         if (empty($ids) || !is_array($ids)) {
             $this->reload();
         }
         $session = $this->Session->getData();
         $session['CURRENT']['IDS'] = $ids;
         $this->Session->setData($session);
         if (isset($_POST['edit'])) {
             $this->redirect(str_replace('act=select', 'act=editAll', \Environment::get('request')));
         } elseif (isset($_POST['delete'])) {
             $this->redirect(str_replace('act=select', 'act=deleteAll', \Environment::get('request')));
         } elseif (isset($_POST['override'])) {
             $this->redirect(str_replace('act=select', 'act=overrideAll', \Environment::get('request')));
         } elseif (isset($_POST['cut']) || isset($_POST['copy'])) {
             $arrClipboard = $this->Session->get('CLIPBOARD');
             $arrClipboard[$strTable] = array('id' => $ids, 'mode' => isset($_POST['cut']) ? 'cutAll' : 'copyAll');
             $this->Session->set('CLIPBOARD', $arrClipboard);
             // Support copyAll in the list view (see #7499)
             if (isset($_POST['copy']) && $GLOBALS['TL_DCA'][$strTable]['list']['sorting']['mode'] < 4) {
                 $this->redirect(str_replace('act=select', 'act=copyAll', \Environment::get('request')));
             }
             $this->redirect($this->getReferer());
         }
     }
     $this->strTable = $strTable;
     $this->ptable = $GLOBALS['TL_DCA'][$this->strTable]['config']['ptable'];
     $this->ctable = $GLOBALS['TL_DCA'][$this->strTable]['config']['ctable'];
     $this->treeView = in_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'], array(5, 6));
     $this->root = null;
     $this->arrModule = $arrModule;
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($this);
             } elseif (is_callable($callback)) {
                 $callback($this);
             }
         }
     }
     // Get the IDs of all root records (tree view)
     if ($this->treeView) {
         $table = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6 ? $this->ptable : $this->strTable;
         // Unless there are any root records specified, use all records with parent ID 0
         if (!isset($GLOBALS['TL_DCA'][$table]['list']['sorting']['root']) || $GLOBALS['TL_DCA'][$table]['list']['sorting']['root'] === false) {
             $objIds = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?" . ($this->Database->fieldExists('sorting', $table) ? ' ORDER BY sorting' : ''))->execute(0);
             if ($objIds->numRows > 0) {
                 $this->root = $objIds->fetchEach('id');
             }
         } elseif (is_array($GLOBALS['TL_DCA'][$table]['list']['sorting']['root'])) {
             $this->root = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$table]['list']['sorting']['root'], $table, $this->Database->fieldExists('sorting', $table));
         }
     } elseif (is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root'])) {
         $this->root = array_unique($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['root']);
     }
     // Store the current referer
     if (!empty($this->ctable) && !\Input::get('act') && !\Input::get('key') && !\Input::get('token') && TL_SCRIPT == 'contao/main.php' && !\Environment::get('isAjaxRequest')) {
         $session = $this->Session->get('referer');
         $session[TL_REFERER_ID][$this->strTable] = substr(\Environment::get('requestUri'), strlen(TL_PATH) + 1);
         $this->Session->set('referer', $session);
     }
 }
 public function addItemColumns($objItem, &$arrItem)
 {
     parent::addItemColumns($objItem, $arrItem);
     global $objPage;
     // edit
     if ($this->addEditCol) {
         $arrItem['addEditCol'] = true;
         $strUrl = $this->addAjaxPagination ? Url::getCurrentUrlWithoutParameters() : Url::getUrl();
         if (($objPageJumpTo = \PageModel::findByPk($this->jumpToEdit)) !== null && $this->jumpToEdit != $objPage->id) {
             $strUrl = \Controller::generateFrontendUrl($objPageJumpTo->row(), null, null, true);
         }
         $arrItem['editUrl'] = Url::addQueryString($this->formHybridIdGetParameter . '=' . $objItem->id . (!$this->deactivateTokens ? '&token=' . \RequestToken::get() : ''), $strUrl);
     }
     // delete url
     if ($this->addDeleteCol) {
         $arrItem['addDeleteCol'] = true;
         $arrItem['deleteUrl'] = Url::addQueryString($this->formHybridIdGetParameter . '=' . $objItem->id . '&act=delete' . (!$this->deactivateTokens ? '&token=' . \RequestToken::get() : ''), $this->addAjaxPagination ? Url::getCurrentUrlWithoutParameters() : Url::getUrl());
     }
     // publish url
     if ($this->addPublishCol) {
         $arrItem['addPublishCol'] = true;
         $arrItem['publishUrl'] = Url::addQueryString($this->formHybridIdGetParameter . '=' . $objItem->id . '&act=publish' . (!$this->deactivateTokens ? '&token=' . \RequestToken::get() : ''), $this->addAjaxPagination ? Url::getCurrentUrlWithoutParameters() : Url::getUrl());
     }
 }
예제 #29
0
 public static function getModalEditLink($strModule, $intId, $strLabel = null, $strTable = '')
 {
     if ($intId) {
         $strLabel = sprintf(specialchars($strLabel ?: $GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $intId);
         return sprintf(' <a href="contao/main.php?do=%s&amp;act=edit&amp;id=%s%s&amp;popup=1&amp;nb=1&amp;rt=%s" title="%s" ' . 'style="padding-left:3px" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s' . '\',\'url\':this.href});return false">%s</a>', $strModule, $intId, $strTable ? '&amp;table=' . $strTable : '', \RequestToken::get(), $strLabel, $strLabel, \Image::getHtml('alias.gif', $strLabel, 'style="vertical-align:top"'));
     }
 }
예제 #30
0
 protected function redirectAfterSubmission()
 {
     global $objPage;
     $blnRedirect = false;
     $strUrl = \Controller::generateFrontendUrl($objPage->row());
     if (($objTarget = \PageModel::findByPk($this->jumpTo)) !== null) {
         $blnRedirect = true;
         $strUrl = \Controller::generateFrontendUrl($objTarget->row(), null, null, true);
     }
     $arrPreserveParams = trimsplit(',', $this->jumpToPreserveParams);
     foreach ($arrPreserveParams as $strParam) {
         $varValue = \Input::get($strParam);
         if ($varValue === null) {
             continue;
         }
         switch ($strParam) {
             case 'token':
                 if ($this->deactivateTokens) {
                     break;
                 }
                 $strUrl = Url::addQueryString($strParam . '=' . \RequestToken::get(), $strUrl);
                 break;
             default:
                 $strUrl = Url::addQueryString($strParam . '=' . $varValue, $strUrl);
         }
     }
     if ($blnRedirect) {
         \HeimrichHannot\StatusMessages\StatusMessage::reset($this->objModule->id);
     }
     if ($this->async) {
         if ($blnRedirect) {
             $objResponse = new ResponseRedirect();
             $objResponse->setUrl($strUrl);
             $objResponse->output();
         }
         return;
     }
     if (!$blnRedirect) {
         if ($this->getReset()) {
             $this->reset(true);
         }
         return;
     }
     \Controller::redirect($strUrl);
 }