本文整理汇总了PHP中FileManager::parseFileExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::parseFileExtension方法的具体用法?PHP FileManager::parseFileExtension怎么用?PHP FileManager::parseFileExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::parseFileExtension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrateSubmissionFilePaths
/**
* For 3.0.0 upgrade. Migrates submission files to new paths.
*/
function migrateSubmissionFilePaths()
{
$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
import('lib.pkp.classes.submission.SubmissionFile');
$genreDao = DAORegistry::getDAO('GenreDAO');
$journalDao = DAORegistry::getDAO('JournalDAO');
$submissionFile = new SubmissionFile();
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$articleFilesResult = $submissionFileDao->retrieve('SELECT af.*, s.submission_id, s.context_id FROM article_files_migration af, submissions s WHERE af.article_id = s.submission_id');
$filesDir = Config::getVar('files', 'files_dir') . '/journals/';
while (!$articleFilesResult->EOF) {
$row = $articleFilesResult->GetRowAssoc(false);
// Assemble the old file path.
$oldFilePath = $filesDir . $row['context_id'] . '/articles/' . $row['submission_id'] . '/';
if (isset($row['type'])) {
// pre 2.4 upgrade.
$oldFilePath .= $row['type'];
} else {
// post 2.4, we have file_stage instead.
switch ($row['file_stage']) {
case 1:
$oldFilePath .= 'submission/original';
break;
case 2:
$oldFilePath .= 'submission/review';
break;
case 3:
$oldFilePath .= 'submission/editor';
break;
case 4:
$oldFilePath .= 'submission/copyedit';
break;
case 5:
$oldFilePath .= 'submission/layout';
break;
case 6:
$oldFilePath .= 'supp';
break;
case 7:
$oldFilePath .= 'public';
break;
case 8:
$oldFilePath .= 'note';
break;
case 9:
$oldFilePath .= 'attachment';
break;
}
}
$oldFilePath .= '/' . $row['file_name'];
if (file_exists($oldFilePath)) {
// sanity check.
$newFilePath = $filesDir . $row['context_id'] . '/articles/' . $row['submission_id'] . '/';
// Since we cannot be sure that we had a file_stage column before, query the new submission_files table.
$submissionFileResult = $submissionFileDao->retrieve('SELECT genre_id, file_stage, date_uploaded, original_file_name
FROM submission_files WHERE file_id = ? and revision = ?', array($row['file_id'], $row['revision']));
$submissionFileRow = $submissionFileResult->GetRowAssoc(false);
$newFilePath .= $submissionFile->_fileStageToPath($submissionFileRow['file_stage']);
$genre = $genreDao->getById($submissionFileRow['genre_id']);
// pull in the primary locale for this journal without loading the whole object.
$localeResult = $journalDao->retrieve('SELECT primary_locale FROM journals WHERE journal_id = ?', array($row['context_id']));
$localeRow = $localeResult->GetRowAssoc(false);
$newFilePath .= '/' . $row['submission_id'] . '-' . $genre->getDesignation() . '_' . $genre->getName($localeRow['primary_locale']) . '-' . $row['file_id'] . '-' . $row['revision'] . '-' . $submissionFileRow['file_stage'] . '-' . date('Ymd', strtotime($submissionFileRow['date_uploaded'])) . '.' . strtolower_codesafe($fileManager->parseFileExtension($submissionFileRow['original_file_name']));
$fileManager->copyFile($oldFilePath, $newFilePath);
if (file_exists($newFilePath)) {
$fileManager->deleteFile($oldFilePath);
}
}
$articleFilesResult->MoveNext();
unset($localeResult);
unset($submissionFileResult);
unset($localeRow);
unset($submissionFileRow);
}
return true;
}
示例2: getExtension
/**
* Get the file's extension.
* @return string
*/
function getExtension()
{
import('lib.pkp.classes.file.FileManager');
return strtoupper(FileManager::parseFileExtension($this->getOriginalFileName()));
}
示例3: viewFileContents
/**
* Output PDF generated from the XML/XSL/FO source to browser
* This function performs any necessary filtering, like image URL replacement.
* @return string
*/
function viewFileContents()
{
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$pdfFileName = CacheManager::getFileCachePath() . DIRECTORY_SEPARATOR . 'fc-xsltGalley-' . str_replace($fileManager->parseFileExtension($this->getFileName()), 'pdf', $this->getFileName());
// if file does not exist or is outdated, regenerate it from FO
if (!$fileManager->fileExists($pdfFileName) || filemtime($pdfFileName) < filemtime($this->getFilePath())) {
// render XML into XSL-FO
$cache =& $this->_getXSLTCache($this->getFileName() . '-' . $this->getId());
$contents = $cache->getContents();
if ($contents == "") {
return false;
}
// if for some reason the XSLT failed, show original file
// Replace image references
$images =& $this->getImageFiles();
if ($images !== null) {
// TODO: this should "smart replace" the file path ($this->getFilePath()) in the XSL-FO
// in lieu of requiring XSL parameters, and transparently for FO that are hardcoded
foreach ($images as $image) {
$contents = preg_replace('/src\\s*=\\s*"([^"]*)' . preg_quote($image->getOriginalFileName()) . '([^"]*)"/i', 'src="${1}' . dirname($this->getFilePath()) . DIRECTORY_SEPARATOR . $image->getFileName() . '$2"', $contents);
}
}
// Replace supplementary file references
$this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
$suppFiles = $this->suppFileDao->getSuppFilesByArticle($this->getArticleId());
if ($suppFiles) {
$journal =& Request::getJournal();
foreach ($suppFiles as $supp) {
$suppUrl = Request::url(null, 'article', 'downloadSuppFile', array($this->getArticleId(), $supp->getBestSuppFileId($journal)));
$contents = preg_replace('/external-destination\\s*=\\s*"([^"]*)' . preg_quote($supp->getOriginalFileName()) . '([^"]*)"/i', 'external-destination="' . $suppUrl . '"', $contents);
}
}
// create temporary FO file and write the contents
import('classes.file.TemporaryFileManager');
$temporaryFileManager = new TemporaryFileManager();
$tempFoName = $temporaryFileManager->filesDir . $this->getFileName() . '-' . $this->getId() . '.fo';
$temporaryFileManager->writeFile($tempFoName, $contents);
// perform %fo and %pdf replacements for fully-qualified shell command
$journal =& Request::getJournal();
$xmlGalleyPlugin =& PluginRegistry::getPlugin('generic', $this->parentPluginName);
$fopCommand = str_replace(array('%fo', '%pdf'), array($tempFoName, $pdfFileName), $xmlGalleyPlugin->getSetting($journal->getId(), 'externalFOP'));
// check for safe mode and escape the shell command
if (!ini_get('safe_mode')) {
$fopCommand = escapeshellcmd($fopCommand);
}
// run the shell command and get the results
exec($fopCommand . ' 2>&1', $contents, $status);
// if there is an error, spit out the shell results to aid debugging
if ($status != false) {
if ($contents != '') {
echo implode("\n", $contents);
$cache->flush();
// clear the XSL cache in case it's a FO error
return true;
} else {
return false;
}
}
// clear the temporary FO file
$fileManager->deleteFile($tempFoName);
}
// use FileManager to send file to browser
$fileManager->downloadFile($pdfFileName, $this->getFileType(), true);
return true;
}