Plugin Directory

Changeset 3282892


Ignore:
Timestamp:
04/27/2025 07:39:58 PM (10 months ago)
Author:
Tkama
Message:

Update to version 4.0.2 from GitHub

Location:
kama-clic-counter
Files:
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • kama-clic-counter/tags/4.0.2/admin/pages/_edit-link.php

    r3056424 r3282892  
    11<?php
    2 
    32namespace KamaClickCounter;
    43
     
    76/**
    87 * @var Admin $this
     8 * @var int $edit_link_id
    99 */
    1010
    1111global $wpdb;
    1212
    13 $link = $wpdb->get_row( "SELECT * FROM $wpdb->kcc_clicks WHERE link_id = " . (int) $edit_link_id );
     13$link = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->kcc_clicks WHERE link_id = %d", $edit_link_id ) );
    1414
    1515if( ! $link ){
     
    4646    <input type="hidden" name="local_referer" value="<?= esc_attr($referer) ?>" />
    4747
    48     <img style="position:absolute; top:-10px; right:350px; width:70px; width:50px;" src="<?= $icon_link ?>" />
     48    <img style="position:absolute; top:-10px; right:350px; width:70px; height:50px;" src="<?= $icon_link ?>"  alt=""/>
    4949    <p>
    5050        <input type="number" style="width:100px;" name="up[link_clicks]" value='<?= esc_attr( $link->link_clicks ) ?>' /> <?php printf( __('Clicks. Per day: %s', 'kama-clic-counter'), ($var=get_clicks_per_day($link)) ? $var : 0 ) ?></p>
     
    6262    </p>
    6363    <p>
    64         <input type="text" style="width:600px;" name="up[link_url]" value="<?= esc_attr( $link->link_url ) ?>" readonly="readonly" /> <a href="#" style="margin-top:.5em; font-size:110%;" class="dashicons dashicons-edit" onclick="var $the = jQuery(this); $the.parent().find('input').removeAttr('readonly').focus(); $the.remove();"></a> <?php _e('Link to file', 'kama-clic-counter') ?>
     64        <input type="text" style="width:600px;" name="up[link_url]" value="<?= esc_attr( $link->link_url ) ?>" readonly="readonly" />
     65        <a href="#" style="margin-top:.5em; font-size:110%;" class="dashicons dashicons-edit"
     66           onclick="const $the = jQuery(this) $the.parent().find('input').removeAttr('readonly').focus(); $the.remove();"
     67        ></a>
     68        <?php _e('Link to file', 'kama-clic-counter') ?>
    6569    </p>
    6670    <p>
  • kama-clic-counter/tags/4.0.2/kama_click_counter.php

    r3167383 r3282892  
    22/**
    33 * Plugin Name: Kama Click Counter
    4  * Description: Count clicks on any link all over the site. Creates beautiful file download block in post content - use shortcode [download url="any file URL"]. Has widget of top clicks/downloads.
     4 * Description: Counts clicks on any link across the entire site. Creates a beautiful file download block in post content using the shortcode `[download url="any file URL"]`. Includes a widget for top clicks/downloads.
    55 *
    66 * Text Domain: kama-clic-counter
     
    1111 * Plugin URI: https://wp-kama.com/77
    1212 *
    13  * Requires PHP: 7.0
     13 * Requires PHP: 7.1
    1414 * Requires at least: 5.7
    1515 *
    16  * Version: 4.0.1
     16 * Version: 4.0.2
    1717 */
    1818
     
    2626register_activation_hook( __FILE__, [ plugin(), 'activation' ] );
    2727
    28 add_action( 'plugins_loaded', [ plugin(), 'init' ] );
     28/**
     29 * NOTE: Init the plugin later on the 'after_setup_theme' hook to
     30 * run current_user_can() later to avoid possible conflicts.
     31 */
     32add_action( 'after_setup_theme', [ plugin(), 'init' ] );
    2933
    3034function plugin(): Plugin {
  • kama-clic-counter/tags/4.0.2/readme.txt

    r3167383 r3282892  
    1 
    21=== Plugin Name ===
    32Stable tag: trunk
    4 Tested up to: 6.6.2
     3Tested up to: 6.8.0
    54Contributors: Tkama
    65Tags: analytics, statistics, count clicks, counter
     
    87License URI: http://www.gnu.org/licenses/gpl-2.0.html
    98
    10 Count clicks on any link all over the site. Creates beautiful file download block in post content. Has top downloads' widget.
     9Count clicks on any link across the site. Creates a beautiful file download block in post content. Includes a widget for top downloads.
     10
    1111
    1212
    1313== Description ==
    1414
    15 Using this plugin you will have statistics on clicks on file download or any other link all over the site.
    16 
    17 To insert file download block use `[download url="any file URL"]` shortcode.
    18 
    19 Plugin don't have any additional instruments to uploads files. All files uploaded using standard wordpress media uploader. To create download block URL are used.
    20 
    21 In additional, plugin has:
    22 
    23 * Button in visual editor to fast insert file download block shortcode.
    24 * Customizable widget, that allows output a list of "Top Downloads" or "Top link Clicks".
     15With this plugin, you can gather statistics on clicks for file downloads or any other link across the site.
     16
     17To insert a file download block, use the `[download url="any file URL"]` shortcode.
     18
     19The plugin does not include additional tools for uploading files. All files must be uploaded using the standard WordPress media uploader. The URLs are then used to create the download block.
     20
     21Additionally, the plugin includes:
     22
     23* A button in the visual editor for quickly inserting the file download block shortcode.
     24* A customizable widget that allows you to display a list of "Top Downloads" or "Top Link Clicks."
    2525
    2626
     
    2828== Frequently Asked Questions ==
    2929
    30 = How can I customize download block with CSS? =
    31 
    32 Just customize CSS styles in plugin options page. Also you can add css styles into 'style.css' file of your theme.
     30= How can I customize the download block with CSS? =
     31
     32You can customize CSS styles on the plugin options page. Alternatively, you can add CSS styles to the `style.css` file of your theme.
    3333
    3434
     
    39392. Plugin settings page.
    40403. Single link edit page.
    41 4. TinyMce visual editor downloads button.
     414. TinyMCE visual editor downloads button.
    4242
    4343
     
    4545== Changelog ==
    4646
     47= 4.0.2 =
     48- CHG: Min PHP version 7.0 >> 7.1.
     49- FIX: Plugin `init` moved to `after_setup_theme` hook to avoid some conflicts.
     50- IMP: minor improvements.
     51- UPD: Tested up to: WP 6.8.0
     52
    4753= 4.0.1 =
    48 * FIX: Bugfix in "counter.js" script.
     54* FIX: Bug in `counter.js` script.
    4955
    5056= 4.0.0 =
    51 * Requires PHP >= 7.0.
    52 * Backcompat removed.
    53 * Code refactored.
    54 * PHP class autoloader added.
    55 * PHP namespaces added.
    56 * Filter `kcc_admin_access` renamed to `kcc_manage_access`.
    57 * Filter `parce_kcc_url` renamed to `click_counter__parse_kcc_url`.
    58 * Filter `get_url_icon` renamed to `click_counter__get_icon_url`.
     57* CHG: Requires PHP >= 7.0.
     58* DEL: Removed backcompat code.
     59* IMP: Code refactored.
     60* ADD: PHP class autoloader.
     61* ADD: PHP namespaces.
     62* CHG: Filter `kcc_admin_access` renamed to `kcc_manage_access`.
     63* CHG: Filter `parce_kcc_url` renamed to `click_counter__parse_kcc_url`.
     64* CHG: Filter `get_url_icon` renamed to `click_counter__get_icon_url`.
    5965
    6066= 3.6.10 =
    61 * Minor improvemets.
     67* IMP: Minor improvements.
    6268
    6369= 3.6.9 =
    64 * A little performance improvements and no jQuery dependence for base count js.
     70* IMP: Performance improvements; no jQuery dependency for base count JS.
    6571
    6672= 3.6.8.2 =
    67 * BUG: some bug in previous version.
     73* FIX: Bug in previous version.
    6874
    6975= 3.6.8.1 =
    70 * BUG: previously, the Protocol for external links was removed (leaved //).
    71 * FIX: compatibility with PHP 7.4
     76* FIX: Protocol for external links issue (leaving `//`).
     77* FIX: Compatibility with PHP 7.4.
    7278
    7379= 3.6.8 =
    74 * BUG: wrong count of URL with query parameters. Code improved!
    75 * BUG: in widget loop.
    76 * FIX: other minor fixes.
     80* FIX: Wrong URL count with query parameters.
     81* FIX: Bug in widget loop.
     82* FIX: Other minor fixes.
    7783
    7884= 3.6.7.3 =
    79 * FIX: wrong `<title>` parsing in some cases.
     85* FIX: `<title>` parsing issue.
    8086
    8187= 3.6.7 =
    82 * FIX: bug with wrong counting when 'hide link under id' option is enadled.
    83 * FIX: minor code fixes
    84 
     88* FIX: Wrong counting with "hide link under id" option enabled.
     89* FIX: Minor code fixes.
    8590
    8691= 3.6.6 =
    87 * FIX: access_role option not saved.
    88 * ADD: desc attr to shortcode.
     92* FIX: `access_role` option not saved.
     93* ADD: `desc` attribute to shortcode.
    8994
    9095= 3.6.5 =
    91 * FIX: because of missing http protocol, filesize was parsed incorrect sometimes (not parsed).
     96* FIX: Filesize parsing issue due to missing HTTP protocol.
    9297
    9398= 3.6.4.2 =
    94 * CHG: Download block HTML markup and css styles changed a little - nothing important...
     99* CHG: Minor changes to download block HTML markup and CSS styles.
    95100
    96101= 3.6.4 =
    97 * ADD: urldecode for incoming URLs writing to DB. Thank to Mark Carson!
    98 * NEW: Exclude url counting filter. See options page.
     102* ADD: `urldecode` for incoming URLs when saving to DB. Thanks to Mark Carson.
     103* NEW: Exclude URL counting filter added (see options page).
    99104
    100105= 3.6.3 =
    101 * FIX: esc_url for wp_redirect() to avoid spaces deletion. Thank to Mark Carson!
     106* FIX: `esc_url()` for `wp_redirect()` to avoid spaces deletion. Thanks to Mark Carson.
    102107
    103108= 3.6.2 =
    104 * ADD: 'in_post' field on edit link admin page. It allow change ID of the post where link is...
    105 * ADD: sanitize data on edit link POST request
    106 * NEW: now all url in database saves as no protocol url - //site.ru/foo. So click on url 'http://site.ru/foo' and click on 'https://site.ru/foo' will be counted in one place.
    107 * FIX: search in admin list worked incorrectly if we begun search from pagination page...
    108 * FIX: correct detection of urls without protocol - //site.ru/foo
    109 * FIX: correct title detection of urls without protocol - //site.ru/foo. Now uses WP HTTP API to retrive external html of link...
    110 * FIX: some minor bug fixes
     109* ADD: `in_post` field on edit link admin page to change associated post ID.
     110* ADD: Sanitize data on edit link POST request.
     111* NEW: Save URLs without protocol (`//site.ru/foo`).
     112* FIX: Admin list search starting from pagination page.
     113* FIX: Detection of URLs without protocol.
     114* FIX: Title detection for protocol-less URLs using WP HTTP API.
     115* FIX: Minor bug fixes.
    111116
    112117= 3.6.1 =
    113 * ADD: 'title' attribute to [download] shortcode. Ex: [download url="URL" title="my file title"]
    114 * ADD: improve tinymce button insert shortcode modal window - now you can find files in media library.
    115 * FIX: It just counted the clicks done with the left-click-mouse-button and not counted clicks with the mouse-wheel and not with "open link..." from context menu opened with right-mouse-click.
    116 
     118* ADD: `title` attribute for `[download]` shortcode.
     119* ADD: Improved TinyMCE button modal window (browse media library).
     120* FIX: Count clicks from mouse wheel and context menu.
    117121
    118122= 3.6.0 =
    119 * CHG: class name 'KCClick' changed to 'KCCounter'. If you have external code for this plugin, change in it all 'KCClick::' or 'KCC::' to 'KCCounter::'!!!
    120 * CHG: Icon in Tinymce visual editor
     123* CHG: Class name `KCClick` changed to `KCCounter`.
     124* CHG: Icon in TinyMCE visual editor updated.
    121125
    122126= 3.5.1 =
    123 * CHG: move localisation to translate.wordpress.org
    124 * FIX: minor code fix
     127* CHG: Move localization to translate.wordpress.org.
     128* FIX: Minor code fix.
    125129
    126130= 3.5.0 =
    127 * FIX: XSS valneruble
    128 * CHG: Change class name 'KCC' to 'KCClick'
    129 * CHG: Translate PHP code to english. Now Russian is localization file...
     131* FIX: XSS vulnerability fixed.
     132* CHG: Class name `KCC` changed to `KCClick`.
     133* CHG: Translate PHP code to English (Russian moved to localization file).
    130134
    131135= 3.4.9 =
    132 * FIX: Remove link from Admin-bar for Roles who has no plugin access
     136* FIX: Remove admin-bar link for roles without plugin access.
    133137
    134138= 3.4.8 =
    135 * ADD: "click per day" data to edit link screen
     139* ADD: "Clicks per day" data on edit link screen.
    136140
    137141= 3.4.7 - 3.4.7.3 =
    138 * FIX: table structure to work fine with 'utf8mb4_unicode_ci' charset
     142* FIX: Table structure to support `utf8mb4_unicode_ci` charset.
    139143
    140144= 3.4.6 =
    141 * ADD: 'get_url_icon' filter to manage icons.
     145* ADD: `get_url_icon` filter to manage icons.
    142146
    143147= 3.4.5 =
    144 * ADD: Administrator option to set access to plugin to other WP roles.
    145 * ADD: Option to add link to KCC Stat in admin bar.
    146 * DEL: no HTTP_REFERER block on direct kcc url use.
     148* ADD: Administrator option to assign plugin access to other WP roles.
     149* ADD: Option to add KCC Stats link to admin bar.
     150* DEL: Removed `HTTP_REFERER` block on direct KCC URL use.
    147151
    148152= 3.4.4 =
    149 * CHANGE: is_file extention check method for url.
    150 * ADD: 'kcc_is_file' filter
    151 * ADD: widget option to set link to post instead of link to file
    152 * REMOVED: 'kcc_file_ext' filter
     153* CHG: `is_file` extension check method for URL.
     154* ADD: `kcc_is_file` filter.
     155* ADD: Widget option to set link to post instead of file.
     156* DEL: Removed `kcc_file_ext` filter.
    153157
    154158= 3.4.3 =
    155 * ADD hooks: 'parce_kcc_url', 'kcc_count_before', 'kcc_count_after'.
    156 * ADD: second parametr '$args' to 'kcc_insert_link_data' filter.
    157 * ADD: punycode support. Now links filter in admin table trying to find keyword in 'link_name' db column too, not only in 'link_url'.
    158 * FIX: It just count the clicks done with the left-click mouse button. Doesn't count clicks done with the mouse wheel, which opens in new tab. Also doesn't count clicks from mobile browsers. left click, mouse wheel, ctrl + left click, touch clicks (I test it in iphone – chrome and safari)
     159* ADD: Hooks `parce_kcc_url`, `kcc_count_before`, `kcc_count_after`.
     160* ADD: Second parameter `$args` to `kcc_insert_link_data` filter.
     161* ADD: Punycode support for link filtering.
     162* FIX: Count clicks from mouse wheel, touch, and ctrl+click.
    159163
    160164= 3.4.2 =
    161 * ADD: 'kcc_admin_access' filter. For possibility to change access capability.
    162 * FIX: redirect protection fix.
     165* ADD: `kcc_admin_access` filter to change access capability.
     166* FIX: Redirect protection fix.
    163167
    164168= 3.4.1 =
    165 * FIX: parse kcc url fix.
     169* FIX: KCC URL parsing issue.
    166170
    167171= 3.4.0 =
    168 * ADD: Hide url in download block option. See the options page.
    169 * ADD: 'link_url' column index in DB for faster plugin work.
    170 * ADD: 'get_kcc_url', 'kcc_redefine_redirect', 'kcc_file_ext', 'kcc_insert_link_data' hooks.
    171 * ADD: Now plugin replace its ugly URL with original URL, when link hover.
    172 * ADD: Replace 'edit link' text for download block to icon. It's more convenient.
    173 * FIX: Correct updates of existing URLs. In some cases there appeared duplicates, when link contain '%' symbol (it could be cyrillic url or so on...)
    174 * FIX: XSS attack protection.
    175 * FIX: Many structure fix in code.
    176 
     172* ADD: Option to hide URL in download block.
     173* ADD: `link_url` column index in DB for performance.
     174* ADD: Hooks `get_kcc_url`, `kcc_redefine_redirect`, `kcc_file_ext`, `kcc_insert_link_data`.
     175* ADD: Replace ugly URL with original URL on hover.
     176* ADD: Replace "edit link" text in download block with icon.
     177* FIX: Duplicate URL updates (e.g., containing `%` symbol).
     178* FIX: XSS protection added.
     179* FIX: Code structure fixes.
    177180
    178181= 3.3.2 =
    179 * FIX: php notice
     182* FIX: PHP notice.
    180183
    181184= 3.3.1 =
    182 * ADD: de_DE l10n, thanks to Volker Typke.
     185* ADD: `de_DE` localization. Thanks to Volker Typke.
    183186
    184187= 3.3.0 =
    185 * ADD: l10n on plugin page.
    186 * ADD: menu to admin page.
    187 * FIX: antivirus wrongly says that file infected.
     188* ADD: Localization on plugin page.
     189* ADD: Menu to admin page.
     190* FIX: Antivirus false positive detection.
    188191
    189192= 3.2.34 =
    190 * FIX: Some admin css change
     193* FIX: Admin CSS changes.
    191194
    192195= 3.2.3.3 =
    193 * ADD: jQuery links become hidden. All jQuery affected links have #kcc anchor and onclick attr with countclick url
    194 * FIX: error with parse_url part. If url had "=" it was exploded...
     196* ADD: jQuery links now hidden with `#kcc` anchor and `onclick` attribute.
     197* FIX: `parse_url` bug when URL contained "=" character.
    195198
    196199= 3.2.3.2 =
    197 * FIX: didn't correctly redirected to url with " " character
    198 * ADD: round "clicks per day" on admin statistics page to one decimal digit
     200* FIX: Redirect to URL with space (`" "`) character.
     201* ADD: Round "clicks per day" value to one decimal on admin stats page.
    199202
    200203= 3.2.3.1 =
    201 * FIX: "back to stat" link on "edit link" admin page
     204* FIX: "Back to stat" link on "edit link" admin page.
    202205
    203206= 3.2.3 =
    204 * FIX: redirects to https doesn't worked correctly
    205 * FIX: PHP less than 5.3 support
    206 * FIX: go back button on "edit link" admin page
    207 * FIX: localization
     207* FIX: Redirects to HTTPS were not working correctly.
     208* FIX: PHP < 5.3 support.
     209* FIX: "Go back" button on "edit link" admin page.
     210* FIX: Localization issues.
    208211
    209212= 3.2.2 =
    210 * ADD: "go back" button on "edit link" admin page
     213* ADD: "Go back" button on "edit link" admin page.
    211214
    212215= 3.2.1 =
    213 Set autoreplace old shortcodes to new in DB during update: [download=""] [download url=""]
     216* CHG: Auto-replace old shortcodes `[download=""]` with `[download url=""]` in DB during update.
    214217
    215218= 3.2 =
    216 Widget has been added
     219* ADD: Widget feature.
     220
  • kama-clic-counter/tags/4.0.2/src/Admin.php

    r3056424 r3282892  
    3333    }
    3434
    35     public function upgrade(){
     35    public function upgrade() {
    3636        $upgrader = new Upgrader();
    3737        $upgrader->init();
     
    4242     * For WP hook.
    4343     */
    44     public function plugins_page_links( $actions ){
     44    public function plugins_page_links( $actions ) {
    4545
    4646        $actions[] = sprintf( '<a href="%s">%s</a>', $this->admin_page_url( 'settings' ), __( 'Settings', 'kama-clic-counter' ) );
     
    5050    }
    5151
    52     public function admin_menu(){
     52    public function admin_menu() {
    5353
    5454        // just in case
     
    6969    }
    7070
    71     public function admin_page_load(){
     71    public function admin_page_load() {
    7272
    7373        // just in case...
     
    9696                is_string( $val ) && $val = trim( $val );
    9797
    98                 if( $key === 'download_tpl' ){} // no sanitize... wp_kses($val, 'post');
    99                 elseif( $key === 'url_exclude_patterns' ){} // no sanitize...
     98                if( $key === 'download_tpl' ){
     99                    // no sanitize...
     100                }
     101                elseif( $key === 'url_exclude_patterns' ){
     102                    // no sanitize... wp_kses($val, 'post');
     103                }
     104                // no sanitize...
    100105                elseif( is_array( $val ) ){
    101106                    $val = array_map( 'sanitize_key', $val );
     
    136141
    137142            $data = wp_unslash( $_POST['up'] );
    138             $id   = (int) $data['link_id'];
     143            $id = (int) $data['link_id'];
    139144
    140145            // очистка
     
    210215     * Callback for {@see add_options_page()} function parameter.
    211216     */
    212     public function options_page_output(){
     217    public function options_page_output() {
    213218        include plugin()->dir . '/admin/pages/admin.php';
    214219    }
    215220
    216221    /**
    217      * @param int   $link_id
    218      * @param array $data
    219      *
    220222     * @return int|false
    221223     */
    222     private function update_link( $link_id, $data ) {
    223         global $wpdb;
    224 
    225         $link_id = (int) $link_id;
     224    private function update_link( int $link_id, array $data ) {
     225        global $wpdb;
     226
    226227        if( $link_id ){
    227228            $query = $wpdb->update( $wpdb->kcc_clicks, $data, [ 'link_id' => $link_id ] );
     
    243244
    244245    public function delete_link_url( $link_id ): string {
    245         return add_query_arg( [ 'delete_link' => $link_id, '_wpnonce' =>wp_create_nonce('delete_link') ] );
     246        return add_query_arg( [ 'delete_link' => $link_id, '_wpnonce' => wp_create_nonce( 'delete_link' ) ] );
    246247    }
    247248
     
    249250     * Deleting links from the database by passed array ID or link ID.
    250251     *
    251      * @param  array|int $array_ids IDs of links to be deleted.
     252     * @param array|int $array_ids IDs of links to be deleted.
    252253     */
    253254    private function delete_links( $array_ids = [] ): bool {
     
    263264    }
    264265
    265     public function delete_link_by_attach_id( $attach_id ){
     266    public function delete_link_by_attach_id( $attach_id ) {
    266267        global $wpdb;
    267268
     
    276277     * Update the link if the attachment is updated.
    277278     */
    278     public function update_link_with_attach( $attach_id ){
     279    public function update_link_with_attach( $attach_id ) {
    279280        global $wpdb;
    280281
  • kama-clic-counter/tags/4.0.2/src/Content_Replacer.php

    r3056424 r3282892  
    55class Content_Replacer {
    66
    7     public function __construct(){
     7    public function __construct() {
    88    }
    99
    10     public function init(){
     10    public function init() {
    1111
    1212        if( plugin()->opt->links_class ){
     
    4545        foreach( $args[0] as $pair ){
    4646            list( $tag, $value ) = explode( '=', $pair, 2 );
    47             $value = trim( trim($value, '"\'') );
    48             $args[ trim($tag) ] = $value;
     47            $value = trim( trim( $value, '"\'' ) );
     48            $args[ trim( $tag ) ] = $value;
    4949        }
    5050        unset( $args[0], $args[1] );
    5151
    5252        $after = '';
    53         $args[ 'data-'. Counter::PID_KEY ] = $post->ID;
     53        $args[ 'data-' . Counter::PID_KEY ] = $post->ID;
    5454        if( plugin()->opt->add_hits ){
    5555            $link = plugin()->counter->get_link( $args['href'] );
  • kama-clic-counter/tags/4.0.2/src/Counter.php

    r3167383 r3282892  
    1717    public $opt;
    1818
    19     public function __construct( Options $options ){
     19    public function __construct( Options $options ) {
    2020
    2121        $this->opt = $options;
     
    9595     * Hides the original link under the link ID. The link must exist in the database.
    9696     *
    97      * @param string $kcc_url Plugin formated URL of the link counting.
     97     * @param string $kcc_url  Plugin formated URL of the link counting.
    9898     *
    9999     * @return string URL with a hidden link.
     
    368368            else{
    369369                trigger_error( sprintf( 'Error: kcc link with id %s not found.', $url ) );
     370
    370371                return;
    371372            }
     
    399400
    400401        // cut URL from $query, because - there could be query args (&) that is why cut it
    401         $split = preg_split( '/[&?]?'. self::COUNT_KEY .'=/', $kcc_query );
     402        $split = preg_split( '/[&?]?' . self::COUNT_KEY . '=/', $kcc_query );
    402403        $query = $split[0];
    403         $url   = self::replace_url_placeholders( $split[1] ); // can be base64 encoded
     404        $url = self::replace_url_placeholders( $split[1] ); // can be base64 encoded
    404405
    405406        if( ! $url ){
     
    427428            ! is_numeric( $url )
    428429            && $url[0] !== '/'
    429             && ! preg_match( '~^(?:' . implode( '|', wp_allowed_protocols() ) . '):~', $url )
    430         ) {
     430            && ! preg_match( '~^(' . implode( '|', wp_allowed_protocols() ) . '):~', $url )
     431        ){
    431432            return [];
    432433        }
    433434
    434435        $return = [
    435             self::COUNT_KEY => $url, // no esc_url()
     436            self::COUNT_KEY => $url, // !!! no esc_url()
    436437            self::PID_KEY   => (int) ( $query_args[ self::PID_KEY ] ?? 0 ),
    437438            // array_key_exists( 'download', $query_args ), // isset null не берет
     
    442443    }
    443444
    444     public static function del_http_protocol( $url ){
     445    public static function del_http_protocol( $url ) {
    445446        return preg_replace( '/https?:/', '', $url );
    446447    }
    447448
    448     private function is_file( $url ){
     449    private function is_file( $url ) {
    449450        /**
    450451         * Allows to repalce {@see Counter::is_file()} method.
     
    537538        $i = 0;
    538539        $type = [ "B", "KB", "MB", "GB" ];
    539         while( ( $size/1024 ) > 1 ){
    540             $size = $size/1024;
     540        while( ( $size / 1024 ) > 1 ){
     541            $size = $size / 1024;
    541542            $i++;
    542543        }
     
    548549     * Returns the size of a file without downloading it.
    549550     *
    550      * @param string $url The location of the remote file to download. Cannot be null or empty.
     551     * @param string $url  The location of the remote file to download. Cannot be null or empty.
    551552     *
    552553     * @return int The size of the file referenced by $url, or 0 if the size could not be determined.
  • kama-clic-counter/tags/4.0.2/src/Download_Shortcode.php

    r3056424 r3282892  
    55class Download_Shortcode {
    66
    7     public function __construct(){
     7    public function __construct() {
    88    }
    99
    10     public function init(){
     10    public function init() {
    1111        add_shortcode( 'download', [ $this, 'download_shortcode' ] );
    1212    }
  • kama-clic-counter/tags/4.0.2/src/Helpers.php

    r3056424 r3282892  
    66
    77    /**
    8      * @param string $message Message HTML.
    9      * @param string $type    Allowed: success | error | warning | info.
     8     * @param string $message HTML.
     9     * @param string $type     One of: success|error|warning|info.
    1010     */
    1111    public static function notice_message( string $message, string $type = 'warning' ) {
    1212
    13         add_action(
    14             'admin_notices',
    15             function () use ( $message, $type ) {
    16                 ?>
    17                 <div id="message" class="notice <?= esc_attr( "notice-$type" ) ?>">
    18                     <p><?= wp_kses_post( $message ) ?></p>
    19                 </div>
    20                 <?php
    21             }
    22         );
     13        add_action( 'admin_notices', function() use ( $message, $type ) {
     14            ?>
     15            <div id="message" class="notice <?= esc_attr( "notice-$type" ) ?>">
     16                <p><?= wp_kses_post( $message ) ?></p>
     17            </div>
     18            <?php
     19        } );
    2320    }
    2421
     
    2623     * Gets a link to the icon image by the extension in the passed URL.
    2724     *
    28      * @param $link_url
    29      *
    3025     * @return mixed|null
    3126     */
    32     public static function get_icon_url( $link_url ){
     27    public static function get_icon_url( $link_url ) {
    3328
    3429        $url_path = parse_url( $link_url, PHP_URL_PATH );
     
    3732            $icon_name = $m[1] . '.png';
    3833        }
    39         else{
     34        else {
    4035            $icon_name = 'default.png';
    4136        }
  • kama-clic-counter/tags/4.0.2/src/Options.php

    r3056424 r3282892  
    4949        ',
    5050        // css class for links in content (if not specified, this functionality is disabled).
    51         'links_class' => 'count',
     51        'links_class'          => 'count',
    5252        // may be: '', 'in_title' or 'in_plain' (for simple links)
    5353        'add_hits'             => '',
  • kama-clic-counter/tags/4.0.2/src/Plugin.php

    r3056424 r3282892  
    4242
    4343    public function __construct( string $main_file_path ) {
    44 
    4544        $this->set_wpdb_tables();
    4645
     
    5049        $this->url = plugins_url( '', $main_file_path );
    5150
    52         $this->info = get_file_data(
    53             $main_file_path,
    54             [
    55                 'name'    => 'Plugin Name',
    56                 'version' => 'Version',
    57                 'php_ver' => 'Requires PHP',
    58             ]
    59         );
     51        $this->info = get_file_data( $main_file_path, [
     52            'name'    => 'Plugin Name',
     53            'version' => 'Version',
     54            'php_ver' => 'Requires PHP',
     55        ] );
    6056
    6157        $this->opt = new Options();
    6258    }
    6359
    64     /**
    65      * The plugin initialization. Performs on `plugins_loaded` hook.
    66      *
    67      * @return void
    68      */
    69     public function init() {
     60    public function init(): void {
    7061
    71         if ( ! $this->check_dependencies() ) {
     62        if( ! $this->check_dependencies() ){
    7263            return;
    7364        }
     
    10798    }
    10899
    109     /**
    110      * @return void
    111      */
    112     private function set_admin_access() {
     100    private function set_admin_access(): void {
    113101        $this->admin_access = current_user_can( 'manage_options' );
    114102    }
    115103
    116     /**
    117      * @return void
    118      */
    119     private function set_manage_access() {
     104    private function set_manage_access(): void {
    120105
    121106        $this->manage_access = apply_filters( 'kcc_manage_access', null );
     
    139124    }
    140125
    141     public function add_toolbar_menu( $toolbar ){
     126    public function add_toolbar_menu( $toolbar ) {
    142127
    143128        $toolbar->add_menu( [
     
    149134
    150135    public function check_dependencies(): bool {
    151 
    152         if ( version_compare( PHP_VERSION, $this->info['php_ver'], '<=' ) ) {
    153 
     136        if( version_compare( PHP_VERSION, $this->info['php_ver'], '<=' ) ){
    154137            Helpers::notice_message(
    155138                '<b>Kama Click Counter</b> plugin requires PHP version <b>' . $this->info['php_ver'] . '</b> or higher. Please upgrade PHP or diactivate the plugin.',
     
    163146    }
    164147
    165     public function activation(){
     148    public function activation() {
    166149        global $wpdb;
    167150
    168         if ( ! $this->check_dependencies() ) {
     151        if( ! $this->check_dependencies() ){
    169152            return;
    170153        }
  • kama-clic-counter/tags/4.0.2/src/TinyMCE.php

    r3056424 r3282892  
    2121
    2222    public static function register_buttons( $buttons ) {
    23         $last      = array_pop( $buttons );
     23        $last = array_pop( $buttons );
    2424        $buttons[] = 'kcc';
    2525        $buttons[] = $last;
  • kama-clic-counter/tags/4.0.2/src/Upgrader.php

    r3056424 r3282892  
    2222    private $db_fields;
    2323
    24     public function __construct(){
    25         $this->is_force_upgrade = isset( $_GET['kcc_force_upgrade'] );
     24    public function __construct() {
     25        $this->is_force_upgrade = isset( $_GET['kcc_force_upgrade'] );
    2626
    27         $this->prev_ver = $this->is_force_upgrade ? '1.0' : get_option( self::OPTION_NAME, '1.0' );
    28         $this->curr_ver = plugin()->info['version'];
     27        $this->prev_ver = $this->is_force_upgrade ? '1.0' : get_option( self::OPTION_NAME, '1.0' );
     28        $this->curr_ver = plugin()->info['version'];
    2929    }
    3030
     
    5050            exit;
    5151        }
    52 
    5352    }
    5453
  • kama-clic-counter/tags/4.0.2/src/Widget.php

    r3056424 r3282892  
    1313    }
    1414
    15     public static function init(){
     15    public static function init() {
    1616
    1717        if( ! plugin()->opt->widget ){
     
    1919        }
    2020
    21         add_action( 'widgets_init', function () {
     21        add_action( 'widgets_init', function() {
    2222            register_widget( self::class );
    2323        } );
     
    125125     * Admin part of the widget
    126126     */
    127     public function form( $instance ){
    128 
    129         $title        = @ $instance['title']     ? $instance[ 'title' ]     : __('Top Downloads', 'kama-clic-counter' );
    130         $number       = @ $instance['number']    ? $instance[ 'number' ]    : 5;
    131         $last_date    = @ $instance['last_date'] ? $instance[ 'last_date' ] : '';
    132         $template_css = @ $instance['template_css']
    133             ? $instance[ 'template_css' ]
    134             : preg_replace(
    135                 '~^\t+~m', '', '.kcc_widget{ padding:15px; }
    136                 .kcc_widget li{ margin-bottom:10px; list-style: none; }
    137                 .kcc_widget li:after{ content:""; display:table; clear:both; }
    138                 .kcc_widget img{ width:30px; float:left; margin:5px 10px 5px 0; }
    139                 .kcc_widget p{ margin-left:40px; }'
    140             );
    141 
    142         $template = @ $instance['template']
    143             ? $instance['template']
    144             : '<img src="[icon_url]" alt="" />' . "\n"
    145                . '<a href="[link_url]">[link_title]</a> ([link_clicks])' . "\n"
    146                . '<p>[link_description]</p>';
     127    public function form( $instance ) {
     128
     129        $default_template_css = '
     130            .kcc_widget{ padding:15px; }
     131            .kcc_widget li{ margin-bottom:10px; list-style: none; }
     132            .kcc_widget li:after{ content:""; display:table; clear:both; }
     133            .kcc_widget img{ width:30px; float:left; margin:5px 10px 5px 0; }
     134            .kcc_widget p{ margin-left:40px; }
     135        ';
     136
     137        $default_template = '
     138            <img src="[icon_url]" alt="" />
     139            <a href="[link_url]">[link_title]</a> ([link_clicks])
     140            <p>[link_description]</p>
     141        ';
     142
     143        $title        = $instance['title'] ?? __( 'Top Downloads', 'kama-clic-counter' );
     144        $number       = $instance['number'] ?? 5;
     145        $last_date    = $instance['last_date'] ?? '';
     146        $template_css = $instance['template_css'] ?? preg_replace( '~^\t+~m', '', trim( $default_template_css ) );
     147        $template     = $instance['template'] ?? preg_replace( '~^\t+~m', '', trim( $default_template ) );
    147148        ?>
    148149        <p>
  • kama-clic-counter/trunk/admin/pages/_edit-link.php

    r3056424 r3282892  
    11<?php
    2 
    32namespace KamaClickCounter;
    43
     
    76/**
    87 * @var Admin $this
     8 * @var int $edit_link_id
    99 */
    1010
    1111global $wpdb;
    1212
    13 $link = $wpdb->get_row( "SELECT * FROM $wpdb->kcc_clicks WHERE link_id = " . (int) $edit_link_id );
     13$link = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->kcc_clicks WHERE link_id = %d", $edit_link_id ) );
    1414
    1515if( ! $link ){
     
    4646    <input type="hidden" name="local_referer" value="<?= esc_attr($referer) ?>" />
    4747
    48     <img style="position:absolute; top:-10px; right:350px; width:70px; width:50px;" src="<?= $icon_link ?>" />
     48    <img style="position:absolute; top:-10px; right:350px; width:70px; height:50px;" src="<?= $icon_link ?>"  alt=""/>
    4949    <p>
    5050        <input type="number" style="width:100px;" name="up[link_clicks]" value='<?= esc_attr( $link->link_clicks ) ?>' /> <?php printf( __('Clicks. Per day: %s', 'kama-clic-counter'), ($var=get_clicks_per_day($link)) ? $var : 0 ) ?></p>
     
    6262    </p>
    6363    <p>
    64         <input type="text" style="width:600px;" name="up[link_url]" value="<?= esc_attr( $link->link_url ) ?>" readonly="readonly" /> <a href="#" style="margin-top:.5em; font-size:110%;" class="dashicons dashicons-edit" onclick="var $the = jQuery(this); $the.parent().find('input').removeAttr('readonly').focus(); $the.remove();"></a> <?php _e('Link to file', 'kama-clic-counter') ?>
     64        <input type="text" style="width:600px;" name="up[link_url]" value="<?= esc_attr( $link->link_url ) ?>" readonly="readonly" />
     65        <a href="#" style="margin-top:.5em; font-size:110%;" class="dashicons dashicons-edit"
     66           onclick="const $the = jQuery(this) $the.parent().find('input').removeAttr('readonly').focus(); $the.remove();"
     67        ></a>
     68        <?php _e('Link to file', 'kama-clic-counter') ?>
    6569    </p>
    6670    <p>
  • kama-clic-counter/trunk/kama_click_counter.php

    r3167383 r3282892  
    22/**
    33 * Plugin Name: Kama Click Counter
    4  * Description: Count clicks on any link all over the site. Creates beautiful file download block in post content - use shortcode [download url="any file URL"]. Has widget of top clicks/downloads.
     4 * Description: Counts clicks on any link across the entire site. Creates a beautiful file download block in post content using the shortcode `[download url="any file URL"]`. Includes a widget for top clicks/downloads.
    55 *
    66 * Text Domain: kama-clic-counter
     
    1111 * Plugin URI: https://wp-kama.com/77
    1212 *
    13  * Requires PHP: 7.0
     13 * Requires PHP: 7.1
    1414 * Requires at least: 5.7
    1515 *
    16  * Version: 4.0.1
     16 * Version: 4.0.2
    1717 */
    1818
     
    2626register_activation_hook( __FILE__, [ plugin(), 'activation' ] );
    2727
    28 add_action( 'plugins_loaded', [ plugin(), 'init' ] );
     28/**
     29 * NOTE: Init the plugin later on the 'after_setup_theme' hook to
     30 * run current_user_can() later to avoid possible conflicts.
     31 */
     32add_action( 'after_setup_theme', [ plugin(), 'init' ] );
    2933
    3034function plugin(): Plugin {
  • kama-clic-counter/trunk/readme.txt

    r3167383 r3282892  
    1 
    21=== Plugin Name ===
    32Stable tag: trunk
    4 Tested up to: 6.6.2
     3Tested up to: 6.8.0
    54Contributors: Tkama
    65Tags: analytics, statistics, count clicks, counter
     
    87License URI: http://www.gnu.org/licenses/gpl-2.0.html
    98
    10 Count clicks on any link all over the site. Creates beautiful file download block in post content. Has top downloads' widget.
     9Count clicks on any link across the site. Creates a beautiful file download block in post content. Includes a widget for top downloads.
     10
    1111
    1212
    1313== Description ==
    1414
    15 Using this plugin you will have statistics on clicks on file download or any other link all over the site.
    16 
    17 To insert file download block use `[download url="any file URL"]` shortcode.
    18 
    19 Plugin don't have any additional instruments to uploads files. All files uploaded using standard wordpress media uploader. To create download block URL are used.
    20 
    21 In additional, plugin has:
    22 
    23 * Button in visual editor to fast insert file download block shortcode.
    24 * Customizable widget, that allows output a list of "Top Downloads" or "Top link Clicks".
     15With this plugin, you can gather statistics on clicks for file downloads or any other link across the site.
     16
     17To insert a file download block, use the `[download url="any file URL"]` shortcode.
     18
     19The plugin does not include additional tools for uploading files. All files must be uploaded using the standard WordPress media uploader. The URLs are then used to create the download block.
     20
     21Additionally, the plugin includes:
     22
     23* A button in the visual editor for quickly inserting the file download block shortcode.
     24* A customizable widget that allows you to display a list of "Top Downloads" or "Top Link Clicks."
    2525
    2626
     
    2828== Frequently Asked Questions ==
    2929
    30 = How can I customize download block with CSS? =
    31 
    32 Just customize CSS styles in plugin options page. Also you can add css styles into 'style.css' file of your theme.
     30= How can I customize the download block with CSS? =
     31
     32You can customize CSS styles on the plugin options page. Alternatively, you can add CSS styles to the `style.css` file of your theme.
    3333
    3434
     
    39392. Plugin settings page.
    40403. Single link edit page.
    41 4. TinyMce visual editor downloads button.
     414. TinyMCE visual editor downloads button.
    4242
    4343
     
    4545== Changelog ==
    4646
     47= 4.0.2 =
     48- CHG: Min PHP version 7.0 >> 7.1.
     49- FIX: Plugin `init` moved to `after_setup_theme` hook to avoid some conflicts.
     50- IMP: minor improvements.
     51- UPD: Tested up to: WP 6.8.0
     52
    4753= 4.0.1 =
    48 * FIX: Bugfix in "counter.js" script.
     54* FIX: Bug in `counter.js` script.
    4955
    5056= 4.0.0 =
    51 * Requires PHP >= 7.0.
    52 * Backcompat removed.
    53 * Code refactored.
    54 * PHP class autoloader added.
    55 * PHP namespaces added.
    56 * Filter `kcc_admin_access` renamed to `kcc_manage_access`.
    57 * Filter `parce_kcc_url` renamed to `click_counter__parse_kcc_url`.
    58 * Filter `get_url_icon` renamed to `click_counter__get_icon_url`.
     57* CHG: Requires PHP >= 7.0.
     58* DEL: Removed backcompat code.
     59* IMP: Code refactored.
     60* ADD: PHP class autoloader.
     61* ADD: PHP namespaces.
     62* CHG: Filter `kcc_admin_access` renamed to `kcc_manage_access`.
     63* CHG: Filter `parce_kcc_url` renamed to `click_counter__parse_kcc_url`.
     64* CHG: Filter `get_url_icon` renamed to `click_counter__get_icon_url`.
    5965
    6066= 3.6.10 =
    61 * Minor improvemets.
     67* IMP: Minor improvements.
    6268
    6369= 3.6.9 =
    64 * A little performance improvements and no jQuery dependence for base count js.
     70* IMP: Performance improvements; no jQuery dependency for base count JS.
    6571
    6672= 3.6.8.2 =
    67 * BUG: some bug in previous version.
     73* FIX: Bug in previous version.
    6874
    6975= 3.6.8.1 =
    70 * BUG: previously, the Protocol for external links was removed (leaved //).
    71 * FIX: compatibility with PHP 7.4
     76* FIX: Protocol for external links issue (leaving `//`).
     77* FIX: Compatibility with PHP 7.4.
    7278
    7379= 3.6.8 =
    74 * BUG: wrong count of URL with query parameters. Code improved!
    75 * BUG: in widget loop.
    76 * FIX: other minor fixes.
     80* FIX: Wrong URL count with query parameters.
     81* FIX: Bug in widget loop.
     82* FIX: Other minor fixes.
    7783
    7884= 3.6.7.3 =
    79 * FIX: wrong `<title>` parsing in some cases.
     85* FIX: `<title>` parsing issue.
    8086
    8187= 3.6.7 =
    82 * FIX: bug with wrong counting when 'hide link under id' option is enadled.
    83 * FIX: minor code fixes
    84 
     88* FIX: Wrong counting with "hide link under id" option enabled.
     89* FIX: Minor code fixes.
    8590
    8691= 3.6.6 =
    87 * FIX: access_role option not saved.
    88 * ADD: desc attr to shortcode.
     92* FIX: `access_role` option not saved.
     93* ADD: `desc` attribute to shortcode.
    8994
    9095= 3.6.5 =
    91 * FIX: because of missing http protocol, filesize was parsed incorrect sometimes (not parsed).
     96* FIX: Filesize parsing issue due to missing HTTP protocol.
    9297
    9398= 3.6.4.2 =
    94 * CHG: Download block HTML markup and css styles changed a little - nothing important...
     99* CHG: Minor changes to download block HTML markup and CSS styles.
    95100
    96101= 3.6.4 =
    97 * ADD: urldecode for incoming URLs writing to DB. Thank to Mark Carson!
    98 * NEW: Exclude url counting filter. See options page.
     102* ADD: `urldecode` for incoming URLs when saving to DB. Thanks to Mark Carson.
     103* NEW: Exclude URL counting filter added (see options page).
    99104
    100105= 3.6.3 =
    101 * FIX: esc_url for wp_redirect() to avoid spaces deletion. Thank to Mark Carson!
     106* FIX: `esc_url()` for `wp_redirect()` to avoid spaces deletion. Thanks to Mark Carson.
    102107
    103108= 3.6.2 =
    104 * ADD: 'in_post' field on edit link admin page. It allow change ID of the post where link is...
    105 * ADD: sanitize data on edit link POST request
    106 * NEW: now all url in database saves as no protocol url - //site.ru/foo. So click on url 'http://site.ru/foo' and click on 'https://site.ru/foo' will be counted in one place.
    107 * FIX: search in admin list worked incorrectly if we begun search from pagination page...
    108 * FIX: correct detection of urls without protocol - //site.ru/foo
    109 * FIX: correct title detection of urls without protocol - //site.ru/foo. Now uses WP HTTP API to retrive external html of link...
    110 * FIX: some minor bug fixes
     109* ADD: `in_post` field on edit link admin page to change associated post ID.
     110* ADD: Sanitize data on edit link POST request.
     111* NEW: Save URLs without protocol (`//site.ru/foo`).
     112* FIX: Admin list search starting from pagination page.
     113* FIX: Detection of URLs without protocol.
     114* FIX: Title detection for protocol-less URLs using WP HTTP API.
     115* FIX: Minor bug fixes.
    111116
    112117= 3.6.1 =
    113 * ADD: 'title' attribute to [download] shortcode. Ex: [download url="URL" title="my file title"]
    114 * ADD: improve tinymce button insert shortcode modal window - now you can find files in media library.
    115 * FIX: It just counted the clicks done with the left-click-mouse-button and not counted clicks with the mouse-wheel and not with "open link..." from context menu opened with right-mouse-click.
    116 
     118* ADD: `title` attribute for `[download]` shortcode.
     119* ADD: Improved TinyMCE button modal window (browse media library).
     120* FIX: Count clicks from mouse wheel and context menu.
    117121
    118122= 3.6.0 =
    119 * CHG: class name 'KCClick' changed to 'KCCounter'. If you have external code for this plugin, change in it all 'KCClick::' or 'KCC::' to 'KCCounter::'!!!
    120 * CHG: Icon in Tinymce visual editor
     123* CHG: Class name `KCClick` changed to `KCCounter`.
     124* CHG: Icon in TinyMCE visual editor updated.
    121125
    122126= 3.5.1 =
    123 * CHG: move localisation to translate.wordpress.org
    124 * FIX: minor code fix
     127* CHG: Move localization to translate.wordpress.org.
     128* FIX: Minor code fix.
    125129
    126130= 3.5.0 =
    127 * FIX: XSS valneruble
    128 * CHG: Change class name 'KCC' to 'KCClick'
    129 * CHG: Translate PHP code to english. Now Russian is localization file...
     131* FIX: XSS vulnerability fixed.
     132* CHG: Class name `KCC` changed to `KCClick`.
     133* CHG: Translate PHP code to English (Russian moved to localization file).
    130134
    131135= 3.4.9 =
    132 * FIX: Remove link from Admin-bar for Roles who has no plugin access
     136* FIX: Remove admin-bar link for roles without plugin access.
    133137
    134138= 3.4.8 =
    135 * ADD: "click per day" data to edit link screen
     139* ADD: "Clicks per day" data on edit link screen.
    136140
    137141= 3.4.7 - 3.4.7.3 =
    138 * FIX: table structure to work fine with 'utf8mb4_unicode_ci' charset
     142* FIX: Table structure to support `utf8mb4_unicode_ci` charset.
    139143
    140144= 3.4.6 =
    141 * ADD: 'get_url_icon' filter to manage icons.
     145* ADD: `get_url_icon` filter to manage icons.
    142146
    143147= 3.4.5 =
    144 * ADD: Administrator option to set access to plugin to other WP roles.
    145 * ADD: Option to add link to KCC Stat in admin bar.
    146 * DEL: no HTTP_REFERER block on direct kcc url use.
     148* ADD: Administrator option to assign plugin access to other WP roles.
     149* ADD: Option to add KCC Stats link to admin bar.
     150* DEL: Removed `HTTP_REFERER` block on direct KCC URL use.
    147151
    148152= 3.4.4 =
    149 * CHANGE: is_file extention check method for url.
    150 * ADD: 'kcc_is_file' filter
    151 * ADD: widget option to set link to post instead of link to file
    152 * REMOVED: 'kcc_file_ext' filter
     153* CHG: `is_file` extension check method for URL.
     154* ADD: `kcc_is_file` filter.
     155* ADD: Widget option to set link to post instead of file.
     156* DEL: Removed `kcc_file_ext` filter.
    153157
    154158= 3.4.3 =
    155 * ADD hooks: 'parce_kcc_url', 'kcc_count_before', 'kcc_count_after'.
    156 * ADD: second parametr '$args' to 'kcc_insert_link_data' filter.
    157 * ADD: punycode support. Now links filter in admin table trying to find keyword in 'link_name' db column too, not only in 'link_url'.
    158 * FIX: It just count the clicks done with the left-click mouse button. Doesn't count clicks done with the mouse wheel, which opens in new tab. Also doesn't count clicks from mobile browsers. left click, mouse wheel, ctrl + left click, touch clicks (I test it in iphone – chrome and safari)
     159* ADD: Hooks `parce_kcc_url`, `kcc_count_before`, `kcc_count_after`.
     160* ADD: Second parameter `$args` to `kcc_insert_link_data` filter.
     161* ADD: Punycode support for link filtering.
     162* FIX: Count clicks from mouse wheel, touch, and ctrl+click.
    159163
    160164= 3.4.2 =
    161 * ADD: 'kcc_admin_access' filter. For possibility to change access capability.
    162 * FIX: redirect protection fix.
     165* ADD: `kcc_admin_access` filter to change access capability.
     166* FIX: Redirect protection fix.
    163167
    164168= 3.4.1 =
    165 * FIX: parse kcc url fix.
     169* FIX: KCC URL parsing issue.
    166170
    167171= 3.4.0 =
    168 * ADD: Hide url in download block option. See the options page.
    169 * ADD: 'link_url' column index in DB for faster plugin work.
    170 * ADD: 'get_kcc_url', 'kcc_redefine_redirect', 'kcc_file_ext', 'kcc_insert_link_data' hooks.
    171 * ADD: Now plugin replace its ugly URL with original URL, when link hover.
    172 * ADD: Replace 'edit link' text for download block to icon. It's more convenient.
    173 * FIX: Correct updates of existing URLs. In some cases there appeared duplicates, when link contain '%' symbol (it could be cyrillic url or so on...)
    174 * FIX: XSS attack protection.
    175 * FIX: Many structure fix in code.
    176 
     172* ADD: Option to hide URL in download block.
     173* ADD: `link_url` column index in DB for performance.
     174* ADD: Hooks `get_kcc_url`, `kcc_redefine_redirect`, `kcc_file_ext`, `kcc_insert_link_data`.
     175* ADD: Replace ugly URL with original URL on hover.
     176* ADD: Replace "edit link" text in download block with icon.
     177* FIX: Duplicate URL updates (e.g., containing `%` symbol).
     178* FIX: XSS protection added.
     179* FIX: Code structure fixes.
    177180
    178181= 3.3.2 =
    179 * FIX: php notice
     182* FIX: PHP notice.
    180183
    181184= 3.3.1 =
    182 * ADD: de_DE l10n, thanks to Volker Typke.
     185* ADD: `de_DE` localization. Thanks to Volker Typke.
    183186
    184187= 3.3.0 =
    185 * ADD: l10n on plugin page.
    186 * ADD: menu to admin page.
    187 * FIX: antivirus wrongly says that file infected.
     188* ADD: Localization on plugin page.
     189* ADD: Menu to admin page.
     190* FIX: Antivirus false positive detection.
    188191
    189192= 3.2.34 =
    190 * FIX: Some admin css change
     193* FIX: Admin CSS changes.
    191194
    192195= 3.2.3.3 =
    193 * ADD: jQuery links become hidden. All jQuery affected links have #kcc anchor and onclick attr with countclick url
    194 * FIX: error with parse_url part. If url had "=" it was exploded...
     196* ADD: jQuery links now hidden with `#kcc` anchor and `onclick` attribute.
     197* FIX: `parse_url` bug when URL contained "=" character.
    195198
    196199= 3.2.3.2 =
    197 * FIX: didn't correctly redirected to url with " " character
    198 * ADD: round "clicks per day" on admin statistics page to one decimal digit
     200* FIX: Redirect to URL with space (`" "`) character.
     201* ADD: Round "clicks per day" value to one decimal on admin stats page.
    199202
    200203= 3.2.3.1 =
    201 * FIX: "back to stat" link on "edit link" admin page
     204* FIX: "Back to stat" link on "edit link" admin page.
    202205
    203206= 3.2.3 =
    204 * FIX: redirects to https doesn't worked correctly
    205 * FIX: PHP less than 5.3 support
    206 * FIX: go back button on "edit link" admin page
    207 * FIX: localization
     207* FIX: Redirects to HTTPS were not working correctly.
     208* FIX: PHP < 5.3 support.
     209* FIX: "Go back" button on "edit link" admin page.
     210* FIX: Localization issues.
    208211
    209212= 3.2.2 =
    210 * ADD: "go back" button on "edit link" admin page
     213* ADD: "Go back" button on "edit link" admin page.
    211214
    212215= 3.2.1 =
    213 Set autoreplace old shortcodes to new in DB during update: [download=""] [download url=""]
     216* CHG: Auto-replace old shortcodes `[download=""]` with `[download url=""]` in DB during update.
    214217
    215218= 3.2 =
    216 Widget has been added
     219* ADD: Widget feature.
     220
  • kama-clic-counter/trunk/src/Admin.php

    r3056424 r3282892  
    3333    }
    3434
    35     public function upgrade(){
     35    public function upgrade() {
    3636        $upgrader = new Upgrader();
    3737        $upgrader->init();
     
    4242     * For WP hook.
    4343     */
    44     public function plugins_page_links( $actions ){
     44    public function plugins_page_links( $actions ) {
    4545
    4646        $actions[] = sprintf( '<a href="%s">%s</a>', $this->admin_page_url( 'settings' ), __( 'Settings', 'kama-clic-counter' ) );
     
    5050    }
    5151
    52     public function admin_menu(){
     52    public function admin_menu() {
    5353
    5454        // just in case
     
    6969    }
    7070
    71     public function admin_page_load(){
     71    public function admin_page_load() {
    7272
    7373        // just in case...
     
    9696                is_string( $val ) && $val = trim( $val );
    9797
    98                 if( $key === 'download_tpl' ){} // no sanitize... wp_kses($val, 'post');
    99                 elseif( $key === 'url_exclude_patterns' ){} // no sanitize...
     98                if( $key === 'download_tpl' ){
     99                    // no sanitize...
     100                }
     101                elseif( $key === 'url_exclude_patterns' ){
     102                    // no sanitize... wp_kses($val, 'post');
     103                }
     104                // no sanitize...
    100105                elseif( is_array( $val ) ){
    101106                    $val = array_map( 'sanitize_key', $val );
     
    136141
    137142            $data = wp_unslash( $_POST['up'] );
    138             $id   = (int) $data['link_id'];
     143            $id = (int) $data['link_id'];
    139144
    140145            // очистка
     
    210215     * Callback for {@see add_options_page()} function parameter.
    211216     */
    212     public function options_page_output(){
     217    public function options_page_output() {
    213218        include plugin()->dir . '/admin/pages/admin.php';
    214219    }
    215220
    216221    /**
    217      * @param int   $link_id
    218      * @param array $data
    219      *
    220222     * @return int|false
    221223     */
    222     private function update_link( $link_id, $data ) {
    223         global $wpdb;
    224 
    225         $link_id = (int) $link_id;
     224    private function update_link( int $link_id, array $data ) {
     225        global $wpdb;
     226
    226227        if( $link_id ){
    227228            $query = $wpdb->update( $wpdb->kcc_clicks, $data, [ 'link_id' => $link_id ] );
     
    243244
    244245    public function delete_link_url( $link_id ): string {
    245         return add_query_arg( [ 'delete_link' => $link_id, '_wpnonce' =>wp_create_nonce('delete_link') ] );
     246        return add_query_arg( [ 'delete_link' => $link_id, '_wpnonce' => wp_create_nonce( 'delete_link' ) ] );
    246247    }
    247248
     
    249250     * Deleting links from the database by passed array ID or link ID.
    250251     *
    251      * @param  array|int $array_ids IDs of links to be deleted.
     252     * @param array|int $array_ids IDs of links to be deleted.
    252253     */
    253254    private function delete_links( $array_ids = [] ): bool {
     
    263264    }
    264265
    265     public function delete_link_by_attach_id( $attach_id ){
     266    public function delete_link_by_attach_id( $attach_id ) {
    266267        global $wpdb;
    267268
     
    276277     * Update the link if the attachment is updated.
    277278     */
    278     public function update_link_with_attach( $attach_id ){
     279    public function update_link_with_attach( $attach_id ) {
    279280        global $wpdb;
    280281
  • kama-clic-counter/trunk/src/Content_Replacer.php

    r3056424 r3282892  
    55class Content_Replacer {
    66
    7     public function __construct(){
     7    public function __construct() {
    88    }
    99
    10     public function init(){
     10    public function init() {
    1111
    1212        if( plugin()->opt->links_class ){
     
    4545        foreach( $args[0] as $pair ){
    4646            list( $tag, $value ) = explode( '=', $pair, 2 );
    47             $value = trim( trim($value, '"\'') );
    48             $args[ trim($tag) ] = $value;
     47            $value = trim( trim( $value, '"\'' ) );
     48            $args[ trim( $tag ) ] = $value;
    4949        }
    5050        unset( $args[0], $args[1] );
    5151
    5252        $after = '';
    53         $args[ 'data-'. Counter::PID_KEY ] = $post->ID;
     53        $args[ 'data-' . Counter::PID_KEY ] = $post->ID;
    5454        if( plugin()->opt->add_hits ){
    5555            $link = plugin()->counter->get_link( $args['href'] );
  • kama-clic-counter/trunk/src/Counter.php

    r3167383 r3282892  
    1717    public $opt;
    1818
    19     public function __construct( Options $options ){
     19    public function __construct( Options $options ) {
    2020
    2121        $this->opt = $options;
     
    9595     * Hides the original link under the link ID. The link must exist in the database.
    9696     *
    97      * @param string $kcc_url Plugin formated URL of the link counting.
     97     * @param string $kcc_url  Plugin formated URL of the link counting.
    9898     *
    9999     * @return string URL with a hidden link.
     
    368368            else{
    369369                trigger_error( sprintf( 'Error: kcc link with id %s not found.', $url ) );
     370
    370371                return;
    371372            }
     
    399400
    400401        // cut URL from $query, because - there could be query args (&) that is why cut it
    401         $split = preg_split( '/[&?]?'. self::COUNT_KEY .'=/', $kcc_query );
     402        $split = preg_split( '/[&?]?' . self::COUNT_KEY . '=/', $kcc_query );
    402403        $query = $split[0];
    403         $url   = self::replace_url_placeholders( $split[1] ); // can be base64 encoded
     404        $url = self::replace_url_placeholders( $split[1] ); // can be base64 encoded
    404405
    405406        if( ! $url ){
     
    427428            ! is_numeric( $url )
    428429            && $url[0] !== '/'
    429             && ! preg_match( '~^(?:' . implode( '|', wp_allowed_protocols() ) . '):~', $url )
    430         ) {
     430            && ! preg_match( '~^(' . implode( '|', wp_allowed_protocols() ) . '):~', $url )
     431        ){
    431432            return [];
    432433        }
    433434
    434435        $return = [
    435             self::COUNT_KEY => $url, // no esc_url()
     436            self::COUNT_KEY => $url, // !!! no esc_url()
    436437            self::PID_KEY   => (int) ( $query_args[ self::PID_KEY ] ?? 0 ),
    437438            // array_key_exists( 'download', $query_args ), // isset null не берет
     
    442443    }
    443444
    444     public static function del_http_protocol( $url ){
     445    public static function del_http_protocol( $url ) {
    445446        return preg_replace( '/https?:/', '', $url );
    446447    }
    447448
    448     private function is_file( $url ){
     449    private function is_file( $url ) {
    449450        /**
    450451         * Allows to repalce {@see Counter::is_file()} method.
     
    537538        $i = 0;
    538539        $type = [ "B", "KB", "MB", "GB" ];
    539         while( ( $size/1024 ) > 1 ){
    540             $size = $size/1024;
     540        while( ( $size / 1024 ) > 1 ){
     541            $size = $size / 1024;
    541542            $i++;
    542543        }
     
    548549     * Returns the size of a file without downloading it.
    549550     *
    550      * @param string $url The location of the remote file to download. Cannot be null or empty.
     551     * @param string $url  The location of the remote file to download. Cannot be null or empty.
    551552     *
    552553     * @return int The size of the file referenced by $url, or 0 if the size could not be determined.
  • kama-clic-counter/trunk/src/Download_Shortcode.php

    r3056424 r3282892  
    55class Download_Shortcode {
    66
    7     public function __construct(){
     7    public function __construct() {
    88    }
    99
    10     public function init(){
     10    public function init() {
    1111        add_shortcode( 'download', [ $this, 'download_shortcode' ] );
    1212    }
  • kama-clic-counter/trunk/src/Helpers.php

    r3056424 r3282892  
    66
    77    /**
    8      * @param string $message Message HTML.
    9      * @param string $type    Allowed: success | error | warning | info.
     8     * @param string $message HTML.
     9     * @param string $type     One of: success|error|warning|info.
    1010     */
    1111    public static function notice_message( string $message, string $type = 'warning' ) {
    1212
    13         add_action(
    14             'admin_notices',
    15             function () use ( $message, $type ) {
    16                 ?>
    17                 <div id="message" class="notice <?= esc_attr( "notice-$type" ) ?>">
    18                     <p><?= wp_kses_post( $message ) ?></p>
    19                 </div>
    20                 <?php
    21             }
    22         );
     13        add_action( 'admin_notices', function() use ( $message, $type ) {
     14            ?>
     15            <div id="message" class="notice <?= esc_attr( "notice-$type" ) ?>">
     16                <p><?= wp_kses_post( $message ) ?></p>
     17            </div>
     18            <?php
     19        } );
    2320    }
    2421
     
    2623     * Gets a link to the icon image by the extension in the passed URL.
    2724     *
    28      * @param $link_url
    29      *
    3025     * @return mixed|null
    3126     */
    32     public static function get_icon_url( $link_url ){
     27    public static function get_icon_url( $link_url ) {
    3328
    3429        $url_path = parse_url( $link_url, PHP_URL_PATH );
     
    3732            $icon_name = $m[1] . '.png';
    3833        }
    39         else{
     34        else {
    4035            $icon_name = 'default.png';
    4136        }
  • kama-clic-counter/trunk/src/Options.php

    r3056424 r3282892  
    4949        ',
    5050        // css class for links in content (if not specified, this functionality is disabled).
    51         'links_class' => 'count',
     51        'links_class'          => 'count',
    5252        // may be: '', 'in_title' or 'in_plain' (for simple links)
    5353        'add_hits'             => '',
  • kama-clic-counter/trunk/src/Plugin.php

    r3056424 r3282892  
    4242
    4343    public function __construct( string $main_file_path ) {
    44 
    4544        $this->set_wpdb_tables();
    4645
     
    5049        $this->url = plugins_url( '', $main_file_path );
    5150
    52         $this->info = get_file_data(
    53             $main_file_path,
    54             [
    55                 'name'    => 'Plugin Name',
    56                 'version' => 'Version',
    57                 'php_ver' => 'Requires PHP',
    58             ]
    59         );
     51        $this->info = get_file_data( $main_file_path, [
     52            'name'    => 'Plugin Name',
     53            'version' => 'Version',
     54            'php_ver' => 'Requires PHP',
     55        ] );
    6056
    6157        $this->opt = new Options();
    6258    }
    6359
    64     /**
    65      * The plugin initialization. Performs on `plugins_loaded` hook.
    66      *
    67      * @return void
    68      */
    69     public function init() {
     60    public function init(): void {
    7061
    71         if ( ! $this->check_dependencies() ) {
     62        if( ! $this->check_dependencies() ){
    7263            return;
    7364        }
     
    10798    }
    10899
    109     /**
    110      * @return void
    111      */
    112     private function set_admin_access() {
     100    private function set_admin_access(): void {
    113101        $this->admin_access = current_user_can( 'manage_options' );
    114102    }
    115103
    116     /**
    117      * @return void
    118      */
    119     private function set_manage_access() {
     104    private function set_manage_access(): void {
    120105
    121106        $this->manage_access = apply_filters( 'kcc_manage_access', null );
     
    139124    }
    140125
    141     public function add_toolbar_menu( $toolbar ){
     126    public function add_toolbar_menu( $toolbar ) {
    142127
    143128        $toolbar->add_menu( [
     
    149134
    150135    public function check_dependencies(): bool {
    151 
    152         if ( version_compare( PHP_VERSION, $this->info['php_ver'], '<=' ) ) {
    153 
     136        if( version_compare( PHP_VERSION, $this->info['php_ver'], '<=' ) ){
    154137            Helpers::notice_message(
    155138                '<b>Kama Click Counter</b> plugin requires PHP version <b>' . $this->info['php_ver'] . '</b> or higher. Please upgrade PHP or diactivate the plugin.',
     
    163146    }
    164147
    165     public function activation(){
     148    public function activation() {
    166149        global $wpdb;
    167150
    168         if ( ! $this->check_dependencies() ) {
     151        if( ! $this->check_dependencies() ){
    169152            return;
    170153        }
  • kama-clic-counter/trunk/src/TinyMCE.php

    r3056424 r3282892  
    2121
    2222    public static function register_buttons( $buttons ) {
    23         $last      = array_pop( $buttons );
     23        $last = array_pop( $buttons );
    2424        $buttons[] = 'kcc';
    2525        $buttons[] = $last;
  • kama-clic-counter/trunk/src/Upgrader.php

    r3056424 r3282892  
    2222    private $db_fields;
    2323
    24     public function __construct(){
    25         $this->is_force_upgrade = isset( $_GET['kcc_force_upgrade'] );
     24    public function __construct() {
     25        $this->is_force_upgrade = isset( $_GET['kcc_force_upgrade'] );
    2626
    27         $this->prev_ver = $this->is_force_upgrade ? '1.0' : get_option( self::OPTION_NAME, '1.0' );
    28         $this->curr_ver = plugin()->info['version'];
     27        $this->prev_ver = $this->is_force_upgrade ? '1.0' : get_option( self::OPTION_NAME, '1.0' );
     28        $this->curr_ver = plugin()->info['version'];
    2929    }
    3030
     
    5050            exit;
    5151        }
    52 
    5352    }
    5453
  • kama-clic-counter/trunk/src/Widget.php

    r3056424 r3282892  
    1313    }
    1414
    15     public static function init(){
     15    public static function init() {
    1616
    1717        if( ! plugin()->opt->widget ){
     
    1919        }
    2020
    21         add_action( 'widgets_init', function () {
     21        add_action( 'widgets_init', function() {
    2222            register_widget( self::class );
    2323        } );
     
    125125     * Admin part of the widget
    126126     */
    127     public function form( $instance ){
    128 
    129         $title        = @ $instance['title']     ? $instance[ 'title' ]     : __('Top Downloads', 'kama-clic-counter' );
    130         $number       = @ $instance['number']    ? $instance[ 'number' ]    : 5;
    131         $last_date    = @ $instance['last_date'] ? $instance[ 'last_date' ] : '';
    132         $template_css = @ $instance['template_css']
    133             ? $instance[ 'template_css' ]
    134             : preg_replace(
    135                 '~^\t+~m', '', '.kcc_widget{ padding:15px; }
    136                 .kcc_widget li{ margin-bottom:10px; list-style: none; }
    137                 .kcc_widget li:after{ content:""; display:table; clear:both; }
    138                 .kcc_widget img{ width:30px; float:left; margin:5px 10px 5px 0; }
    139                 .kcc_widget p{ margin-left:40px; }'
    140             );
    141 
    142         $template = @ $instance['template']
    143             ? $instance['template']
    144             : '<img src="[icon_url]" alt="" />' . "\n"
    145                . '<a href="[link_url]">[link_title]</a> ([link_clicks])' . "\n"
    146                . '<p>[link_description]</p>';
     127    public function form( $instance ) {
     128
     129        $default_template_css = '
     130            .kcc_widget{ padding:15px; }
     131            .kcc_widget li{ margin-bottom:10px; list-style: none; }
     132            .kcc_widget li:after{ content:""; display:table; clear:both; }
     133            .kcc_widget img{ width:30px; float:left; margin:5px 10px 5px 0; }
     134            .kcc_widget p{ margin-left:40px; }
     135        ';
     136
     137        $default_template = '
     138            <img src="[icon_url]" alt="" />
     139            <a href="[link_url]">[link_title]</a> ([link_clicks])
     140            <p>[link_description]</p>
     141        ';
     142
     143        $title        = $instance['title'] ?? __( 'Top Downloads', 'kama-clic-counter' );
     144        $number       = $instance['number'] ?? 5;
     145        $last_date    = $instance['last_date'] ?? '';
     146        $template_css = $instance['template_css'] ?? preg_replace( '~^\t+~m', '', trim( $default_template_css ) );
     147        $template     = $instance['template'] ?? preg_replace( '~^\t+~m', '', trim( $default_template ) );
    147148        ?>
    148149        <p>
Note: See TracChangeset for help on using the changeset viewer.