Plugin Directory

Changeset 2970133


Ignore:
Timestamp:
09/22/2023 09:25:19 AM (3 years ago)
Author:
wpmunich
Message:

Update to version 0.2.0 from GitHub

Location:
citations
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • citations/tags/0.2.0/citations.php

    r2958928 r2970133  
    1010 * Author: WP Munich
    1111 * Author URI: https://www.wp-munich.com
    12  * Version: 0.1.2
     12 * Version: 0.2.0
    1313 * Text Domain: citations
    1414 */
  • citations/tags/0.2.0/inc/Citations/Citations.php

    r2958837 r2970133  
    8181
    8282        /**
    83          * Initialize the DOMDocument.
     83         * Use regex to find all span tags with the class js--wpm-format-cite.
     84         * The class attribute can be anywhere in the tag. Catch the whole tag.
    8485         */
    85         $doc = new \DOMDocument();
     86        $pattern = '/<span[^>]*class=[\'"]*js--wpm-format-cite[\'"]*[^>]*>(.*?)<\/span>/i';
     87        $content = preg_replace_callback( $pattern, array( $this, 'replace_citation' ), $content );
     88
     89        return $content;
     90    }
     91
     92    /**
     93     * Replaces the citation with the bibliography.
     94     *
     95     * @param array $match The match.
     96     *
     97     * @return string
     98     */
     99    private function replace_citation( $match ) {
     100        $whole_tag   = $match[0];
     101        $tag_content = $match[1];
    86102
    87103        /**
    88          * Load the block content into a DOMDocument.
    89          * We cannot just load the block content as is, as it will be cast as ISO-8859-1. We need to
    90          * tell the DOMDocument to use UTF-8.
     104         * The number of citations we have so far.
    91105         */
    92         libxml_use_internal_errors( true );
    93         $doc->loadHTML( '<?xml encoding="utf-8" ?>' . $content );
    94         libxml_clear_errors();
    95 
    96         $doc->removeChild( $doc->childNodes->item( 1 ) );
    97 
    98         $finder = new \DOMXPath( $doc );
     106        $citation_count = count( $this->citations );
    99107
    100108        /**
    101          * Find all the citation elements.
     109         * The human readable citation number. (We start with 1)
    102110         */
    103         $citations = $finder->query( '//*[@class="js--wpm-format-cite"]' );
    104 
    105         $citation_link = $doc->createElement( 'a' );
    106         $citation_link->setAttribute( 'class', 'js--wpm-format-cite-link' );
    107         $citation_link->setAttribute( 'href', '#' );
     111        $c = $citation_count + 1;
    108112
    109113        /**
    110          * Loop through all the citation elements.
     114         * Compile the citation link, that links to the bibliography.
    111115         */
    112         foreach ( $citations as $citation ) {
    113             $specific_link = $citation_link->cloneNode( true );
    114             $specific_link->setAttribute( 'id', 'wpm-citation-' . ( count( $this->citations ) + 1 ) );
    115             $specific_link->setAttribute( 'href', '#wpm-citation-source-' . ( count( $this->citations ) + 1 ) );
     116        $citations_tag = '<a href="#wpm-citation-source-' . $c . '" id="wpm-citation-' . $c . '" class="js--wpm-format-cite-link">[' . $c . ']</a>';
    116117
    117             // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    118             $specific_link->nodeValue = '[' . ( count( $this->citations ) + 1 ) . ']';
    119 
    120             $citation->appendChild( $specific_link );
    121             $this->citations[] = $citation->attributes->getNamedItem( 'data-cite-text' )->nodeValue;
     118        /**
     119         * Use regex to fetch the 'data-cite-text' attribute from the tag.
     120         */
     121        $pattern = '/data-cite-text=[\'"]([^\'"]*)[\'"]/i';
     122        preg_match( $pattern, $whole_tag, $matches );
     123        if ( ! empty( $matches[1] ) ) {
     124            $citation = $matches[1];
    122125        }
    123126
    124         return $doc->saveHTML();
     127        /**
     128         * Add the citation to the citations array.
     129         */
     130        $this->citations[] = $citation;
     131
     132        return str_replace( $tag_content, $tag_content . $citations_tag, $whole_tag );
    125133    }
    126134}
  • citations/tags/0.2.0/readme.txt

    r2958928 r2970133  
    66License: GNU General Public License v2.0
    77License URI: https://github.com/luehrsenheinrich/wpm-citations/blob/main/LICENSE
    8 Stable tag: 0.1.2
    9 Tested up to: 6.3
     8Stable tag: 0.2.0
     9Tested up to: 6.3.1
    1010
    1111This Plugin introduces practical citation functionality to the WordPress Block Editor, aiming to streamline the process of adding references to your content.
     
    15151.  **Cite Rich Text Format**: This feature lets users mark citations in their text and assign them a specific source. This makes adding citations straightforward, enhancing the clarity and reliability of your content.
    16162.  **Bibliography Block**: This plugin also offers a bibliography block that displays all referenced sources. The plugin creates links between your in-text citations and their corresponding sources in the bibliography block, making it easier for readers to find and check your references.
     17
     18### [Try now on WordPress Playground!](https://playground.wordpress.net/?plugin=citations&url=/wp-admin/post-new.php)
     19
     20## How to use
    1721
    1822### Creating In-Text Citations
     
    42464. A few lines of filler text with pre-defined citations and a bibliography block will appear in your post content.
    4347
     48## Contributing
     49If you are a developer, we encourage you to follow along or [contribute](https://github.com/luehrsenheinrich/wpm-citations) to the development of this plugin [on GitHub](https://github.com/luehrsenheinrich/wpm-citations).
     50
    4451== Installation ==
    4552= From within WordPress =
  • citations/tags/0.2.0/vendor/autoload.php

    r2958928 r2970133  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2::getLoader();
     25return ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577::getLoader();
  • citations/tags/0.2.0/vendor/composer/autoload_real.php

    r2958928 r2970133  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2
     5class ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • citations/tags/0.2.0/vendor/composer/autoload_static.php

    r2958928 r2970133  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2
     7class ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • citations/tags/0.2.0/vendor/composer/installed.php

    r2958928 r2970133  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '487258bd02ac8de717125297e7130cd6b914b765',
     6        'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '487258bd02ac8de717125297e7130cd6b914b765',
     16            'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
  • citations/trunk/citations.php

    r2958928 r2970133  
    1010 * Author: WP Munich
    1111 * Author URI: https://www.wp-munich.com
    12  * Version: 0.1.2
     12 * Version: 0.2.0
    1313 * Text Domain: citations
    1414 */
  • citations/trunk/inc/Citations/Citations.php

    r2958837 r2970133  
    8181
    8282        /**
    83          * Initialize the DOMDocument.
     83         * Use regex to find all span tags with the class js--wpm-format-cite.
     84         * The class attribute can be anywhere in the tag. Catch the whole tag.
    8485         */
    85         $doc = new \DOMDocument();
     86        $pattern = '/<span[^>]*class=[\'"]*js--wpm-format-cite[\'"]*[^>]*>(.*?)<\/span>/i';
     87        $content = preg_replace_callback( $pattern, array( $this, 'replace_citation' ), $content );
     88
     89        return $content;
     90    }
     91
     92    /**
     93     * Replaces the citation with the bibliography.
     94     *
     95     * @param array $match The match.
     96     *
     97     * @return string
     98     */
     99    private function replace_citation( $match ) {
     100        $whole_tag   = $match[0];
     101        $tag_content = $match[1];
    86102
    87103        /**
    88          * Load the block content into a DOMDocument.
    89          * We cannot just load the block content as is, as it will be cast as ISO-8859-1. We need to
    90          * tell the DOMDocument to use UTF-8.
     104         * The number of citations we have so far.
    91105         */
    92         libxml_use_internal_errors( true );
    93         $doc->loadHTML( '<?xml encoding="utf-8" ?>' . $content );
    94         libxml_clear_errors();
    95 
    96         $doc->removeChild( $doc->childNodes->item( 1 ) );
    97 
    98         $finder = new \DOMXPath( $doc );
     106        $citation_count = count( $this->citations );
    99107
    100108        /**
    101          * Find all the citation elements.
     109         * The human readable citation number. (We start with 1)
    102110         */
    103         $citations = $finder->query( '//*[@class="js--wpm-format-cite"]' );
    104 
    105         $citation_link = $doc->createElement( 'a' );
    106         $citation_link->setAttribute( 'class', 'js--wpm-format-cite-link' );
    107         $citation_link->setAttribute( 'href', '#' );
     111        $c = $citation_count + 1;
    108112
    109113        /**
    110          * Loop through all the citation elements.
     114         * Compile the citation link, that links to the bibliography.
    111115         */
    112         foreach ( $citations as $citation ) {
    113             $specific_link = $citation_link->cloneNode( true );
    114             $specific_link->setAttribute( 'id', 'wpm-citation-' . ( count( $this->citations ) + 1 ) );
    115             $specific_link->setAttribute( 'href', '#wpm-citation-source-' . ( count( $this->citations ) + 1 ) );
     116        $citations_tag = '<a href="#wpm-citation-source-' . $c . '" id="wpm-citation-' . $c . '" class="js--wpm-format-cite-link">[' . $c . ']</a>';
    116117
    117             // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    118             $specific_link->nodeValue = '[' . ( count( $this->citations ) + 1 ) . ']';
    119 
    120             $citation->appendChild( $specific_link );
    121             $this->citations[] = $citation->attributes->getNamedItem( 'data-cite-text' )->nodeValue;
     118        /**
     119         * Use regex to fetch the 'data-cite-text' attribute from the tag.
     120         */
     121        $pattern = '/data-cite-text=[\'"]([^\'"]*)[\'"]/i';
     122        preg_match( $pattern, $whole_tag, $matches );
     123        if ( ! empty( $matches[1] ) ) {
     124            $citation = $matches[1];
    122125        }
    123126
    124         return $doc->saveHTML();
     127        /**
     128         * Add the citation to the citations array.
     129         */
     130        $this->citations[] = $citation;
     131
     132        return str_replace( $tag_content, $tag_content . $citations_tag, $whole_tag );
    125133    }
    126134}
  • citations/trunk/readme.txt

    r2958928 r2970133  
    66License: GNU General Public License v2.0
    77License URI: https://github.com/luehrsenheinrich/wpm-citations/blob/main/LICENSE
    8 Stable tag: 0.1.2
    9 Tested up to: 6.3
     8Stable tag: 0.2.0
     9Tested up to: 6.3.1
    1010
    1111This Plugin introduces practical citation functionality to the WordPress Block Editor, aiming to streamline the process of adding references to your content.
     
    15151.  **Cite Rich Text Format**: This feature lets users mark citations in their text and assign them a specific source. This makes adding citations straightforward, enhancing the clarity and reliability of your content.
    16162.  **Bibliography Block**: This plugin also offers a bibliography block that displays all referenced sources. The plugin creates links between your in-text citations and their corresponding sources in the bibliography block, making it easier for readers to find and check your references.
     17
     18### [Try now on WordPress Playground!](https://playground.wordpress.net/?plugin=citations&url=/wp-admin/post-new.php)
     19
     20## How to use
    1721
    1822### Creating In-Text Citations
     
    42464. A few lines of filler text with pre-defined citations and a bibliography block will appear in your post content.
    4347
     48## Contributing
     49If you are a developer, we encourage you to follow along or [contribute](https://github.com/luehrsenheinrich/wpm-citations) to the development of this plugin [on GitHub](https://github.com/luehrsenheinrich/wpm-citations).
     50
    4451== Installation ==
    4552= From within WordPress =
  • citations/trunk/vendor/autoload.php

    r2958928 r2970133  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2::getLoader();
     25return ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577::getLoader();
  • citations/trunk/vendor/composer/autoload_real.php

    r2958928 r2970133  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2
     5class ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderIniteebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • citations/trunk/vendor/composer/autoload_static.php

    r2958928 r2970133  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2
     7class ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticIniteebe86be26d0e6bc7c1cefa05e988dd2::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • citations/trunk/vendor/composer/installed.php

    r2958928 r2970133  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '487258bd02ac8de717125297e7130cd6b914b765',
     6        'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '487258bd02ac8de717125297e7130cd6b914b765',
     16            'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.