PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.1
ShareThis Dashboard for Google Analytics v2.1
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_View.php 9 years ago
Ga_Sharethis.php
113 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 if ( Ga_Helper::should_create_sharethis_property() ) {
26 $domain = parse_url( get_site_url(), PHP_URL_HOST );
27 $query_params = array( 'domain' => $domain );
28 $response = $api_client->call( 'ga_api_create_sharethis_property', array(
29 $query_params
30 ) );
31 $sharethis_options = self::get_sharethis_options( $response );
32 if ( !empty( $sharethis_options[ 'id' ] ) ) {
33 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID, $sharethis_options[ 'id' ] );
34 }
35 if ( !empty( $sharethis_options[ 'secret' ] ) ) {
36 add_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET, $sharethis_options[ 'secret' ] );
37 }
38 }
39
40 return $data;
41 }
42
43 public static function get_sharethis_options( $response ) {
44 $body = self::get_body( $response );
45 $options = array();
46 if ( !empty( $body ) ) {
47 foreach ( $body as $key => $value ) {
48 if ( $key == '_id' ) {
49 $options[ 'id' ] = $value;
50 } else if ( $key == 'secret' ) {
51 $options[ 'secret' ] = $value;
52 } else if ( $key == 'error' ) {
53 $options[ 'error' ] = $value;
54 }
55 }
56 } else {
57 $options[ 'error' ] = self::GA_SHARETHIS_ALERTS_ERROR;
58 }
59 return $options;
60 }
61
62 public static function sharethis_installation_verification( $api_client ) {
63 if ( Ga_Helper::should_verify_sharethis_installation() ) {
64 $query_params = array(
65 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
66 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET )
67 );
68 $response = $api_client->call( 'ga_api_sharethis_installation_verification', array(
69 $query_params
70 ) );
71 $result = self::get_verification_result( $response );
72 if ( !empty( $result ) ) {
73 add_option( Ga_Admin::GA_SHARETHIS_VERIFICATION_RESULT, true );
74 }
75 }
76 }
77
78 public static function get_verification_result( $response ) {
79 $body = self::get_body( $response );
80 if ( !empty( $body->{"status"} ) ) {
81 return true;
82 }
83 return false;
84 }
85
86 public static function load_sharethis_trending_alerts( $api_client ) {
87 if ( Ga_Helper::should_load_trending_alerts() ) {
88 $query_params = array(
89 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
90 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET )
91 );
92 $response = $api_client->call( 'ga_api_sharethis_get_trending_alerts', array(
93 $query_params
94 ) );
95 return self::get_alerts( $response );
96 }
97 }
98
99 public static function get_alerts( $response ) {
100 $body = self::get_body( $response );
101 if ( !empty( $body ) ) {
102 if ( !empty( $body[ 'error' ] ) ) {
103 return (object) array( 'error' => self::GA_SHARETHIS_ALERTS_ERROR );
104 }
105
106 return $body;
107 } else {
108 return array();
109 }
110 }
111
112 }
113