*/ class Chart_Builder_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The capability of this plugin. * * @since 1.0.0 * @access private * @var string $capability The capability for users access to this plugin. */ private $capability; /** * @var Chart_Builder_DB_Actions */ private $db_obj; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; add_filter('set-screen-option', array(__CLASS__, 'set_screen'), 10, 3); add_filter('set_screen_option_cb_charts_per_page', array(__CLASS__, 'set_screen'), 10, 3); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles($hook_suffix) { wp_enqueue_style( $this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'css/admin.css', array(), $this->version, 'all'); // Not enqueue styles if they are not on the current plugin page if (false === strpos($hook_suffix, $this->plugin_name)) return; // wp_enqueue_style( $this->plugin_name . '-normalize', plugin_dir_url( __FILE__ ) . 'css/normalize.css', array(), $this->version . time(), 'all' ); wp_enqueue_style( $this->plugin_name . '-admin-general', plugin_dir_url( __FILE__ ) . 'css/admin-general.css', array(), $this->version, 'all' ); wp_enqueue_style( $this->plugin_name . '-banner', plugin_dir_url( __FILE__ ) . 'css/banner.css', array(), $this->version, 'all' ); wp_enqueue_style( $this->plugin_name . '-animate', plugin_dir_url(__FILE__) . 'css/animate.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-font-awesome', plugin_dir_url(__FILE__) . 'css/ays-font-awesome.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-font-awesome-icons', plugin_dir_url(__FILE__) . 'css/ays-font-awesome-icons.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-select2', plugin_dir_url(__FILE__) . 'css/ays-select2.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-chosen', plugin_dir_url(__FILE__) . 'css/chosen.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-data-bootstrap', plugin_dir_url(__FILE__) . 'css/dataTables.bootstrap4.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-layer', plugin_dir_url( __FILE__ ) . 'css/chart-builder-admin-layer.css', array(), $this->version, 'all' ); wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/chart-builder-admin.css', array(), $this->version . time(), 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts($hook_suffix) { if (false !== strpos($hook_suffix, "plugins.php")){ wp_enqueue_script($this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery'), $this->version, true); wp_localize_script($this->plugin_name . '-admin', 'chart_builder_admin_ajax', array('ajax_url' => admin_url('admin-ajax.php'))); } // Not enqueue scripts if they are not on the current plugin page if (false === strpos($hook_suffix, $this->plugin_name)) return; // global $wp_version; $version1 = $wp_version; $operator = '>='; $version2 = '5.5'; $versionCompare = CBFunctions()->versionCompare( $version1, $operator, $version2 ); if ( $versionCompare ) { wp_enqueue_script( $this->plugin_name.'-wp-load-scripts', plugin_dir_url(__FILE__) . 'js/load-scripts.js', array(), $this->version, true); } wp_enqueue_script( 'jquery' ); /* ========================================== * Bootstrap * select2 * jQuery DataTables ========================================== */ wp_enqueue_script( $this->plugin_name . "-popper", plugin_dir_url(__FILE__) . 'js/popper.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . "-bootstrap", plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . '-select2js', plugin_dir_url( __FILE__ ) . 'js/ays-select2.min.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . '-chosen', plugin_dir_url( __FILE__ ) . 'js/chosen.jquery.min.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . '-datatable-min', plugin_dir_url( __FILE__ ) . 'js/chart-builder-datatable.min.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . "-db4.min.js", plugin_dir_url( __FILE__ ) . 'js/dataTables.bootstrap4.min.js', array( 'jquery' ), $this->version, true ); $table_col_mapping = CBFunctions()->get_all_db_tables_column_mapping( 1 ); wp_enqueue_code_editor( array( 'type' => 'sql', 'codemirror' => array( 'autofocus' => true, 'lineWrapping' => true, 'dragDrop' => false, 'matchBrackets' => true, 'autoCloseBrackets' => true, 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete' ), 'hintOptions' => array( 'tables' => $table_col_mapping ), ), ) ); wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . '-functions', plugin_dir_url( __FILE__ ) . 'js/functions.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/chart-builder-admin.js', array( 'jquery' ), $this->version .time(), true ); wp_enqueue_script( $this->plugin_name . "-general-js", plugin_dir_url( __FILE__ ) . 'js/chart-builder-admin-general.js', array( 'jquery' ), $this->version, true ); wp_localize_script( $this->plugin_name, 'aysChartBuilderAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'selectUserRoles' => __( 'Select user roles', "chart-builder" ), 'delete' => __( 'Delete', "chart-builder" ), 'selectQuestionDefaultType' => __( 'Select question default type', "chart-builder" ), 'yes' => __( 'Yes', "chart-builder" ), 'cancel' => __( 'Cancel', "chart-builder" ), 'somethingWentWrong' => __( "Maybe something went wrong.", "chart-builder" ), 'failed' => __( 'Failed', "chart-builder" ), 'selectPage' => __( 'Select page', "chart-builder" ), 'selectPostType' => __( 'Select post type', "chart-builder" ), 'copied' => __( 'Copied!', "chart-builder"), 'clickForCopy' => __( 'Click for copy', "chart-builder"), 'selectForm' => __( 'Select form', "chart-builder"), ) ); wp_localize_script( $this->plugin_name, 'aysChartBuilderChartSettings', array( 'types' => CBFunctions()->getAllowedTypes(), 'max_selected_options' => 2, 'l10n' => array( 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', "chart-builder" ), 'loading' => esc_html__( 'Loading...', "chart-builder" ), 'filter_config_error' => esc_html__( 'Please check the filters you have configured.', "chart-builder" ), 'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', "chart-builder" ), '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" ), ), 'ajax' => array( 'url' => admin_url( 'admin-ajax.php' ), 'nonces' => array( 'filter_get_props' => wp_create_nonce( 'cbuilder-fetch-post-type-props' ), 'filter_get_data' => wp_create_nonce( 'cbuilder-fetch-post-type-data' ), ), 'actions' => array( 'filter_get_props' => 'fetch_post_type_props', 'filter_get_data' => 'fetch_post_type_data', ), ), 'db_query' => array( 'tables' => $table_col_mapping, ), ) ); } /** * Register the administration menu for this plugin into the WordPress Dashboard menu. * * @since 1.0.0 */ public function add_plugin_admin_menu(){ /* * Add a settings page for this plugin to the Settings menu. * * NOTE: Alternative menu locations are available via WordPress administration menu functions. * * Administration Menus: http://codex.wordpress.org/Administration_Menus * */ global $wpdb; // $sql = "SELECT COUNT(*) FROM " . esc_sql( $wpdb->prefix . EXAM_MAKER_DB_PREFIX ) . "submissions WHERE `read` = 0 OR `read` = 2 "; // $unread_results_count = intval( $wpdb->get_var( $sql ) ); $menu_item = __( 'Chart Builder', "chart-builder" );// : 'Exam Maker' . ''; $this->capability = 'manage_options';// $this->survey_maker_capabilities(); // $this->current_user_can_edit = Survey_Maker_Data::survey_maker_capabilities_for_editing(); $hook_page_view = add_menu_page( __( 'Charts', "chart-builder" ), $menu_item, $this->capability, $this->plugin_name, array($this, 'display_plugin_charts_page'), CHART_BUILDER_ADMIN_URL . '/images/icons/ays_chart_logo_icon.png', '46.00' ); add_action( "load-$hook_page_view", array( $this, 'screen_option_charts' ) ); } public function screen_option_charts(){ $option = 'per_page'; $args = array( 'label' => __('Charts', "chart-builder"), 'default' => 5, 'option' => 'cb_charts_per_page' ); if( ! ( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ) ){ add_screen_option( $option, $args ); } // $this->charts_obj = new Surveys_List_Table($this->plugin_name); $this->db_obj = new Chart_Builder_DB_Actions( $this->plugin_name ); // var_dump($this); // $this->settings_obj = new Survey_Maker_Settings_Actions($this->plugin_name); } public function display_plugin_charts_page(){ global $ays_chart_db_actions; $action = (isset($_GET['action'])) ? sanitize_text_field( $_GET['action'] ) : ''; $id = (isset($_GET['id'])) ? absint( esc_attr($_GET['id']) ) : 0; switch ($action) { case 'trash': if( $id > 0 ){ $this->db_obj->trash_item( $id ); $url = remove_query_arg( array('action', 'id', '_wpnonce') ); $url = esc_url_raw( add_query_arg( array( "status" => 'trashed' ), $url ) ); wp_redirect( $url ); exit; } break; case 'restore': if( $id > 0 ){ $this->db_obj->restore_item( $id ); $url = remove_query_arg( array('action', 'id', '_wpnonce') ); $url = esc_url_raw( add_query_arg( array( "status" => 'restored' ), $url ) ); wp_redirect( $url ); exit; } break; case 'delete': if( $id > 0 ){ $this->db_obj->delete_item( $id ); $url = remove_query_arg( array('action', 'id', '_wpnonce') ); $url = esc_url_raw( add_query_arg( array( "status" => 'deleted' ), $url ) ); wp_redirect( $url ); exit; } break; case 'add': include_once('partials/charts/actions/chart-builder-charts-actions.php'); break; case 'edit': include_once('partials/charts/actions/chart-builder-charts-actions.php'); break; default: include_once('partials/charts/chart-builder-charts-display.php'); } } /** * Add settings action link to the plugins page. * * @since 1.0.0 */ public function add_action_links( $links ){ /* * Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) */ $settings_link = array( '' . __('Settings', "chart-builder") . '', '' . __('Demo', "chart-builder") . '', ); return array_merge( $settings_link, $links ); } public static function set_screen($status, $option, $value){ return $value; } public function ays_admin_ajax(){ global $wpdb; $response = array( "status" => false ); $function = isset($_REQUEST['function']) ? sanitize_text_field( $_REQUEST['function'] ) : null; if($function !== null){ $response = array(); if( is_callable( array( $this, $function ) ) ){ $response = $this->$function(); ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode( $response ); wp_die(); } } ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode( $response ); wp_die(); } public function deactivate_plugin_option(){ $request_value = esc_attr($_REQUEST['upgrade_plugin']); $upgrade_option = get_option( 'ays_chart_builder_upgrade_plugin', '' ); if($upgrade_option === ''){ add_option( 'ays_chart_builder_upgrade_plugin', $request_value ); }else{ update_option( 'ays_chart_builder_upgrade_plugin', $request_value ); } ob_end_clean(); $ob_get_clean = ob_get_clean(); return json_encode( array( 'option' => get_option( 'ays_chart_builder_upgrade_plugin', '' ) ) ); wp_die(); } public function chart_builder_admin_footer($a){ if(isset($_REQUEST['page'])){ if(false !== strpos( sanitize_text_field( $_REQUEST['page'] ), $this->plugin_name)){ ?>
get_post_type_properties( sanitize_text_field( $_POST['post_type'] ) ); return array( 'success' => true, 'fields' => $results, ); } return array( 'success' => false, ); } /** * Chart page action hooks */ /** * Chart page sources contents * @param $args */ public function ays_chart_page_source_contents( $args ){ $sources_contents = apply_filters( 'ays_cb_chart_page_sources_contents_settings', array(), $args ); $source_type = $args['source_type']; $sources = array(); foreach ( $sources_contents as $key => $sources_content ) { $collapsed = $key == $source_type ? 'false' : 'true'; $content = ''; $sources[] = $content; } $content_for_escape = implode('' , $sources ); echo html_entity_decode(esc_html( $content_for_escape )); } public function source_contents_manual_settings( $sources, $args ){ $html_class_prefix = $args['html_class_prefix']; $html_name_prefix = $args['html_name_prefix']; $source = $args['source']; $settings = $args['settings']; ob_start(); ?>