function _cacheMiss(&$cache, $id) { $allCodelistItems =& Registry::get('all' . $this->getListName() . 'CodelistItems', true, null); if ($allCodelistItems === null) { // Add a locale load to the debug notes. $notes =& Registry::get('system.debug.notes'); $locale = $cache->cacheId; if ($locale == null) { $locale = AppLocale::getLocale(); } $filename = $this->getFilename($locale); $notes[] = array('debug.notes.codelistItemListLoad', array('filename' => $filename)); // Reload locale registry file $xmlDao = new XMLDAO(); $listName =& $this->getListName(); // i.e., 'List30' import('lib.pkp.classes.codelist.ONIXParserDOMHandler'); $handler = new ONIXParserDOMHandler($listName); import('lib.pkp.classes.xslt.XSLTransformer'); import('lib.pkp.classes.file.FileManager'); import('classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $fileManager = new FileManager(); $tmpName = tempnam($temporaryFileManager->getBasePath(), 'ONX'); $xslTransformer = new XSLTransformer(); $xslTransformer->setParameters(array('listName' => $listName)); $xslTransformer->setRegisterPHPFunctions(true); $xslFile = 'lib/pkp/xml/onixFilter.xsl'; $filteredXml = $xslTransformer->transform($filename, XSL_TRANSFORMER_DOCTYPE_FILE, $xslFile, XSL_TRANSFORMER_DOCTYPE_FILE, XSL_TRANSFORMER_DOCTYPE_STRING); if (!$filteredXml) { assert(false); } $data = null; if (is_writeable($tmpName)) { $fp = fopen($tmpName, 'wb'); fwrite($fp, $filteredXml); fclose($fp); $data = $xmlDao->parseWithHandler($tmpName, $handler); $fileManager->deleteFile($tmpName); } else { fatalError('misconfigured directory permissions on: ' . $temporaryFileManager->getBasePath()); } // Build array with ($charKey => array(stuff)) if (isset($data[$listName])) { foreach ($data[$listName] as $code => $codelistData) { $allCodelistItems[$code] = $codelistData; } } if (is_array($allCodelistItems)) { asort($allCodelistItems); } $cache->setEntireCache($allCodelistItems); } return null; }
/** * Handle a child of the revision element * @param $node DOMElement * @param $submission Submission * @param $submissionFile SubmissionFile * @return string Filename for new file */ function handleRevisionChildElement($node, $submission, $submissionFile) { switch ($node->tagName) { case 'name': $submissionFile->setName($node->textContent, $node->getAttribute('locale')); break; case 'remote': $submissionFile->setFileType($node->getAttribute('mime_type')); $src = $node->getAttribute('src'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFilename = tempnam($temporaryFileManager->getBasePath(), 'remote'); $temporaryFileManager->copyFile($src, $temporaryFilename); return $temporaryFilename; break; case 'href': $submissionFile->setFileType($node->getAttribute('mime_type')); // Allow wrappers to handle URLs return $node->getAttribute('src'); break; case 'embed': $submissionFile->setFileType($node->getAttribute('mime_type')); if (($e = $node->getAttribute('encoding')) != 'base64') { fatalError('Unknown encoding "' . $e . '"!'); } $temporaryFileManager = new TemporaryFileManager(); $temporaryFilename = tempnam($temporaryFileManager->getBasePath(), 'embed'); file_put_contents($temporaryFilename, base64_decode($node->textContent)); return $temporaryFilename; break; } }
/** * Handle a child of the revision element * @param $node DOMElement * @param $submission Submission * @param $submissionFile SubmissionFile * @return string Filename for new file */ function handleRevisionChildElement($node, $submission, $submissionFile) { $deployment = $this->getDeployment(); $context = $deployment->getContext(); switch ($node->tagName) { case 'id': $this->parseIdentifier($node, $submissionFile); break; case 'name': $locale = $node->getAttribute('locale'); if (empty($locale)) { $locale = $context->getPrimaryLocale(); } $submissionFile->setName($node->textContent, $locale); break; case 'href': $submissionFile->setFileType($node->getAttribute('mime_type')); // Allow wrappers to handle URLs return $node->getAttribute('src'); break; case 'embed': $submissionFile->setFileType($node->getAttribute('mime_type')); if (($e = $node->getAttribute('encoding')) != 'base64') { fatalError('Unknown encoding "' . $e . '"!'); } $temporaryFileManager = new TemporaryFileManager(); $temporaryFilename = tempnam($temporaryFileManager->getBasePath(), 'embed'); file_put_contents($temporaryFilename, base64_decode($node->textContent)); return $temporaryFilename; break; } }
/** * Execute import/export tasks using the command-line interface. * @param $args Parameters to the plugin */ function executeCLI($scriptName, &$args) { AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON); $filename = array_shift($args); $username = array_shift($args); if (!$filename || !$username) { $this->usage($scriptName); exit; } if (!file_exists($filename)) { echo __('plugins.importexport.csv.fileDoesNotExist', array('filename' => $filename)) . "\n"; exit; } $data = file($filename); if (is_array($data) && count($data) > 0) { $userDao = DAORegistry::getDAO('UserDAO'); $user = $userDao->getByUsername($username); if (!$user) { echo __('plugins.importexport.csv.unknownUser', array('username' => $username)) . "\n"; exit; } $submissionDao = Application::getSubmissionDAO(); $authorDao = DAORegistry::getDAO('AuthorDAO'); $pressDao = Application::getContextDAO(); $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); $seriesDao = DAORegistry::getDAO('SeriesDAO'); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); import('lib.pkp.classes.submission.SubmissionFile'); // constants. $genreDao = DAORegistry::getDAO('GenreDAO'); $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO'); foreach ($data as $csvLine) { // Format is: // Press Path, Author string, title, series path, year, is_edited_volume, locale, URL to PDF, doi (optional) list($pressPath, $authorString, $title, $seriesPath, $year, $isEditedVolume, $locale, $pdfUrl, $doi) = preg_split('/\\t/', $csvLine); $press = $pressDao->getByPath($pressPath); if ($press) { $supportedLocales = $press->getSupportedSubmissionLocales(); if (!is_array($supportedLocales) || count($supportedLocales) < 1) { $supportedLocales = array($press->getPrimaryLocale()); } $authorGroup = $userGroupDao->getDefaultByRoleId($press->getId(), ROLE_ID_AUTHOR); // we need a Genre for the files. Assume a key of MANUSCRIPT as a default. $genre = $genreDao->getByKey('MANUSCRIPT', $press->getId()); if (!$genre) { echo __('plugins.importexport.csv.noGenre') . "\n"; exit; } if (!$authorGroup) { echo __('plugins.importexport.csv.noAuthorGroup', array('press' => $pressPath)) . "\n"; continue; } if (in_array($locale, $supportedLocales)) { $submission = $submissionDao->newDataObject(); $submission->setContextId($press->getId()); $submission->setUserId($user->getId()); $submission->stampStatusModified(); $submission->setStatus(STATUS_PUBLISHED); $submission->setWorkType($isEditedVolume == 1 ? WORK_TYPE_EDITED_VOLUME : WORK_TYPE_AUTHORED_WORK); $submission->setCopyrightNotice($press->getLocalizedSetting('copyrightNotice'), $locale); $submission->setLocale($locale); $series = $seriesDao->getByPath($seriesPath, $press->getId()); if ($series) { $submission->setSeriesId($series->getId()); } else { echo __('plugins.importexport.csv.noSeries', array('seriesPath' => $seriesPath)) . "\n"; } $submissionId = $submissionDao->insertObject($submission); $contactEmail = $press->getContactEmail(); $authorString = trim($authorString, '"'); // remove double quotes if present. $authors = preg_split('/,\\s*/', $authorString); $firstAuthor = true; foreach ($authors as $authorString) { // Examine the author string. Best case is: First1 Last1 <*****@*****.**>, First2 Last2 <*****@*****.**>, etc // But default to press email address based on press path if not present. $firstName = $lastName = $emailAddress = null; $authorString = trim($authorString); // whitespace. if (preg_match('/^(\\w+)(\\s+\\w+)?\\s*(<([^>]+)>)?$/', $authorString, $matches)) { $firstName = $matches[1]; // Mandatory if (count($matches) > 2) { $lastName = $matches[2]; } if (count($matches) == 5) { $emailAddress = $matches[4]; } else { $emailAddress = $contactEmail; } } $author = $authorDao->newDataObject(); $author->setSubmissionId($submissionId); $author->setUserGroupId($authorGroup->getId()); $author->setFirstName($firstName); $author->setLastName($lastName); $author->setEmail($emailAddress); if ($firstAuthor) { $author->setPrimaryContact(1); $firstAuthor = false; } $authorDao->insertObject($author); } // Authors done. $submission->setTitle($title, $locale); $submissionDao->updateObject($submission); // Submission is done. Create a publication format for it. $publicationFormat = $publicationFormatDao->newDataObject(); $publicationFormat->setPhysicalFormat(false); $publicationFormat->setIsApproved(true); $publicationFormat->setIsAvailable(true); $publicationFormat->setSubmissionId($submissionId); $publicationFormat->setProductAvailabilityCode('20'); // ONIX code for Available. $publicationFormat->setEntryKey('DA'); // ONIX code for Digital $publicationFormat->setData('name', 'PDF', $submission->getLocale()); $publicationFormat->setSequence(REALLY_BIG_NUMBER); $publicationFormatId = $publicationFormatDao->insertObject($publicationFormat); if ($doi) { $publicationFormat->setStoredPubId('doi', $doi); } $publicationFormatDao->updateObject($publicationFormat); // Create a publication format date for this publication format. $publicationDate = $publicationDateDao->newDataObject(); $publicationDate->setDateFormat('05'); // List55, YYYY $publicationDate->setRole('01'); // List163, Publication Date $publicationDate->setDate($year); $publicationDate->setPublicationFormatId($publicationFormatId); $publicationDateDao->insertObject($publicationDate); // Submission File. import('lib.pkp.classes.file.TemporaryFileManager'); import('lib.pkp.classes.file.FileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFilename = tempnam($temporaryFileManager->getBasePath(), 'remote'); $temporaryFileManager->copyFile($pdfUrl, $temporaryFilename); $submissionFile = $submissionFileDao->newDataObjectByGenreId($genre->getId()); $submissionFile->setSubmissionId($submissionId); $submissionFile->setGenreId($genre->getId()); $submissionFile->setFileStage(SUBMISSION_FILE_PROOF); $submissionFile->setDateUploaded(Core::getCurrentDate()); $submissionFile->setDateModified(Core::getCurrentDate()); $submissionFile->setAssocType(ASSOC_TYPE_REPRESENTATION); $submissionFile->setAssocId($publicationFormatId); $submissionFile->setFileType('application/pdf'); // Assume open access, no price. $submissionFile->setDirectSalesPrice(0); $submissionFile->setSalesType('openAccess'); $submissionFileDao->insertObject($submissionFile, $temporaryFilename); $fileManager = new FileManager(); $fileManager->deleteFile($temporaryFilename); echo __('plugins.importexport.csv.import.submission', array('title' => $title)) . "\n"; } else { echo __('plugins.importexport.csv.unknownLocale', array('locale' => $locale)) . "\n"; } } else { echo __('plugins.importexport.csv.unknownPress', array('pressPath' => $pressPath)) . "\n"; } } } }
/** * Return absolute path to the file on the host filesystem. * @return string */ function getFilePath() { import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); return $temporaryFileManager->getBasePath() . $this->getServerFileName(); }
/** * Handle a child of the revision element * @param $node DOMElement * @param $submission Submission * @param $submissionFile SubmissionFile * @return string Filename for new file */ function handleRevisionChildElement($node, $submission, $submissionFile) { $deployment = $this->getDeployment(); $context = $deployment->getContext(); $submission = $deployment->getSubmission(); switch ($node->tagName) { case 'id': $this->parseIdentifier($node, $submissionFile); break; case 'name': $locale = $node->getAttribute('locale'); if (empty($locale)) { $locale = $context->getPrimaryLocale(); } $submissionFile->setName($node->textContent, $locale); break; case 'href': $submissionFile->setFileType($node->getAttribute('mime_type')); // Allow wrappers to handle URLs return $node->getAttribute('src'); break; case 'embed': $submissionFile->setFileType($node->getAttribute('mime_type')); $temporaryFileManager = new TemporaryFileManager(); $temporaryFilename = tempnam($temporaryFileManager->getBasePath(), 'embed'); if (($e = $node->getAttribute('encoding')) != 'base64') { $deployment->addError(ASSOC_TYPE_SUBMISSION, $submission->getId(), __('plugins.importexport.common.error.unknownEncoding', array('param' => $e))); } else { file_put_contents($temporaryFilename, base64_decode($node->textContent)); } return $temporaryFilename; break; } }