updated plugin Connect Matomo version 1.1.5
This commit is contained in:
@ -1,70 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class BrowserDetails extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class BrowserDetails extends Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Browser Details', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicesDetection.getBrowserVersions';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Browser', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Browser Details', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getBrowserVersions';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Browser', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,73 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Browsers extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Browsers extends Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Browsers', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicesDetection.getBrowsers';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Browser', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
elseif ($count == $this->limit) {
|
||||
$class['Others'] = $js['Others'] = '';
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Browsers', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getBrowsers';
|
||||
$this->context = 'normal';
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Browser', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
} elseif ( $count === $this->limit ) {
|
||||
$css_class['Others'] = '';
|
||||
$js['Others'] = '';
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,85 +4,97 @@ namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Chart extends Visitors
|
||||
{
|
||||
class Chart extends Visitors {
|
||||
|
||||
public $className = __CLASS__;
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
public function show()
|
||||
{
|
||||
$result = $this->requestData();
|
||||
$response = $result["response"];
|
||||
if (!$result["success"]) {
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response[$method]['message'], ENT_QUOTES, 'utf-8');
|
||||
} else {
|
||||
$values = $labels = $bounced = $unique = '';
|
||||
$count = $uniqueSum = 0;
|
||||
if (is_array($response['VisitsSummary.getVisits']))
|
||||
foreach ($response['VisitsSummary.getVisits'] as $date => $value) {
|
||||
$count++;
|
||||
$values .= $value . ',';
|
||||
$unique .= $response['VisitsSummary.getUniqueVisitors'][$date] . ',';
|
||||
$bounced .= $response['VisitsSummary.getBounceCount'][$date] . ',';
|
||||
if ($this->parameter['period'] == 'week') {
|
||||
preg_match("/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date, $dateList);
|
||||
$textKey = $this->dateFormat($dateList[0], 'short_week');
|
||||
} else $textKey = substr($date, -2);
|
||||
$labels .= '["' . $textKey . '"],';
|
||||
$uniqueSum += $response['VisitsSummary.getActions'][$date];
|
||||
}
|
||||
else {
|
||||
$values = '0,';
|
||||
$labels = '[0,"-"],';
|
||||
$unique = '0,';
|
||||
$bounced = '0,';
|
||||
}
|
||||
$average = round($uniqueSum / 30, 0);
|
||||
$values = substr($values, 0, -1);
|
||||
$unique = substr($unique, 0, -1);
|
||||
$labels = substr($labels, 0, -1);
|
||||
$bounced = substr($bounced, 0, -1);
|
||||
?>
|
||||
<div>
|
||||
<canvas id="wp-piwik_stats_vistors_graph" style="height:220px;"></canvas>
|
||||
</div>
|
||||
<script>
|
||||
new Chart(
|
||||
document.getElementById('wp-piwik_stats_vistors_graph'),
|
||||
{
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: [<?php echo $labels ?>],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Visitors',
|
||||
backgroundColor: '#0277bd',
|
||||
borderColor: '#0277bd',
|
||||
data: [<?php echo $values; ?>],
|
||||
borderWidth: 1
|
||||
},
|
||||
{
|
||||
label: 'Unique',
|
||||
backgroundColor: '#ff8f00',
|
||||
borderColor: '#ff8f00',
|
||||
data: [<?php echo $unique; ?>],
|
||||
borderWidth: 1
|
||||
},
|
||||
{
|
||||
label: 'Bounced',
|
||||
backgroundColor: '#ad1457',
|
||||
borderColor: '#ad1457',
|
||||
data: [<?php echo $bounced; ?>],
|
||||
borderWidth: 1
|
||||
},
|
||||
]
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
public function show() {
|
||||
$result = $this->request_data();
|
||||
$response = $result['response'];
|
||||
if ( ! $result['success'] ) {
|
||||
$message = '';
|
||||
if ( is_array( $this->method ) ) {
|
||||
foreach ( $this->method as $m ) {
|
||||
if ( empty( $response[ $m ]['message'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$message .= ' ' . $m . ' - ' . $response[ $m ]['message'];
|
||||
}
|
||||
} else {
|
||||
$message = $response[ $this->method ]['message'];
|
||||
}
|
||||
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $message );
|
||||
} else {
|
||||
$values = array();
|
||||
$labels = array();
|
||||
$bounced = array();
|
||||
$unique = array();
|
||||
$count = 0;
|
||||
$unique_sum = 0;
|
||||
if ( is_array( $response['VisitsSummary.getVisits'] ) ) {
|
||||
foreach ( $response['VisitsSummary.getVisits'] as $date => $value ) {
|
||||
++$count;
|
||||
$values [] = $value;
|
||||
$unique [] = $response['VisitsSummary.getUniqueVisitors'][ $date ];
|
||||
$bounced [] = $response['VisitsSummary.getBounceCount'][ $date ];
|
||||
if ( 'week' === $this->parameter['period'] ) {
|
||||
preg_match( '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $date, $date_list );
|
||||
$text_key = $this->date_format( $date_list[0], 'short_week' );
|
||||
} else {
|
||||
$text_key = substr( $date, -2 );
|
||||
}
|
||||
$labels [] = array( $text_key );
|
||||
$unique_sum += $response['VisitsSummary.getActions'][ $date ];
|
||||
}
|
||||
} else {
|
||||
$values = array( 0 );
|
||||
$labels = array( array( 0, '-' ) );
|
||||
$unique = array( 0 );
|
||||
$bounced = array( 0 );
|
||||
}
|
||||
$average = round( $unique_sum / 30, 0 );
|
||||
?>
|
||||
<div>
|
||||
<canvas id="wp-piwik_stats_vistors_graph" style="height:220px;"></canvas>
|
||||
</div>
|
||||
<script>
|
||||
new Chart(
|
||||
document.getElementById('wp-piwik_stats_vistors_graph'),
|
||||
{
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: <?php echo wp_json_encode( $labels ); ?>,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Visitors',
|
||||
backgroundColor: '#0277bd',
|
||||
borderColor: '#0277bd',
|
||||
data: <?php echo wp_json_encode( $values ); ?>,
|
||||
borderWidth: 1
|
||||
},
|
||||
{
|
||||
label: 'Unique',
|
||||
backgroundColor: '#ff8f00',
|
||||
borderColor: '#ff8f00',
|
||||
data: <?php echo wp_json_encode( $unique ); ?>,
|
||||
borderWidth: 1
|
||||
},
|
||||
{
|
||||
label: 'Bounced',
|
||||
backgroundColor: '#ad1457',
|
||||
borderColor: '#ad1457',
|
||||
data: <?php echo wp_json_encode( $bounced ); ?>,
|
||||
borderWidth: 1
|
||||
},
|
||||
]
|
||||
},
|
||||
options: {}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,73 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class City extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class City extends Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Cities', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'UserCountry.getCity';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('City', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
elseif ($count == $this->limit) {
|
||||
$class['Others'] = $js['Others'] = '';
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Cities', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'UserCountry.getCity';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'City', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
} elseif ( $count === $this->limit ) {
|
||||
$css_class['Others'] = '';
|
||||
$js['Others'] = '';
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,70 +4,80 @@
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Country extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Country extends Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Countries', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'UserCountry.getCountry ';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Country', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
elseif ($count == $this->limit) {
|
||||
$class['Others'] = $js['Others'] = '';
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Countries', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'UserCountry.getCountry ';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Country', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
} elseif ( $count === $this->limit ) {
|
||||
$css_class['Others'] = '';
|
||||
$js['Others'] = '';
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,50 +2,52 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Ecommerce extends \WP_Piwik\Widget
|
||||
{
|
||||
class Ecommerce extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array())
|
||||
{
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->title = $prefix . __('E-Commerce', 'wp-piwik');
|
||||
$this->method = 'Goals.get';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
public function show()
|
||||
{
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] = 'error')
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = null;
|
||||
$revenue = is_float($this->value($response, 'revenue')) ? number_format($this->value($response, 'revenue'), 2) : "";
|
||||
$revenue_new = is_float($this->value($response, 'revenue_new_visit')) ? number_format($this->value($response, 'revenue_new_visit'), 2) : "";
|
||||
$revenue_return = is_float($this->value($response, 'revenue_returning_visit')) ? number_format($this->value($response, 'revenue_returning_visit'), 2) : "";
|
||||
$tableBody = array(
|
||||
array(__('Conversions', 'wp-piwik') . ':', $this->value($response, 'nb_conversions')),
|
||||
array(__('Visits converted', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted')),
|
||||
array(__('Revenue', 'wp-piwik') . ':', $revenue),
|
||||
array(__('Conversion rate', 'wp-piwik') . ':', $this->value($response, 'conversion_rate')),
|
||||
array(__('Conversions (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_new_visit')),
|
||||
array(__('Visits converted (new visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_new_visit')),
|
||||
array(__('Revenue (new visitor)', 'wp-piwik') . ':', $revenue_new),
|
||||
array(__('Conversion rate (new visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_new_visit')),
|
||||
array(__('Conversions (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_conversions_returning_visit')),
|
||||
array(__('Visits converted (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'nb_visits_converted_returning_visit')),
|
||||
array(__('Revenue (returning visitor)', 'wp-piwik') . ':', $revenue_return),
|
||||
array(__('Conversion rate (returning visitor)', 'wp-piwik') . ':', $this->value($response, 'conversion_rate_returning_visit')),
|
||||
);
|
||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '">Piwik</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
||||
$this->table($tableHead, $tableBody, $tableFoot);
|
||||
}
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->title = $prefix . __( 'E-Commerce', 'wp-piwik' );
|
||||
$this->method = 'Goals.get';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = null;
|
||||
$revenue = is_numeric( $this->value( $response, 'revenue' ) ) ? number_format( (float) $this->value( $response, 'revenue' ), 2 ) : '';
|
||||
$revenue_new = is_numeric( $this->value( $response, 'revenue_new_visit' ) ) ? number_format( (float) $this->value( $response, 'revenue_new_visit' ), 2 ) : '';
|
||||
$revenue_return = is_numeric( $this->value( $response, 'revenue_returning_visit' ) ) ? number_format( (float) $this->value( $response, 'revenue_returning_visit' ), 2 ) : '';
|
||||
$table_body = array(
|
||||
array( __( 'Conversions', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions' ) ),
|
||||
array( __( 'Visits converted', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted' ) ),
|
||||
array( __( 'Revenue', 'wp-piwik' ) . ':', $revenue ),
|
||||
array( __( 'Conversion rate', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate' ) ),
|
||||
array( __( 'Conversions (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions_new_visit' ) ),
|
||||
array( __( 'Visits converted (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted_new_visit' ) ),
|
||||
array( __( 'Revenue (new visitor)', 'wp-piwik' ) . ':', $revenue_new ),
|
||||
array( __( 'Conversion rate (new visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate_new_visit' ) ),
|
||||
array( __( 'Conversions (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_conversions_returning_visit' ) ),
|
||||
array( __( 'Visits converted (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits_converted_returning_visit' ) ),
|
||||
array( __( 'Revenue (returning visitor)', 'wp-piwik' ) . ':', $revenue_return ),
|
||||
array( __( 'Conversion rate (returning visitor)', 'wp-piwik' ) . ':', $this->value( $response, 'conversion_rate_returning_visit' ) ),
|
||||
);
|
||||
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||
? array(
|
||||
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '">Piwik</a>',
|
||||
)
|
||||
: null;
|
||||
$this->table( $table_head, $table_body, $table_foot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Items extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Items extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->title = $prefix.__('E-Commerce Items', 'wp-piwik');
|
||||
$this->method = 'Goals.getItemsName';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(
|
||||
__('Label', 'wp-piwik'),
|
||||
__('Revenue', 'wp-piwik'),
|
||||
__('Quantity', 'wp-piwik'),
|
||||
__('Orders', 'wp-piwik'),
|
||||
__('Avg. price', 'wp-piwik'),
|
||||
__('Avg. quantity', 'wp-piwik'),
|
||||
__('Conversion rate', 'wp-piwik'),
|
||||
);
|
||||
$tableBody = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $data) {
|
||||
array_push($tableBody, array(
|
||||
$data['label'],
|
||||
number_format($data['revenue'],2),
|
||||
$data['quantity'],
|
||||
$data['orders'],
|
||||
number_format($data['avg_price'],2),
|
||||
$data['avg_quantity'],
|
||||
$data['conversion_rate']
|
||||
));
|
||||
}
|
||||
$tableFoot = array();
|
||||
$this->table($tableHead, $tableBody, $tableFoot);
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->title = $prefix . __( 'E-Commerce Items', 'wp-piwik' );
|
||||
$this->method = 'Goals.getItemsName';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array(
|
||||
__( 'Label', 'wp-piwik' ),
|
||||
__( 'Revenue', 'wp-piwik' ),
|
||||
__( 'Quantity', 'wp-piwik' ),
|
||||
__( 'Orders', 'wp-piwik' ),
|
||||
__( 'Avg. price', 'wp-piwik' ),
|
||||
__( 'Avg. quantity', 'wp-piwik' ),
|
||||
__( 'Conversion rate', 'wp-piwik' ),
|
||||
);
|
||||
$table_body = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $data ) {
|
||||
array_push(
|
||||
$table_body,
|
||||
array(
|
||||
$data['label'],
|
||||
number_format( $data['revenue'], 2 ),
|
||||
$data['quantity'],
|
||||
$data['orders'],
|
||||
number_format( $data['avg_price'], 2 ),
|
||||
$data['avg_quantity'],
|
||||
$data['conversion_rate'],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$table_foot = array();
|
||||
$this->table( $table_head, $table_body, $table_foot );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,49 +4,52 @@ namespace WP_Piwik\Widget;
|
||||
|
||||
class ItemsCategory extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->title = $prefix.__('E-Commerce Item Categories', 'wp-piwik');
|
||||
$this->method = 'Goals.getItemsCategory';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->title = $prefix . __( 'E-Commerce Item Categories', 'wp-piwik' );
|
||||
$this->method = 'Goals.getItemsCategory';
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(
|
||||
__('Label', 'wp-piwik'),
|
||||
__('Revenue', 'wp-piwik'),
|
||||
__('Quantity', 'wp-piwik'),
|
||||
__('Orders', 'wp-piwik'),
|
||||
__('Avg. price', 'wp-piwik'),
|
||||
__('Avg. quantity', 'wp-piwik'),
|
||||
__('Conversion rate', 'wp-piwik'),
|
||||
);
|
||||
$tableBody = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $data) {
|
||||
array_push($tableBody, array(
|
||||
$data['label'],
|
||||
isset($data['revenue'])?number_format($data['revenue'],2):"-.--",
|
||||
isset($data['quantity'])?$data['quantity']:'-',
|
||||
isset($data['orders'])?$data['orders']:'-',
|
||||
number_format($data['avg_price'],2),
|
||||
$data['avg_quantity'],
|
||||
$data['conversion_rate']
|
||||
));
|
||||
}
|
||||
$tableFoot = array();
|
||||
$this->table($tableHead, $tableBody, $tableFoot);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array(
|
||||
__( 'Label', 'wp-piwik' ),
|
||||
__( 'Revenue', 'wp-piwik' ),
|
||||
__( 'Quantity', 'wp-piwik' ),
|
||||
__( 'Orders', 'wp-piwik' ),
|
||||
__( 'Avg. price', 'wp-piwik' ),
|
||||
__( 'Avg. quantity', 'wp-piwik' ),
|
||||
__( 'Conversion rate', 'wp-piwik' ),
|
||||
);
|
||||
$table_body = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $data ) {
|
||||
array_push(
|
||||
$table_body,
|
||||
array(
|
||||
$data['label'],
|
||||
isset( $data['revenue'] ) ? number_format( $data['revenue'], 2 ) : '-.--',
|
||||
isset( $data['quantity'] ) ? $data['quantity'] : '-',
|
||||
isset( $data['orders'] ) ? $data['orders'] : '-',
|
||||
number_format( $data['avg_price'], 2 ),
|
||||
$data['avg_quantity'],
|
||||
$data['conversion_rate'],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$table_foot = array();
|
||||
$this->table( $table_head, $table_body, $table_foot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Keywords extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Keywords extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Keywords', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Referrers.getKeywords';
|
||||
$this->name = 'Keyword';
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Keywords', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Referrers.getKeywords';
|
||||
$this->name = 'Keyword';
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,73 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Models extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Models extends Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Models', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicesDetection.getModel';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Model', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array(htmlentities($row['label']), $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
elseif ($count == $this->limit) {
|
||||
$class['Others'] = $js['Others'] = '';
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Models', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getModel';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Model', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( htmlentities( $row['label'] ), $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
} elseif ( $count === $this->limit ) {
|
||||
$css_class['Others'] = '';
|
||||
$js['Others'] = '';
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,37 +2,42 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Noresult extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Noresult extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Site Search', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Actions.getSiteSearchNoResultKeywords';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Keyword', 'wp-piwik'), __('Requests', 'wp-piwik'), __('Bounced', 'wp-piwik'));
|
||||
$tableBody = array();
|
||||
$count = 0;
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$tableBody[] = array($row['label'], $row['nb_visits'], $row['bounce_rate']);
|
||||
if ($count == 10) break;
|
||||
}
|
||||
$this->table($tableHead, $tableBody, null);
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Site Search', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Actions.getSiteSearchNoResultKeywords';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if (
|
||||
! empty( $response['result'] )
|
||||
&& 'error' === $response['result']
|
||||
) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Keyword', 'wp-piwik' ), __( 'Requests', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ) );
|
||||
$table_body = array();
|
||||
$count = 0;
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$table_body[] = array( $row['label'], $row['nb_visits'], $row['bounce_rate'] );
|
||||
if ( 10 === $count ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->table( $table_head, $table_body, null );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,37 +2,34 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class OptOut extends \WP_Piwik\Widget
|
||||
{
|
||||
class OptOut extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array())
|
||||
{
|
||||
$this->parameter = $params;
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$this->parameter = $params;
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$protocol = (isset ($_SERVER ['HTTPS']) && $_SERVER ['HTTPS'] != 'off') ? 'https' : 'http';
|
||||
switch (self::$settings->getGlobalOption('piwik_mode')) {
|
||||
case 'php' :
|
||||
$PIWIK_URL = $protocol . ':' . self::$settings->getGlobalOption('proxy_url');
|
||||
break;
|
||||
case 'cloud' :
|
||||
$PIWIK_URL = 'https://' . self::$settings->getGlobalOption('piwik_user') . '.innocraft.cloud/';
|
||||
break;
|
||||
case 'cloud-matomo':
|
||||
$PIWIK_URL = 'https://' . self::$settings->getGlobalOption('matomo_user') . '.matomo.cloud/';
|
||||
break;
|
||||
default :
|
||||
$PIWIK_URL = self::$settings->getGlobalOption('piwik_url');
|
||||
}
|
||||
$width = (isset($this->parameter['width']) ? esc_attr($this->parameter['width']) : '');
|
||||
$height = (isset($this->parameter['height']) ? esc_attr($this->parameter['height']) : '');
|
||||
$idSite = (isset($this->parameter['idsite']) ? 'idsite=' . (int)$this->parameter['idsite'] . '&' : '');
|
||||
$language = (isset($this->parameter['language']) ? esc_attr($this->parameter['language']) : 'en');
|
||||
$this->out('<iframe frameborder="no" width="' . $width . '" height="' . $height . '" src="' . $PIWIK_URL . 'index.php?module=CoreAdminHome&action=optOut&' . $idSite . 'language=' . $language . '"></iframe>');
|
||||
}
|
||||
|
||||
}
|
||||
public function show() {
|
||||
$protocol = ( isset( $_SERVER ['HTTPS'] ) && 'off' !== $_SERVER ['HTTPS'] ) ? 'https' : 'http';
|
||||
switch ( self::$settings->get_global_option( 'piwik_mode' ) ) {
|
||||
case 'php':
|
||||
$piwik_url = $protocol . ':' . self::$settings->get_global_option( 'proxy_url' );
|
||||
break;
|
||||
case 'cloud':
|
||||
$piwik_url = 'https://' . self::$settings->get_global_option( 'piwik_user' ) . '.innocraft.cloud/';
|
||||
break;
|
||||
case 'cloud-matomo':
|
||||
$piwik_url = 'https://' . self::$settings->get_global_option( 'matomo_user' ) . '.matomo.cloud/';
|
||||
break;
|
||||
default:
|
||||
$piwik_url = self::$settings->get_global_option( 'piwik_url' );
|
||||
break;
|
||||
}
|
||||
$width = ( isset( $this->parameter['width'] ) ? rawurlencode( $this->parameter['width'] ) : '' );
|
||||
$height = ( isset( $this->parameter['height'] ) ? rawurlencode( $this->parameter['height'] ) : '' );
|
||||
$idsite = ( isset( $this->parameter['idsite'] ) ? 'idsite=' . (int) $this->parameter['idsite'] . '&' : '' );
|
||||
$language = ( isset( $this->parameter['language'] ) ? rawurlencode( $this->parameter['language'] ) : 'en' );
|
||||
$this->out( '<iframe frameborder="no" width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '" src="' . esc_attr( $piwik_url . 'index.php?module=CoreAdminHome&action=optOut&' . $idsite . 'language=' . $language ) . '"></iframe>' );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,65 +2,76 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Overview extends \WP_Piwik\Widget
|
||||
{
|
||||
class Overview extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array())
|
||||
{
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
||||
'date' => isset($params['date']) ? $params['date'] : $timeSettings['date'],
|
||||
'description' => $timeSettings['description']
|
||||
);
|
||||
$this->title = !$this->isShortcode ? $prefix . __('Overview', 'wp-piwik') . ' (' . __($this->pageId == 'dashboard' ? $this->rangeName() : $timeSettings['description'], 'wp-piwik') . ')' : ($params['title'] ? $params['title'] : '');
|
||||
$this->method = 'VisitsSummary.get';
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||
'date' => isset( $params['date'] ) ? $params['date'] : $time_settings['date'],
|
||||
'description' => $time_settings['description'],
|
||||
);
|
||||
$this->title = ! $this->is_shortcode ? $prefix . __( 'Overview', 'wp-piwik' ) . ' (' . ( 'dashboard' === $this->page_id ? $this->range_name() : $time_settings['description'] ) . ')' : ( $params['title'] ? $params['title'] : '' );
|
||||
$this->method = 'VisitsSummary.get';
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] = 'error')
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
if (in_array($this->parameter['date'], array('last30', 'last60', 'last90'))) {
|
||||
$result = array();
|
||||
if (is_array($response)) {
|
||||
foreach ($response as $data)
|
||||
foreach ($data as $key => $value)
|
||||
if (isset($result[$key]) && is_numeric($value))
|
||||
$result[$key] += $value;
|
||||
elseif (is_numeric($value))
|
||||
$result[$key] = $value;
|
||||
else
|
||||
$result[$key] = 0;
|
||||
if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
|
||||
$result['nb_actions_per_visit'] = round($result['nb_actions'] / $result['nb_visits'], 1);
|
||||
$result['bounce_rate'] = round($result['bounce_count'] / $result['nb_visits'] * 100, 1) . '%';
|
||||
$result['avg_time_on_site'] = round($result['sum_visit_length'] / $result['nb_visits'], 0);
|
||||
} else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
|
||||
}
|
||||
$response = $result;
|
||||
}
|
||||
$time = isset($response['sum_visit_length']) ? $this->timeFormat($response['sum_visit_length']) : '-';
|
||||
$avgTime = isset($response['avg_time_on_site']) ? $this->timeFormat($response['avg_time_on_site']) : '-';
|
||||
$tableHead = null;
|
||||
$tableBody = array(array(__('Visitors', 'wp-piwik') . ':', $this->value($response, 'nb_visits')));
|
||||
if ($this->value($response, 'nb_uniq_visitors') != '-')
|
||||
array_push($tableBody, array(__('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'nb_uniq_visitors')));
|
||||
array_push($tableBody,
|
||||
array(__('Page views', 'wp-piwik') . ':', $this->value($response, 'nb_actions') . ' (Ø ' . $this->value($response, 'nb_actions_per_visit') . ')'),
|
||||
array(__('Total time spent', 'wp-piwik') . ':', $time . ' (Ø ' . $avgTime . ')'),
|
||||
array(__('Bounce count', 'wp-piwik') . ':', $this->value($response, 'bounce_count') . ' (' . $this->value($response, 'bounce_rate') . ')')
|
||||
);
|
||||
if (!in_array($this->parameter['date'], array('last30', 'last60', 'last90')))
|
||||
array_push($tableBody, array(__('Time/visit', 'wp-piwik') . ':', $avgTime), array(__('Max. page views in one visit', 'wp-piwik') . ':', $this->value($response, 'max_actions')));
|
||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '" target="_BLANK">Matomo</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
||||
$this->table($tableHead, $tableBody, $tableFoot);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
if ( in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||
$result = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $data ) {
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( isset( $result[ $key ] ) && is_numeric( $value ) ) {
|
||||
$result[ $key ] += $value;
|
||||
} elseif ( is_numeric( $value ) ) {
|
||||
$result[ $key ] = $value;
|
||||
} else {
|
||||
$result[ $key ] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( isset( $result['nb_visits'] ) && $result['nb_visits'] > 0 ) {
|
||||
$result['nb_actions_per_visit'] = round( $result['nb_actions'] / $result['nb_visits'], 1 );
|
||||
$result['bounce_rate'] = round( $result['bounce_count'] / $result['nb_visits'] * 100, 1 ) . '%';
|
||||
$result['avg_time_on_site'] = round( $result['sum_visit_length'] / $result['nb_visits'], 0 );
|
||||
} else {
|
||||
$result['nb_actions_per_visit'] = 0;
|
||||
$result['bounce_rate'] = 0;
|
||||
$result['avg_time_on_site'] = 0;
|
||||
}
|
||||
}
|
||||
$response = $result;
|
||||
}
|
||||
$time = isset( $response['sum_visit_length'] ) ? $this->time_format( $response['sum_visit_length'] ) : '-';
|
||||
$avg_time = isset( $response['avg_time_on_site'] ) ? $this->time_format( $response['avg_time_on_site'] ) : '-';
|
||||
$table_head = null;
|
||||
$table_body = array( array( __( 'Visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits' ) ) );
|
||||
if ( '-' !== $this->value( $response, 'nb_uniq_visitors' ) ) {
|
||||
array_push( $table_body, array( __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_uniq_visitors' ) ) );
|
||||
}
|
||||
array_push(
|
||||
$table_body,
|
||||
array( __( 'Page views', 'wp-piwik' ) . ':', $this->value( $response, 'nb_actions' ) . ' (Ø ' . $this->value( $response, 'nb_actions_per_visit' ) . ')' ),
|
||||
array( __( 'Total time spent', 'wp-piwik' ) . ':', $time . ' (Ø ' . $avg_time . ')' ),
|
||||
array( __( 'Bounce count', 'wp-piwik' ) . ':', $this->value( $response, 'bounce_count' ) . ' (' . $this->value( $response, 'bounce_rate' ) . ')' )
|
||||
);
|
||||
if ( ! in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||
array_push( $table_body, array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ), array( __( 'Max. page views in one visit', 'wp-piwik' ) . ':', $this->value( $response, 'max_actions' ) ) );
|
||||
}
|
||||
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||
? array(
|
||||
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '" target="_BLANK">Matomo</a>',
|
||||
)
|
||||
: null;
|
||||
$this->table( $table_head, $table_body, $table_foot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Pages extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Pages extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Pages', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Actions.getPageTitles';
|
||||
$this->name = __('Page', 'wp-piwik' );
|
||||
}
|
||||
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Pages', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Actions.getPageTitles';
|
||||
$this->name = __( 'Page', 'wp-piwik' );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,38 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Plugins extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Plugins extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Plugins', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicePlugins.getPlugin';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Plugin', 'wp-piwik'), __('Visits', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
$tableBody = array();
|
||||
$count = 0;
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$tableBody[] = array($row['label'], $row['nb_visits'], $row['nb_visits_percentage']);
|
||||
if ($count == 10) break;
|
||||
}
|
||||
$this->table($tableHead, $tableBody, null);
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Plugins', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicePlugins.getPlugin';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Plugin', 'wp-piwik' ), __( 'Visits', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
$table_body = array();
|
||||
$count = 0;
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$table_body[] = array( $row['label'], $row['nb_visits'], $row['nb_visits_percentage'] );
|
||||
if ( 10 === $count ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->table( $table_head, $table_body, null );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,82 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Post extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Post extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
global $post;
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
||||
'date' => isset($params['date']) ? $params['date'] : $timeSettings['date'],
|
||||
'key' => isset($params['key'])?$params['key']:null,
|
||||
'pageUrl' => isset($params['url'])?$params['url']:urlencode(get_permalink($post->ID)),
|
||||
'description' => $timeSettings['description']
|
||||
);
|
||||
$this->title = $prefix.__('Overview', 'wp-piwik').' ('.__($this->parameter['date'],'wp-piwik').')';
|
||||
$this->method = 'Actions.getPageUrl';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] = 'error')
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
if (in_array($this->parameter['date'], array('last30', 'last60', 'last90'))) {
|
||||
$result = array();
|
||||
if (is_array($response)) {
|
||||
foreach ($response as $data) {
|
||||
if (isset($data[0])) {
|
||||
foreach ($data[0] as $key => $value)
|
||||
if (isset($result[$key]) && is_numeric($value))
|
||||
$result[$key] += $value;
|
||||
elseif (is_numeric($value))
|
||||
$result[$key] = $value;
|
||||
else
|
||||
$result[$key] = 0;
|
||||
}
|
||||
}
|
||||
if (isset($result['nb_visits']) && $result['nb_visits'] > 0) {
|
||||
$result['nb_actions_per_visit'] = round((isset( $result['nb_actions'] ) ? $result['nb_actions'] : 0) / $result['nb_visits'], 1);
|
||||
$result['bounce_rate'] = round((isset($result['bounce_count']) ? $result['bounce_count'] : 0) / $result['nb_visits'] * 100, 1) . '%';
|
||||
$result['avg_time_on_site'] = round((isset($result['sum_visit_length']) ? $result['sum_visit_length'] : 0) / $result['nb_visits'], 0);
|
||||
} else $result['nb_actions_per_visit'] = $result['bounce_rate'] = $result['avg_time_on_site'] = 0;
|
||||
}
|
||||
$response = $result;
|
||||
} else {
|
||||
if (isset($response[0]))
|
||||
$response = $response[0];
|
||||
if ($this->parameter['key']) {
|
||||
$this->out(isset($response[$this->parameter['key']])?$response[$this->parameter['key']]:'<em>not defined</em>');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$time = isset($response['sum_visit_length']) ? $this->timeFormat($response['sum_visit_length']) : '-';
|
||||
$avgTime = isset($response['avg_time_on_site']) ? $this->timeFormat($response['avg_time_on_site']) : '-';
|
||||
$tableHead = null;
|
||||
$tableBody = array(array(__('Visitors', 'wp-piwik') . ':', $this->value($response, 'nb_visits')));
|
||||
if ($this->value($response, 'nb_uniq_visitors') != '-')
|
||||
array_push($tableBody, array(__('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'nb_uniq_visitors')));
|
||||
elseif ($this->value($response, 'sum_daily_nb_uniq_visitors') != '-') {
|
||||
array_push($tableBody, __('Unique visitors', 'wp-piwik') . ':', $this->value($response, 'sum_daily_nb_uniq_visitors'));
|
||||
}
|
||||
array_push($tableBody,
|
||||
array(__('Page views', 'wp-piwik').':', $this->value($response, 'nb_hits').' (Ø '.$this->value($response, 'entry_nb_actions').')'),
|
||||
array(__('Total time spent', 'wp-piwik').':', $time),
|
||||
array(__('Bounce count', 'wp-piwik').':', $this->value($response, 'entry_bounce_count').' ('.$this->value($response, 'bounce_rate').')'),
|
||||
array(__('Time/visit', 'wp-piwik').':', $avgTime),
|
||||
array(__('Min. generation time', 'wp-piwik').':', $this->value($response, 'min_time_generation')),
|
||||
array(__('Max. generation time', 'wp-piwik').':', $this->value($response, 'max_time_generation'))
|
||||
);
|
||||
if (!in_array($this->parameter['date'], array('last30', 'last60', 'last90')))
|
||||
array_push($tableBody, array(__('Time/visit', 'wp-piwik') . ':', $avgTime), array(__('Max. page views in one visit', 'wp-piwik') . ':', $this->value($response, 'max_actions')));
|
||||
$tableFoot = (self::$settings->getGlobalOption('piwik_shortcut') ? array(__('Shortcut', 'wp-piwik') . ':', '<a href="' . self::$settings->getGlobalOption('piwik_url') . '">Piwik</a>' . (isset($aryConf['inline']) && $aryConf['inline'] ? ' - <a href="?page=wp-piwik_stats">WP-Piwik</a>' : '')) : null);
|
||||
$this->table($tableHead, $tableBody, $tableFoot);
|
||||
}
|
||||
}
|
||||
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
global $post;
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||
'date' => isset( $params['date'] ) ? $params['date'] : $time_settings['date'],
|
||||
'key' => isset( $params['key'] ) ? $params['key'] : null,
|
||||
'pageUrl' => isset( $params['url'] ) ? $params['url'] : get_permalink( $post->ID ),
|
||||
'description' => $time_settings['description'],
|
||||
);
|
||||
$this->title = $prefix . esc_html__( 'Overview', 'wp-piwik' ) . ' (' . $this->parameter['date'] . ')';
|
||||
$this->method = 'Actions.getPageUrl';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
if ( in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||
$result = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $data ) {
|
||||
if ( isset( $data[0] ) ) {
|
||||
foreach ( $data[0] as $key => $value ) {
|
||||
if ( isset( $result[ $key ] ) && is_numeric( $value ) ) {
|
||||
$result[ $key ] += $value;
|
||||
} elseif ( is_numeric( $value ) ) {
|
||||
$result[ $key ] = $value;
|
||||
} else {
|
||||
$result[ $key ] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( isset( $result['nb_visits'] ) && $result['nb_visits'] > 0 ) {
|
||||
$result['nb_actions_per_visit'] = round( ( isset( $result['nb_actions'] ) ? $result['nb_actions'] : 0 ) / $result['nb_visits'], 1 );
|
||||
$result['bounce_rate'] = round( ( isset( $result['bounce_count'] ) ? $result['bounce_count'] : 0 ) / $result['nb_visits'] * 100, 1 ) . '%';
|
||||
$result['avg_time_on_site'] = round( ( isset( $result['sum_visit_length'] ) ? $result['sum_visit_length'] : 0 ) / $result['nb_visits'], 0 );
|
||||
} else {
|
||||
$result['nb_actions_per_visit'] = 0;
|
||||
$result['bounce_rate'] = 0;
|
||||
$result['avg_time_on_site'] = 0;
|
||||
}
|
||||
}
|
||||
$response = $result;
|
||||
} else {
|
||||
if ( isset( $response[0] ) ) {
|
||||
$response = $response[0];
|
||||
}
|
||||
if ( $this->parameter['key'] ) {
|
||||
$this->out( isset( $response[ $this->parameter['key'] ] ) ? esc_html( $response[ $this->parameter['key'] ] ) : '<em>not defined</em>' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
$time = isset( $response['sum_visit_length'] ) ? $this->time_format( $response['sum_visit_length'] ) : '-';
|
||||
$avg_time = isset( $response['avg_time_on_site'] ) ? $this->time_format( $response['avg_time_on_site'] ) : '-';
|
||||
$table_head = null;
|
||||
$table_body = array( array( __( 'Visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_visits' ) ) );
|
||||
if ( '-' !== $this->value( $response, 'nb_uniq_visitors' ) ) {
|
||||
array_push( $table_body, array( __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'nb_uniq_visitors' ) ) );
|
||||
} elseif ( '-' !== $this->value( $response, 'sum_daily_nb_uniq_visitors' ) ) {
|
||||
array_push( $table_body, __( 'Unique visitors', 'wp-piwik' ) . ':', $this->value( $response, 'sum_daily_nb_uniq_visitors' ) );
|
||||
}
|
||||
array_push(
|
||||
$table_body,
|
||||
array( __( 'Page views', 'wp-piwik' ) . ':', $this->value( $response, 'nb_hits' ) . ' (Ø ' . $this->value( $response, 'entry_nb_actions' ) . ')' ),
|
||||
array( __( 'Total time spent', 'wp-piwik' ) . ':', $time ),
|
||||
array( __( 'Bounce count', 'wp-piwik' ) . ':', $this->value( $response, 'entry_bounce_count' ) . ' (' . $this->value( $response, 'bounce_rate' ) . ')' ),
|
||||
array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ),
|
||||
array( __( 'Min. generation time', 'wp-piwik' ) . ':', $this->value( $response, 'min_time_generation' ) ),
|
||||
array( __( 'Max. generation time', 'wp-piwik' ) . ':', $this->value( $response, 'max_time_generation' ) )
|
||||
);
|
||||
if ( ! in_array( $this->parameter['date'], array( 'last30', 'last60', 'last90' ), true ) ) {
|
||||
array_push( $table_body, array( __( 'Time/visit', 'wp-piwik' ) . ':', $avg_time ), array( __( 'Max. page views in one visit', 'wp-piwik' ) . ':', $this->value( $response, 'max_actions' ) ) );
|
||||
}
|
||||
$table_foot = self::$settings->get_global_option( 'piwik_shortcut' )
|
||||
? array(
|
||||
esc_html__( 'Shortcut', 'wp-piwik' ) . ':',
|
||||
'<a href="' . esc_attr( self::$settings->get_global_option( 'piwik_url' ) ) . '">Piwik</a>',
|
||||
)
|
||||
: null;
|
||||
$this->table( $table_head, $table_body, $table_foot );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,20 +2,19 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Referrers extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Referrers extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Referrers', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Referrers.getWebsites';
|
||||
$this->name = 'Referrer';
|
||||
}
|
||||
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Referrers', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Referrers.getWebsites';
|
||||
$this->name = 'Referrer';
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,68 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Screens extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Screens extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Resolutions', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Resolution.getResolution';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Resolution', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Resolutions', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Resolution.getResolution';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Resolution', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,38 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Search extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Search extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Site Search', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'Actions.getSiteSearchKeywords';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Keyword', 'wp-piwik'), __('Requests', 'wp-piwik'), __('Bounced', 'wp-piwik'));
|
||||
$tableBody = array();
|
||||
$count = 0;
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$tableBody[] = array(htmlentities($row['label']), $row['nb_visits'], $row['bounce_rate']);
|
||||
if ($count == 10) break;
|
||||
}
|
||||
$this->table($tableHead, $tableBody, null);
|
||||
}
|
||||
}
|
||||
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Site Search', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'Actions.getSiteSearchKeywords';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Keyword', 'wp-piwik' ), __( 'Requests', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ) );
|
||||
$table_body = array();
|
||||
$count = 0;
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$table_body[] = array( $row['label'], $row['nb_visits'], $row['bounce_rate'] );
|
||||
if ( 10 === $count ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->table( $table_head, $table_body, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,31 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Seo extends \WP_Piwik\Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
class Seo extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$this->parameter = array(
|
||||
'url' => get_bloginfo('url')
|
||||
);
|
||||
$this->title = $prefix.__('SEO', 'wp-piwik');
|
||||
$this->method = 'SEO.getRank';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
echo '<div class="table"><table class="widefat"><tbody>';
|
||||
if (is_array($response))
|
||||
foreach ($response as $val)
|
||||
echo '<tr><td>'.(isset($val['logo_link']) && !empty($val['logo_link'])?'<a href="'.$val['logo_link'].'" title="'.$val['logo_tooltip'].'">'.$val['label'].'</a>':$val['label']).'</td><td>'.$val['rank'].'</td></tr>';
|
||||
else echo '<tr><td>SEO module currently not available.</td></tr>';
|
||||
echo '</tbody></table></div>';
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$this->parameter = array(
|
||||
'url' => get_bloginfo( 'url' ),
|
||||
);
|
||||
$this->title = $prefix . __( 'SEO', 'wp-piwik' );
|
||||
$this->method = 'SEO.getRank';
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
echo '<div class="table"><table class="widefat"><tbody>';
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $val ) {
|
||||
echo '<tr><td>' . ( isset( $val['logo_link'] ) && ! empty( $val['logo_link'] ) ? '<a href="' . esc_attr( $val['logo_link'] ) . '" title="' . esc_attr( $val['logo_tooltip'] ) . '">' . esc_html( $val['label'] ) . '</a>' : esc_html( $val['label'] ) ) . '</td><td>' . esc_html( $val['rank'] ) . '</td></tr>';
|
||||
}
|
||||
} else {
|
||||
echo '<tr><td>SEO module currently not available.</td></tr>';
|
||||
}
|
||||
echo '</tbody></table></div>';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,66 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class SystemDetails extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Operation System Details', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicesDetection.getOsVersions';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Operation System', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
class SystemDetails extends \WP_Piwik\Widget {
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Operation System Details', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getOsVersions';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Operation System', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,65 +2,75 @@
|
||||
|
||||
namespace WP_Piwik\Widget;
|
||||
|
||||
class Systems extends \WP_Piwik\Widget {
|
||||
|
||||
protected function configure($prefix = '', $params = array()) {
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix.__('Operation Systems', 'wp-piwik').' ('.__($timeSettings['description'],'wp-piwik').')';
|
||||
$this->method = 'DevicesDetection.getOsFamilies';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL().'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script ( 'wp-piwik-chartjs', self::$wpPiwik->getPluginURL () . 'js/chartjs/chart.min.js', "3.4.1" );
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL().'css/wp-piwik.css',array(),self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] ='error')
|
||||
echo '<strong>'.__('Piwik error', 'wp-piwik').':</strong> '.htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Operation System', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) $unique = 'nb_uniq_visitors';
|
||||
else $unique = 'sum_daily_nb_uniq_visitors';
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$count++;
|
||||
$sum += isset($row[$unique])?$row[$unique]:0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$unique], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$unique];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$unique], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j'."( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit)
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
class Systems extends \WP_Piwik\Widget {
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1]/$sum*100, 2).'%';
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Operation Systems', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getOsFamilies';
|
||||
$this->context = 'normal';
|
||||
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Operation System', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
++$count;
|
||||
$sum += isset( $row[ $unique ] ) ? $row[ $unique ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $unique ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $unique ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
}
|
||||
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,77 +4,81 @@ namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Types extends Widget
|
||||
{
|
||||
class Types extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array())
|
||||
{
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => $timeSettings['period'],
|
||||
'date' => $timeSettings['date']
|
||||
);
|
||||
$this->title = $prefix . __('Types', 'wp-piwik') . ' (' . __($timeSettings['description'], 'wp-piwik') . ')';
|
||||
$this->method = 'DevicesDetection.getType';
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL() . 'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script('wp-piwik-chartjs', self::$wpPiwik->getPluginURL() . 'js/chartjs/chart.min.js', "3.4.1");
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL() . 'css/wp-piwik.css', array(), self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
public function show()
|
||||
{
|
||||
$response = self::$wpPiwik->request($this->apiID[$this->method]);
|
||||
$tableBody = array();
|
||||
if (!empty($response['result']) && $response['result'] = 'error')
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response['message'], ENT_QUOTES, 'utf-8');
|
||||
else {
|
||||
$tableHead = array(__('Type', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Percent', 'wp-piwik'));
|
||||
if (isset($response[0]['nb_uniq_visitors'])) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$class = array();
|
||||
if (is_array($response))
|
||||
foreach ($response as $row) {
|
||||
$key = isset($row[$unique]) ? $unique : "nb_visits";
|
||||
$count++;
|
||||
$sum += isset($row[$key]) ? $row[$key] : 0;
|
||||
if ($count < $this->limit)
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
||||
elseif (!isset($tableBody['Others'])) {
|
||||
$tableBody['Others'] = array($row['label'], $row[$key], 0);
|
||||
$class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$tableBody['Others'][1] += $row[$key];
|
||||
$tableBody[$row['label']] = array($row['label'], $row[$key], 0);
|
||||
$class[$row['label']] = 'wp-piwik-hideDetails hidden';
|
||||
$js[$row['label']] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
if ($count > $this->limit) {
|
||||
$tableBody['Others'][0] = __('Others', 'wp-piwik');
|
||||
} elseif ($count == $this->limit) {
|
||||
$class['Others'] = $js['Others'] = '';
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => $time_settings['period'],
|
||||
'date' => $time_settings['date'],
|
||||
);
|
||||
$this->title = $prefix . __( 'Types', 'wp-piwik' ) . ' (' . $time_settings['description'] . ')';
|
||||
$this->method = 'DevicesDetection.getType';
|
||||
$this->context = 'normal';
|
||||
|
||||
foreach ($tableBody as $key => $row)
|
||||
$tableBody[$key][2] = number_format($row[1] / $sum * 100, 2) . '%';
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
if (!empty($tableBody)) $this->pieChart($tableBody);
|
||||
$this->table($tableHead, $tableBody, null, false, $js, $class);
|
||||
}
|
||||
}
|
||||
public function show() {
|
||||
$response = self::$wp_piwik->request( $this->api_id[ $this->method ] );
|
||||
$table_body = array();
|
||||
if ( ! empty( $response['result'] ) && 'error' === $response['result'] ) {
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $response['message'] );
|
||||
} else {
|
||||
$table_head = array( __( 'Type', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Percent', 'wp-piwik' ) );
|
||||
if ( isset( $response[0]['nb_uniq_visitors'] ) ) {
|
||||
$unique = 'nb_uniq_visitors';
|
||||
} else {
|
||||
$unique = 'sum_daily_nb_uniq_visitors';
|
||||
}
|
||||
$count = 0;
|
||||
$sum = 0;
|
||||
$js = array();
|
||||
$css_class = array();
|
||||
if ( is_array( $response ) ) {
|
||||
foreach ( $response as $row ) {
|
||||
$key = isset( $row[ $unique ] ) ? $unique : 'nb_visits';
|
||||
++$count;
|
||||
$sum += isset( $row[ $key ] ) ? $row[ $key ] : 0;
|
||||
if ( $count < $this->limit ) {
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||
} elseif ( ! isset( $table_body['Others'] ) ) {
|
||||
$table_body['Others'] = array( $row['label'], $row[ $key ], 0 );
|
||||
$css_class['Others'] = 'wp-piwik-hideDetails';
|
||||
$js['Others'] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
} else {
|
||||
$table_body['Others'][1] += $row[ $key ];
|
||||
$table_body[ $row['label'] ] = array( $row['label'], $row[ $key ], 0 );
|
||||
$css_class[ $row['label'] ] = 'wp-piwik-hideDetails hidden';
|
||||
$js[ $row['label'] ] = '$j' . "( '.wp-piwik-hideDetails' ).toggle( 'hidden' );";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $count > $this->limit ) {
|
||||
$table_body['Others'][0] = __( 'Others', 'wp-piwik' );
|
||||
} elseif ( $count === $this->limit ) {
|
||||
$css_class['Others'] = '';
|
||||
$js['Others'] = '';
|
||||
}
|
||||
|
||||
}
|
||||
foreach ( $table_body as $key => $row ) {
|
||||
$table_body[ $key ][2] = number_format( $row[1] / $sum * 100, 2 ) . '%';
|
||||
}
|
||||
|
||||
if ( ! empty( $table_body ) ) {
|
||||
$this->pie_chart( $table_body );
|
||||
}
|
||||
$this->table( $table_head, $table_body, null, false, $js, $css_class );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,76 +4,97 @@ namespace WP_Piwik\Widget;
|
||||
|
||||
use WP_Piwik\Widget;
|
||||
|
||||
class Visitors extends Widget
|
||||
{
|
||||
class Visitors extends Widget {
|
||||
|
||||
public $className = __CLASS__;
|
||||
public $class_name = __CLASS__;
|
||||
|
||||
protected function configure($prefix = '', $params = array())
|
||||
{
|
||||
$timeSettings = $this->getTimeSettings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wpPiwik->getPiwikSiteId($this->blogId),
|
||||
'period' => isset($params['period']) ? $params['period'] : $timeSettings['period'],
|
||||
'date' => 'last' . ($timeSettings['period'] == 'day' ? '30' : '12'),
|
||||
'limit' => null
|
||||
);
|
||||
$this->title = $prefix . __('Visitors', 'wp-piwik') . ' (' . __($this->rangeName(), 'wp-piwik') . ')';
|
||||
$this->method = array('VisitsSummary.getVisits', 'VisitsSummary.getUniqueVisitors', 'VisitsSummary.getBounceCount', 'VisitsSummary.getActions');
|
||||
$this->context = 'normal';
|
||||
wp_enqueue_script('wp-piwik', self::$wpPiwik->getPluginURL() . 'js/wp-piwik.js', array(), self::$wpPiwik->getPluginVersion(), true);
|
||||
wp_enqueue_script('wp-piwik-chartjs', self::$wpPiwik->getPluginURL() . 'js/chartjs/chart.min.js', "3.4.1");
|
||||
wp_enqueue_style('wp-piwik', self::$wpPiwik->getPluginURL() . 'css/wp-piwik.css', array(), self::$wpPiwik->getPluginVersion());
|
||||
}
|
||||
protected function configure( $prefix = '', $params = array() ) {
|
||||
$time_settings = $this->get_time_settings();
|
||||
$this->parameter = array(
|
||||
'idSite' => self::$wp_piwik->get_piwik_site_id( $this->blog_id ),
|
||||
'period' => isset( $params['period'] ) ? $params['period'] : $time_settings['period'],
|
||||
'date' => 'last' . ( 'day' === $time_settings['period'] ? '30' : '12' ),
|
||||
'limit' => null,
|
||||
);
|
||||
$this->title = $prefix . __( 'Visitors', 'wp-piwik' ) . ' (' . $this->range_name() . ')';
|
||||
$this->method = array( 'VisitsSummary.getVisits', 'VisitsSummary.getUniqueVisitors', 'VisitsSummary.getBounceCount', 'VisitsSummary.getActions' );
|
||||
$this->context = 'normal';
|
||||
|
||||
public function requestData()
|
||||
{
|
||||
$response = array();
|
||||
$success = true;
|
||||
foreach ($this->method as $method) {
|
||||
$response[$method] = self::$wpPiwik->request($this->apiID[$method]);
|
||||
if (!empty($response[$method]['result']) && $response[$method]['result'] = 'error')
|
||||
$success = false;
|
||||
}
|
||||
return array("response" => $response, "success" => $success);
|
||||
}
|
||||
$version = self::$wp_piwik->get_plugin_version();
|
||||
wp_enqueue_script( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'js/wp-piwik.js', array(), $version, true );
|
||||
wp_enqueue_script( 'wp-piwik-chartjs', self::$wp_piwik->get_plugin_url() . 'js/chartjs/chart.min.js', array(), $version, false );
|
||||
wp_enqueue_style( 'wp-piwik', self::$wp_piwik->get_plugin_url() . 'css/wp-piwik.css', array(), $version );
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$result = $this->requestData();
|
||||
$response = $result["response"];
|
||||
if (!$result["success"]) {
|
||||
echo '<strong>' . __('Piwik error', 'wp-piwik') . ':</strong> ' . htmlentities($response[$method]['message'], ENT_QUOTES, 'utf-8');
|
||||
} else {
|
||||
$data = array();
|
||||
if (is_array($response) && is_array($response['VisitsSummary.getVisits']))
|
||||
foreach ($response['VisitsSummary.getVisits'] as $key => $value) {
|
||||
if ($this->parameter['period'] == 'week') {
|
||||
preg_match("/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $key, $dateList);
|
||||
$jsKey = $dateList[0];
|
||||
$textKey = $this->dateFormat($jsKey, 'week');
|
||||
} elseif ($this->parameter['period'] == 'month') {
|
||||
$jsKey = $key . '-01';
|
||||
$textKey = $key;
|
||||
} else $jsKey = $textKey = $key;
|
||||
$data[] = array(
|
||||
$textKey,
|
||||
$value,
|
||||
$response['VisitsSummary.getUniqueVisitors'][$key] ? $response['VisitsSummary.getUniqueVisitors'][$key] : '-',
|
||||
$response['VisitsSummary.getBounceCount'][$key] ? $response['VisitsSummary.getBounceCount'][$key] : '-',
|
||||
$response['VisitsSummary.getActions'][$key] ? $response['VisitsSummary.getActions'][$key] : '-'
|
||||
);
|
||||
$javaScript[] = 'javascript:wp_piwik_datelink(\'' . urlencode('wp-piwik_stats') . '\',\'' . str_replace('-', '', $jsKey) . '\',\'' . (isset($_GET['wpmu_show_stats']) ? (int)$_GET['wpmu_show_stats'] : '') . '\');';
|
||||
}
|
||||
$this->table(
|
||||
array(__('Date', 'wp-piwik'), __('Visits', 'wp-piwik'), __('Unique', 'wp-piwik'), __('Bounced', 'wp-piwik'), __('Page Views', 'wp-piwik')),
|
||||
array_reverse($data),
|
||||
array(),
|
||||
'clickable',
|
||||
array_reverse(isset($javaScript) ? $javaScript : [])
|
||||
);
|
||||
}
|
||||
public function request_data() {
|
||||
$response = array();
|
||||
$success = true;
|
||||
foreach ( $this->method as $method ) {
|
||||
$response[ $method ] = self::$wp_piwik->request( $this->api_id[ $method ] );
|
||||
if ( ! empty( $response[ $method ]['result'] ) && 'error' === $response[ $method ]['result'] ) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'response' => $response,
|
||||
'success' => $success,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
public function show() {
|
||||
$result = $this->request_data();
|
||||
$response = $result['response'];
|
||||
if ( ! $result['success'] ) {
|
||||
$message = '';
|
||||
if ( is_array( $this->method ) ) {
|
||||
foreach ( $this->method as $m ) {
|
||||
if ( empty( $response[ $m ]['message'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
$message .= ' ' . $m . ' - ' . $response[ $m ]['message'];
|
||||
}
|
||||
} else {
|
||||
$message = $response[ $this->method ]['message'];
|
||||
}
|
||||
|
||||
echo '<strong>' . esc_html__( 'Piwik error', 'wp-piwik' ) . ':</strong> ' . esc_html( $message );
|
||||
} else {
|
||||
$data = array();
|
||||
if ( is_array( $response ) && is_array( $response['VisitsSummary.getVisits'] ) ) {
|
||||
foreach ( $response['VisitsSummary.getVisits'] as $key => $value ) {
|
||||
if ( 'week' === $this->parameter['period'] ) {
|
||||
preg_match( '/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $key, $date_list );
|
||||
$js_key = $date_list[0];
|
||||
$text_key = $this->date_format( $js_key, 'week' );
|
||||
} elseif ( 'month' === $this->parameter['period'] ) {
|
||||
$js_key = $key . '-01';
|
||||
$text_key = $key;
|
||||
} else {
|
||||
$js_key = $key;
|
||||
$text_key = $key;
|
||||
}
|
||||
$data[] = array(
|
||||
$text_key,
|
||||
$value,
|
||||
$response['VisitsSummary.getUniqueVisitors'][ $key ] ? $response['VisitsSummary.getUniqueVisitors'][ $key ] : '-',
|
||||
$response['VisitsSummary.getBounceCount'][ $key ] ? $response['VisitsSummary.getBounceCount'][ $key ] : '-',
|
||||
$response['VisitsSummary.getActions'][ $key ] ? $response['VisitsSummary.getActions'][ $key ] : '-',
|
||||
);
|
||||
$java_script[] = 'javascript:wp_piwik_datelink('
|
||||
. wp_json_encode( rawurlencode( 'wp-piwik_stats' ) ) . ','
|
||||
. wp_json_encode( str_replace( '-', '', $js_key ) ) . ','
|
||||
. wp_json_encode( isset( $_GET['wpmu_show_stats'] ) ? (int) $_GET['wpmu_show_stats'] : '' )
|
||||
. ');';
|
||||
}
|
||||
}
|
||||
$this->table(
|
||||
array( __( 'Date', 'wp-piwik' ), __( 'Visits', 'wp-piwik' ), __( 'Unique', 'wp-piwik' ), __( 'Bounced', 'wp-piwik' ), __( 'Page Views', 'wp-piwik' ) ),
|
||||
array_reverse( $data ),
|
||||
array(),
|
||||
'clickable',
|
||||
array_reverse( isset( $java_script ) ? $java_script : array() )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user