本文整理汇总了PHP中Files::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Files::getInstance方法的具体用法?PHP Files::getInstance怎么用?PHP Files::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Files
的用法示例。
在下文中一共展示了Files::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if (version_compare(VERSION, '3.0', '>=') && $this->Database->tableExists('tl_files') && $this->Database->fieldExists('image', 'tl_link_data')) {
$objData = $this->Database->prepare("SELECT id,image FROM tl_link_data WHERE 1")->execute();
if ($objData->numRows) {
while ($objData->next()) {
$objImage = $this->Database->prepare("SELECT id FROM tl_files WHERE path = ?")->execute($objData->image);
if ($objImage->id > 0) {
$this->log("UPDATE tl_link_data SET image = " . $objImage->id . " WHERE id = " . $objData->id . " ", 'SQL Update 2.x to 3.x', TL_GENERAL);
$this->Database->prepare("UPDATE tl_link_data SET image = ? WHERE id = ? ")->execute($objImage->id, $objData->id);
}
}
}
}
if (version_compare(VERSION, '3.2', '>=') && $this->Database->tableExists('tl_link_data')) {
$arrFields = $this->Database->listFields('tl_link_data');
foreach ($arrFields as $arrField) {
if ($arrField['name'] == 'image' && $arrField['type'] != 'binary') {
Database\Updater::convertSingleField('tl_link_data', 'image');
}
}
}
/* remove protocol */
$this->Database->prepare("UPDATE `tl_link_data` SET `url` = CONCAT(`url_protocol`, `url`), url_protocol = ''")->execute();
if (version_compare(VERSION, '3.2', '>=')) {
$strFile = 'system/modules/delirius_linkliste/config/database.sql';
if (\Files::getInstance()->is_writeable($strFile)) {
\Files::getInstance()->delete($strFile);
}
}
}
示例2: parse
/**
* Generate the widget and return it as string
* @param array
* @return string
*/
public function parse($arrAttributes = null)
{
if ($this->varValue != '') {
$blnTemporaryFile = $this->isTemporaryFile($this->varValue);
if ($blnTemporaryFile) {
$strNew = $this->getThumbnailPath($this->varValue);
// Auto-resize the user avatar
if (\Config::get('avatar_user_autoresize')) {
$this->varValue = \Image::get($this->varValue, $this->arrAvatarSize[0], $this->arrAvatarSize[1], 'center_center');
// Copy the file
if (\Files::getInstance()->rename($this->varValue, $strNew)) {
$this->varValue = $strNew;
$blnTemporaryFile = false;
}
} else {
// If the file is temporary but has the exact avatar dimensions
// there is no need to crop it just treat it as a ready avatar
$arrSize = @getimagesize(TL_ROOT . '/' . $this->varValue);
if ($arrSize[0] == $this->arrAvatarSize[0] && $arrSize[1] == $this->arrAvatarSize[1] && \Files::getInstance()->rename($this->varValue, $strNew)) {
$this->varValue = $strNew;
$blnTemporaryFile = false;
}
}
}
// Temporary file
if ($blnTemporaryFile) {
// Crop the file
if (\Input::post('crop') != '') {
list($intPositionX, $intPositionY) = explode(',', \Input::post('crop'));
$this->varValue = $this->cropImage($this->varValue, $intPositionX, $intPositionY);
$this->thumbnail = \Image::getHtml($this->varValue);
$this->imgSize = @getimagesize(TL_ROOT . '/' . $this->varValue);
$this->set = $this->varValue;
$this->noCrop = true;
} else {
// Crop mode
$strThumbnail = $this->getThumbnail($this->varValue);
$this->thumbnail = \Image::getHtml($strThumbnail);
$this->imgSize = @getimagesize(TL_ROOT . '/' . $strThumbnail);
}
} else {
// Avatar
$this->avatar = \Image::getHtml(\Image::get($this->varValue, $this->arrAvatarSize[0], $this->arrAvatarSize[1], 'center_center'));
$this->set = $this->varValue;
}
}
$this->ajax = \Environment::get('isAjaxRequest');
$this->delete = $GLOBALS['TL_LANG']['MSC']['delete'];
$this->deleteTitle = specialchars($GLOBALS['TL_LANG']['MSC']['delete']);
$this->crop = $GLOBALS['TL_LANG']['MSC']['avatar_crop'];
$this->cropTitle = specialchars($GLOBALS['TL_LANG']['MSC']['avatar_crop']);
$this->extensions = json_encode(trimsplit(',', $this->getAllowedExtensions()));
$this->sizeLimit = $this->getMaximumFileSize();
$this->avatarSize = json_encode($this->arrAvatarSize);
$this->texts = json_encode(array('text' => array('formatProgress' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_formatProgress'], 'failUpload' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_failUpload'], 'waitingForResponse' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_waitingForResponse'], 'paused' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_paused']), 'messages' => array('tooManyFilesError' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_tooManyFilesError'], 'unsupportedBrowser' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_unsupportedBrowser']), 'retry' => array('autoRetryNote' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_autoRetryNote']), 'deleteFile' => array('confirmMessage' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_confirmMessage'], 'deletingStatusText' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_deletingStatusText'], 'deletingFailedText' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_deletingFailedText']), 'paste' => array('namePromptMessage' => $GLOBALS['TL_LANG']['MSC']['avatar_fineuploader_namePromptMessage'])));
$this->labels = array('drop' => $GLOBALS['TL_LANG']['MSC']['avatar_drop'], 'upload' => $GLOBALS['TL_LANG']['MSC']['avatar_upload'], 'processing' => $GLOBALS['TL_LANG']['MSC']['avatar_processing']);
return parent::parse($arrAttributes);
}
示例3: __construct
/**
* Create the new twig contao environment
*/
protected function __construct()
{
$arrTemplatePaths = array();
$blnDebug = $GLOBALS['TL_CONFIG']['debugMode'] || $GLOBALS['TL_CONFIG']['twigDebugMode'];
// Make sure the cache directory exists
if (version_compare(VERSION, '2', '<=') && !is_dir(TL_ROOT . '/system/cache')) {
Files::getInstance()->mkdir('system/cache');
}
if (!is_dir(TL_ROOT . '/system/cache/twig')) {
Files::getInstance()->mkdir('system/cache/twig');
}
// Add the layout templates directory
if (TL_MODE == 'FE') {
global $objPage;
$strTemplateGroup = str_replace(array('../', 'templates/'), '', $objPage->templateGroup);
if ($strTemplateGroup != '') {
$arrTemplatePaths[] = TL_ROOT . '/templates/' . $strTemplateGroup;
}
}
// Add the global templates directory
$arrTemplatePaths[] = TL_ROOT . '/templates';
// Add all modules templates directories
foreach (Config::getInstance()->getActiveModules() as $strModule) {
$strPath = TL_ROOT . '/system/modules/' . $strModule . '/templates';
if (is_dir($strPath)) {
$arrTemplatePaths[] = $strPath;
}
}
// Create the default array loader
$this->loaderArray = new Twig_Loader_Array(array());
// Create the default filesystem loader
$this->loaderFilesystem = new Twig_Loader_Filesystem($arrTemplatePaths);
// Create the effective chain loader
$this->loader = new Twig_Loader_Chain();
// Register the default filesystem loaders
$this->loader->addLoader($this->loaderArray);
$this->loader->addLoader($this->loaderFilesystem);
// Create the environment
$this->environment = new Twig_Environment($this->loader, array('cache' => TL_ROOT . '/system/cache/twig', 'debug' => $blnDebug, 'autoescape' => false));
// set default formats
$this->environment->getExtension('core')->setNumberFormat(2, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']);
// set default date format and timezone
$this->environment->getExtension('core')->setDateFormat($GLOBALS['TL_CONFIG']['datimFormat']);
$this->environment->getExtension('core')->setTimezone('Europe/Paris');
// Add debug extension
if ($blnDebug || $GLOBALS['TL_CONFIG']['twigDebugExtension']) {
$this->environment->addExtension(new Twig_Extension_Debug());
}
$this->environment->addExtension(new ContaoTwigExtension());
// HOOK: custom twig initialisation
if (isset($GLOBALS['TL_HOOKS']['initializeTwig']) && is_array($GLOBALS['TL_HOOKS']['initializeTwig'])) {
foreach ($GLOBALS['TL_HOOKS']['initializeTwig'] as $callback) {
$this->import($callback[0]);
$this->{$callback}[0]->{$callback}[1]($this);
}
}
}
示例4: __construct
/**
* Construct object
*
* @param string $strFileName
* @param string $strPath
*/
public function __construct($strFileName, $strPath)
{
$this->_objHelper = ClipboardHelper::getInstance();
$this->_objXmlWriter = ClipboardXmlWriter::getInstance();
$this->_objXmlReader = ClipboardXmlReader::getInstance();
$this->_objFiles = Files::getInstance();
$this->_filename = $strFileName;
$this->_path = $strPath;
}
示例5: deleteFile
/**
* @param \Compat\FilesModel|int|string $file
* @return bool
*/
public static function deleteFile($file)
{
// normalize path
$file = preg_replace('~//+~', '/', $file);
if (file_exists(TL_ROOT . '/' . $file)) {
return \Files::getInstance()->delete($file);
}
return false;
}
示例6: __construct
/**
* Prevent constructing the object (Singleton)
*/
protected function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
$this->_objXmlReader = ClipboardXmlReader::getInstance();
$this->_objXmlWriter = ClipboardXmlWriter::getInstance();
$this->_objHelper = ClipboardHelper::getInstance();
$this->_objFiles = Files::getInstance();
$this->_createClipboardFromFiles();
}
示例7: compile
/**
* Compile the asset and return true on success
*
* @throws \Exception
*/
protected function compile()
{
$file = $this->getTemporaryFile();
$sourceMap = !$this->model->disableSourceMap;
exec(sprintf('sass %s %s %s', TL_ROOT . '/' . $this->getSourceFile()->path, TL_ROOT . '/' . $file->path, !$sourceMap ? '--sourcemap=none' : ''));
// Move the source map to assets folder
if ($sourceMap) {
$folder = str_replace(TL_ROOT, '', $file->dirname);
$sourceMapFileName = $file->filename . '.css.map';
\Files::getInstance()->rename($folder . '/' . $sourceMapFileName, 'assets/css/' . $sourceMapFileName);
}
}
示例8: run
public function run()
{
if (!file_exists(TL_ROOT . '/system/languages/locallang.php')) {
// The composer client uses a custom error handler so the auto creation of the folder does not work
// because Contao does not check if the folder exists.
if (!is_dir(TL_ROOT . '/system/languages')) {
$files = \Files::getInstance();
$files->mkdir('system/languages');
}
$file = new \File('system/languages/locallang.php');
$file->write('<?php' . "\n");
$file->close();
}
}
示例9: getFileUploadPathForToken
/**
* Moves an uploaded file to the tmp folder and returns its TL_ROOT relative path.
* If it was not properly uploaded, the method will return null.
*
* @param array $file
* @return null|string
*/
public static function getFileUploadPathForToken(array $file)
{
if (!is_uploaded_file($file['tmp_name'])) {
if (file_exists($file['tmp_name'])) {
$basePath = TL_ROOT . "/";
return str_replace($basePath, '', $file['tmp_name']);
}
return null;
}
$tmpDir = 'system/tmp';
$filePath = $tmpDir . '/' . $file['name'];
\Files::getInstance()->move_uploaded_file($file['tmp_name'], $filePath);
\Files::getInstance()->chmod($filePath, $GLOBALS['TL_CONFIG']['defaultFileChmod']);
return $filePath;
}
示例10: mkdirr
/**
* Recursively create a directory
* @param string
* @param bool
* @return bool
* @deprecated use `new Folder(...)` (see https://github.com/contao/core/issues/6553)
*/
public static function mkdirr($strDirectory)
{
$components = explode('/', $strDirectory);
$strDirectory = '';
foreach ($components as $folder) {
$strDirectory .= '/' . (string) $folder;
$strDirectory = ltrim($strDirectory, '/');
// Does not matter if file or directory
if (!file_exists(TL_ROOT . '/' . $strDirectory)) {
if (!\Files::getInstance()->mkdir($strDirectory)) {
return false;
}
}
}
return is_dir(TL_ROOT . '/' . $strDirectory);
}
示例11: run
public function run()
{
if (version_compare(VERSION, '3.2', '>=') && $this->Database->tableExists('tl_slogan_data')) {
$arrFields = $this->Database->listFields('tl_slogan_data');
foreach ($arrFields as $arrField) {
if ($arrField['name'] == 'image' && $arrField['type'] != 'binary') {
Database\Updater::convertSingleField('tl_slogan_data', 'image');
}
}
}
if (version_compare(VERSION, '3.2', '>=')) {
$strFile = 'system/modules/delirius_slogan/config/database.sql';
if (\Files::getInstance()->is_writeable($strFile)) {
\Files::getInstance()->delete($strFile);
}
}
}
示例12: __construct
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Init
$this->objSyncCtoHelper = SyncCtoHelper::getInstance();
$this->objFiles = \Files::getInstance();
$this->strTimestampFormat = str_replace(array(':', ' '), array('', '_'), $GLOBALS['TL_CONFIG']['datimFormat']);
// Load blacklists and whitelists
$this->arrRootFolderList = $this->objSyncCtoHelper->getWhitelistFolder();
// Get memory limit
$this->intMaxMemoryUsage = SyncCtoModuleClient::parseSize(ini_get('memory_limit'));
$this->intMaxMemoryUsage = $this->intMaxMemoryUsage / 100 * 30;
// Get execution limit
$this->intMaxExecutionTime = SyncCtoHelper::parseRuntime(ini_get('max_execution_time'));
$this->intMaxExecutionTime = intval($this->intMaxExecutionTime / 100 * 25);
// Flags for file scanning.
$this->strRDIFlags = RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS;
}
示例13: optimize
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function optimize($strImage, $strTarget = null)
{
$objFile = new \File($strImage, true);
if (!$strTarget) {
$strTarget = $strImage;
}
if ($objFile->exists() && $objFile->extension == 'png') {
// advpng does not support output files,
// so we need to copy the file before optimize it
if ($strImage != $strTarget) {
\Files::getInstance()->copy($strImage, $strTarget);
}
$objProcessBuilder = new ProcessBuilder();
$objProcessBuilder->add($this->strPath);
$objProcessBuilder->add('-z');
switch ($this->strLevel) {
case 'store':
$objProcessBuilder->add('--shrink-store');
break;
case 'fast':
$objProcessBuilder->add('--shrink-fast');
break;
case 'extra':
$objProcessBuilder->add('--shrink-extra');
break;
case 'insane':
$objProcessBuilder->add('--shrink-insane');
break;
default:
$objProcessBuilder->add('--shrink-normal');
break;
}
$objProcessBuilder->add(TL_ROOT . '/' . $strTarget);
$objProcess = $objProcessBuilder->getProcess();
$objProcess->run();
if (!$objProcess->isSuccessful()) {
throw new \RuntimeException('Could not execute advpng: ' . $objProcess->getErrorOutput());
}
return $strTarget;
}
return $strImage;
}
示例14: moveTemporaryFile
/**
* Move the temporary file to its destination
* @param string
* @param string
* @return string
*/
protected function moveTemporaryFile($strFile, $strDestination)
{
if (!is_file(TL_ROOT . '/' . $strFile)) {
return '';
}
// Do not store the file
if (!$this->arrConfiguration['storeFile']) {
return $strFile;
}
// The file is not temporary
if (stripos($strFile, $this->strTemporaryPath) === false) {
return $strFile;
}
$strNew = $strDestination . '/' . basename($strFile);
// Do not overwrite existing files
if ($this->arrConfiguration['doNotOverwrite']) {
$strNew = $strDestination . '/' . $this->getFileName(basename($strFile), $strDestination);
}
$blnRename = \Files::getInstance()->rename($strFile, $strNew);
// Add the file to Dbafs
if ($this->arrConfiguration['addToDbafs'] && $blnRename) {
$objModel = \Dbafs::addResource($strNew);
if ($objModel !== null) {
$strNew = $objModel->uuid;
}
}
return $strNew;
}
示例15: get
/**
* Resize an image and store the resized version in the assets/images folder
*
* @param string $image The image path
* @param integer $width The target width
* @param integer $height The target height
* @param string $mode The resize mode
* @param string $target An optional target path
* @param boolean $force Override existing target images
*
* @return string|null The path of the resized image or null
*/
public static function get($image, $width, $height, $mode = '', $target = null, $force = false)
{
if ($image == '') {
return null;
}
$image = rawurldecode($image);
// Check whether the file exists
if (!is_file(TL_ROOT . '/' . $image)) {
\System::log('Image "' . $image . '" could not be found', __METHOD__, TL_ERROR);
return null;
}
$objFile = new \File($image, true);
$arrAllowedTypes = trimsplit(',', strtolower(\Config::get('validImageTypes')));
// Check the file type
if (!in_array($objFile->extension, $arrAllowedTypes)) {
\System::log('Image type "' . $objFile->extension . '" was not allowed to be processed', __METHOD__, TL_ERROR);
return null;
}
// No resizing required
if (($objFile->width == $width || !$width) && ($objFile->height == $height || !$height)) {
// Return the target image (thanks to Tristan Lins) (see #4166)
if ($target) {
// Copy the source image if the target image does not exist or is older than the source image
if (!file_exists(TL_ROOT . '/' . $target) || $objFile->mtime > filemtime(TL_ROOT . '/' . $target)) {
\Files::getInstance()->copy($image, $target);
}
return \System::urlEncode($target);
}
return \System::urlEncode($image);
}
// No mode given
if ($mode == '') {
// Backwards compatibility
if ($width && $height) {
$mode = 'center_top';
} else {
$mode = 'proportional';
}
}
// Backwards compatibility
if ($mode == 'crop') {
$mode = 'center_center';
}
$strCacheKey = substr(md5('-w' . $width . '-h' . $height . '-' . $image . '-' . $mode . '-' . $objFile->mtime), 0, 8);
$strCacheName = 'assets/images/' . substr($strCacheKey, -1) . '/' . $objFile->filename . '-' . $strCacheKey . '.' . $objFile->extension;
// Check whether the image exists already
if (!\Config::get('debugMode')) {
// Custom target (thanks to Tristan Lins) (see #4166)
if ($target && !$force) {
if (file_exists(TL_ROOT . '/' . $target) && $objFile->mtime <= filemtime(TL_ROOT . '/' . $target)) {
return \System::urlEncode($target);
}
}
// Regular cache file
if (file_exists(TL_ROOT . '/' . $strCacheName)) {
// Copy the cached file if it exists
if ($target) {
\Files::getInstance()->copy($strCacheName, $target);
return \System::urlEncode($target);
}
return \System::urlEncode($strCacheName);
}
}
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['getImage']) && is_array($GLOBALS['TL_HOOKS']['getImage'])) {
foreach ($GLOBALS['TL_HOOKS']['getImage'] as $callback) {
$return = \System::importStatic($callback[0])->{$callback}[1]($image, $width, $height, $mode, $strCacheName, $objFile, $target);
if (is_string($return)) {
return \System::urlEncode($return);
}
}
}
// Return the path to the original image if the GDlib cannot handle it
if (!extension_loaded('gd') || !$objFile->isGdImage || $objFile->width > \Config::get('gdMaxImgWidth') || $objFile->height > \Config::get('gdMaxImgHeight') || !$width && !$height || $width > \Config::get('gdMaxImgWidth') || $height > \Config::get('gdMaxImgHeight')) {
return \System::urlEncode($image);
}
$intPositionX = 0;
$intPositionY = 0;
$intWidth = $width;
$intHeight = $height;
// Mode-specific changes
if ($intWidth && $intHeight) {
switch ($mode) {
case 'proportional':
if ($objFile->width >= $objFile->height) {
unset($height, $intHeight);
} else {
unset($width, $intWidth);
//.........这里部分代码省略.........