WP-Matomo (WP-Piwik) - Version 0.8.9

Version Description

  • WP 3.2 compatible, metabox support
Download this release

Release Info

Developer Braekling
Plugin Icon 128x128 WP-Matomo (WP-Piwik)
Version 0.8.9
Comparing to
See all releases

Code changes from version 0.8.8 to 0.8.9

dashboard/footer.php CHANGED
@@ -2,6 +2,5 @@
2
  /*********************************
3
  WP-Piwik::Stats:Footer
4
  **********************************/
5
- ?>
6
- </div>
7
- </div>
2
  /*********************************
3
  WP-Piwik::Stats:Footer
4
  **********************************/
5
+
6
+ ?>
 
dashboard/header.php CHANGED
@@ -2,7 +2,7 @@
2
  /*********************************
3
  WP-Piwik::Stats:Header
4
  **********************************/
5
- ?>
6
  <div id="<?php echo $aryConf['id']; ?>" class="postbox <?php echo ($aryConf['closed']?'if-js-closed':''); ?>" >
7
  <div class="handlediv" title="Click to toggle">
8
  <br />
@@ -13,3 +13,5 @@
13
  </span>
14
  </h3>
15
  <div class="inside">
 
 
2
  /*********************************
3
  WP-Piwik::Stats:Header
4
  **********************************/
5
+ /*
6
  <div id="<?php echo $aryConf['id']; ?>" class="postbox <?php echo ($aryConf['closed']?'if-js-closed':''); ?>" >
7
  <div class="handlediv" title="Click to toggle">
8
  <br />
13
  </span>
14
  </h3>
15
  <div class="inside">
16
+ */
17
+ ?>
dashboard/overview.php CHANGED
@@ -58,7 +58,7 @@
58
  echo '<tr><td>'.__('Time/visit', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
59
  echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
60
  if (self::$aryGlobalSettings['piwik_shortcut'])
61
- echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.self::$aryGlobalSettings['piwik_url'].'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik/wp-piwik.php">WP-Piwik</a>':'').'</td></tr>';
62
 
63
  /***************************************************************************/ ?>
64
  </tbody>
58
  echo '<tr><td>'.__('Time/visit', 'wp-piwik').':</td><td>'.$strAvgTime.'</td></tr>';
59
  echo '<tr><td>'.__('Bounce count', 'wp-piwik').':</td><td>'.$aryConf['data']['bounce_count'].' ('.$aryConf['data']['bounce_rate'].')</td></tr>';
60
  if (self::$aryGlobalSettings['piwik_shortcut'])
61
+ echo '<tr><td>'.__('Shortcut', 'wp-piwik').':</td><td><a href="'.self::$aryGlobalSettings['piwik_url'].'">Piwik</a>'.(isset($aryConf['inline']) && $aryConf['inline']?' - <a href="?page=wp-piwik_stats">WP-Piwik</a>':'').'</td></tr>';
62
 
63
  /***************************************************************************/ ?>
64
  </tbody>
dashboard/visitors.php CHANGED
@@ -21,7 +21,6 @@
21
  $aryConf['params']['date'],
22
  $aryConf['params']['limit']
23
  );
24
- $aryConf['title'] = __('Visitors', 'wp-piwik');
25
 
26
  if (!isset($aryConf['inline']) || $aryConf['inline'] != true)
27
  include('header.php');
@@ -47,7 +46,7 @@
47
 
48
  /***************************************************************************/ ?>
49
  <div class="wp-piwik-graph-wide">
50
- <div id="wp-piwik_stats_vistors_graph" style="height:220px;width:100%"></div>
51
  </div>
