Changeset 3284665
- Timestamp:
- 04/30/2025 07:38:49 AM (10 months ago)
- Location:
- kama-clic-counter
- Files:
-
- 2 added
- 8 edited
- 1 copied
-
tags/4.0.3 (copied) (copied from kama-clic-counter/trunk)
-
tags/4.0.3/assets/counter.js (modified) (4 diffs)
-
tags/4.0.3/assets/counter.min.js (added)
-
tags/4.0.3/kama_click_counter.php (modified) (1 diff)
-
tags/4.0.3/readme.txt (modified) (2 diffs)
-
tags/4.0.3/src/Counter.php (modified) (5 diffs)
-
trunk/assets/counter.js (modified) (4 diffs)
-
trunk/assets/counter.min.js (added)
-
trunk/kama_click_counter.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Counter.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kama-clic-counter/tags/4.0.3/assets/counter.js
r3167383 r3284665 1 // IMPORTANT: This file is included as a script in the HTML, 2 // so ending with `;` is required! 1 3 (function(){ 2 4 … … 7 9 aclass : '__aclass__', 8 10 questSymbol : '__questSymbol__', 9 ampSymbol : '__ampSymbol__' 11 ampSymbol : '__ampSymbol__', 10 12 }; 11 13 … … 18 20 let a = ev.target; 19 21 20 // test `a[href*= "'+ kcckey +'"]` selector22 // test `a[href*={kcckey}]` selector 21 23 if( 'A' !== a.tagName || a.href.indexOf( params.kcckey ) === -1 ){ 22 24 return; 23 25 } 24 26 25 let match = a.href.match( new RegExp( params.kcckey +'=(.*)' ) ); 26 if( match && match[1] ){ 27 let realurl = match[1]; 27 let match = a.href.match( new RegExp( params.kcckey +'=(.+)' ) ); 28 let url = match[1] || ''; 29 if( ! url ){ 30 return; 31 } 28 32 29 if( parseInt( realurl ) ){30 realurl = '/#download' + realurl;31 }33 if( parseInt( url ) ){ 34 url = '/#download' + url; 35 } 32 36 33 // !!! before a.href 34 a.dataset.kccurl = a.href.replace( realurl, replaceUrlExtraSymbols( realurl ) ); 35 a.href = realurl; 36 } 37 } 38 39 function replaceUrlExtraSymbols( url ){ 40 return url 41 .replace( /[?]/g, params.questSymbol ) 42 .replace( /[&]/g, params.ampSymbol ); 37 // !!! before a.href 38 a.dataset.kccurl = a.href.replace( url, replaceExtraSymbols( url ) ); 39 a.href = url; 43 40 } 44 41 45 42 function clickEventHandler( ev ){ 46 let a = ev.target.closest( `.${params.aclass}` );47 43 48 if( !a || 'A' !== a.tagName ){ 44 let a = ev.target.closest( 'a' ); 45 if( ! a ){ 49 46 return; 50 47 } … … 66 63 } 67 64 68 a.href = url; 69 a.dataset.kccurl = href.replace( url, replaceUrlExtraSymbols( url ) ); 65 a.dataset.kccurl = href.replace( url, replaceExtraSymbols( url ) ); 70 66 } 71 67 } 72 68 // count class 73 69 else if( a.classList.contains( params.aclass ) ){ 74 let pid = a.dataset[ params.pidkey ] || ''; 75 76 let kccurl = params.urlpatt.replace( '{in_post}', pid ) 77 .replace( '{download}', ( a.dataset.kccdownload ? 1 : '' ) ) 78 .replace( '{url}', replaceUrlExtraSymbols( href ) ); 79 80 a.dataset.kccurl = kccurl; 70 a.dataset.kccurl = params.urlpatt 71 .replace( '{in_post}', (a.dataset[ params.pidkey ] || '') ) 72 .replace( '{download}', (a.dataset.kccdownload ? 1 : '') ) 73 .replace( '{url}', replaceExtraSymbols( href ) ); 81 74 } 82 75 83 a.dataset.kccurl && ( a.href = a.dataset.kccurl ); 76 if( a.dataset.kccurl ){ 77 a.href = a.dataset.kccurl; 78 } 79 } 80 81 function replaceExtraSymbols( url ){ 82 return url 83 .replace( /[?]/g, params.questSymbol ) 84 .replace( /[&]/g, params.ampSymbol ); 84 85 } 85 86 -
kama-clic-counter/tags/4.0.3/kama_click_counter.php
r3282892 r3284665 14 14 * Requires at least: 5.7 15 15 * 16 * Version: 4.0. 216 * Version: 4.0.3 17 17 */ 18 18 -
kama-clic-counter/tags/4.0.3/readme.txt
r3282892 r3284665 1 === Plugin Name===1 === Kama Click Counter === 2 2 Stable tag: trunk 3 3 Tested up to: 6.8.0 … … 44 44 45 45 == Changelog == 46 47 = 4.0.3 = 48 - FIX: Bugfix the counter not worked after the last updates for the count click of Download block. And more: 49 - IMP: Minor improvements. 46 50 47 51 = 4.0.2 = -
kama-clic-counter/tags/4.0.3/src/Counter.php
r3282892 r3284665 5 5 class Counter { 6 6 7 const COUNT_KEY = 'kcccount';8 9 const PID_KEY = 'kccpid';10 11 const URL_PLACEHOLDERS = [7 public const COUNT_KEY = 'kcccount'; 8 9 public const PID_KEY = 'kccpid'; 10 11 public const URL_PLACEHOLDERS = [ 12 12 '?' => '__QUESTION__', 13 13 '&' => '__AMPERSAND__', … … 18 18 19 19 public function __construct( Options $options ) { 20 21 20 $this->opt = $options; 22 21 } 23 22 24 public function init() {25 23 public function init(): void { 24 // add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 99 ); 26 25 add_action( 'wp_footer', [ $this, 'footer_js' ], 99 ); 27 28 26 add_filter( 'init', [ $this, 'redirect' ], 0 ); 29 27 } 30 28 29 // public function enqueue_scripts(): void { 30 // wp_enqueue_script( 'kama-click-counter', plugin()->url . '/assets/counter.js', [], '4.0.2', [ 31 // 'in_footer' => true, 32 // 'strategy' => 'defer', 33 // ] ); 34 // } 35 31 36 /** 32 37 * A script to count links all over the site. 33 * 34 * @return void 35 */ 36 public function footer_js() { 37 $js = strtr( 38 file_get_contents( plugin()->dir . '/assets/counter.js' ), 39 [ 40 '__kcckey__' => self::COUNT_KEY, 41 '__pidkey__' => self::PID_KEY, 42 '__urlpatt__' => $this->get_kcc_url( '{url}', '{in_post}', '{download}' ), 43 '__aclass__' => sanitize_html_class( $this->opt->links_class ), 44 '__questSymbol__' => self::URL_PLACEHOLDERS['?'], 45 '__ampSymbol__' => self::URL_PLACEHOLDERS['&'], 46 ] 47 ); 48 49 $js = preg_replace( '~[^:]//[^\n]+|[\t\n\r]~', ' ', $js ); // remove comments, \t\r\n 50 $js = preg_replace( '~[ ]{2,}~', ' ', $js ); 38 */ 39 public function footer_js(): void { 40 $js = file_get_contents( plugin()->dir . '/assets/counter.min.js' ); 41 42 $js = strtr( $js, [ 43 '__kcckey__' => self::COUNT_KEY, 44 '__pidkey__' => self::PID_KEY, 45 '__urlpatt__' => $this->get_kcc_url( '{url}', '{in_post}', '{download}' ), 46 '__aclass__' => sanitize_html_class( $this->opt->links_class ), 47 '__questSymbol__' => self::URL_PLACEHOLDERS['?'], 48 '__ampSymbol__' => self::URL_PLACEHOLDERS['&'], 49 ] ); 51 50 ?> 52 51 <script id="kama-click-counter"><?= $js ?></script> … … 334 333 /** 335 334 * Redirect to link url. 336 * 337 * @return void 338 */ 339 public function redirect() { 335 */ 336 public function redirect(): void { 340 337 341 338 /** … … 418 415 } 419 416 420 // remove http, https protocol if it's current site url417 // remove http, https protocol if it's the current site url 421 418 if( strpos( $url, $_SERVER['HTTP_HOST'] ) ){ 422 419 $url = self::del_http_protocol( $url ); … … 474 471 475 472 /** 476 * Retrieve t itle of a (local or remote) webpage.473 * Retrieve the title of a (local or remote) webpage. 477 474 */ 478 475 private function get_html_title( string $url ): string { -
kama-clic-counter/trunk/assets/counter.js
r3167383 r3284665 1 // IMPORTANT: This file is included as a script in the HTML, 2 // so ending with `;` is required! 1 3 (function(){ 2 4 … … 7 9 aclass : '__aclass__', 8 10 questSymbol : '__questSymbol__', 9 ampSymbol : '__ampSymbol__' 11 ampSymbol : '__ampSymbol__', 10 12 }; 11 13 … … 18 20 let a = ev.target; 19 21 20 // test `a[href*= "'+ kcckey +'"]` selector22 // test `a[href*={kcckey}]` selector 21 23 if( 'A' !== a.tagName || a.href.indexOf( params.kcckey ) === -1 ){ 22 24 return; 23 25 } 24 26 25 let match = a.href.match( new RegExp( params.kcckey +'=(.*)' ) ); 26 if( match && match[1] ){ 27 let realurl = match[1]; 27 let match = a.href.match( new RegExp( params.kcckey +'=(.+)' ) ); 28 let url = match[1] || ''; 29 if( ! url ){ 30 return; 31 } 28 32 29 if( parseInt( realurl ) ){30 realurl = '/#download' + realurl;31 }33 if( parseInt( url ) ){ 34 url = '/#download' + url; 35 } 32 36 33 // !!! before a.href 34 a.dataset.kccurl = a.href.replace( realurl, replaceUrlExtraSymbols( realurl ) ); 35 a.href = realurl; 36 } 37 } 38 39 function replaceUrlExtraSymbols( url ){ 40 return url 41 .replace( /[?]/g, params.questSymbol ) 42 .replace( /[&]/g, params.ampSymbol ); 37 // !!! before a.href 38 a.dataset.kccurl = a.href.replace( url, replaceExtraSymbols( url ) ); 39 a.href = url; 43 40 } 44 41 45 42 function clickEventHandler( ev ){ 46 let a = ev.target.closest( `.${params.aclass}` );47 43 48 if( !a || 'A' !== a.tagName ){ 44 let a = ev.target.closest( 'a' ); 45 if( ! a ){ 49 46 return; 50 47 } … … 66 63 } 67 64 68 a.href = url; 69 a.dataset.kccurl = href.replace( url, replaceUrlExtraSymbols( url ) ); 65 a.dataset.kccurl = href.replace( url, replaceExtraSymbols( url ) ); 70 66 } 71 67 } 72 68 // count class 73 69 else if( a.classList.contains( params.aclass ) ){ 74 let pid = a.dataset[ params.pidkey ] || ''; 75 76 let kccurl = params.urlpatt.replace( '{in_post}', pid ) 77 .replace( '{download}', ( a.dataset.kccdownload ? 1 : '' ) ) 78 .replace( '{url}', replaceUrlExtraSymbols( href ) ); 79 80 a.dataset.kccurl = kccurl; 70 a.dataset.kccurl = params.urlpatt 71 .replace( '{in_post}', (a.dataset[ params.pidkey ] || '') ) 72 .replace( '{download}', (a.dataset.kccdownload ? 1 : '') ) 73 .replace( '{url}', replaceExtraSymbols( href ) ); 81 74 } 82 75 83 a.dataset.kccurl && ( a.href = a.dataset.kccurl ); 76 if( a.dataset.kccurl ){ 77 a.href = a.dataset.kccurl; 78 } 79 } 80 81 function replaceExtraSymbols( url ){ 82 return url 83 .replace( /[?]/g, params.questSymbol ) 84 .replace( /[&]/g, params.ampSymbol ); 84 85 } 85 86 -
kama-clic-counter/trunk/kama_click_counter.php
r3282892 r3284665 14 14 * Requires at least: 5.7 15 15 * 16 * Version: 4.0. 216 * Version: 4.0.3 17 17 */ 18 18 -
kama-clic-counter/trunk/readme.txt
r3282892 r3284665 1 === Plugin Name===1 === Kama Click Counter === 2 2 Stable tag: trunk 3 3 Tested up to: 6.8.0 … … 44 44 45 45 == Changelog == 46 47 = 4.0.3 = 48 - FIX: Bugfix the counter not worked after the last updates for the count click of Download block. And more: 49 - IMP: Minor improvements. 46 50 47 51 = 4.0.2 = -
kama-clic-counter/trunk/src/Counter.php
r3282892 r3284665 5 5 class Counter { 6 6 7 const COUNT_KEY = 'kcccount';8 9 const PID_KEY = 'kccpid';10 11 const URL_PLACEHOLDERS = [7 public const COUNT_KEY = 'kcccount'; 8 9 public const PID_KEY = 'kccpid'; 10 11 public const URL_PLACEHOLDERS = [ 12 12 '?' => '__QUESTION__', 13 13 '&' => '__AMPERSAND__', … … 18 18 19 19 public function __construct( Options $options ) { 20 21 20 $this->opt = $options; 22 21 } 23 22 24 public function init() {25 23 public function init(): void { 24 // add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 99 ); 26 25 add_action( 'wp_footer', [ $this, 'footer_js' ], 99 ); 27 28 26 add_filter( 'init', [ $this, 'redirect' ], 0 ); 29 27 } 30 28 29 // public function enqueue_scripts(): void { 30 // wp_enqueue_script( 'kama-click-counter', plugin()->url . '/assets/counter.js', [], '4.0.2', [ 31 // 'in_footer' => true, 32 // 'strategy' => 'defer', 33 // ] ); 34 // } 35 31 36 /** 32 37 * A script to count links all over the site. 33 * 34 * @return void 35 */ 36 public function footer_js() { 37 $js = strtr( 38 file_get_contents( plugin()->dir . '/assets/counter.js' ), 39 [ 40 '__kcckey__' => self::COUNT_KEY, 41 '__pidkey__' => self::PID_KEY, 42 '__urlpatt__' => $this->get_kcc_url( '{url}', '{in_post}', '{download}' ), 43 '__aclass__' => sanitize_html_class( $this->opt->links_class ), 44 '__questSymbol__' => self::URL_PLACEHOLDERS['?'], 45 '__ampSymbol__' => self::URL_PLACEHOLDERS['&'], 46 ] 47 ); 48 49 $js = preg_replace( '~[^:]//[^\n]+|[\t\n\r]~', ' ', $js ); // remove comments, \t\r\n 50 $js = preg_replace( '~[ ]{2,}~', ' ', $js ); 38 */ 39 public function footer_js(): void { 40 $js = file_get_contents( plugin()->dir . '/assets/counter.min.js' ); 41 42 $js = strtr( $js, [ 43 '__kcckey__' => self::COUNT_KEY, 44 '__pidkey__' => self::PID_KEY, 45 '__urlpatt__' => $this->get_kcc_url( '{url}', '{in_post}', '{download}' ), 46 '__aclass__' => sanitize_html_class( $this->opt->links_class ), 47 '__questSymbol__' => self::URL_PLACEHOLDERS['?'], 48 '__ampSymbol__' => self::URL_PLACEHOLDERS['&'], 49 ] ); 51 50 ?> 52 51 <script id="kama-click-counter"><?= $js ?></script> … … 334 333 /** 335 334 * Redirect to link url. 336 * 337 * @return void 338 */ 339 public function redirect() { 335 */ 336 public function redirect(): void { 340 337 341 338 /** … … 418 415 } 419 416 420 // remove http, https protocol if it's current site url417 // remove http, https protocol if it's the current site url 421 418 if( strpos( $url, $_SERVER['HTTP_HOST'] ) ){ 422 419 $url = self::del_http_protocol( $url ); … … 474 471 475 472 /** 476 * Retrieve t itle of a (local or remote) webpage.473 * Retrieve the title of a (local or remote) webpage. 477 474 */ 478 475 private function get_html_title( string $url ): string {
Note: See TracChangeset
for help on using the changeset viewer.