本文整理汇总了PHP中System::getReadableSize方法的典型用法代码示例。如果您正苦于以下问题:PHP System::getReadableSize方法的具体用法?PHP System::getReadableSize怎么用?PHP System::getReadableSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System::getReadableSize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderContent
/**
* Render a single message content element.
*
* @param RenderMessageContentEvent $event
*
* @return string
*/
public function renderContent(RenderMessageContentEvent $event)
{
global $container;
$content = $event->getMessageContent();
if ($content->getType() != 'downloads' || $event->getRenderedContent()) {
return;
}
/** @var EntityAccessor $entityAccessor */
$entityAccessor = $container['doctrine.orm.entityAccessor'];
$context = $entityAccessor->getProperties($content);
$context['files'] = array();
foreach ($context['downloadSources'] as $index => $downloadSource) {
$context['downloadSources'][$index] = $downloadSource = \Compat::resolveFile($downloadSource);
$file = new \File($downloadSource, true);
if (!$file->exists()) {
unset($context['downloadSources'][$index]);
continue;
}
$context['files'][$index] = array('url' => $downloadSource, 'size' => \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $downloadSource)), 'icon' => 'assets/contao/images/' . $file->icon, 'title' => basename($downloadSource));
}
if (empty($context['files'])) {
return;
}
$template = new \TwigTemplate('avisota/message/renderer/default/mce_downloads', 'html');
$buffer = $template->parse($context);
$event->setRenderedContent($buffer);
}
示例2: getForTemplate
/**
* Generate array representation for download
* @return array
*/
public function getForTemplate($blnOrderPaid = false)
{
global $objPage;
$objDownload = $this->getRelated('download_id');
if (null === $objDownload) {
return array();
}
$arrDownloads = array();
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
foreach ($objDownload->getFiles() as $objFileModel) {
$objFile = new \File($objFileModel->path, true);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
// Send file to the browser
if ($blnOrderPaid && $this->canDownload() && \Input::get('download') == $objDownload->id && \Input::get('file') == $objFileModel->path) {
$this->download($objFileModel->path);
}
$arrMeta = \Frontend::getMetaData($objFileModel->meta, $objPage->language);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
}
$strHref = '';
if (TL_MODE == 'FE') {
$strHref = \Haste\Util\Url::addQueryString('download=' . $objDownload->id . '&file=' . $objFileModel->path);
}
// Add the image
$arrDownloads[] = array('id' => $this->id, 'name' => $objFile->basename, 'title' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname, 'remaining' => $objDownload->downloads_allowed > 0 ? sprintf($GLOBALS['TL_LANG']['MSC']['downloadsRemaining'], intval($this->downloads_remaining)) : '', 'downloadable' => $blnOrderPaid && $this->canDownload());
}
return $arrDownloads;
}
示例3: addToPDFSearchIndex
protected static function addToPDFSearchIndex($strFile, $arrParentSet)
{
$objFile = new \File($strFile);
if (!Validator::isValidPDF($objFile)) {
return false;
}
$objDatabase = \Database::getInstance();
$objModel = $objFile->getModel();
$arrMeta = \Frontend::getMetaData($objModel->meta, $arrParentSet['language']);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars($objFile->basename);
}
$strHref = \Environment::get('base') . \Environment::get('request');
// Remove an existing file parameter
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->value);
$arrSet = array('pid' => $arrParentSet['pid'], 'tstamp' => time(), 'title' => $arrMeta['title'], 'url' => $strHref, 'filesize' => \System::getReadableSize($objFile->size, 2), 'checksum' => $objFile->hash, 'protected' => $arrParentSet['protected'], 'groups' => $arrParentSet['groups'], 'language' => $arrParentSet['language'], 'mime' => $objFile->mime);
// Return if the file is indexed and up to date
$objIndex = $objDatabase->prepare("SELECT * FROM tl_search WHERE pid=? AND checksum=?")->execute($arrSet['pid'], $arrSet['checksum']);
// there are already indexed files containing this file (same checksum and filename)
if ($objIndex->numRows) {
// Return if the page with the file is indexed
if (in_array($arrSet['pid'], $objIndex->fetchEach('pid'))) {
return false;
}
$strContent = $objIndex->text;
} else {
try {
// parse only for the first occurrence
$parser = new \Smalot\PdfParser\Parser();
$objPDF = $parser->parseFile($strFile);
$strContent = $objPDF->getText();
} catch (\Exception $e) {
// Missing object refernce #...
return false;
}
}
// Put everything together
$arrSet['text'] = $strContent;
$arrSet['text'] = trim(preg_replace('/ +/', ' ', \String::decodeEntities($arrSet['text'])));
// Update an existing old entry
if ($objIndex->pid == $arrSet['pid']) {
$objDatabase->prepare("UPDATE tl_search %s WHERE id=?")->set($arrSet)->execute($objIndex->id);
$intInsertId = $objIndex->id;
} else {
$objInsertStmt = $objDatabase->prepare("INSERT INTO tl_search %s")->set($arrSet)->execute();
$intInsertId = $objInsertStmt->insertId;
}
static::indexContent($arrSet, $intInsertId);
}
示例4: generateMarkup
/**
* Generate the markup for the default uploader
*
* @return string
*/
public function generateMarkup()
{
// Maximum file size in MB
$intMaxSize = intval($this->getMaximumUploadSize() / 1024 / 1024);
// String of accepted file extensions
$strAccepted = implode(',', array_map(function ($a) {
return '.' . $a;
}, 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("processing", 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
public function generate(WatchlistItemModel $objItem, Watchlist $objWatchlist)
{
global $objPage;
$objFileModel = \FilesModel::findById($objItem->uuid);
if ($objFileModel === null) {
return;
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && $file == $objFileModel->path) {
\Controller::sendFileToBrowser($file);
}
$objFile = new \File($objFileModel->path, true);
$objContent = \ContentModel::findByPk($objItem->cid);
$objT = new \FrontendTemplate('watchlist_view_download');
$objT->setData($objFileModel->row());
$linkTitle = specialchars($objFile->name);
// use generate for download & downloads as well
if ($objContent->type == 'download' && $objContent->linkTitle != '') {
$linkTitle = $objContent->linkTitle;
}
$arrMeta = deserialize($objFileModel->meta);
// Language support
if (($arrLang = $arrMeta[$GLOBALS['TL_LANGUAGE']]) != '') {
$linkTitle = $arrLang['title'] ? $arrLang['title'] : $linkTitle;
}
$strHref = \Controller::generateFrontendUrl($objPage->row());
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path);
$objT->link = ($objItemTitle = $objItem->title) ? $objItemTitle : $linkTitle;
$objT->title = specialchars($objContent->titleText ?: $linkTitle);
$objT->href = $strHref;
$objT->filesize = \System::getReadableSize($objFile->filesize, 1);
$objT->icon = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon;
$objT->mime = $objFile->mime;
$objT->extension = $objFile->extension;
$objT->path = $objFile->dirname;
$objT->actions = $this->generateEditActions($objItem, $objWatchlist);
return $objT->parse();
}
示例6: renderContent
/**
* Render a single message content element.
*
* @param RenderMessageContentEvent $event
*
* @return string
*/
public function renderContent(RenderMessageContentEvent $event)
{
global $container;
$content = $event->getMessageContent();
if ($content->getType() != 'download' || $event->getRenderedContent()) {
return;
}
/** @var EntityAccessor $entityAccessor */
$entityAccessor = $container['doctrine.orm.entityAccessor'];
$context = $entityAccessor->getProperties($content);
$context['downloadSource'] = \Compat::resolveFile($context['downloadSource']);
$file = new \File($context['downloadSource'], true);
if (!$file->exists()) {
return;
}
$context['downloadSize'] = \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $context['downloadSource']));
$context['downloadIcon'] = 'assets/contao/images/' . $file->icon;
if (empty($context['downloadTitle'])) {
$context['downloadTitle'] = basename($context['downloadSource']);
}
$template = new \TwigTemplate('avisota/message/renderer/default/mce_download', 'html');
$buffer = $template->parse($context);
$event->setRenderedContent($buffer);
}
示例7: doReplace
//.........这里部分代码省略.........
// HOOK: pass unknown tags to callback functions
default:
if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
$this->import($callback[0]);
$varValue = $this->{$callback[0]}->{$callback[1]}($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt);
// see #6672
// Replace the tag and stop the loop
if ($varValue !== false) {
$arrCache[$strTag] = $varValue;
break;
}
}
}
if (\Config::get('debugMode')) {
$GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag;
}
break;
}
// Handle the flags
if (!empty($flags)) {
foreach ($flags as $flag) {
switch ($flag) {
case 'addslashes':
case 'stripslashes':
case 'standardize':
case 'ampersand':
case 'specialchars':
case 'nl2br':
case 'nl2br_pre':
case 'strtolower':
case 'utf8_strtolower':
case 'strtoupper':
case 'utf8_strtoupper':
case 'ucfirst':
case 'lcfirst':
case 'ucwords':
case 'trim':
case 'rtrim':
case 'ltrim':
case 'utf8_romanize':
case 'strrev':
case 'urlencode':
case 'rawurlencode':
$arrCache[$strTag] = $flag($arrCache[$strTag]);
break;
case 'encodeEmail':
case 'decodeEntities':
$arrCache[$strTag] = \StringUtil::$flag($arrCache[$strTag]);
break;
case 'number_format':
$arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
break;
case 'currency_format':
$arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
break;
case 'readable_size':
$arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
break;
case 'flatten':
if (!is_array($arrCache[$strTag])) {
break;
}
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($arrCache[$strTag]));
$result = array();
foreach ($it as $leafValue) {
$keys = array();
foreach (range(0, $it->getDepth()) as $depth) {
$keys[] = $it->getSubIterator($depth)->key();
}
$result[] = implode('.', $keys) . ': ' . $leafValue;
}
$arrCache[$strTag] = implode(', ', $result);
break;
// HOOK: pass unknown flags to callback functions
// HOOK: pass unknown flags to callback functions
default:
if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
$this->import($callback[0]);
$varValue = $this->{$callback[0]}->{$callback[1]}($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
// see #5806
// Replace the tag and stop the loop
if ($varValue !== false) {
$arrCache[$strTag] = $varValue;
break;
}
}
}
if (\Config::get('debugMode')) {
$GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
}
break;
}
}
}
$strBuffer .= $arrCache[$strTag];
}
return \StringUtil::restoreBasicEntities($strBuffer);
}
示例8: generateMarkup
/**
* Generate the markup for the default uploader
*
* @return string
*/
public function generateMarkup()
{
$return = '
<div>
<input type="file" name="' . $this->strName . '[]" class="tl_upload_field" onfocus="Backend.getScrollOffset()" multiple>
</div>';
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;
}
示例9: addDownloadsFromProductDownloadsToTemplate
public static function addDownloadsFromProductDownloadsToTemplate($objTemplate)
{
$arrDownloads = array();
// array for downloadfiles from db
$arrFiles = array();
// contains queryresults from db
$strTable = "tl_iso_download";
// name of download table
global $objPage;
$arrOptions = array('order' => 'sorting ASC');
$arrFiles = \Isotope\Model\Download::findBy('pid', $objTemplate->id, $arrOptions);
if ($arrFiles === null) {
return $arrDownloads;
}
while ($arrFiles->next()) {
$objModel = \FilesModel::findByUuid($arrFiles->singleSRC);
if ($objModel === null) {
if (!\Validator::isUuid($arrFiles->singleSRC)) {
$objTemplate->text = '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>';
}
} elseif (is_file(TL_ROOT . '/' . $objModel->path)) {
$objFile = new \File($objModel->path, true);
$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);
}
$arrMeta = \Frontend::getMetaData($objModel->meta, $objPage->language);
if (empty($arrMeta)) {
if ($objPage->rootFallbackLanguage !== null) {
$arrMeta = \Frontend::getMetaData($objModel->meta, $objPage->rootFallbackLanguage);
}
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= (\Config::get('disableAlias') || strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . \System::urlEncode($objFile->path);
$objDownload = new \stdClass();
$objDownload->id = $objModel->id;
$objDownload->uuid = $objModel->uuid;
$objDownload->name = $objFile->basename;
$objDownload->formedname = preg_replace(array('/_/', '/.\\w+$/'), array(' ', ''), $objFile->basename);
$objDownload->title = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['download'], $objFile->basename));
$objDownload->link = $arrMeta['title'];
$objDownload->filesize = \System::getReadableSize($objFile->filesize, 1);
$objDownload->icon = TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon;
$objDownload->href = $strHref;
$objDownload->mime = $objFile->mime;
$objDownload->extension = $objFile->extension;
$objDownload->path = $objFile->dirname;
$objDownload->class = 'isotope-download isotope-download-file';
$objT = new \FrontendTemplate('isotope_download_from_attribute');
$objT->setData((array) $objDownload);
$objDownload->output = $objT->parse();
$arrDownloads[] = $objDownload;
}
}
$objTemplate->downloads = $arrDownloads;
}
示例10: generateMarkup
/**
* Generate the markup for the default uploader
*
* @return string
*/
public function generateMarkup()
{
$fields = '';
for ($i = 0; $i < \Config::get('uploadFields'); $i++) {
$fields .= '
<input type="file" name="' . $this->strName . '[]" class="tl_upload_field" onfocus="Backend.getScrollOffset()"><br>';
}
return '
<div id="upload-fields">' . $fields . '
</div>
<script>
window.addEvent("domready", function() {
if ("multiple" in document.createElement("input")) {
var div = $("upload-fields");
var input = div.getElement("input");
div.empty();
input.set("multiple", true);
input.inject(div);
}
});
</script>
<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>';
}
示例11: generate
/**
* Generate download attributes
* @param IsotopeProduct
* @return string
*/
public function generate(IsotopeProduct $objProduct, array $arrOptions = array())
{
global $objPage;
$arrFiles = deserialize($objProduct->{$this->field_name});
// Return if there are no files
if (empty($arrFiles) || !is_array($arrFiles)) {
return '';
}
// Get the file entries from the database
$objFiles = \FilesModel::findMultipleByIds($arrFiles);
if (null === $objFiles) {
return '';
}
$file = \Input::get('file', true);
// Send the file to the browser and do not send a 404 header (see #4632)
if ($file != '' && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', basename($file))) {
while ($objFiles->next()) {
if ($file == $objFiles->path || dirname($file) == $objFiles->path) {
\Controller::sendFileToBrowser($file);
}
}
$objFiles->reset();
}
$files = array();
$auxDate = array();
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['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, true);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = \Frontend::getMetaData($objFiles->meta, $objPage->language);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || 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' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
} else {
$objSubfiles = \FilesModel::findByPid($objFiles->id);
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
continue;
}
$objFile = new \File($objSubfiles->path, true);
if (!in_array($objFile->extension, $allowedDownload) || preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
continue;
}
$arrMeta = \Frontend::getMetaData($objSubfiles->meta, $objPage->language);
// Use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars(str_replace('_', ' ', preg_replace('/^[0-9]+_/', '', $objFile->filename)));
}
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\\?)file=/', $strHref)) {
$strHref = preg_replace('/(&(amp;)?|\\?)file=[^&]+/', '', $strHref);
}
$strHref .= ($GLOBALS['TL_CONFIG']['disableAlias'] || 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' => $arrMeta['title'], 'link' => $arrMeta['title'], 'caption' => $arrMeta['caption'], 'href' => $strHref, 'filesize' => \System::getReadableSize($objFile->filesize, 1), 'icon' => TL_ASSETS_URL . 'assets/contao/images/' . $objFile->icon, 'mime' => $objFile->mime, 'meta' => $arrMeta, 'extension' => $objFile->extension, 'path' => $objFile->dirname);
$auxDate[] = $objFile->mtime;
}
}
}
// Sort array
$sortBy = $arrOptions['sortBy'] ?: $this->sortBy;
switch ($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);
//.........这里部分代码省略.........
示例12: replaceInsertTags
//.........这里部分代码省略.........
// Sanitize path
$strFile = str_replace('../', '', $strFile);
// Include .php, .tpl, .xhtml and .html5 files
if (preg_match('/\\.(php|tpl|xhtml|html5)$/', $strFile) && file_exists(TL_ROOT . '/templates/' . $strFile)) {
ob_start();
include TL_ROOT . '/templates/' . $strFile;
$arrCache[$strTag] = ob_get_contents();
ob_end_clean();
}
$_GET = $arrGet;
\Input::resetCache();
break;
// HOOK: pass unknown tags to callback functions
// HOOK: pass unknown tags to callback functions
default:
if (isset($GLOBALS['TL_HOOKS']['replaceInsertTags']) && is_array($GLOBALS['TL_HOOKS']['replaceInsertTags'])) {
foreach ($GLOBALS['TL_HOOKS']['replaceInsertTags'] as $callback) {
$this->import($callback[0]);
$varValue = $this->{$callback}[0]->{$callback}[1]($tag, $blnCache, $arrCache[$strTag], $flags, $tags, $arrCache, $_rit, $_cnt);
// see #6672
// Replace the tag and stop the loop
if ($varValue !== false) {
$arrCache[$strTag] = $varValue;
break;
}
}
}
if (\Config::get('debugMode')) {
$GLOBALS['TL_DEBUG']['unknown_insert_tags'][] = $strTag;
}
break;
}
// Handle the flags
if (!empty($flags)) {
foreach ($flags as $flag) {
switch ($flag) {
case 'addslashes':
case 'stripslashes':
case 'standardize':
case 'ampersand':
case 'specialchars':
case 'nl2br':
case 'nl2br_pre':
case 'strtolower':
case 'utf8_strtolower':
case 'strtoupper':
case 'utf8_strtoupper':
case 'ucfirst':
case 'lcfirst':
case 'ucwords':
case 'trim':
case 'rtrim':
case 'ltrim':
case 'utf8_romanize':
case 'strrev':
case 'base64_encode':
case 'base64_decode':
case 'urlencode':
case 'rawurlencode':
$arrCache[$strTag] = $flag($arrCache[$strTag]);
break;
case 'encodeEmail':
case 'decodeEntities':
$arrCache[$strTag] = \String::$flag($arrCache[$strTag]);
break;
case 'number_format':
$arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 0);
break;
case 'currency_format':
$arrCache[$strTag] = \System::getFormattedNumber($arrCache[$strTag], 2);
break;
case 'readable_size':
$arrCache[$strTag] = \System::getReadableSize($arrCache[$strTag]);
break;
// HOOK: pass unknown flags to callback functions
// HOOK: pass unknown flags to callback functions
default:
if (isset($GLOBALS['TL_HOOKS']['insertTagFlags']) && is_array($GLOBALS['TL_HOOKS']['insertTagFlags'])) {
foreach ($GLOBALS['TL_HOOKS']['insertTagFlags'] as $callback) {
$this->import($callback[0]);
$varValue = $this->{$callback}[0]->{$callback}[1]($flag, $tag, $arrCache[$strTag], $flags, $blnCache, $tags, $arrCache, $_rit, $_cnt);
// see #5806
// Replace the tag and stop the loop
if ($varValue !== false) {
$arrCache[$strTag] = $varValue;
break;
}
}
}
if (\Config::get('debugMode')) {
$GLOBALS['TL_DEBUG']['unknown_insert_tag_flags'][] = $flag;
}
break;
}
}
}
$strBuffer .= $arrCache[$strTag];
}
return \String::restoreBasicEntities($strBuffer);
}
示例13: generateFileItem
/**
* Generate a file item and return it as HTML string
* @param string
* @return string
*/
protected function generateFileItem($strPath)
{
if (!is_file(TL_ROOT . '/' . $strPath)) {
return '';
}
$imageSize = $this->getImageSize();
$objFile = new \File($strPath, true);
$strInfo = $strPath . ' <span class="tl_gray">(' . \System::getReadableSize($objFile->size) . ($objFile->isGdImage ? ', ' . $objFile->width . 'x' . $objFile->height . ' px' : '') . ')</span>';
$allowedDownload = trimsplit(',', strtolower($GLOBALS['TL_CONFIG']['allowedDownload']));
$strReturn = '';
// Show files and folders
if (!$this->blnIsGallery && !$this->blnIsDownloads) {
if ($objFile->isGdImage) {
$strReturn = \Image::getHtml(\Image::get($strPath, $imageSize[0], $imageSize[1], $imageSize[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
} else {
$strReturn = \Image::getHtml($objFile->icon) . ' ' . $strInfo;
}
} else {
if ($this->blnIsGallery) {
// Only show images
if ($objFile->isGdImage) {
$strReturn = \Image::getHtml(\Image::get($strPath, $imageSize[0], $imageSize[1], $imageSize[2]), '', 'class="gimage" title="' . specialchars($strInfo) . '"');
}
} else {
// Only show allowed download types
if (in_array($objFile->extension, $allowedDownload) && !preg_match('/^meta(_[a-z]{2})?\\.txt$/', $objFile->basename)) {
$strReturn = \Image::getHtml($objFile->icon) . ' ' . $strPath;
}
}
}
return $strReturn;
}