_liste_references[$id]; $result = null; if ( $list != null ) { foreach ($list as $ref) { if ( strcmp($ref->get_name(), $name) == 0 ) { $result = $ref; break; } } } return $result; } /** * Adds the reference in the list, if needed. If already in list, increments the usage counter (= the number * indicating how many times the references is used in the post). * * @param int $the_ID The post ID * @param Jref_Reference $reference The reference we are looking at right now * * @return Jref_Reference The reference (added or updated) */ function add_reference( $the_ID, $reference ) { $ref_num = count($this->_liste_references[$the_ID]) + 1; $reference->set_ref_num( $ref_num ); $this->_liste_references[$the_ID][] = $reference; return $reference; } /** * What to do with the reference ? * * If it has a no name, we'll reference that reference (yuk) with its number and treat it (yuk) as unique (=used nowhere else). * If it has a name, we can refer to it with that name, that means we can reuse it elsewhere. * * @param Jref_Reference $reference A Jref_Rreference object that we'll be added following the rules (see above). * * @return Jref_Reference The reference itself */ function handle_reference( $reference ) { $the_ID = get_the_ID(); $current_reference = null; /** Does this reference have a name ? */ $reference_name = $reference->get_name(); if ( $reference_name == "" ) { /** If no: let's assume the reference is unique */ $current_reference = $this->add_reference( $the_ID, $reference ); } else { /** Tricker: we have a reference name ; so does it already exists in the list ? */ $reference_multiple = $this->get_reference_by_name( $the_ID, $reference_name ); if ( $reference_multiple != null) { /** Yes: it exists. So let's increment the counter of usage */ $reference_multiple->add_count(); $current_reference = $reference_multiple; } else { /** New Reference, with a name. May be used later. */ $current_reference = $this->add_reference( get_the_ID(), $reference ); } } /** Now we have to set a name for the HTML anchor we'll use to navigate */ $current_reference->set_anchor( "jref-p" . $the_ID . "-r" . $current_reference->get_ref_num() . "-o" . $current_reference->get_occ_nb() ); return $current_reference; } /** * Shortcode handler. */ function jref_shortcode( $atts, $content ) { ob_start(); $current_reference = $this->handle_reference( new Jref_Reference( $atts, $content ) ); $res = ""; $res .= "[" . $current_reference->get_ref_num() . "]"; print( $res ); return ob_get_clean(); } /** * Appends a footer containing all necessary references to the current post. This function is a WP content filter. * * @param html $content The content of the post (at its current state) * * @return html The content of the post with the reference table at its bottom * * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content */ function jref_footer( $content ) { $the_ID = get_the_ID(); $count = count( $this->_liste_references[$the_ID] ); if ( $count > 0 ) { /** Title */ $content .= "