本文整理汇总了PHP中StringUtil::trimsplit方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::trimsplit方法的具体用法?PHP StringUtil::trimsplit怎么用?PHP StringUtil::trimsplit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::trimsplit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Exempt folders from the synchronisation (see #4522)
*
* @param \RecursiveIterator $iterator The iterator object
*/
public function __construct(\RecursiveIterator $iterator)
{
if (\Config::get('fileSyncExclude') != '') {
$this->arrExempt = array_map(function ($e) {
return \Config::get('uploadPath') . '/' . $e;
}, \StringUtil::trimsplit(',', \Config::get('fileSyncExclude')));
}
parent::__construct($iterator);
}
示例2: generate
/**
* Change the palette of the current table and switch to edit mode
*
* @return string
*/
public function generate()
{
$this->import('BackendUser', 'User');
$GLOBALS['TL_DCA'][$this->table]['config']['closed'] = true;
$GLOBALS['TL_DCA'][$this->table]['config']['hideVersionMenu'] = true;
$GLOBALS['TL_DCA'][$this->table]['palettes'] = array('__selector__' => $GLOBALS['TL_DCA'][$this->table]['palettes']['__selector__'], 'default' => $GLOBALS['TL_DCA'][$this->table]['palettes']['login']);
$arrFields = \StringUtil::trimsplit('[,;]', $GLOBALS['TL_DCA'][$this->table]['palettes']['default']);
foreach ($arrFields as $strField) {
$GLOBALS['TL_DCA'][$this->table]['fields'][$strField]['exclude'] = false;
}
return $this->objDc->edit($this->User->id);
}
示例3: run
/**
* {@inheritdoc}
*/
public function run()
{
$statement = $this->connection->query("SELECT id, sections, sPosition FROM tl_layout WHERE sections!=''");
while (false !== ($layout = $statement->fetch(\PDO::FETCH_OBJ))) {
$sections = \StringUtil::trimsplit(',', $layout->sections);
if (!empty($sections) && is_array($sections)) {
$set = [];
foreach ($sections as $section) {
$set[$section] = ['title' => $section, 'id' => $section, 'template' => 'block_section', 'position' => $layout->sPosition];
}
$stmt = $this->connection->prepare('UPDATE tl_layout SET sections=:sections WHERE id=:id');
$stmt->execute([':sections' => serialize(array_values($set)), ':id' => $layout->id]);
}
}
$this->connection->query("ALTER TABLE `tl_layout` ADD `combineScripts` char(1) NOT NULL default ''");
$this->connection->query("UPDATE tl_layout SET combineScripts='1'");
}
示例4: generateMarkup
/**
* Generate the markup for the default uploader
*
* @return string
*/
public function generateMarkup()
{
// Maximum file size in MB
$intMaxSize = round($this->getMaximumUploadSize() / 1024 / 1024);
// String of accepted file extensions
$strAccepted = implode(',', array_map(function ($a) {
return '.' . $a;
}, \StringUtil::trimsplit(',', strtolower(\Config::get('uploadTypes')))));
// Add the scripts
$GLOBALS['TL_CSS'][] = 'assets/dropzone/css/dropzone.min.css';
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/dropzone/js/dropzone.min.js';
// Generate the markup
$return = '
<input type="hidden" name="action" value="fileupload">
<div class="fallback">
<input type="file" name="' . $this->strName . '[]" class="tl_upload_field" onfocus="Backend.getScrollOffset()" multiple>
</div>
<div class="dz-container">
<div class="dz-default dz-message">
<span>' . $GLOBALS['TL_LANG']['tl_files']['dropzone'] . '</span>
</div>
<div class="dropzone-previews"></div>
</div>
<script>
window.addEvent("domready", function() {
new Dropzone("#tl_files", {
paramName: "' . $this->strName . '",
maxFilesize: ' . $intMaxSize . ',
acceptedFiles: "' . $strAccepted . '",
previewsContainer: ".dropzone-previews",
uploadMultiple: true
}).on("drop", function() {
$$(".dz-message").setStyle("padding", "12px 18px 0");
});
$$("div.tl_formbody_submit").setStyle("display", "none");
});
</script>';
if (isset($GLOBALS['TL_LANG']['tl_files']['fileupload'][1])) {
$return .= '
<p class="tl_help tl_tip">' . sprintf($GLOBALS['TL_LANG']['tl_files']['fileupload'][1], \System::getReadableSize($this->getMaximumUploadSize()), \Config::get('gdMaxImgWidth') . 'x' . \Config::get('gdMaxImgHeight')) . '</p>';
}
return $return;
}
示例5: generate
/**
* Return if the file does not exist
*
* @return string
*/
public function generate()
{
// Return if there is no file
if ($this->singleSRC == '') {
return '';
}
$objFile = \FilesModel::findByUuid($this->singleSRC);
if ($objFile === null) {
return '';
}
$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Return if the file type is not allowed
if (!in_array($objFile->extension, $allowedDownload)) {
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFile->path) {
\Controller::sendFileToBrowser($file);
}
$this->singleSRC = $objFile->path;
return parent::generate();
}
示例6: generate
/**
* Generate the widget and return it as string
*
* @return string
*/
public function generate()
{
$arrSet = array();
$arrValues = array();
$blnHasOrder = $this->orderField != '' && is_array($this->{$this->orderField});
if (!empty($this->varValue)) {
$objFiles = \FilesModel::findMultipleByUuids((array) $this->varValue);
$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
if ($objFiles !== null) {
while ($objFiles->next()) {
// File system and database seem not in sync
if (!file_exists(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
$arrSet[$objFiles->id] = $objFiles->uuid;
// Show files and folders
if (!$this->isGallery && !$this->isDownloads) {
if ($objFiles->type == 'folder') {
$arrValues[$objFiles->uuid] = \Image::getHtml('folderC.svg') . ' ' . $objFiles->path;
} else {
$objFile = new \File($objFiles->path);
$strInfo = $objFiles->path . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
if ($objFile->isImage) {
$image = \Image::getPath('placeholder.svg');
if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
$image = \Image::get($objFiles->path, 80, 60, 'center_center');
}
$arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . \StringUtil::specialchars($strInfo) . '"');
} else {
$arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
}
}
} else {
if ($objFiles->type == 'folder') {
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
continue;
}
$objFile = new \File($objSubfiles->path);
$strInfo = '<span class="dirname">' . dirname($objSubfiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
if ($this->isGallery) {
// Only show images
if ($objFile->isImage) {
$image = \Image::getPath('placeholder.svg');
if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
$image = \Image::get($objSubfiles->path, 80, 60, 'center_center');
}
$arrValues[$objSubfiles->uuid] = \Image::getHtml($image, '', 'class="gimage" title="' . \StringUtil::specialchars($strInfo) . '"');
}
} else {
// Only show allowed download types
if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
$arrValues[$objSubfiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
}
}
}
} else {
$objFile = new \File($objFiles->path);
$strInfo = '<span class="dirname">' . dirname($objFiles->path) . '/</span>' . $objFile->basename . ' <span class="tl_gray">(' . $this->getReadableSize($objFile->size) . ($objFile->isImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
if ($this->isGallery) {
// Only show images
if ($objFile->isImage) {
$image = \Image::getPath('placeholder.svg');
if (($objFile->isSvgImage || $objFile->height <= \Config::get('gdMaxImgHeight') && $objFile->width <= \Config::get('gdMaxImgWidth')) && $objFile->viewWidth && $objFile->viewHeight) {
$image = \Image::get($objFiles->path, 80, 60, 'center_center');
}
$arrValues[$objFiles->uuid] = \Image::getHtml($image, '', 'class="gimage removable" title="' . \StringUtil::specialchars($strInfo) . '"');
}
} else {
// Only show allowed download types
if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
$arrValues[$objFiles->uuid] = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
}
}
}
}
}
}
// Apply a custom sort order
if ($blnHasOrder) {
$arrNew = array();
foreach ((array) $this->{$this->orderField} as $i) {
if (isset($arrValues[$i])) {
$arrNew[$i] = $arrValues[$i];
unset($arrValues[$i]);
}
}
if (!empty($arrValues)) {
foreach ($arrValues as $k => $v) {
$arrNew[$k] = $v;
//.........这里部分代码省略.........
示例7: __construct
/**
* 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
*/
public function __construct(File $file)
{
// 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');
}
}
示例8: getLayoutSections
/**
* Return all layout sections as array
*
* @return array
*/
public function getLayoutSections()
{
$arrCustom = array();
$arrSections = array('header', 'left', 'right', 'main', 'footer');
// Check for custom layout sections
$objLayout = $this->Database->query("SELECT sections FROM tl_layout WHERE sections!=''");
while ($objLayout->next()) {
$arrCustom = array_merge($arrCustom, StringUtil::trimsplit(',', $objLayout->sections));
}
$arrCustom = array_unique($arrCustom);
// Add the custom layout sections
if (!empty($arrCustom) && is_array($arrCustom)) {
$arrSections = array_merge($arrSections, $arrCustom);
}
return $arrSections;
}
示例9: uploadTo
/**
* Check the uploaded files and move them to the target directory
*
* @param string $strTarget
*
* @return array
*
* @throws \Exception
*/
public function uploadTo($strTarget)
{
if ($strTarget == '' || \Validator::isInsecurePath($strTarget)) {
throw new \InvalidArgumentException('Invalid target path ' . $strTarget);
}
$maxlength_kb = $this->getMaximumUploadSize();
$maxlength_kb_readable = $this->getReadableSize($maxlength_kb);
$arrUploaded = array();
$arrFiles = $this->getFilesFromGlobal();
foreach ($arrFiles as $file) {
// Sanitize the filename
try {
$file['name'] = \StringUtil::sanitizeFileName($file['name']);
} catch (\InvalidArgumentException $e) {
\Message::addError($GLOBALS['TL_LANG']['ERR']['filename']);
$this->blnHasError = true;
continue;
}
// Invalid file name
if (!\Validator::isValidFileName($file['name'])) {
\Message::addError($GLOBALS['TL_LANG']['ERR']['filename']);
$this->blnHasError = true;
} elseif (!is_uploaded_file($file['tmp_name'])) {
if ($file['error'] == 1 || $file['error'] == 2) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filesize'], $maxlength_kb_readable));
$this->log('File "' . $file['name'] . '" exceeds the maximum file size of ' . $maxlength_kb_readable, __METHOD__, TL_ERROR);
$this->blnHasError = true;
} elseif ($file['error'] == 3) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filepartial'], $file['name']));
$this->log('File "' . $file['name'] . '" was only partially uploaded', __METHOD__, TL_ERROR);
$this->blnHasError = true;
} elseif ($file['error'] > 0) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['fileerror'], $file['error'], $file['name']));
$this->log('File "' . $file['name'] . '" could not be uploaded (error ' . $file['error'] . ')', __METHOD__, TL_ERROR);
$this->blnHasError = true;
}
} elseif ($file['size'] > $maxlength_kb) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filesize'], $maxlength_kb_readable));
$this->log('File "' . $file['name'] . '" exceeds the maximum file size of ' . $maxlength_kb_readable, __METHOD__, TL_ERROR);
$this->blnHasError = true;
} else {
$strExtension = strtolower(substr($file['name'], strrpos($file['name'], '.') + 1));
// File type not allowed
if (!in_array($strExtension, \StringUtil::trimsplit(',', strtolower(\Config::get('uploadTypes'))))) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $strExtension));
$this->log('File type "' . $strExtension . '" is not allowed to be uploaded (' . $file['name'] . ')', __METHOD__, TL_ERROR);
$this->blnHasError = true;
} else {
$this->import('Files');
$strNewFile = $strTarget . '/' . $file['name'];
// Set CHMOD and resize if neccessary
if ($this->Files->move_uploaded_file($file['tmp_name'], $strNewFile)) {
$this->Files->chmod($strNewFile, \Config::get('defaultFileChmod'));
$blnResized = $this->resizeUploadedImage($strNewFile);
// Notify the user
if (!$blnResized) {
\Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['MSC']['fileUploaded'], $file['name']));
$this->log('File "' . $file['name'] . '" uploaded successfully', __METHOD__, TL_FILES);
}
$arrUploaded[] = $strNewFile;
}
}
}
}
return $arrUploaded;
}
示例10: createDefinition
/**
* Create a format definition and insert it into the database
*
* @param array $arrDefinition
*/
protected function createDefinition($arrDefinition)
{
$arrSet = array('pid' => $arrDefinition['pid'], 'sorting' => $arrDefinition['sorting'], 'tstamp' => time(), 'comment' => $arrDefinition['comment'], 'category' => $arrDefinition['category'], 'selector' => $arrDefinition['selector']);
$arrAttributes = \StringUtil::trimsplit(';', $arrDefinition['attributes']);
foreach ($arrAttributes as $strDefinition) {
// Skip empty definitions
if (trim($strDefinition) == '') {
continue;
}
// Handle keywords, variables and functions (see #7448)
if (strpos($strDefinition, 'important') !== false || strpos($strDefinition, 'transparent') !== false || strpos($strDefinition, 'inherit') !== false || strpos($strDefinition, '$') !== false || strpos($strDefinition, '(') !== false) {
$arrSet['own'][] = $strDefinition;
continue;
}
$arrChunks = array_map('trim', explode(':', $strDefinition, 2));
$strKey = strtolower($arrChunks[0]);
switch ($strKey) {
case 'width':
case 'height':
if ($arrChunks[1] == 'auto') {
$strUnit = '';
$varValue = 'auto';
} else {
$strUnit = preg_replace('/[^acehimnprtvwx%]/', '', $arrChunks[1]);
$varValue = preg_replace('/[^0-9.-]+/', '', $arrChunks[1]);
}
$arrSet['size'] = 1;
$arrSet[$strKey]['value'] = $varValue;
$arrSet[$strKey]['unit'] = $strUnit;
break;
case 'min-width':
case 'min-height':
$strName = str_replace('-', '', $strKey);
if ($arrChunks[1] == 'inherit') {
$strUnit = '';
$varValue = 'inherit';
} else {
$strUnit = preg_replace('/[^acehimnprtvwx%]/', '', $arrChunks[1]);
$varValue = preg_replace('/[^0-9.-]+/', '', $arrChunks[1]);
}
$arrSet['size'] = 1;
$arrSet[$strName]['value'] = $varValue;
$arrSet[$strName]['unit'] = $strUnit;
break;
case 'max-width':
case 'max-height':
$strName = str_replace('-', '', $strKey);
if ($arrChunks[1] == 'inherit' || $arrChunks[1] == 'none') {
$strUnit = '';
$varValue = $arrChunks[1];
} else {
$strUnit = preg_replace('/[^acehimnprtvwx%]/', '', $arrChunks[1]);
$varValue = preg_replace('/[^0-9.-]+/', '', $arrChunks[1]);
}
$arrSet['size'] = 1;
$arrSet[$strName]['value'] = $varValue;
$arrSet[$strName]['unit'] = $strUnit;
break;
case 'top':
case 'right':
case 'bottom':
case 'left':
if ($arrChunks[1] == 'auto') {
$strUnit = '';
$varValue = 'auto';
} elseif (isset($arrSet['trbl']['unit'])) {
$arrSet['own'][] = $strDefinition;
break;
} else {
$strUnit = preg_replace('/[^acehimnprtvwx%]/', '', $arrChunks[1]);
$varValue = preg_replace('/[^0-9.-]+/', '', $arrChunks[1]);
}
$arrSet['positioning'] = 1;
$arrSet['trbl'][$strKey] = $varValue;
if ($strUnit != '') {
$arrSet['trbl']['unit'] = $strUnit;
}
break;
case 'position':
case 'overflow':
case 'clear':
case 'display':
$arrSet['positioning'] = 1;
$arrSet[$strKey] = $arrChunks[1];
break;
case 'float':
$arrSet['positioning'] = 1;
$arrSet['floating'] = $arrChunks[1];
break;
case 'margin':
case 'padding':
$arrSet['alignment'] = 1;
$arrTRBL = preg_split('/\\s+/', $arrChunks[1]);
$arrUnits = array();
switch (count($arrTRBL)) {
//.........这里部分代码省略.........
示例11: isFileSyncExclude
/**
* Check if a file or folder is excluded from synchronization
*
* @param string $strPath The relative path
*
* @return bool True if the file or folder is excluded from synchronization
*/
protected static function isFileSyncExclude($strPath)
{
if (\Config::get('uploadPath') == 'templates') {
return true;
}
if (is_file(TL_ROOT . '/' . $strPath)) {
$strPath = dirname($strPath);
}
// Outside the files directory
if (strncmp($strPath . '/', \Config::get('uploadPath') . '/', strlen(\Config::get('uploadPath')) + 1) !== 0) {
return true;
}
// Check the excluded folders
if (\Config::get('fileSyncExclude') != '') {
$arrExempt = array_map(function ($e) {
return \Config::get('uploadPath') . '/' . $e;
}, \StringUtil::trimsplit(',', \Config::get('fileSyncExclude')));
foreach ($arrExempt as $strExempt) {
if (strncmp($strExempt . '/', $strPath . '/', strlen($strExempt) + 1) === 0) {
return true;
}
}
}
return false;
}
示例12: getActiveLayoutSections
/**
* Return all active layout sections as array
*
* @param DataContainer $dc
*
* @return array
*/
public function getActiveLayoutSections(DataContainer $dc)
{
// Show only active sections
if ($dc->activeRecord->pid) {
$arrSections = array();
$objPage = PageModel::findWithDetails($dc->activeRecord->pid);
// Get the layout sections
foreach (array('layout', 'mobileLayout') as $key) {
if (!$objPage->{$key}) {
continue;
}
$objLayout = LayoutModel::findByPk($objPage->{$key});
if ($objLayout === null) {
continue;
}
$arrModules = StringUtil::deserialize($objLayout->modules);
if (empty($arrModules) || !is_array($arrModules)) {
continue;
}
// Find all sections with an article module (see #6094)
foreach ($arrModules as $arrModule) {
if ($arrModule['mod'] == 0 && $arrModule['enable']) {
$arrSections[] = $arrModule['col'];
}
}
}
} else {
$arrSections = array('header', 'left', 'right', 'main', 'footer');
$objLayout = $this->Database->query("SELECT sections FROM tl_layout WHERE sections!=''");
while ($objLayout->next()) {
$arrCustom = StringUtil::trimsplit(',', $objLayout->sections);
// Add the custom layout sections
if (!empty($arrCustom) && is_array($arrCustom)) {
$arrSections = array_merge($arrSections, $arrCustom);
}
}
}
return array_values(array_unique($arrSections));
}
示例13: getDbInstallerArray
/**
* Return an array that can be used by the database installer
*
* @return array The data array
*/
public function getDbInstallerArray()
{
$return = array();
// Fields
foreach ($this->arrFields as $k => $v) {
if (is_array($v)) {
if (!isset($v['name'])) {
$v['name'] = $k;
}
$return['SCHEMA_FIELDS'][$k] = $v;
} else {
$return['TABLE_FIELDS'][$k] = '`' . $k . '` ' . $v;
}
}
$quote = function ($item) {
return '`' . $item . '`';
};
// Keys
foreach ($this->arrKeys as $k => $v) {
// Handle multi-column indexes (see #5556)
if (strpos($k, ',') !== false) {
$f = array_map($quote, \StringUtil::trimsplit(',', $k));
$k = str_replace(',', '_', $k);
} else {
$f = array($quote($k));
}
// Handle key lengths (see #221)
if (preg_match('/\\([0-9]+\\)/', $v)) {
list($v, $length) = explode('(', rtrim($v, ')'));
$f = array($quote($k) . '(' . $length . ')');
}
if ($v == 'primary') {
$k = 'PRIMARY';
$v = 'PRIMARY KEY (' . implode(', ', $f) . ')';
} elseif ($v == 'index') {
$v = 'KEY `' . $k . '` (' . implode(', ', $f) . ')';
} else {
$v = strtoupper($v) . ' KEY `' . $k . '` (' . implode(', ', $f) . ')';
}
$return['TABLE_CREATE_DEFINITIONS'][$k] = $v;
}
$return['TABLE_OPTIONS'] = '';
// Options
foreach ($this->arrMeta as $k => $v) {
if ($k == 'engine') {
$return['TABLE_OPTIONS'] .= ' ENGINE=' . $v;
} elseif ($k == 'charset') {
$return['TABLE_OPTIONS'] .= ' DEFAULT CHARSET=' . $v;
}
}
return $return;
}
示例14: addNewTemplate
/**
* Create a new template
*
* @return string
*/
public function addNewTemplate()
{
$arrAllTemplates = array();
$arrAllowed = StringUtil::trimsplit(',', strtolower(Config::get('templateFiles')));
/** @var SplFileInfo[] $files */
$files = System::getContainer()->get('contao.resource_finder')->findIn('templates')->files()->name('/\\.(' . implode('|', $arrAllowed) . ')$/');
foreach ($files as $file) {
$strRelpath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', $file->getPathname());
$strModule = preg_replace('@^(vendor|system/modules)/([^/]+(/.*-bundle)?)/.*$@', '$2', strtr($strRelpath, '\\', '/'));
$arrAllTemplates[$strModule][$strRelpath] = basename($strRelpath);
}
$strError = '';
// Copy an existing template
if (Input::post('FORM_SUBMIT') == 'tl_create_template') {
$strOriginal = Input::post('original', true);
if (Validator::isInsecurePath($strOriginal)) {
throw new RuntimeException('Invalid path ' . $strOriginal);
}
$strTarget = Input::post('target', true);
if (Validator::isInsecurePath($strTarget)) {
throw new RuntimeException('Invalid path ' . $strTarget);
}
// Validate the target path
if (strncmp($strTarget, 'templates', 9) !== 0 || !is_dir(TL_ROOT . '/' . $strTarget)) {
$strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['invalid'], $strTarget);
} else {
$blnFound = false;
// Validate the source path
foreach ($arrAllTemplates as $arrTemplates) {
if (isset($arrTemplates[$strOriginal])) {
$blnFound = true;
break;
}
}
if (!$blnFound) {
$strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['invalid'], $strOriginal);
} else {
$strTarget .= '/' . basename($strOriginal);
// Check whether the target file exists
if (file_exists(TL_ROOT . '/' . $strTarget)) {
$strError = sprintf($GLOBALS['TL_LANG']['tl_templates']['exists'], $strTarget);
} else {
$this->import('Files');
$this->Files->copy($strOriginal, $strTarget);
$this->redirect($this->getReferer());
}
}
}
}
$strAllTemplates = '';
// Group the templates by module
foreach ($arrAllTemplates as $k => $v) {
$strAllTemplates .= '<optgroup label="' . $k . '">';
foreach ($v as $kk => $vv) {
$strAllTemplates .= sprintf('<option value="%s"%s>%s</option>', $kk, Input::post('original') == $kk ? ' selected="selected"' : '', $vv);
}
$strAllTemplates .= '</optgroup>';
}
// Show form
return '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>' . ($strError != '' ? '
<div class="tl_message">
<p class="tl_error">' . $strError . '</p>
</div>' : '') . '
<form action="' . ampersand(Environment::get('request')) . '" id="tl_create_template" class="tl_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_create_template">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<fieldset class="tl_tbox nolegend">
<div>
<h3><label for="ctrl_original">' . $GLOBALS['TL_LANG']['tl_templates']['original'][0] . '</label></h3>
<select name="original" id="ctrl_original" class="tl_select tl_chosen" onfocus="Backend.getScrollOffset()">' . $strAllTemplates . '</select>' . ($GLOBALS['TL_LANG']['tl_templates']['original'][1] && Config::get('showHelp') ? '
<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_templates']['original'][1] . '</p>' : '') . '
</div>
<div>
<h3><label for="ctrl_target">' . $GLOBALS['TL_LANG']['tl_templates']['target'][0] . '</label></h3>
<select name="target" id="ctrl_target" class="tl_select" onfocus="Backend.getScrollOffset()"><option value="templates">templates</option>' . $this->getTargetFolders('templates') . '</select>' . ($GLOBALS['TL_LANG']['tl_templates']['target'][1] && Config::get('showHelp') ? '
<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['tl_templates']['target'][1] . '</p>' : '') . '
</div>
</fieldset>
</div>
<div class="tl_formbody_submit">
<div class="tl_submit_container">
<button type="submit" name="create" id="create" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['tl_templates']['newTpl'] . '</button>
</div>
</div>
</form>';
}
示例15: compile
/**
* Generate the content element
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$files = array();
$auxDate = array();
$objFiles = $this->objFiles;
$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Get all files
while ($objFiles->next()) {
// Continue if the files has been processed or does not exist
if (isset($files[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
// Single files
if ($objFiles->type == 'file') {
$objFile = new \File($objFiles->path);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = $this->getMetaData($objFiles->meta, $objPage->language);
if (empty($arrMeta)) {
if ($this->metaIgnore) {
continue;
} elseif ($objPage->rootFallbackLanguage !== null) {
$arrMeta = $this->getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
}
}
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFiles->path);
// Add the image
$files[$objFiles->path] = array('id' => $objFiles->id, 'uuid' => $objFiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
} else {
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
continue;
}
$objFile = new \File($objSubfiles->path);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->language);
if (empty($arrMeta)) {
if ($this->metaIgnore) {
continue;
} elseif ($objPage->rootFallbackLanguage !== null) {
$arrMeta = $this->getMetaData($objSubfiles->meta, $objPage->rootFallbackLanguage);
}
}
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objSubfiles->path);
// Add the image
$files[$objSubfiles->path] = array('id' => $objSubfiles->id, 'uuid' => $objSubfiles->uuid, 'name' => $objFile->basename, 'title' => \StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename)), 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => $this->getReadableSize($objFile->filesize, 1), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
}
}
}
// Sort array
switch ($this->sortBy) {
default:
case 'name_asc':
uksort($files, 'basename_natcasecmp');
break;
case 'name_desc':
uksort($files, 'basename_natcasercmp');
break;
case 'date_asc':
array_multisort($files, SORT_NUMERIC, $auxDate, SORT_ASC);
break;
case 'date_desc':
array_multisort($files, SORT_NUMERIC, $auxDate, SORT_DESC);
break;
// Deprecated since Contao 4.0, to be removed in Contao 5.0
// Deprecated since Contao 4.0, to be removed in Contao 5.0
case 'meta':
//.........这里部分代码省略.........