本文整理汇总了PHP中Contao\StringUtil::trimsplit方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::trimsplit方法的具体用法?PHP StringUtil::trimsplit怎么用?PHP StringUtil::trimsplit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contao\StringUtil
的用法示例。
在下文中一共展示了StringUtil::trimsplit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['rssReader'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->objFeed = new \SimplePie();
$arrUrls = \StringUtil::trimsplit('[\\n\\t ]', trim($this->rss_feed));
if (count($arrUrls) > 1) {
$this->objFeed->set_feed_url($arrUrls);
} else {
$this->objFeed->set_feed_url($arrUrls[0]);
}
$this->objFeed->set_output_encoding(\Config::get('characterSet'));
$this->objFeed->set_cache_location(TL_ROOT . '/system/tmp');
$this->objFeed->enable_cache(false);
if ($this->rss_cache > 0) {
$this->objFeed->enable_cache(true);
$this->objFeed->set_cache_duration($this->rss_cache);
}
if (!$this->objFeed->init()) {
$this->log('Error importing RSS feed "' . $this->rss_feed . '"', __METHOD__, TL_ERROR);
return '';
}
$this->objFeed->handle_content_type();
return parent::generate();
}
示例2: __construct
/**
* Initialize the object
*
* @param string $strTable
* @param integer $intPid
*/
public function __construct($strTable, $intPid)
{
$this->import('Database');
parent::__construct();
$this->strTable = $strTable;
$this->intPid = $intPid;
// Store the path if it is an editable file
if ($strTable == 'tl_files') {
$objFile = \FilesModel::findByPk($intPid);
if ($objFile !== null && in_array($objFile->extension, \StringUtil::trimsplit(',', strtolower(\Config::get('editableFiles'))))) {
$this->strPath = $objFile->path;
}
}
}
示例3: executePostActions
//.........这里部分代码省略.........
$objRow = null;
$varValue = null;
// Load the value
if (\Input::get('act') != 'overrideAll') {
if ($GLOBALS['TL_DCA'][$dc->table]['config']['dataContainer'] == 'File') {
$varValue = \Config::get($strField);
} elseif ($intId > 0 && $this->Database->tableExists($dc->table)) {
$objRow = $this->Database->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")->execute($intId);
// The record does not exist
if ($objRow->numRows < 1) {
$this->log('A record with the ID "' . $intId . '" does not exist in table "' . $dc->table . '"', __METHOD__, TL_ERROR);
throw new BadRequestHttpException('Bad request');
}
$varValue = $objRow->{$strField};
$dc->activeRecord = $objRow;
}
}
// Call the load_callback
if (is_array($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'])) {
foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]['load_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $dc);
} elseif (is_callable($callback)) {
$varValue = $callback($varValue, $dc);
}
}
}
// Set the new value
$varValue = \Input::post('value', true);
$strKey = $this->strAction == 'reloadPagetree' ? 'pageTree' : 'fileTree';
// Convert the selected values
if ($varValue != '') {
$varValue = \StringUtil::trimsplit("\t", $varValue);
// Automatically add resources to the DBAFS
if ($strKey == 'fileTree') {
foreach ($varValue as $k => $v) {
if (\Dbafs::shouldBeSynchronized($v)) {
$objFile = \FilesModel::findByPath($v);
if ($objFile === null) {
$objFile = \Dbafs::addResource($v);
}
$varValue[$k] = $objFile->uuid;
}
}
}
$varValue = serialize($varValue);
}
/** @var FileTree|PageTree $strClass */
$strClass = $GLOBALS['BE_FFL'][$strKey];
/** @var FileTree|PageTree $objWidget */
$objWidget = new $strClass($strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField], $dc->inputName, $varValue, $strField, $dc->table, $dc));
throw new ResponseException($this->convertToResponse($objWidget->generate()));
// Feature/unfeature an element
// Feature/unfeature an element
case 'toggleFeatured':
if (class_exists($dc->table, false)) {
$dca = new $dc->table();
if (method_exists($dca, 'toggleFeatured')) {
$dca->toggleFeatured(\Input::post('id'), \Input::post('state') == 1 ? true : false);
}
}
throw new NoContentResponseException();
// Toggle subpalettes
// Toggle subpalettes
case 'toggleSubpalette':
示例4: explode
/**
* Converts a palette string to a configuration array.
*
* @param string $palette The palette string
*
* @return array The configuration array
*/
private function explode($palette)
{
if ('' === (string) $palette) {
return [];
}
$legendCount = 0;
$legendMap = [];
$groups = StringUtil::trimsplit(';', $palette);
foreach ($groups as $group) {
$hide = false;
$fields = StringUtil::trimsplit(',', $group);
if (preg_match('#\\{(.+?)(:hide)?\\}#', $fields[0], $matches)) {
$legend = $matches[1];
$hide = count($matches) > 2 && ':hide' === $matches[2];
array_shift($fields);
} else {
$legend = $legendCount++;
}
$legendMap[$legend] = ['fields' => $fields, 'hide' => $hide];
}
return $legendMap;
}
示例5: compile
//.........这里部分代码省略.........
$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'];
}
}
示例6: filterMenu
//.........这里部分代码省略.........
}
} elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'], array(7, 8))) {
$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'] == 8 ? rsort($options) : sort($options);
foreach ($options as $k => $v) {
if ($v == '') {
$options[$v] = '-';
} else {
$options[$v] = date('Y-m', $v);
$intMonth = date('m', $v) - 1;
if (isset($GLOBALS['TL_LANG']['MONTHS'][$intMonth])) {
$options[$v] = $GLOBALS['TL_LANG']['MONTHS'][$intMonth] . ' ' . date('Y', $v);
}
}
unset($options[$k]);
}
} elseif (in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'], array(9, 10))) {
$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'] == 10 ? rsort($options) : sort($options);
foreach ($options as $k => $v) {
if ($v == '') {
$options[$v] = '-';
} else {
$options[$v] = date('Y', $v);
}
unset($options[$k]);
}
}
// Manual filter
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['eval']['multiple']) {
$moptions = array();
// TODO: find a more effective solution
foreach ($options as $option) {
// CSV lists (see #2890)
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['eval']['csv'])) {
$doptions = \StringUtil::trimsplit($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['eval']['csv'], $option);
} else {
$doptions = \StringUtil::deserialize($option);
}
if (is_array($doptions)) {
$moptions = array_merge($moptions, $doptions);
}
}
$options = $moptions;
}
$options = array_unique($options);
$options_callback = array();
// Call the options_callback
if ((is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback']) || is_callable($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback'])) && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['reference']) {
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback'])) {
$strClass = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback'][0];
$strMethod = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback'][1];
$this->import($strClass);
$options_callback = $this->{$strClass}->{$strMethod}($this);
} elseif (is_callable($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback'])) {
$options_callback = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['options_callback']($this);
}
// Sort options according to the keys of the callback array
$options = array_intersect(array_keys($options_callback), $options);
}
$options_sorter = array();
$blnDate = in_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['flag'], array(5, 6, 7, 8, 9, 10));
// Options
foreach ($options as $kk => $vv) {
$value = $blnDate ? $kk : $vv;
// Options callback
if (!empty($options_callback) && is_array($options_callback)) {
$vv = $options_callback[$vv];
示例7: 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) {
$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;
}
示例8: edit
/**
* Auto-generate a form to edit the local configuration file
*
* @return string
*/
public function edit()
{
$return = '';
$ajaxId = null;
if (\Environment::get('isAjaxRequest')) {
$ajaxId = func_get_arg(1);
}
// Build an array from boxes and rows
$this->strPalette = $this->getPalette();
$boxes = \StringUtil::trimsplit(';', $this->strPalette);
$legends = array();
if (!empty($boxes)) {
foreach ($boxes as $k => $v) {
$boxes[$k] = \StringUtil::trimsplit(',', $v);
foreach ($boxes[$k] as $kk => $vv) {
if (preg_match('/^\\[.*\\]$/', $vv)) {
continue;
}
if (preg_match('/^\\{.*\\}$/', $vv)) {
$legends[$k] = substr($vv, 1, -1);
unset($boxes[$k][$kk]);
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) {
unset($boxes[$k][$kk]);
}
}
// Unset a box if it does not contain any fields
if (empty($boxes[$k])) {
unset($boxes[$k]);
}
}
/** @var AttributeBagInterface $objSessionBag */
$objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
// Render boxes
$class = 'tl_tbox';
$fs = $objSessionBag->get('fieldset_states');
$blnIsFirst = true;
foreach ($boxes as $k => $v) {
$strAjax = '';
$blnAjax = false;
$key = '';
$cls = '';
$legend = '';
if (isset($legends[$k])) {
list($key, $cls) = explode(':', $legends[$k]);
$legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this, \'' . $key . '\', \'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>';
}
if (isset($fs[$this->strTable][$key])) {
$class .= $fs[$this->strTable][$key] ? '' : ' collapsed';
} else {
$class .= $cls && $legend ? ' ' . $cls : '';
}
$return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend;
// Build rows of the current box
foreach ($v as $vv) {
if ($vv == '[EOF]') {
if ($blnAjax && \Environment::get('isAjaxRequest')) {
return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . \StringUtil::specialchars($this->strPalette) . '">';
}
$blnAjax = false;
$return .= "\n " . '</div>';
continue;
}
if (preg_match('/^\\[.*\\]$/', $vv)) {
$thisId = 'sub_' . substr($vv, 1, -1);
$blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false;
$return .= "\n " . '<div id="' . $thisId . '">';
continue;
}
$this->strField = $vv;
$this->strInputName = $vv;
$this->varValue = \Config::get($this->strField);
// Handle entities
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text' || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'textarea') {
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) {
$this->varValue = \StringUtil::deserialize($this->varValue);
}
if (!is_array($this->varValue)) {
$this->varValue = htmlspecialchars($this->varValue);
} else {
foreach ($this->varValue as $k => $v) {
$this->varValue[$k] = htmlspecialchars($v);
}
}
}
// Autofocus the first field
if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') {
$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus';
$blnIsFirst = false;
}
// Call load_callback
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'])) {
foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['load_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$this->varValue = $this->{$callback[0]}->{$callback[1]}($this->varValue, $this);
//.........这里部分代码省略.........
示例9: validator
//.........这里部分代码省略.........
// Check whether the current value is a valid date and time format
// Check whether the current value is a valid date and time format
case 'datim':
if (!\Validator::isDatim($varInput)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['dateTime'], \Date::getInputFormat(\Date::getNumericDatimFormat())));
} else {
// Validate the date (see #5086)
try {
new \Date($varInput, \Date::getNumericDatimFormat());
} catch (\OutOfBoundsException $e) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $varInput));
}
}
break;
// Check whether the current value is a valid friendly name e-mail address
// Check whether the current value is a valid friendly name e-mail address
case 'friendly':
list($strName, $varInput) = \StringUtil::splitFriendlyEmail($varInput);
// no break;
// Check whether the current value is a valid e-mail address
// no break;
// Check whether the current value is a valid e-mail address
case 'email':
if (!\Validator::isEmail($varInput)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['email'], $this->strLabel));
}
if ($this->rgxp == 'friendly' && !empty($strName)) {
$varInput = $strName . ' [' . $varInput . ']';
}
break;
// Check whether the current value is list of valid e-mail addresses
// Check whether the current value is list of valid e-mail addresses
case 'emails':
$arrEmails = \StringUtil::trimsplit(',', $varInput);
foreach ($arrEmails as $strEmail) {
$strEmail = \Idna::encodeEmail($strEmail);
if (!\Validator::isEmail($strEmail)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['emails'], $this->strLabel));
break;
}
}
break;
// Check whether the current value is a valid URL
// Check whether the current value is a valid URL
case 'url':
if (!\Validator::isUrl($varInput)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['url'], $this->strLabel));
}
break;
// Check whether the current value is a valid alias
// Check whether the current value is a valid alias
case 'alias':
if (!\Validator::isAlias($varInput)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['alias'], $this->strLabel));
}
break;
// Check whether the current value is a valid folder URL alias
// Check whether the current value is a valid folder URL alias
case 'folderalias':
if (!\Validator::isFolderAlias($varInput)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['folderalias'], $this->strLabel));
}
break;
// Phone numbers (numeric characters, space [ ], plus [+], minus [-], parentheses [()] and slash [/])
// Phone numbers (numeric characters, space [ ], plus [+], minus [-], parentheses [()] and slash [/])
case 'phone':
示例10: addEnclosuresToTemplate
/**
* Add enclosures to a template
*
* @param object $objTemplate The template object to add the enclosures to
* @param array $arrItem The element or module as array
* @param string $strKey The name of the enclosures field in $arrItem
*/
public static function addEnclosuresToTemplate($objTemplate, $arrItem, $strKey = 'enclosure')
{
$arrEnclosures = \StringUtil::deserialize($arrItem[$strKey]);
if (!is_array($arrEnclosures) || empty($arrEnclosures)) {
return;
}
$objFiles = \FilesModel::findMultipleByUuids($arrEnclosures);
if ($objFiles === null) {
return;
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #5178)
if ($file != '') {
while ($objFiles->next()) {
if ($file == $objFiles->path) {
static::sendFileToBrowser($file);
}
}
$objFiles->reset();
}
/** @var PageModel $objPage */
global $objPage;
$arrEnclosures = array();
$allowedDownload = \StringUtil::trimsplit(',', strtolower(\Config::get('allowedDownload')));
// Add download links
while ($objFiles->next()) {
if ($objFiles->type == 'file') {
if (!in_array($objFiles->extension, $allowedDownload) || !is_file(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
$objFile = new \File($objFiles->path);
$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);
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
if (empty($arrMeta) && $objPage->rootFallbackLanguage !== null) {
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->rootFallbackLanguage);
}
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = \StringUtil::specialchars($objFile->basename);
}
$arrEnclosures[] = 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' => static::getReadableSize($objFile->filesize), 'icon' => \Image::getPath($objFile->icon), 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname, 'enclosure' => $objFiles->path);
}
}
$objTemplate->enclosure = $arrEnclosures;
}
示例11: compile
/**
* Generate the form
*
* @return string
*/
protected function compile()
{
$hasUpload = false;
$doNotSubmit = false;
$arrSubmitted = array();
$this->loadDataContainer('tl_form_field');
$formId = $this->formID != '' ? 'auto_' . $this->formID : 'auto_form_' . $this->id;
$this->Template->fields = '';
$this->Template->hidden = '';
$this->Template->formSubmit = $formId;
$this->Template->method = $this->method == 'GET' ? 'get' : 'post';
$this->initializeSession($formId);
$arrLabels = array();
// Get all form fields
$arrFields = array();
$objFields = \FormFieldModel::findPublishedByPid($this->id);
if ($objFields !== null) {
while ($objFields->next()) {
if ($objFields->name != '') {
$arrFields[$objFields->name] = $objFields->current();
} else {
$arrFields[] = $objFields->current();
}
}
}
// HOOK: compile form fields
if (isset($GLOBALS['TL_HOOKS']['compileFormFields']) && is_array($GLOBALS['TL_HOOKS']['compileFormFields'])) {
foreach ($GLOBALS['TL_HOOKS']['compileFormFields'] as $callback) {
$this->import($callback[0]);
$arrFields = $this->{$callback[0]}->{$callback[1]}($arrFields, $formId, $this);
}
}
// Process the fields
if (!empty($arrFields) && is_array($arrFields)) {
$row = 0;
$max_row = count($arrFields);
foreach ($arrFields as $objField) {
/** @var FormFieldModel $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'] = $this->allowTags;
$arrData['rowClass'] = 'row_' . $row . ($row == 0 ? ' row_first' : ($row == $max_row - 1 ? ' row_last' : '')) . ($row % 2 == 0 ? ' even' : ' odd');
// 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', \StringUtil::trimsplit('[,;]', $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$objField->type]))) {
$arrData['value'] = '';
}
}
/** @var Widget $objWidget */
$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, $this->arrData, $this);
}
}
// Validate the input
if (\Input::post('FORM_SUBMIT') == $formId) {
$objWidget->validate();
// HOOK: validate form field callback
if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) {
foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) {
$this->import($callback[0]);
$objWidget = $this->{$callback[0]}->{$callback[1]}($objWidget, $formId, $this->arrData, $this);
}
}
if ($objWidget->hasErrors()) {
$doNotSubmit = true;
} elseif ($objWidget->submitInput()) {
$arrSubmitted[$objField->name] = $objWidget->value;
$_SESSION['FORM_DATA'][$objField->name] = $objWidget->value;
unset($_POST[$objField->name]);
// see #5474
}
}
if ($objWidget instanceof \uploadable) {
$hasUpload = true;
}
//.........这里部分代码省略.........
示例12: save
/**
* Save the current value
*
* @param mixed $varValue
*
* @throws \Exception
*/
protected function save($varValue)
{
if (\Input::post('FORM_SUBMIT') != $this->strTable) {
return;
}
$arrData = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField];
// File names
if ($this->strField == 'name') {
if (!file_exists(TL_ROOT . '/' . $this->strPath . '/' . $this->varValue . $this->strExtension) || !$this->isMounted($this->strPath . '/' . $this->varValue . $this->strExtension) || $this->varValue === $varValue) {
return;
}
$this->import('Files');
$varValue = Utf8::toAscii($varValue);
// Trigger the save_callback
if (is_array($arrData['save_callback'])) {
foreach ($arrData['save_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this);
} elseif (is_callable($callback)) {
$varValue = $callback($varValue, $this);
}
}
}
// The target exists
if (strcasecmp($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension) !== 0 && file_exists(TL_ROOT . '/' . $this->strPath . '/' . $varValue . $this->strExtension)) {
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['fileExists'], $varValue));
}
$arrImageTypes = \StringUtil::trimsplit(',', strtolower(\Config::get('validImageTypes')));
// Remove potentially existing thumbnails (see #6641)
if (in_array(substr($this->strExtension, 1), $arrImageTypes)) {
foreach (glob(TL_ROOT . '/' . \System::getContainer()->getParameter('contao.image.target_path') . '/*/' . $this->varValue . '-*' . $this->strExtension) as $strThumbnail) {
$this->Files->delete(str_replace(TL_ROOT . '/', '', $strThumbnail));
}
}
// Rename the file
$this->Files->rename($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension);
// New folders
if (stristr($this->intId, '__new__') !== false) {
// Update the database
if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->strPath . '/' . $varValue . $this->strExtension)) {
$this->objActiveRecord = \Dbafs::addResource($this->strPath . '/' . $varValue . $this->strExtension);
}
$this->log('Folder "' . $this->strPath . '/' . $varValue . $this->strExtension . '" has been created', __METHOD__, TL_FILES);
} else {
// Update the database
if ($this->blnIsDbAssisted) {
$syncSource = \Dbafs::shouldBeSynchronized($this->strPath . '/' . $this->varValue . $this->strExtension);
$syncTarget = \Dbafs::shouldBeSynchronized($this->strPath . '/' . $varValue . $this->strExtension);
if ($syncSource && $syncTarget) {
\Dbafs::moveResource($this->strPath . '/' . $this->varValue . $this->strExtension, $this->strPath . '/' . $varValue . $this->strExtension);
} elseif ($syncSource) {
\Dbafs::deleteResource($this->strPath . '/' . $this->varValue . $this->strExtension);
} elseif ($syncTarget) {
\Dbafs::addResource($this->strPath . '/' . $varValue . $this->strExtension);
}
}
$this->log('File or folder "' . $this->strPath . '/' . $this->varValue . $this->strExtension . '" has been renamed to "' . $this->strPath . '/' . $varValue . $this->strExtension . '"', __METHOD__, TL_FILES);
}
// Update the symlinks
if (is_link(TL_ROOT . '/web/' . $this->strPath . '/' . $this->varValue . $this->strExtension)) {
$this->Files->delete('web/' . $this->strPath . '/' . $this->varValue . $this->strExtension);
SymlinkUtil::symlink($this->strPath . '/' . $varValue . $this->strExtension, 'web/' . $this->strPath . '/' . $varValue . $this->strExtension, TL_ROOT);
}
// Set the new value so the input field can show it
if (\Input::get('act') == 'editAll') {
/** @var SessionInterface $objSession */
$objSession = \System::getContainer()->get('session');
$session = $objSession->all();
if (($index = array_search($this->strPath . '/' . $this->varValue . $this->strExtension, $session['CURRENT']['IDS'])) !== false) {
$session['CURRENT']['IDS'][$index] = $this->strPath . '/' . $varValue . $this->strExtension;
$objSession->replace($session);
}
}
$this->varValue = $varValue;
} elseif ($this->blnIsDbAssisted && $this->objActiveRecord !== null) {
// Convert date formats into timestamps
if ($varValue != '' && in_array($arrData['eval']['rgxp'], array('date', 'time', 'datim'))) {
$objDate = new \Date($varValue, \Date::getFormatFromRgxp($arrData['eval']['rgxp']));
$varValue = $objDate->tstamp;
}
// Make sure unique fields are unique
if ($arrData['eval']['unique'] && $varValue != '' && !$this->Database->isUniqueValue($this->strTable, $this->strField, $varValue, $this->objActiveRecord->id)) {
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrData['label'][0] ?: $this->strField));
}
// Handle multi-select fields in "override all" mode
if (\Input::get('act') == 'overrideAll' && ($arrData['inputType'] == 'checkbox' || $arrData['inputType'] == 'checkboxWizard') && $arrData['eval']['multiple']) {
if ($this->objActiveRecord !== null) {
$new = \StringUtil::deserialize($varValue, true);
$old = \StringUtil::deserialize($this->objActiveRecord->{$this->strField}, true);
switch (\Input::post($this->strInputName . '_update')) {
case 'add':
$varValue = array_values(array_unique(array_merge($old, $new)));
//.........这里部分代码省略.........
示例13: doReplace
//.........这里部分代码省略.........
break;
// POST data
// POST data
case 'post':
$arrCache[$strTag] = \Input::post($elements[1]);
break;
// Mobile/desktop toggle (see #6469)
// Mobile/desktop toggle (see #6469)
case 'toggle_view':
$strUrl = ampersand(\Environment::get('request'));
$strGlue = strpos($strUrl, '?') === false ? '?' : '&';
if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') {
$arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=desktop" class="toggle_desktop" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleDesktop'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleDesktop'][0] . '</a>';
} else {
$arrCache[$strTag] = '<a href="' . $strUrl . $strGlue . 'toggle_view=mobile" class="toggle_mobile" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['toggleMobile'][1]) . '">' . $GLOBALS['TL_LANG']['MSC']['toggleMobile'][0] . '</a>';
}
break;
// Conditional tags (if)
// Conditional tags (if)
case 'iflng':
if ($elements[1] != '' && $elements[1] != $objPage->language) {
for (; $_rit < $_cnt; $_rit += 2) {
if ($tags[$_rit + 1] == 'iflng' || $tags[$_rit + 1] == 'iflng::' . $objPage->language) {
break;
}
}
}
unset($arrCache[$strTag]);
break;
// Conditional tags (if not)
// Conditional tags (if not)
case 'ifnlng':
if ($elements[1] != '') {
$langs = \StringUtil::trimsplit(',', $elements[1]);
if (in_array($objPage->language, $langs)) {
for (; $_rit < $_cnt; $_rit += 2) {
if ($tags[$_rit + 1] == 'ifnlng') {
break;
}
}
}
}
unset($arrCache[$strTag]);
break;
// Environment
// Environment
case 'env':
switch ($elements[1]) {
case 'host':
$arrCache[$strTag] = \Idna::decode(\Environment::get('host'));
break;
case 'http_host':
$arrCache[$strTag] = \Idna::decode(\Environment::get('httpHost'));
break;
case 'url':
$arrCache[$strTag] = \Idna::decode(\Environment::get('url'));
break;
case 'path':
$arrCache[$strTag] = \Idna::decode(\Environment::get('base'));
break;
case 'request':
$arrCache[$strTag] = \Environment::get('indexFreeRequest');
break;
case 'ip':
$arrCache[$strTag] = \Environment::get('ip');
break;
示例14: __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
*
* @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');
}
}
示例15: compile
/**
* Compile the template
*
* @param bool $blnCheckRequest If true, check for unsued $_GET parameters
*
* @throws \UnusedArgumentsException If there are unused $_GET parameters
*
* @internal Do not call this method in your code. It will be made private in Contao 5.0.
*/
protected function compile($blnCheckRequest = false)
{
$this->keywords = '';
$arrKeywords = \StringUtil::trimsplit(',', $GLOBALS['TL_KEYWORDS']);
// Add the meta keywords
if (strlen($arrKeywords[0])) {
$this->keywords = str_replace(array("\n", "\r", '"'), array(' ', '', ''), implode(', ', array_unique($arrKeywords)));
}
// Parse the template
$this->strBuffer = $this->parse();
// HOOK: add custom output filters
if (isset($GLOBALS['TL_HOOKS']['outputFrontendTemplate']) && is_array($GLOBALS['TL_HOOKS']['outputFrontendTemplate'])) {
foreach ($GLOBALS['TL_HOOKS']['outputFrontendTemplate'] as $callback) {
$this->import($callback[0]);
$this->strBuffer = $this->{$callback[0]}->{$callback[1]}($this->strBuffer, $this->strTemplate);
}
}
// Add the output to the cache
$this->addToCache();
// Unset only after the output has been cached (see #7824)
unset($_SESSION['LOGIN_ERROR']);
// Replace insert tags and then re-replace the request_token tag in case a form element has been loaded via insert tag
$this->strBuffer = $this->replaceInsertTags($this->strBuffer, false);
$this->strBuffer = str_replace(array('{{request_token}}', '[{]', '[}]'), array(REQUEST_TOKEN, '{{', '}}'), $this->strBuffer);
$this->strBuffer = $this->replaceDynamicScriptTags($this->strBuffer);
// see #4203
// HOOK: allow to modify the compiled markup (see #4291)
if (isset($GLOBALS['TL_HOOKS']['modifyFrontendPage']) && is_array($GLOBALS['TL_HOOKS']['modifyFrontendPage'])) {
foreach ($GLOBALS['TL_HOOKS']['modifyFrontendPage'] as $callback) {
$this->import($callback[0]);
$this->strBuffer = $this->{$callback[0]}->{$callback[1]}($this->strBuffer, $this->strTemplate);
}
}
// Check whether all $_GET parameters have been used (see #4277)
if ($blnCheckRequest && \Input::hasUnusedGet()) {
throw new \UnusedArgumentsException();
}
parent::compile();
}