本文整理汇总了PHP中FilesModel::findByPath方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesModel::findByPath方法的具体用法?PHP FilesModel::findByPath怎么用?PHP FilesModel::findByPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilesModel
的用法示例。
在下文中一共展示了FilesModel::findByPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateFileTreeFields
/**
* Update FileTree fields
*/
public function updateFileTreeFields()
{
$objDatabase = \Database::getInstance();
$arrFields = array('singleSRC', 'imgSRC');
// Check the column type
$objDesc = $objDatabase->query("DESC tl_downloadarchiveitems singleSRC");
// Change the column type
if ($objDesc->Type != 'binary(16)') {
foreach ($arrFields as $field) {
$objFiles = $objDatabase->execute("SELECT id,{$field} FROM tl_downloadarchiveitems");
$objDatabase->query("ALTER TABLE tl_downloadarchiveitems CHANGE {$field} {$field} binary(16) NULL");
#$objDatabase->query("UPDATE tl_downloadarchiveitems SET $field=NULL WHERE $field='' OR $field=0");
while ($objFiles->next()) {
$objHelper = $this->generateHelperObject($this->changePath($objFiles->{$field}));
// UUID already
if ($objHelper->isUuid) {
continue;
}
// Numeric ID to UUID
if ($objHelper->isNumeric) {
$objFile = \FilesModel::findByPk($objHelper->value);
$objDatabase->prepare("UPDATE tl_downloadarchiveitems SET {$field}=? WHERE id=?")->execute($objFile->uuid, $objFiles->id);
} else {
$objFile = \FilesModel::findByPath($objHelper->value);
$objDatabase->prepare("UPDATE tl_downloadarchiveitems SET {$field}=? WHERE id=?")->execute($objFile->uuid, $objFiles->id);
}
}
}
}
}
示例2: reverseTransform
/**
* Transforms a value from the transformed representation to its original
* representation.
* An example might be transforming a human readable date format to a unix timestamp.
*
* @param mixed $value The value in the transformed representation
*
* @return mixed The value in the original representation
*
* @throws TransformationFailedException When the transformation fails.
*/
public function reverseTransform($value)
{
$filesModel = \FilesModel::findByPath($value);
if (null === $filesModel) {
return $value;
}
return $filesModel->uuid;
}
示例3: run
/**
* Run the controller and parse the template
*/
public function run()
{
if ($this->strFile == '') {
die('No file given');
}
// Make sure there are no attempts to hack the file system
if (preg_match('@^\\.+@i', $this->strFile) || preg_match('@\\.+/@i', $this->strFile) || preg_match('@(://)+@i', $this->strFile)) {
die('Invalid file name');
}
// Limit preview to the files directory
if (!preg_match('@^' . preg_quote(Config::get('uploadPath'), '@') . '@i', $this->strFile)) {
die('Invalid path');
}
// Check whether the file exists
if (!file_exists(TL_ROOT . '/' . $this->strFile)) {
die('File not found');
}
// Check whether the file is mounted (thanks to Marko Cupic)
if (!$this->User->hasAccess($this->strFile, 'filemounts')) {
die('Permission denied');
}
// Open the download dialogue
if (Input::get('download')) {
$objFile = new File($this->strFile, true);
$objFile->sendToBrowser();
}
// Add the resource (see #6880)
if (($objModel = FilesModel::findByPath($this->strFile)) === null) {
$objModel = Dbafs::addResource($this->strFile);
}
$this->Template = new BackendTemplate('be_popup');
$this->Template->uuid = String::binToUuid($objModel->uuid);
// see #5211
// Add the file info
if (is_dir(TL_ROOT . '/' . $this->strFile)) {
$objFile = new Folder($this->strFile, true);
} else {
$objFile = new File($this->strFile, true);
// Image
if ($objFile->isGdImage) {
$this->Template->isImage = true;
$this->Template->width = $objFile->width;
$this->Template->height = $objFile->height;
$this->Template->src = $this->urlEncode($this->strFile);
}
$this->Template->href = ampersand(Environment::get('request'), true) . '&download=1';
$this->Template->filesize = $this->getReadableSize($objFile->filesize) . ' (' . number_format($objFile->filesize, 0, $GLOBALS['TL_LANG']['MSC']['decimalSeparator'], $GLOBALS['TL_LANG']['MSC']['thousandsSeparator']) . ' Byte)';
}
$this->Template->icon = $objFile->icon;
$this->Template->mime = $objFile->mime;
$this->Template->ctime = Date::parse(Config::get('datimFormat'), $objFile->ctime);
$this->Template->mtime = Date::parse(Config::get('datimFormat'), $objFile->mtime);
$this->Template->atime = Date::parse(Config::get('datimFormat'), $objFile->atime);
$this->Template->path = $this->strFile;
$this->output();
}
示例4: executeResizeHook
public function executeResizeHook($objImage)
{
if (TL_MODE == 'BE') {
return false;
}
// do not return a string to not interrupt Image::executeResize
$objFile = \FilesModel::findByPath($objImage->getOriginalPath());
if ($objFile !== null) {
FileCreditIndex::indexFile($objFile);
}
return false;
// do not return a string to not interrupt Image::executeResize
}
示例5: renameFiles
/**
* Renames the given files
*
* @param array $arrFiles
*
* @return none
*/
public function renameFiles($arrFiles)
{
if (!$GLOBALS['TL_CONFIG']['checkFilenames']) {
return null;
}
$this->Import('Files');
$this->Import('FilesModel');
if (!empty($arrFiles)) {
foreach ($arrFiles as $file) {
// rename physical file
$newFile = $this->replaceForbiddenCharacters($file);
// because the \Files renaming function is doing
$this->Files->rename($file, $newFile . '.tmp');
$this->Files->rename($newFile . '.tmp', $newFile);
// rename file in database
$objFile = \FilesModel::findByPath($file);
$objFile->path = $newFile;
$objFile->hash = md5_file(TL_ROOT . '/' . $newFile);
$objFile->save();
}
}
}
示例6: addFolderToArchive
/**
* Recursively add a folder to the archive
*
* @param \ZipWriter $objArchive
* @param string $strFolder
* @param \DOMDocument $xml
* @param \DOMNode|\DOMElement $table
* @param array $arrOrder
*
* @throws \Exception If the folder path is insecure
*/
protected function addFolderToArchive(\ZipWriter $objArchive, $strFolder, \DOMDocument $xml, \DOMElement $table, array $arrOrder = array())
{
// Strip the custom upload folder name
$strFolder = preg_replace('@^' . preg_quote(\Config::get('uploadPath'), '@') . '/@', '', $strFolder);
// Add the default upload folder name
if ($strFolder == '') {
$strTarget = 'files';
$strFolder = \Config::get('uploadPath');
} else {
$strTarget = 'files/' . $strFolder;
$strFolder = \Config::get('uploadPath') . '/' . $strFolder;
}
if (\Validator::isInsecurePath($strFolder)) {
throw new \RuntimeException('Insecure path ' . $strFolder);
}
// Return if the folder does not exist
if (!is_dir(TL_ROOT . '/' . $strFolder)) {
return;
}
// Recursively add the files and subfolders
foreach (scan(TL_ROOT . '/' . $strFolder) as $strFile) {
// Skip hidden resources
if (strncmp($strFile, '.', 1) === 0) {
continue;
}
if (is_dir(TL_ROOT . '/' . $strFolder . '/' . $strFile)) {
$this->addFolderToArchive($objArchive, $strFolder . '/' . $strFile, $xml, $table, $arrOrder);
} else {
// Always store files in files and convert the directory upon import
$objArchive->addFile($strFolder . '/' . $strFile, $strTarget . '/' . $strFile);
$arrRow = array();
$objFile = new \File($strFolder . '/' . $strFile, true);
$objModel = \FilesModel::findByPath($strFolder . '/' . $strFile);
if ($objModel !== null) {
$arrRow = $objModel->row();
foreach (array('id', 'pid', 'tstamp', 'uuid', 'type', 'extension', 'found', 'name') as $key) {
unset($arrRow[$key]);
}
}
// Always use files as directory and convert it upon import
$arrRow['path'] = $strTarget . '/' . $strFile;
$arrRow['hash'] = $objFile->hash;
// Add the row
$this->addDataRow($xml, $table, $arrRow, $arrOrder);
}
}
}
示例7: createNewUser
/**
* Create a new user based on the given data
* @param array
* @return boolean
*/
protected function createNewUser($arrProfile)
{
\System::loadLanguageFile('tl_member');
$this->loadDataContainer('tl_member');
// Call onload_callback (e.g. to check permissions)
if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'])) {
foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$this->{$callback}[0]->{$callback}[1]();
}
}
}
$time = time();
$arrData = array('tstamp' => $time, 'dateAdded' => $time, 'firstname' => $arrProfile['first_name'], 'lastname' => $arrProfile['last_name'], 'gender' => $arrProfile['gender'], 'email' => $arrProfile['email'], 'login' => 1, 'username' => 'fb_' . $arrProfile['id'], 'fblogin' => $arrProfile['id'], 'groups' => $this->reg_groups);
$blnHasError = false;
// Check the data
foreach ($arrData as $k => $v) {
if (!isset($GLOBALS['TL_DCA']['tl_member']['fields'][$k])) {
unset($arrData[$k]);
continue;
}
$arrField = $GLOBALS['TL_DCA']['tl_member']['fields'][$k];
// Make sure that unique fields are unique
if ($arrField['eval']['unique'] && $v != '' && !$this->Database->isUniqueValue('tl_member', $k, $v)) {
$blnHasError = true;
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrField['label'][0] ?: $k));
continue;
}
// Save callback
if (is_array($arrField['save_callback'])) {
foreach ($arrField['save_callback'] as $callback) {
$this->import($callback[0]);
try {
$v = $this->{$callback}[0]->{$callback}[1]($v, null);
} catch (\Exception $e) {
$blnHasError = true;
\Message::addError($e->getMessage());
}
}
$arrData[$k] = $v;
}
}
// HOOK: parse data before it is saved
if (isset($GLOBALS['TL_HOOKS']['validateFacebookLogin']) && is_array($GLOBALS['TL_HOOKS']['validateFacebookLogin'])) {
foreach ($GLOBALS['TL_HOOKS']['validateFacebookLogin'] as $callback) {
$this->import($callback[0]);
try {
$arrData = $this->{$callback}[0]->{$callback}[1]($arrData, $arrProfile);
} catch (\Exception $e) {
$blnHasError = true;
\Message::addError($e->getMessage());
}
}
}
// Return false if there is an error
if ($blnHasError) {
return false;
}
$objNewUser = new \MemberModel();
$objNewUser->setRow($arrData);
$objNewUser->save();
// Assign home directory
if ($this->reg_assignDir) {
$objHomeDir = \FilesModel::findByUuid($this->reg_homeDir);
if ($objHomeDir !== null) {
$this->import('Files');
$strUserDir = standardize($arrData['username']) ?: 'user_' . $objNewUser->id;
// Add the user ID if the directory exists
while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) {
$strUserDir .= '_' . $objNewUser->id;
}
// Create the user folder
new \Folder($objHomeDir->path . '/' . $strUserDir);
$objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir);
// Save the folder ID
$objNewUser->assignDir = 1;
$objNewUser->homeDir = $objUserDir->uuid;
$objNewUser->save();
}
}
$insertId = $objNewUser->id;
// HOOK: send insert ID and user data
if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) {
foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) {
$this->import($callback[0]);
$this->{$callback}[0]->{$callback}[1]($insertId, $arrData, $this, $arrProfile);
}
}
return true;
}
示例8: execSync
/**
* Recursively synchronize the file system
* @param string
* @param integer
*/
protected function execSync($strPath, $intPid = 0)
{
if (!$this->blnIsDbAssisted) {
return;
}
$arrFiles = array();
$arrFolders = array();
$arrScan = scan(TL_ROOT . '/' . $strPath);
// Separate files from folders
foreach ($arrScan as $strFile) {
if ($strFile == '.svn' || $strFile == '.DS_Store') {
continue;
}
if (is_dir(TL_ROOT . '/' . $strPath . '/' . $strFile)) {
$arrFolders[] = $strPath . '/' . $strFile;
} else {
$arrFiles[] = $strPath . '/' . $strFile;
}
}
// Folders
foreach ($arrFolders as $strFolder) {
$objFolder = new \Folder($strFolder);
$objModel = \FilesModel::findByPath($strFolder);
// Create the entry if it does not yet exist
if ($objModel === null) {
$objModel = new \FilesModel();
$objModel->pid = $intPid;
$objModel->tstamp = time();
$objModel->name = basename($strFolder);
$objModel->type = 'folder';
$objModel->path = $strFolder;
$objModel->hash = $objFolder->hash;
$objModel->found = 1;
$objModel->save();
$this->arrMessages[] = '<p class="tl_new">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFolderC'], $strFolder) . '</p>';
} else {
// Update the hash if the folder has changed
if ($objModel->hash != $objFolder->hash) {
$objModel->hash = $objFolder->hash;
$this->arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncHash'], $strFolder) . '</p>';
}
$objModel->found = 1;
$objModel->save();
$this->arrMessages[] = '<p class="tl_confirm">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFolderF'], $strFolder) . '</p>';
}
$this->execSync($strFolder, $objModel->id);
}
// Files
foreach ($arrFiles as $strFile) {
$objFile = new \File($strFile);
$objModel = \FilesModel::findByPath($strFile);
// Create the entry if it does not yet exist
if ($objModel === null) {
$objModel = new \FilesModel();
$objModel->pid = $intPid;
$objModel->tstamp = time();
$objModel->name = basename($strFile);
$objModel->type = 'file';
$objModel->path = $strFile;
$objModel->extension = $objFile->extension;
$objModel->hash = $objFile->hash;
$objModel->found = 1;
$objModel->save();
$this->arrMessages[] = '<p class="tl_new">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFileC'], $strFile) . '</p>';
} else {
// Update the hash if the file has changed
if ($objModel->hash != $objFile->hash) {
$objModel->hash = $objFile->hash;
$this->arrMessages[] = '<p class="tl_info">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncHash'], $strFile) . '</p>';
}
$objModel->found = 1;
$objModel->save();
$this->arrMessages[] = '<p class="tl_confirm">' . sprintf($GLOBALS['TL_LANG']['tl_files']['syncFileF'], $strFile) . '</p>';
}
}
}
示例9: exportTable
//.........这里部分代码省略.........
$objXml->setIndentString("\t");
$objXml->startDocument('1.0', $strDestinationCharset != '' ? $strDestinationCharset : 'UTF-8');
$objXml->startElement($strTable);
foreach ($arrData as $row => $arrRow) {
// Headline
if ($row == 0) {
continue;
}
// New row
$objXml->startElement('datarecord');
//$objXml->writeAttribute('index', $row);
foreach ($arrRow as $i => $fieldvalue) {
// New field
$objXml->startElement($arrHeadline[$i]);
// Write Attributes
//$objXml->writeAttribute('name', $arrHeadline[$i]);
//$objXml->writeAttribute('type', gettype($fieldvalue));
//$objXml->writeAttribute('origtype', $arrFieldInfo[$arrHeadline[$i]]['type']);
// Convert to charset
if ($strDestinationCharset != '') {
$fieldvalue = iconv("UTF-8", $strDestinationCharset, $fieldvalue);
}
if (is_numeric($fieldvalue) || is_null($fieldvalue) || $fieldvalue == '') {
$objXml->text($fieldvalue);
} else {
// Write CDATA
$objXml->writeCdata($fieldvalue);
}
$objXml->endElement();
//end field-tag
}
$objXml->endElement();
// End row-tag
}
$objXml->endElement();
// End table-tag
$objXml->endDocument();
$xml = $objXml->outputMemory();
// Write output to file system
if ($strDestination != '') {
new \Folder($strDestination);
$objFolder = \FilesModel::findByPath($strDestination);
if ($objFolder !== null) {
if ($objFolder->type == 'folder' && is_dir(TL_ROOT . '/' . $objFolder->path)) {
$objFile = new \File($objFolder->path . '/' . $strTable . '_' . \Date::parse('Y-m-d_H-i-s') . '.csv');
$objFile->write($xml);
$objFile->close();
return;
}
}
}
// Send file to browser
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="' . $strTable . '.xml"');
echo $xml;
exit;
}
// csv-output
if ($exportType == 'csv') {
// Write output to file system
if ($strDestination != '') {
new \Folder($strDestination);
$objFolder = \FilesModel::findByPath($strDestination);
if ($objFolder !== null) {
if ($objFolder->type == 'folder' && is_dir(TL_ROOT . '/' . $objFolder->path)) {
$objFile = new \File($objFolder->path . '/' . $strTable . '_' . \Date::parse('Y-m-d_H-i-s') . '.csv');
foreach ($arrData as $arrRow) {
$arrLine = array_map(function ($v) use($strDestinationCharset) {
if ($strDestinationCharset != '') {
$v = iconv("UTF-8", $strDestinationCharset, $v);
}
return html_entity_decode($v);
}, $arrRow);
self::fputcsv($objFile->handle, $arrLine, $strSeperator, $strEnclosure);
}
$objFile->close();
}
}
return;
}
// Send file to browser
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=" . $strTable . ".csv");
header("Content-Description: csv File");
header("Pragma: no-cache");
header("Expires: 0");
$fh = fopen("php://output", 'w');
foreach ($arrData as $arrRow) {
$arrLine = array_map(function ($v) use($strDestinationCharset) {
if ($strDestinationCharset != '') {
$v = iconv("UTF-8", $strDestinationCharset, $v);
}
return html_entity_decode($v);
}, $arrRow);
self::fputcsv($fh, $arrLine, $strSeperator, $strEnclosure);
}
fclose($fh);
exit;
}
}
示例10: getModel
/**
* Return the files model
*
* @return FilesModel The files model
*/
public function getModel()
{
if ($this->objModel === null && \Dbafs::shouldBeSynchronized($this->strFolder)) {
$this->objModel = \FilesModel::findByPath($this->strFolder);
}
return $this->objModel;
}
示例11: syncFiles
/**
* Synchronize the file system with the database
*
* @return string The path to the synchronization log file
*
* @throws \Exception If a parent ID entry is missing
*/
public static function syncFiles()
{
// Try to raise the limits (see #7035)
@ini_set('memory_limit', -1);
@ini_set('max_execution_time', 0);
$objDatabase = \Database::getInstance();
// Lock the files table
$objDatabase->lockTables(array('tl_files'));
// Reset the "found" flag
$objDatabase->query("UPDATE tl_files SET found=''");
// Get a filtered list of all files
$objFiles = new \RecursiveIteratorIterator(new \Dbafs\Filter(new \RecursiveDirectoryIterator(TL_ROOT . '/' . \Config::get('uploadPath'), \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS)), \RecursiveIteratorIterator::SELF_FIRST);
$strLog = 'system/tmp/' . md5(uniqid(mt_rand(), true));
// Open the log file
$objLog = new \File($strLog, true);
$objLog->truncate();
$arrModels = array();
// Create or update the database entries
foreach ($objFiles as $objFile) {
$strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname());
// Get all subfiles in a single query
if ($objFile->isDir()) {
$objSubfiles = \FilesModel::findMultipleFilesByFolder($strRelpath);
if ($objSubfiles !== null) {
while ($objSubfiles->next()) {
$arrModels[$objSubfiles->path] = $objSubfiles->current();
}
}
}
// Get the model
if (isset($arrModels[$strRelpath])) {
$objModel = $arrModels[$strRelpath];
} else {
$objModel = \FilesModel::findByPath($strRelpath);
}
if ($objModel === null) {
// Add a log entry
$objLog->append("[Added] {$strRelpath}");
// Get the parent folder
$strParent = dirname($strRelpath);
// Get the parent ID
if ($strParent == \Config::get('uploadPath')) {
$strPid = null;
} else {
$objParent = \FilesModel::findByPath($strParent);
if ($objParent === null) {
throw new \Exception("No parent entry for {$strParent}");
}
$strPid = $objParent->uuid;
}
// Create the file or folder
if (is_file(TL_ROOT . '/' . $strRelpath)) {
$objFile = new \File($strRelpath, true);
$objModel = new \FilesModel();
$objModel->pid = $strPid;
$objModel->tstamp = time();
$objModel->name = $objFile->name;
$objModel->type = 'file';
$objModel->path = $objFile->path;
$objModel->extension = $objFile->extension;
$objModel->found = 2;
$objModel->hash = $objFile->hash;
$objModel->uuid = $objDatabase->getUuid();
$objModel->save();
} else {
$objFolder = new \Folder($strRelpath);
$objModel = new \FilesModel();
$objModel->pid = $strPid;
$objModel->tstamp = time();
$objModel->name = $objFolder->name;
$objModel->type = 'folder';
$objModel->path = $objFolder->path;
$objModel->extension = '';
$objModel->found = 2;
$objModel->hash = $objFolder->hash;
$objModel->uuid = $objDatabase->getUuid();
$objModel->save();
}
} else {
// Check whether the MD5 hash has changed
$objResource = $objFile->isDir() ? new \Folder($strRelpath) : new \File($strRelpath);
$strType = $objModel->hash != $objResource->hash ? 'Changed' : 'Unchanged';
// Add a log entry
$objLog->append("[{$strType}] {$strRelpath}");
// Update the record
$objModel->found = 1;
$objModel->hash = $objResource->hash;
$objModel->save();
}
}
// Check for left-over entries in the DB
$objFiles = \FilesModel::findByFound('');
if ($objFiles !== null) {
//.........这里部分代码省略.........
示例12: source
/**
* Load the source editor
*
* @return string
*/
public function source()
{
$this->isValid($this->intId);
if (is_dir(TL_ROOT . '/' . $this->intId)) {
$this->log('Folder "' . $this->intId . '" cannot be edited', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
} elseif (!file_exists(TL_ROOT . '/' . $this->intId)) {
$this->log('File "' . $this->intId . '" does not exist', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$this->import('BackendUser', 'User');
// Check user permission
if (!$this->User->hasAccess('f5', 'fop')) {
$this->log('Not enough permissions to edit the file source of file "' . $this->intId . '"', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$objFile = new \File($this->intId, true);
// Check whether file type is editable
if (!in_array($objFile->extension, trimsplit(',', strtolower(\Config::get('editableFiles'))))) {
$this->log('File type "' . $objFile->extension . '" (' . $this->intId . ') is not allowed to be edited', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$objMeta = null;
$objVersions = null;
// Add the versioning routines
if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) {
$objMeta = \FilesModel::findByPath($objFile->value);
if ($objMeta === null) {
$objMeta = \Dbafs::addResource($objFile->value);
}
$objVersions = new \Versions($this->strTable, $objMeta->id);
if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) {
// Compare versions
if (\Input::get('versions')) {
$objVersions->compare();
}
// Restore a version
if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') {
$objVersions->restore(\Input::post('version'));
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
$this->reload();
}
}
$objVersions->initialize();
}
$strContent = $objFile->getContent();
if ($objFile->extension == 'svgz') {
$strContent = gzdecode($strContent);
}
// Process the request
if (\Input::post('FORM_SUBMIT') == 'tl_files') {
// Restore the basic entities (see #7170)
$strSource = \StringUtil::restoreBasicEntities(\Input::postRaw('source'));
// Save the file
if (md5($strContent) != md5($strSource)) {
if ($objFile->extension == 'svgz') {
$strSource = gzencode($strSource);
}
// Write the file
$objFile->write($strSource);
$objFile->close();
// Update the database
if ($this->blnIsDbAssisted && $objMeta !== null) {
/** @var \FilesModel $objMeta */
$objMeta->hash = $objFile->hash;
$objMeta->save();
$objVersions->create();
}
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
}
if (\Input::post('saveNclose')) {
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->redirect($this->getReferer());
}
$this->reload();
}
$codeEditor = '';
// Prepare the code editor
if (\Config::get('useCE')) {
$selector = 'ctrl_source';
$type = $objFile->extension;
// Load the code editor configuration
ob_start();
include TL_ROOT . '/system/config/ace.php';
$codeEditor = ob_get_contents();
ob_end_clean();
unset($selector, $type);
//.........这里部分代码省略.........
示例13: generate
/**
* Generate the widget and return it as string
* @return string
*/
public function generate()
{
$this->import('BackendUser', 'User');
// Store the keyword
if (\Input::post('FORM_SUBMIT') == 'item_selector') {
$this->Session->set('file_selector_search', \Input::post('keyword'));
$this->reload();
}
// Extension filter
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['extensions'] != '') {
$this->strExtensions = " AND (type='folder' OR extension IN('" . implode("','", trimsplit(',', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['extensions'])) . "'))";
}
// Sort descending
if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['flag']) && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['flag'] % 2 == 0) {
$this->strSortFlag = ' DESC';
}
$tree = '';
$this->getPathNodes();
$for = $this->Session->get('file_selector_search');
$arrIds = array();
// Search for a specific file
if ($for != '') {
// The keyword must not start with a wildcard (see #4910)
if (strncmp($for, '*', 1) === 0) {
$for = substr($for, 1);
}
$objRoot = $this->Database->prepare("SELECT id FROM tl_files WHERE CAST(name AS CHAR) REGEXP ?{$this->strExtensions} ORDER BY type='file', name{$this->strSortFlag}")->execute($for);
if ($objRoot->numRows > 0) {
// Respect existing limitations
if ($this->User->isAdmin) {
$arrIds = $objRoot->fetchEach('id');
} else {
$arrRoot = array();
while ($objRoot->next()) {
if (count(array_intersect($this->User->filemounts, $this->Database->getParentRecords($objRoot->id, 'tl_files'))) > 0) {
$arrRoot[] = $objRoot->id;
}
}
$arrIds = $arrRoot;
}
}
// Build the tree
foreach ($arrIds as $id) {
$tree .= $this->renderFiletree($id, -20, false, true);
}
} else {
// Show a custom path (see #4926)
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['path'] != '') {
$objFolder = \FilesModel::findByPath($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['path']);
if ($objFolder !== null) {
$tree .= $this->renderFiletree($objFolder->id, -20);
}
} elseif ($this->User->isAdmin) {
$objFile = $this->Database->prepare("SELECT id FROM tl_files WHERE pid=?{$this->strExtensions} ORDER BY type='file', name{$this->strSortFlag}")->execute(0);
while ($objFile->next()) {
$tree .= $this->renderFiletree($objFile->id, -20);
}
} else {
foreach ($this->eliminateNestedPages($this->User->filemountIds, 'tl_files') as $node) {
$tree .= $this->renderFiletree($node, -20);
}
}
}
// Select all checkboxes
if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType'] == 'checkbox') {
$strReset = "\n" . ' <li class="tl_folder"><div class="tl_left"> </div> <div class="tl_right"><label for="check_all_' . $this->strId . '" class="tl_change_selected">' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</label> <input type="checkbox" id="check_all_' . $this->strId . '" class="tl_tree_checkbox" value="" onclick="Backend.toggleCheckboxGroup(this,\'' . $this->strName . '\')"></div><div style="clear:both"></div></li>';
} else {
$strReset = "\n" . ' <li class="tl_folder"><div class="tl_left"> </div> <div class="tl_right"><label for="reset_' . $this->strId . '" class="tl_change_selected">' . $GLOBALS['TL_LANG']['MSC']['resetSelected'] . '</label> <input type="radio" name="' . $this->strName . '" id="reset_' . $this->strName . '" class="tl_tree_radio" value="" onfocus="Backend.getScrollOffset()"></div><div style="clear:both"></div></li>';
}
// Return the tree
return '<ul class="tl_listing tree_view' . ($this->strClass != '' ? ' ' . $this->strClass : '') . '" id="' . $this->strId . '">
<li class="tl_folder_top"><div class="tl_left">' . $this->generateImage($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['icon'] != '' ? $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['icon'] : 'filemounts.gif') . ' ' . ($GLOBALS['TL_CONFIG']['websiteTitle'] ?: 'Contao Open Source CMS') . '</div> <div class="tl_right"> </div><div style="clear:both"></div></li><li class="parent" id="' . $this->strId . '_parent"><ul>' . $tree . $strReset . '
</ul></li></ul>';
}
示例14: validate
//.........这里部分代码省略.........
$this->log('File "' . $file['name'] . '" could not be uploaded (error ' . $file['error'] . ')', __METHOD__, TL_ERROR);
}
unset($_FILES[$this->strName]);
return;
}
// File is too big
if ($this->maxlength > 0 && $file['size'] > $this->maxlength) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filesize'], $maxlength_kb));
$this->log('File "' . $file['name'] . '" exceeds the maximum file size of ' . $maxlength_kb, __METHOD__, TL_ERROR);
unset($_FILES[$this->strName]);
return;
}
$strExtension = pathinfo($file['name'], PATHINFO_EXTENSION);
$uploadTypes = trimsplit(',', $this->extensions);
// File type is not allowed
if (!in_array(strtolower($strExtension), $uploadTypes)) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $strExtension));
$this->log('File type "' . $strExtension . '" is not allowed to be uploaded (' . $file['name'] . ')', __METHOD__, TL_ERROR);
unset($_FILES[$this->strName]);
return;
}
if (($arrImageSize = @getimagesize($file['tmp_name'])) != false) {
// Image exceeds maximum image width
if ($arrImageSize[0] > \Config::get('imageWidth')) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filewidth'], $file['name'], \Config::get('imageWidth')));
$this->log('File "' . $file['name'] . '" exceeds the maximum image width of ' . \Config::get('imageWidth') . ' pixels', __METHOD__, TL_ERROR);
unset($_FILES[$this->strName]);
return;
}
// Image exceeds maximum image height
if ($arrImageSize[1] > \Config::get('imageHeight')) {
$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['fileheight'], $file['name'], \Config::get('imageHeight')));
$this->log('File "' . $file['name'] . '" exceeds the maximum image height of ' . \Config::get('imageHeight') . ' pixels', __METHOD__, TL_ERROR);
unset($_FILES[$this->strName]);
return;
}
}
// Store file in the session and optionally on the server
if (!$this->hasErrors()) {
$_SESSION['FILES'][$this->strName] = $_FILES[$this->strName];
$this->log('File "' . $file['name'] . '" uploaded successfully', __METHOD__, TL_FILES);
if ($this->storeFile) {
$intUploadFolder = $this->uploadFolder;
// Overwrite the upload folder with user's home directory
if ($this->useHomeDir && FE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
if ($this->User->assignDir && $this->User->homeDir) {
$intUploadFolder = $this->User->homeDir;
}
}
$objUploadFolder = \FilesModel::findByUuid($intUploadFolder);
// The upload folder could not be found
if ($objUploadFolder === null) {
throw new \Exception("Invalid upload folder ID {$intUploadFolder}");
}
$strUploadFolder = $objUploadFolder->path;
// Store the file if the upload folder exists
if ($strUploadFolder != '' && is_dir(TL_ROOT . '/' . $strUploadFolder)) {
$this->import('Files');
// Do not overwrite existing files
if ($this->doNotOverwrite && file_exists(TL_ROOT . '/' . $strUploadFolder . '/' . $file['name'])) {
$offset = 1;
$pathinfo = pathinfo($file['name']);
$name = $pathinfo['filename'];
$arrAll = scan(TL_ROOT . '/' . $strUploadFolder);
$arrFiles = preg_grep('/^' . preg_quote($name, '/') . '.*\\.' . preg_quote($pathinfo['extension'], '/') . '/', $arrAll);
foreach ($arrFiles as $strFile) {
if (preg_match('/__[0-9]+\\.' . preg_quote($pathinfo['extension'], '/') . '$/', $strFile)) {
$strFile = str_replace('.' . $pathinfo['extension'], '', $strFile);
$intValue = intval(substr($strFile, strrpos($strFile, '_') + 1));
$offset = max($offset, $intValue);
}
}
$file['name'] = str_replace($name, $name . '__' . ++$offset, $file['name']);
}
$this->Files->move_uploaded_file($file['tmp_name'], $strUploadFolder . '/' . $file['name']);
$this->Files->chmod($strUploadFolder . '/' . $file['name'], \Config::get('defaultFileChmod'));
// Generate the DB entries
$strFile = $strUploadFolder . '/' . $file['name'];
$objFile = \FilesModel::findByPath($strFile);
// Existing file is being replaced (see #4818)
if ($objFile !== null) {
$objFile->tstamp = time();
$objFile->path = $strFile;
$objFile->hash = md5_file(TL_ROOT . '/' . $strFile);
$objFile->save();
} else {
$objFile = \Dbafs::addResource($strFile);
}
// Update the hash of the target folder
\Dbafs::updateFolderHashes($strUploadFolder);
// Add the session entry (see #6986)
$_SESSION['FILES'][$this->strName] = array('name' => $file['name'], 'type' => $file['type'], 'tmp_name' => TL_ROOT . '/' . $strFile, 'error' => $file['error'], 'size' => $file['size'], 'uploaded' => true, 'uuid' => \String::binToUuid($objFile->uuid));
// Add a log entry
$this->log('File "' . $file['name'] . '" has been moved to "' . $strUploadFolder . '"', __METHOD__, TL_FILES);
}
}
}
unset($_FILES[$this->strName]);
}
示例15: compile
//.........这里部分代码省略.........
}
// Make sure that unique fields are unique (check the eval setting first -> #3063)
if ($arrData['eval']['unique'] && $varValue != '' && !$this->Database->isUniqueValue($this->strTableData, $field, $varValue)) {
$objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrData['label'][0] ?: $field));
}
// Save callback
if ($objWidget->submitInput() && !$objWidget->hasErrors() && is_array($arrData['save_callback'])) {
foreach ($arrData['save_callback'] as $callback) {
try {
if (is_array($callback)) {
$this->import($callback[0]);
$varValue = $this->{$callback[0]}->{$callback[1]}($varValue, null);
} elseif (is_callable($callback)) {
$varValue = $callback($varValue, null);
}
} catch (\Exception $e) {
$objWidget->class = 'error';
$objWidget->addError($e->getMessage());
}
}
}
// Store the current value
if ($objWidget->hasErrors()) {
$doNotSubmit = true;
} elseif ($objWidget->submitInput()) {
// Set the correct empty value (see #6284, #6373)
if ($varValue === '') {
$varValue = $objWidget->getEmptyValue();
}
// Encrypt the value (see #7815)
if ($arrData['eval']['encrypt']) {
$varValue = \Encryption::encrypt($varValue);
}
// Set the new value
$arrValidData[$field] = $varValue;
}
// store file
$Files = $_SESSION['FILES'];
if ($Files && isset($Files[$field]) && $this->fm_storeFile) {
$strRoot = TL_ROOT . '/';
$strUuid = $Files[$field]['uuid'];
$strFile = substr($Files[$field]['tmp_name'], strlen($strRoot));
$arrFiles = \FilesModel::findByPath($strFile);
if ($arrFiles !== null) {
$strUuid = $arrFiles->uuid;
}
$arrValidData[$field] = $strUuid;
}
// reset session
if ($Files && isset($Files[$field])) {
unset($_SESSION['FILES'][$field]);
}
}
if ($objWidget instanceof \uploadable) {
$hasUpload = true;
}
$temp = $objWidget->parse();
// $objWidget->generate();
$this->Template->fields .= $temp;
$arrFields[$arrData['eval']['fmGroup']][$field] .= $temp;
++$i;
}
// Captcha
if (!$this->disableCaptcha) {
$objCaptcha->rowClass = 'row_' . $i . ($i == 0 ? ' row_first' : '') . ($i % 2 == 0 ? ' even' : ' odd');
$strCaptcha = $objCaptcha->parse();
$this->Template->fields .= $strCaptcha;
$arrFields['captcha']['captcha'] .= $strCaptcha;
}
$this->Template->rowLast = 'row_' . ++$i . ($i % 2 == 0 ? ' even' : ' odd');
$this->Template->enctype = $hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
$this->Template->hasError = $doNotSubmit;
// Create new entity if there are no errors
if (\Input::post('FORM_SUBMIT') == 'fm_registration' && !$doNotSubmit) {
$this->createNewEntity($arrValidData);
}
$this->Template->teaserDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['teaserData'];
$this->Template->dateDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['dateDetails'];
$this->Template->imageDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['imageDetails'];
$this->Template->enclosureDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['enclosureDetails'];
$this->Template->expertDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['expertDetails'];
$this->Template->mapDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['mapDetails'];
$this->Template->authorDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['authorDetails'];
$this->Template->sourceDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['sourceDetails'];
$this->Template->otherDetails = $GLOBALS['TL_LANG']['tl_fmodules_language_pack']['otherDetails'];
$this->Template->captchaDetails = $GLOBALS['TL_LANG']['MSC']['securityQuestion'];
// Add the groups
foreach ($arrFields as $k => $v) {
$this->Template->{$k} = $v;
// backwards compatibility
$key = $k . ($k == 'teaser' ? 'Data' : 'Details');
$arrGroups[$GLOBALS['TL_LANG']['tl_fmodules_language_pack'][$key]] = $v;
}
$this->Template->categories = $arrGroups;
$this->Template->formId = 'fm_registration';
$this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['register']);
$this->Template->action = \Environment::get('indexFreeRequest');
$this->Template->captcha = $arrFields['captcha']['captcha'];
// backwards compatibility
}