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 / controller / Ga_Admin_Controller.php
googleanalytics / class / controller Last commit date
Ga_Admin_Controller.php 5 years ago
Ga_Admin_Controller.php
114 lines
1 <?php
2
3 /**
4 * Manages actions in the admin area.
5 *
6 * Created by PhpStorm.
7 * User: mdn
8 * Date: 2017-01-25
9 * Time: 09:50
10 */
11 class Ga_Admin_Controller extends Ga_Controller_Core {
12
13 const ACTION_SHARETHIS_INVITE = 'ga_action_sharethis_invite';
14
15 /**
16 * Redirects to Google oauth authentication endpoint.
17 */
18 public static function ga_action_auth() {
19 header( 'Location:' . Ga_Admin::api_client()->create_auth_url() );
20 }
21
22 /**
23 * Handle Sharethis invite action
24 */
25 public static function ga_action_sharethis_invite() {
26
27 if ( self::verify_nonce( self::ACTION_SHARETHIS_INVITE ) ) {
28 $email = !empty( $_POST[ 'sharethis_invite_email' ] ) ? $_POST[ 'sharethis_invite_email' ] : null;
29 $response = null;
30 if ( !empty( $email ) ) {
31 $data = array(
32 'id' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ),
33 'secret' => get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_SECRET ),
34 'product' => 'viral-notifications',
35 'role' => 'admin', // array_shift(Ga_Helper::get_user_roles())
36 'email' => $email
37 );
38
39 $response = Ga_Admin::api_client( Ga_Admin::GA_SHARETHIS_API_ALIAS )->call( 'ga_api_sharethis_user_invite', array( $data ) );
40 $errors = Ga_Admin::api_client( Ga_Admin::GA_SHARETHIS_API_ALIAS )->get_errors();
41
42 if ( !empty( $errors ) ) {
43 $msg = '';
44 foreach ( $errors as $error ) {
45 $msg .= $error[ 'message' ];
46 }
47 $msg = Ga_Helper::create_url_msg( $msg, Ga_Admin::NOTICE_ERROR );
48 } else {
49 $msg = Ga_Helper::create_url_msg( _( 'An invite was sent to this email' ), Ga_Admin::NOTICE_SUCCESS );
50 }
51 }
52 } else {
53 $msg = Ga_Helper::create_url_msg( _( 'Invalid request.' ), Ga_Admin::NOTICE_ERROR );
54 }
55 }
56
57 /**
58 * Sets accept terms option to TRUE.
59 */
60 public static function ga_action_update_terms() {
61 update_option( Ga_Admin::GA_SHARETHIS_TERMS_OPTION_NAME, true );
62
63 wp_redirect( admin_url( Ga_Helper::GA_SETTINGS_PAGE_URL ) );
64 }
65
66 /**
67 * Enables all features option.
68 */
69 public static function ga_action_enable_all_features() {
70 Ga_Helper::update_option( Ga_Admin::GA_DISABLE_ALL_FEATURES, false );
71
72 $url = !empty( $_GET[ 'page' ] ) ? Ga_Helper::create_url( admin_url( 'admin.php' ), array( 'page' => $_GET[ 'page' ] ) ) : admin_url( Ga_Helper::create_url( Ga_Helper::GA_SETTINGS_PAGE_URL ) );
73
74 wp_redirect( $url );
75 }
76
77 /**
78 * Disables all features option.
79 */
80 public static function ga_action_disable_all_features() {
81 Ga_Helper::update_option( Ga_Admin::GA_DISABLE_ALL_FEATURES, true );
82
83 $url = !empty( $_GET[ 'page' ] ) ? Ga_Helper::create_url( admin_url( 'admin.php' ), array( 'page' => $_GET[ 'page' ] ) ) : admin_url( Ga_Helper::create_url( Ga_Helper::GA_SETTINGS_PAGE_URL ) );
84
85 wp_redirect( $url );
86 }
87
88 public static function validate_ajax_data_change_post( $post ) {
89 $error = 0;
90
91 if ( self::verify_nonce( 'ga_ajax_data_change' ) ) {
92 if ( !empty( $post[ 'date_range' ] ) ) {
93 if ( !is_string( $post[ 'date_range' ] ) ) {
94 $error ++;
95 }
96 } else {
97 $error ++;
98 }
99
100 if ( !empty( $post[ 'metric' ] ) ) {
101 if ( !is_string( $post[ 'metric' ] ) ) {
102 $error ++;
103 }
104 } else {
105 $error ++;
106 }
107 } else {
108 $error ++;
109 }
110
111 return $error == 0;
112 }
113 }
114