Exemplo n.º 1
0
 /**
  * Generate a filename for a library file.
  * @param $type int LIBRARY_FILE_TYPE_...
  * @param $originalFileName string
  * @return string
  */
 function generateFileName($type, $originalFileName)
 {
     $libraryFileDao =& DAORegistry::getDAO('LibraryFileDAO');
     $suffix = $this->getFileSuffixFromType($type);
     $ext = $this->getExtension($originalFileName);
     $truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($suffix) - 1);
     $baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
     // Try a simple syntax first
     $fileName = $baseName . '-' . $suffix . '.' . $ext;
     if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
         return $fileName;
     }
     for ($i = 1;; $i++) {
         $fullSuffix = $suffix . '-' . $i;
         //truncate more if necessary
         $truncated = $this->truncateFileName($originalFileName, 127 - String::strlen($fullSuffix) - 1);
         // get the base name and append the suffix
         $baseName = String::substr($truncated, 0, String::strpos($originalFileName, $ext) - 1);
         //try the following
         $fileName = $baseName . '-' . $fullSuffix . '.' . $ext;
         if (!$libraryFileDao->filenameExists($this->pressId, $fileName)) {
             return $fileName;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Get a set of GalleryPlugin objects describing the available
  * compatible plugins in their newest versions.
  * @param $application PKPApplication
  * @param $category string Optional category name to use as filter
  * @param $search string Optional text to use as filter
  * @return array GalleryPlugin objects
  */
 function getNewestCompatible($application, $category = null, $search = null)
 {
     $doc = $this->_getDocument();
     $plugins = array();
     foreach ($doc->getElementsByTagName('plugin') as $element) {
         $plugin = $this->_compatibleFromElement($element, $application);
         // May be null if no compatible version exists; also
         // apply search filters if any supplied.
         if ($plugin && ($category == '' || $plugin->getCategory() == $category) && ($search == '' || String::strpos(String::strtolower(serialize($plugin)), String::strtolower($search)) !== false)) {
             $plugins[] = $plugin;
         }
     }
     return $plugins;
 }
 /**
  * Helper function: Recursive function called by _removeTags
  * @author Matt Crider
  * @param string
  * @param int
  * @param array
  * @param int
  * @return string
  */
 function _removeTagsAux($string, $loc, &$tags, $length)
 {
     if (strlen($string) > 0 && $length > 0) {
         $length--;
         if (String::substr($string, 0, 1) == '<') {
             $closeBrack = String::strpos($string, '>') + 1;
             if ($closeBrack) {
                 $tags[] = array(String::substr($string, 0, $closeBrack), $loc);
                 return $this->_removeTagsAux(String::substr($string, $closeBrack), $loc + $closeBrack, $tags, $length);
             }
         }
         return String::substr($string, 0, 1) . $this->_removeTagsAux(String::substr($string, 1), $loc + 1, $tags, $length);
     }
 }
Exemplo n.º 4
0
 /**
  * Helper function: Recursive function called by _removeTags
  * @author Matt Crider
  * @param string
  * @param int
  * @param array
  * @param int
  * @return string
  */
 function _removeTagsAux($string, $loc, &$tags, $length)
 {
     $newString = '';
     for ($i = 0; $i < strlen($string); $i++) {
         if (String::substr($string, $i, 1) == '<') {
             // We've found the beginning of an HTML tag, find the position of its ending
             $closeBrack = String::strpos($string, '>', $i);
             if ($closeBrack) {
                 // Add the tag and its position to the tags array reference
                 $tags[] = array(String::substr($string, $i, $closeBrack - $i + 1), $i);
                 $i += $closeBrack - $i;
                 continue;
             }
         }
         $length--;
         $newString = $newString . String::substr($string, $i, 1);
     }
     return $newString;
 }
 /**
  * Fills the given citation object with
  * meta-data retrieved from PubMed.
  * @param $pmid string
  * @param $citationDescription MetadataDescription
  * @return MetadataDescription
  */
 function &_lookup($pmid, &$citationDescription)
 {
     $nullVar = null;
     // Use eFetch to get XML metadata for the given PMID
     $lookupParams = array('db' => 'pubmed', 'mode' => 'xml', 'tool' => 'pkp-wal', 'id' => $pmid);
     if (!is_null($this->getEmail())) {
         $lookupParams['email'] = $this->getEmail();
     }
     // Call the eFetch URL and get an XML result
     if (is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_EFETCH, $lookupParams))) {
         return $nullVar;
     }
     $metadata = array('pub-id[@pub-id-type="pmid"]' => $pmid, 'article-title' => $resultDOM->getElementsByTagName("ArticleTitle")->item(0)->textContent, 'source' => $resultDOM->getElementsByTagName("MedlineTA")->item(0)->textContent);
     if ($resultDOM->getElementsByTagName("Volume")->length > 0) {
         $metadata['volume'] = $resultDOM->getElementsByTagName("Volume")->item(0)->textContent;
     }
     if ($resultDOM->getElementsByTagName("Issue")->length > 0) {
         $metadata['issue'] = $resultDOM->getElementsByTagName("Issue")->item(0)->textContent;
     }
     // get list of author full names
     $nlmNameSchema = new NlmNameSchema();
     foreach ($resultDOM->getElementsByTagName("Author") as $authorNode) {
         if (!isset($metadata['person-group[@person-group-type="author"]'])) {
             $metadata['person-group[@person-group-type="author"]'] = array();
         }
         // Instantiate an NLM name description
         $authorDescription = new MetadataDescription($nlmNameSchema, ASSOC_TYPE_AUTHOR);
         // Surname
         $authorDescription->addStatement('surname', $authorNode->getElementsByTagName("LastName")->item(0)->textContent);
         // Given names
         $givenNamesString = '';
         if ($authorNode->getElementsByTagName("FirstName")->length > 0) {
             $givenNamesString = $authorNode->getElementsByTagName("FirstName")->item(0)->textContent;
         } elseif ($authorNode->getElementsByTagName("ForeName")->length > 0) {
             $givenNamesString = $authorNode->getElementsByTagName("ForeName")->item(0)->textContent;
         }
         if (!empty($givenNamesString)) {
             foreach (explode(' ', $givenNamesString) as $givenName) {
                 $authorDescription->addStatement('given-names', String::trimPunctuation($givenName));
             }
         }
         // Suffix
         if ($authorNode->getElementsByTagName("Suffix")->length > 0) {
             $authorDescription->addStatement('suffix', $authorNode->getElementsByTagName("Suffix")->item(0)->textContent);
         }
         // Include collective names
         /*if ($resultDOM->getElementsByTagName("CollectiveName")->length > 0 && $authorNode->getElementsByTagName("CollectiveName")->item(0)->textContent != '') {
         			// FIXME: This corresponds to an NLM-citation <collab> tag and should be part of the Metadata implementation
         		}*/
         $metadata['person-group[@person-group-type="author"]'][] =& $authorDescription;
         unset($authorDescription);
     }
     // Extract pagination
     if (String::regexp_match_get("/^[:p\\.\\s]*(?P<fpage>[Ee]?\\d+)(-(?P<lpage>\\d+))?/", $resultDOM->getElementsByTagName("MedlinePgn")->item(0)->textContent, $pages)) {
         $fPage = (int) $pages['fpage'];
         $metadata['fpage'] = $fPage;
         if (!empty($pages['lpage'])) {
             $lPage = (int) $pages['lpage'];
             // Deal with shortcuts like '382-7'
             if ($lPage < $fPage) {
                 $lPage = (int) (String::substr($pages['fpage'], 0, -String::strlen($pages['lpage'])) . $pages['lpage']);
             }
             $metadata['lpage'] = $lPage;
         }
     }
     // Get publication date
     // TODO: The publication date could be in multiple places
     if ($resultDOM->getElementsByTagName("ArticleDate")->length > 0) {
         $publicationDate = $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Year")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Month")->item(0)->textContent . '-' . $resultDOM->getElementsByTagName("ArticleDate")->item(0)->getElementsByTagName("Day")->item(0)->textContent;
         $metadata['date'] = $publicationDate;
     }
     // Get publication type
     if ($resultDOM->getElementsByTagName("PublicationType")->length > 0) {
         foreach ($resultDOM->getElementsByTagName("PublicationType") as $publicationType) {
             // The vast majority of items on PubMed are articles so catch these...
             if (String::strpos(String::strtolower($publicationType->textContent), 'article') !== false) {
                 $metadata['[@publication-type]'] = NLM_PUBLICATION_TYPE_JOURNAL;
                 break;
             }
         }
     }
     // Get DOI if it exists
     foreach ($resultDOM->getElementsByTagName("ArticleId") as $idNode) {
         if ($idNode->getAttribute('IdType') == 'doi') {
             $metadata['pub-id[@pub-id-type="doi"]'] = $idNode->textContent;
         }
     }
     // Use eLink utility to find fulltext links
     $lookupParams = array('dbfrom' => 'pubmed', 'cmd' => 'llinks', 'tool' => 'pkp-wal', 'id' => $pmid);
     if (!is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_ELINK, $lookupParams))) {
         // Get a list of possible links
         foreach ($resultDOM->getElementsByTagName("ObjUrl") as $linkOut) {
             $attributes = '';
             foreach ($linkOut->getElementsByTagName("Attribute") as $attribute) {
                 $attributes .= String::strtolower($attribute->textContent) . ' / ';
             }
             // Only add links to open access resources
             if (String::strpos($attributes, "subscription") === false && String::strpos($attributes, "membership") === false && String::strpos($attributes, "fee") === false && $attributes != "") {
                 $links[] = $linkOut->getElementsByTagName("Url")->item(0)->textContent;
             }
         }
         // Take the first link if we have any left (presumably pubmed returns them in preferential order)
         if (isset($links[0])) {
             $metadata['uri'] = $links[0];
         }
     }
     return $this->addMetadataArrayToNlmCitationDescription($metadata, $citationDescription);
 }
 /**
  * Fills the given citation object with
  * meta-data retrieved from PubMed.
  * @param $pmid string
  * @return MetadataDescription
  */
 function &_lookup($pmid)
 {
     $nullVar = null;
     // Use eFetch to get XML metadata for the given PMID
     $lookupParams = array('db' => 'pubmed', 'mode' => 'xml', 'tool' => 'pkp-wal', 'id' => $pmid);
     if (!is_null($this->getEmail())) {
         $lookupParams['email'] = $this->getEmail();
     }
     // Call the eFetch URL and get an XML result
     if (is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_EFETCH, $lookupParams))) {
         return $nullVar;
     }
     $articleTitleNodes =& $resultDOM->getElementsByTagName("ArticleTitle");
     $articleTitleFirstNode =& $articleTitleNodes->item(0);
     $medlineTaNodes =& $resultDOM->getElementsByTagName("MedlineTA");
     $medlineTaFirstNode =& $medlineTaNodes->item(0);
     $metadata = array('pub-id[@pub-id-type="pmid"]' => $pmid, 'article-title' => $articleTitleFirstNode->textContent, 'source' => $medlineTaFirstNode->textContent);
     $volumeNodes =& $resultDOM->getElementsByTagName("Volume");
     $issueNodes =& $resultDOM->getElementsByTagName("Issue");
     if ($volumeNodes->length > 0) {
         $volumeFirstNode =& $volumeNodes->item(0);
     }
     $metadata['volume'] = $volumeFirstNode->textContent;
     if ($issueNodes->length > 0) {
         $issueFirstNode =& $issueNodes->item(0);
     }
     $metadata['issue'] = $issueFirstNode->textContent;
     // Get list of author full names
     foreach ($resultDOM->getElementsByTagName("Author") as $authorNode) {
         if (!isset($metadata['person-group[@person-group-type="author"]'])) {
             $metadata['person-group[@person-group-type="author"]'] = array();
         }
         // Instantiate an NLM name description
         $authorDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30NameSchema', ASSOC_TYPE_AUTHOR);
         // Surname
         $lastNameNodes =& $authorNode->getElementsByTagName("LastName");
         $lastNameFirstNode =& $lastNameNodes->item(0);
         $authorDescription->addStatement('surname', $lastNameFirstNode->textContent);
         // Given names
         $givenNamesString = '';
         $firstNameNodes =& $authorNode->getElementsByTagName("FirstName");
         if ($firstNameNodes->length > 0) {
             $firstNameFirstNode =& $firstNameNodes->item(0);
             $givenNamesString = $firstNameFirstNode->textContent;
         } else {
             $foreNameNodes =& $authorNode->getElementsByTagName("ForeName");
             if ($foreNameNodes->length > 0) {
                 $foreNameFirstNode =& $foreNameNodes->item(0);
                 $givenNamesString = $foreNameFirstNode->textContent;
             }
         }
         if (!empty($givenNamesString)) {
             foreach (explode(' ', $givenNamesString) as $givenName) {
                 $authorDescription->addStatement('given-names', String::trimPunctuation($givenName));
             }
         }
         // Suffix
         $suffixNodes =& $authorNode->getElementsByTagName("Suffix");
         if ($suffixNodes->length > 0) {
             $suffixFirstNode =& $suffixNodes->item(0);
             $authorDescription->addStatement('suffix', $suffixFirstNode->textContent);
         }
         // Include collective names
         // FIXME: This corresponds to an NLM-citation <collab> tag and should be part of the Metadata implementation
         /*if ($resultDOM->getElementsByTagName("CollectiveName")->length > 0 && $authorNode->getElementsByTagName("CollectiveName")->item(0)->textContent != '') {
         		}*/
         $metadata['person-group[@person-group-type="author"]'][] =& $authorDescription;
         unset($authorDescription);
     }
     // Extract pagination
     $medlinePgnNodes =& $resultDOM->getElementsByTagName("MedlinePgn");
     $medlinePgnFirstNode =& $medlinePgnNodes->item(0);
     if (String::regexp_match_get("/^[:p\\.\\s]*(?P<fpage>[Ee]?\\d+)(-(?P<lpage>\\d+))?/", $medlinePgnFirstNode->textContent, $pages)) {
         $fPage = (int) $pages['fpage'];
         $metadata['fpage'] = $fPage;
         if (!empty($pages['lpage'])) {
             $lPage = (int) $pages['lpage'];
             // Deal with shortcuts like '382-7'
             if ($lPage < $fPage) {
                 $lPage = (int) (String::substr($pages['fpage'], 0, -String::strlen($pages['lpage'])) . $pages['lpage']);
             }
             $metadata['lpage'] = $lPage;
         }
     }
     // Get publication date (can be in several places in PubMed).
     $dateNode = null;
     $articleDateNodes =& $resultDOM->getElementsByTagName("ArticleDate");
     if ($articleDateNodes->length > 0) {
         $dateNode =& $articleDateNodes->item(0);
     } else {
         $pubDateNodes =& $resultDOM->getElementsByTagName("PubDate");
         if ($pubDateNodes->length > 0) {
             $dateNode =& $pubDateNodes->item(0);
         }
     }
     // Retrieve the data parts and assemble date.
     if (!is_null($dateNode)) {
         $publicationDate = '';
         $requiresNormalization = false;
         foreach (array('Year' => 4, 'Month' => 2, 'Day' => 2) as $dateElement => $padding) {
             $dateElementNodes =& $dateNode->getElementsByTagName($dateElement);
             if ($dateElementNodes->length > 0) {
                 if (!empty($publicationDate)) {
                     $publicationDate .= '-';
                 }
                 $dateElementFirstNode =& $dateElementNodes->item(0);
                 $datePart = str_pad($dateElementFirstNode->textContent, $padding, '0', STR_PAD_LEFT);
                 if (!is_numeric($datePart)) {
                     $requiresNormalization = true;
                 }
                 $publicationDate .= $datePart;
             } else {
                 break;
             }
         }
         // Normalize the date to NLM standard if necessary.
         if ($requiresNormalization) {
             $dateFilter = new DateStringNormalizerFilter();
             $publicationDate = $dateFilter->execute($publicationDate);
         }
         if (!empty($publicationDate)) {
             $metadata['date'] = $publicationDate;
         }
     }
     // Get publication type
     $publicationTypeNodes =& $resultDOM->getElementsByTagName("PublicationType");
     if ($publicationTypeNodes->length > 0) {
         foreach ($publicationTypeNodes as $publicationType) {
             // The vast majority of items on PubMed are articles so catch these...
             if (String::strpos(String::strtolower($publicationType->textContent), 'article') !== false) {
                 $metadata['[@publication-type]'] = NLM30_PUBLICATION_TYPE_JOURNAL;
                 break;
             }
         }
     }
     // Get DOI if it exists
     $articleIdNodes =& $resultDOM->getElementsByTagName("ArticleId");
     foreach ($articleIdNodes as $idNode) {
         if ($idNode->getAttribute('IdType') == 'doi') {
             $metadata['pub-id[@pub-id-type="doi"]'] = $idNode->textContent;
         }
     }
     // Use eLink utility to find fulltext links
     $lookupParams = array('dbfrom' => 'pubmed', 'cmd' => 'llinks', 'tool' => 'pkp-wal', 'id' => $pmid);
     if (!is_null($resultDOM = $this->callWebService(PUBMED_WEBSERVICE_ELINK, $lookupParams))) {
         // Get a list of possible links
         foreach ($resultDOM->getElementsByTagName("ObjUrl") as $linkOut) {
             $attributes = '';
             foreach ($linkOut->getElementsByTagName("Attribute") as $attribute) {
                 $attributes .= String::strtolower($attribute->textContent) . ' / ';
             }
             // Only add links to open access resources
             if (String::strpos($attributes, "subscription") === false && String::strpos($attributes, "membership") === false && String::strpos($attributes, "fee") === false && $attributes != "") {
                 $urlNodes =& $linkOut->getElementsByTagName("Url");
                 $urlFirstNode =& $urlNodes->item(0);
                 $links[] = $urlFirstNode->textContent;
             }
         }
         // Take the first link if we have any left (presumably pubmed returns them in preferential order)
         if (isset($links[0])) {
             $metadata['uri'] = $links[0];
         }
     }
     return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
 }
