/**
  * Display help.
  * @param $args array
  * @param $request PKPRequest
  */
 function index($args, $request)
 {
     require_once 'lib/pkp/lib/vendor/michelf/php-markdown/Michelf/Markdown.inc.php';
     $path = 'docs/manual/';
     $filename = join('/', $request->getRequestedArgs());
     // If a hash (anchor) was specified, discard it -- we don't need it here.
     if ($hashIndex = strpos($filename, '#')) {
         $hash = substr($filename, $hashIndex + 1);
         $filename = substr($filename, 0, $hashIndex);
     } else {
         $hash = null;
     }
     $language = AppLocale::getIso1FromLocale(AppLocale::getLocale());
     if (!file_exists($path . $language)) {
         $language = 'en';
     }
     // Default
     if (!$filename || !preg_match('#^([[a-zA-Z0-9_-]+/)+[a-zA-Z0-9_-]+\\.\\w+$#', $filename) || !file_exists($path . $filename)) {
         $request->redirect(null, null, null, array($language, 'SUMMARY.md'));
     }
     // Use the summary document to find next/previous links.
     // (Yes, we're grepping markdown outside the parser, but this is much faster.)
     $previousLink = $nextLink = null;
     if (preg_match_all('/\\(([^)]+\\.md)\\)/sm', file_get_contents($path . $language . '/SUMMARY.md'), $matches)) {
         $matches = $matches[1];
         if (($i = array_search(substr($filename, strpos($filename, '/') + 1), $matches)) !== false) {
             if ($i > 0) {
                 $previousLink = $matches[$i - 1];
             }
             if ($i < count($matches) - 1) {
                 $nextLink = $matches[$i + 1];
             }
         }
     }
     // Use a URL filter to prepend the current path to relative URLs.
     $parser = new \Michelf\Markdown();
     $parser->url_filter_func = function ($url) use($filename) {
         return dirname($filename) . '/' . $url;
     };
     return new JSONMessage(true, array('content' => $parser->transform(file_get_contents($path . $filename)), 'previous' => $previousLink, 'next' => $nextLink));
 }
 /**
  * Identify published article, issue and language of the given galley.
  * @param $galley ArticleGalley
  * @param $journal Journal
  * @return array|null An array with article, issue and language of
  *  the given galley. Null will be returned if one of these objects
  *  cannot be identified for the galley (e.g. when the galley belongs
  *  to an unpublished article).
  */
 function &_prepareGalleyData(&$galley, &$journal)
 {
     // Retrieve article and issue for the galley.
     $galleyData =& $this->prepareArticleFileData($galley, $journal);
     if (!is_array($galleyData)) {
         $nullVar = null;
         return $nullVar;
     }
     // Add the galley language.
     $languageDao = DAORegistry::getDAO('LanguageDAO');
     /* @var $languageDao LanguageDAO */
     $galleyData['language'] = $languageDao->getLanguageByCode(AppLocale::getIso1FromLocale($galley->getLocale()));
     // Add the galley itself.
     $galleyData['galley'] =& $galley;
     return $galleyData;
 }
 /**
  * @see DOIExportDom::generate()
  */
 function &generate(&$object)
 {
     $falseVar = false;
     // Declare variables that will contain publication objects.
     $journal =& $this->getJournal();
     $issue = null;
     /* @var $issue Issue */
     $article = null;
     /* @var $article PublishedArticle */
     $galley = null;
     /* @var $galley ArticleGalley */
     $suppFile = null;
     /* @var $suppFile SuppFile */
     $articlesByIssue = null;
     $galleysByArticle = null;
     $suppFilesByArticle = null;
     // Retrieve required publication objects (depends on the object to be exported).
     $pubObjects =& $this->retrievePublicationObjects($object);
     extract($pubObjects);
     // Identify an object implementing an ArticleFile (if any).
     $articleFile = empty($suppFile) ? $galley : $suppFile;
     // Identify the object locale.
     $objectLocalePrecedence = $this->getObjectLocalePrecedence($article, $galley, $suppFile);
     // The publisher is required.
     $publisher = is_a($object, 'SuppFile') ? $object->getSuppFilePublisher() : null;
     if (empty($publisher)) {
         $publisher = $this->getPublisher($objectLocalePrecedence);
     }
     // The publication date is required.
     $publicationDate = is_a($article, 'PublishedArticle') ? $article->getDatePublished() : null;
     if (empty($publicationDate)) {
         $publicationDate = $issue->getDatePublished();
     }
     assert(!empty($publicationDate));
     // Create the XML document and its root element.
     $doc =& $this->getDoc();
     $rootElement =& $this->rootElement();
     XMLCustomWriter::appendChild($doc, $rootElement);
     // DOI (mandatory)
     if (($identifierElement =& $this->_identifierElement($object)) === false) {
         return false;
     }
     XMLCustomWriter::appendChild($rootElement, $identifierElement);
     // Creators (mandatory)
     XMLCustomWriter::appendChild($rootElement, $this->_creatorsElement($object, $objectLocalePrecedence, $publisher));
     // Title (mandatory)
     XMLCustomWriter::appendChild($rootElement, $this->_titlesElement($object, $objectLocalePrecedence));
     // Publisher (mandatory)
     XMLCustomWriter::createChildWithText($this->getDoc(), $rootElement, 'publisher', $publisher);
     // Publication Year (mandatory)
     XMLCustomWriter::createChildWithText($this->getDoc(), $rootElement, 'publicationYear', date('Y', strtotime($publicationDate)));
     // Subjects
     if (!empty($suppFile)) {
         $this->_appendNonMandatoryChild($rootElement, $this->_subjectsElement($suppFile, $objectLocalePrecedence));
     } elseif (!empty($article)) {
         $this->_appendNonMandatoryChild($rootElement, $this->_subjectsElement($article, $objectLocalePrecedence));
     }
     // Dates
     XMLCustomWriter::appendChild($rootElement, $this->_datesElement($issue, $article, $articleFile, $suppFile, $publicationDate));
     // Language
     XMLCustomWriter::createChildWithText($this->getDoc(), $rootElement, 'language', AppLocale::getIso1FromLocale($objectLocalePrecedence[0]));
     // Resource Type
     if (!is_a($object, 'SuppFile')) {
         $resourceTypeElement =& $this->_resourceTypeElement($object);
         XMLCustomWriter::appendChild($rootElement, $resourceTypeElement);
     }
     // Alternate Identifiers
     $this->_appendNonMandatoryChild($rootElement, $this->_alternateIdentifiersElement($object, $issue, $article, $articleFile));
     // Related Identifiers
     $this->_appendNonMandatoryChild($rootElement, $this->_relatedIdentifiersElement($object, $articlesByIssue, $galleysByArticle, $suppFilesByArticle, $issue, $article));
     // Sizes
     $sizesElement =& $this->_sizesElement($object, $article);
     if ($sizesElement) {
         XMLCustomWriter::appendChild($rootElement, $sizesElement);
     }
     // Formats
     if (!empty($articleFile)) {
         XMLCustomWriter::appendChild($rootElement, $this->_formatsElement($articleFile));
     }
     // Rights
     $rightsURL = $article ? $article->getLicenseURL() : $journal->getSetting('licenseURL');
     $rightsListElement =& XMLCustomWriter::createElement($this->getDoc(), 'rightsList');
     $rightsElement = $this->createElementWithText('rights', strip_tags(Application::getCCLicenseBadge($rightsURL)), array('rightsURI' => $rightsURL));
     XMLCustomWriter::appendChild($rightsListElement, $rightsElement);
     XMLCustomWriter::appendChild($rootElement, $rightsListElement);
     // Descriptions
     $descriptionsElement =& $this->_descriptionsElement($issue, $article, $suppFile, $objectLocalePrecedence, $articlesByIssue);
     if ($descriptionsElement) {
         XMLCustomWriter::appendChild($rootElement, $descriptionsElement);
     }
     return $doc;
 }
