예제 #1
0
 public function test_strToDate_yearRange()
 {
     $pattern = "1983-84";
     $parts = Zotero_Date::strToDate($pattern);
     $this->assertEquals(1983, $parts['year']);
     $this->assertFalse(isset($parts['month']));
     $this->assertFalse(isset($parts['day']));
     $this->assertEquals("84", $parts['part']);
     $pattern = "1983-1984";
     $parts = Zotero_Date::strToDate($pattern);
     $this->assertEquals(1983, $parts['year']);
     $this->assertFalse(isset($parts['month']));
     $this->assertFalse(isset($parts['day']));
     $this->assertEquals("1984", $parts['part']);
 }
예제 #2
0
 public static function retrieveItem($zoteroItem)
 {
     if (!$zoteroItem) {
         throw new Exception("Zotero item not provided");
     }
     // don't return URL or accessed information for journal articles if a
     // pages field exists
     $itemType = Zotero_ItemTypes::getName($zoteroItem->itemTypeID);
     $cslType = isset(self::$zoteroTypeMap[$itemType]) ? self::$zoteroTypeMap[$itemType] : false;
     if (!$cslType) {
         $cslType = "article";
     }
     $ignoreURL = ($zoteroItem->getField("accessDate", true, true, true) || $zoteroItem->getField("url", true, true, true)) && in_array($itemType, array("journalArticle", "newspaperArticle", "magazineArticle")) && $zoteroItem->getField("pages", false, false, true) && self::$citePaperJournalArticleURL;
     $cslItem = array('id' => $zoteroItem->libraryID . "/" . $zoteroItem->key, 'type' => $cslType);
     // get all text variables (there must be a better way)
     // TODO: does citeproc-js permit short forms?
     foreach (self::$zoteroFieldMap as $variable => $fields) {
         if ($variable == "URL" && $ignoreURL) {
             continue;
         }
         foreach ($fields as $field) {
             $value = $zoteroItem->getField($field, false, true, true);
             if ($value !== "") {
                 // Strip enclosing quotes
                 if (preg_match(self::$quotedRegexp, $value)) {
                     $value = substr($value, 1, strlen($value) - 2);
                 }
                 $cslItem[$variable] = $value;
                 break;
             }
         }
     }
     // separate name variables
     $authorID = Zotero_CreatorTypes::getPrimaryIDForType($zoteroItem->itemTypeID);
     $creators = $zoteroItem->getCreators();
     foreach ($creators as $creator) {
         if ($creator['creatorTypeID'] == $authorID) {
             $creatorType = "author";
         } else {
             $creatorType = Zotero_CreatorTypes::getName($creator['creatorTypeID']);
         }
         $creatorType = isset(self::$zoteroNameMap[$creatorType]) ? self::$zoteroNameMap[$creatorType] : false;
         if (!$creatorType) {
             continue;
         }
         $nameObj = array('family' => $creator['ref']->lastName, 'given' => $creator['ref']->firstName);
         if (isset($cslItem[$creatorType])) {
             $cslItem[$creatorType][] = $nameObj;
         } else {
             $cslItem[$creatorType] = array($nameObj);
         }
     }
     // get date variables
     foreach (self::$zoteroDateMap as $key => $val) {
         $date = $zoteroItem->getField($val, false, true, true);
         if ($date) {
             $cslItem[$key] = array("raw" => $date);
             continue;
             $date = Zotero_Date::strToDate($date);
             if (!empty($date['part']) && !$date['month']) {
                 // if there's a part but no month, interpret literally
                 $cslItem[$variable] = array("literal" => $date['part']);
             } else {
                 // otherwise, use date-parts
                 $dateParts = array();
                 if ($date['year']) {
                     $dateParts[] = $date['year'];
                     if ($date['month']) {
                         $dateParts[] = $date['month'] + 1;
                         // Mimics JS
                         if ($date['day']) {
                             $dateParts[] = $date['day'];
                         }
                     }
                 }
                 $cslItem[$key] = array("date-parts" => array($dateParts));
             }
         }
     }
     return $cslItem;
 }