/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $mediaType string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null) { $result = null; if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) { return $result; } if (is_readable($filePath)) { if ($mediaType === null) { // If the media type wasn't specified, try to detect. $mediaType = String::mime_content_type($filePath); if (empty($mediaType)) { $mediaType = 'application/octet-stream'; } } if ($fileName === null) { // If the filename wasn't specified, use the server-side. $fileName = basename($filePath); } Registry::clear(); // Free some memory header("Content-Type: {$mediaType}"); header('Content-Length: ' . filesize($filePath)); header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\""); header('Cache-Control: private'); // Workarounds for IE weirdness header('Pragma: public'); // Beware of converting to instance call // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396 FileManager::readFile($filePath, true); return true; } else { return false; } }
/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $mediaType string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null) { $result = null; if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) { return $result; } $postDownloadHookList = array('FileManager::downloadFileFinished', 'UsageEventPlugin::getUsageEvent'); if (is_readable($filePath)) { if ($mediaType === null) { // If the media type wasn't specified, try to detect. $mediaType = String::mime_content_type($filePath); if (empty($mediaType)) { $mediaType = 'application/octet-stream'; } } if ($fileName === null) { // If the filename wasn't specified, use the server-side. $fileName = basename($filePath); } $postDownloadHooks = null; $hooks = HookRegistry::getHooks(); foreach ($postDownloadHookList as $hookName) { if (isset($hooks[$hookName])) { $postDownloadHooks[$hookName] = $hooks[$hookName]; } } unset($hooks); Registry::clear(); // Stream the file to the end user. header("Content-Type: {$mediaType}"); header('Content-Length: ' . filesize($filePath)); header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\""); header('Cache-Control: private'); // Workarounds for IE weirdness header('Pragma: public'); // Beware of converting to instance call // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396 FileManager::readFile($filePath, true); if ($postDownloadHooks) { foreach ($postDownloadHooks as $hookName => $hooks) { HookRegistry::setHooks($hookName, $hooks); } } $returner = true; } else { $returner = false; } HookRegistry::call('FileManager::downloadFileFinished', array(&$returner)); return $returner; }
function _fileMimeType($filePath) { return String::mime_content_type($filePath); }
/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $mediaType string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $mediaType = null, $inline = false) { $result = null; if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result))) { return $result; } if (is_readable($filePath)) { if ($mediaType == null) { $mediaType = String::mime_content_type($filePath); if (empty($mediaType)) { $mediaType = 'application/octet-stream'; } } Registry::clear(); // Free some memory header("Content-Type: {$mediaType}"); header("Content-Length: " . filesize($filePath)); header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\""); header("Cache-Control: private"); // Workarounds for IE weirdness header("Pragma: public"); import('lib.pkp.classes.file.FileManager'); FileManager::readFile($filePath, true); return true; } else { return false; } }
/** * Copy all image files for an article's HTML galley. * @param $galley ArticleHTMLGalley * @param $prefix string image file prefix, e.g. "<abbrev>-<year>-<id>" */ function copyHTMLGalleyImages($galley, $prefix) { $dir = opendir($this->importPath . '/images/articleimages'); if (!$dir) { printf("Failed to open directory %s\n", $this->importPath . '/images/articleimages'); return; // This should never happen } while (($file = readdir($dir)) !== false) { if (!strstr($file, $prefix . '-')) { continue; } if (!isset($fileManager)) { $fileManager =& new ArticleFileManager($galley->getArticleId()); $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO'); $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO'); } $fileType = ARTICLE_FILE_PUBLIC; $oldPath = $this->importPath . '/images/articleimages/' . $file; $mimeType = String::mime_content_type($oldPath); if (empty($mimeType)) { $extension = $fileManager->getExtension($file); if ($extension == 'jpg') { $mimeType = 'image/jpeg'; } else { $mimeType = 'image/' . $extension; } } $articleFile =& new ArticleFile(); $articleFile->setArticleId($galley->getArticleId()); $articleFile->setFileName('temp'); $articleFile->setOriginalFileName($file); $articleFile->setFileType($mimeType); $articleFile->setFileSize(filesize($oldPath)); $articleFile->setType($fileManager->typeToPath($fileType)); $articleFile->setStatus(''); $articleFile->setDateUploaded(date('Y-m-d', filemtime($oldPath))); $articleFile->setDateModified($articleFile->getDateUploaded()); $articleFile->setRound(1); $articleFile->setRevision(1); $fileId = $articleFileDao->insertArticleFile($articleFile); $newFileName = $fileManager->generateFilename($articleFile, $fileType, $file); if (!$fileManager->copyFile($oldPath, $fileManager->filesDir . $fileManager->typeToPath($fileType) . '/' . $newFileName)) { $articleFileDao->deleteArticleFileById($articleFile->getFileId()); printf("Failed to copy file %s\n", $oldPath); // This should never happen } else { $articleFileDao->updateArticleFile($articleFile); $galleyDao->insertGalleyImage($galley->getGalleyId(), $fileId); } } closedir($dir); }
/** * Upload the file and add it to the database. * @param $fileName string index into the $_FILES array * @param $userId int * @return object The new TemporaryFile or false on failure */ function handleUpload($fileName, $userId) { // Get the file extension, then rename the file. $fileExtension = $this->parseFileExtension($this->getUploadedFileName($fileName)); if (!$this->fileExists($this->getBasePath(), 'dir')) { // Try to create destination directory $this->mkdirtree($this->getBasePath()); } $newFileName = basename(tempnam($this->getBasePath(), $fileExtension)); if (!$newFileName) { return false; } if ($this->uploadFile($fileName, $this->getBasePath() . $newFileName)) { $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO'); $temporaryFile = $temporaryFileDao->newDataObject(); $temporaryFile->setUserId($userId); $temporaryFile->setFileName($newFileName); $temporaryFile->setFileType(String::mime_content_type($this->getBasePath() . $newFileName)); $temporaryFile->setFileSize($_FILES[$fileName]['size']); $temporaryFile->setOriginalFileName($this->truncateFileName($_FILES[$fileName]['name'], 127)); $temporaryFile->setDateUploaded(Core::getCurrentDate()); $temporaryFileDao->insertTemporaryFile($temporaryFile); return $temporaryFile; } else { return false; } }
/** * Adds a file attachment to the email. * @param $filePath string complete path to the file to attach * @param $fileName string attachment file name (optional) * @param $contentType string attachment content type (optional) * @param $contentDisposition string attachment content disposition, inline or attachment (optional, default attachment) */ function addAttachment($filePath, $fileName = '', $contentType = '', $contentDisposition = 'attachment') { if (($attachments =& $this->getData('attachments')) == null) { $attachments = array(); } /* If the arguments $fileName and $contentType are not specified, then try and determine them automatically. */ if (empty($fileName)) { $fileName = basename($filePath); } if (empty($contentType)) { $contentType = String::mime_content_type($filePath); if (empty($contentType)) { $contentType = 'application/x-unknown-content-type'; } } // Open the file and read contents into $attachment if (is_readable($filePath) && is_file($filePath)) { $fp = fopen($filePath, 'rb'); if ($fp) { $content = ''; while (!feof($fp)) { $content .= fread($fp, 4096); } fclose($fp); } } if (isset($content)) { /* Encode the contents in base64. */ $content = chunk_split(base64_encode($content), MAIL_WRAP, MAIL_EOL); array_push($attachments, array('filename' => $fileName, 'content-type' => $contentType, 'disposition' => $contentDisposition, 'content' => $content)); return $this->setData('attachments', $attachments); } else { return false; } }
function &generateArticleDom(&$doc, &$journal, &$issue, &$section, &$article) { $root =& XMLCustomWriter::createElement($doc, 'article'); XMLCustomWriter::setAttribute($root, 'locale', $article->getLocale()); XMLCustomWriter::setAttribute($root, 'public_id', $article->getPubId('publisher-id'), false); XMLCustomWriter::setAttribute($root, 'language', $article->getLanguage(), false); NativeExportDom::generatePubId($doc, $root, $article, $issue); /* --- Titles and Abstracts --- */ if (is_array($article->getTitle(null))) { foreach ($article->getTitle(null) as $locale => $title) { $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false); if ($titleNode) { XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); } unset($titleNode); } } if (is_array($article->getAbstract(null))) { foreach ($article->getAbstract(null) as $locale => $abstract) { $abstractNode =& XMLCustomWriter::createChildWithText($doc, $root, 'abstract', $abstract, false); if ($abstractNode) { XMLCustomWriter::setAttribute($abstractNode, 'locale', $locale); } unset($abstractNode); } } /* --- Indexing --- */ $indexingNode =& XMLCustomWriter::createElement($doc, 'indexing'); $isIndexingNecessary = false; if (is_array($article->getDiscipline(null))) { foreach ($article->getDiscipline(null) as $locale => $discipline) { $disciplineNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'discipline', $discipline, false); if ($disciplineNode) { XMLCustomWriter::setAttribute($disciplineNode, 'locale', $locale); $isIndexingNecessary = true; } unset($disciplineNode); } } if (is_array($article->getType(null))) { foreach ($article->getType(null) as $locale => $type) { $typeNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'type', $type, false); if ($typeNode) { XMLCustomWriter::setAttribute($typeNode, 'locale', $locale); $isIndexingNecessary = true; } unset($typeNode); } } if (is_array($article->getSubject(null))) { foreach ($article->getSubject(null) as $locale => $subject) { $subjectNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject', $subject, false); if ($subjectNode) { XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale); $isIndexingNecessary = true; } unset($subjectNode); } } if (is_array($article->getSubjectClass(null))) { foreach ($article->getSubjectClass(null) as $locale => $subjectClass) { $subjectClassNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject_class', $subjectClass, false); if ($subjectClassNode) { XMLCustomWriter::setAttribute($subjectClassNode, 'locale', $locale); $isIndexingNecessary = true; } unset($subjectClassNode); } } $coverageNode =& XMLCustomWriter::createElement($doc, 'coverage'); $isCoverageNecessary = false; if (is_array($article->getCoverageGeo(null))) { foreach ($article->getCoverageGeo(null) as $locale => $geographical) { $geographicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'geographical', $geographical, false); if ($geographicalNode) { XMLCustomWriter::setAttribute($geographicalNode, 'locale', $locale); $isCoverageNecessary = true; } unset($geographicalNode); } } if (is_array($article->getCoverageChron(null))) { foreach ($article->getCoverageChron(null) as $locale => $chronological) { $chronologicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'chronological', $chronological, false); if ($chronologicalNode) { XMLCustomWriter::setAttribute($chronologicalNode, 'locale', $locale); $isCoverageNecessary = true; } unset($chronologicalNode); } } if (is_array($article->getCoverageSample(null))) { foreach ($article->getCoverageSample(null) as $locale => $sample) { $sampleNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'sample', $sample, false); if ($sampleNode) { XMLCustomWriter::setAttribute($sampleNode, 'locale', $locale); $isCoverageNecessary = true; } unset($sampleNode); } } if ($isCoverageNecessary) { XMLCustomWriter::appendChild($indexingNode, $coverageNode); $isIndexingNecessary = true; } if ($isIndexingNecessary) { XMLCustomWriter::appendChild($root, $indexingNode); } /* --- */ /* --- Authors --- */ foreach ($article->getAuthors() as $author) { $authorNode =& NativeExportDom::generateAuthorDom($doc, $journal, $issue, $article, $author); XMLCustomWriter::appendChild($root, $authorNode); unset($authorNode); } /* --- */ if (is_array($article->getShowCoverPage(null))) { foreach (array_keys($article->getShowCoverPage(null)) as $locale) { if ($article->getShowCoverPage($locale)) { $coverNode =& XMLCustomWriter::createElement($doc, 'cover'); XMLCustomWriter::appendChild($root, $coverNode); XMLCustomWriter::setAttribute($coverNode, 'locale', $locale); XMLCustomWriter::createChildWithText($doc, $coverNode, 'altText', $issue->getCoverPageDescription($locale), false); $coverFile = $article->getFileName($locale); if ($coverFile != '') { $imageNode =& XMLCustomWriter::createElement($doc, 'image'); XMLCustomWriter::appendChild($coverNode, $imageNode); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getId()) . '/'; $coverPagePath .= $coverFile; $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath))); XMLCustomWriter::setAttribute($embedNode, 'filename', $article->getOriginalFileName($locale)); XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64'); XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath)); } unset($coverNode); } } } XMLCustomWriter::createChildWithText($doc, $root, 'pages', $article->getPages(), false); // NOTE that this is a required field for import, but it's // possible here to generate nonconforming XML via export b/c // of the potentially missing date_published node. This is due // to legacy data issues WRT an earlier lack of ability to // define article pub dates. Some legacy data will be missing // this date. XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($article->getDatePublished()), false); if ($article->getAccessStatus() == ARTICLE_ACCESS_OPEN) { $accessNode =& XMLCustomWriter::createElement($doc, 'open_access'); XMLCustomWriter::appendChild($root, $accessNode); } /* --- Permissions --- */ $permissionsNode =& XMLCustomWriter::createElement($doc, 'permissions'); XMLCustomWriter::appendChild($root, $permissionsNode); XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'license_url', $article->getLicenseURL(), false); foreach ($article->getCopyrightHolder(null) as $locale => $copyrightHolder) { $copyrightHolderNode =& XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'copyright_holder', $copyrightHolder, false); if ($copyrightHolderNode) { XMLCustomWriter::setAttribute($copyrightHolderNode, 'locale', $locale); } unset($copyrightHolderNode); } XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'copyright_year', $article->getCopyrightYear(), false); /* --- */ /* --- Galleys --- */ foreach ($article->getGalleys() as $galley) { $galleyNode =& NativeExportDom::generateGalleyDom($doc, $journal, $issue, $article, $galley); if ($galleyNode !== null) { XMLCustomWriter::appendChild($root, $galleyNode); } unset($galleyNode); } /* --- Supplementary Files --- */ foreach ($article->getSuppFiles() as $suppFile) { $suppNode =& NativeExportDom::generateSuppFileDom($doc, $journal, $issue, $article, $suppFile); if ($suppNode !== null) { XMLCustomWriter::appendChild($root, $suppNode); } unset($suppNode); } return $root; }
/** * Adds a file attachment to the email. * @param $filePath string complete path to the file to attach * @param $fileName string attachment file name (optional) * @param $contentType string attachment content type (optional) * @param $contentDisposition string attachment content disposition, inline or attachment (optional, default attachment) */ function addAttachment($filePath, $fileName = '', $contentType = '', $contentDisposition = 'attachment') { if (($attachments =& $this->getData('attachments')) == null) { $attachments = array(); } /* If the arguments $fileName and $contentType are not specified, then try and determine them automatically. */ if (empty($fileName)) { $fileName = basename($filePath); } if (empty($contentType)) { $contentType = String::mime_content_type($filePath); if (empty($contentType)) { $contentType = 'application/x-unknown-content-type'; } } array_push($attachments, array('path' => $filePath, 'filename' => $fileName, 'content-type' => $contentType)); return $this->setData('attachments', $attachments); }
/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $type string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $type = null, $inline = false) { if (is_readable($filePath)) { if ($type == null) { $type = String::mime_content_type($filePath); if (empty($type)) { $type = 'application/octet-stream'; } } header("Content-Type: {$type}"); header("Content-Length: " . filesize($filePath)); header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\""); header("Cache-Control: private"); // Workarounds for IE weirdness header("Pragma: public"); import('file.FileManager'); FileManager::readFile($filePath, true); return true; } else { return false; } }
function &generateIssueDom(&$doc, &$journal, &$issue) { $root =& XMLCustomWriter::createElement($doc, 'issue'); XMLCustomWriter::setAttribute($root, 'published', $issue->getPublished() ? 'true' : 'false'); XMLCustomWriter::setAttribute($root, 'current', $issue->getCurrent() ? 'true' : 'false'); XMLCustomWriter::setAttribute($root, 'public_id', $issue->getPublicIssueId(), false); if (is_array($issue->getTitle(null))) { foreach ($issue->getTitle(null) as $locale => $title) { $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false); if ($titleNode) { XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); } unset($titleNode); } } if (is_array($issue->getDescription(null))) { foreach ($issue->getDescription(null) as $locale => $description) { $descriptionNode =& XMLCustomWriter::createChildWithText($doc, $root, 'description', $description, false); if ($descriptionNode) { XMLCustomWriter::setAttribute($descriptionNode, 'locale', $locale); } unset($descriptionNode); } } XMLCustomWriter::createChildWithText($doc, $root, 'volume', $issue->getVolume(), false); XMLCustomWriter::createChildWithText($doc, $root, 'number', $issue->getNumber(), false); XMLCustomWriter::createChildWithText($doc, $root, 'year', $issue->getYear(), false); if (is_array($issue->getShowCoverPage(null))) { foreach (array_keys($issue->getShowCoverPage(null)) as $locale) { if ($issue->getShowCoverPage($locale)) { $coverNode =& XMLCustomWriter::createElement($doc, 'cover'); XMLCustomWriter::appendChild($root, $coverNode); XMLCustomWriter::setAttribute($coverNode, 'locale', $locale); XMLCustomWriter::createChildWithText($doc, $coverNode, 'caption', $issue->getCoverPageDescription($locale), false); $coverFile = $issue->getFileName($locale); if ($coverFile != '') { $imageNode =& XMLCustomWriter::createElement($doc, 'image'); XMLCustomWriter::appendChild($coverNode, $imageNode); import('file.PublicFileManager'); $publicFileManager =& new PublicFileManager(); $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/'; $coverPagePath .= $coverFile; $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath))); XMLCustomWriter::setAttribute($embedNode, 'filename', $issue->getOriginalFileName($locale)); XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64'); XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath)); } unset($coverNode); } } } XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($issue->getDatePublished()), false); if (XMLCustomWriter::createChildWithText($doc, $root, 'access_date', NativeExportDom::formatDate($issue->getDatePublished()), false) == null) { // This may be an open access issue. Check and flag // as necessary. if ($issue->getAccessStatus() == OPEN_ACCESS || !$journal->getSetting('enableSubscriptions') && $issue->getAccessStatus() == ISSUE_DEFAULT) { $accessNode =& XMLCustomWriter::createElement($doc, 'open_access'); XMLCustomWriter::appendChild($root, $accessNode); } } $sectionDao =& DAORegistry::getDAO('SectionDAO'); foreach ($sectionDao->getSectionsForIssue($issue->getIssueId()) as $section) { $sectionNode =& NativeExportDom::generateSectionDom($doc, $journal, $issue, $section); XMLCustomWriter::appendChild($root, $sectionNode); unset($sectionNode); } return $root; }
/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $type string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $type = null, $inline = false, $filename = null) { if (is_null($filename)) { $filename = basename($filePath); } $u_agent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/MSIE/i', $u_agent) && !preg_match('/Opera/i', $u_agent) || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) { $filename = iconv('utf8', 'big5', $filename); } //$filename = basename($filePath); $result = null; if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$type, &$inline, &$result))) { return $result; } if (is_readable($filePath)) { if ($type == null) { $type = String::mime_content_type($filePath); if (empty($type)) { $type = 'application/octet-stream'; } } Registry::clear(); // Free some memory header("Content-Type: {$type}"); header("Content-Length: " . filesize($filePath)); header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . $filename . "\""); header("Cache-Control: private"); // Workarounds for IE weirdness header("Pragma: public"); import('file.FileManager'); FileManager::readFile($filePath, true); return true; } else { return false; } }
function &generateArticleDom(&$doc, &$journal, &$issue, &$section, &$article) { $root =& XMLCustomWriter::createElement($doc, 'article'); if ($doi = $article->getDOI()) { $idNode =& XMLCustomWriter::createChildWithText($doc, $root, 'id', $doi); XMLCustomWriter::setAttribute($idNode, 'type', 'doi'); } /* --- Titles and Abstracts --- */ if (is_array($article->getTitle(null))) { foreach ($article->getTitle(null) as $locale => $title) { $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false); if ($titleNode) { XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); } unset($titleNode); } } if (is_array($article->getAbstract(null))) { foreach ($article->getAbstract(null) as $locale => $abstract) { $abstractNode =& XMLCustomWriter::createChildWithText($doc, $root, 'abstract', $abstract, false); if ($abstractNode) { XMLCustomWriter::setAttribute($abstractNode, 'locale', $locale); } unset($abstractNode); } } /* --- Indexing --- */ $indexingNode =& XMLCustomWriter::createElement($doc, 'indexing'); $isIndexingNecessary = false; if (is_array($article->getDiscipline(null))) { foreach ($article->getDiscipline(null) as $locale => $discipline) { $disciplineNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'discipline', $discipline, false); if ($disciplineNode) { XMLCustomWriter::setAttribute($disciplineNode, 'locale', $locale); $isIndexingNecessary = true; } unset($disciplineNode); } } if (is_array($article->getType(null))) { foreach ($article->getType(null) as $locale => $type) { $typeNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'type', $type, false); if ($typeNode) { XMLCustomWriter::setAttribute($typeNode, 'locale', $locale); $isIndexingNecessary = true; } unset($typeNode); } } if (is_array($article->getSubject(null))) { foreach ($article->getSubject(null) as $locale => $subject) { $subjectNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject', $subject, false); if ($subjectNode) { XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale); $isIndexingNecessary = true; } unset($subjectNode); } } if (is_array($article->getSubjectClass(null))) { foreach ($article->getSubjectClass(null) as $locale => $subjectClass) { $subjectClassNode =& XMLCustomWriter::createChildWithText($doc, $indexingNode, 'subject_class', $subjectClass, false); if ($subjectClassNode) { XMLCustomWriter::setAttribute($subjectClassNode, 'locale', $locale); $isIndexingNecessary = true; } unset($subjectClassNode); } } $coverageNode =& XMLCustomWriter::createElement($doc, 'coverage'); $isCoverageNecessary = false; if (is_array($article->getCoverageGeo(null))) { foreach ($article->getCoverageGeo(null) as $locale => $geographical) { $geographicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'geographical', $geographical, false); if ($geographicalNode) { XMLCustomWriter::setAttribute($geographicalNode, 'locale', $locale); $isCoverageNecessary = true; } unset($geographicalNode); } } if (is_array($article->getCoverageChron(null))) { foreach ($article->getCoverageChron(null) as $locale => $chronological) { $chronologicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'chronological', $chronological, false); if ($chronologicalNode) { XMLCustomWriter::setAttribute($chronologicalNode, 'locale', $locale); $isCoverageNecessary = true; } unset($chronologicalNode); } } if (is_array($article->getCoverageSample(null))) { foreach ($article->getCoverageSample(null) as $locale => $sample) { $sampleNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'sample', $sample, false); if ($sampleNode) { XMLCustomWriter::setAttribute($sampleNode, 'locale', $locale); $isCoverageNecessary = true; } unset($sampleNode); } } if ($isCoverageNecessary) { XMLCustomWriter::appendChild($indexingNode, $coverageNode); $isIndexingNecessary = true; } if ($isIndexingNecessary) { XMLCustomWriter::appendChild($root, $indexingNode); } /* --- */ /* --- Authors --- */ foreach ($article->getAuthors() as $author) { $authorNode =& NativeExportDom::generateAuthorDom($doc, $journal, $issue, $article, $author); XMLCustomWriter::appendChild($root, $authorNode); unset($authorNode); } /* --- */ if (is_array($article->getShowCoverPage(null))) { foreach (array_keys($article->getShowCoverPage(null)) as $locale) { if ($article->getShowCoverPage($locale)) { $coverNode =& XMLCustomWriter::createElement($doc, 'cover'); XMLCustomWriter::appendChild($root, $coverNode); XMLCustomWriter::setAttribute($coverNode, 'locale', $locale); XMLCustomWriter::createChildWithText($doc, $coverNode, 'altText', $issue->getCoverPageDescription($locale), false); $coverFile = $article->getFileName($locale); if ($coverFile != '') { $imageNode =& XMLCustomWriter::createElement($doc, 'image'); XMLCustomWriter::appendChild($coverNode, $imageNode); import('classes.file.PublicFileManager'); $publicFileManager = new PublicFileManager(); $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getId()) . '/'; $coverPagePath .= $coverFile; $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath))); XMLCustomWriter::setAttribute($embedNode, 'filename', $article->getOriginalFileName($locale)); XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64'); XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath)); } unset($coverNode); } } } XMLCustomWriter::createChildWithText($doc, $root, 'pages', $article->getPages(), false); XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($article->getDatePublished()), false); if ($article->getAccessStatus() == ARTICLE_ACCESS_OPEN) { $accessNode =& XMLCustomWriter::createElement($doc, 'open_access'); XMLCustomWriter::appendChild($root, $accessNode); } /* --- */ /* --- Galleys --- */ foreach ($article->getGalleys() as $galley) { $galleyNode =& NativeExportDom::generateGalleyDom($doc, $journal, $issue, $article, $galley); if ($galleyNode !== null) { XMLCustomWriter::appendChild($root, $galleyNode); } unset($galleyNode); } /* --- Supplementary Files --- */ foreach ($article->getSuppFiles() as $suppFile) { $suppNode =& NativeExportDom::generateSuppFileDom($doc, $journal, $issue, $article, $suppFile); if ($suppNode !== null) { XMLCustomWriter::appendChild($root, $suppNode); } unset($suppNode); } return $root; }
function uploadImg($clib, $chkT, $selR) { global $cfg; global $l; if (!$cfg['upload']) { return false; } foreach ($_FILES['nfile']['size'] as $key => $size) { if ($size > 0) { // get file extension and check for validity $ext = pathinfo($_FILES['nfile']['name'][$key]); $mimeType = String::mime_content_type($_FILES['nfile']['tmp_name'][0]); $ext = strtolower($ext['extension']); if (!in_array($ext, $cfg['valid'])) { // invalid image (only checks extension) echo $l->m('er_029'); return false; } if (!in_array($mimeType, $cfg['mimeTypes'])) { // invalid image (checks mime type) echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename // Check that the user doesn't exceed their upload limit: $newSize = dirsize($path) + $_FILES['nfile']['size'][$key]; if ($newSize > $cfg['ulLimit'] && $cfg['ulLimit'] != 0) { echo 'Warning: Upload limit exceeded'; return false; } // move file to temp directory for processing if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $path . '/' . $nfile)) { // upload image to temp dir echo $l->m('er_028'); return false; } $size = getimagesize($path . '/' . $nfile); // process (thumbnail) images $arr = $cfg['thumbs']; foreach ($arr as $key => $thumb) { if (in_array($key, $chkT)) { // create new phpThumb() object require_once dirname(__FILE__) . '/phpThumb/ThumbLib.inc.php'; $phpThumb = PhpThumbFactory::create($path . '/' . $nfile); // Create object //------------------------------------------------------------------------- if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes // resize parameters $phpThumb->resize($thumb['size'], $thumb['size']); // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . $thumb['size']; // e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . ($size[0] <= $size[1] ? $size[1] : $size[0]); // source height or width - e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } else { // default setting - images smaller than predefined sizes $dim = ''; // no file suffix is used } //------------------------------------------------------------------------- $nthumb = fixFileName(basename($nfile, '.' . $ext) . sanitize_filename($dim) . '.' . $ext); $nthumb = chkFileName($path, $nthumb); // rename if file already exists $phpThumb->save($path . $nthumb); @chmod($path . $nthumb, 0755) or die($l->m('er_028')); unset($phpThumb); } } @unlink($path . '/' . $nfile); // delete temporary file } } return $nthumb; }
function uploadImg($clib, $chkT, $selR) { global $cfg; global $l; if (!$cfg['upload']) { return false; } foreach ($_FILES['nfile']['size'] as $key => $size) { if ($size > 0) { // get file extension and check for validity $ext = pathinfo($_FILES['nfile']['name'][$key]); $mimeType = String::mime_content_type($_FILES['nfile']['tmp_name'][0]); $ext = strtolower($ext['extension']); if (!in_array($ext, $cfg['valid'])) { // invalid image (only checks extension) echo $l->m('er_029'); return false; } if (!in_array($mimeType, $cfg['mimeTypes'])) { // invalid image (checks mime type) echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename // Check that the user doesn't exceed their upload limit: $newSize = dirsize($path) + $_FILES['nfile']['size'][$key]; if ($newSize > $cfg['ulLimit'] && $cfg['ulLimit'] != 0) { echo 'Warning: Upload limit exceeded'; return false; } // move file to temp directory for processing if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $path . '/' . $nfile)) { // upload image to temp dir echo $l->m('er_028'); return false; } $size = getimagesize($path . '/' . $nfile); // process (thumbnail) images $arr = $cfg['thumbs']; foreach ($arr as $key => $thumb) { if (in_array($key, $chkT)) { // create new phpThumb() object require_once dirname(__FILE__) . '/phpThumb/phpthumb.class.php'; $phpThumb = new phpThumb(); // create object // parameters $phpThumb->config_cache_disable_warning = true; // disable cache warning $phpThumb->config_output_format = $ext; // output format $phpThumb->src = $path . '/' . $nfile; // destination $phpThumb->q = 95; // compression level for jpeg if ($selR != '') { // set auto rotate $phpThumb->ar = $selR; } //------------------------------------------------------------------------- if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes // resize parameters if ($size[0] < $size[1]) { // portrait $phpThumb->h = $thumb['size']; // max. height } else { $phpThumb->w = $thumb['size']; // max. width } // crop parameters if ($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop $phpThumb->w = $thumb['size']; // width $phpThumb->h = $thumb['size']; // height } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . $thumb['size']; // e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING // crop parameters if ($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop if ($size[0] < $size[1]) { // portrait $phpThumb->w = $size[0]; // getimagesize width value $phpThumb->h = $size[0]; // getimagesize width value } else { // landscape $phpThumb->w = $size[1]; // getimagesize height value $phpThumb->h = $size[1]; // getimagesize height value } } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . ($size[0] <= $size[1] ? $size[1] : $size[0]); // source height or width - e.g. _1280 } else { if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_' . $thumb['ext']; } } //------------------------------------------------------------------------- } else { // default setting - images smaller than predefined sizes $dim = ''; // no file suffix is used } //------------------------------------------------------------------------- $nthumb = fixFileName(basename($nfile, '.' . $ext) . $dim . '.' . $ext); $nthumb = chkFileName($path, $nthumb); // rename if file already exists if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($path . $nthumb); @chmod($path . $nthumb, 0755) or die($l->m('er_028')); } else { // error //echo $l->m('er_028'); return false; } unset($phpThumb); } } @unlink($path . '/' . $nfile); // delete temporary file } } return $nthumb; }
/** * Download a file. * Outputs HTTP headers and file content for download * @param $filePath string the location of the file to be sent * @param $type string the MIME type of the file, optional * @param $inline print file as inline instead of attachment, optional * @return boolean */ function downloadFile($filePath, $type = null, $inline = false, $label = null, $repo = false) { if ($repo == false) { if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$type, &$inline, &$result))) { return $result; } if (is_readable($filePath)) { if ($type == null) { $type = String::mime_content_type($filePath); if (empty($type)) { $type = 'application/octet-stream'; } } Registry::clear(); // Free some memory header("Content-Type: {$type}"); header("Content-Length: " . filesize($filePath)); header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\""); header("Cache-Control: private"); header("Pragma: public"); import('lib.pkp.classes.file.FileManager'); FileManager::readFile($filePath, true); return true; } else { return false; } } else { //return file from repository $ch = curl_init($filePath); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $c = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); if ($label == null) { $filename = str_replace("/content", "", $filePath); $filename = substr($filename, strrpos($filename, "/") + 1); } header("Etag: " . md5($filename)); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header("Content-Type:" . $info['content_type']); header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . $label . "\""); header("Cache-Control: private"); header("Pragma: public"); ob_clean(); flush(); readfile($filePath); } }