/** * Creates a citation object for each citation parser function. * * Reads flags and parameters from WCArgumentReader object, * then creates an appropriate child of class WCStyle based on the * first parameter after the colon, then returns the citation as text. * @remark Note that this $parser is guaranteed to be the same parser that * initialized the object. * * @param WCArgumentReader $argumentReader * @return string Unique marker for citation. */ public function parseCitation( WCArgumentReader $argumentReader ) { # Use the explicit citation style if defined, or use last style. $styleClassName = $argumentReader->getStyleClassName(); if ( $styleClassName ) { # Store citation style in a running database of style object singlets. $this->currentDefaultStyle = self::getStyle($styleClassName); } # A citation function, with no data, may exist merely to define the citation style. if ( $argumentReader->isEmpty() ) { ++$this->citationCount; return ''; } $reference = new WCReference(); $citation = new WCCitation( $reference ); $citation->readArguments( $argumentReader ); $reference->finalize(); # Store reference in database that checks for uniqueness. # $citation->reference will be reloaded later, after all citations are read. $citation->distance = $this->referenceStore->addUniqueReference( $this->citationCount, $reference ); # Is this a citation explicitly inserted in bibliography tags? # If so, then we will not be leaving behind a marker. if ( $this->bibliographyLevel > 0 ) { ++$this->citationCount; return ''; # Only a single marker is left behind per bibliography. } # Determine whether the citation is in a note, or inline. $section = $this->sectionStack[ $this->sectionStackPointer ]; if ( $this->noteLevel > 0 ) { $section->addNoteCite( $this->citationCount, $citation ); } else { $section->addInlineCite( $this->citationCount, $citation ); } # Store citation and leave behind a random marker for later replacement by the citation: $this->citations[ $this->citationCount++ ] = $citation; return $citation->marker; }
/** * Need to create separate WCCitation object for each entry here!! * Enter description here ... * @param unknown_type $text * @param WCArticle $article */ public function render( &$text, WCReferenceStore $referenceStore ) { $references = $referenceStore->getReferences(); $entries = array(); # Render entries in biblio format. foreach( $references as $key => $reference ) { $citation = new WCCitation( $reference ); $citation->style = $this->citationStyle; $citation->citationType = $this->citationType; $citation->citationLength = WCCitationLengthEnum::$long; $entries[ $key ] = $citation->render(); } # Sort bibliography. $this->sortBibliography( $entries ); # Generate bibliography. $bibliography = '<ul class="bibliography"' . $this->styleHTML . '>' . PHP_EOL; foreach ( $entries as $key => $entry ) { $bibliography .= '<li id="' . $references[ $key ]->id . '">' . $entry[0] . '</li>' . PHP_EOL; } $bibliography .= '</ul>'; $text = str_replace( $this->marker, $bibliography, $text ); }