PluginProbe
Chartify – WordPress Chart Plugin / 3.1.0
Chartify – WordPress Chart Plugin v3.1.0
3.8.0 3.7.9 3.7.8 3.7.7 3.7.6 3.7.5 trunk 1.0.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 All 83 releases
chart-builder / includes / class-chart-builder-integrations.php

class-chart-builder-integrations.php in Chartify – WordPress Chart Plugin 3.1.0, at includes/class-chart-builder-integrations.php

411 lines 25.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link http://ays-pro.com/
7 * @since 1.0.0
8 *
9 * @package Chart_Builder
10 * @subpackage Chart_Builder/includes
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Chart_Builder
20 * @subpackage Chart_Builder/includes
21 * @author AYS Pro LLC <info@ays-pro.com>
22 */
23 class Chart_Builder_Integrations
24 {
25
26 /**
27 * The ID of this plugin.
28 *
29 * @since 1.0.0
30 * @access private
31 * @var string $plugin_name The ID of this plugin.
32 */
33 private $plugin_name;
34
35 /**
36 * The version of this plugin.
37 *
38 * @since 1.0.0
39 * @access private
40 * @var string $version The current version of this plugin.
41 */
42 private $version;
43
44 private $settings_obj;
45
46 private $capability;
47
48 private $blockquote_content;
49
50 /**
51 * Initialize the class and set its properties.
52 *
53 * @since 1.0.0
54 * @param string $plugin_name The name of this plugin.
55 * @param string $version The version of this plugin.
56 */
57 public function __construct($plugin_name, $version){
58
59 $this->plugin_name = $plugin_name;
60 $this->version = $version;
61 $this->settings_obj = new Chart_Builder_Settings_DB_Actions($this->plugin_name);
62
63 $settings_url = sprintf(
64 __( "For enabling this option, please go to %s page and fill all options.", $this->plugin_name ),
65 "<a style='color:blue;text-decoration:underline;font-size:20px;' href='?page=".$this->plugin_name."-settings&ays_tab=tab2' target='_blank'>". __( "this", $this->plugin_name ) ."</a>"
66 );
67 $blockquote_content = '<blockquote class="error_message">'. $settings_url .'</blockquote>';
68 $this->blockquote_content = $blockquote_content;
69 }
70
71 // ===== INTEGRATIONS HOOKS =====
72
73 public function ays_chart_page_integrations_content( $args ){
74
75 if( ! $this->settings_obj->get_permission_for_editing_plugin() ){
76 $settings_url = __( "This functionality is disabled.", $this->plugin_name );
77 $blockquote_content = '<blockquote class="error_message">'. $settings_url .'</blockquote>';
78 $this->blockquote_content = $blockquote_content;
79 }
80
81 $integrations_contents = apply_filters( 'ays_cb_chart_page_integrations_contents', array(), $args );
82
83 $integrations = array();
84
85 foreach ($integrations_contents as $key => $integrations_content) {
86 $content = '<fieldset>';
87 if(isset($integrations_content['title'])){
88 $content .= '<legend>';
89 if(isset($integrations_content['icon'])){
90 $content .= '<img class="ays_integration_logo" src="'. $integrations_content['icon'] .'" alt="">';
91 }
92 $content .= '<h5>'. $integrations_content['title'] .'</h5></legend>';
93 }
94 $content .= $integrations_content['content'];
95
96 $content .= '</fieldset>';
97
98 $integrations[] = $content;
99 }
100
101 echo implode('<hr />', $integrations);
102
103 }
104
105 // Integrations settings page action hook
106 public function ays_settings_page_integrations_content( $args ){
107
108 $integrations_contents = apply_filters( 'ays_cb_settings_page_integrations_contents', array(), $args );
109
110 $integrations = array();
111
112 foreach ($integrations_contents as $key => $integrations_content) {
113 $content = '<fieldset>';
114 if(isset($integrations_content['title'])){
115 $content .= '<legend>';
116 if(isset($integrations_content['icon'])){
117 $content .= '<img class="ays_integration_logo" src="'. $integrations_content['icon'] .'" alt="">';
118 }
119 $content .= '<h5>'. $integrations_content['title'] .'</h5></legend>';
120 }
121 if(isset($integrations_content['content'])){
122 $content .= $integrations_content['content'];
123 }
124
125 $content .= '</fieldset>';
126
127 $integrations[] = $content;
128 }
129
130 echo implode('<hr />', $integrations);
131 }
132
133 ////////////////////////////////////////////////////////////////////////////////////////
134 //====================================================================================//
135 ////////////////////////////////////////////////////////////////////////////////////////
136
137 // ===== Google sheet starts =====
138
139 public function source_contents_import_from_google_sheet_settings( $sources, $args ){
140
141 $html_class_prefix = $args['html_class_prefix'];
142 $html_name_prefix = $args['html_name_prefix'];
143
144 ob_start();
145 ?>
146 <div class="ays-accordion-data-main-wrap ays-pro-features-v2-main-box">
147 <div class="ays-pro-features-v2-big-buttons-box">
148 <a href="https://www.youtube.com/watch?v=Qox2ev6OgUM" target="_blank" class="ays-pro-features-v2-video-button">
149 <div class="ays-pro-features-v2-video-icon" style="background-image: url('<?php echo esc_attr(CHART_BUILDER_ADMIN_URL); ?>/images/icons/pro-features-icons/Video_24x24.svg');" data-img-src="<?php echo esc_attr(CHART_BUILDER_ADMIN_URL); ?>/images/icons/pro-features-icons/Video_24x24_Hover.svg"></div>
150 <div class="ays-pro-features-v2-video-text">
151 <?php echo __("Watch Video" , "chart-builder"); ?>
152 </div>
153 </a>
154 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
155 <div class="ays-pro-features-v2-upgrade-icon" style="background-image: url('<?php echo esc_attr(CHART_BUILDER_ADMIN_URL); ?>/images/icons/pro-features-icons/Locked_24x24.svg');" data-img-src="<?php echo esc_attr(CHART_BUILDER_ADMIN_URL); ?>/images/icons/pro-features-icons/Locked_24x24.svg"></div>
156 <div class="ays-pro-features-v2-upgrade-text">
157 <?php echo __("Upgrade" , "chart-builder"); ?>
158 </div>
159 </a>
160 </div>
161 <div class="<?= $html_class_prefix ?>source-data-main-wrap">
162 <div class="<?= $html_class_prefix ?>chart-source-data-main">
163 <div id="ays-chart-google-sheet-form">
164 <div class="<?= $html_class_prefix ?>google-sheet-select-wrap">
165 <select name="<?= $html_name_prefix ?>google_sheet_id" id="" class="<?= $html_class_prefix ?>google-sheet-select" data-chart-id="1">
166 <option value=""><?= __( 'Select spreadsheet', $this->plugin_name ) ?></option>
167 </select>
168 </div>
169 <div class="ays-chart-buttons-group">
170 <div class="ays-chart-buttons-group-main">
171 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-fetch">
172 <?php echo __( 'Show Results', "chart-builder" ); ?>
173 </button>
174 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-show-on-chart">
175 <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.722 6.59785C12.2407 3.47754 10.0017 1.90723 7.00009 1.90723C3.99697 1.90723 1.75947 3.47754 0.278215 6.59941C0.218802 6.72522 0.187988 6.86263 0.187988 7.00176C0.187988 7.14089 0.218802 7.27829 0.278215 7.4041C1.75947 10.5244 3.99853 12.0947 7.00009 12.0947C10.0032 12.0947 12.2407 10.5244 13.722 7.40254C13.8423 7.14941 13.8423 6.85566 13.722 6.59785ZM7.00009 10.9697C4.47978 10.9697 2.63447 9.6916 1.3329 7.00098C2.63447 4.31035 4.47978 3.03223 7.00009 3.03223C9.5204 3.03223 11.3657 4.31035 12.6673 7.00098C11.3673 9.6916 9.52197 10.9697 7.00009 10.9697ZM6.93759 4.25098C5.41884 4.25098 4.18759 5.48223 4.18759 7.00098C4.18759 8.51973 5.41884 9.75098 6.93759 9.75098C8.45634 9.75098 9.68759 8.51973 9.68759 7.00098C9.68759 5.48223 8.45634 4.25098 6.93759 4.25098ZM6.93759 8.75098C5.9704 8.75098 5.18759 7.96816 5.18759 7.00098C5.18759 6.03379 5.9704 5.25098 6.93759 5.25098C7.90478 5.25098 8.68759 6.03379 8.68759 7.00098C8.68759 7.96816 7.90478 8.75098 6.93759 8.75098Z" fill="#14524A" /></svg>
176 <?php echo __( 'Preview', "chart-builder" ); ?>
177 </button>
178 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-save">
179 <?php echo __( 'Save data', "chart-builder" ); ?>
180 </button>
181 </div>
182 <div class="ays-chart-buttons-group-columns">
183 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-columns">
184 <?php echo __( 'Columns', "chart-builder" ); ?>
185 </button>
186 </div>
187 </div>
188 </div>
189 </div>
190 </div>
191 </div>
192 <?php
193 $content = ob_get_clean();
194
195 $title = __( 'Connect to Google Sheets', $this->plugin_name ) . ' <a class="ays_help" data-bs-toggle="tooltip" title="' . __("Activate Google Integration to import the information from the Google Sheets.",$this->plugin_name) . '">
196 <i class="ays_fa ays_fa_info_circle"></i>
197 </a>';
198
199 $sources['google_sheet'] = array(
200 'content' => $content,
201 'title' => $title
202 );
203
204 return $sources;
205 }
206
207 // Google sheet integration / settings page
208 // Google sheet integration / settings page content
209 public function ays_settings_page_google_sheet_content($integrations, $args){
210 $icon = CHART_BUILDER_ADMIN_URL . '/images/integrations/google_logo.png';
211 $title = __( 'Google', $this->plugin_name );
212
213 $content = '<div class="form-group row ays-pro-features-v2-main-box">
214 <div class="ays-pro-features-v2-small-buttons-box" style="width:fit-content;">
215 <a href="https://www.youtube.com/watch?v=Qox2ev6OgUM" target="_blank" class="ays-pro-features-v2-video-button">
216 <div class="ays-pro-features-v2-video-icon" style="background-image: url(&quot;' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Video_24x24.svg&quot;);" data-img-src="' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Video_24x24_Hover.svg"></div>
217 <div class="ays-pro-features-v2-video-text">
218 '. __("Watch Video" , "chart-builder") .'
219 </div>
220 </a>
221 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
222 <div class="ays-pro-features-v2-upgrade-icon" style="background-image: url(&quot;' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Locked_24x24.svg&quot;)" data-img-src="' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Locked_24x24.svg"></div>
223 <div class="ays-pro-features-v2-upgrade-text">
224 '. __("Upgrade", $this->plugin_name) .'
225 </div>
226 </a>
227 </div>
228 <div class="col-sm-12">
229 <div class="form-group row" aria-describedby="aaa">
230 <div class="col-sm-3">
231 <button id="googleInstructionsPopOver" type="button" class="btn btn-info" data-original-title="Google Integration Setup Instructions" >'. __("Instructions", $this->plugin_name). '</button>
232 <div class="d-none" id="googleInstructions">
233 <p>1. '. __("Turn on Your Google Sheet API", $this->plugin_name) .'
234 <a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>
235 </p>
236 <p>2. <a href="https://console.developers.google.com/apis/credentials" target="_blank">'. __("Create ", $this->plugin_name) .'</a>'. __("new Google Oauth client ID credentials (if you do not still have)", $this->plugin_name).'</p>
237 <p>3. '. __("Choose the application type as <b>Web application</b>", $this->plugin_name) .'</p>
238 <p>4. '. __("Add the following link in the <b>Authorized redirect URIs</b> field", $this->plugin_name) .'</p>
239 <p>
240 <code>Redirect url</code>
241 </p>
242 <p>5. '. __("Click on the <b>Create</b> button", $this->plugin_name) .'</p>
243 <p>6. '. __("Copy the <b>Your Client ID</b> and <b>Your Client Secret</b> from the opened popup and paste them in the corresponding fields.", $this->plugin_name) .'</p>
244 <p>7. '. __("Click on the <b>Connect</b> button to complete authorization", $this->plugin_name) .'</p>
245 </div>
246 </div>
247 </div>
248 <div class="form-group row">
249 <div class="col-sm-3">
250 <label for="ays_google_client">
251 '. __("Google Client ID", $this->plugin_name) .'
252 </label>
253 </div>
254 <div class="col-sm-9">
255 <input type="text" class="ays-text-input" id="ays_google_client" name="ays_google_client" value="">
256 </div>
257 </div>
258 <br>
259 <div class="form-group row">
260 <div class="col-sm-3">
261 <label for="ays_google_secret">
262 '. __("Google Client Secret", $this->plugin_name) .'
263 </label>
264 </div>
265 <div class="col-sm-9">
266 <input type="text" class="ays-text-input" id="ays_google_secret" name="ays_google_secret" value="">
267 <input type="hidden" id="ays_google_redirect" name="ays_google_redirect" value="">
268 </div>
269 </div>
270 <br>
271 <div class="form-group row">
272 <div class="col-sm-3"></div>
273 <div class="col-sm-9">
274 <button type="submit" name="ays_googleOAuth2" id="ays_googleOAuth2" class="btn btn-outline-info">
275 '. __("Connect", $this->plugin_name) .'
276 </button>
277 </div>
278 </div>
279 </div>
280 </div>';
281
282 $integrations['google'] = array(
283 'content' => $content,
284 'icon' => $icon,
285 'title' => $title
286 );
287 return $integrations;
288 }
289
290 // ===== Google sheet end =====
291
292 // ===== Database starts =====
293
294 // Database integration / settings page
295 public function ays_settings_page_database_content($integrations, $args) {
296 $actions = $this->settings_obj;
297
298 // Database settings
299 $databaseb_res = ($actions->get_setting('database') === false) ? json_encode(array()) : $actions->get_setting('database');
300 $db_settings = json_decode($databaseb_res, true);
301 $db_host = isset($db_settings['host']) ? $db_settings['host'] : '';
302 $db_name = isset($db_settings['db_name']) ? $db_settings['db_name'] : '';
303 $db_user = isset($db_settings['user']) ? $db_settings['user'] : '';
304 $db_password = isset($db_settings['password']) ? openssl_decrypt(base64_decode($db_settings['password']), 'aes-256-cbc', SECURE_AUTH_KEY, 0, substr(md5(SECURE_AUTH_KEY), 0, 16)) : '';
305 $db_port = isset($db_settings['port']) ? $db_settings['port'] : '3306';
306
307 $nonce = wp_create_nonce('ays_test_database_nonce');
308
309 // Create the form content for database settings
310 $content = '
311 <div class="form-group row ays-pro-features-v2-main-box">
312 <div class="ays-pro-features-v2-small-buttons-box" style="width:fit-content;">
313 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
314 <div class="ays-pro-features-v2-upgrade-icon" style="background-image: url(&quot;' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Locked_24x24.svg&quot;)" data-img-src="' . esc_attr(CHART_BUILDER_ADMIN_URL) . '/images/icons/pro-features-icons/Locked_24x24.svg"></div>
315 <div class="ays-pro-features-v2-upgrade-text">
316 '. __("Upgrade", $this->plugin_name) .'
317 </div>
318 </a>
319 </div>
320 <div class="col-sm-12">
321 <div class="form-group row" aria-describedby="aaa">
322 <div class="col-sm-3">
323 <button id="dbInstructionsPopOver" type="button" class="btn btn-info" data-original-title="Database Integration Setup Instructions" >' . __("Instructions", $this->plugin_name) . '</button>
324 <div class="d-none" id="dbInstructions">
325 <p><strong>' . __("IP Access:", $this->plugin_name) . '</strong></p>
326 <p>'. __("In some cases, your database may block connections from unknown IP addresses. You might need to whitelist your IP in the database settings to allow access.", $this->plugin_name) .'</p>
327 <p><strong>' . __("Database Host:", $this->plugin_name) . '</strong> ' . __("Enter the address of your database (e.g., 'localhost', or a host like 'db.example.com').", $this->plugin_name) . '</p>
328 <p><strong>' . __("Database Name:", $this->plugin_name) . '</strong> ' . __("Enter the name of the database you want to connect to.", $this->plugin_name) . '</p>
329 <p><strong>' . __("Database User:", $this->plugin_name) . '</strong> ' . __("Enter the username for accessing the database.", $this->plugin_name) . '</p>
330 <p><strong>' . __("Database Password:", $this->plugin_name) . '</strong> ' . __("Enter the password for your database user. Make sure this is correct.", $this->plugin_name) . '</p>
331 <p><strong>' . __("Database Port (Optional):", $this->plugin_name) . '</strong> ' . __("The default MySQL port is '3306'. You can leave this field empty. If your host doesn't specify a port, we'll use the default value.", $this->plugin_name) . '</p>
332 <p><strong>' . __("Test Connection:", $this->plugin_name) . '</strong> ' . __("Click on the 'Test Connection' button to verify that the connection is successful.", $this->plugin_name) . '</p>
333 <p><strong>' . __("If the test fails:", $this->plugin_name) . '</strong> ' . __("Please recheck your details or verify if your IP address is whitelisted.", $this->plugin_name) . '</p>
334 </div>
335 </div>
336 </div>
337 <div class="form-group row">
338 <div class="col-sm-3">
339 <label for="ays_database_host">'. __("Database Host", $this->plugin_name) .'</label>
340 </div>
341 <div class="col-sm-9">
342 <input type="text" class="ays-text-input" id="ays_database_host" name="ays_database_host" value="'. esc_attr($db_host) .'">
343 </div>
344 </div>
345 <br>
346 <div class="form-group row">
347 <div class="col-sm-3">
348 <label for="ays_database_name">'. __("Database Name", $this->plugin_name) .'</label>
349 </div>
350 <div class="col-sm-9">
351 <input type="text" class="ays-text-input" id="ays_database_name" name="ays_database_name" value="'. esc_attr($db_name) .'">
352 </div>
353 </div>
354 <br>
355 <div class="form-group row">
356 <div class="col-sm-3">
357 <label for="ays_database_user">'. __("Database User", $this->plugin_name) .'</label>
358 </div>
359 <div class="col-sm-9">
360 <input type="text" class="ays-text-input" id="ays_database_user" name="ays_database_user" value="'. esc_attr($db_user) .'">
361 </div>
362 </div>
363 <br>
364 <div class="form-group row">
365 <div class="col-sm-3">
366 <label for="ays_database_password">'. __("Database Password", $this->plugin_name) .'</label>
367 </div>
368 <div class="col-sm-9">
369 <input type="password" class="ays-text-input" id="ays_database_password" name="ays_database_password" value="'. esc_attr($db_password) .'">
370 </div>
371 </div>
372 <br>
373 <div class="form-group row">
374 <div class="col-sm-3">
375 <label for="ays_database_port">'. __("Database Port (optional)", $this->plugin_name) .'</label>
376 </div>
377 <div class="col-sm-9">
378 <input type="text" class="ays-text-input" id="ays_database_port" name="ays_database_port" value="'. esc_attr($db_port) .'" placeholder="3306">
379 </div>
380 </div>
381 <br>
382 <div class="form-group row">
383 <div class="col-sm-3"></div>
384 <div class="col-sm-9">
385 <button id="ays_database_test_connection" class="btn btn-outline-info">
386 '. __("Test Connection", $this->plugin_name) .'
387 </button>
388 <span class="ays_cb_loader display_none_not_important"><img src=' . CHART_BUILDER_ADMIN_URL . '/images/loaders/loading.gif></span>
389 <input type="hidden" id="ays_database_nonce" value="'. esc_attr($nonce) .'">
390 </div>
391 </div>
392 </div>
393 </div>';
394
395 $icon = CHART_BUILDER_ADMIN_URL . '/images/integrations/database_logo.png';
396 $title = __( 'Database', $this->plugin_name );
397 $integrations['database'] = array(
398 'content' => $content,
399 'icon' => $icon,
400 'title' => $title
401 );
402
403 return $integrations;
404 }
405 // ===== Database end =====
406
407 ////////////////////////////////////////////////////////////////////////////////////////
408 //====================================================================================//
409 ////////////////////////////////////////////////////////////////////////////////////////
410 }
411