Plugin Directory

Changeset 3284665


Ignore:
Timestamp:
04/30/2025 07:38:49 AM (10 months ago)
Author:
Tkama
Message:

Update to version 4.0.3 from GitHub

Location:
kama-clic-counter
Files:
2 added
8 edited
1 copied

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!
    13(function(){
    24
     
    79        aclass      : '__aclass__',
    810        questSymbol : '__questSymbol__',
    9         ampSymbol   : '__ampSymbol__'
     11        ampSymbol   : '__ampSymbol__',
    1012    };
    1113
     
    1820        let a = ev.target;
    1921
    20         // test `a[href*="'+ kcckey +'"]` selector
     22        // test `a[href*={kcckey}]` selector
    2123        if( 'A' !== a.tagName || a.href.indexOf( params.kcckey ) === -1 ){
    2224            return;
    2325        }
    2426
    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        }
    2832
    29             if( parseInt( realurl ) ){
    30                 realurl = '/#download' + realurl;
    31             }
     33        if( parseInt( url ) ){
     34            url = '/#download' + url;
     35        }
    3236
    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;
    4340    }
    4441
    4542    function clickEventHandler( ev ){
    46         let a = ev.target.closest( `.${params.aclass}` );
    4743
    48         if( !a || 'A' !== a.tagName ){
     44        let a = ev.target.closest( 'a' );
     45        if( ! a ){
    4946            return;
    5047        }
     
    6663                }
    6764
    68                 a.href = url;
    69                 a.dataset.kccurl = href.replace( url, replaceUrlExtraSymbols( url ) );
     65                a.dataset.kccurl = href.replace( url, replaceExtraSymbols( url ) );
    7066            }
    7167        }
    7268        // count class
    7369        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 ) );
    8174        }
    8275
    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 );
    8485    }
    8586
  • kama-clic-counter/tags/4.0.3/kama_click_counter.php

    r3282892 r3284665  
    1414 * Requires at least: 5.7
    1515 *
    16  * Version: 4.0.2
     16 * Version: 4.0.3
    1717 */
    1818
  • kama-clic-counter/tags/4.0.3/readme.txt

    r3282892 r3284665  
    1 === Plugin Name ===
     1=== Kama Click Counter ===
    22Stable tag: trunk
    33Tested up to: 6.8.0
     
    4444
    4545== 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.
    4650
    4751= 4.0.2 =
  • kama-clic-counter/tags/4.0.3/src/Counter.php

    r3282892 r3284665  
    55class Counter {
    66
    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 = [
    1212        '?' => '__QUESTION__',
    1313        '&' => '__AMPERSAND__',
     
    1818
    1919    public function __construct( Options $options ) {
    20 
    2120        $this->opt = $options;
    2221    }
    2322
    24     public function init() {
    25 
     23    public function init(): void {
     24//      add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 99 );
    2625        add_action( 'wp_footer', [ $this, 'footer_js' ], 99 );
    27 
    2826        add_filter( 'init', [ $this, 'redirect' ], 0 );
    2927    }
    3028
     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
    3136    /**
    3237     * 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        ] );
    5150        ?>
    5251        <script id="kama-click-counter"><?= $js ?></script>
     
    334333    /**
    335334     * Redirect to link url.
    336      *
    337      * @return void
    338      */
    339     public function redirect() {
     335     */
     336    public function redirect(): void {
    340337
    341338        /**
     
    418415        }
    419416
    420         // remove http, https protocol if it's current site url
     417        // remove http, https protocol if it's the current site url
    421418        if( strpos( $url, $_SERVER['HTTP_HOST'] ) ){
    422419            $url = self::del_http_protocol( $url );
     
    474471
    475472    /**
    476      * Retrieve title of a (local or remote) webpage.
     473     * Retrieve the title of a (local or remote) webpage.
    477474     */
    478475    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!
    13(function(){
    24
     
    79        aclass      : '__aclass__',
    810        questSymbol : '__questSymbol__',
    9         ampSymbol   : '__ampSymbol__'
     11        ampSymbol   : '__ampSymbol__',
    1012    };
    1113
     
    1820        let a = ev.target;
    1921
    20         // test `a[href*="'+ kcckey +'"]` selector
     22        // test `a[href*={kcckey}]` selector
    2123        if( 'A' !== a.tagName || a.href.indexOf( params.kcckey ) === -1 ){
    2224            return;
    2325        }
    2426
    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        }
    2832
    29             if( parseInt( realurl ) ){
    30                 realurl = '/#download' + realurl;
    31             }
     33        if( parseInt( url ) ){
     34            url = '/#download' + url;
     35        }
    3236
    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;
    4340    }
    4441
    4542    function clickEventHandler( ev ){
    46         let a = ev.target.closest( `.${params.aclass}` );
    4743
    48         if( !a || 'A' !== a.tagName ){
     44        let a = ev.target.closest( 'a' );
     45        if( ! a ){
    4946            return;
    5047        }
     
    6663                }
    6764
    68                 a.href = url;
    69                 a.dataset.kccurl = href.replace( url, replaceUrlExtraSymbols( url ) );
     65                a.dataset.kccurl = href.replace( url, replaceExtraSymbols( url ) );
    7066            }
    7167        }
    7268        // count class
    7369        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 ) );
    8174        }
    8275
    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 );
    8485    }
    8586
  • kama-clic-counter/trunk/kama_click_counter.php

    r3282892 r3284665  
    1414 * Requires at least: 5.7
    1515 *
    16  * Version: 4.0.2
     16 * Version: 4.0.3
    1717 */
    1818
  • kama-clic-counter/trunk/readme.txt

    r3282892 r3284665  
    1 === Plugin Name ===
     1=== Kama Click Counter ===
    22Stable tag: trunk
    33Tested up to: 6.8.0
     
    4444
    4545== 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.
    4650
    4751= 4.0.2 =
  • kama-clic-counter/trunk/src/Counter.php

    r3282892 r3284665  
    55class Counter {
    66
    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 = [
    1212        '?' => '__QUESTION__',
    1313        '&' => '__AMPERSAND__',
     
    1818
    1919    public function __construct( Options $options ) {
    20 
    2120        $this->opt = $options;
    2221    }
    2322
    24     public function init() {
    25 
     23    public function init(): void {
     24//      add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ], 99 );
    2625        add_action( 'wp_footer', [ $this, 'footer_js' ], 99 );
    27 
    2826        add_filter( 'init', [ $this, 'redirect' ], 0 );
    2927    }
    3028
     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
    3136    /**
    3237     * 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        ] );
    5150        ?>
    5251        <script id="kama-click-counter"><?= $js ?></script>
     
    334333    /**
    335334     * Redirect to link url.
    336      *
    337      * @return void
    338      */
    339     public function redirect() {
     335     */
     336    public function redirect(): void {
    340337
    341338        /**
     
    418415        }
    419416
    420         // remove http, https protocol if it's current site url
     417        // remove http, https protocol if it's the current site url
    421418        if( strpos( $url, $_SERVER['HTTP_HOST'] ) ){
    422419            $url = self::del_http_protocol( $url );
     
    474471
    475472    /**
    476      * Retrieve title of a (local or remote) webpage.
     473     * Retrieve the title of a (local or remote) webpage.
    477474     */
    478475    private function get_html_title( string $url ): string {
Note: See TracChangeset for help on using the changeset viewer.