/** * Upload a new cover image file. * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function uploadCoverImage($args, $request) { $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); return $json; } else { return new JSONMessage(false, __('common.uploadFailed')); } }
function display(&$args, $request) { parent::display($args, $request); $templateMgr =& TemplateManager::getManager(); $journal =& $request->getJournal(); switch (array_shift($args)) { case 'export': @set_time_limit(0); $errors = array(); $success = $this->handleExport($journal, $errors); if ($success === false) { return $errors; } break; case 'import': AppLocale::requireComponents(LOCALE_COMPONENT_OJS_EDITOR, LOCALE_COMPONENT_OJS_AUTHOR); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); if ($existingFileId = $request->getUserVar('temporaryFileId')) { // The user has just entered more context. Fetch an existing file. $temporaryFile = $temporaryFileManager->getFile($existingFileId, $user->getId()); } else { $user = Request::getUser(); $temporaryFile = $temporaryFileManager->handleUpload('importFile', $user->getId()); } if (!$temporaryFile) { $templateMgr->assign('error', 'plugins.importexport.fullJournal.error.uploadFailed'); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } @set_time_limit(0); $errors = array(); if ($this->handleImport($temporaryFile->getFilePath(), $errors)) { return $templateMgr->display($this->getTemplatePath() . 'importSuccess.tpl'); } else { $templateMgr->assign_by_ref('errors', $errors); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } break; default: $this->setBreadcrumbs(); $templateMgr->display($this->getTemplatePath() . 'index.tpl'); } }
/** * Handles attachments in a generalized manner in situations where * an email message must span several requests. Called from the * constructor when attachments are enabled. */ function _handleAttachments($userId) { import('file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $this->attachmentsEnabled = true; $this->persistAttachments = array(); $deleteAttachment = Request::getUserVar('deleteAttachment'); if (Request::getUserVar('persistAttachments') != null) { foreach (Request::getUserVar('persistAttachments') as $fileId) { $temporaryFile = $temporaryFileManager->getFile($fileId, $userId); if (!empty($temporaryFile)) { if ($deleteAttachment != $temporaryFile->getId()) { $this->persistAttachments[] = $temporaryFile; } else { // This file is being deleted. $temporaryFileManager->deleteFile($temporaryFile->getId(), $userId); } } } } if (Request::getUserVar('addAttachment') && $temporaryFileManager->uploadedFileExists('newAttachment')) { $user =& Request::getUser(); $this->persistAttachments[] = $temporaryFileManager->handleUpload('newAttachment', $user->getId()); } }
function display(&$args, $request) { $templateMgr =& TemplateManager::getManager(); parent::display($args, $request); $issueDao =& DAORegistry::getDAO('IssueDAO'); $journal =& $request->getJournal(); switch (array_shift($args)) { case 'exportIssues': $issueIds = $request->getUserVar('issueId'); if (!isset($issueIds)) { $issueIds = array(); } $issues = array(); foreach ($issueIds as $issueId) { $issue =& $issueDao->getIssueById($issueId, $journal->getId()); if (!$issue) { $request->redirect(); } $issues[] =& $issue; unset($issue); } $this->exportIssues($journal, $issues); break; case 'exportIssue': $issueId = array_shift($args); $issue =& $issueDao->getIssueById($issueId, $journal->getId()); if (!$issue) { $request->redirect(); } $this->exportIssue($journal, $issue); break; case 'exportArticle': $articleIds = array(array_shift($args)); $result = array_shift(ArticleSearch::formatResults($articleIds)); $this->exportArticle($journal, $result['issue'], $result['section'], $result['publishedArticle']); break; case 'exportArticles': $articleIds = $request->getUserVar('articleId'); if (!isset($articleIds)) { $articleIds = array(); } $results =& ArticleSearch::formatResults($articleIds); $this->exportArticles($results); break; case 'issues': // Display a list of issues for export $this->setBreadcrumbs(array(), true); AppLocale::requireComponents(LOCALE_COMPONENT_OJS_EDITOR); $issueDao =& DAORegistry::getDAO('IssueDAO'); $issues =& $issueDao->getIssues($journal->getId(), Handler::getRangeInfo('issues')); $templateMgr->assign_by_ref('issues', $issues); $templateMgr->display($this->getTemplatePath() . 'issues.tpl'); break; case 'articles': // Display a list of articles for export $this->setBreadcrumbs(array(), true); $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $rangeInfo = Handler::getRangeInfo('articles'); $articleIds = $publishedArticleDao->getPublishedArticleIdsAlphabetizedByJournal($journal->getId(), false); $totalArticles = count($articleIds); if ($rangeInfo->isValid()) { $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount()); } import('lib.pkp.classes.core.VirtualArrayIterator'); $iterator = new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount()); $templateMgr->assign_by_ref('articles', $iterator); $templateMgr->display($this->getTemplatePath() . 'articles.tpl'); break; case 'import': AppLocale::requireComponents(LOCALE_COMPONENT_OJS_EDITOR, LOCALE_COMPONENT_OJS_AUTHOR); import('classes.file.TemporaryFileManager'); $issueDao =& DAORegistry::getDAO('IssueDAO'); $sectionDao =& DAORegistry::getDAO('SectionDAO'); $user =& $request->getUser(); $temporaryFileManager = new TemporaryFileManager(); if ($existingFileId = $request->getUserVar('temporaryFileId')) { // The user has just entered more context. Fetch an existing file. $temporaryFile = $temporaryFileManager->getFile($existingFileId, $user->getId()); } else { $temporaryFile = $temporaryFileManager->handleUpload('importFile', $user->getId()); } $context = array('journal' => $journal, 'user' => $user); if ($sectionId = $request->getUserVar('sectionId')) { $context['section'] = $sectionDao->getSection($sectionId); } if ($issueId = $request->getUserVar('issueId')) { $context['issue'] = $issueDao->getIssueById($issueId, $journal->getId()); } if (!$temporaryFile) { $templateMgr->assign('error', 'plugins.importexport.native.error.uploadFailed'); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } $doc =& $this->getDocument($temporaryFile->getFilePath()); if (substr($this->getRootNodeName($doc), 0, 7) === 'article') { // Ensure the user has supplied enough valid information to // import articles within an appropriate context. If not, // prompt them for the. if (!isset($context['issue']) || !isset($context['section'])) { $issues =& $issueDao->getIssues($journal->getId(), Handler::getRangeInfo('issues')); $templateMgr->assign_by_ref('issues', $issues); $templateMgr->assign('sectionOptions', array('0' => __('author.submit.selectSection')) + $sectionDao->getSectionTitles($journal->getId(), false)); $templateMgr->assign('temporaryFileId', $temporaryFile->getId()); return $templateMgr->display($this->getTemplatePath() . 'articleContext.tpl'); } } @set_time_limit(0); if ($this->handleImport($context, $doc, $errors, $issues, $articles, false)) { $templateMgr->assign_by_ref('issues', $issues); $templateMgr->assign_by_ref('articles', $articles); return $templateMgr->display($this->getTemplatePath() . 'importSuccess.tpl'); } else { $templateMgr->assign_by_ref('errors', $errors); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } break; default: $this->setBreadcrumbs(); $templateMgr->display($this->getTemplatePath() . 'index.tpl'); } }
/** * Upload a new library file. * @param $args array * @param $request PKPRequest * @return string */ function uploadFile($args, &$request) { $router =& $request->getRouter(); $context = $request->getContext(); $user =& $request->getUser(); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSON(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSON(false, Locale::translate('common.uploadFailed')); } return $json->getString(); }
function display(&$args) { $templateMgr =& TemplateManager::getManager(); $request =& $this->getRequest(); parent::display($args); $conference =& $request->getConference(); $schedConf =& $request->getSchedConf(); switch (array_shift($args)) { case 'exportPaper': $paperIds = array(array_shift($args)); $result = array_shift(PaperSearch::formatResults($paperIds)); $this->exportPaper($schedConf, $result['track'], $result['publishedPaper']); break; case 'exportPapers': $paperIds = $request->getUserVar('paperId'); if (!isset($paperIds)) { $paperIds = array(); } $results =& PaperSearch::formatResults($paperIds); $this->exportPapers($results); break; case 'papers': // Display a list of papers for export $this->setBreadcrumbs(array(), true); $publishedPaperDao = DAORegistry::getDAO('PublishedPaperDAO'); $rangeInfo = Handler::getRangeInfo($request, 'papers'); $paperIds = $publishedPaperDao->getPublishedPaperIdsAlphabetizedBySchedConf($conference->getId(), $schedConf->getId()); $totalPapers = count($paperIds); if ($rangeInfo->isValid()) { $paperIds = array_slice($paperIds, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount()); } import('lib.pkp.classes.core.VirtualArrayIterator'); $iterator = new VirtualArrayIterator(PaperSearch::formatResults($paperIds), $totalPapers, $rangeInfo->getPage(), $rangeInfo->getCount()); $templateMgr->assign_by_ref('papers', $iterator); $templateMgr->display($this->getTemplatePath() . 'papers.tpl'); break; case 'import': import('classes.file.TemporaryFileManager'); $trackDao = DAORegistry::getDAO('TrackDAO'); $user =& $request->getUser(); $temporaryFileManager = new TemporaryFileManager(); if ($existingFileId = $request->getUserVar('temporaryFileId')) { // The user has just entered more context. Fetch an existing file. $temporaryFile = $temporaryFileManager->getFile($existingFileId, $user->getId()); } else { $temporaryFile = $temporaryFileManager->handleUpload('importFile', $user->getId()); } $context = array('conference' => $conference, 'schedConf' => $schedConf, 'user' => $user); if ($trackId = $request->getUserVar('trackId')) { $context['track'] = $trackDao->getTrack($trackId); } if (!$temporaryFile) { $templateMgr->assign('error', 'plugins.importexport.native.error.uploadFailed'); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } $doc =& $this->getDocument($temporaryFile->getFilePath()); if (substr($this->getRootNodeName($doc), 0, 5) === 'paper') { // Ensure the user has supplied enough valid information to // import papers within an appropriate context. If not, // prompt them for the. if (!isset($context['track'])) { AppLocale::requireComponents(LOCALE_COMPONENT_APP_AUTHOR); $templateMgr->assign('trackOptions', array('0' => __('author.submit.selectTrack')) + $trackDao->getTrackTitles($schedConf->getId(), false)); $templateMgr->assign('temporaryFileId', $temporaryFile->getId()); return $templateMgr->display($this->getTemplatePath() . 'paperContext.tpl'); } } @set_time_limit(0); if ($this->handleImport($context, $doc, $errors, $papers, false)) { $templateMgr->assign_by_ref('papers', $papers); return $templateMgr->display($this->getTemplatePath() . 'importSuccess.tpl'); } else { $templateMgr->assign_by_ref('errors', $errors); return $templateMgr->display($this->getTemplatePath() . 'importError.tpl'); } break; default: $this->setBreadcrumbs(); $templateMgr->display($this->getTemplatePath() . 'index.tpl'); } }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $context = $request->getContext(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.importexport.users.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); $users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user); $templateMgr->assign('users', $users); $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser()); header('Content-type: application/xml'); echo $exportXml; break; case 'exportAllUsers': $exportXml = $this->exportAllUsers($request->getContext(), $request->getUser()); header('Content-type: application/xml'); echo $exportXml; break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * @see ImportExportPlugin::display() */ function display(&$args, $request) { $templateMgr = TemplateManager::getManager($request); parent::display($args, $request); $issueDao = DAORegistry::getDAO('IssueDAO'); $journal = $request->getJournal(); switch (array_shift($args)) { case 'exportIssues': $issueIds = $request->getUserVar('issueId'); if (!isset($issueIds)) { $issueIds = array(); } $issues = array(); foreach ($issueIds as $issueId) { $issue = $issueDao->getById($issueId, $journal->getId()); if (!$issue) { $request->redirect(); } $issues[] = $issue; } $this->exportPubIdsForIssues($journal, $issues); break; case 'exportIssue': $issueId = array_shift($args); $issue = $issueDao->getById($issueId, $journal->getId()); if (!$issue) { $request->redirect(); } $issues = array($issue); $this->exportPubIdsForIssues($journal, $issues); break; case 'selectIssue': // Display a list of issues for export AppLocale::requireComponents(array(LOCALE_COMPONENT_APP_EDITOR)); $issueDao = DAORegistry::getDAO('IssueDAO'); $issues = $issueDao->getIssues($journal->getId(), Handler::getRangeInfo($this->getRequest(), 'issues')); $templateMgr->assign('issues', $issues); $templateMgr->display($this->getTemplatePath() . 'selectIssue.tpl'); break; case 'import': import('lib.pkp.classes.file.TemporaryFileManager'); $user = $request->getUser(); $temporaryFileManager = new TemporaryFileManager(); if ($existingFileId = $request->getUserVar('temporaryFileId')) { // The user has just entered more context. Fetch an existing file. $temporaryFile = $temporaryFileManager->getFile($existingFileId, $user->getId()); } else { $temporaryFile = $temporaryFileManager->handleUpload('importFile', $user->getId()); } if (!$temporaryFile) { $templateMgr->assign('error', 'plugins.importexport.pubIds.import.error.uploadFailed'); return $templateMgr->display($this->getTemplatePath() . 'importResults.tpl'); } $context = array('journal' => $journal); $doc =& $this->getDocument($temporaryFile->getFilePath()); @set_time_limit(0); $this->handleImport($context, $doc, $errors, $pubIds, false); $templateMgr->assign('errors', $errors); $templateMgr->assign('pubIds', $pubIds); return $templateMgr->display($this->getTemplatePath() . 'importResults.tpl'); break; default: $templateMgr->display($this->getTemplatePath() . 'importExportIndex.tpl'); } }
/** * Batch import from an ONIX XML export. * @param array $args * @param PKPRequest $request */ function uploadONIXObjectForReview($args, &$request) { $user = $request->getUser(); $journal =& $request->getJournal(); $ofrOrgDao =& DAORegistry::getDAO('ObjectForReviewOrganizationDAO'); $ofrPlugin =& $this->_getObjectsForReviewPlugin(); $ofrPlugin->import('classes.form.ObjectForReviewForm'); $reviewObjectTypeId = (int) $request->getUserVar('reviewObjectTypeId'); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('onixFile', $user->getId()); $filePath = $temporaryFile->getFilePath(); $parser = new XMLParser(); $doc =& $parser->parse($filePath); $multiple = $request->getUserVar('multiple'); if ($doc) { // Determine if we have short or long tags. $productNodes = $doc->getChildByName('product'); $shortTags = $productNodes ? true : false; for ($index = 0; $productNode = $doc->getChildByName($this->_getOnixTag('Product', $shortTags), $index); $index++) { $importData = array(); if ($productNode) { $publisherNode = $productNode->getChildByName($this->_getOnixTag('Publisher', $shortTags)); if ($publisherNode) { $publisherNameNode = $publisherNode->getChildByName($this->_getOnixTag('PublisherName', $shortTags)); if ($publisherNameNode) { $publisher = $publisherNameNode->getValue(); $organization =& $ofrOrgDao->getOrganizationByName(trim($publisher)); if ($organization) { $importData['publisherId'] = $organization->getId(); } } } $websiteNode = $publisherNode->getChildByName($this->_getOnixTag('Website', $shortTags)); if ($websiteNode) { $websiteLinkNode = $websiteNode->getChildByName($this->_getOnixTag('WebsiteLink', $shortTags)); $websiteLink = $websiteLinkNode->getValue(); $importData['book_publisher_url'] = $websiteLink; } $titleNode = $productNode->getChildByName($this->_getOnixTag('Title', $shortTags)); if ($titleNode) { $titleTextNode = $titleNode->getChildByName($this->_getOnixTag('TitleText', $shortTags)); $title = $titleTextNode->getValue(); $importData['title'] = $title; } $subTitleNode = $titleNode->getChildByName($this->_getOnixTag('Subtitle', $shortTags)); if ($subTitleNode) { $subTitle = $subTitleNode->getValue(); $importData['shortTitle'] = $subTitle; } $seriesNode = $productNode->getChildByName($this->_getOnixTag('Series', $shortTags)); if ($seriesNode) { $seriesTextNode = $seriesNode->getChildByName($this->_getOnixTag('TitleOfSeries', $shortTags)); $series = $seriesTextNode->getValue(); $importData['book_series'] = $series; } $languageNode = $productNode->getChildByName($this->_getOnixTag('Language', $shortTags)); if ($languageNode) { $languageCodeNode = $languageNode->getChildByName($this->_getOnixTag('LanguageCode', $shortTags)); $language = $languageCodeNode->getValue(); $importData['language'] = substr($language, 0, 2); } else { $importData['language'] = 'en'; } $pageNode = $productNode->getChildByName($this->_getOnixTag('NumberOfPages', $shortTags)); if ($pageNode) { $pages = $pageNode->getValue(); $importData['book_pages_no'] = $pages; } // Abstract. Look for OtherText with // sub element of TextTypeCode of '01' (main description) $abstract = ''; for ($authorIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('OtherText', $shortTags), $authorIndex); $authorIndex++) { $typeNode = $node->getChildByName($this->_getOnixTag('TextTypeCode', $shortTags)); if ($typeNode && $typeNode->getValue() == '01') { $textNode = $node->getChildByName($this->_getOnixTag('Text', $shortTags)); if ($textNode) { $abstract = strip_tags($textNode->getValue()); } break; } } $importData['abstract'] = $abstract; // ISBN-13 for ($productIdentifierIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('ProductIdentifier', $shortTags), $productIdentifierIndex); $productIdentifierIndex++) { $idTypeNode = $node->getChildByName($this->_getOnixTag('ProductIDType', $shortTags)); if ($idTypeNode && $idTypeNode->getValue() == '15') { // ISBN-13 $textNode = $node->getChildByName($this->_getOnixTag('IDValue', $shortTags)); if ($textNode) { $importData['book_isbn'] = $textNode->getValue(); } break; } } // Subjects $importData['subjectKeywords'] = ''; $subjects = array(); for ($subjectIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('Subject', $shortTags), $subjectIndex); $subjectIndex++) { $textNode = $node->getChildByName($this->_getOnixTag('SubjectHeadingText', $shortTags)); if ($textNode) { $subjects[] = $textNode->getValue(); } } $importData['subjectKeywords'] = join(', ', $subjects); $publicationDateNode = $productNode->getChildByName($this->_getOnixTag('PublicationDate', $shortTags)); if ($publicationDateNode) { $publicationDate = $publicationDateNode->getValue(); $importData['date'] = $publicationDate; } // Contributors. $persons = array(); for ($authorIndex = 0; $node = $productNode->getChildByName($this->_getOnixTag('Contributor', $shortTags), $authorIndex); $authorIndex++) { $firstNameNode = $node->getChildByName($this->_getOnixTag('NamesBeforeKey', $shortTags)); if ($firstNameNode) { $firstName = $firstNameNode->getValue(); } $lastNameNode = $node->getChildByName($this->_getOnixTag('KeyNames', $shortTags)); if ($lastNameNode) { $lastName = $lastNameNode->getValue(); } $seqNode = $node->getChildByName($this->_getOnixTag('SequenceNumber', $shortTags)); if ($seqNode) { $seq = $seqNode->getValue(); } $contributorRoleNode = $node->getChildByName($this->_getOnixTag('ContributorRole', $shortTags)); $contributorRole = ''; if ($contributorRoleNode) { switch ($contributorRoleNode->getValue()) { case 'A01': $contributorRole = '1'; break; case 'B01': $contributorRole = '3'; break; case 'B09': $contributorRole = '4'; break; case 'B06': $contributorRole = '5'; break; default: $contributorRole = '2'; // Contributor break; } } $persons[] = array('personId' => '', 'role' => $contributorRole, 'firstName' => $firstName, 'middleName' => '', 'lastName' => $lastName, 'seq' => (int) $seq); unset($node); } $importData['persons'] = $persons; if (!$multiple) { $temporaryFileManager->deleteFile($temporaryFile->getId(), $user->getId()); $this->editObjectForReview($args, &$request, $importData); break; } else { // we are processing more than one Product. Instaniate the form and let it // handle the object creation. $ofrForm = new ObjectForReviewForm($ofrPlugin->getName(), null, $reviewObjectTypeId, $importData); $ofrForm->initData(); $ofrForm->execute(); } } else { $request->redirect(null, 'editor', 'objectsForReview', 'onixError'); } } $request->redirect(null, 'editor', 'objectsForReview'); } else { // this deleteFile is only called if the document does not parse. $temporaryFileManager->deleteFile($temporaryFile->getId(), $user->getId()); $request->redirect(null, 'editor', 'objectsForReview'); } }
/** * Upload a plugin file. * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function uploadPluginFile($args, $request) { import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $user = $request->getUser(); // Return the temporary file id. if ($temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId())) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); return $json; } else { return new JSONMessage(false, __('manager.plugins.uploadError')); } }
/** * Decompress uploaded plugin and install in the correct plugin directory. * $param function string type of operation to perform after upload ('upgrade' or 'install') */ function uploadPlugin($function) { $templateMgr =& TemplateManager::getManager(); $this->setupTemplate(true); $templateMgr->assign('error', false); $templateMgr->assign('uploaded', false); $templateMgr->assign('path', $function); $templateMgr->assign('pageHierarchy', PluginManagementHandler::setBreadcrumbs(true)); if (Request::getUserVar('uploadPlugin')) { import('file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $user =& Request::getUser(); if ($temporaryFile = $temporaryFileManager->handleUpload('newPlugin', $user->getId())) { // tar archive basename must equal plugin directory name, and plugin files must be in root directory $pluginName = basename($temporaryFile->getOriginalFileName(), '.tar.gz'); $pluginDir = dirname($temporaryFile->getFilePath()); exec('tar -xzf ' . escapeshellarg($temporaryFile->getFilePath()) . ' -C ' . escapeshellarg($pluginDir)); if ($function == 'install') { PluginManagementHandler::installPlugin($pluginDir . DIRECTORY_SEPARATOR . $pluginName, $templateMgr); } else { if ($function == 'upgrade') { PluginManagementHandler::upgradePlugin($pluginDir . DIRECTORY_SEPARATOR . $pluginName, $templateMgr); } } } else { $templateMgr->assign('error', true); $templateMgr->assign('message', 'manager.plugins.uploadError'); } } else { if (Request::getUserVar('installPlugin')) { if (Request::getUserVar('pluginUploadLocation') == '') { $templateMgr->assign('error', true); $templateMgr->assign('message', 'manager.plugins.fileSelectError'); } } } $templateMgr->display('manager/plugins/managePlugins.tpl'); }
/** * Upload the supplementary file. * @param $fileName string * @return int TemporaryFile ID */ function uploadSupplementaryFile($fileName) { import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $user =& Request::getUser(); $temporaryFile = $temporaryFileManager->handleUpload($fileName, $user->getId()); if ($temporaryFile) { return $temporaryFile->getId(); } else { return false; } }
/** * Upload a temporary file. * @param $request Request */ function uploadFile($request) { $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { return $temporaryFile->getId(); } return false; }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $context = $request->getContext(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.users.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.importexport.users.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); libxml_use_internal_errors(true); $users = $this->importUsers(file_get_contents($temporaryFilePath), $context, $user); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); $templateMgr->assign('users', $users); $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportUsers((array) $request->getUserVar('selectedUsers'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; case 'exportAllUsers': $exportXml = $this->exportAllUsers($request->getContext(), $request->getUser()); import('lib.pkp.classes.file.TemporaryFileManager'); $fileManager = new TemporaryFileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'users', $context, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }
/** * Decompress uploaded plugin and install in the correct plugin directory. * @param $function string type of operation to perform after upload ('upgrade' or 'install') * @param $category string the category of the uploaded plugin (upgrade only) * @param $plugin string the name of the uploaded plugin (upgrade only) */ function uploadPlugin($function, $category = null, $plugin = null) { $this->validate(); $templateMgr =& TemplateManager::getManager(); $this->setupTemplate(true); $templateMgr->assign('error', false); $templateMgr->assign('uploaded', false); $templateMgr->assign('path', $function); $errorMsg = ''; if (Request::getUserVar('uploadPlugin')) { import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $user =& Request::getUser(); } else { $errorMsg = 'manager.plugins.fileSelectError'; } if (empty($errorMsg)) { if ($temporaryFile = $temporaryFileManager->handleUpload('newPlugin', $user->getId())) { // tar archive basename (less potential version number) must equal plugin directory name // and plugin files must be in a directory named after the plug-in. $matches = array(); String::regexp_match_get('/^[a-zA-Z0-9]+/', basename($temporaryFile->getOriginalFileName(), '.tar.gz'), $matches); $pluginName = array_pop($matches); // Create random dirname to avoid symlink attacks. $pluginDir = dirname($temporaryFile->getFilePath()) . DIRECTORY_SEPARATOR . $pluginName . substr(md5(mt_rand()), 0, 10); mkdir($pluginDir); } else { $errorMsg = 'manager.plugins.uploadError'; } } if (empty($errorMsg)) { // Test whether the tar binary is available for the export to work $tarBinary = Config::getVar('cli', 'tar'); if (!empty($tarBinary) && file_exists($tarBinary)) { exec($tarBinary . ' -xzf ' . escapeshellarg($temporaryFile->getFilePath()) . ' -C ' . escapeshellarg($pluginDir)); } else { $errorMsg = 'manager.plugins.tarCommandNotFound'; } } if (empty($errorMsg)) { // We should now find a directory named after the // plug-in within the extracted archive. $pluginDir .= DIRECTORY_SEPARATOR . $pluginName; if (is_dir($pluginDir)) { if ($function == 'install') { $this->installPlugin($pluginDir, $templateMgr); } else { if ($function == 'upgrade') { $this->upgradePlugin($pluginDir, $templateMgr, $category, $plugin); } } } else { $errorMsg = 'manager.plugins.invalidPluginArchive'; } } if (!empty($errorMsg)) { $templateMgr->assign('error', true); $templateMgr->assign('message', $errorMsg); } $templateMgr->display('manager/plugins/managePlugins.tpl'); }
/** * Upload the submission file. * @param $fileName string * @return int TemporaryFile ID */ function uploadSubmissionFile($fileName) { import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $request = $this->request; $user = $request->getUser(); $temporaryFile = $temporaryFileManager->handleUpload($fileName, $user->getId()); if ($temporaryFile) { return $temporaryFile->getId(); } else { return false; } }
/** * Display the plugin. * @param $args array * @param $request PKPRequest */ function display($args, $request) { $templateMgr = TemplateManager::getManager($request); $press = $request->getPress(); parent::display($args, $request); $templateMgr->assign('plugin', $this); switch (array_shift($args)) { case 'index': case '': $templateMgr->display($this->getTemplatePath() . 'index.tpl'); break; case 'uploadImportXML': $user = $request->getUser(); import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFile = $temporaryFileManager->handleUpload('uploadedFile', $user->getId()); if ($temporaryFile) { $json = new JSONMessage(true); $json->setAdditionalAttributes(array('temporaryFileId' => $temporaryFile->getId())); } else { $json = new JSONMessage(false, __('common.uploadFailed')); } return $json->getString(); case 'importBounce': $json = new JSONMessage(true); $json->setEvent('addTab', array('title' => __('plugins.importexport.native.results'), 'url' => $request->url(null, null, null, array('plugin', $this->getName(), 'import'), array('temporaryFileId' => $request->getUserVar('temporaryFileId'))))); return $json->getString(); case 'import': AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION); $temporaryFileId = $request->getUserVar('temporaryFileId'); $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $user = $request->getUser(); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $user->getId()); if (!$temporaryFile) { $json = new JSONMessage(true, __('plugins.inportexport.native.uploadFile')); return $json->getString(); } $temporaryFilePath = $temporaryFile->getFilePath(); $deployment = new NativeImportExportDeployment($press, $user); libxml_use_internal_errors(true); $submissions = $this->importSubmissions(file_get_contents($temporaryFilePath), $deployment); $templateMgr->assign('submissions', $submissions); $validationErrors = array_filter(libxml_get_errors(), create_function('$a', 'return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;')); $templateMgr->assign('validationErrors', $validationErrors); libxml_clear_errors(); // Are there any submissions import errors $processedSubmissionsIds = $deployment->getProcessedObjectsIds(ASSOC_TYPE_SUBMISSION); if (!empty($processedSubmissionsIds)) { $submissionsErrors = array_filter($processedSubmissionsIds, create_function('$a', 'return !empty($a);')); if (!empty($submissionsErrors)) { $templateMgr->assign('submissionsErrors', $processedSubmissionsIds); } } // If there are any submissions or validataion errors // delete imported submissions. if (!empty($submissionsErrors) || !empty($validationErrors)) { // remove all imported sumissions $deployment->removeImportedObjects(ASSOC_TYPE_SUBMISSION); } // Display the results $json = new JSONMessage(true, $templateMgr->fetch($this->getTemplatePath() . 'results.tpl')); return $json->getString(); case 'export': $exportXml = $this->exportSubmissions((array) $request->getUserVar('selectedSubmissions'), $request->getContext(), $request->getUser()); import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); $exportFileName = $this->getExportFileName($this->getExportPath(), 'monographs', $press, '.xml'); $fileManager->writeFile($exportFileName, $exportXml); $fileManager->downloadFile($exportFileName); $fileManager->deleteFile($exportFileName); break; default: $dispatcher = $request->getDispatcher(); $dispatcher->handle404(); } }