| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The admin-specific functionality of the plugin. |
| 5 |
* |
| 6 |
* @link https://ays-pro.com/ |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Chart_Builder |
| 10 |
* @subpackage Chart_Builder/admin |
| 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/admin |
| 21 |
* @author Chart Builder Team <info@ays-pro.com> |
| 22 |
*/ |
| 23 |
class Chart_Builder_Admin { |
| 24 |
|
| 25 |
/** |
| 26 |
* The ID of this plugin. |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
* @access private |
| 30 |
* @var string $plugin_name The ID of this plugin. |
| 31 |
*/ |
| 32 |
private $plugin_name; |
| 33 |
|
| 34 |
/** |
| 35 |
* The version of this plugin. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @access private |
| 39 |
* @var string $version The current version of this plugin. |
| 40 |
*/ |
| 41 |
private $version; |
| 42 |
|
| 43 |
/** |
| 44 |
* The capability of this plugin. |
| 45 |
* |
| 46 |
* @since 1.0.0 |
| 47 |
* @access private |
| 48 |
* @var string $capability The capability for users access to this plugin. |
| 49 |
*/ |
| 50 |
private $capability; |
| 51 |
|
| 52 |
/** |
| 53 |
* @var Chart_Builder_DB_Actions |
| 54 |
*/ |
| 55 |
private $db_obj; |
| 56 |
|
| 57 |
/** |
| 58 |
* Initialize the class and set its properties. |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
* @param string $plugin_name The name of this plugin. |
| 62 |
* @param string $version The version of this plugin. |
| 63 |
*/ |
| 64 |
public function __construct( $plugin_name, $version ) { |
| 65 |
|
| 66 |
$this->plugin_name = $plugin_name; |
| 67 |
$this->version = $version; |
| 68 |
|
| 69 |
add_filter('set-screen-option', array(__CLASS__, 'set_screen'), 10, 3); |
| 70 |
add_filter('set_screen_option_cb_charts_per_page', array(__CLASS__, 'set_screen'), 10, 3); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Register the stylesheets for the admin area. |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
*/ |
| 79 |
public function enqueue_styles($hook_suffix) { |
| 80 |
wp_enqueue_style( $this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'css/admin.css', array(), $this->version, 'all'); |
| 81 |
// Not enqueue styles if they are not on the current plugin page |
| 82 |
if (false === strpos($hook_suffix, $this->plugin_name)) return; |
| 83 |
// |
| 84 |
wp_enqueue_style( $this->plugin_name . '-normalize', plugin_dir_url( __FILE__ ) . 'css/normalize.css', array(), $this->version . time(), 'all' ); |
| 85 |
wp_enqueue_style( $this->plugin_name . '-admin-general', plugin_dir_url( __FILE__ ) . 'css/admin-general.css', array(), $this->version, 'all' ); |
| 86 |
wp_enqueue_style( $this->plugin_name . '-banner', plugin_dir_url( __FILE__ ) . 'css/banner.css', array(), $this->version, 'all' ); |
| 87 |
wp_enqueue_style( $this->plugin_name . '-animate', plugin_dir_url(__FILE__) . 'css/animate.css', array(), $this->version, 'all'); |
| 88 |
wp_enqueue_style( $this->plugin_name . '-font-awesome', plugin_dir_url(__FILE__) . 'css/ays-font-awesome.min.css', array(), $this->version, 'all'); |
| 89 |
wp_enqueue_style( $this->plugin_name . '-font-awesome-icons', plugin_dir_url(__FILE__) . 'css/ays-font-awesome-icons.css', array(), $this->version, 'all'); |
| 90 |
wp_enqueue_style( $this->plugin_name . '-select2', plugin_dir_url(__FILE__) . 'css/ays-select2.min.css', array(), $this->version, 'all'); |
| 91 |
wp_enqueue_style( $this->plugin_name . '-chosen', plugin_dir_url(__FILE__) . 'css/chosen.min.css', array(), $this->version, 'all'); |
| 92 |
wp_enqueue_style( $this->plugin_name . '-bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css', array(), $this->version, 'all'); |
| 93 |
wp_enqueue_style( $this->plugin_name . '-data-bootstrap', plugin_dir_url(__FILE__) . 'css/dataTables.bootstrap4.min.css', array(), $this->version, 'all'); |
| 94 |
|
| 95 |
wp_enqueue_style( $this->plugin_name . '-layer', plugin_dir_url( __FILE__ ) . 'css/chart-builder-admin-layer.css', array(), $this->version, 'all' ); |
| 96 |
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/chart-builder-admin.css', array(), $this->version . time(), 'all' ); |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Register the JavaScript for the admin area. |
| 102 |
* |
| 103 |
* @since 1.0.0 |
| 104 |
*/ |
| 105 |
public function enqueue_scripts($hook_suffix) { |
| 106 |
if (false !== strpos($hook_suffix, "plugins.php")){ |
| 107 |
wp_enqueue_script($this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery'), $this->version, true); |
| 108 |
wp_localize_script($this->plugin_name . '-admin', 'chart_builder_admin_ajax', array('ajax_url' => admin_url('admin-ajax.php'))); |
| 109 |
} |
| 110 |
|
| 111 |
// Not enqueue scripts if they are not on the current plugin page |
| 112 |
if (false === strpos($hook_suffix, $this->plugin_name)) return; |
| 113 |
// |
| 114 |
global $wp_version; |
| 115 |
$version1 = $wp_version; |
| 116 |
$operator = '>='; |
| 117 |
$version2 = '5.5'; |
| 118 |
$versionCompare = CBFunctions()->versionCompare( $version1, $operator, $version2 ); |
| 119 |
|
| 120 |
if ( $versionCompare ) { |
| 121 |
wp_enqueue_script( $this->plugin_name.'-wp-load-scripts', plugin_dir_url(__FILE__) . 'js/load-scripts.js', array(), $this->version, true); |
| 122 |
} |
| 123 |
|
| 124 |
wp_enqueue_script( 'jquery' ); |
| 125 |
|
| 126 |
/* |
| 127 |
========================================== |
| 128 |
* Bootstrap |
| 129 |
* select2 |
| 130 |
* jQuery DataTables |
| 131 |
========================================== |
| 132 |
*/ |
| 133 |
wp_enqueue_script( $this->plugin_name . "-popper", plugin_dir_url(__FILE__) . 'js/popper.min.js', array( 'jquery' ), $this->version, true ); |
| 134 |
wp_enqueue_script( $this->plugin_name . "-bootstrap", plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array( 'jquery' ), $this->version, true ); |
| 135 |
wp_enqueue_script( $this->plugin_name . '-select2js', plugin_dir_url( __FILE__ ) . 'js/ays-select2.min.js', array('jquery'), $this->version, true); |
| 136 |
wp_enqueue_script( $this->plugin_name . '-chosen', plugin_dir_url( __FILE__ ) . 'js/chosen.jquery.min.js', array('jquery'), $this->version, true); |
| 137 |
wp_enqueue_script( $this->plugin_name . '-datatable-min', plugin_dir_url( __FILE__ ) . 'js/chart-builder-datatable.min.js', array('jquery'), $this->version, true); |
| 138 |
wp_enqueue_script( $this->plugin_name . "-db4.min.js", plugin_dir_url( __FILE__ ) . 'js/dataTables.bootstrap4.min.js', array( 'jquery' ), $this->version, true ); |
| 139 |
|
| 140 |
$table_col_mapping = CBFunctions()->get_all_db_tables_column_mapping( 1 ); |
| 141 |
|
| 142 |
wp_enqueue_code_editor( |
| 143 |
array( |
| 144 |
'type' => 'sql', |
| 145 |
'codemirror' => array( |
| 146 |
'autofocus' => true, |
| 147 |
'lineWrapping' => true, |
| 148 |
'dragDrop' => false, |
| 149 |
'matchBrackets' => true, |
| 150 |
'autoCloseBrackets' => true, |
| 151 |
'extraKeys' => array( 'Ctrl-Space' => 'autocomplete' ), |
| 152 |
'hintOptions' => array( 'tables' => $table_col_mapping ), |
| 153 |
), |
| 154 |
) |
| 155 |
); |
| 156 |
|
| 157 |
wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true); |
| 158 |
|
| 159 |
wp_enqueue_script( $this->plugin_name . '-functions', plugin_dir_url( __FILE__ ) . 'js/functions.js', array( 'jquery' ), $this->version, true ); |
| 160 |
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/chart-builder-admin.js', array( 'jquery' ), $this->version .time(), true ); |
| 161 |
|
| 162 |
wp_enqueue_script( $this->plugin_name . "-general-js", plugin_dir_url( __FILE__ ) . 'js/chart-builder-admin-general.js', array( 'jquery' ), $this->version, true ); |
| 163 |
wp_localize_script( $this->plugin_name, 'aysChartBuilderAdmin', array( |
| 164 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 165 |
'selectUserRoles' => __( 'Select user roles', "chart-builder" ), |
| 166 |
'delete' => __( 'Delete', "chart-builder" ), |
| 167 |
'selectQuestionDefaultType' => __( 'Select question default type', "chart-builder" ), |
| 168 |
'yes' => __( 'Yes', "chart-builder" ), |
| 169 |
'cancel' => __( 'Cancel', "chart-builder" ), |
| 170 |
'somethingWentWrong' => __( "Maybe something went wrong.", "chart-builder" ), |
| 171 |
'failed' => __( 'Failed', "chart-builder" ), |
| 172 |
'selectPage' => __( 'Select page', "chart-builder" ), |
| 173 |
'selectPostType' => __( 'Select post type', "chart-builder" ), |
| 174 |
'copied' => __( 'Copied!', "chart-builder"), |
| 175 |
'clickForCopy' => __( 'Click for copy', "chart-builder"), |
| 176 |
'selectForm' => __( 'Select form', "chart-builder"), |
| 177 |
) ); |
| 178 |
|
| 179 |
wp_localize_script( |
| 180 |
$this->plugin_name, 'aysChartBuilderChartSettings', array( |
| 181 |
'types' => CBFunctions()->getAllowedTypes(), |
| 182 |
'max_selected_options' => 2, |
| 183 |
'l10n' => array( |
| 184 |
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', "chart-builder" ), |
| 185 |
'loading' => esc_html__( 'Loading...', "chart-builder" ), |
| 186 |
'filter_config_error' => esc_html__( 'Please check the filters you have configured.', "chart-builder" ), |
| 187 |
'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', "chart-builder" ), |
| 188 |
'save_settings' => __( 'You have modified the chart\'s settings. To modify the source/data again, you must save this chart and reopen it for editing. If you continue without saving the chart, you may lose your changes.', "chart-builder" ), |
| 189 |
), |
| 190 |
'ajax' => array( |
| 191 |
'url' => admin_url( 'admin-ajax.php' ), |
| 192 |
'nonces' => array( |
| 193 |
'filter_get_props' => wp_create_nonce( 'cbuilder-fetch-post-type-props' ), |
| 194 |
'filter_get_data' => wp_create_nonce( 'cbuilder-fetch-post-type-data' ), |
| 195 |
), |
| 196 |
'actions' => array( |
| 197 |
'filter_get_props' => 'fetch_post_type_props', |
| 198 |
'filter_get_data' => 'fetch_post_type_data', |
| 199 |
), |
| 200 |
), |
| 201 |
'db_query' => array( |
| 202 |
'tables' => $table_col_mapping, |
| 203 |
), |
| 204 |
) |
| 205 |
); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
/** |
| 210 |
* Register the administration menu for this plugin into the WordPress Dashboard menu. |
| 211 |
* |
| 212 |
* @since 1.0.0 |
| 213 |
*/ |
| 214 |
public function add_plugin_admin_menu(){ |
| 215 |
|
| 216 |
/* |
| 217 |
* Add a settings page for this plugin to the Settings menu. |
| 218 |
* |
| 219 |
* NOTE: Alternative menu locations are available via WordPress administration menu functions. |
| 220 |
* |
| 221 |
* Administration Menus: http://codex.wordpress.org/Administration_Menus |
| 222 |
* |
| 223 |
*/ |
| 224 |
global $wpdb; |
| 225 |
// $sql = "SELECT COUNT(*) FROM " . esc_sql( $wpdb->prefix . EXAM_MAKER_DB_PREFIX ) . "submissions WHERE `read` = 0 OR `read` = 2 "; |
| 226 |
// $unread_results_count = intval( $wpdb->get_var( $sql ) ); |
| 227 |
$menu_item = __( 'Chart Builder', "chart-builder" );// : 'Exam Maker' . '<span class="ays-survey-menu-badge ays-survey-results-bage">' . $unread_results_count . '</span>'; |
| 228 |
|
| 229 |
$this->capability = 'manage_options';// $this->survey_maker_capabilities(); |
| 230 |
// $this->current_user_can_edit = Survey_Maker_Data::survey_maker_capabilities_for_editing(); |
| 231 |
|
| 232 |
$hook_page_view = add_menu_page( |
| 233 |
__( 'Charts', "chart-builder" ), |
| 234 |
$menu_item, |
| 235 |
$this->capability, |
| 236 |
$this->plugin_name, |
| 237 |
array($this, 'display_plugin_charts_page'), |
| 238 |
CHART_BUILDER_ADMIN_URL . '/images/icons/ays_chart_logo_icon.png', |
| 239 |
'46.00' |
| 240 |
); |
| 241 |
|
| 242 |
add_action( "load-$hook_page_view", array( $this, 'screen_option_charts' ) ); |
| 243 |
|
| 244 |
} |
| 245 |
|
| 246 |
public function screen_option_charts(){ |
| 247 |
$option = 'per_page'; |
| 248 |
$args = array( |
| 249 |
'label' => __('Charts', "chart-builder"), |
| 250 |
'default' => 5, |
| 251 |
'option' => 'cb_charts_per_page' |
| 252 |
); |
| 253 |
|
| 254 |
if( ! ( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ) ){ |
| 255 |
add_screen_option( $option, $args ); |
| 256 |
} |
| 257 |
|
| 258 |
// $this->charts_obj = new Surveys_List_Table($this->plugin_name); |
| 259 |
$this->db_obj = new Chart_Builder_DB_Actions( $this->plugin_name ); |
| 260 |
// var_dump($this); |
| 261 |
// $this->settings_obj = new Survey_Maker_Settings_Actions($this->plugin_name); |
| 262 |
} |
| 263 |
|
| 264 |
public function display_plugin_charts_page(){ |
| 265 |
global $ays_chart_db_actions; |
| 266 |
|
| 267 |
$action = (isset($_GET['action'])) ? sanitize_text_field( $_GET['action'] ) : ''; |
| 268 |
$id = (isset($_GET['id'])) ? absint( esc_attr($_GET['id']) ) : 0; |
| 269 |
|
| 270 |
switch ($action) { |
| 271 |
case 'trash': |
| 272 |
if( $id > 0 ){ |
| 273 |
$this->db_obj->trash_item( $id ); |
| 274 |
$url = remove_query_arg( array('action', 'id', '_wpnonce') ); |
| 275 |
$url = esc_url_raw( add_query_arg( array( |
| 276 |
"status" => 'trashed' |
| 277 |
), $url ) ); |
| 278 |
wp_redirect( $url ); |
| 279 |
exit; |
| 280 |
} |
| 281 |
break; |
| 282 |
case 'restore': |
| 283 |
if( $id > 0 ){ |
| 284 |
$this->db_obj->restore_item( $id ); |
| 285 |
$url = remove_query_arg( array('action', 'id', '_wpnonce') ); |
| 286 |
$url = esc_url_raw( add_query_arg( array( |
| 287 |
"status" => 'restored' |
| 288 |
), $url ) ); |
| 289 |
wp_redirect( $url ); |
| 290 |
exit; |
| 291 |
} |
| 292 |
break; |
| 293 |
case 'delete': |
| 294 |
if( $id > 0 ){ |
| 295 |
$this->db_obj->delete_item( $id ); |
| 296 |
$url = remove_query_arg( array('action', 'id', '_wpnonce') ); |
| 297 |
$url = esc_url_raw( add_query_arg( array( |
| 298 |
"status" => 'deleted' |
| 299 |
), $url ) ); |
| 300 |
wp_redirect( $url ); |
| 301 |
exit; |
| 302 |
} |
| 303 |
break; |
| 304 |
case 'add': |
| 305 |
include_once('partials/charts/actions/chart-builder-charts-actions.php'); |
| 306 |
break; |
| 307 |
case 'edit': |
| 308 |
include_once('partials/charts/actions/chart-builder-charts-actions.php'); |
| 309 |
break; |
| 310 |
default: |
| 311 |
include_once('partials/charts/chart-builder-charts-display.php'); |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Add settings action link to the plugins page. |
| 317 |
* |
| 318 |
* @since 1.0.0 |
| 319 |
*/ |
| 320 |
public function add_action_links( $links ){ |
| 321 |
/* |
| 322 |
* Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) |
| 323 |
*/ |
| 324 |
$settings_link = array( |
| 325 |
'<a href="' . admin_url('admin.php?page=' . $this->plugin_name) . '">' . __('Settings', "chart-builder") . '</a>', |
| 326 |
'<a href="https://ays-demo.com/chart-builder-demo/" target="_blank">' . __('Demo', "chart-builder") . '</a>', |
| 327 |
); |
| 328 |
return array_merge( $settings_link, $links ); |
| 329 |
|
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
public static function set_screen($status, $option, $value){ |
| 334 |
return $value; |
| 335 |
} |
| 336 |
|
| 337 |
public function ays_admin_ajax(){ |
| 338 |
global $wpdb; |
| 339 |
|
| 340 |
$response = array( |
| 341 |
"status" => false |
| 342 |
); |
| 343 |
|
| 344 |
$function = isset($_REQUEST['function']) ? sanitize_text_field( $_REQUEST['function'] ) : null; |
| 345 |
|
| 346 |
if($function !== null){ |
| 347 |
$response = array(); |
| 348 |
if( is_callable( array( $this, $function ) ) ){ |
| 349 |
$response = $this->$function(); |
| 350 |
|
| 351 |
ob_end_clean(); |
| 352 |
$ob_get_clean = ob_get_clean(); |
| 353 |
echo json_encode( $response ); |
| 354 |
wp_die(); |
| 355 |
} |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
ob_end_clean(); |
| 360 |
$ob_get_clean = ob_get_clean(); |
| 361 |
echo json_encode( $response ); |
| 362 |
wp_die(); |
| 363 |
} |
| 364 |
|
| 365 |
public function deactivate_plugin_option(){ |
| 366 |
$request_value = esc_attr($_REQUEST['upgrade_plugin']); |
| 367 |
$upgrade_option = get_option( 'ays_chart_builder_upgrade_plugin', '' ); |
| 368 |
if($upgrade_option === ''){ |
| 369 |
add_option( 'ays_chart_builder_upgrade_plugin', $request_value ); |
| 370 |
}else{ |
| 371 |
update_option( 'ays_chart_builder_upgrade_plugin', $request_value ); |
| 372 |
} |
| 373 |
ob_end_clean(); |
| 374 |
$ob_get_clean = ob_get_clean(); |
| 375 |
return json_encode( array( 'option' => get_option( 'ays_chart_builder_upgrade_plugin', '' ) ) ); |
| 376 |
wp_die(); |
| 377 |
} |
| 378 |
|
| 379 |
public function chart_builder_admin_footer($a){ |
| 380 |
if(isset($_REQUEST['page'])){ |
| 381 |
if(false !== strpos( sanitize_text_field( $_REQUEST['page'] ), $this->plugin_name)){ |
| 382 |
?> |
| 383 |
<p style="font-size:13px;text-align:center;font-style:italic;"> |
| 384 |
<span style="margin-left:0px;margin-right:10px;" class="ays_heart_beat"><i class="ays_fa ays_fa_heart_o animated"></i></span> |
| 385 |
<span><?php echo esc_html(__( "If you love our plugin, please do big favor and rate us on", "chart-builder")); ?></span> |
| 386 |
<a target="_blank" href='https://wordpress.org/support/plugin/chart-builder/reviews/'>WordPress.org</a> |
| 387 |
<span class="ays_heart_beat"><i class="ays_fa ays_fa_heart_o animated"></i></span> |
| 388 |
</p> |
| 389 |
<?php |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
public function fetch_post_type_props(){ |
| 395 |
$nonce = isset( $_POST['nonce'] ) ? wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'cbuilder-fetch-post-type-props' ) : ''; |
| 396 |
if ( $nonce ) { |
| 397 |
$results = CBFunctions()->get_post_type_properties( sanitize_text_field( $_POST['post_type'] ) ); |
| 398 |
|
| 399 |
return array( |
| 400 |
'success' => true, |
| 401 |
'fields' => $results, |
| 402 |
); |
| 403 |
} |
| 404 |
|
| 405 |
return array( |
| 406 |
'success' => false, |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Chart page action hooks |
| 412 |
*/ |
| 413 |
|
| 414 |
/** |
| 415 |
* Chart page sources contents |
| 416 |
* @param $args |
| 417 |
*/ |
| 418 |
public function ays_chart_page_source_contents( $args ){ |
| 419 |
|
| 420 |
$sources_contents = apply_filters( 'ays_cb_chart_page_sources_contents_settings', array(), $args ); |
| 421 |
|
| 422 |
$source_type = $args['source_type']; |
| 423 |
|
| 424 |
$sources = array(); |
| 425 |
foreach ( $sources_contents as $key => $sources_content ) { |
| 426 |
$collapsed = $key == $source_type ? 'false' : 'true'; |
| 427 |
|
| 428 |
$content = '<fieldset class="ays-accordion-options-container" data-collapsed="'. $collapsed .'">'; |
| 429 |
if( isset( $sources_content['title'] ) ){ |
| 430 |
$content .= '<legend class="ays-accordion-options-header">'; |
| 431 |
$content .= '<svg class="ays-accordion-arrow '. ( $key == $source_type ? 'ays-accordion-arrow-down' : 'ays-accordion-arrow-right' ) .'" version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="visible" preserveAspectRatio="none" viewBox="0 0 24 24" width="20" height="20"> |
| 432 |
<g> |
| 433 |
<path xmlns:default="http://www.w3.org/2000/svg" d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z" style="fill: rgb(0, 140, 255);" vector-effect="non-scaling-stroke" /> |
| 434 |
</g> |
| 435 |
</svg>'; |
| 436 |
|
| 437 |
$content .= '<span>'. $sources_content['title'] .'</span></legend>'; |
| 438 |
} |
| 439 |
|
| 440 |
$content .= '<div class="ays-accordion-options-content">'; |
| 441 |
$content .= $sources_content['content']; |
| 442 |
$content .= '</div>'; |
| 443 |
|
| 444 |
$content .= '</fieldset>'; |
| 445 |
|
| 446 |
$sources[] = $content; |
| 447 |
} |
| 448 |
$content_for_escape = implode('' , $sources ); |
| 449 |
echo html_entity_decode(esc_html( $content_for_escape )); |
| 450 |
} |
| 451 |
|
| 452 |
public function source_contents_manual_settings( $sources, $args ){ |
| 453 |
$html_class_prefix = $args['html_class_prefix']; |
| 454 |
$html_name_prefix = $args['html_name_prefix']; |
| 455 |
$source = $args['source']; |
| 456 |
$settings = $args['settings']; |
| 457 |
|
| 458 |
ob_start(); |
| 459 |
?> |
| 460 |
<div class="ays-accordion-data-main-wrap"> |
| 461 |
<div class="<?php echo esc_attr($html_class_prefix) ?>source-data-main-wrap"> |
| 462 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-main"> |
| 463 |
<!-- <div class="<//?= $html_class_prefix ?>icons-box"> |
| 464 |
<img class="<//?= $html_class_prefix ?>add-new-row" src="<//?php echo CHART_BUILDER_ADMIN_URL; ?>/images/icons/add-circle-outline.svg"> |
| 465 |
</div> --> |
| 466 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-content-container"> |
| 467 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-content"> |
| 468 |
<?php if(!empty($source)): |
| 469 |
foreach($source as $source_id => $source_value): |
| 470 |
if(!empty($source_value) ): ?> |
| 471 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-edit-block" data-source-id = "<?php echo esc_attr($source_id); ?>"> |
| 472 |
<div class="<?php echo esc_attr($html_class_prefix) ?>icons-box <?php echo esc_attr($html_class_prefix) ?>icons-remove-box"> |
| 473 |
<svg class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-remove-block" data-trigger="hover" data-toggle="tooltip" title="Delete row" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"> |
| 474 |
<path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;"/> |
| 475 |
</svg> |
| 476 |
</div> |
| 477 |
<?php foreach($source_value as $each_source_id => $each_source_value): ?> |
| 478 |
<?php if ($each_source_id == 0): ?> |
| 479 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-box"> |
| 480 |
<input type="text" class="ays-text-input form-control" name="<?php echo esc_attr($html_name_prefix); ?>chart_source_data[<?php echo esc_attr($source_id); ?>][]" value="<?php echo stripslashes(esc_attr($each_source_value)); ?>"> |
| 481 |
</div> |
| 482 |
<?php else: ?> |
| 483 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-box <?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-number"> |
| 484 |
<input type="number" class="ays-text-input form-control" name="<?php echo esc_attr($html_name_prefix); ?>chart_source_data[<?php echo esc_attr($source_id); ?>][]" value="<?php echo stripslashes(esc_attr($each_source_value)); ?>"> |
| 485 |
</div> |
| 486 |
<?php endif; ?> |
| 487 |
<?php endforeach; ?> |
| 488 |
</div> |
| 489 |
<?php endif; ?> |
| 490 |
<?php endforeach; ?> |
| 491 |
<?php else:?> |
| 492 |
<div class = "<?php echo esc_attr($html_class_prefix) ?>chart-source-data-edit-block" data-source-id="1"> |
| 493 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-box"> |
| 494 |
<input type="text" class="ays-text-input form-control" name="<?php echo esc_attr($html_name_prefix); ?>chart_source_data[1][]" > |
| 495 |
</div> |
| 496 |
<div class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-box <?php echo esc_attr($html_class_prefix) ?>chart-source-data-input-number"> |
| 497 |
<input type="number" class="ays-text-input form-control" name="<?php echo esc_attr($html_name_prefix); ?>chart_source_data[1][]"> |
| 498 |
</div> |
| 499 |
<div class="<?php echo esc_attr($html_class_prefix) ?>icons-box <?php echo esc_attr($html_class_prefix) ?>icons-remove-box" > |
| 500 |
<svg class="<?php echo esc_attr($html_class_prefix) ?>chart-source-data-remove-block" data-trigger="hover" data-toggle="tooltip" title="Delete row" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"> |
| 501 |
<path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;"/> |
| 502 |
</svg> |
| 503 |
</div> |
| 504 |
</div> |
| 505 |
<?php endif; ?> |
| 506 |
</div> |
| 507 |
<div class="<?php echo esc_attr($html_class_prefix) ?>icons-box <?php echo esc_attr($html_class_prefix) ?>add-new-column-box" style="display: none;"> |
| 508 |
<img class="<?php echo esc_attr($html_class_prefix) ?>add-new-column" src="<?php echo esc_url(CHART_BUILDER_ADMIN_URL); ?>/images/icons/add-circle-outline.svg"> |
| 509 |
Add column |
| 510 |
</div> |
| 511 |
</div> |
| 512 |
<div class="<?php echo esc_attr($html_class_prefix) ?>icons-box <?php echo esc_attr($html_class_prefix) ?>add-new-row-box"> |
| 513 |
<img class="<?php echo esc_attr($html_class_prefix) ?>add-new-row" src="<?php echo esc_url(CHART_BUILDER_ADMIN_URL); ?>/images/icons/add-circle-outline.svg"> |
| 514 |
Add row |
| 515 |
</div> |
| 516 |
<br> |
| 517 |
<button class="<?php echo esc_attr($html_class_prefix) ?>show-on-chart-bttn button button-primary ays-button">Show on Chart</button> |
| 518 |
</div> |
| 519 |
</div> |
| 520 |
</div> |
| 521 |
<?php |
| 522 |
$content = ob_get_clean(); |
| 523 |
|
| 524 |
$title = __( 'Manual data', "chart-builder" ) . ' <a class="ays_help" data-toggle="tooltip" title="' . __("Add the data manually. By clicking on the Add Row button you will be able to add as many rows as you need. While choosing the Line Chart type you will be able to also add the columns.","chart-builder") . '"> |
| 525 |
<i class="ays_fa ays_fa_info_circle"></i> |
| 526 |
</a>'; |
| 527 |
|
| 528 |
$sources['manual'] = array( |
| 529 |
'content' => $content, |
| 530 |
'title' => $title |
| 531 |
); |
| 532 |
|
| 533 |
return $sources; |
| 534 |
} |
| 535 |
|
| 536 |
/** |
| 537 |
* Chart page settings contents |
| 538 |
* @param $args |
| 539 |
*/ |
| 540 |
public function ays_chart_page_settings_contents( $args ){ |
| 541 |
|
| 542 |
$sources_contents = apply_filters( 'ays_cb_chart_page_settings_contents_settings', array(), $args ); |
| 543 |
|
| 544 |
$sources = array(); |
| 545 |
foreach ( $sources_contents as $key => $sources_content ) { |
| 546 |
$collapsed = $key == 'general_settings' ? 'false' : 'true'; |
| 547 |
|
| 548 |
$content = '<fieldset class="ays-accordion-options-container" data-collapsed="' . $collapsed . '">'; |
| 549 |
if(isset($sources_content['title'])){ |
| 550 |
$content .= '<legend class="ays-accordion-options-header">'; |
| 551 |
$content .= '<svg class="ays-accordion-arrow ays-accordion-arrow-right" version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="visible" preserveAspectRatio="none" viewBox="0 0 24 24" width="20" height="20"> |
| 552 |
<g> |
| 553 |
<path xmlns:default="http://www.w3.org/2000/svg" d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z" style="fill: rgb(0, 140, 255);" vector-effect="non-scaling-stroke" /> |
| 554 |
</g> |
| 555 |
</svg>'; |
| 556 |
|
| 557 |
$content .= '<span>'. esc_html($sources_content['title']) .'</span></legend>'; |
| 558 |
} |
| 559 |
|
| 560 |
$content .= '<div class="ays-accordion-options-content">'; |
| 561 |
$content .= $sources_content['content']; |
| 562 |
$content .= '</div>'; |
| 563 |
|
| 564 |
$content .= '</fieldset>'; |
| 565 |
|
| 566 |
$sources[] = $content; |
| 567 |
} |
| 568 |
$content_for_escape = implode('' , $sources ); |
| 569 |
echo html_entity_decode(esc_html( $content_for_escape )); |
| 570 |
} |
| 571 |
|
| 572 |
public function settings_contents_general_settings( $sources, $args ){ |
| 573 |
$html_class_prefix = $args['html_class_prefix']; |
| 574 |
$html_name_prefix = $args['html_name_prefix']; |
| 575 |
$status = $args['status']; |
| 576 |
|
| 577 |
ob_start(); |
| 578 |
?> |
| 579 |
<div class="ays-accordion-data-main-wrap"> |
| 580 |
<div class="<?php echo esc_attr($html_class_prefix) ?>settings-data-main-wrap"> |
| 581 |
<div class="form-group row <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 582 |
<div class="col-sm-5 <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 583 |
<label for="ays-status" class="form-label"> |
| 584 |
<?php echo esc_html(__('Chart status', "chart-builder")); ?> |
| 585 |
<a class="ays_help" data-toggle="tooltip" title="<?php echo esc_attr( __("Decide whether the chart is active or not. If the chart is a draft, it won't be shown anywhere on your website (you don't need to remove shortcodes).","chart-builder") ); ?>"> |
| 586 |
<i class="ays_fa ays_fa_info_circle"></i> |
| 587 |
</a> |
| 588 |
</label> |
| 589 |
</div> |
| 590 |
<div class="col-sm-7 py-2 <?php echo esc_attr($html_class_prefix) ?>input-align-right"> |
| 591 |
<label class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch-switch"> |
| 592 |
<input class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch" id="ays-status" type="checkbox" name="<?php echo esc_attr($html_name_prefix); ?>status" value="published" <?php echo $status == 'published' ? 'checked' : ''; ?> > |
| 593 |
<span class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch-slider <?php echo esc_attr($html_class_prefix) ?>toggle-switch-round"></span> |
| 594 |
</label> |
| 595 |
</div> |
| 596 |
</div> <!-- Status --> |
| 597 |
</div> |
| 598 |
</div> |
| 599 |
<?php |
| 600 |
$content = ob_get_clean(); |
| 601 |
|
| 602 |
$title = __( 'General Settings', "chart-builder" ); |
| 603 |
|
| 604 |
$sources['general_settings'] = array( |
| 605 |
'content' => $content, |
| 606 |
'title' => $title |
| 607 |
); |
| 608 |
|
| 609 |
return $sources; |
| 610 |
} |
| 611 |
|
| 612 |
public function settings_contents_styles_settings( $sources, $args ){ |
| 613 |
$html_class_prefix = $args['html_class_prefix']; |
| 614 |
$html_name_prefix = $args['html_name_prefix']; |
| 615 |
$settings = $args['settings']; |
| 616 |
$width = $settings['width']; |
| 617 |
$height = $settings['height']; |
| 618 |
$font_size = $settings['font_size']; |
| 619 |
$title_color = $settings['title_color']; |
| 620 |
|
| 621 |
ob_start(); |
| 622 |
?> |
| 623 |
<div class="ays-accordion-data-main-wrap"> |
| 624 |
<div class="<?php echo esc_attr($html_class_prefix) ?>settings-data-main-wrap"> |
| 625 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 626 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 627 |
<label for="ays-chart-option-width" class="form-label"> |
| 628 |
<?php echo esc_html(__( "Width", "chart-builder" )); ?> |
| 629 |
</label> |
| 630 |
</div> |
| 631 |
<div class="col-sm-7 <?php echo esc_attr($html_class_prefix) ?>option-input"> |
| 632 |
<input class="ays-text-input form-control <?php echo esc_attr($html_class_prefix) ?>option-text-input" id="ays-chart-option-width" type="number" name="<?php echo esc_attr($html_name_prefix); ?>settings[width]" value="<?php echo esc_attr($width) ?>"> |
| 633 |
<div class="<?php echo esc_attr($html_class_prefix) ?>option-desc-box"><img src="<?php echo esc_url(CHART_BUILDER_ADMIN_URL); ?>/images/icons/percent.svg"></div> |
| 634 |
</div> |
| 635 |
</div> <!-- Width --> |
| 636 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 637 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 638 |
<label for="ays-chart-option-height" class="form-label"> |
| 639 |
<?php echo esc_html(__( "Height", "chart-builder" )); ?> |
| 640 |
</label> |
| 641 |
</div> |
| 642 |
<div class="col-sm-7 <?php echo esc_attr($html_class_prefix) ?>option-input"> |
| 643 |
<input class="ays-text-input form-control <?php echo esc_attr($html_class_prefix) ?>option-text-input" id="ays-chart-option-height" type="number" name="<?php echo esc_attr($html_name_prefix); ?>settings[height]" value="<?php echo esc_attr($height) ?>"> |
| 644 |
<div class="<?php echo esc_attr($html_class_prefix) ?>option-desc-box">px</div> |
| 645 |
</div> |
| 646 |
</div> <!-- Height --> |
| 647 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 648 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 649 |
<label for="ays-chart-option-font-size" class="form-label"> |
| 650 |
<?php echo esc_html(__( "Font size", "chart-builder" )); ?> |
| 651 |
</label> |
| 652 |
</div> |
| 653 |
<div class="col-sm-7 <?php echo esc_attr($html_class_prefix) ?>option-input"> |
| 654 |
<input class="ays-text-input form-control <?php echo esc_attr($html_class_prefix) ?>option-text-input" id="ays-chart-option-font-size" type="number" name="<?php echo esc_attr($html_name_prefix); ?>settings[font_size]" value="<?php echo esc_attr($font_size) ?>"> |
| 655 |
<div class="<?php echo esc_attr($html_class_prefix) ?>option-desc-box">px</div> |
| 656 |
</div> |
| 657 |
</div> <!-- Font size --> |
| 658 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 659 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 660 |
<label for="ays-chart-option-title-color"> |
| 661 |
<?php echo esc_html(__( "Chart title color", "chart-builder" )); ?> |
| 662 |
</label> |
| 663 |
</div> |
| 664 |
<div class="col-sm-7 <?php echo esc_attr($html_class_prefix) ?>input-align-right"> |
| 665 |
<input id="ays-chart-option-title-color" class="form-control-color" type="color" name="<?php echo esc_attr($html_name_prefix); ?>settings[title_color]" value="<?php echo esc_attr($title_color) ?>"> |
| 666 |
</div> |
| 667 |
</div> <!-- Chart title color --> |
| 668 |
</div> |
| 669 |
</div> |
| 670 |
<?php |
| 671 |
$content = ob_get_clean(); |
| 672 |
|
| 673 |
$title = __( 'Styles', "chart-builder" ); |
| 674 |
|
| 675 |
$sources['styles'] = array( |
| 676 |
'content' => $content, |
| 677 |
'title' => $title |
| 678 |
); |
| 679 |
|
| 680 |
return $sources; |
| 681 |
} |
| 682 |
|
| 683 |
public function settings_contents_tooltip_settings( $sources, $args ){ |
| 684 |
$html_class_prefix = $args['html_class_prefix']; |
| 685 |
$html_name_prefix = $args['html_name_prefix']; |
| 686 |
$settings = $args['settings']; |
| 687 |
$width = $settings['width']; |
| 688 |
$tooltip_trigger_options = $settings['tooltip_trigger_options']; |
| 689 |
$tooltip_trigger = $settings['tooltip_trigger']; |
| 690 |
$show_color_code = $settings['show_color_code']; |
| 691 |
|
| 692 |
ob_start(); |
| 693 |
?> |
| 694 |
<div class="ays-accordion-data-main-wrap"> |
| 695 |
<div class="<?php echo esc_attr($html_class_prefix) ?>settings-data-main-wrap"> |
| 696 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 697 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 698 |
<label for="ays-chart-option-tooltip-trigger"> |
| 699 |
<?php echo esc_html(__( "Trigger", "chart-builder" )); ?> |
| 700 |
<a class="ays_help" data-toggle="tooltip" title="<?php echo htmlspecialchars( __("Choose when to display the results on the chart.","chart-builder") ); ?>"> |
| 701 |
<i class="ays_fa ays_fa_info_circle"></i> |
| 702 |
</a> |
| 703 |
</label> |
| 704 |
</div> |
| 705 |
<div class="col-sm-7"> |
| 706 |
<select class="<?php echo esc_attr($html_class_prefix) ?>option-select-input form-select" id="ays-chart-option-tooltip-trigger" name="<?php echo esc_attr($html_name_prefix); ?>settings[tooltip_trigger]"> |
| 707 |
<?php |
| 708 |
foreach ( $tooltip_trigger_options as $option_slug => $option ): |
| 709 |
$selected = ( $tooltip_trigger == $option_slug ) ? 'selected' : ''; |
| 710 |
?> |
| 711 |
<option value="<?php echo esc_attr($option_slug); ?>" <?php echo esc_attr($selected); ?>><?php echo esc_html($option); ?></option> |
| 712 |
<?php |
| 713 |
endforeach; |
| 714 |
?> |
| 715 |
</select> |
| 716 |
</div> |
| 717 |
</div> |
| 718 |
<div class="form-group row mb-2 <?php echo esc_attr($html_class_prefix) ?>options-section"> |
| 719 |
<div class="col-sm-5 d-flex align-items-center <?php echo esc_attr($html_class_prefix) ?>option-title"> |
| 720 |
<label for="ays-chart-option-show-color-code"> |
| 721 |
<?php echo esc_html(__( "Show Color Code", "chart-builder" )); ?> |
| 722 |
<a class="ays_help" data-toggle="tooltip" title="<?php echo esc_attr( __("The color will be displayed while clicking on a particular part of the chart.","chart-builder") ); ?>"> |
| 723 |
<i class="ays_fa ays_fa_info_circle"></i> |
| 724 |
</a> |
| 725 |
</label> |
| 726 |
</div> |
| 727 |
<div class="col-sm-7 py-2 <?php echo esc_attr($html_class_prefix) ?>input-align-right"> |
| 728 |
<label class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch-switch"> |
| 729 |
<input class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch" id="ays-chart-option-show-color-code" type="checkbox" name="<?php echo esc_attr($html_name_prefix); ?>settings[show_color_code]" value="on" <?php echo esc_attr($show_color_code); ?> > |
| 730 |
<span class="<?php echo esc_attr($html_class_prefix) ?>toggle-switch-slider <?php echo esc_attr($html_class_prefix) ?>toggle-switch-round"></span> |
| 731 |
</label> |
| 732 |
</div> |
| 733 |
</div> |
| 734 |
</div> |
| 735 |
</div> |
| 736 |
<?php |
| 737 |
$content = ob_get_clean(); |
| 738 |
|
| 739 |
$title = __( 'Tooltip', "chart-builder" ); |
| 740 |
|
| 741 |
$sources['tooltip'] = array( |
| 742 |
'content' => $content, |
| 743 |
'title' => $title |
| 744 |
); |
| 745 |
|
| 746 |
return $sources; |
| 747 |
} |
| 748 |
|
| 749 |
} |
| 750 |
|