/** * Handles chart type selection page. * * @since 1.0.0 * * @access private */ private function _handleTypesPage() { // process post request if ($_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce(filter_input(INPUT_POST, 'nonce'))) { $type = filter_input(INPUT_POST, 'type'); if (in_array($type, Visualizer_Plugin::getChartTypes())) { // save new chart type update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, $type); // if the chart has default data, update it with appropriate default data for new type if (filter_var(get_post_meta($this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true), FILTER_VALIDATE_BOOLEAN)) { $source = new Visualizer_Source_Csv(VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv'); $source->fetch(); $this->_chart->post_content = $source->getData(); wp_update_post($this->_chart->to_array()); update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries()); } // redirect to next tab wp_redirect(add_query_arg('tab', 'data')); return; } } $render = new Visualizer_Render_Page_Types(); $render->type = get_post_meta($this->_chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true); $render->types = Visualizer_Plugin::getChartTypes(); $render->chart = $this->_chart; wp_enqueue_style('visualizer-frame'); wp_enqueue_script('visualizer-frame'); wp_iframe(array($render, 'render')); }
/** * Renders visualizer library page. * * @since 1.0.0 * * @access public */ public function renderLibraryPage() { // get current page $page = filter_input(INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'default' => 1))); // the initial query arguments to fetch charts $query_args = array('post_type' => Visualizer_Plugin::CPT_VISUALIZER, 'posts_per_page' => 6, 'paged' => $page); // add chart type filter to the query arguments $filter = filter_input(INPUT_GET, 'type'); if ($filter && in_array($filter, Visualizer_Plugin::getChartTypes())) { $query_args['meta_query'] = array(array('key' => Visualizer_Plugin::CF_CHART_TYPE, 'value' => $filter, 'compare' => '=')); } else { $filter = 'all'; } // fetch charts $charts = array(); $query = new WP_Query($query_args); while ($query->have_posts()) { $chart = $query->next_post(); // fetch and update settings $settings = get_post_meta($chart->ID, Visualizer_Plugin::CF_SETTINGS, true); unset($settings['height'], $settings['width']); $type = get_post_meta($chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true); $series = apply_filters(Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta($chart->ID, Visualizer_Plugin::CF_SERIES, true), $chart->ID, $type); $data = apply_filters(Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize($chart->post_content), $chart->ID, $type); // add chart to the array $charts['visualizer-' . $chart->ID] = array('id' => $chart->ID, 'type' => $type, 'series' => $series, 'settings' => $settings, 'data' => $data); } // enqueue charts array $ajaxurl = admin_url('admin-ajax.php'); wp_localize_script('visualizer-library', 'visualizer', array('charts' => $charts, 'urls' => array('base' => add_query_arg('vpage', false), 'create' => add_query_arg(array('action' => Visualizer_Plugin::ACTION_CREATE_CHART, 'library' => 'yes'), $ajaxurl), 'edit' => add_query_arg(array('action' => Visualizer_Plugin::ACTION_EDIT_CHART, 'library' => 'yes'), $ajaxurl)))); // render library page $render = new Visualizer_Render_Library(); $render->charts = $charts; $render->type = $filter; $render->types = self::_getChartTypesLocalized(); $render->pagination = paginate_links(array('base' => add_query_arg('vpage', '%#%'), 'format' => '', 'current' => $page, 'total' => $query->max_num_pages, 'type' => 'array')); $render->render(); }