PluginProbe
Datafeedr API / 1.0.13
Datafeedr API v1.0.13
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / classes / class-dfrapi-account.php

class-dfrapi-account.php in Datafeedr API 1.0.13, at classes/class-dfrapi-account.php

180 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if ( ! class_exists( 'Dfrapi_Account' ) ) {
6
7 /**
8 * Configuration page.
9 */
10 class Dfrapi_Account {
11
12 private $page = 'dfrapi-account';
13 private $key;
14
15 public function __construct() {
16 $this->key = 'dfrapi_account';
17 add_action( 'admin_init', array( &$this, 'register_settings' ) );
18 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19 add_action( 'init', array( &$this, 'load_settings' ) );
20 }
21
22 function load_settings() {
23 $this->options = (array) get_option( $this->key );
24 if ( isset( $this->options[0] ) && empty( $this->options[0] ) ) {
25 $this->options = $status = dfrapi_api_get_status();
26 if ( !array_key_exists( 'dfrapi_api_error', $status ) ) {
27 update_option( $this->key, $status );
28 }
29 }
30 }
31
32 function admin_menu() {
33 add_submenu_page(
34 'dfrapi',
35 __( 'Account &#8212; Datafeedr API', DFRAPI_DOMAIN ),
36 __( 'Account', DFRAPI_DOMAIN ),
37 'manage_options',
38 $this->key,
39 array( $this, 'output' )
40 );
41 }
42
43 function output() {
44 echo '<div class="wrap" id="' . $this->key . '">';
45 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
46 settings_fields( $this->page );
47 do_settings_sections( $this->page);
48 echo '</div>';
49 }
50
51 function register_settings() {
52
53 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
54
55 // Current Plan
56 add_settings_section( 'current_plan', __( 'Current Plan', DFRAPI_DOMAIN ), array( &$this, 'section_current_plan_desc' ), $this->page );
57
58 // Only show the following if there is no Error.
59 if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
60
61 // Current Usage
62 add_settings_section( 'current_usage', __( 'Current Usage', DFRAPI_DOMAIN ), array( &$this, 'section_current_usage_desc' ), $this->page );
63 }
64
65 // Account Links
66 add_settings_section( 'account', __( 'Account Links', DFRAPI_DOMAIN ), array( &$this, 'section_account_desc' ), $this->page );
67 }
68
69 function section_current_plan_desc() {
70
71 $plans = dfrapi_get_membership_plans();
72 $plan_name = '';
73 if ( $this->options['plan_id'] > 0 ) {
74 $plan_name .= $plans[$this->options['plan_id']];
75 if ( $this->options['plan_id'] != 10250000 ) {
76 $plan_name .= ' (';
77 $plan_name .= '<a href="' . dfrapi_user_pages( 'change' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank" class="dfrapi_plan_link">' . __( 'Upgrade', DFRAPI_DOMAIN ) . '</a>';
78 $plan_name .= ')';
79 }
80 } else {
81 $plan_name .= '<em>';
82 $plan_name .= __( 'None', DFRAPI_DOMAIN );
83 $plan_name .= '</em> (';
84 $plan_name .= '<a href="' . dfrapi_user_pages( 'signup' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank" class="dfrapi_plan_link">' . __( 'Reactivate your subscription', DFRAPI_DOMAIN ) . '</a>';
85 $plan_name .= ')';
86 }
87
88 echo '
89 <table class="widefat account_table" cellspacing="0">
90 <tbody>
91 <tr class="alternate">
92 <td class="row-title">' . __( 'Plan name', DFRAPI_DOMAIN ) . '</td>
93 <td class="desc">' . $plan_name . '</td>
94 </tr>
95 ';
96
97 if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
98 echo '
99 <tr>
100 <td class="row-title">' . __( 'Requests per month (RPM)', DFRAPI_DOMAIN ) . '</td>
101 <td class="desc">' . number_format( $this->options['max_requests'] ) . '</td>
102 </tr>
103 <tr class="alternate">
104 <td class="row-title">' . __( 'Products per request (PPR)', DFRAPI_DOMAIN ) . '</td>
105 <td class="desc">' . number_format( $this->options['max_length'] ) . '</td>
106 </tr>
107 ';
108 }
109
110 echo '
111 </tbody>
112 </table>
113 ';
114 }
115
116 function section_current_usage_desc() {
117
118 // Percent of API Requests Used
119 $percent_api_requests_users = '';
120 if ( $this->options['max_requests'] > 0 ) {
121 $percent_api_requests_users .= floor ( ( intval( $this->options['request_count'] ) / intval( $this->options['max_requests'] ) * 100 ) );
122 } else {
123 $percent_api_requests_users .= 0;
124 }
125 $percent_api_requests_users .= '%';
126
127 // Your API requests will reset on
128 $reset_date = '';
129 $today = date('j');
130 $num_days = date('t');
131 if ( $this->options['bill_day'] > $num_days ) {
132 $bill_day = $num_days;
133 } else {
134 $bill_day = $this->options['bill_day'];
135 }
136 if ( $bill_day == 0 ) {
137 $reset_date .= '<em>' . __( 'Never', DFRAPI_DOMAIN ) . '</em>';
138 } elseif ( $today >= $bill_day ) {
139 $reset_date .= date('F', strtotime('+1 month')) . ' ' . $bill_day . ', ' . date('Y', strtotime('+1 month'));
140 } else {
141 $reset_date .= date('F') . ' ' . $bill_day . ', ' . date('Y');
142 }
143
144 echo '
145 <table class="widefat account_table" cellspacing="0">
146 <tbody>
147 <tr class="alternate">
148 <td class="row-title">' . __( 'API requests used this period', DFRAPI_DOMAIN ) . '</td>
149 <td class="desc">' . number_format( $this->options['request_count'] ) . '</td>
150 </tr>
151 <tr>
152 <td class="row-title">' . __( 'API requests remaining this period', DFRAPI_DOMAIN ) . '</td>
153 <td class="desc">' . number_format( $this->options['max_requests'] - $this->options['request_count'] ) . '</td>
154 </tr>
155 <tr class="alternate">
156 <td class="row-title">' . __( 'Percent of API requests used this period', DFRAPI_DOMAIN ) . '</td>
157 <td class="desc">' . $percent_api_requests_users . '</td>
158 </tr>
159 <tr>
160 <td class="row-title">' . __( 'Your API requests will reset on', DFRAPI_DOMAIN ) . '</td>
161 <td class="desc">' . $reset_date . '</td>
162 </tr>
163 </tbody>
164 </table>
165 ';
166 }
167
168 function section_account_desc() {
169 echo '<p><a href="' . dfrapi_user_pages( 'summary' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank">' . __( 'View your Datafeedr account', DFRAPI_DOMAIN ) . '</a></p>';
170 echo '<p><a href="' . dfrapi_user_pages( 'change' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank">' . __( 'Upgrade your plan', DFRAPI_DOMAIN ) . '</a></p>';
171 }
172
173 function validate( $input ) {
174 return $input;
175 }
176
177 } // class Dfrapi_Account
178
179 } // class_exists check
180