예제 #1
0
 /**
  * Disambiguate ambiguous values.
  */
 private function solve()
 {
     Container::getContext()->enter('disambiguation');
     $this->layout = Container::getContext()->get('layout', 'layout');
     $this->names = $this->layout->getChildElement('\\Geissler\\CSL\\Names\\Names');
     // if "et-al-subsequent-min" or "et-al-subsequent-use-first" are used, use the first citation
     // to disambiguate the values (see disambiguate_BasedOnEtAlSubsequent.txt)
     $citations = Container::getRendered()->getAllById();
     if (is_object($this->names) == true) {
         $this->sorted = array_keys($citations);
         asort($citations);
         $this->disambiguateByName($citations);
     } else {
         $this->disambiguateByCitationLabel($citations);
     }
 }
예제 #2
0
 /**
  * Render a bibliography.
  *
  * @param string $data
  * @return string
  */
 public function render($data)
 {
     // sort
     $this->sort();
     // render citation to create year-suffix if necessary
     if (Container::getContext()->getValue('disambiguateAddYearSuffix', 'citation') == true) {
         Container::getContext()->setName('citation');
         Container::getData()->moveToFirst();
         Container::getCitation()->render($data);
         Container::getContext()->setName('bibliography');
         // re-sort with bibliography keys
         $this->sort();
     }
     // render
     Container::getContext()->enter('bibliography');
     $result = $this->layout->render($data);
     Container::getContext()->leave();
     // format return
     $return = '<div class="csl-bib-body"><div class="csl-entry">';
     if (is_array($result) == true && count($result) > 0) {
         $return .= implode('</div><div class="csl-entry">', $result);
     } else {
         $return .= $result;
     }
     return $return . '</div></div>';
 }
예제 #3
0
파일: Citation.php 프로젝트: geissler/csl
 /**
  * Render the citations.
  *
  * @param string $data
  * @return string
  */
 public function render($data)
 {
     Container::getContext()->enter('citation');
     // sort
     if (isset($this->sort) == true) {
         $this->sort->sort('citation');
     }
     // render citation
     $result = $this->layout->render($data);
     // The assignment of the year-suffixes follows the order of the bibliographies entries,
     // so sort if disambiguation by year-suffixes is needed, sort the data by the bibliography
     // and re-render citations
     if (Container::hasBibliography() == true && Container::getContext()->getValue('disambiguateAddYearSuffix', 'citation') === true && Container::getContext()->getLastDisambiguation() == 'Geissler\\CSL\\Options\\Disambiguation\\AddYearSuffix' && Container::getBibliography()->sort() == true) {
         Container::getRendered()->clear();
         // re-render citation
         $result = $this->layout->render($data);
     }
     if (Container::getCitationItem() !== false) {
         // apply additional citation formatting options
         Container::getCitationItem()->moveToFirst();
         if (Container::getCitationItem()->get('noteIndex') !== null || Container::getCitationItem()->get('index') !== null) {
             $citation = array();
             $length = count($result);
             $prefix = '..';
             for ($i = 0; $i < $length; $i++) {
                 if ($i + 1 == $length) {
                     $prefix = '>>';
                 }
                 // Therefore, the first character of a citation should preferably be uppercased
                 $citation[] = $prefix . '[' . $i . '] ' . $this->upperCase($result[$i]);
             }
             $return = implode("\n", $citation);
         } else {
             array_walk($result, array($this, 'upperCase'));
             $return = implode("\n", $result);
         }
     } else {
         array_walk($result, array($this, 'upperCase'));
         $return = implode("\n", $result);
     }
     Container::getContext()->leave();
     return $return;
 }
예제 #4
0
파일: LayoutTest.php 프로젝트: geissler/csl
 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/>')));
 }