PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.1.3
ShareThis Dashboard for Google Analytics v2.1.3
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 9 years ago core 9 years ago Ga_Admin.php 9 years ago Ga_Autoloader.php 9 years ago Ga_Frontend.php 9 years ago Ga_Helper.php 9 years ago Ga_Hook.php 9 years ago Ga_Notice.php 9 years ago Ga_Sharethis.php 9 years ago Ga_Stats.php 9 years ago
Ga_Sharethis.php
114 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 class Ga_Sharethis {
12
13 const GA_SHARETHIS_ALERTS_ERROR = 'Trending content alerts are temporarily unavailable, please try again later or contact support@sharethis.com';
14
15 public static function get_body( $data ) {
16 $body = $data->getBody();
17 return json_decode( $body );
18 }
19
20 /**
21 * Create sharethis options
22 */
23 public static function create_sharethis_options( $api_client ) {
24 $data = array();
25 $parsed_url = parse_url( get_option( 'siteurl' ) );
26 if ( Ga_Helper::should_create_sharethis_property() ) {
27 $domain = $parsed_url['host'] . ( !empty( $parsed_url['path'] ) ? $parsed_url['path'] : '' );
28 $query_params = array( 'domain' => $domain );
29 $response = $api_client->call( 'ga_api_create_sharethis_property', array(
30 $query_params
31 ) );
32 $sharethis_options = self::get_sharethis_options( $response );
33 if ( !empty( $sharethis_options[ 'id' ] ) ) {
34 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID, $sharethis_options[ 'id' ] );
35 }
36 if ( !empty( $sharethis_options[ 'secret' ] ) ) {
37 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET, $sharethis_options[ 'secret' ] );
38 }
39 }
40
41 return $data;
42 }
43
44 public static function get_sharethis_options( $response ) {
45 $body = self::get_body( $response );
46 $options = array();
47 if ( !empty( $body ) ) {
48 foreach ( $body as $key => $value ) {
49 if ( $key == '_id' ) {
50 $options[ 'id' ] = $value;
51 } else if ( $key == 'secret' ) {
52 $options[ 'secret' ] = $value;
53 } else if ( $key == 'error' ) {
54 $options[ 'error' ] = $value;
55 }
56 }
57 } else {
58 $options[ 'error' ] = self::GA_SHARETHIS_ALERTS_ERROR;
59 }
60 return $options;
61 }
62
63 public static function sharethis_installation_verification( $api_client ) {
64 if ( Ga_Helper::should_verify_sharethis_installation() ) {
65 $query_params = array(
66 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
67 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET )
68 );
69 $response = $api_client->call( 'ga_api_sharethis_installation_verification', array(
70 $query_params
71 ) );
72 $result = self::get_verification_result( $response );
73 if ( !empty( $result ) ) {
74 add_option( Ga_Admin::GA_SHARETHIS_VERIFICATION_RESULT, true );
75 }
76 }
77 }
78
79 public static function get_verification_result( $response ) {
80 $body = self::get_body( $response );
81 if ( !empty( $body->{"status"} ) ) {
82 return true;
83 }
84 return false;
85 }
86
87 public static function load_sharethis_trending_alerts( $api_client ) {
88 if ( Ga_Helper::should_load_trending_alerts() ) {
89 $query_params = array(
90 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
91 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET )
92 );
93 $response = $api_client->call( 'ga_api_sharethis_get_trending_alerts', array(
94 $query_params
95 ) );
96 return self::get_alerts( $response );
97 }
98 }
99
100 public static function get_alerts( $response ) {
101 $body = self::get_body( $response );
102 if ( !empty( $body ) ) {
103 if ( !empty( $body[ 'error' ] ) ) {
104 return (object) array( 'error' => self::GA_SHARETHIS_ALERTS_ERROR );
105 }
106
107 return $body;
108 } else {
109 return array();
110 }
111 }
112
113 }
114