Exemplo n.º 7
0
 /**
  * @see PubIdPlugin::getResolvingURL()
  */
 function getResolvingURL($journalId, $pubId)
 {
     // See ANSI/NISO Z39.84-2005, Appendix E. (Bug #8190)
     $separatorIndex = String::strpos($pubId, '/');
     assert($separatorIndex !== false);
     // Should contain a slash
     $prefix = String::substr($pubId, 0, $separatorIndex);
     $suffix = String::substr($pubId, $separatorIndex + 1);
     return 'http://dx.doi.org/' . $prefix . '/' . urlencode($suffix);
 }
Exemplo n.º 8
0
 function testOffsetStringPosition()
 {
     $string = 'abcdabcdabcd';
     $find = 'a';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = '¡¢£¤¡¢£¤¡¢£¤';
     $find = '¡';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ÉÊËÌÉÊËÌÉÊËÌ';
     $find = 'É';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ĭĮįİĭĮįİĭĮįİ';
     $find = 'ĭ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ƑƒƓƔƑƒƓƔƑƒƓƔ';
     $find = 'Ƒ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'əɚɛɜəɚɛɜəɚɛɜ';
     $find = 'ə';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ЀЁЂЃЀЁЂЃЀЁЂЃ';
     $find = 'Ѐ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'МНОПМНОПМНОП';
     $find = 'М';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'չպջռչպջռչպջռ';
     $find = 'չ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'فقكلفقكلفقكل';
     $find = 'ف';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = '✰✱✲✳✰✱✲✳✰✱✲✳';
     $find = '✰';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = '⺀⺁⺂⺃⺀⺁⺂⺃⺀⺁⺂⺃';
     $find = '⺀';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = '⽅⽆⽇⽈⽅⽆⽇⽈⽅⽆⽇⽈';
     $find = '⽅';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = '눡눢눣눤눡눢눣눤눡눢눣눤';
     $find = '눡';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ﹲﹳﹴ﹵ﹲﹳﹴ﹵ﹲﹳﹴ﹵';
     $find = 'ﹲ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ﻓﻔﻕﻖﻓﻔﻕﻖﻓﻔﻕﻖ';
     $find = 'ﻓ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'abcdabcdabcd';
     $find = 'a';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ィゥェォィゥェォィゥェォ';
     $find = 'ィ';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     $this->assertEqual($result, $expected);
     $string = 'ケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙';
     $find = 'ル';
     $result = String::strpos($string, $find);
     $expected = 32;
     $this->assertEqual($result, $expected);
     $string = '𐐀𐐁𐐀𐐁𐐀𐐁';
     $find = '';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     //$this->assertEqual($result, $expected);
     $string = '𐐩𐐪𐐩𐐪𐐩𐐪';
     $find = '';
     $result = String::strpos($string, $find, 5);
     $expected = 8;
     //$this->assertEqual($result, $expected);
     $string = 'Ĥēĺļŏ, Ŵőřļď!';
     $find = 'ļ';
     $result = String::strpos($string, $find, 4);
     $expected = 10;
     $this->assertEqual($result, $expected);
     $string = 'Hello, World!';
     $find = 'l';
     $result = String::strpos($string, $find, 4);
     $expected = 10;
     $this->assertEqual($result, $expected);
     $string = 'čini';
     $find = 'i';
     $result = String::strpos($string, $find, 2);
     $expected = 3;
     $this->assertEqual($result, $expected);
     $string = 'moći';
     $find = 'ć';
     $result = String::strpos($string, $find, 3);
     $this->assertFalse($result);
     $string = 'državni';
     $find = 'ž';
     $result = String::strpos($string, $find, 3);
     $this->assertFalse($result);
     $string = '把百度设为首页';
     $find = '首';
     $result = String::strpos($string, $find, 6);
     $this->assertFalse($result);
     $string = '一二三周永龍';
     $find = '周';
     $result = String::strpos($string, $find, 4);
     $this->assertFalse($result);
 }