52
  <?php if (!isset($aryConf['inline']) || $aryConf['inline'] != true) { ?>
53
  <div class="table">
@@ -65,7 +64,7 @@
65
  if (is_array($aryConf['data']['Visitors'])) {
66
  $aryTmp = array_reverse($aryConf['data']['Visitors']);
67
  foreach ($aryTmp as $strDate => $intValue)
68
- echo '<tr onclick="javascript:datelink(\''.urlencode(self::$strPluginBasename).'\',\''.str_replace('-', '', $strDate).'\');"><td>'.$strDate.'</td><td class="n">'.
69
  $intValue.'</td><td class="n">'.
70
  $aryConf['data']['Unique'][$strDate].
71
  '</td><td class="n">'.
21
  $aryConf['params']['date'],
22
  $aryConf['params']['limit']
23
  );
 
24
 
25
  if (!isset($aryConf['inline']) || $aryConf['inline'] != true)
26
  include('header.php');
46
 
47
  /***************************************************************************/ ?>
48
  <div class="wp-piwik-graph-wide">
49
+ <div id="wp-piwik_stats_vistors_graph" style="height:220px;width:490px;"></div>
50
  </div>
51
  <?php if (!isset($aryConf['inline']) || $aryConf['inline'] != true) { ?>
52
  <div class="table">
64
  if (is_array($aryConf['data']['Visitors'])) {
65
  $aryTmp = array_reverse($aryConf['data']['Visitors']);
66
  foreach ($aryTmp as $strDate => $intValue)
67
+ echo '<tr onclick="javascript:datelink(\''.urlencode('wp-piwik_stats').'\',\''.str_replace('-', '', $strDate).'\');"><td>'.$strDate.'</td><td class="n">'.
68
  $intValue.'</td><td class="n">'.
69
  $aryConf['data']['Unique'][$strDate].
70
  '</td><td class="n">'.
js/wp-piwik.js CHANGED
@@ -1,9 +1,3 @@
1
- jQuery( function($) {
2
- // close postboxes that should be closed
3
- jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
4
- postboxes.add_postbox_toggles('wppiwik');
5
- } );
6
-
7
  function datelink(strPage,strDate) {
8
  window.location.href='index.php?page='+strPage+'&date='+strDate;
9
- }
 
 
 
 
 
 
1
  function datelink(strPage,strDate) {
2
  window.location.href='index.php?page='+strPage+'&date='+strDate;
3
+ }
languages/wp-piwik-de_DE.mo CHANGED
Binary file
languages/wp-piwik-de_DE.po CHANGED
@@ -355,7 +355,7 @@ msgid "Thank you very much, all users who send me mails containing criticism, co
355
  msgstr "Vielen Dank an alle Nutzer, die mir Mails mit Kritik, Lob, Featurew&uuml;nsche und Bugmeldungen senden. Ihr helft mir dabei, WP-Piwik viel besser zu machen."
356
 
357
  msgid "Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!"
358
- msgstr "Vielen Dank an <strong>Dich</strong> für die Nutzung meines Plugins. Es ist das gr&ouml;&szlig;te Lob, wenn mein Code tats&auml;chlich benutzt wird!"
359
 
360
  msgid "Changes saved"
361
  msgstr "&Auml;nderungen gespeichert"
355
  msgstr "Vielen Dank an alle Nutzer, die mir Mails mit Kritik, Lob, Featurew&uuml;nsche und Bugmeldungen senden. Ihr helft mir dabei, WP-Piwik viel besser zu machen."
356
 
357
  msgid "Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!"
358
+ msgstr "Vielen Dank an <strong>Dich</strong> f&uuml;r die Nutzung meines Plugins. Es ist das gr&ouml;&szlig;te Lob, wenn mein Code tats&auml;chlich benutzt wird!"
359
 
360
  msgid "Changes saved"
361
  msgstr "&Auml;nderungen gespeichert"
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WP-Piwik ===
2
 
3
  Contributors: Braekling
4
- Requires at least: 3.1
5
- Tested up to: 3.1.3
6
- Stable tag: 0.8.8
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: statistics, stats, analytics, piwik, wpmu
9
 
@@ -47,6 +47,7 @@ Just add WP-Piwik to your /wp-content/plugins folder. So each user can enable WP
47
  = Credits =
48
 
49
  * Graphs powered by [jqPlot](http://www.jqplot.com/), an open source project by Chris Leonello. Give it a try! (GPL 2.0 and MIT)
 
50
  * Albanian [sq] language file by [Besnik Bleta](http://blogu.programeshqip.org/).
51
  * Azerbaijani [az_AZ] language file by [Galina Miklosic](http://www.webhostinggeeks.com).
52
  * Belorussian [be_BY] language file by [FatCow](http://www.fatcow.com/).
@@ -78,6 +79,9 @@ Thank you, guys!
78
 
79
  == Changelog ==
80
 
 
 
 
81
  = 0.8.8 =
82
  * Bugfix: Will also work with index.php in Piwik path
83
  * Bugfix: last30 dashboard widget - show correct bounce rate
1
  === WP-Piwik ===
2
 
3
  Contributors: Braekling
4
+ Requires at least: 3.2
5
+ Tested up to: 3.2.1
6
+ Stable tag: 0.8.9
7
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6046779
8
  Tags: statistics, stats, analytics, piwik, wpmu
9
 
47
  = Credits =
48
 
49
  * Graphs powered by [jqPlot](http://www.jqplot.com/), an open source project by Chris Leonello. Give it a try! (GPL 2.0 and MIT)
50
+ * Metabox support inspired by [Heiko Rabe's metabox demo plugin](http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins).
51
  * Albanian [sq] language file by [Besnik Bleta](http://blogu.programeshqip.org/).
52
  * Azerbaijani [az_AZ] language file by [Galina Miklosic](http://www.webhostinggeeks.com).
53
  * Belorussian [be_BY] language file by [FatCow](http://www.fatcow.com/).
79
 
80
  == Changelog ==
81
 
82
+ = 0.8.9 =
83
+ * WP 3.2 compatible, metabox support
84
+
85
  = 0.8.8 =
86
  * Bugfix: Will also work with index.php in Piwik path
87
  * Bugfix: last30 dashboard widget - show correct bounce rate
wp-piwik.php CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://www.braekling.de/wp-piwik-wpmu-piwik-wordpress/
6
 
7
  Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress footer.
8
 
9
- Version: 0.8.8
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: http://www.braekling.de
12
 
@@ -27,15 +27,24 @@ Author URI: http://www.braekling.de
27
  along with this program. If not, see <http://www.gnu.org/licenses/>.
28
  *******************************************************************************************/
29
 
 
 
 
 
 
 
 
 
 
30
  // Change this to enable *experimental* multisite-mode
31
  $GLOBALS['wp-piwik_wpmu'] = false;
32
 
33
  class wp_piwik {
34
 
35
  private static
36
- $intRevisionId = 80800,
37
- $strVersion = '0.8.8',
38
- $intDashboardID = 6,
39
  $bolWPMU = false,
40
  $bolOverall = false,
41
  $strPluginBasename = NULL,
@@ -59,6 +68,9 @@ class wp_piwik {
59
  'last_tracking_code_update' => 0,
60
  'dashboard_revision' => 0
61
  );
 
 
 
62
 
63
  /**
64
  * Load plugin settings
@@ -116,11 +128,15 @@ class wp_piwik {
116
  // Call install function on activation
117
  register_activation_hook(__FILE__, array($this, 'install'));
118
  // Add meta links to plugin details
119
- if (!self::$bolWPMU) add_filter('plugin_row_meta', array($this, 'set_plugin_meta'), 10, 2);
120
  // Add tracking code to footer if enabled
121
  if (self::$aryGlobalSettings['add_tracking_code']) add_action('wp_footer', array($this, 'footer'));
 
 
122
  // Add admin menu
123
- add_action('admin_menu', array($this, 'build_menu'));
 
 
124
  // Add dashboard widget if enabled
125
  if (self::$aryGlobalSettings['dashboard_widget'] || self::$aryGlobalSettings['dashboard_chart'])
126
  add_action('wp_dashboard_setup', array($this, 'extend_wp_dashboard_setup'));
@@ -135,7 +151,6 @@ class wp_piwik {
135
  * Install or upgrade
136
  */
137
  function install() {
138
-
139
  // Update: Translate options
140
  if (self::$aryGlobalSettings['revision'] < 80403) {
141
  // Capability read stats: Translate level to role
@@ -173,9 +188,7 @@ class wp_piwik {
173
  'capability_read_stats' => $aryDisplayToCap,
174
  'piwik_shortcut' => get_option('wp-piwik_piwiklink',false),
175
  );
176
-
177
  $this->installSite(false);
178
-
179
  // Remove deprecated option values
180
  $aryRemoveOptions = array(
181
  'wp-piwik_disable_gapi','wp-piwik_displayto',
@@ -200,7 +213,6 @@ class wp_piwik {
200
  // Set current revision ID
201
  self::$aryGlobalSettings['revision'] = self::$intRevisionId;
202
  self::$aryGlobalSettings['last_settings_update'] = time();
203
-
204
  // Save upgraded or default settings
205
  self::saveSettings();
206
  // Reload settings
@@ -291,23 +303,25 @@ class wp_piwik {
291
  /**
292
  * Add pages to admin menu
293
  */
294
- function build_menu() {
295
  // Show stats dashboard page if WP-Piwik is configured
296
  if (!empty(self::$aryGlobalSettings['piwik_token']) && !empty(self::$aryGlobalSettings['piwik_url'])) {
297
  // Add dashboard page
298
- $intStatsPage = add_dashboard_page(
299
  __('Piwik Statistics', 'wp-piwik'),
300
  __('WP-Piwik', 'wp-piwik'),
301
  (!self::$bolWPMU?'wp-piwik_read_stats':'administrator'),
302
- __FILE__,
303
- array($this, 'show_stats')
304
  );
305
  // Add required scripts
306
- add_action('admin_print_scripts-'.$intStatsPage, array($this, 'load_scripts'));
307
  // Add required styles
308
- add_action('admin_print_styles-'.$intStatsPage, array($this, 'add_admin_style'));
309
  // Add required header tags
310
- add_action('admin_head-'.$intStatsPage, array($this, 'add_admin_header'));
 
 
311
  }
312
  // Add options page if not multi-user
313
  if (!self::$bolWPMU)
@@ -335,32 +349,33 @@ class wp_piwik {
335
  add_action('admin_print_styles-'.$intOptionsPage, array($this, 'add_admin_style'));
336
  }
337
 
 
 
 
 
 
 
 
 
 
338
  function extend_wp_dashboard_setup() {
339
  if (current_user_can('wp-piwik_read_stats')) {
340
  if (self::$aryGlobalSettings['dashboard_widget'])
341
- wp_add_dashboard_widget(
342
- 'wp-piwik_dashboard_widget',
343
- __('WP-Piwik', 'wp-piwik').' - '.__(self::$aryGlobalSettings['dashboard_widget'], 'wp-piwik'),
344
- array (&$this, 'add_wp_dashboard_widget')
345
- );
346
- if (self::$aryGlobalSettings['dashboard_chart']) {
347
  // Add required scripts
348
  add_action('admin_print_scripts-index.php', array($this, 'load_scripts'));
349
  // Add required styles
350
  add_action('admin_print_styles-index.php', array($this, 'add_admin_style'));
351
  // Add required header tags
352
  add_action('admin_head-index.php', array($this, 'add_admin_header'));
353
- wp_add_dashboard_widget(
354
- 'wp-piwik_dashboard_chart',
355
- __('WP-Piwik', 'wp-piwik').' - '.__('Visitors', 'wp-piwik'),
356
- array (&$this, 'add_wp_dashboard_chart')
357
- );
358
  }
359
  }
360
  }
361
 
362
  function add_wp_dashboard_widget() {
363
- $arySetup = array(
364
  'params' => array(
365
  'period' => 'day',
366
  'date' => self::$aryGlobalSettings['dashboard_widget'],
@@ -368,14 +383,23 @@ class wp_piwik {
368
  ),
369
  'inline' => true,
370
  );
371
- $this->create_dashboard_widget('overview', $arySetup);
 
 
 
 
 
 
 
 
 
372
  }
373
 
374
  /**
375
  * Add a visitor chart to the WordPress dashboard
376
  */
377
  function add_wp_dashboard_chart() {
378
- $arySetup = array(
379
  'params' => array(
380
  'period' => 'day',
381
  'date' => 'last30',
@@ -383,7 +407,16 @@ class wp_piwik {
383
  ),
384
  'inline' => true,
385
  );
386
- $this->create_dashboard_widget('visitors', $arySetup);
 
 
 
 
 
 
 
 
 
387
  }
388
 
389
  /**
@@ -391,7 +424,7 @@ class wp_piwik {
391
  *
392
  * @see http://wpengineer.com/1295/meta-links-for-wordpress-plugins/
393
  */
394
- function set_plugin_meta($strLinks, $strFile) {
395
  // Get plugin basename
396
  $strPlugin = plugin_basename(__FILE__);
397
  // Add link just to this plugin's details
@@ -411,7 +444,7 @@ class wp_piwik {
411
  */
412
  function load_scripts() {
413
  // Load WP-Piwik script
414
- wp_enqueue_script('wp-piwik', $this->get_plugin_url().'js/wp-piwik.js', array('jquery', 'admin-comments', 'postbox'));
415
  // Load jqPlot
416
  wp_enqueue_script('wp-piwik-jqplot',$this->get_plugin_url().'js/jqplot/wp-piwik.jqplot.js',array('jquery'));
417
  }
@@ -528,14 +561,15 @@ class wp_piwik {
528
  return array('js' => $strJavaScript, 'id' => self::$arySettings['site_id']);
529
  }
530
 
531
- function create_dashboard_widget($strFile, $aryConfig) {
532
  $strDesc = $strID = '';
 
533
  foreach ($aryConfig['params'] as $strParam)
534
  if (!empty($strParam)) {
535
  $strDesc .= $strParam.', ';
536
  $strID .= '_'.$strParam;
537
  }
538
- $strFile = str_replace('.', '', $strFile);
539
  $aryConf = array_merge($aryConfig, array(
540
  'id' => $strFile.$strID,
541
  'desc' => substr($strDesc, 0, -2)));
@@ -554,67 +588,83 @@ class wp_piwik {
554
  }
555
  }
556
 
557
- function show_stats() {
 
 
 
558
  $strToken = self::$aryGlobalSettings['piwik_token'];
559
  $strPiwikURL = self::$aryGlobalSettings['piwik_url'];
560
- $arySortOrder = get_user_option('meta-box-order_wppiwik');
561
- $aryClosed = get_user_option('closedpostboxes_wppiwik');
562
- if (empty($aryClosed)) $aryClosed = array();
563
  $aryDashboard = array();
564
- $intCurrentDashboard = self::$arySettings['dashboard_revision'];
565
- if (!$arySortOrder) {
566
- // Set default configuration
567
- $arySortOrder = array(
568
- 'side' => 'overview_day_yesterday,pages_day_yesterday,keywords_day_yesterday_10,websites_day_yesterday_10,plugins_day_yesterday',
569
- 'normal' => 'visitors_day_last30,browsers_day_yesterday,screens_day_yesterday,systems_day_yesterday'
570
- );
571
- global $current_user;
572
- get_currentuserinfo();
573
- update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
574
- self::$arySettings['dashboard_revision'] = self::$intDashboardID;
575
- self::saveSettings();
576
- } elseif ($intCurrentDashboard < self::$intDashboardID) {
577
- if ($intCurrentDashboard < 5) {
578
- $arySortOrder['normal'] .= ',screens_day_yesterday,systems_day_yesterday';
579
- $arySortOrder['side'] .= ',plugins_day_yesterday';
580
- }
581
- if ($intCurrentDashboard < 6) {
582
- $arySortOrder['side'] .= ',pages_day_yesterday';
583
- }
584
- global $current_user;
585
- get_currentuserinfo();
586
- update_user_option($current_user->ID, 'meta-box-order_wppiwik', $arySortOrder);
587
- self::$arySettings['dashboard_revision'] = self::$intDashboardID;
588
- self::saveSettings();
589
- }
590
- foreach ($arySortOrder as $strCol => $strWidgets) {
591
- $aryWidgets = explode(',', $strWidgets);
592
- if (is_array($aryWidgets)) foreach ($aryWidgets as $strParams) {
593
- $aryParams = explode('_', $strParams);
594
- $aryDashboard[$strCol][$aryParams[0]] = array(
595
  'params' => array(
 
596
  'period' => (isset($aryParams[1])?$aryParams[1]:''),
597
  'date' => (isset($aryParams[2])?$aryParams[2]:''),
598
  'limit' => (isset($aryParams[3])?$aryParams[3]:'')
599
- ),
600
- 'closed' => (in_array($strParams, $aryClosed))
601
  );
602
- if (isset($_GET['date']) && preg_match('/^[0-9]{8}$/', $_GET['date']) && $aryParams[0] != 'visitors')
603
- $aryDashboard[$strCol][$aryParams[0]]['params']['date'] = $_GET['date'];
604
- elseif ($aryParams[0] != 'visitors')
605
- $aryDashboard[$strCol][$aryParams[0]]['params']['date'] = self::$aryGlobalSettings['default_date'];
606
  }
607
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  /***************************************************************************/ ?>
609
- <div class="wrap">
610
- <div id="icon-post" class="icon32"><br /></div>
611
  <h2><?php _e('Piwik Statistics', 'wp-piwik'); ?></h2>
612
  <?php /************************************************************************/
613
-
614
  if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
615
  if (isset($_POST['wpmu_show_stats']))
616
- /*if ($_POST['wpmu_show_stats'] == 'all') self::$bolOverall = true;
617
- else*/ switch_to_blog((int) $_POST['wpmu_show_stats']);
618
  global $blog_id;
619
  global $wpdb;
620
  $aryBlogs = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM '.$wpdb->prefix.'blogs ORDER BY blog_id'));
@@ -629,40 +679,55 @@ class wp_piwik {
629
  else _e('Current shown stats: <strong>Overall</strong>');
630
  echo '</form>'."\n";
631
  }
632
-
633
- /***************************************************************************/ ?>
634
- <div id="dashboard-widgets-wrap">
635
- <div id="dashboard-widgets" class="metabox-holder">
636
- <div id="postbox-container" class="wp-piwik-side" style="width:290px; float:left;">
637
- <div id="side-sortables" class="meta-box-sortables ui-sortable wp-piwik-sortables">
638
- <?php /************************************************************************/
639
- foreach ($aryDashboard['side'] as $strFile => $aryConfig)
640
- $this->create_dashboard_widget($strFile, $aryConfig);
641
  /***************************************************************************/ ?>
642
- </div>
 
 
 
 
 
 
 
643
  </div>
644
- <div id="postbox-container" class="" style="width:520px; float:left; ">
645
- <div id="wppiwik-widgets-main-content" class="has-sidebar-content">
646
- <div id="normal-sortables" class="meta-box-sortables ui-sortable wp-piwik-sortables">
647
- <?php /************************************************************************/
648
- foreach ($aryDashboard['normal'] as $strFile => $aryConfig)
649
- $this->create_dashboard_widget($strFile, $aryConfig);
650
- wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
651
- wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
652
- /***************************************************************************/ ?>
653
- <div class="clear"></div>
654
- </div>
655
  </div>
656
  </div>
657
- </div>
658
- </div>
 
659
  </div>
 
 
 
 
 
 
 
 
 
 
660
  <?php /************************************************************************/
661
  if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
662
  restore_current_blog(); self::$bolOverall = false;
663
  }
664
  }
665
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
  function applySettings() {
667
  if (!self::$bolWPMU) {
668
  self::$aryGlobalSettings['add_tracking_code'] = (isset($_POST['wp-piwik_addjs'])?$_POST['wp-piwik_addjs']:'');
@@ -910,17 +975,6 @@ class wp_piwik {
910
  echo '</div>';
911
  echo '<div class="wp-piwik_desc">'.
912
  __('Choose users by user role you do <strong>not</strong> want to track.', 'wp-piwik').'</div>';
913
-
914
- /*echo '<h4><label>'.__('Display to', 'wp-piwik').':</label></h4>';
915
- echo '<div class="input-wrap">';
916
- $intDisplayTo = self::$aryGlobalSettings['capability_read_stats'];
917
- foreach($wp_roles->role_names as $strKey => $strName) {
918
- $role = get_role($strKey);
919
- echo '<input name="wp-piwik_displayto['.$strKey.']" type="checkbox" value="1"'.(isset(self::$aryGlobalSettings['capability_read_stats'][$strKey]) && self::$aryGlobalSettings['capability_read_stats'][$strKey]?' checked="checked"':'').'/> '.$strName.' &nbsp; ';
920
- }
921
- echo '</div><div class="wp-piwik_desc">'.
922
- __('Choose user roles allowed to see the statistics page.', 'wp-piwik').
923
- '</div>';*/
924
  }
925
  /***************************************************************************/ ?>
926
  <div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
@@ -944,7 +998,7 @@ class wp_piwik {
944
  <script type="text/javascript">
945
  var flattr_url = 'http://www.braekling.de/wp-piwik-wpmu-piwik-wordpress';
946
  </script>
947
- <script src="http://api.flattr.com/button/load.js" type="text/javascript"></script>
948
  </div>
949
  <div>Paypal
950
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
@@ -961,12 +1015,17 @@ class wp_piwik {
961
  <?php /************************************************************************/
962
  }
963
 
 
 
 
 
964
  function credits() {
965
  /***************************************************************************/ ?>
966
  <h2 style="clear:left;"><?php _e('Credits', 'wp-piwik'); ?></h2>
967
  <div class="inside">
968
  <p><strong><?php _e('Thank you very much for your donation', 'wp-piwik'); ?>:</strong> Marco L., Rolf W., Tobias U., Lars K., Donna F. <?php _e('and all people flattering this','wp-piwik'); ?>!</p>
969
  <p><?php _e('Graphs powered by <a href="http://www.jqplot.com/">jqPlot</a>, an open source project by Chris Leonello. Give it a try! (License: GPL 2.0 and MIT)','wp-piwik'); ?></p>
 
970
  <p><?php _e('Thank you very much','wp-piwik'); ?>, <a href="http://blogu.programeshqip.org/">Besnik Bleta</a>, <a href="http://www.fatcow.com/">FatCow</a>, <a href="http://www.pamukkaleturkey.com/">Rene</a>, Fab, <a href="http://ezbizniz.com/">EzBizNiz</a>, Gormer, Natalya, <a href="www.aggeliopolis.gr">AggelioPolis</a><?php _e(', and', 'wp-piwik'); ?> <a href="http://wwww.webhostinggeeks.com">Galina Miklosic</a> <?php _e('for your translation work','wp-piwik'); ?>!</p>
971
  <p><?php _e('Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better.','wp-piwik'); ?></p>
972
  <p><?php _e('Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!','wp-piwik'); ?></p>
6
 
7
  Description: Adds Piwik stats to your dashboard menu and Piwik code to your wordpress footer.
8
 
9
+ Version: 0.8.9
10
  Author: Andr&eacute; Br&auml;kling
11
  Author URI: http://www.braekling.de
12
 
27
  along with this program. If not, see <http://www.gnu.org/licenses/>.
28
  *******************************************************************************************/
29
 
30
+ /* Avoid direct calls to this file if wp core files not present
31
+ seen (as some other parts) in Heiko Rabe's metabox demo plugin
32
+ http://tinyurl.com/5r5vnzs */
33
+ if (!function_exists ('add_action')) {
34
+ header('Status: 403 Forbidden');
35
+ header('HTTP/1.1 403 Forbidden');
36
+ exit();
37
+ }
38
+
39
  // Change this to enable *experimental* multisite-mode
40
  $GLOBALS['wp-piwik_wpmu'] = false;
41
 
42
  class wp_piwik {
43
 
44
  private static
45
+ $intRevisionId = 80900,
46
+ $strVersion = '0.8.9',
47
+ $intDashboardID = 30,
48
  $bolWPMU = false,
49
  $bolOverall = false,
50
  $strPluginBasename = NULL,
68
  'last_tracking_code_update' => 0,
69
  'dashboard_revision' => 0
70
  );
71
+
72
+ private
73
+ $intStatsPage = NULL;
74
 
75
  /**
76
  * Load plugin settings
128
  // Call install function on activation
129
  register_activation_hook(__FILE__, array($this, 'install'));
130
  // Add meta links to plugin details
131
+ if (!self::$bolWPMU) add_filter('plugin_row_meta', array($this, 'setPluginMeta'), 10, 2);
132
  // Add tracking code to footer if enabled
133
  if (self::$aryGlobalSettings['add_tracking_code']) add_action('wp_footer', array($this, 'footer'));
134
+ // Register columns
135
+ //add_filter('screen_layout_columns', array(&$this, 'onScreenLayoutColumns'), 10, 2);
136
  // Add admin menu
137
+ add_action('admin_menu', array($this, 'buildAdminMenu'));
138
+ // Register the callback been used if options of page been submitted and needs to be processed
139
+ add_action('admin_post_save_wp-piwik_stats', array(&$this, 'onStatsPageSaveChanges'));
140
  // Add dashboard widget if enabled
141
  if (self::$aryGlobalSettings['dashboard_widget'] || self::$aryGlobalSettings['dashboard_chart'])
142
  add_action('wp_dashboard_setup', array($this, 'extend_wp_dashboard_setup'));
151
  * Install or upgrade
152
  */
153
  function install() {
 
154
  // Update: Translate options
155
  if (self::$aryGlobalSettings['revision'] < 80403) {
156
  // Capability read stats: Translate level to role
188
  'capability_read_stats' => $aryDisplayToCap,
189
  'piwik_shortcut' => get_option('wp-piwik_piwiklink',false),
190
  );
 
191
  $this->installSite(false);
 
192
  // Remove deprecated option values
193
  $aryRemoveOptions = array(
194
  'wp-piwik_disable_gapi','wp-piwik_displayto',
213
  // Set current revision ID
214
  self::$aryGlobalSettings['revision'] = self::$intRevisionId;
215
  self::$aryGlobalSettings['last_settings_update'] = time();
 
216
  // Save upgraded or default settings
217
  self::saveSettings();
218
  // Reload settings
303
  /**
304
  * Add pages to admin menu
305
  */
306
+ function buildAdminMenu() {
307
  // Show stats dashboard page if WP-Piwik is configured
308
  if (!empty(self::$aryGlobalSettings['piwik_token']) && !empty(self::$aryGlobalSettings['piwik_url'])) {
309
  // Add dashboard page
310
+ $this->intStatsPage = add_dashboard_page(
311
  __('Piwik Statistics', 'wp-piwik'),
312
  __('WP-Piwik', 'wp-piwik'),
313
  (!self::$bolWPMU?'wp-piwik_read_stats':'administrator'),
314
+ 'wp-piwik_stats',
315
+ array($this, 'showStats')
316
  );
317
  // Add required scripts
318
+ add_action('admin_print_scripts-'.$this->intStatsPage, array($this, 'load_scripts'));
319
  // Add required styles
320
+ add_action('admin_print_styles-'.$this->intStatsPage, array($this, 'add_admin_style'));
321
  // Add required header tags
322
+ add_action('admin_head-'.$this->intStatsPage, array($this, 'add_admin_header'));
323
+ // Stats page onload callback
324
+ add_action('load-'.$this->intStatsPage, array(&$this, 'onloadStatsPage'));
325
  }
326
  // Add options page if not multi-user
327
  if (!self::$bolWPMU)
349
  add_action('admin_print_styles-'.$intOptionsPage, array($this, 'add_admin_style'));
350
  }
351
 
352
+ /* Support two columns
353
+ seen in Heiko Rabe's metabox demo plugin
354
+ http://tinyurl.com/5r5vnzs */
355
+ function onScreenLayoutColumns($aryColumns, $strScreen) {
356
+ if ($strScreen == $this->intStatsPage)
357
+ $aryColumns[$this->intStatsPage] = 4;
358
+ return $aryColumns;
359
+ }
360
+
361
  function extend_wp_dashboard_setup() {
362
  if (current_user_can('wp-piwik_read_stats')) {
363
  if (self::$aryGlobalSettings['dashboard_widget'])
364
+ $this->add_wp_dashboard_widget();
365
+ if (self::$aryGlobalSettings['dashboard_chart']) {
 
 
 
 
366
  // Add required scripts
367
  add_action('admin_print_scripts-index.php', array($this, 'load_scripts'));
368
  // Add required styles
369
  add_action('admin_print_styles-index.php', array($this, 'add_admin_style'));
370
  // Add required header tags
371
  add_action('admin_head-index.php', array($this, 'add_admin_header'));
372
+ $this->add_wp_dashboard_chart();
 
 
 
 
373
  }
374
  }
375
  }
376
 
377
  function add_wp_dashboard_widget() {
378
+ $aryConfig = array(
379
  'params' => array(
380
  'period' => 'day',
381
  'date' => self::$aryGlobalSettings['dashboard_widget'],
383
  ),
384
  'inline' => true,
385
  );
386
+ $strFile = 'overview';
387
+ add_meta_box(
388
+ 'wp-piwik_stats-dashboard-overview',
389
+ __('WP-Piwik', 'wp-piwik').' - '.__(self::$aryGlobalSettings['dashboard_widget'], 'wp-piwik'),
390
+ array(&$this, 'createDashboardWidget'),
391
+ 'dashboard',
392
+ 'side',
393
+ 'high',
394
+ array('strFile' => $strFile, 'aryConfig' => $aryConfig)
395
+ );
396
  }
397
 
398
  /**
399
  * Add a visitor chart to the WordPress dashboard
400
  */
401
  function add_wp_dashboard_chart() {
402
+ $aryConfig = array(
403
  'params' => array(
404
  'period' => 'day',
405
  'date' => 'last30',
407
  ),
408
  'inline' => true,
409
  );
410
+ $strFile = 'visitors';
411
+ add_meta_box(
412
+ 'wp-piwik_stats-dashboard-chart',
413
+ __('WP-Piwik', 'wp-piwik').' - '.__('Visitors', 'wp-piwik'),
414
+ array(&$this, 'createDashboardWidget'),
415
+ 'dashboard',
416
+ 'side',
417
+ 'high',
418
+ array('strFile' => $strFile, 'aryConfig' => $aryConfig)
419
+ );
420
  }
421
 
422
  /**
424
  *
425
  * @see http://wpengineer.com/1295/meta-links-for-wordpress-plugins/
426
  */
427
+ function setPluginMeta($strLinks, $strFile) {
428
  // Get plugin basename
429
  $strPlugin = plugin_basename(__FILE__);
430
  // Add link just to this plugin's details
444
  */
445
  function load_scripts() {
446
  // Load WP-Piwik script
447
+ wp_enqueue_script('wp-piwik', $this->get_plugin_url().'js/wp-piwik.js', array(), self::$strVersion, true);
448
  // Load jqPlot
449
  wp_enqueue_script('wp-piwik-jqplot',$this->get_plugin_url().'js/jqplot/wp-piwik.jqplot.js',array('jquery'));
450
  }
561
  return array('js' => $strJavaScript, 'id' => self::$arySettings['site_id']);
562
  }
563
 
564
+ function createDashboardWidget($objPost, $aryMetabox) {
565
  $strDesc = $strID = '';
566
+ $aryConfig = $aryMetabox['args']['aryConfig'];
567
  foreach ($aryConfig['params'] as $strParam)
568
  if (!empty($strParam)) {
569
  $strDesc .= $strParam.', ';
570
  $strID .= '_'.$strParam;
571
  }
572
+ $strFile = str_replace('.', '', $aryMetabox['args']['strFile']);
573
  $aryConf = array_merge($aryConfig, array(
574
  'id' => $strFile.$strID,
575
  'desc' => substr($strDesc, 0, -2)));
588
  }
589
  }
590
 
591
+ function onloadStatsPage() {
592
+ wp_enqueue_script('common');
593
+ wp_enqueue_script('wp-lists');
594
+ wp_enqueue_script('postbox');
595
  $strToken = self::$aryGlobalSettings['piwik_token'];
596
  $strPiwikURL = self::$aryGlobalSettings['piwik_url'];
 
 
 
597
  $aryDashboard = array();
598
+ // Set default configuration
599
+ $arySortOrder = array(
600
+ 'side' => array(
601
+ 'overview' => array(__('Overview', 'wp-piwik'), 'day', 'yesterday'),
602
+ 'pages' => array(__('Pages', 'wp-piwik'), 'day', 'yesterday'),
603
+ 'keywords' => array(__('Keywords', 'wp-piwik'), 'day', 'yesterday', 10),
604
+ 'websites' => array(__('Websites', 'wp-piwik'), 'day', 'yesterday', 10),
605
+ 'plugins' => array(__('Plugins', 'wp-piwik'), 'day', 'yesterday')
606
+ ),
607
+ 'normal' => array(
608
+ 'visitors' => array(__('Visitors', 'wp-piwik'), 'day', 'last30'),
609
+ 'browsers' => array(__('Browser', 'wp-piwik'), 'day', 'yesterday'),
610
+ 'screens' => array(__('Resolution', 'wp-piwik'), 'day', 'yesterday'),
611
+ 'systems' => array(__('Operating System', 'wp-piwik'), 'day', 'yesterday')
612
+ )
613
+ );
614
+ foreach ($arySortOrder as $strCol => $aryWidgets) {
615
+ if (is_array($aryWidgets)) foreach ($aryWidgets as $strFile => $aryParams) {
616
+ $aryDashboard[$strCol][$strFile] = array(
 
 
 
 
 
 
 
 
 
 
 
 
617
  'params' => array(
618
+ 'title' => (isset($aryParams[0])?$aryParams[0]:$strFile),
619
  'period' => (isset($aryParams[1])?$aryParams[1]:''),
620
  'date' => (isset($aryParams[2])?$aryParams[2]:''),
621
  'limit' => (isset($aryParams[3])?$aryParams[3]:'')
622
+ )
 
623
  );
624
+ if (isset($_GET['date']) && preg_match('/^[0-9]{8}$/', $_GET['date']) && $strFile != 'visitors')
625
+ $aryDashboard[$strCol][$strFile]['params']['date'] = $_GET['date'];
626
+ elseif ($strFile != 'visitors')
627
+ $aryDashboard[$strCol][$strFile]['params']['date'] = self::$aryGlobalSettings['default_date'];
628
  }
629
  }
630
+ $intSideBoxCnt = $intContentBox = 0;
631
+ foreach ($aryDashboard['side'] as $strFile => $aryConfig) {
632
+ $intSideBoxCnt++;
633
+ add_meta_box(
634
+ 'wp-piwik_stats-sidebox-'.$intSideBoxCnt,
635
+ $aryConfig['params']['title'].' '.$aryConfig['params']['date'],
636
+ array(&$this, 'createDashboardWidget'),
637
+ $this->intStatsPage,
638
+ 'side',
639
+ 'core',
640
+ array('strFile' => $strFile, 'aryConfig' => $aryConfig)
641
+ );
642
+ }
643
+ foreach ($aryDashboard['normal'] as $strFile => $aryConfig) {
644
+ $intContentBox++;
645
+ add_meta_box(
646
+ 'wp-piwik_stats-contentbox-'.$intContentBox,
647
+ $aryConfig['params']['title'].' '.$aryConfig['params']['date'],
648
+ array(&$this, 'createDashboardWidget'),
649
+ $this->intStatsPage,
650
+ 'normal',
651
+ 'core',
652
+ array('strFile' => $strFile, 'aryConfig' => $aryConfig)
653
+ );
654
+ }
655
+ }
656
+
657
+ function showStats() {
658
+ //we need the global screen column value to be able to have a sidebar in WordPress 2.8
659
+ global $screen_layout_columns;
660
  /***************************************************************************/ ?>
661
+ <div id="wp-piwik-stats-general" class="wrap">
662
+ <?php screen_icon('options-general'); ?>
663
  <h2><?php _e('Piwik Statistics', 'wp-piwik'); ?></h2>
664
  <?php /************************************************************************/
 
665
  if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
666
  if (isset($_POST['wpmu_show_stats']))
667
+ switch_to_blog((int) $_POST['wpmu_show_stats']);
 
668
  global $blog_id;
669
  global $wpdb;
670
  $aryBlogs = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM '.$wpdb->prefix.'blogs ORDER BY blog_id'));
679
  else _e('Current shown stats: <strong>Overall</strong>');
680
  echo '</form>'."\n";
681
  }
 
 
 
 
 
 
 
 
 
682
  /***************************************************************************/ ?>
683
+ <form action="admin-post.php" method="post">
684
+ <?php wp_nonce_field('wp-piwik_stats-general'); ?>
685
+ <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
686
+ <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
687
+ <input type="hidden" name="action" value="save_wp-piwik_stats_general" />
688
+ <div id="poststuff" class="metabox-holder has-right-sidebar" style="width:<?php echo 528+281; ?>px;">
689
+ <div id="side-info-column" class="inner-sidebar wp-piwik-side">
690
+ <?php do_meta_boxes($this->intStatsPage, 'side', $data); ?>
691
  </div>
692
+ <div id="post-body" class="has-sidebar">
693
+ <div id="post-body-content" class="postbox-container has-sidebar-content">
694
+ <?php $meta_boxes = do_meta_boxes($this->intStatsPage, 'normal', $data); ?>
 
 
 
 
 
 
 
 
695
  </div>
696
  </div>
697
+ <br class="clear"/>
698
+ </div>
699
+ </form>
700
  </div>
701
+ <script type="text/javascript">
702
+ //<![CDATA[
703
+ jQuery(document).ready( function($) {
704
+ // close postboxes that should be closed
705
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
706
+ // postboxes setup
707
+ postboxes.add_postbox_toggles('<?php echo $this->intStatsPage; ?>');
708
+ });
709
+ //]]>
710
+ </script>
711
  <?php /************************************************************************/
712
  if (self::$bolWPMU && function_exists('is_super_admin') && is_super_admin()) {
713
  restore_current_blog(); self::$bolOverall = false;
714
  }
715
  }
716
 
717
+ /* Stats page changes by POST submit
718
+ seen in Heiko Rabe's metabox demo plugin
719
+ http://tinyurl.com/5r5vnzs */
720
+ function onStatsPageSaveChanges() {
721
+ //user permission check
722
+ if ( !current_user_can('manage_options') )
723
+ wp_die( __('Cheatin&#8217; uh?') );
724
+ //cross check the given referer
725
+ check_admin_referer('wp-piwik_stats');
726
+ //process here your on $_POST validation and / or option saving
727
+ //lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
728
+ wp_redirect($_POST['_wp_http_referer']);
729
+ }
730
+
731
  function applySettings() {
732
  if (!self::$bolWPMU) {
733
  self::$aryGlobalSettings['add_tracking_code'] = (isset($_POST['wp-piwik_addjs'])?$_POST['wp-piwik_addjs']:'');
975
  echo '</div>';
976
  echo '<div class="wp-piwik_desc">'.
977
  __('Choose users by user role you do <strong>not</strong> want to track.', 'wp-piwik').'</div>';
 
 
 
 
 
 
 
 
 
 
 
978
  }
979
  /***************************************************************************/ ?>
980
  <div><input type="submit" name="Submit" value="<?php _e('Save settings', 'wp-piwik') ?>" /></div>
998
  <script type="text/javascript">
999
  var flattr_url = 'http://www.braekling.de/wp-piwik-wpmu-piwik-wordpress';
1000
  </script>
1001
+ <script src="http<?php echo (self::isSSL()?'s':''); ?>://api.flattr.com/button/load.js" type="text/javascript"></script>
1002
  </div>
1003
  <div>Paypal
1004
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
1015
  <?php /************************************************************************/
1016
  }
1017
 
1018
+ private static function isSSL() {
1019
+ return (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off');
1020
+ }
1021
+
1022
  function credits() {
1023
  /***************************************************************************/ ?>
1024
  <h2 style="clear:left;"><?php _e('Credits', 'wp-piwik'); ?></h2>
1025
  <div class="inside">
1026
  <p><strong><?php _e('Thank you very much for your donation', 'wp-piwik'); ?>:</strong> Marco L., Rolf W., Tobias U., Lars K., Donna F. <?php _e('and all people flattering this','wp-piwik'); ?>!</p>
1027
  <p><?php _e('Graphs powered by <a href="http://www.jqplot.com/">jqPlot</a>, an open source project by Chris Leonello. Give it a try! (License: GPL 2.0 and MIT)','wp-piwik'); ?></p>
1028
+ <p><?php _e('Metabox support inspired by <a href="http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins">Heiko Rabe\'s metabox demo plugin</a>.')?></p>
1029
  <p><?php _e('Thank you very much','wp-piwik'); ?>, <a href="http://blogu.programeshqip.org/">Besnik Bleta</a>, <a href="http://www.fatcow.com/">FatCow</a>, <a href="http://www.pamukkaleturkey.com/">Rene</a>, Fab, <a href="http://ezbizniz.com/">EzBizNiz</a>, Gormer, Natalya, <a href="www.aggeliopolis.gr">AggelioPolis</a><?php _e(', and', 'wp-piwik'); ?> <a href="http://wwww.webhostinggeeks.com">Galina Miklosic</a> <?php _e('for your translation work','wp-piwik'); ?>!</p>
1030
  <p><?php _e('Thank you very much, all users who send me mails containing criticism, commendation, feature requests and bug reports! You help me to make WP-Piwik much better.','wp-piwik'); ?></p>
1031
  <p><?php _e('Thank <strong>you</strong> for using my plugin. It is the best commendation if my piece of code is really used!','wp-piwik'); ?></p>