/** * Set the Citation-Items. * * @see https://bitbucket.org/bdarcus/citeproc-test/overview#citation-items * @param string $data JSON array * @return CSL */ public function setCitationItems($data) { if ($data != '') { $citation = new CitationItems(); $citation->set($data); Container::setCitationItem($citation); } return $this; }
protected function initElement($layout, $json, $citation, $mode = 'citation') { $data = new Data(); $data->set($json); Container::setData($data); $citationItems = new CitationItems(); $citationItems->set($citation); Container::setCitationItem($citationItems); Container::getContext()->setName($mode); $xml = new \SimpleXMLElement($layout); $this->object = new Layout($xml); $this->object->setOptions(new Citation(new \SimpleXMLElement('<xml/>'))); }
/** * Running PHPUnit test * @param $text * @param $name * @return array */ protected function runTestFromFile($text, $name) { Container::clear(); preg_match('/MODE [=]+>>(.*)<<[=]+ MODE/s', $text, $match); $mode = preg_replace('/\\s\\s+/', '', $match[1]); $mode = preg_replace('/\\n/', '', $mode); preg_match('/RESULT [=]+>>(.*)<<[=]+ RESULT/s', $text, $match); $result = preg_replace('/\\s\\s+/', '', $match[1]); $result = preg_replace('/^\\n/', '', $result); $result = preg_replace('/\\n$/', '', $result); preg_match('/CSL [=]+>>(.*)<<[=]+ CSL/s', $text, $match); $csl = preg_replace('/^\\n/', '', $match[1]); preg_match('/INPUT [=]+>>(.*)<<[=]+ INPUT/s', $text, $match); $json = preg_replace('/\\s\\s+/', '', $match[1]); $style = new Style(); if (strpos($csl, '<') !== false) { $style->readXml(new \SimpleXMLElement($csl)); } else { $csl = preg_replace('/\\n/', '', $csl); $csl = str_replace('.csl', '', $csl); $style->setDir(__DIR__ . $this->style)->readFile($csl); } $data = new Data(); $data->set($json); Container::setData($data); Container::getContext()->setName($mode); // Abbreviations if (preg_match('/ABBREVIATIONS [=]+>>(.*)<<[=]+ ABBREVIATIONS/s', $text, $match) == 1) { $json = preg_replace('/\\s\\s+/', '', $match[1]); $abbreviation = new Abbreviation(); $abbreviation->set($json); Container::setAbbreviation($abbreviation); } // CitationItems items if (preg_match('/CITATION-ITEMS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATION-ITEMS/s', $text, $match) == 1) { $json = preg_replace('/\\s\\s+/', '', $match[1]); $citation = new CitationItems(); $citation->set($json); Container::setCitationItem($citation); } elseif (preg_match('/CITATIONS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATIONS/s', $text, $match) == 1) { // Citations items $json = preg_replace('/\\s\\s+/', '', $match[1]); $citation = new Citations(); $citation->set($json); Container::setCitationItem($citation); } if ($mode == 'citation') { return array($result, Container::getCitation()->render(''), $name); } elseif ($mode == 'bibliography') { return array($result, Container::getBibliography()->render(''), $name); } elseif ($mode == 'bibliography-nosort') { Container::getBibliography()->setDoNotSort(true); return array($result, Container::getBibliography()->render(''), $name); } else { return array('Missing mode', '', $name); } }