PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.3.8
ShareThis Dashboard for Google Analytics v2.3.8
3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.0.0 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.3.0 3.3.1
googleanalytics / class / Ga_Sharethis.php
googleanalytics / class Last commit date
controller 5 years ago core 5 years ago Ga_Admin.php 5 years ago Ga_Autoloader.php 5 years ago Ga_Frontend.php 5 years ago Ga_Helper.php 5 years ago Ga_Hook.php 9 years ago Ga_Notice.php 5 years ago Ga_Sharethis.php 5 years ago Ga_Stats.php 5 years ago
Ga_Sharethis.php
102 lines
1 <?php
2
3 /**
4 * Ga_Sharethis class
5 *
6 * Preparing request and parsing response from Sharethis Platform Api
7 *
8 * @author wle@adips.com
9 * @version 1.0
10 */
11
12 class Ga_Sharethis {
13
14 public static function get_body( $data ) {
15 $body = $data->getBody();
16 return json_decode( $body );
17 }
18
19 /**
20 * Create sharethis options
21 */
22 public static function create_sharethis_options( $api_client ) {
23 $data = array();
24 $parsed_url = parse_url( get_option( 'siteurl' ) );
25 $domain = $parsed_url['host'] . ( !empty( $parsed_url['path'] ) ? $parsed_url['path'] : '' );
26 $query_params = array(
27 'domain' => $domain,
28 'is_wordpress' => true,
29 'onboarding_product' => 'ga',
30 );
31 $response = $api_client->call( 'ga_api_create_sharethis_property', array(
32 $query_params
33 ) );
34 $sharethis_options = self::get_sharethis_options( $response );
35 if ( !empty( $sharethis_options[ 'id' ] ) ) {
36 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID, $sharethis_options[ 'id' ] );
37 }
38 if ( !empty( $sharethis_options[ 'secret' ] ) ) {
39 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET, $sharethis_options[ 'secret' ] );
40 }
41
42 return $data;
43 }
44
45 public static function get_sharethis_options( $response ) {
46 $body = self::get_body( $response );
47 $options = array();
48 if ( !empty( $body ) ) {
49 foreach ( $body as $key => $value ) {
50 if ( $key == '_id' ) {
51 $options[ 'id' ] = $value;
52 } else if ( $key == 'secret' ) {
53 $options[ 'secret' ] = $value;
54 } else if ( $key == 'error' ) {
55 $options[ 'error' ] = $value;
56 }
57 }
58 } else {
59 $options[ 'error' ] = 'error';
60 }
61 return $options;
62 }
63
64 public static function sharethis_installation_verification( $api_client ) {
65 if ( Ga_Helper::should_verify_sharethis_installation() ) {
66 $query_params = array(
67 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
68 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET )
69 );
70 $response = $api_client->call( 'ga_api_sharethis_installation_verification', array(
71 $query_params
72 ) );
73 $result = self::get_verification_result( $response );
74 if ( !empty( $result ) ) {
75 add_option( Ga_Admin::GA_SHARETHIS_VERIFICATION_RESULT, true );
76 }
77 }
78 }
79
80 public static function get_verification_result( $response ) {
81 $body = self::get_body( $response );
82 if ( !empty( $body->{"status"} ) ) {
83 return true;
84 }
85 return false;
86 }
87
88 public static function get_alerts( $response ) {
89 $body = self::get_body( $response );
90 if ( !empty( $body ) ) {
91 if ( !empty( $body[ 'error' ] ) ) {
92 return (object) array( 'error' => self::GA_SHARETHIS_ALERTS_ERROR );
93 }
94
95 return $body;
96 } else {
97 return array();
98 }
99 }
100
101 }
102