Plugin Directory

Changeset 1933857


Ignore:
Timestamp:
08/31/2018 01:31:25 PM (8 years ago)
Author:
nir0ma
Message:

V1.2.0

Location:
matomo-tracker
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • matomo-tracker/trunk/README.txt

    r1894061 r1933857  
    44Tags: matomo, piwik, analytics, tracking code
    55Requires at least: 3.0.1
    6 Tested up to: 4.9.6
     6Tested up to: 4.9.8
    77Requires PHP: 5.6.0
    8 Stable tag: 1.1.0
     8Stable tag: 1.2.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5656= 1.1.0 =
    5757* Tracking Mode selection added : You can now choose between Javscript or Php tracking Mode
     58
     59= 1.2.0 =
     60* JS Tracking Mode is no more including inline javascript and now calls a JS File
     61* JS Tracking file loading mode is now customizable (defer, async or nothing)
     62* JS Tracking file can be disallowed in robots.txt
  • matomo-tracker/trunk/inc/admin/class-admin.php

    r1885339 r1933857  
    4242     */
    4343    private $plugin_text_domain;
     44   
     45    private $plugin_name_dir;
     46    private $plugin_name_url;
    4447
    4548    /**
     
    5154     * @param       string $plugin_text_domain The text domain of this plugin.
    5255     */
    53     public function __construct( $plugin_name, $version, $plugin_text_domain ) {
     56    public function __construct( $plugin_name, $version, $plugin_text_domain, $plugin_name_dir, $plugin_name_url ) {
    5457
    5558        $this->plugin_name = $plugin_name;
    5659        $this->version = $version;
    5760        $this->plugin_text_domain = $plugin_text_domain;
     61       
     62        $this->plugin_name_dir = $plugin_name_dir;
     63        $this->plugin_name_url = $plugin_name_url;
    5864
    5965    }
     
    8793     * @since    1.0.0
    8894     */
    89 /*  public function enqueue_scripts() {
     95    public function enqueue_scripts() {
    9096        /*
    9197         * This function is provided for demonstration purposes only.
     
    99105         * class.
    100106         */
    101 /*
     107
    102108        wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/matomo-tracker-admin.js', array( 'jquery' ), $this->version, false );
    103109
    104110    }
    105     */
     111
    106112    public function display_plugin_setup_page() {
    107113        include_once( 'views/html-matomo-tracker-admin-display.php' );
     
    130136                $matomoId = $_POST[$this->plugin_name.'-tracking-id'] ? (int) $_POST[$this->plugin_name.'-tracking-id'] : '';
    131137                $matomoMode = $_POST[$this->plugin_name.'-tracking-mode'] ? $_POST[$this->plugin_name.'-tracking-mode'] : '';
     138                $matomoJsMode = $_POST[$this->plugin_name.'-javascript-mode'] ? $_POST[$this->plugin_name.'-javascript-mode'] : 'defer';
     139                $matomoDisallowRobot = $_POST[$this->plugin_name.'-javascript-disallow-robot'] ? $_POST[$this->plugin_name.'-javascript-disallow-robot'] : 'y';
    132140               
    133141                if (empty($matomoUrl)) {
     
    169177                    } else {
    170178                        add_option( $this->plugin_name.'-tracking-mode', $matomoMode);
    171                     }           
     179                    }   
     180                    if ( get_option( $this->plugin_name.'-javascript-mode' ) !== false ) {
     181                        update_option( $this->plugin_name.'-javascript-mode', $matomoJsMode );
     182                    } else {
     183                        add_option( $this->plugin_name.'-javascript-mode', $matomoJsMode);
     184                    }       
     185                    if ( get_option( $this->plugin_name.'-javascript-disallow-robot' ) !== false ) {
     186                        update_option( $this->plugin_name.'-javascript-disallow-robot', $matomoDisallowRobot );
     187                    } else {
     188                        add_option( $this->plugin_name.'-javascript-disallow-robot', $matomoDisallowRobot);
     189                    }       
    172190                    $admin_notice = "success";
    173191                    $messageLog .= 'Settings saved';
    174192                }
    175                
    176                
     193                if ( $matomoMode == 'js' ) $this->update_tracker_settings();
    177194                $this->custom_redirect( $admin_notice, $messageLog);
    178195                die();
     
    183200                ) );
    184201            }
     202    }
     203   
     204    private function update_tracker_settings() {
     205        if ( get_option( $this->plugin_name.'-tracking-mode' ) == 'js' &&!empty(get_option( $this->plugin_name.'-url' )) && !empty(get_option( $this->plugin_name.'-tracking-id' )) && !empty(get_option( $this->plugin_name.'-token' )) ) {
     206            $piwikId = get_option( $this->plugin_name.'-tracking-id' );
     207           
     208            $piwikFileDir = $this->plugin_name_url . 'inc/frontend/';
     209            $piwikJsFile = $this->plugin_name_dir . 'inc/frontend/track.js';
     210            $js = 'var _paq = _paq || []; _paq.push(["trackPageView"]); _paq.push(["enableLinkTracking"]); (function() { var u="'. $piwikFileDir .'piwik.php"; _paq.push(["setTrackerUrl", u]); _paq.push(["setSiteId", "'. $piwikId .'"]);  var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript"; g.async=true; g.defer=true; g.src=u; s.parentNode.insertBefore(g,s); })();';
     211            file_put_contents($piwikJsFile, $js);
     212        }
     213       
    185214    }
    186215   
  • matomo-tracker/trunk/inc/admin/views/html-matomo-tracker-admin-display.php

    r1885339 r1933857  
    6969                </td>
    7070            </tr>   
     71            <tr id="matomoJsMode" valign="top">
     72                <th scope="row">
     73                    <label for="<?php echo $this->plugin_name; ?>-javascript-mode">
     74                        <span><?php esc_attr_e('Javascript Loading Mode', $this->plugin_text_domain); ?></span>
     75                    </label>
     76                </th>
     77                <td>                               
     78                    <select id="<?php echo $this->plugin_name; ?>-javascript-mode" name="<?php echo $this->plugin_name; ?>-javascript-mode">
     79                        <option value="defer"<?php if (( get_option( $this->plugin_name.'-javascript-mode' ) == 'defer')  || empty(get_option( $this->plugin_name.'-javascript-mode' )) ) echo ' selected';  ?>>defer</option>
     80                        <option value="async"<?php if ( get_option( $this->plugin_name.'-javascript-mode' ) == 'async') echo ' selected';  ?>>async</option>
     81                        <option value="none"<?php if ( get_option( $this->plugin_name.'-javascript-mode' ) == 'none') echo ' selected';  ?>>none</option>
     82                    </select>
     83                </td>
     84            </tr>   
     85            <tr id="matomoJsDisallowRobot" valign="top">
     86                <th scope="row">
     87                    <label for="<?php echo $this->plugin_name; ?>-javascript-disallow-robot">
     88                        <span><?php esc_attr_e('Disallow JS File in robot.txt', $this->plugin_text_domain); ?></span>
     89                    </label>
     90                </th>
     91                <td>                               
     92                    <select id="<?php echo $this->plugin_name; ?>-javascript-disallow-robot" name="<?php echo $this->plugin_name; ?>-javascript-disallow-robot">
     93                        <option value="y"<?php if (( get_option( $this->plugin_name.'-javascript-disallow-robot' ) == 'y')  || empty(get_option( $this->plugin_name.'-javascript-disallow-robot' )) ) echo ' selected';  ?>>Yes</option>
     94                        <option value="n"<?php if ( get_option( $this->plugin_name.'-javascript-disallow-robot' ) == 'n') echo ' selected';  ?>>No</option>
     95                    </select>
     96                    <p  id="<?php echo $this->plugin_name; ?>-javascript-disallow-robot-description" class="description">
     97                        <?php esc_attr_e('If activated this option will disallow js file in robot.txt', $this->plugin_text_domain); ?>
     98                    </p>   
     99                </td>
     100            </tr>   
    71101            <tr valign="top">
    72102                <th scope="row">
  • matomo-tracker/trunk/inc/core/class-init.php

    r1885339 r1933857  
    5151     */
    5252    protected $plugin_text_domain;
     53   
     54    protected $plugin_name_dir;
     55    protected $plugin_name_url;
    5356
    5457    /**
     
    5962        $this->plugin_name = NS\PLUGIN_NAME;
    6063        $this->version = NS\PLUGIN_VERSION;
    61                 $this->plugin_basename = NS\PLUGIN_BASENAME;
    62                 $this->plugin_text_domain = NS\PLUGIN_TEXT_DOMAIN;
     64        $this->plugin_basename = NS\PLUGIN_BASENAME;
     65        $this->plugin_text_domain = NS\PLUGIN_TEXT_DOMAIN;
     66       
     67        $this->plugin_name_dir = NS\PLUGIN_NAME_DIR;
     68        $this->plugin_name_url = NS\PLUGIN_NAME_URL;
    6369
    6470        $this->load_dependencies();
     
    107113    private function define_admin_hooks() {
    108114
    109         $plugin_admin = new Admin\Admin( $this->get_plugin_name(), $this->get_version(), $this->get_plugin_text_domain() );
     115        $plugin_admin = new Admin\Admin( $this->get_plugin_name(), $this->get_version(), $this->get_plugin_text_domain(), $this->get_plugin_name_dir(), $this->get_plugin_name_url() );
    110116       
    111117        //$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    112         //$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
     118        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    113119
    114120        /*
     
    127133        $this->loader->add_action( 'admin_post_matomo_tracker_form_response', $plugin_admin, 'check_for_event_submissions');
    128134        $this->loader->add_action( 'admin_notices', $plugin_admin, 'print_plugin_admin_notices');
     135        $this->loader->add_action( 'upgrader_process_complete', $plugin_admin, 'update_tracker_settings');
     136
    129137    }
    130138
     
    145153        } else {
    146154            $this->loader->add_action( 'wp_footer', $plugin_public, 'add_tracking_code_footer' );
     155            if ( empty(get_option( $this->plugin_name.'-javascript-disallow-robot' )) || get_option( $this->plugin_name.'-javascript-disallow-robot') == 'y' ) {
     156                $this->loader->add_filter( 'robots_txt', $plugin_public, 'disallow_javascript_tracking', 10, 2 );
     157            }
    147158        }
    148159
     
    192203        return $this->plugin_text_domain;
    193204    }
     205   
     206    public function get_plugin_name_dir() {
     207        return $this->plugin_name_dir;
     208    }
     209   
     210    public function get_plugin_name_url() {
     211        return $this->plugin_name_url;
     212    }
     213   
    194214
    195215}
  • matomo-tracker/trunk/inc/frontend/class-frontend.php

    r1885339 r1933857  
    108108    public function add_tracking_code_footer() {
    109109        if ( !empty(get_option( $this->plugin_name.'-url' )) && !empty(get_option( $this->plugin_name.'-tracking-id' )) && !empty(get_option( $this->plugin_name.'-token' )) ) {
    110             $piwikId = get_option( $this->plugin_name.'-tracking-id' );
    111110            $piwikFileDir = plugin_dir_url( __FILE__ );
    112             echo '<script type="text/javascript">var _paq = _paq || []; _paq.push(["trackPageView"]); _paq.push(["enableLinkTracking"]); (function() { var u="'. $piwikFileDir .'piwik.php"; _paq.push(["setTrackerUrl", u]); _paq.push(["setSiteId", "'. $piwikId .'"]);  var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript"; g.async=true; g.defer=true; g.src=u; s.parentNode.insertBefore(g,s); })();</script>';
     111            $matomoJsMode = get_option( $this->plugin_name.'-javascript-mode' );
     112            $matomoScript = "<script type='text/javascript'";
     113            if ($matomoJsMode == 'defer') $matomoScript .= " defer='defer'";
     114            if ($matomoJsMode == 'async') $matomoScript .= " async='async'";
     115            $matomoScript .= " src='".$piwikFileDir."track.js'></script>";
     116            echo $matomoScript;
    113117        }
     118    }
     119   
     120    public function disallow_javascript_tracking( $output, $public ) {
     121        if ( '1' === $public ) {
     122            $output .= "Disallow: /wp-content/plugins/matomo-tracker/inc/frontend/track.js\n";
     123        }
     124            return $output;
    114125    }
    115126   
  • matomo-tracker/trunk/matomo-tracker.php

    r1885339 r1933857  
    1616 * Plugin URI:        https://wordpress.org/plugins/matomo-tracker/
    1717 * Description:       Matomo tracker adds matomo (formerly piwik) tracking code to your website while hiding your matomo installation url
    18  * Version:           1.1.0
     18 * Version:           1.2.0
    1919 * Author:            Niroma
    2020 * Author URI:        https://www.niroma.net/
     
    4040define( NS . 'PLUGIN_NAME', 'matomo-tracker' );
    4141
    42 define( NS . 'PLUGIN_VERSION', '1.1.0' );
     42define( NS . 'PLUGIN_VERSION', '1.2.0' );
    4343
    4444define( NS . 'PLUGIN_NAME_DIR', plugin_dir_path( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.