本文整理汇总了PHP中GADWP_Tools类的典型用法代码示例。如果您正苦于以下问题:PHP GADWP_Tools类的具体用法?PHP GADWP_Tools怎么用?PHP GADWP_Tools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GADWP_Tools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tracking_code
public function tracking_code()
{
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_track_exclude'], true) || $this->gadwp->config->options['ga_dash_excludesa'] && current_user_can('manage_network')) {
return;
}
$traking_mode = $this->gadwp->config->options['ga_dash_tracking'];
$traking_type = $this->gadwp->config->options['ga_dash_tracking_type'];
if ($traking_mode > 0) {
if (!$this->gadwp->config->options['ga_dash_tableid_jail']) {
return;
}
if ($traking_type == "classic") {
echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Classic Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
if ($this->gadwp->config->options['ga_event_tracking']) {
require_once 'tracking/events-classic.php';
}
require_once 'tracking/code-classic.php';
echo "\n<!-- END GADWP Classic Tracking -->\n\n";
} else {
echo "\n<!-- BEGIN GADWP v" . GADWP_CURRENT_VERSION . " Universal Tracking - https://deconf.com/google-analytics-dashboard-wordpress/ -->\n";
if ($this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking']) {
require_once 'tracking/events-universal.php';
}
require_once 'tracking/code-universal.php';
echo "\n<!-- END GADWP Universal Tracking -->\n\n";
}
}
}
示例2: __construct
public function __construct()
{
$this->gadwp = GADWP();
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['dashboard_widget']) {
add_action('wp_dashboard_setup', array($this, 'add_widget'));
}
}
示例3: load_styles_scripts
/**
* Styles & Scripts conditional loading
*
* @param
* $hook
*/
public function load_styles_scripts()
{
$lang = get_bloginfo('language');
$lang = explode('-', $lang);
$lang = $lang[0];
/*
* Item reports Styles & Scripts
*/
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) {
wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
wp_enqueue_style('gadwp-frontend-item-reports', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION);
$country_codes = GADWP_Tools::get_countrycodes();
if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
$region = $this->gadwp->config->options['ga_target_geomap'];
} else {
$region = false;
}
wp_enqueue_style("wp-jquery-ui-dialog");
if (!wp_script_is('googlejsapi')) {
wp_register_script('googlejsapi', 'https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22visualization%22%2C%22version%22%3A%221%22%2C%22language%22%3A%22' . $lang . '%22%2C%22packages%22%3A%5B%22corechart%22%2C%20%22table%22%2C%20%22orgchart%22%2C%20%22geochart%22%5D%7D%5D%7D%27', array(), null);
}
wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'common/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION);
wp_enqueue_script('gadwp-frontend-item-reports', GADWP_URL . 'common/js/reports.js', array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION);
/* @formatter:off */
wp_localize_script('gadwp-frontend-item-reports', 'gadwpItemData', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_frontend_item_reports'), 'dateList' => array('today' => __("Today", 'google-analytics-dashboard-for-wp'), 'yesterday' => __("Yesterday", 'google-analytics-dashboard-for-wp'), '7daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 7), '14daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 14), '30daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 30), '90daysAgo' => sprintf(__("Last %d Days", 'google-analytics-dashboard-for-wp'), 90), '365daysAgo' => sprintf(_n("%s Year", "%s Years", 1, 'google-analytics-dashboard-for-wp'), __('One', 'google-analytics-dashboard-for-wp')), '1095daysAgo' => sprintf(_n("%s Year", "%s Years", 3, 'google-analytics-dashboard-for-wp'), __('Three', 'google-analytics-dashboard-for-wp'))), 'reportList' => array('uniquePageviews' => __("Unique Views", 'google-analytics-dashboard-for-wp'), 'users' => __("Users", 'google-analytics-dashboard-for-wp'), 'organicSearches' => __("Organic", 'google-analytics-dashboard-for-wp'), 'pageviews' => __("Page Views", 'google-analytics-dashboard-for-wp'), 'visitBounceRate' => __("Bounce Rate", 'google-analytics-dashboard-for-wp'), 'locations' => __("Location", 'google-analytics-dashboard-for-wp'), 'referrers' => __("Referrers", 'google-analytics-dashboard-for-wp'), 'searches' => __("Searches", 'google-analytics-dashboard-for-wp'), 'trafficdetails' => __("Traffic", 'google-analytics-dashboard-for-wp'), 'technologydetails' => __("Technology", 'google-analytics-dashboard-for-wp')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'google-analytics-dashboard-for-wp'), __("Traffic Mediums", 'google-analytics-dashboard-for-wp'), __("Visitor Type", 'google-analytics-dashboard-for-wp'), __("Search Engines", 'google-analytics-dashboard-for-wp'), __("Social Networks", 'google-analytics-dashboard-for-wp'), __("Unique Views", 'google-analytics-dashboard-for-wp'), __("Users", 'google-analytics-dashboard-for-wp'), __("Page Views", 'google-analytics-dashboard-for-wp'), __("Bounce Rate", 'google-analytics-dashboard-for-wp'), __("Organic Search", 'google-analytics-dashboard-for-wp'), __("Pages/Session", 'google-analytics-dashboard-for-wp'), __("Invalid response, more details in JavaScript Console (F12).", 'google-analytics-dashboard-for-wp'), __("Not enough data collected", 'google-analytics-dashboard-for-wp'), __("This report is unavailable", 'google-analytics-dashboard-for-wp'), __("report generated by", 'google-analytics-dashboard-for-wp'), __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . ' <strong>' . __("authorize the plugin", 'google-analytics-dashboard-for-wp') . '</strong>!', __("Browser", 'google-analytics-dashboard-for-wp'), __("Operating System", 'google-analytics-dashboard-for-wp'), __("Screen Resolution", 'google-analytics-dashboard-for-wp'), __("Mobile Brand", 'google-analytics-dashboard-for-wp')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region, 'language' => get_bloginfo('language'), 'filter' => $_SERVER["REQUEST_URI"], 'viewList' => false, 'scope' => 'front-item'));
/* @formatter:on */
}
}
示例4: load_styles_scripts
/**
* Styles & Scripts conditional loading
*
* @param
* $hook
*/
public function load_styles_scripts()
{
/*
* GADWP main stylesheet
*/
wp_enqueue_style('ga_dash-front', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION);
/*
* Item reports Styles & Scripts
*/
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) {
wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
wp_enqueue_style('gadwp_frontend_item_reports', GADWP_URL . 'front/css/item-reports.css', null, GADWP_CURRENT_VERSION);
$country_codes = GADWP_Tools::get_countrycodes();
if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
$region = $this->gadwp->config->options['ga_target_geomap'];
} else {
$region = false;
}
wp_enqueue_style("wp-jquery-ui-dialog");
if (!wp_script_is('googlejsapi')) {
wp_register_script('googlejsapi', 'https://www.google.com/jsapi');
}
wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION);
wp_enqueue_script('gadwp_frontend_item_reports', plugins_url('js/item-reports.js', __FILE__), array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION);
/* @formatter:off */
wp_localize_script('gadwp_frontend_item_reports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_frontend_item_reports'), 'dateList' => array('today' => __("Today", 'ga-dash'), 'yesterday' => __("Yesterday", 'ga-dash'), '7daysAgo' => __("Last 7 Days", 'ga-dash'), '30daysAgo' => __("Last 30 Days", 'ga-dash'), '90daysAgo' => __("Last 90 Days", 'ga-dash')), 'reportList' => array('uniquePageviews' => __("Unique Views", 'ga-dash'), 'users' => __("Users", 'ga-dash'), 'organicSearches' => __("Organic", 'ga-dash'), 'pageviews' => __("Page Views", 'ga-dash'), 'visitBounceRate' => __("Bounce Rate", 'ga-dash'), 'locations' => __("Location", 'ga-dash'), 'referrers' => __("Referrers", 'ga-dash'), 'searches' => __("Searches", 'ga-dash'), 'trafficdetails' => __("Traffic Details", 'ga-dash')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'ga-dash'), __("Traffic Mediums", 'ga-dash'), __("Visitor Type", 'ga-dash'), __("Social Networks", 'ga-dash'), __("Search Engines", 'ga-dash'), __("Unique Views", 'ga-dash'), __("Users", 'ga-dash'), __("Page Views", 'ga-dash'), __("Bounce Rate", 'ga-dash'), __("Organic Search", 'ga-dash'), __("Pages/Session", 'ga-dash'), __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'), __("Not enough data collected", 'ga-dash'), __("This report is unavailable", 'ga-dash'), __("report generated by", 'ga-dash')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region));
/* @formatter:on */
}
}
示例5: ajax_set_error
/**
* Ajax handler for storing JavaScript Errors
*
* @return json|int
*/
public function ajax_set_error()
{
if (!isset($_POST['gadwp_security_set_error']) || !(wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_backend_item_reports') || wp_verify_nonce($_POST['gadwp_security_set_error'], 'gadwp_frontend_item_reports'))) {
wp_die(-40);
}
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($_POST['response']), 24 * 60 * 60);
wp_die();
}
示例6: custom_adminbar_node
function custom_adminbar_node($wp_admin_bar)
{
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) && $this->gadwp->config->options['frontend_item_reports']) {
/* @formatter:off */
$args = array('id' => 'gadwp-1', 'title' => '<span class="ab-icon"></span><span class="">' . __("Analytics", 'ga-dash') . '</span>', 'href' => '#1');
/* @formatter:on */
$wp_admin_bar->add_node($args);
}
}
示例7: ajax_item_reports
/**
* Ajax handler for Item Reports
*
* @return json|int
*/
public function ajax_item_reports()
{
if (!isset($_REQUEST['gadwp_security_backend_item_reports']) || !wp_verify_nonce($_REQUEST['gadwp_security_backend_item_reports'], 'gadwp_backend_item_reports')) {
wp_die(-30);
}
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$query = $_REQUEST['query'];
if (isset($_REQUEST['filter'])) {
$filter_id = $_REQUEST['filter'];
} else {
$filter_id = false;
}
if (ob_get_length()) {
ob_clean();
}
if (!GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['backend_item_reports']) {
wp_die(-31);
}
if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to) {
if (null === $this->gadwp->gapi_controller) {
$this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
}
} else {
wp_die(-24);
}
$projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
$profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
if (isset($profile_info[4])) {
$this->gadwp->gapi_controller->timeshift = $profile_info[4];
} else {
$this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
}
if ($filter_id) {
$uri_parts = explode('/', get_permalink($filter_id), 4);
if (isset($uri_parts[3])) {
$uri = '/' . $uri_parts[3];
} else {
wp_die(-25);
}
// allow URL correction before sending an API request
$filter = apply_filters('gadwp_backenditem_uri', $uri);
$lastchar = substr($filter, -1);
if (isset($profile_info[6]) && $profile_info[6] && $lastchar == '/') {
$filter = $filter . $profile_info[6];
}
// Encode URL
$filter = rawurlencode(rawurldecode($filter));
}
$queries = explode(',', $query);
$results = array();
foreach ($queries as $value) {
$results[] = $this->gadwp->gapi_controller->get($projectId, $value, $from, $to, $filter);
}
wp_send_json($results);
}
示例8: __construct
public function __construct()
{
$this->gadwp = GADWP();
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['backend_item_reports']) {
// Add custom column in Posts List
add_filter('manage_posts_columns', array($this, 'add_columns'));
// Populate custom column in Posts List
add_action('manage_posts_custom_column', array($this, 'add_icons'), 10, 2);
// Add custom column in Pages List
add_filter('manage_pages_columns', array($this, 'add_columns'));
// Populate custom column in Pages List
add_action('manage_pages_custom_column', array($this, 'add_icons'), 10, 2);
}
}
示例9: uninstall
public static function uninstall()
{
global $wpdb;
if (is_multisite()) {
// Cleanup Network install
foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) {
switch_to_blog($blog['blog_id']);
$sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gadwp_cache_%%'");
delete_option('gadash_options');
restore_current_blog();
}
delete_site_option('gadash_network_options');
} else {
// Cleanup Single install
$sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'gadwp_cache_%%'");
delete_option('gadash_options');
}
GADWP_Tools::unset_cookie('default_metric');
GADWP_Tools::unset_cookie('default_dimension');
GADWP_Tools::unset_cookie('default_view');
}
示例10: get_realtime
/**
* Analytics data for backend reports (Real-Time)
*
* @param
* $projectId
* @return array|int
*/
private function get_realtime($projectId)
{
$metrics = 'rt:activeUsers';
$dimensions = 'rt:pagePath,rt:source,rt:keyword,rt:trafficType,rt:visitorType,rt:pageTitle';
try {
$serial = 'qr_realtimecache_' . $this->get_serial($projectId);
$transient = GADWP_Tools::get_cache($serial);
if ($transient === false) {
if ($this->gapi_errors_handler()) {
return -23;
}
$data = $this->service->data_realtime->get('ga:' . $projectId, $metrics, array('dimensions' => $dimensions, 'quotaUser' => $this->managequota . 'p' . $projectId));
GADWP_Tools::set_cache($serial, $data, 55);
$this->gadwp->config->options['api_backoff'] = 0;
$this->gadwp->config->set_plugin_options();
} else {
$data = $transient;
}
} catch (Google_Service_Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $this->error_timeout);
GADWP_Tools::set_cache('gapi_errors', array($e->getCode(), (array) $e->getErrors()), $this->error_timeout);
return $e->getCode();
} catch (Exception $e) {
GADWP_Tools::set_cache('last_error', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
return $e->getCode();
}
if ($data->getRows() < 1) {
return -21;
}
$i = 0;
$gadwp_data = $data;
foreach ($data->getRows() as $row) {
$gadwp_data->rows[$i] = array_map('esc_html', $row);
$i++;
}
return $gadwp_data;
}
示例11: dashboard_widget
public function dashboard_widget()
{
if (empty($this->gadwp->config->options['ga_dash_token'])) {
echo '<p>' . __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
if (current_user_can('manage_options')) {
if (isset($_REQUEST['gadwp_selected_profile'])) {
$this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['gadwp_selected_profile'];
}
$profiles = $this->gadwp->config->options['ga_dash_profile_list'];
$profile_switch = '';
if (!empty($profiles)) {
if (!$this->gadwp->config->options['ga_dash_tableid']) {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
$this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain($profiles);
}
} else {
if ($this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail']) {
$this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
}
}
$profile_switch .= '<select id="gadwp_selected_profile" name="gadwp_selected_profile" onchange="this.form.submit()">';
foreach ($profiles as $profile) {
if (!$this->gadwp->config->options['ga_dash_tableid']) {
$this->gadwp->config->options['ga_dash_tableid'] = $profile[1];
}
if (isset($profile[3])) {
$profile_switch .= '<option value="' . esc_attr($profile[1]) . '" ';
$profile_switch .= selected($profile[1], $this->gadwp->config->options['ga_dash_tableid'], false);
$profile_switch .= ' title="' . __("View Name:", 'google-analytics-dashboard-for-wp') . ' ' . esc_attr($profile[0]) . '">' . esc_attr(GADWP_Tools::strip_protocol($profile[3])) . '</option>';
}
}
$profile_switch .= "</select>";
} else {
echo '<p>' . __("Something went wrong while retrieving profiles list.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
}
$this->gadwp->config->set_plugin_options();
if (current_user_can('manage_options')) {
if ($this->gadwp->config->options['switch_profile'] == 0) {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
} else {
echo $profile_switch;
$projectId = $this->gadwp->config->options['ga_dash_tableid'];
}
} else {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
}
if (!$projectId) {
echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'google-analytics-dashboard-for-wp') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
?>
<div id="gadwp-window-1"></div>
<?php
}
示例12: get_locations
/**
* Analytics data for backend reports (location reports)
*
* @param
* $projectId
* @param
* $from
* @param
* $to
* @return array|int
*/
public function get_locations($projectId, $from, $to, $filter = '')
{
$metrics = 'ga:sessions';
$options = "";
$title = __("Countries", 'ga-dash');
$serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $filter);
$dimensions = 'ga:country';
$local_filter = '';
if ($this->gadwp->config->options['ga_target_geomap']) {
$dimensions = 'ga:city, ga:region';
$country_codes = GADWP_Tools::get_countrycodes();
if (isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
$local_filter = 'ga:country==' . $country_codes[$this->gadwp->config->options['ga_target_geomap']];
$title = __("Cities from", 'ga-dash') . ' ' . __($country_codes[$this->gadwp->config->options['ga_target_geomap']]);
$serial = 'gadash_qr7_' . $this->get_serial($projectId . $from . $this->gadwp->config->options['ga_target_geomap'] . $filter);
}
}
$options = array('dimensions' => $dimensions, 'sort' => '-ga:sessions', 'quotaUser' => $this->managequota . 'p' . $projectId);
if ($filter) {
$options['filters'] = 'ga:pagePath==' . $filter;
if ($local_filter) {
$options['filters'] .= ';' . $local_filter;
}
} else {
if ($local_filter) {
$options['filters'] = $local_filter;
}
}
$data = $this->handle_corereports($projectId, $from, $to, $metrics, $options, $serial);
if (is_numeric($data)) {
return $data;
}
$ga_dash_data = array(array($title, __("Sessions", 'ga-dash')));
foreach ($data->getRows() as $row) {
if (isset($row[2])) {
$ga_dash_data[] = array(esc_html($row[0]) . ', ' . esc_html($row[1]), (int) $row[2]);
} else {
$ga_dash_data[] = array(esc_html($row[0]), (int) $row[1]);
}
}
return $ga_dash_data;
}
示例13: load_styles_scripts
/**
* Styles & Scripts conditional loading (based on current URI)
*
* @param
* $hook
*/
public function load_styles_scripts($hook)
{
/*
* GADWP main stylesheet
*/
wp_enqueue_style('gadwp', GADWP_URL . 'admin/css/gadwp.css', null, GADWP_CURRENT_VERSION);
/*
* Dashboard Widgets Styles & Scripts
*/
$widgets_hooks = array('index.php');
if (in_array($hook, $widgets_hooks)) {
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['dashboard_widget']) {
wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
wp_enqueue_script('gadwp-admin-widgets', plugins_url('js/widgets.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION);
if (!wp_script_is('googlejsapi')) {
wp_register_script('googlejsapi', 'https://www.google.com/jsapi');
wp_enqueue_script('googlejsapi');
}
wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION);
}
}
/*
* Posts/Pages List Styles & Scripts
*/
$contentstats_hooks = array('edit.php');
if (in_array($hook, $contentstats_hooks)) {
if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && $this->gadwp->config->options['item_reports']) {
wp_enqueue_style('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.css', null, GADWP_CURRENT_VERSION);
wp_enqueue_style('gadwp_itemreports', GADWP_URL . 'admin/css/item-reports.css', null, GADWP_CURRENT_VERSION);
$country_codes = GADWP_Tools::get_countrycodes();
if ($this->gadwp->config->options['ga_target_geomap'] && isset($country_codes[$this->gadwp->config->options['ga_target_geomap']])) {
$region = $this->gadwp->config->options['ga_target_geomap'];
} else {
$region = false;
}
wp_enqueue_style("wp-jquery-ui-dialog");
if (!wp_script_is('googlejsapi')) {
wp_register_script('googlejsapi', 'https://www.google.com/jsapi');
}
wp_enqueue_script('gadwp-nprogress', GADWP_URL . 'tools/nprogress/nprogress.js', array('jquery'), GADWP_CURRENT_VERSION);
wp_enqueue_script('gadwp_itemreports', plugins_url('js/item-reports.js', __FILE__), array('gadwp-nprogress', 'googlejsapi', 'jquery', 'jquery-ui-dialog'), GADWP_CURRENT_VERSION);
wp_localize_script('gadwp_itemreports', 'gadwp_item_data', array('ajaxurl' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('gadwp_get_itemreports'), 'dateList' => array('today' => __("Today", 'ga-dash'), 'yesterday' => __("Yesterday", 'ga-dash'), '7daysAgo' => __("Last 7 Days", 'ga-dash'), '30daysAgo' => __("Last 30 Days", 'ga-dash'), '90daysAgo' => __("Last 90 Days", 'ga-dash')), 'reportList' => array('uniquePageviews' => __("Unique Views", 'ga-dash'), 'users' => __("Users", 'ga-dash'), 'organicSearches' => __("Organic", 'ga-dash'), 'pageviews' => __("Page Views", 'ga-dash'), 'visitBounceRate' => __("Bounce Rate", 'ga-dash'), 'locations' => __("Location", 'ga-dash'), 'referrers' => __("Referrers", 'ga-dash'), 'searches' => __("Searches", 'ga-dash'), 'trafficdetails' => __("Traffic Details", 'ga-dash')), 'i18n' => array(__("A JavaScript Error is blocking plugin resources!", 'ga-dash'), __("Traffic Mediums", 'ga-dash'), __("Visitor Type", 'ga-dash'), __("Social Networks", 'ga-dash'), __("Search Engines", 'ga-dash'), __("Unique Views", 'ga-dash'), __("Users", 'ga-dash'), __("Page Views", 'ga-dash'), __("Bounce Rate", 'ga-dash'), __("Organic Search", 'ga-dash'), __("Pages/Session", 'ga-dash'), __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'), __("Not enough data collected", 'ga-dash'), __("This report is unavailable", 'ga-dash'), __("report generated by", 'ga-dash')), 'colorVariations' => GADWP_Tools::variations($this->gadwp->config->options['ga_dash_style']), 'region' => $region));
}
}
/*
* Settings Styles & Scripts
*/
$settings_hooks = array('toplevel_page_gadash_settings', 'google-analytics_page_gadash_backend_settings', 'google-analytics_page_gadash_frontend_settings', 'google-analytics_page_gadash_tracking_settings', 'google-analytics_page_gadash_errors_debugging');
if (in_array($hook, $settings_hooks)) {
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wp-color-picker');
wp_enqueue_script('wp-color-picker-script-handle', plugins_url('js/wp-color-picker-script.js', __FILE__), array('wp-color-picker'), false, true);
wp_enqueue_script('gadwp-settings', plugins_url('js/settings.js', __FILE__), array('jquery'), GADWP_CURRENT_VERSION);
}
}
示例14: dashboard_widget
public function dashboard_widget()
{
if (empty($this->gadwp->config->options['ga_dash_token'])) {
echo '<p>' . __("This plugin needs an authorization:", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Authorize Plugin", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
if (current_user_can('manage_options')) {
if (isset($_REQUEST['gadwp_selected_profile'])) {
$this->gadwp->config->options['ga_dash_tableid'] = $_REQUEST['gadwp_selected_profile'];
}
$profiles = $this->gadwp->config->options['ga_dash_profile_list'];
$profile_switch = '';
if (!empty($profiles)) {
if (!$this->gadwp->config->options['ga_dash_tableid']) {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
$this->gadwp->config->options['ga_dash_tableid'] = GADWP_Tools::guess_default_domain($profiles);
}
} else {
if ($this->gadwp->config->options['switch_profile'] == 0 && $this->gadwp->config->options['ga_dash_tableid_jail']) {
$this->gadwp->config->options['ga_dash_tableid'] = $this->gadwp->config->options['ga_dash_tableid_jail'];
}
}
$profile_switch .= '<select id="gadwp_selected_profile" name="gadwp_selected_profile" onchange="this.form.submit()">';
foreach ($profiles as $profile) {
if (!$this->gadwp->config->options['ga_dash_tableid']) {
$this->gadwp->config->options['ga_dash_tableid'] = $profile[1];
}
if (isset($profile[3])) {
$profile_switch .= '<option value="' . esc_attr($profile[1]) . '" ';
$profile_switch .= selected($profile[1], $this->gadwp->config->options['ga_dash_tableid'], false);
$profile_switch .= ' title="' . __("View Name:", 'google-analytics-dashboard-for-wp') . ' ' . esc_attr($profile[0]) . '">' . esc_attr(GADWP_Tools::strip_protocol($profile[3])) . '</option>';
}
}
$profile_switch .= "</select>";
} else {
echo '<p>' . __("Something went wrong while retrieving profiles list.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("More details", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
}
$this->gadwp->config->set_plugin_options();
?>
<form id="ga-dash" method="POST">
<?php
if (current_user_can('manage_options')) {
if ($this->gadwp->config->options['switch_profile'] == 0) {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
} else {
echo $profile_switch;
$projectId = $this->gadwp->config->options['ga_dash_tableid'];
}
} else {
if ($this->gadwp->config->options['ga_dash_tableid_jail']) {
$projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
} else {
echo '<p>' . __("An admin should asign a default Google Analytics Profile.", 'google-analytics-dashboard-for-wp') . '</p><form action="' . menu_page_url('gadash_settings', false) . '" method="POST">' . get_submit_button(__("Select Domain", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
}
if (!$projectId) {
echo '<p>' . __("Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'google-analytics-dashboard-for-wp') . '</p> <form action="https://deconf.com/how-to-set-up-google-analytics-on-your-website/" method="POST">' . get_submit_button(__("Find out more!", 'google-analytics-dashboard-for-wp'), 'secondary') . '</form>';
return;
}
if (isset($_REQUEST['gadwpquery'])) {
$query = $_REQUEST['gadwpquery'];
} else {
$default_metric = GADWP_Tools::get_cookie('default_metric');
$query = $default_metric ? $default_metric : 'sessions';
}
if (isset($_REQUEST['gadwpperiod'])) {
$period = $_REQUEST['gadwpperiod'];
} else {
$default_dimension = GADWP_Tools::get_cookie('default_dimension');
$period = $default_dimension ? $default_dimension : '30daysAgo';
}
?>
<select id="ga_dash_period" name="gadwpperiod" onchange="this.form.submit()">
<option value="realtime" <?php
selected("realtime", $period, true);
?>
><?php
_e("Real-Time", 'google-analytics-dashboard-for-wp');
?>
</option>
<option value="today" <?php
selected("today", $period, true);
?>
><?php
_e("Today", 'google-analytics-dashboard-for-wp');
?>
</option>
<option value="yesterday" <?php
selected("yesterday", $period, true);
?>
//.........这里部分代码省略.........
示例15: add_content
public function add_content($content)
{
if (!GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_front']) || !($this->gadwp->config->options['ga_dash_frontend_stats'] || $this->gadwp->config->options['ga_dash_frontend_keywords'])) {
return $content;
}
if ($this->gadwp->config->options['ga_dash_frontend_stats'] && $this->gadwp->config->options['ga_dash_frontend_keywords']) {
$npcounter = 1;
} else {
$npcounter = 0;
}
if ((is_page() || is_single()) && !is_preview()) {
$page_url = $_SERVER["REQUEST_URI"];
//Encode URL
$page_url = rawurlencode($page_url);
$content .= '<script type="text/javascript">
gadash_firstclick = true;
function checknpcounter(max) {
try {
if (npcounter == max) {
NProgress.done();
} else {
npcounter++;
NProgress.set((1/(max+1))*npcounter);
}
} catch(e) {}
}
npcounter = 0;
jQuery(document).ready(function(){
jQuery("#gadwp-title").click(function(){
if (gadash_firstclick){
try {
NProgress.configure({ parent: "#gadwp-progressbar" });
NProgress.configure({ showSpinner: false });
NProgress.start();
} catch(e) {
jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
jQuery("#gadwp-progressbar").html("' . __("A JavaScript Error is blocking plugin resources!", 'ga-dash') . '");
}
if(typeof ga_dash_drawpagesessions == "function"){
jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
if (!jQuery.isNumeric(response)){
if (jQuery.isArray(response)){
gadash_pagesessions = response;
google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions));
} else {
checknpcounter(0);
jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
console.log("\\n********************* GADWP Log ********************* \\n\\n"+response);
}
}else{
jQuery("#gadwp-sessions").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"});
jQuery("#gadwp-sessions").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")");
checknpcounter(' . $npcounter . ');
}
});
}
if(typeof ga_dash_drawpagesearches == "function"){
jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
if (!jQuery.isNumeric(response)){
if (jQuery.isArray(response)){
gadash_pagesearches = response;
google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches));
} else {
checknpcounter(0);
jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
console.log("\\n********************* GADWP Log ********************* \\n\\n"+response);
}
}else{
jQuery("#gadwp-searches").css({"background-color":"#F7F7F7","height":"auto","padding-top":"30px","padding-bottom":"30px","color":"#000","text-align":"center"});
jQuery("#gadwp-searches").html("' . __("This report is unavailable", 'ga-dash') . ' ("+response+")");
checknpcounter(' . $npcounter . ');
}
});
}
gadash_firstclick = false;
}
});
});';
if ($this->gadwp->config->options['ga_dash_frontend_stats']) {
$title = __("Views vs UniqueViews", 'ga-dash');
if (isset($this->gadwp->config->options['ga_dash_style'])) {
$css = "colors:['" . $this->gadwp->config->options['ga_dash_style'] . "','" . GADWP_Tools::colourVariator($this->gadwp->config->options['ga_dash_style'], -20) . "'],";
$color = $this->gadwp->config->options['ga_dash_style'];
} else {
$css = "";
$color = "#3366CC";
}
$content .= '
google.load("visualization", "1", {packages:["corechart"]});
function ga_dash_drawpagesessions(gadash_pagesessions) {
var data = google.visualization.arrayToDataTable(gadash_pagesessions);
//.........这里部分代码省略.........