/** * {@inheritdoc} */ public function __get($strKey) { switch ($strKey) { case 'imageSize': // Check default routine first parent::__get($strKey); if ($this->isImage && empty($this->arrImageSize)) { $this->arrImageSize = @getimagesize(TL_ROOT . '/' . $this->strFile); //@todo this helps for psd files. what's about a pdf file? # if we want to use a ImageMagick function: add a static getImageSize() to IHook } return $this->arrImageSize; break; case 'isImage': return in_array($this->extension, trimsplit(',', \Config::get('validImageTypes'))); break; default: return parent::__get($strKey); break; } }
/** * Set the video image * * @param string $key * @param string $content */ public function setImage($key, $content) { $folder = new Folder(static::$imagesFolder); // Create the .htaccess file so images are accessible if (!is_file(TL_ROOT . '/' . $folder->path . '/.htaccess')) { $htaccessFile = new File($folder->path . '/.htaccess'); $htaccessFile->write("<IfModule !mod_authz_core.c>\r\nOrder allow,deny\r\nAllow from all\r\n</IfModule>\r\n<IfModule mod_authz_core.c>\r\n Require all granted\r\n</IfModule>"); $htaccessFile->close(); } $file = new \File($this->getImageFilePath($key)); $file->truncate(); $file->write($content); $file->close(); }
/** * Load the source editor * * @return string * * @throws InternalServerErrorException */ public function source() { $this->isValid($this->intId); if (is_dir(TL_ROOT . '/' . $this->intId)) { throw new InternalServerErrorException('Folder "' . $this->intId . '" cannot be edited.'); } elseif (!file_exists(TL_ROOT . '/' . $this->intId)) { throw new InternalServerErrorException('File "' . $this->intId . '" does not exist.'); } $this->import('BackendUser', 'User'); // Check user permission if (!$this->User->hasAccess('f5', 'fop')) { throw new AccessDeniedException('Not enough permissions to edit the file source of file "' . $this->intId . '".'); } $objFile = new \File($this->intId); // Check whether file type is editable if (!in_array($objFile->extension, trimsplit(',', \Config::get('editableFiles')))) { throw new AccessDeniedException('File type "' . $objFile->extension . '" (' . $this->intId . ') is not allowed to be edited.'); } $objMeta = null; $objVersions = null; // Add the versioning routines if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) { $objMeta = \FilesModel::findByPath($objFile->value); if ($objMeta === null) { $objMeta = \Dbafs::addResource($objFile->value); } $objVersions = new \Versions($this->strTable, $objMeta->id); if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) { // Compare versions if (\Input::get('versions')) { $objVersions->compare(); } // Restore a version if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') { $objVersions->restore(\Input::post('version')); // Purge the script cache (see #7005) if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') { $this->import('Automator'); $this->Automator->purgeScriptCache(); } $this->reload(); } } $objVersions->initialize(); } $strContent = $objFile->getContent(); if ($objFile->extension == 'svgz') { $strContent = gzdecode($strContent); } // Process the request if (\Input::post('FORM_SUBMIT') == 'tl_files') { // Restore the basic entities (see #7170) $strSource = \StringUtil::restoreBasicEntities(\Input::postRaw('source')); // Save the file if (md5($strContent) != md5($strSource)) { if ($objFile->extension == 'svgz') { $strSource = gzencode($strSource); } // Write the file $objFile->write($strSource); $objFile->close(); // Update the database if ($this->blnIsDbAssisted && $objMeta !== null) { /** @var FilesModel $objMeta */ $objMeta->hash = $objFile->hash; $objMeta->save(); $objVersions->create(); } // Purge the script cache (see #7005) if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') { $this->import('Automator'); $this->Automator->purgeScriptCache(); } } if (isset($_POST['saveNclose'])) { \System::setCookie('BE_PAGE_OFFSET', 0, 0); $this->redirect($this->getReferer()); } $this->reload(); } $codeEditor = ''; // Prepare the code editor if (\Config::get('useCE')) { /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_ace'); $objTemplate->selector = 'ctrl_source'; $objTemplate->type = $objFile->extension; $codeEditor = $objTemplate->parse(); } // Versions overview if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu'] && $this->blnIsDbAssisted && $objVersions !== null) { $version = $objVersions->renderDropdown(); } else { $version = ''; } // Submit buttons $arrButtons = array(); $arrButtons['save'] = '<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['save'] . '</button>'; $arrButtons['saveNclose'] = '<button type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['saveNclose'] . '</button>'; // Call the buttons_callback (see #4691) if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this); } elseif (is_callable($callback)) { $arrButtons = $callback($arrButtons, $this); } } } // Add the form return $version . ' <div id="tl_buttons"> <a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . \Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_files" class="tl_form" method="post"> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="tl_files"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <div class="tl_tbox"> <h3><label for="ctrl_source">' . $GLOBALS['TL_LANG']['tl_files']['editor'][0] . '</label></h3> <textarea name="source" id="ctrl_source" class="tl_textarea monospace" rows="12" cols="80" style="height:400px" onfocus="Backend.getScrollOffset()">' . "\n" . htmlspecialchars($strContent) . '</textarea>' . (\Config::get('showHelp') && strlen($GLOBALS['TL_LANG']['tl_files']['editor'][1]) ? ' <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_files']['editor'][1] . '</p>' : '') . ' </div> </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> ' . implode(' ', $arrButtons) . ' </div> </div> </form>' . "\n\n" . $codeEditor; }
/** * Export a theme * * @param DataContainer $dc */ public function exportTheme(DataContainer $dc) { // Get the theme meta data $objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")->limit(1)->execute($dc->id); if ($objTheme->numRows < 1) { return; } // Romanize the name $strName = Utf8::toAscii($objTheme->name); $strName = strtolower(str_replace(' ', '_', $strName)); $strName = preg_replace('/[^A-Za-z0-9._-]/', '', $strName); $strName = basename($strName); // Create a new XML document $xml = new \DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; // Root element $tables = $xml->createElement('tables'); $tables = $xml->appendChild($tables); // Add the tables $this->addTableTlTheme($xml, $tables, $objTheme); $this->addTableTlStyleSheet($xml, $tables, $objTheme); $this->addTableTlImageSize($xml, $tables, $objTheme); $this->addTableTlModule($xml, $tables, $objTheme); $this->addTableTlLayout($xml, $tables, $objTheme); // Generate the archive $strTmp = md5(uniqid(mt_rand(), true)); $objArchive = new \ZipWriter('system/tmp/' . $strTmp); // Add the files $this->addTableTlFiles($xml, $tables, $objTheme, $objArchive); // Add the template files $this->addTemplatesToArchive($objArchive, $objTheme->templates); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['exportTheme']) && is_array($GLOBALS['TL_HOOKS']['exportTheme'])) { foreach ($GLOBALS['TL_HOOKS']['exportTheme'] as $callback) { \System::importStatic($callback[0])->{$callback[1]}($xml, $objArchive, $objTheme->id); } } // Add the XML document $objArchive->addString($xml->saveXML(), 'theme.xml'); // Close the archive $objArchive->close(); // Open the "save as …" dialogue $objFile = new \File('system/tmp/' . $strTmp); $objFile->sendToBrowser($strName . '.cto'); }
/** * Send a file to the browser so the "save as …" dialogue opens * * @param string $strFile The file path */ public static function sendFileToBrowser($strFile) { // Make sure there are no attempts to hack the file system if (preg_match('@^\\.+@i', $strFile) || preg_match('@\\.+/@i', $strFile) || preg_match('@(://)+@i', $strFile)) { throw new PageNotFoundException('Invalid file name'); } // Limit downloads to the files directory if (!preg_match('@^' . preg_quote(\Config::get('uploadPath'), '@') . '@i', $strFile)) { throw new PageNotFoundException('Invalid path'); } // Check whether the file exists if (!file_exists(TL_ROOT . '/' . $strFile)) { throw new PageNotFoundException('File not found'); } $objFile = new \File($strFile); $arrAllowedTypes = trimsplit(',', strtolower(\Config::get('allowedDownload'))); // Check whether the file type is allowed to be downloaded if (!in_array($objFile->extension, $arrAllowedTypes)) { throw new AccessDeniedException(sprintf('File type "%s" is not allowed', $objFile->extension)); } // HOOK: post download callback if (isset($GLOBALS['TL_HOOKS']['postDownload']) && is_array($GLOBALS['TL_HOOKS']['postDownload'])) { foreach ($GLOBALS['TL_HOOKS']['postDownload'] as $callback) { static::importStatic($callback[0])->{$callback}[1]($strFile); } } // Send the file (will stop the script execution) $objFile->sendToBrowser(); }
private function compileModule($parameters, $bridgeNamespace, $module) { $file = new File($parameters['path'], true); $file->truncate(); $file->putContent($parameters['path'], '<?php ' . "\n" . "\n" . '/**' . "\n" . ' * DESCRIPTION' . "\n" . ' *' . "\n" . ' * Copyright (C) ORGANISE' . "\n" . ' *' . "\n" . ' * @package PACKAGE NAME' . "\n" . ' * @file ' . $module . '.php' . "\n" . ' * @author AUTHOR' . "\n" . ' * @license GNU/LGPL' . "\n" . ' * @copyright Copyright ' . Date::parse('Y', time()) . ' ORGANISE' . "\n" . ' */' . "\n" . "\n" . "\n" . 'namespace ' . $bridgeNamespace . ';' . "\n" . "\n" . 'class ' . $module . ' extends \\' . $bridgeNamespace . 'Bridge\\' . $module . "\n" . '{' . "\n" . '}'); }
/** * Rotate the log files * * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0. * Use the logger service instead, which rotates its log files automatically. */ public function rotateLogs() { @trigger_error('Using Automator::rotateLogs() has been deprecated and will no longer work in Contao 5.0. Use the logger service instead, which rotates its log files automatically.', E_USER_DEPRECATED); $arrFiles = preg_grep('/\\.log$/', scan(TL_ROOT . '/system/logs')); foreach ($arrFiles as $strFile) { $objFile = new \File('system/logs/' . $strFile . '.9'); // Delete the oldest file if ($objFile->exists()) { $objFile->delete(); } // Rotate the files (e.g. error.log.4 becomes error.log.5) for ($i = 8; $i > 0; $i--) { $strGzName = 'system/logs/' . $strFile . '.' . $i; if (file_exists(TL_ROOT . '/' . $strGzName)) { $objFile = new \File($strGzName); $objFile->renameTo('system/logs/' . $strFile . '.' . ($i + 1)); } } // Add .1 to the latest file $objFile = new \File('system/logs/' . $strFile); $objFile->renameTo('system/logs/' . $strFile . '.1'); } }
/** * Restore a version * * @param integer $intVersion */ public function restore($intVersion) { if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning']) { return; } $objData = $this->Database->prepare("SELECT * FROM tl_version WHERE fromTable=? AND pid=? AND version=?")->limit(1)->execute($this->strTable, $this->intPid, $intVersion); if ($objData->numRows < 1) { return; } $data = \StringUtil::deserialize($objData->data); if (!is_array($data)) { return; } // Restore the content if ($this->strPath !== null) { $objFile = new \File($this->strPath); $objFile->write($data['content']); $objFile->close(); } // Get the currently available fields $arrFields = array_flip($this->Database->getFieldNames($this->strTable)); // Unset fields that do not exist (see #5219) $data = array_intersect_key($data, $arrFields); $this->loadDataContainer($this->strTable); // Reset fields added after storing the version to their default value (see #7755) foreach (array_diff_key($arrFields, $data) as $k => $v) { $data[$k] = \Widget::getEmptyValueByFieldType($GLOBALS['TL_DCA'][$this->strTable]['fields'][$k]['sql']); } $this->Database->prepare("UPDATE " . $this->strTable . " %s WHERE id=?")->set($data)->execute($this->intPid); $this->Database->prepare("UPDATE tl_version SET active='' WHERE fromTable=? AND pid=?")->execute($this->strTable, $this->intPid); $this->Database->prepare("UPDATE tl_version SET active=1 WHERE fromTable=? AND pid=? AND version=?")->execute($this->strTable, $this->intPid, $intVersion); // Trigger the onrestore_version_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_version_callback'])) { foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_version_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->strTable, $this->intPid, $intVersion, $data); } elseif (is_callable($callback)) { $callback($this->strTable, $this->intPid, $intVersion, $data); } } } // Trigger the deprecated onrestore_callback if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'])) { @trigger_error('Using the onrestore_callback has been deprecated and will no longer work in Contao 5.0. Use the onrestore_version_callback instead.', E_USER_DEPRECATED); foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onrestore_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->intPid, $this->strTable, $data, $intVersion); } elseif (is_callable($callback)) { $callback($this->intPid, $this->strTable, $data, $intVersion); } } } $this->log('Version ' . $intVersion . ' of record "' . $this->strTable . '.id=' . $this->intPid . '" has been restored' . $this->getParentEntries($this->strTable, $this->intPid), __METHOD__, TL_GENERAL); }
/** * Run the controller and parse the template * * @return Response */ public function run() { if ($this->strFile == '') { die('No file given'); } // Make sure there are no attempts to hack the file system if (preg_match('@^\\.+@i', $this->strFile) || preg_match('@\\.+/@i', $this->strFile) || preg_match('@(://)+@i', $this->strFile)) { die('Invalid file name'); } // Limit preview to the files directory if (!preg_match('@^' . preg_quote(\Config::get('uploadPath'), '@') . '@i', $this->strFile)) { die('Invalid path'); } // Check whether the file exists if (!file_exists(TL_ROOT . '/' . $this->strFile)) { die('File not found'); } // Check whether the file is mounted (thanks to Marko Cupic) if (!$this->User->hasAccess($this->strFile, 'filemounts')) { die('Permission denied'); } // Open the download dialogue if (\Input::get('download')) { $objFile = new \File($this->strFile); $objFile->sendToBrowser(); } /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_popup'); // Add the resource (see #6880) if (($objModel = \FilesModel::findByPath($this->strFile)) === null) { if (\Dbafs::shouldBeSynchronized($this->strFile)) { $objModel = \Dbafs::addResource($this->strFile); } } if ($objModel !== null) { $objTemplate->uuid = \StringUtil::binToUuid($objModel->uuid); // see #5211 } // Add the file info if (is_dir(TL_ROOT . '/' . $this->strFile)) { $objFile = new \Folder($this->strFile); $objTemplate->filesize = $this->getReadableSize($objFile->size) . ' (' . number_format($objFile->size, 0, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']) . ' Byte)'; } else { $objFile = new \File($this->strFile); // Image if ($objFile->isImage) { $objTemplate->isImage = true; $objTemplate->width = $objFile->width; $objTemplate->height = $objFile->height; $objTemplate->src = $this->urlEncode($this->strFile); } $objTemplate->href = ampersand(\Environment::get('request'), true) . '&download=1'; $objTemplate->filesize = $this->getReadableSize($objFile->filesize) . ' (' . number_format($objFile->filesize, 0, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']) . ' Byte)'; } $objTemplate->icon = $objFile->icon; $objTemplate->mime = $objFile->mime; $objTemplate->ctime = \Date::parse(\Config::get('datimFormat'), $objFile->ctime); $objTemplate->mtime = \Date::parse(\Config::get('datimFormat'), $objFile->mtime); $objTemplate->atime = \Date::parse(\Config::get('datimFormat'), $objFile->atime); $objTemplate->path = specialchars($this->strFile); $objTemplate->theme = \Backend::getTheme(); $objTemplate->base = \Environment::get('base'); $objTemplate->language = $GLOBALS['TL_LANGUAGE']; $objTemplate->title = specialchars($this->strFile); $objTemplate->charset = \Config::get('characterSet'); $objTemplate->label_uuid = $GLOBALS['TL_LANG']['MSC']['fileUuid']; $objTemplate->label_imagesize = $GLOBALS['TL_LANG']['MSC']['fileImageSize']; $objTemplate->label_filesize = $GLOBALS['TL_LANG']['MSC']['fileSize']; $objTemplate->label_ctime = $GLOBALS['TL_LANG']['MSC']['fileCreated']; $objTemplate->label_mtime = $GLOBALS['TL_LANG']['MSC']['fileModified']; $objTemplate->label_atime = $GLOBALS['TL_LANG']['MSC']['fileAccessed']; $objTemplate->label_path = $GLOBALS['TL_LANG']['MSC']['filePath']; $objTemplate->download = specialchars($GLOBALS['TL_LANG']['MSC']['fileDownload']); return $objTemplate->getResponse(); }
/** * Create a new object to handle an image * * @param File $file A file instance of the original image * * @throws \InvalidArgumentException If the file does not exists or cannot be processed * * @deprecated Deprecated since Contao 4.3, to be removed in Contao 5.0. * Use the contao.image.image_factory service instead. */ public function __construct(File $file) { @trigger_error('Using new Contao\\Image() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED); // Check whether the file exists if (!$file->exists()) { // Handle public bundle resources if (file_exists(TL_ROOT . '/web/' . $file->path)) { $file = new \File('web/' . $file->path); } else { throw new \InvalidArgumentException('Image "' . $file->path . '" could not be found'); } } $this->fileObj = $file; $arrAllowedTypes = \StringUtil::trimsplit(',', strtolower(\Config::get('validImageTypes'))); // Check the file type if (!in_array($this->fileObj->extension, $arrAllowedTypes)) { throw new \InvalidArgumentException('Image type "' . $this->fileObj->extension . '" was not allowed to be processed'); } }
/** * @param $arrFeed * @return null */ protected function generateFiles($arrFeed) { $arrArchives = deserialize($arrFeed['wrappers']); if (!is_array($arrArchives) || empty($arrArchives)) { return null; } $strType = $arrFeed['format'] == 'atom' ? 'generateAtom' : 'generateRss'; $strLink = $arrFeed['feedBase'] ?: Environment::get('base'); $strFile = $arrFeed['feedName']; $objFeed = new \Feed($strFile); $objFeed->link = $strLink; $objFeed->title = $arrFeed['title']; $objFeed->description = $arrFeed['description']; $objFeed->language = $arrFeed['language']; $objFeed->published = $arrFeed['tstamp']; if ($arrFeed['maxItems'] > 0) { $objArticle = $this->findPublishedByPids($arrArchives, $arrFeed['maxItems'], $arrFeed['fmodule'] . '_data'); } else { $objArticle = $this->findPublishedByPids($arrArchives, 0, $arrFeed['fmodule'] . '_data'); } if ($objArticle !== null) { $arrUrls = array(); $strUrl = ''; while ($objArticle->next()) { $pid = $objArticle->pid; $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $arrFeed['fmodule'] . ' WHERE id = ?')->execute($pid)->row(); if ($wrapperDB['addDetailPage'] == '1') { $rootPage = $wrapperDB['rootPage']; if (!isset($arrUrls[$rootPage])) { $objParent = PageModel::findWithDetails($rootPage); if ($objParent === null) { $arrUrls[$rootPage] = false; } else { $arrUrls[$rootPage] = $this->generateFrontendUrl($objParent->row(), Config::get('useAutoItem') && !Config::get('disableAlias') ? '/%s' : '/items/%s', $objParent->language); } } $strUrl = $arrUrls[$rootPage]; } $authorName = ''; if ($objArticle->author) { $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($objArticle->author)->row(); $authorName = $authorDB['name']; } $objItem = new \FeedItem(); $objItem->title = $objArticle->title; $objItem->link = HelperModel::getLink($objArticle, $strUrl, $strLink); $objItem->published = $objArticle->date ? $objArticle->date : $arrFeed['tstamp']; $objItem->author = $authorName; // Prepare the description if ($arrFeed['source'] == 'source_text') { $strDescription = ''; $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'detail')); if ($objElement !== null) { // Overwrite the request (see #7756) $strRequest = Environment::get('request'); Environment::set('request', $objItem->link); while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->current()); } Environment::set('request', $strRequest); } } else { $strDescription = ''; $objElement = ContentModelExtend::findPublishedByPidAndTable($objArticle->id, $arrFeed['fmodule'] . '_data', array('fview' => 'list')); if ($objElement !== null) { // Overwrite the request (see #7756) $strRequest = Environment::get('request'); Environment::set('request', $objItem->link); while ($objElement->next()) { $strDescription .= $this->getContentElement($objElement->current()); } Environment::set('request', $strRequest); } if (!$strDescription) { $strDescription = $objArticle->description; } } $strDescription = $this->replaceInsertTags($strDescription, false); $objItem->description = $this->convertRelativeUrls($strDescription, $strLink); // Add the article image as enclosure if ($objArticle->addImage) { $objFile = \FilesModel::findByUuid($objArticle->singleSRC); if ($objFile !== null) { $objItem->addEnclosure($objFile->path); } } // Enclosures if ($objArticle->addEnclosure) { $arrEnclosure = deserialize($objArticle->enclosure, true); if (is_array($arrEnclosure)) { $objFile = \FilesModel::findMultipleByUuids($arrEnclosure); if ($objFile !== null) { while ($objFile->next()) { $objItem->addEnclosure($objFile->path); } } } } $objFeed->addItem($objItem); } } File::putContent('share/' . $strFile . '.xml', $this->replaceInsertTags($objFeed->{$strType}(), false)); }
/** * Rotate the log files */ public function rotateLogs() { $arrFiles = preg_grep('/\\.log$/', scan(TL_ROOT . '/system/logs')); foreach ($arrFiles as $strFile) { $objFile = new \File('system/logs/' . $strFile . '.9'); // Delete the oldest file if ($objFile->exists()) { $objFile->delete(); } // Rotate the files (e.g. error.log.4 becomes error.log.5) for ($i = 8; $i > 0; $i--) { $strGzName = 'system/logs/' . $strFile . '.' . $i; if (file_exists(TL_ROOT . '/' . $strGzName)) { $objFile = new \File($strGzName); $objFile->renameTo('system/logs/' . $strFile . '.' . ($i + 1)); } } // Add .1 to the latest file $objFile = new \File('system/logs/' . $strFile); $objFile->renameTo('system/logs/' . $strFile . '.1'); } }
/** * Generate the combined file and return its path * * @param string $strUrl An optional URL to prepend * * @return string The path to the combined file */ protected function getCombinedFileUrl($strUrl = null) { if ($strUrl === null) { $strUrl = TL_ASSETS_URL; } $strTarget = substr($this->strMode, 1); $strKey = substr(md5($this->strKey), 0, 12); // Load the existing file if (file_exists(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode)) { return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; } // Create the file $objFile = new \File('assets/' . $strTarget . '/' . $strKey . $this->strMode); $objFile->truncate(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // HOOK: modify the file content if (isset($GLOBALS['TL_HOOKS']['getCombinedFile']) && is_array($GLOBALS['TL_HOOKS']['getCombinedFile'])) { foreach ($GLOBALS['TL_HOOKS']['getCombinedFile'] as $callback) { $this->import($callback[0]); $content = $this->{$callback[0]}->{$callback[1]}($content, $strKey, $this->strMode, $arrFile); } } if ($arrFile['extension'] == self::CSS) { $content = $this->handleCss($content, $arrFile); } elseif ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $content = $this->handleScssLess($content, $arrFile); } $objFile->append($content); } unset($content); $objFile->close(); // Create a gzipped version if (\Config::get('gzipScripts') && function_exists('gzencode')) { \File::putContent('assets/' . $strTarget . '/' . $strKey . $this->strMode . '.gz', gzencode(file_get_contents(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode), 9)); } return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; }
/** * Create the local configuration files if they do not exist */ protected function createLocalConfigurationFiles() { if (\Config::get('installPassword') != '') { return; } // The localconfig.php file is created by the Config class foreach (array('dcaconfig', 'initconfig', 'langconfig') as $file) { if (!file_exists(TL_ROOT . '/system/config/' . $file . '.php')) { \File::putContent('system/config/' . $file . '.php', '<?php' . "\n\n// Put your custom configuration here\n"); } } }
/** * Generate the module */ protected function compile() { // Mark the x and y parameter as used (see #4277) if (isset($_GET['x'])) { \Input::get('x'); \Input::get('y'); } // Trigger the search module from a custom form if (!isset($_GET['keywords']) && \Input::post('FORM_SUBMIT') == 'tl_search') { $_GET['keywords'] = \Input::post('keywords'); $_GET['query_type'] = \Input::post('query_type'); $_GET['per_page'] = \Input::post('per_page'); } $blnFuzzy = $this->fuzzy; $strQueryType = \Input::get('query_type') ?: $this->queryType; $strKeywords = trim(\Input::get('keywords')); $this->Template->uniqueId = $this->id; $this->Template->queryType = $strQueryType; $this->Template->keyword = \StringUtil::specialchars($strKeywords); $this->Template->keywordLabel = $GLOBALS['TL_LANG']['MSC']['keywords']; $this->Template->optionsLabel = $GLOBALS['TL_LANG']['MSC']['options']; $this->Template->search = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['searchLabel']); $this->Template->matchAll = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['matchAll']); $this->Template->matchAny = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['matchAny']); $this->Template->action = ampersand(\Environment::get('indexFreeRequest')); $this->Template->advanced = $this->searchType == 'advanced'; // Redirect page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $this->Template->action = $objTarget->getFrontendUrl(); } $this->Template->pagination = ''; $this->Template->results = ''; // Execute the search if there are keywords if ($strKeywords != '' && $strKeywords != '*' && !$this->jumpTo) { // Reference page if ($this->rootPage > 0) { $intRootId = $this->rootPage; $arrPages = $this->Database->getChildRecords($this->rootPage, 'tl_page'); array_unshift($arrPages, $this->rootPage); } else { /** @var PageModel $objPage */ global $objPage; $intRootId = $objPage->rootId; $arrPages = $this->Database->getChildRecords($objPage->rootId, 'tl_page'); } // HOOK: add custom logic (see #5223) if (isset($GLOBALS['TL_HOOKS']['customizeSearch']) && is_array($GLOBALS['TL_HOOKS']['customizeSearch'])) { foreach ($GLOBALS['TL_HOOKS']['customizeSearch'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($arrPages, $strKeywords, $strQueryType, $blnFuzzy); } } // Return if there are no pages if (!is_array($arrPages) || empty($arrPages)) { return; } $strCachePath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', \System::getContainer()->getParameter('kernel.cache_dir')); $arrResult = null; $strChecksum = md5($strKeywords . $strQueryType . $intRootId . $blnFuzzy); $query_starttime = microtime(true); $strCacheFile = $strCachePath . '/contao/search/' . $strChecksum . '.json'; // Load the cached result if (file_exists(TL_ROOT . '/' . $strCacheFile)) { $objFile = new \File($strCacheFile); if ($objFile->mtime > time() - 1800) { $arrResult = json_decode($objFile->getContent(), true); } else { $objFile->delete(); } } // Cache the result if ($arrResult === null) { try { $objSearch = \Search::searchFor($strKeywords, $strQueryType == 'or', $arrPages, 0, 0, $blnFuzzy); $arrResult = $objSearch->fetchAllAssoc(); } catch (\Exception $e) { $this->log('Website search failed: ' . $e->getMessage(), __METHOD__, TL_ERROR); $arrResult = array(); } \File::putContent($strCacheFile, json_encode($arrResult)); } $query_endtime = microtime(true); // Sort out protected pages if (\Config::get('indexProtected') && !BE_USER_LOGGED_IN) { $this->import('FrontendUser', 'User'); foreach ($arrResult as $k => $v) { if ($v['protected']) { if (!FE_USER_LOGGED_IN) { unset($arrResult[$k]); } else { $groups = \StringUtil::deserialize($v['groups']); if (!is_array($groups) || empty($groups) || !count(array_intersect($groups, $this->User->groups))) { unset($arrResult[$k]); } } } } $arrResult = array_values($arrResult); } $count = count($arrResult); $this->Template->count = $count; $this->Template->page = null; $this->Template->keywords = $strKeywords; // No results if ($count < 1) { $this->Template->header = sprintf($GLOBALS['TL_LANG']['MSC']['sEmpty'], $strKeywords); $this->Template->duration = substr($query_endtime - $query_starttime, 0, 6) . ' ' . $GLOBALS['TL_LANG']['MSC']['seconds']; return; } $from = 1; $to = $count; // Pagination if ($this->perPage > 0) { $id = 'page_s' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; $per_page = \Input::get('per_page') ?: $this->perPage; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($count / $per_page), 1)) { throw new PageNotFoundException('Page not found: ' . \Environment::get('uri')); } $from = ($page - 1) * $per_page + 1; $to = $from + $per_page > $count ? $count : $from + $per_page - 1; // Pagination menu if ($to < $count || $from > 1) { $objPagination = new \Pagination($count, $per_page, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $this->Template->page = $page; } // Get the results for ($i = $from - 1; $i < $to && $i < $count; $i++) { /** @var FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->searchTpl); $objTemplate->url = $arrResult[$i]['url']; $objTemplate->link = $arrResult[$i]['title']; $objTemplate->href = $arrResult[$i]['url']; $objTemplate->title = \StringUtil::specialchars($arrResult[$i]['title']); $objTemplate->class = ($i == $from - 1 ? 'first ' : '') . ($i == $to - 1 || $i == $count - 1 ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd'); $objTemplate->relevance = sprintf($GLOBALS['TL_LANG']['MSC']['relevance'], number_format($arrResult[$i]['relevance'] / $arrResult[0]['relevance'] * 100, 2) . '%'); $objTemplate->filesize = $arrResult[$i]['filesize']; $objTemplate->matches = $arrResult[$i]['matches']; $arrContext = array(); $arrMatches = \StringUtil::trimsplit(',', $arrResult[$i]['matches']); // Get the context foreach ($arrMatches as $strWord) { $arrChunks = array(); preg_match_all('/(^|\\b.{0,' . $this->contextLength . '}\\PL)' . str_replace('+', '\\+', $strWord) . '(\\PL.{0,' . $this->contextLength . '}\\b|$)/ui', $arrResult[$i]['text'], $arrChunks); foreach ($arrChunks[0] as $strContext) { $arrContext[] = ' ' . $strContext . ' '; } } // Shorten the context and highlight all keywords if (!empty($arrContext)) { $objTemplate->context = trim(\StringUtil::substrHtml(implode('…', $arrContext), $this->totalLength)); $objTemplate->context = preg_replace('/(\\PL)(' . implode('|', $arrMatches) . ')(\\PL)/ui', '$1<mark class="highlight">$2</mark>$3', $objTemplate->context); $objTemplate->hasContext = true; } $this->Template->results .= $objTemplate->parse(); } $this->Template->header = vsprintf($GLOBALS['TL_LANG']['MSC']['sResults'], array($from, $to, $count, $strKeywords)); $this->Template->duration = substr($query_endtime - $query_starttime, 0, 6) . ' ' . $GLOBALS['TL_LANG']['MSC']['seconds']; } }
/** * Generate the combined file and return its path * * @param string $strUrl An optional URL to prepend * * @return string The path to the combined file */ public function getCombinedFile($strUrl = null) { if ($strUrl === null) { $strUrl = TL_ASSETS_URL; } $strTarget = substr($this->strMode, 1); $strKey = substr(md5($this->strKey), 0, 12); // Do not combine the files in debug mode (see #6450) if (\Config::get('debugMode')) { $return = array(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // Compile SCSS/LESS files into temporary files if ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $strPath = 'assets/' . $strTarget . '/' . str_replace('/', '_', $arrFile['name']) . $this->strMode; $objFile = new \File($strPath, true); $objFile->write($this->handleScssLess($content, $arrFile)); $objFile->close(); $return[] = $strPath; } else { $name = $arrFile['name']; // Add the media query (see #7070) if ($arrFile['media'] != '' && $arrFile['media'] != 'all' && strpos($content, '@media') === false) { $name .= '" media="' . $arrFile['media']; } $return[] = $name; } } if ($this->strMode == self::JS) { return implode('"></script><script src="', $return); } else { return implode('"><link rel="stylesheet" href="', $return); } } // Load the existing file if (file_exists(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode)) { return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; } // Create the file $objFile = new \File('assets/' . $strTarget . '/' . $strKey . $this->strMode, true); $objFile->truncate(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // HOOK: modify the file content if (isset($GLOBALS['TL_HOOKS']['getCombinedFile']) && is_array($GLOBALS['TL_HOOKS']['getCombinedFile'])) { foreach ($GLOBALS['TL_HOOKS']['getCombinedFile'] as $callback) { $this->import($callback[0]); $content = $this->{$callback}[0]->{$callback}[1]($content, $strKey, $this->strMode, $arrFile); } } if ($arrFile['extension'] == self::CSS) { $content = $this->handleCss($content, $arrFile); } elseif ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $content = $this->handleScssLess($content, $arrFile); } $objFile->append($content); } unset($content); $objFile->close(); // Create a gzipped version if (\Config::get('gzipScripts') && function_exists('gzencode')) { \File::putContent('assets/' . $strTarget . '/' . $strKey . $this->strMode . '.gz', gzencode(file_get_contents(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode), 9)); } return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; }
/** * @return string */ public function generate() { if (Input::get('key') != 'import' || !isset($_GET['id'])) { return ''; } $this->import('BackendUser', 'User'); $class = $this->User->uploader; // See #4086 and #7046 if (!class_exists($class) || $class == 'DropZone') { $class = 'FileUpload'; } /** @var \FileUpload $objUploader */ $objUploader = new $class(); // Import CSS if (Input::post('FORM_SUBMIT') == 'tl_iso_attribute_option_import') { $arrUploaded = $this->getUploads($objUploader); if (empty($arrUploaded)) { Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']); Controller::reload(); } foreach ($arrUploaded as $strFile) { if (is_dir(TL_ROOT . '/' . $strFile)) { Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['importFolder'], basename($strFile))); continue; } $objFile = new \File($strFile, true); $strContent = $objFile->getContent(); switch ($objFile->extension) { case 'json': $arrContent = json_decode($strContent, true); break; default: Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension)); continue; break; } if (!isset($arrContent) || !is_array($arrContent)) { \Message::addError('is no array'); Controller::reload(); return false; } if ($this->saveAttributeOptions($arrContent, Input::get('id'))) { // Redirect //\System::setCookie('BE_PAGE_OFFSET', 0, 0); //Controller::redirect(str_replace('&key=import', '', \Environment::get('request'))); } } } // Return form return ' <div id="tl_buttons"> <a href="' . ampersand(str_replace('&key=import', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a> </div> ' . Message::generate() . ' <form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_iso_attribute_option_import" class="tl_form" method="post" enctype="multipart/form-data"> <div class="tl_formbody_edit"> <input type="hidden" name="FORM_SUBMIT" value="tl_iso_attribute_option_import"> <input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '"> <input type="hidden" name="MAX_FILE_SIZE" value="' . \Config::get('maxFileSize') . '"> <div class="tl_tbox"> <h3>Import attribute options</h3>' . $objUploader->generateMarkup() . (isset($GLOBALS['TL_LANG']['tl_style_sheet']['source'][1]) ? ' <p class="tl_help tl_tip">234</p>' : '') . ' </div> </div> <div class="tl_formbody_submit"> <div class="tl_submit_container"> <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="import"> </div> </div> </form>'; }
/** * Add the template output to the cache and add the cache headers */ protected function addToCache() { /** @var PageModel $objPage */ global $objPage; $intCache = 0; // Decide whether the page shall be cached if (!isset($_GET['file']) && !isset($_GET['token']) && empty($_POST) && !BE_USER_LOGGED_IN && !FE_USER_LOGGED_IN && !$_SESSION['DISABLE_CACHE'] && !isset($_SESSION['LOGIN_ERROR']) && !\Message::hasMessages() && intval($objPage->cache) > 0 && !$objPage->protected) { $intCache = time() + intval($objPage->cache); } // Server-side cache if ($intCache > 0 && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'server')) { // If the request string is empty, use a special cache tag which considers the page language if (\Environment::get('relativeRequest') == '') { $strCacheKey = \Environment::get('host') . '/empty.' . $objPage->language; } else { $strCacheKey = \Environment::get('host') . '/' . \Environment::get('relativeRequest'); } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getCacheKey']) && is_array($GLOBALS['TL_HOOKS']['getCacheKey'])) { foreach ($GLOBALS['TL_HOOKS']['getCacheKey'] as $callback) { $this->import($callback[0]); $strCacheKey = $this->{$callback[0]}->{$callback[1]}($strCacheKey); } } // Add a suffix if there is a mobile layout (see #7826) if ($objPage->mobileLayout > 0) { if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') { $strCacheKey .= '.mobile'; } else { $strCacheKey .= '.desktop'; } } // Replace insert tags for caching $strBuffer = $this->replaceInsertTags($this->strBuffer); $strBuffer = $this->replaceDynamicScriptTags($strBuffer); // see #4203 // Add the cache file header $strHeader = sprintf("<?php /* %s */ \$expire = %d; \$content = %s; \$type = %s; \$files = %s; \$assets = %s; ?>\n", $strCacheKey, (int) $intCache, var_export($this->strContentType, true), var_export($objPage->type, true), var_export(TL_FILES_URL, true), var_export(TL_ASSETS_URL, true)); $strCachePath = str_replace(TL_ROOT . '/', '', \System::getContainer()->getParameter('kernel.cache_dir')); // Create the cache file $strMd5CacheKey = md5($strCacheKey); $objFile = new \File($strCachePath . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'); $objFile->write($strHeader); $objFile->append($this->minifyHtml($strBuffer), ''); $objFile->close(); } // Client-side cache if (!headers_sent()) { if ($intCache > 0 && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'browser')) { header('Cache-Control: private, max-age=' . ($intCache - time())); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', $intCache) . ' GMT'); } else { header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Expires: Fri, 06 Jun 1975 15:10:00 GMT'); } } }
/** * Update the cron.txt file * * @param integer $time */ protected function updateCronTxt($time) { \File::putContent('web/system/cron/cron.txt', $time); }
/** * Tests resizing an SVGZ image. */ public function testExecuteResizeSvgz() { file_put_contents(self::$rootDir . '/dummy.svgz', gzencode('<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="200px" height="100px" viewBox="100 100 400 200" ></svg>')); $file = new \File('dummy.svgz'); $imageObj = new Image($file); $imageObj->setTargetWidth(100)->setTargetHeight(100); $imageObj->executeResize(); $resultFile = new \File($imageObj->getResizedPath()); $this->assertEquals(100, $resultFile->width); $this->assertEquals(100, $resultFile->height); $doc = new \DOMDocument(); $doc->loadXML(gzdecode($resultFile->getContent())); $this->assertEquals('100 100 400 200', $doc->documentElement->firstChild->getAttribute('viewBox')); $this->assertEquals('-50', $doc->documentElement->firstChild->getAttribute('x')); $this->assertEquals('0', $doc->documentElement->firstChild->getAttribute('y')); $this->assertEquals('200', $doc->documentElement->firstChild->getAttribute('width')); $this->assertEquals('100', $doc->documentElement->firstChild->getAttribute('height')); }
/** * Ajax actions that do not require a data container object */ public function executePreActions() { /** @var AttributeBagInterface $objSessionBag */ $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend'); switch ($this->strAction) { // Toggle navigation menu case 'toggleNavigation': $bemod = $objSessionBag->get('backend_modules'); $bemod[\Input::post('id')] = intval(\Input::post('state')); $objSessionBag->set('backend_modules', $bemod); throw new NoContentResponseException(); // Load a navigation menu group // Load a navigation menu group case 'loadNavigation': $bemod = $objSessionBag->get('backend_modules'); $bemod[\Input::post('id')] = intval(\Input::post('state')); $objSessionBag->set('backend_modules', $bemod); $this->import('BackendUser', 'User'); /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_navigation'); $navigation = $this->User->navigation(); $objTemplate->modules = $navigation[\Input::post('id')]['modules']; throw new ResponseException($objTemplate->getResponse()); // Toggle nodes of the file or page tree // Toggle nodes of the file or page tree case 'toggleStructure': case 'toggleFileManager': case 'togglePagetree': case 'toggleFiletree': $this->strAjaxId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('id')); $this->strAjaxKey = str_replace('_' . $this->strAjaxId, '', \Input::post('id')); if (\Input::get('act') == 'editAll') { $this->strAjaxKey = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $this->strAjaxKey); $this->strAjaxName = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('name')); } $nodes = $objSessionBag->get($this->strAjaxKey); $nodes[$this->strAjaxId] = intval(\Input::post('state')); $objSessionBag->set($this->strAjaxKey, $nodes); throw new NoContentResponseException(); // Load nodes of the file or page tree // Load nodes of the file or page tree case 'loadStructure': case 'loadFileManager': case 'loadPagetree': case 'loadFiletree': $this->strAjaxId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('id')); $this->strAjaxKey = str_replace('_' . $this->strAjaxId, '', \Input::post('id')); if (\Input::get('act') == 'editAll') { $this->strAjaxKey = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $this->strAjaxKey); $this->strAjaxName = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('name')); } $nodes = $objSessionBag->get($this->strAjaxKey); $nodes[$this->strAjaxId] = intval(\Input::post('state')); $objSessionBag->set($this->strAjaxKey, $nodes); break; // Toggle the visibility of a fieldset // Toggle the visibility of a fieldset case 'toggleFieldset': $fs = $objSessionBag->get('fieldset_states'); $fs[\Input::post('table')][\Input::post('id')] = intval(\Input::post('state')); $objSessionBag->set('fieldset_states', $fs); throw new NoContentResponseException(); // Check whether the temporary directory is writeable // Check whether the temporary directory is writeable case 'liveUpdate': \Config::set('liveUpdateId', \Input::post('id')); \Config::persist('liveUpdateId', \Input::post('id')); // Check whether the temp directory is writeable try { $objFile = new \File('system/tmp/' . md5(uniqid(mt_rand(), true))); $objFile->close(); $objFile->delete(); } catch (\Exception $e) { if ($e->getCode() == 0) { \System::loadLanguageFile('tl_maintenance'); throw new ResponseException($this->convertToResponse('<p class="tl_error">' . $GLOBALS['TL_LANG']['tl_maintenance']['notWriteable'] . '</p>')); } } throw new NoContentResponseException(); // Toggle checkbox groups // Toggle checkbox groups case 'toggleCheckboxGroup': $state = $objSessionBag->get('checkbox_groups'); $state[\Input::post('id')] = intval(\Input::post('state')); $objSessionBag->set('checkbox_groups', $state); break; // HOOK: pass unknown actions to callback functions // HOOK: pass unknown actions to callback functions default: if (isset($GLOBALS['TL_HOOKS']['executePreActions']) && is_array($GLOBALS['TL_HOOKS']['executePreActions'])) { foreach ($GLOBALS['TL_HOOKS']['executePreActions'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($this->strAction); } } break; } }