PluginProbe
Chartify – WordPress Chart Plugin / 3.5.2
Chartify – WordPress Chart Plugin v3.5.2
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.5.2, at includes/class-chart-builder-integrations.php

420 lines 26.1 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 // Add an action to load translations properly
64 add_action('wp_loaded', array($this, 'ays_chart_load_translations'));
65 }
66
67 /**
68 * Load plugin translations.
69 */
70 public function ays_chart_load_translations() {
71
72 $settings_url = sprintf(
73 // Translators: %s will be replaced with a link to the settings page.
74 __( "For enabling this option, please go to %s page and fill all options.", 'chart-builder' ),
75 "<a style='color:blue;text-decoration:underline;font-size:20px;' href='?page=".'chart-builder'."-settings&ays_tab=tab2' target='_blank'>". __( "this", 'chart-builder' ) ."</a>"
76 );
77 $blockquote_content = '<blockquote class="error_message">'. $settings_url .'</blockquote>';
78 $this->blockquote_content = $blockquote_content;
79 }
80
81 // ===== INTEGRATIONS HOOKS =====
82
83 public function ays_chart_page_integrations_content( $args ){
84
85 if( ! $this->settings_obj->get_permission_for_editing_plugin() ){
86 $settings_url = esc_html__( "This functionality is disabled.", 'chart-builder' );
87 $blockquote_content = '<blockquote class="error_message">'. esc_html( $settings_url ) .'</blockquote>';
88 $this->blockquote_content = $blockquote_content;
89 }
90
91 $integrations_contents = apply_filters( 'ays_cb_chart_page_integrations_contents', array(), $args );
92
93 $integrations = array();
94
95 foreach ($integrations_contents as $key => $integrations_content) {
96 $content = '<fieldset>';
97 if(isset($integrations_content['title'])){
98 $content .= '<legend>';
99 if(isset($integrations_content['icon'])){
100 $content .= '<img class="ays_integration_logo" src="' . esc_url( $integrations_content['icon'] ) . '" alt="">';
101 }
102 $content .= '<h5>' . esc_html( $integrations_content['title'] ) . '</h5></legend>';
103 }
104 $content .= $integrations_content['content'];
105
106 $content .= '</fieldset>';
107
108 $integrations[] = $content;
109 }
110 echo implode('<hr />', $integrations) ;
111
112 }
113
114 // Integrations settings page action hook
115 public function ays_settings_page_integrations_content( $args ){
116
117 $integrations_contents = apply_filters( 'ays_cb_settings_page_integrations_contents', array(), $args );
118
119 $integrations = array();
120
121 foreach ($integrations_contents as $key => $integrations_content) {
122 $content = '<fieldset>';
123 if(isset($integrations_content['title'])){
124 $content .= '<legend>';
125 if(isset($integrations_content['icon'])){
126 $content .= '<img class="ays_integration_logo" src="'. $integrations_content['icon'] .'" alt="">';
127 }
128 $content .= '<h5>'. $integrations_content['title'] .'</h5></legend>';
129 }
130 if(isset($integrations_content['content'])){
131 $content .= $integrations_content['content'];
132 }
133
134 $content .= '</fieldset>';
135
136 $integrations[] = $content;
137 }
138
139 echo implode('<hr />', $integrations) ;
140 }
141
142 ////////////////////////////////////////////////////////////////////////////////////////
143 //====================================================================================//
144 ////////////////////////////////////////////////////////////////////////////////////////
145
146 // ===== Google sheet starts =====
147
148 public function source_contents_import_from_google_sheet_settings( $sources, $args ){
149
150 $html_class_prefix = $args['html_class_prefix'];
151 $html_name_prefix = $args['html_name_prefix'];
152
153 ob_start();
154 ?>
155 <div class="ays-accordion-data-main-wrap ays-pro-features-v2-main-box">
156 <div class="ays-pro-features-v2-big-buttons-box">
157 <a href="https://www.youtube.com/watch?v=Qox2ev6OgUM" target="_blank" class="ays-pro-features-v2-video-button">
158 <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>
159 <div class="ays-pro-features-v2-video-text">
160 <?php echo esc_html__("Watch Video" , "chart-builder"); ?>
161 </div>
162 </a>
163 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
164 <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>
165 <div class="ays-pro-features-v2-upgrade-text">
166 <?php echo esc_html__("Upgrade" , "chart-builder"); ?>
167 </div>
168 </a>
169 </div>
170 <div class="<?php echo esc_attr($html_class_prefix) ?>source-data-main-wrap">
171 <div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-main">
172 <div id="ays-chart-google-sheet-form">
173 <div class="<?php echo esc_attr($html_class_prefix)?>google-sheet-select-wrap">
174 <select name="<?php echo esc_attr($html_class_prefix) ?>google_sheet_id" id="" class="<?php echo esc_attr($html_class_prefix) ?>google-sheet-select" data-chart-id="1">
175 <option value=""><?php echo esc_html__( 'Select spreadsheet', 'chart-builder' ) ?></option>
176 </select>
177 </div>
178 <div class="ays-chart-buttons-group">
179 <div class="ays-chart-buttons-group-main">
180 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-fetch">
181 <?php echo esc_html__( 'Show Results', "chart-builder" ); ?>
182 </button>
183 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-show-on-chart">
184 <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>
185 <?php echo esc_html__( 'Preview', "chart-builder" ); ?>
186 </button>
187 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-save">
188 <?php echo esc_html__( 'Save data', "chart-builder" ); ?>
189 </button>
190 </div>
191 <div class="ays-chart-buttons-group-columns">
192 <button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttns" id="ays-chart-gsheet-columns">
193 <?php echo esc_html__( 'Columns', "chart-builder" ); ?>
194 </button>
195 </div>
196 </div>
197 </div>
198 </div>
199 </div>
200 </div>
201 <?php
202 $content = ob_get_clean();
203
204 $title = __( 'Connect to Google Sheets', 'chart-builder') . ' <a class="ays_help" data-bs-toggle="tooltip" title="' . __("Activate Google Integration to import the information from the Google Sheets.",'chart-builder') . '">
205 <i class="ays_fa ays_fa_info_circle"></i>
206 </a>';
207
208 $sources['google_sheet'] = array(
209 'content' => $content,
210 'title' => $title
211 );
212
213 return $sources;
214 }
215
216 // Google sheet integration / settings page
217 // Google sheet integration / settings page content
218 public function ays_settings_page_google_sheet_content($integrations, $args){
219 $icon = CHART_BUILDER_ADMIN_URL . '/images/integrations/google_logo.png';
220 $title = __( 'Google', 'chart-builder' );
221
222 $content = '<div class="form-group row ays-pro-features-v2-main-box">
223 <div class="ays-pro-features-v2-small-buttons-box" style="width:fit-content;">
224 <a href="https://www.youtube.com/watch?v=Qox2ev6OgUM" target="_blank" class="ays-pro-features-v2-video-button">
225 <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>
226 <div class="ays-pro-features-v2-video-text">
227 '. __("Watch Video" , "chart-builder") .'
228 </div>
229 </a>
230 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
231 <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>
232 <div class="ays-pro-features-v2-upgrade-text">
233 '. __("Upgrade", 'chart-builder') .'
234 </div>
235 </a>
236 </div>
237 <div class="col-sm-12">
238 <div class="form-group row" aria-describedby="aaa">
239 <div class="col-sm-3">
240 <button id="googleInstructionsPopOver" type="button" class="btn btn-info" data-original-title="Google Integration Setup Instructions" >'. __("Instructions", 'chart-builder'). '</button>
241 <div class="d-none" id="googleInstructions">
242 <p>1. '. __("Turn on Your Google Sheet API", 'chart-builder') .'
243 <a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>
244 </p>
245 <p>2. <a href="https://console.developers.google.com/apis/credentials" target="_blank">'. __("Create ", 'chart-builder') .'</a>'. __("new Google Oauth client ID credentials (if you do not still have)", 'chart-builder').'</p>
246 <p>3. '. __("Choose the application type as <b>Web application</b>", 'chart-builder') .'</p>
247 <p>4. '. __("Add the following link in the <b>Authorized redirect URIs</b> field", 'chart-builder') .'</p>
248 <p>
249 <code>Redirect url</code>
250 </p>
251 <p>5. '. __("Click on the <b>Create</b> button", 'chart-builder') .'</p>
252 <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.", 'chart-builder') .'</p>
253 <p>7. '. __("Click on the <b>Connect</b> button to complete authorization", 'chart-builder') .'</p>
254 </div>
255 </div>
256 </div>
257 <div class="form-group row">
258 <div class="col-sm-3">
259 <label for="ays_google_client">
260 '. __("Google Client ID", 'chart-builder') .'
261 </label>
262 </div>
263 <div class="col-sm-9">
264 <input type="text" class="ays-text-input" id="ays_google_client" name="ays_google_client" value="">
265 </div>
266 </div>
267 <br>
268 <div class="form-group row">
269 <div class="col-sm-3">
270 <label for="ays_google_secret">
271 '. __("Google Client Secret", 'chart-builder') .'
272 </label>
273 </div>
274 <div class="col-sm-9">
275 <input type="text" class="ays-text-input" id="ays_google_secret" name="ays_google_secret" value="">
276 <input type="hidden" id="ays_google_redirect" name="ays_google_redirect" value="">
277 </div>
278 </div>
279 <br>
280 <div class="form-group row">
281 <div class="col-sm-3"></div>
282 <div class="col-sm-9">
283 <button type="submit" name="ays_googleOAuth2" id="ays_googleOAuth2" class="btn btn-outline-info">
284 '. __("Connect",'chart-builder') .'
285 </button>
286 </div>
287 </div>
288 </div>
289 </div>';
290
291 $integrations['google'] = array(
292 'content' => $content,
293 'icon' => $icon,
294 'title' => $title
295 );
296 return $integrations;
297 }
298
299 // ===== Google sheet end =====
300
301 // ===== Database starts =====
302
303 // Database integration / settings page
304 public function ays_settings_page_database_content($integrations, $args) {
305 $actions = $this->settings_obj;
306
307 // Database settings
308 $databaseb_res = ($actions->get_setting('database') === false) ? json_encode(array()) : $actions->get_setting('database');
309 $db_settings = json_decode($databaseb_res, true);
310 $db_host = isset($db_settings['host']) ? $db_settings['host'] : '';
311 $db_name = isset($db_settings['db_name']) ? $db_settings['db_name'] : '';
312 $db_user = isset($db_settings['user']) ? $db_settings['user'] : '';
313 $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)) : '';
314 $db_port = isset($db_settings['port']) ? $db_settings['port'] : '3306';
315
316 $nonce = wp_create_nonce('ays_test_database_nonce');
317
318 // Create the form content for database settings
319 $content = '
320 <div class="form-group row ays-pro-features-v2-main-box">
321 <div class="ays-pro-features-v2-small-buttons-box" style="width:fit-content;">
322 <a href="https://ays-pro.com/wordpress/chart-builder" target="_blank" class="ays-pro-features-v2-upgrade-button">
323 <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>
324 <div class="ays-pro-features-v2-upgrade-text">
325 '. __("Upgrade", 'chart-builder') .'
326 </div>
327 </a>
328 </div>
329 <div class="col-sm-12">
330 <div class="form-group row" aria-describedby="aaa">
331 <div class="col-sm-3">
332 <button id="dbInstructionsPopOver" type="button" class="btn btn-info" data-original-title="Database Integration Setup Instructions" >' . __("Instructions", 'chart-builder') . '</button>
333 <div class="d-none" id="dbInstructions">
334 <p><strong>' . __("IP Access:", 'chart-builder') . '</strong></p>
335 <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.", 'chart-builder') .'</p>
336 <p><strong>' . __("Database Host:", 'chart-builder') . '</strong> ' . __("Enter the address of your database (e.g., 'localhost', or a host like 'db.example.com').", 'chart-builder') . '</p>
337 <p><strong>' . __("Database Name:", 'chart-builder') . '</strong> ' . __("Enter the name of the database you want to connect to.", 'chart-builder') . '</p>
338 <p><strong>' . __("Database User:", 'chart-builder') . '</strong> ' . __("Enter the username for accessing the database.", 'chart-builder') . '</p>
339 <p><strong>' . __("Database Password:", 'chart-builder') . '</strong> ' . __("Enter the password for your database user. Make sure this is correct.", 'chart-builder') . '</p>
340 <p><strong>' . __("Database Port (Optional):", 'chart-builder') . '</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.", 'chart-builder') . '</p>
341 <p><strong>' . __("Test Connection:", 'chart-builder') . '</strong> ' . __("Click on the 'Test Connection' button to verify that the connection is successful.", 'chart-builder') . '</p>
342 <p><strong>' . __("If the test fails:", 'chart-builder') . '</strong> ' . __("Please recheck your details or verify if your IP address is whitelisted.", 'chart-builder') . '</p>
343 </div>
344 </div>
345 </div>
346 <div class="form-group row">
347 <div class="col-sm-3">
348 <label for="ays_database_host">'. __("Database Host", 'chart-builder') .'</label>
349 </div>
350 <div class="col-sm-9">
351 <input type="text" class="ays-text-input" id="ays_database_host" name="ays_database_host" value="'. esc_attr($db_host) .'">
352 </div>
353 </div>
354 <br>
355 <div class="form-group row">
356 <div class="col-sm-3">
357 <label for="ays_database_name">'. __("Database Name", 'chart-builder') .'</label>
358 </div>
359 <div class="col-sm-9">
360 <input type="text" class="ays-text-input" id="ays_database_name" name="ays_database_name" value="'. esc_attr($db_name) .'">
361 </div>
362 </div>
363 <br>
364 <div class="form-group row">
365 <div class="col-sm-3">
366 <label for="ays_database_user">'. __("Database User", 'chart-builder') .'</label>
367 </div>
368 <div class="col-sm-9">
369 <input type="text" class="ays-text-input" id="ays_database_user" name="ays_database_user" value="'. esc_attr($db_user) .'">
370 </div>
371 </div>
372 <br>
373 <div class="form-group row">
374 <div class="col-sm-3">
375 <label for="ays_database_password">'. __("Database Password", 'chart-builder') .'</label>
376 </div>
377 <div class="col-sm-9">
378 <input type="password" class="ays-text-input" id="ays_database_password" name="ays_database_password" value="'. esc_attr($db_password) .'">
379 </div>
380 </div>
381 <br>
382 <div class="form-group row">
383 <div class="col-sm-3">
384 <label for="ays_database_port">'. __("Database Port (optional)", 'chart-builder') .'</label>
385 </div>
386 <div class="col-sm-9">
387 <input type="text" class="ays-text-input" id="ays_database_port" name="ays_database_port" value="'. esc_attr($db_port) .'" placeholder="3306">
388 </div>
389 </div>
390 <br>
391 <div class="form-group row">
392 <div class="col-sm-3"></div>
393 <div class="col-sm-9">
394 <button id="ays_database_test_connection" class="btn btn-outline-info">
395 '. __("Test Connection", 'chart-builder') .'
396 </button>
397 <span class="ays_cb_loader display_none_not_important"><img src=' . CHART_BUILDER_ADMIN_URL . '/images/loaders/loading.gif></span>
398 <input type="hidden" id="ays_database_nonce" value="'. esc_attr($nonce) .'">
399 </div>
400 </div>
401 </div>
402 </div>';
403
404 $icon = CHART_BUILDER_ADMIN_URL . '/images/integrations/database_logo.png';
405 $title = __( 'Database', 'chart-builder' );
406 $integrations['database'] = array(
407 'content' => $content,
408 'icon' => $icon,
409 'title' => $title
410 );
411
412 return $integrations;
413 }
414 // ===== Database end =====
415
416 ////////////////////////////////////////////////////////////////////////////////////////
417 //====================================================================================//
418 ////////////////////////////////////////////////////////////////////////////////////////
419 }
420