Changeset 2970133
- Timestamp:
- 09/22/2023 09:25:19 AM (3 years ago)
- Location:
- citations
- Files:
-
- 14 edited
- 1 copied
-
tags/0.2.0 (copied) (copied from citations/trunk)
-
tags/0.2.0/citations.php (modified) (1 diff)
-
tags/0.2.0/inc/Citations/Citations.php (modified) (1 diff)
-
tags/0.2.0/readme.txt (modified) (3 diffs)
-
tags/0.2.0/vendor/autoload.php (modified) (1 diff)
-
tags/0.2.0/vendor/composer/autoload_real.php (modified) (2 diffs)
-
tags/0.2.0/vendor/composer/autoload_static.php (modified) (2 diffs)
-
tags/0.2.0/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/citations.php (modified) (1 diff)
-
trunk/inc/Citations/Citations.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/vendor/autoload.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_real.php (modified) (2 diffs)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
citations/tags/0.2.0/citations.php
r2958928 r2970133 10 10 * Author: WP Munich 11 11 * Author URI: https://www.wp-munich.com 12 * Version: 0. 1.212 * Version: 0.2.0 13 13 * Text Domain: citations 14 14 */ -
citations/tags/0.2.0/inc/Citations/Citations.php
r2958837 r2970133 81 81 82 82 /** 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. 84 85 */ 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]; 86 102 87 103 /** 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. 91 105 */ 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 ); 99 107 100 108 /** 101 * Find all the citation elements.109 * The human readable citation number. (We start with 1) 102 110 */ 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; 108 112 109 113 /** 110 * Loop through all the citation elements.114 * Compile the citation link, that links to the bibliography. 111 115 */ 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>'; 116 117 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]; 122 125 } 123 126 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 ); 125 133 } 126 134 } -
citations/tags/0.2.0/readme.txt
r2958928 r2970133 6 6 License: GNU General Public License v2.0 7 7 License URI: https://github.com/luehrsenheinrich/wpm-citations/blob/main/LICENSE 8 Stable tag: 0. 1.29 Tested up to: 6.3 8 Stable tag: 0.2.0 9 Tested up to: 6.3.1 10 10 11 11 This Plugin introduces practical citation functionality to the WordPress Block Editor, aiming to streamline the process of adding references to your content. … … 15 15 1. **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. 16 16 2. **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 17 21 18 22 ### Creating In-Text Citations … … 42 46 4. A few lines of filler text with pre-defined citations and a bibliography block will appear in your post content. 43 47 48 ## Contributing 49 If 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 44 51 == Installation == 45 52 = From within WordPress = -
citations/tags/0.2.0/vendor/autoload.php
r2958928 r2970133 23 23 require_once __DIR__ . '/composer/autoload_real.php'; 24 24 25 return ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2::getLoader();25 return ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577::getLoader(); -
citations/tags/0.2.0/vendor/composer/autoload_real.php
r2958928 r2970133 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd25 class ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::getInitializer($loader)); 31 31 32 32 $loader->register(true); -
citations/tags/0.2.0/vendor/composer/autoload_static.php
r2958928 r2970133 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd27 class ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 32 32 { 33 33 return \Closure::bind(function () use ($loader) { 34 $loader->prefixLengthsPsr4 = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$prefixLengthsPsr4;35 $loader->prefixDirsPsr4 = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$prefixDirsPsr4;36 $loader->classMap = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$classMap;34 $loader->prefixLengthsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixLengthsPsr4; 35 $loader->prefixDirsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixDirsPsr4; 36 $loader->classMap = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$classMap; 37 37 38 38 }, null, ClassLoader::class); -
citations/tags/0.2.0/vendor/composer/installed.php
r2958928 r2970133 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' 487258bd02ac8de717125297e7130cd6b914b765',6 'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' 487258bd02ac8de717125297e7130cd6b914b765',16 'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../', -
citations/trunk/citations.php
r2958928 r2970133 10 10 * Author: WP Munich 11 11 * Author URI: https://www.wp-munich.com 12 * Version: 0. 1.212 * Version: 0.2.0 13 13 * Text Domain: citations 14 14 */ -
citations/trunk/inc/Citations/Citations.php
r2958837 r2970133 81 81 82 82 /** 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. 84 85 */ 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]; 86 102 87 103 /** 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. 91 105 */ 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 ); 99 107 100 108 /** 101 * Find all the citation elements.109 * The human readable citation number. (We start with 1) 102 110 */ 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; 108 112 109 113 /** 110 * Loop through all the citation elements.114 * Compile the citation link, that links to the bibliography. 111 115 */ 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>'; 116 117 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]; 122 125 } 123 126 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 ); 125 133 } 126 134 } -
citations/trunk/readme.txt
r2958928 r2970133 6 6 License: GNU General Public License v2.0 7 7 License URI: https://github.com/luehrsenheinrich/wpm-citations/blob/main/LICENSE 8 Stable tag: 0. 1.29 Tested up to: 6.3 8 Stable tag: 0.2.0 9 Tested up to: 6.3.1 10 10 11 11 This Plugin introduces practical citation functionality to the WordPress Block Editor, aiming to streamline the process of adding references to your content. … … 15 15 1. **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. 16 16 2. **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 17 21 18 22 ### Creating In-Text Citations … … 42 46 4. A few lines of filler text with pre-defined citations and a bibliography block will appear in your post content. 43 47 48 ## Contributing 49 If 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 44 51 == Installation == 45 52 = From within WordPress = -
citations/trunk/vendor/autoload.php
r2958928 r2970133 23 23 require_once __DIR__ . '/composer/autoload_real.php'; 24 24 25 return ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2::getLoader();25 return ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577::getLoader(); -
citations/trunk/vendor/composer/autoload_real.php
r2958928 r2970133 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd25 class ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit eebe86be26d0e6bc7c1cefa05e988dd2', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInit7d8a2e3ea69b86867402aa07b92fe577', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::getInitializer($loader)); 31 31 32 32 $loader->register(true); -
citations/trunk/vendor/composer/autoload_static.php
r2958928 r2970133 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd27 class ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 32 32 { 33 33 return \Closure::bind(function () use ($loader) { 34 $loader->prefixLengthsPsr4 = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$prefixLengthsPsr4;35 $loader->prefixDirsPsr4 = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$prefixDirsPsr4;36 $loader->classMap = ComposerStaticInit eebe86be26d0e6bc7c1cefa05e988dd2::$classMap;34 $loader->prefixLengthsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixLengthsPsr4; 35 $loader->prefixDirsPsr4 = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$prefixDirsPsr4; 36 $loader->classMap = ComposerStaticInit7d8a2e3ea69b86867402aa07b92fe577::$classMap; 37 37 38 38 }, null, ClassLoader::class); -
citations/trunk/vendor/composer/installed.php
r2958928 r2970133 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' 487258bd02ac8de717125297e7130cd6b914b765',6 'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' 487258bd02ac8de717125297e7130cd6b914b765',16 'reference' => 'e2dcf84602963dd9394bf6f457cc3bd1907daccb', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.