Beispiel #4
0
 /**
  * @see Filter::process()
  * @param $pubObject Issue|PublishedArticle|ArticleGalley
  * @return DOMDocument
  */
 function &process(&$pubObject)
 {
     // Create the XML document
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->preserveWhiteSpace = false;
     $doc->formatOutput = true;
     $deployment = $this->getDeployment();
     $context = $deployment->getContext();
     $plugin = $deployment->getPlugin();
     $cache = $plugin->getCache();
     // Get all objects
     $issue = $article = $galley = $galleyFile = null;
     if (is_a($pubObject, 'Issue')) {
         $issue = $pubObject;
         if (!$cache->isCached('issues', $issue->getId())) {
             $cache->add($issue, null);
         }
     } elseif (is_a($pubObject, 'PublishedArticle')) {
         $article = $pubObject;
         if (!$cache->isCached('articles', $article->getId())) {
             $cache->add($article, null);
         }
     } elseif (is_a($pubObject, 'ArticleGalley')) {
         $galley = $pubObject;
         $galleyFile = $galley->getFile();
         $articleId = $galley->getSubmissionId();
         if ($cache->isCached('articles', $articleId)) {
             $article = $cache->get('articles', $articleId);
         } else {
             $articleDao = DAORegistry::getDAO('PublishedArticleDAO');
             /* @var $articleDao PublishedArticleDAO */
             $article = $articleDao->getPublishedArticleByArticleId($pubObject->getSubmissionId(), $context->getId());
             if ($article) {
                 $cache->add($article, null);
             }
         }
     }
     if (!$issue) {
         $issueId = $article->getIssueId();
         if ($cache->isCached('issues', $issueId)) {
             $issue = $cache->get('issues', $issueId);
         } else {
             $issueDao = DAORegistry::getDAO('IssueDAO');
             /* @var $issueDao IssueDAO */
             $issue = $issueDao->getById($issueId, $context->getId());
             if ($issue) {
                 $cache->add($issue, null);
             }
         }
     }
     // The publisher is required.
     // Use the journal title as DataCite recommends for now.
     $publisher = $this->getPrimaryTranslation($context->getName(null), $objectLocalePrecedence);
     assert(!empty($publisher));
     // The publication date is required.
     $publicationDate = isset($article) ? $article->getDatePublished() : null;
     if (empty($publicationDate)) {
         $publicationDate = $issue->getDatePublished();
     }
     assert(!empty($publicationDate));
     // Create the root node
     $rootNode = $this->createRootNode($doc);
     $doc->appendChild($rootNode);
     // Identify the object locale.
     $objectLocalePrecedence = $this->getObjectLocalePrecedence($context, $article, $galley);
     // DOI (mandatory)
     $doi = $pubObject->getStoredPubId('doi');
     if ($plugin->isTestMode($context)) {
         $doi = PKPString::regexp_replace('#^[^/]+/#', DATACITE_API_TESTPREFIX . '/', $doi);
     }
     $rootNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'identifier', htmlspecialchars($doi, ENT_COMPAT, 'UTF-8')));
     $node->setAttribute('identifierType', DATACITE_IDTYPE_DOI);
     // Creators (mandatory)
     $rootNode->appendChild($this->createCreatorsNode($doc, $issue, $article, $galley, $galleyFile, $publisher, $objectLocalePrecedence));
     // Title (mandatory)
     $rootNode->appendChild($this->createTitlesNode($doc, $issue, $article, $galley, $galleyFile, $objectLocalePrecedence));
     // Publisher (mandatory)
     $rootNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'publisher', htmlspecialchars($publisher, ENT_COMPAT, 'UTF-8')));
     // Publication Year (mandatory)
     $rootNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'publicationYear', date('Y', strtotime($publicationDate))));
     // Subjects
     $subject = null;
     if (!empty($galleyFile) && is_a($galleyFile, 'SupplementaryFile')) {
         $subject = $this->getPrimaryTranslation($galleyFile->getSubject(null), $objectLocalePrecedence);
     } elseif (!empty($article)) {
         $subject = $this->getPrimaryTranslation($article->getSubject(null), $objectLocalePrecedence);
     }
     if (!empty($subject)) {
         $subjectsNode = $doc->createElementNS($deployment->getNamespace(), 'subjects');
         $subjectsNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'subject', htmlspecialchars($subject, ENT_COMPAT, 'UTF-8')));
         $rootNode->appendChild($subjectsNode);
     }
     // Dates
     $rootNode->appendChild($this->createDatesNode($doc, $issue, $article, $galley, $galleyFile, $publicationDate));
     // Language
     $rootNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'language', AppLocale::getIso1FromLocale($objectLocalePrecedence[0])));
     // Resource Type
     $resourceTypeNode = $this->createResourceTypeNode($doc, $issue, $article, $galley, $galleyFile);
     if ($resourceTypeNode) {
         $rootNode->appendChild($resourceTypeNode);
     }
     // Alternate Identifiers
     $rootNode->appendChild($this->createAlternateIdentifiersNode($doc, $issue, $article, $galley));
     // Related Identifiers
     $relatedIdentifiersNode = $this->createRelatedIdentifiersNode($doc, $issue, $article, $galley);
     if ($relatedIdentifiersNode) {
         $rootNode->appendChild($relatedIdentifiersNode);
     }
     // Sizes
     $sizesNode = $this->createSizesNode($doc, $issue, $article, $galley, $galleyFile);
     if ($sizesNode) {
         $rootNode->appendChild($sizesNode);
     }
     // Formats
     if (!empty($galleyFile)) {
         $format = $galleyFile->getFileType();
         if (!empty($format)) {
             $formatsNode = $doc->createElementNS($deployment->getNamespace(), 'formats');
             $formatsNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'format', htmlspecialchars($format, ENT_COMPAT, 'UTF-8')));
             $rootNode->appendChild($formatsNode);
         }
     }
     // Rights
     $rightsURL = $article ? $article->getLicenseURL() : $context->getSetting('licenseURL');
     if (!empty($rightsURL)) {
         $rightsNode = $doc->createElementNS($deployment->getNamespace(), 'rightsList');
         $rightsNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'rights', htmlspecialchars(strip_tags(Application::getCCLicenseBadge($rightsURL)), ENT_COMPAT, 'UTF-8')));
         $node->setAttribute('rightsURI', $rightsURL);
         $rootNode->appendChild($rightsNode);
     }
     // Descriptions
     $descriptionsNode = $this->createDescriptionsNode($doc, $issue, $article, $galley, $galleyFile, $objectLocalePrecedence);
     if ($descriptionsNode) {
         $rootNode->appendChild($descriptionsNode);
     }
     return $doc;
 }