/** * Handle table row delete */ function wdt_delete_table_row() { global $wpdb; $table_id = filter_var($_POST['table_id'], FILTER_SANITIZE_NUMBER_INT); $id_key = filter_var($_POST['id_key'], FILTER_SANITIZE_STRING); $id_val = filter_var($_POST['id_val'], FILTER_SANITIZE_NUMBER_INT); $table_data = wdt_get_table_by_id($table_id); $mysql_table_name = $table_data['mysql_table_name']; // If current user cannot edit - do nothing if (!wdt_current_user_can_edit($table_data['editor_roles'], $table_id)) { exit; } do_action('wpdatatables_before_delete_row', $id_val, $table_id); // If the plugin is using WP DB if (!get_option('wdtUseSeparateCon')) { $wpdb->delete($mysql_table_name, array($id_key => $id_val)); } else { $sql = new PDTSql(WDT_MYSQL_HOST, WDT_MYSQL_DB, WDT_MYSQL_USER, WDT_MYSQL_PASSWORD); $query = "DELETE FROM " . $mysql_table_name . " WHERE `" . $id_key . "`='" . $id_val . "'"; $sql->doQuery($query); } exit; }
/** * Duplicate the table */ function wpdatatables_duplicate_table() { global $wpdb; $table_id = $query = wpdatatables_sanitize_query($_POST['table_id']); $new_table_name = wpdatatables_sanitize_query($_POST['new_table_name']); // Getting the table data $table_data = wdt_get_table_by_id($table_id); // Creating new table $wpdb->insert($wpdb->prefix . 'wpdatatables', array('title' => $new_table_name, 'table_type' => $table_data['table_type'], 'content' => $table_data['content'], 'filtering' => $table_data['filtering'], 'sorting' => $table_data['sorting'], 'tools' => $table_data['tools'], 'display_length' => $table_data['display_length'], 'fixed_columns' => $table_data['fixed_columns'], 'chart' => $table_data['chart'], 'chart_title' => $table_data['chart_title'], 'server_side' => $table_data['server_side'], 'fixed_layout' => $table_data['fixed_layout'], 'word_wrap' => $table_data['word_wrap'], 'editable' => $table_data['editable'], 'mysql_table_name' => $table_data['mysql_table_name'], 'responsive' => $table_data['responsive'], 'filtering_form' => $table_data['filtering_form'], 'editor_roles' => $table_data['editor_roles'])); $new_table_id = $wpdb->insert_id; // Getting the column data $columns = wdt_get_columns_by_table_id($table_id); // Creating new columns foreach ($columns as $column) { $wpdb->insert($wpdb->prefix . 'wpdatatables_columns', array('table_id' => $new_table_id, 'orig_header' => $column->orig_header, 'css_class' => $column->css_class, 'display_header' => $column->display_header, 'filter_type' => $column->filter_type, 'column_type' => $column->column_type, 'group_column' => $column->group_column, 'use_in_chart' => $column->use_in_chart, 'chart_horiz_axis' => $column->chart_horiz_axis, 'visible' => $column->visible, 'width' => $column->width, 'pos' => $column->pos, 'input_type' => $column->input_type, 'id_column' => $column->id_column, 'sort_column' => $column->sort_column, 'possible_values' => $column->possible_values, 'hide_on_phones' => $column->hide_on_phones, 'hide_on_tablets' => $column->hide_on_tablets, 'default_value' => $column->default_value)); } exit; }
/** * Handler for the shortcode */ function wpdatatable_shortcode_handler($atts, $content = null) { global $wpdb, $wdt_var1, $wdt_var2, $wdt_var3; extract(shortcode_atts(array('id' => '0', 'show_only_chart' => false, 'no_scripts' => 0, 'var1' => '', 'var2' => '', 'var3' => ''), $atts)); // Protection if (!$id) { return false; } $table_data = wdt_get_table_by_id($id); $column_data = wdt_get_columns_by_table_id($id); // Do action before rendering a table do_action('wpdatatables_before_render_table', $id); // Shortcode variables $wdt_var1 = $var1; $wdt_var2 = $var2; $wdt_var3 = $var3; // Preparing column properties $column_order = array(); $column_titles = array(); $column_widths = array(); $column_types = array(); $column_possible_values = array(); foreach ($column_data as $column) { $column_order[(int) $column->pos] = $column->orig_header; if ($column->display_header) { $column_titles[$column->orig_header] = $column->display_header; } if ($column->width) { $column_widths[$column->orig_header] = $column->width; } if ($column->column_type != 'autodetect') { $column_types[$column->orig_header] = $column->column_type; } $column_possible_values[$column->orig_header] = $column->possible_values; } $tbl = new WPDataTable(); $tbl->setWpId($id); if (empty($table_data['content'])) { return __('wpDataTable with provided ID not found!', 'wpdatatables'); } switch ($table_data['table_type']) { case 'mysql': if ($table_data['server_side']) { $tbl->enableServerProcessing(); } if ($table_data['editable']) { if (wdt_current_user_can_edit($table_data['editor_roles'], $id)) { $tbl->enableEditing(); } } $tbl->queryBasedConstruct($table_data['content'], array(), array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xls': case 'csv': $tbl->excelBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xml': $tbl->XMLBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'json': $tbl->jsonBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'serialized': $array = unserialize(file_get_contents($table_data['content'])); $tbl->arrayBasedConstruct($array, array('data_types' => $column_types, 'column_titles' => $column_titles)); break; } if ($table_data['hide_before_load']) { $tbl->hideBeforeLoad(); } else { $tbl->showBeforeLoad(); } $tbl->reorderColumns($column_order); $tbl->wdtDefineColumnsWidth($column_widths); $tbl->setColumnsPossibleValues($column_possible_values); // Applying form $tbl->setFilteringForm($table_data['filtering_form']); // Applying responsiveness if ($table_data['responsive']) { $tbl->setResponsive(true); } // Applying filter, if enabled if ($table_data['filtering']) { $tbl->enableAdvancedFilter(); } if (!$no_scripts) { wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-progressbar'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-ui-button'); wp_enqueue_style('dashicons'); wp_enqueue_script('wdt_google_charts', 'https://www.google.com/jsapi'); wp_enqueue_script('formstone-selecter', WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js'); wp_enqueue_style('formstone-selecter', WDT_CSS_PATH . 'jquery.fs.selecter.css'); wp_enqueue_script('formstone-picker', WDT_JS_PATH . 'picker/jquery.fs.picker.min.js'); wp_enqueue_style('formstone-picker', WDT_CSS_PATH . 'jquery.fs.picker.css'); wp_enqueue_script('remodal-popup', WDT_JS_PATH . 'popup/jquery.remodal.min.js'); wp_enqueue_style('remodal-popup', WDT_CSS_PATH . 'jquery.remodal.css'); wp_enqueue_script('pickadate-main', WDT_JS_PATH . 'datepicker/picker.js'); wp_enqueue_script('pickadate-date', WDT_JS_PATH . 'datepicker/picker.date.js'); wp_enqueue_style('pickadate-main', WDT_CSS_PATH . 'datepicker.default.css'); wp_enqueue_style('pickadate-date', WDT_CSS_PATH . 'datepicker.default.date.css'); } else { $tbl->disableScripts(); } foreach ($column_data as $column) { // Set filter types $tbl->getColumn($column->orig_header)->setFilterType($column->filter_type); // Set CSS class $tbl->getColumn($column->orig_header)->addCSSClass($column->css_class); // set visibility if (!$column->visible) { $tbl->getColumn($column->orig_header)->hide(); } // Set default value $tbl->getColumn($column->orig_header)->setDefaultValue($column->default_value); // Check the default values passed from URL if (isset($_GET['wdt_column_filter'])) { foreach ($_GET['wdt_column_filter'] as $fltColKey => $fltDefVal) { $tbl->getColumn($fltColKey)->setDefaultValue($fltDefVal); } } // Set hiding on phones and tablets for responsiveness if ($tbl->isResponsive()) { if ($column->hide_on_phones) { $tbl->getColumn($column->orig_header)->hideOnPhones(); } if ($column->hide_on_tablets) { $tbl->getColumn($column->orig_header)->hideOnTablets(); } } // if grouping enabled for this column, passing it to table class if ($column->group_column) { $tbl->groupByColumn($column->orig_header); } if ($column->sort_column !== '0') { $tbl->setDefaultSortColumn($column->orig_header); if ($column->sort_column == '1') { $tbl->setDefaultSortDirection('ASC'); } elseif ($column->sort_column == '2') { $tbl->setDefaultSortDirection('DESC'); } } if ($table_data['chart'] != 'none') { if ($column->use_in_chart) { $tbl->addChartSeries($column->orig_header); } if ($column->chart_horiz_axis) { $tbl->setChartHorizontalAxis($column->orig_header); } } // Set ID column if specified if ($column->id_column) { $tbl->setIdColumnKey($column->orig_header); } // Set front-end editor input type $tbl->getColumn($column->orig_header)->setInputType($column->input_type); } $output_str = ''; if (!$show_only_chart) { if ($table_data['title']) { $output_str .= apply_filters('wpdatatables_filter_table_title', empty($table_data['title']) ? '' : '<h2>' . $table_data['title'] . '</h2>', $id); } if (!$table_data['sorting']) { $tbl->sortDisable(); } if (!$table_data['tools']) { $tbl->disableTT(); } // display length if ($table_data['display_length'] != 0) { $tbl->setDisplayLength($table_data['display_length']); } else { $tbl->disablePagination(); } if (get_option('wdtInterfaceLanguage') != '') { $tbl->setInterfaceLanguage(get_option('wdtInterfaceLanguage')); } $output_str .= $tbl->generateTable(); } if ($table_data['chart'] != 'none') { $tbl->setChartType(ucfirst($table_data['chart'])); $tbl->setChartTitle($table_data['chart_title']); $tbl->printChart('wdt_' . $tbl->getId() . '_chart'); if (get_option('wdtRenderCharts') == 'above') { $output_str = '<div id="wdt_' . $tbl->getId() . '_chart" class="wpDataTables wdt_chart"></div>' . $output_str; } else { $output_str .= '<div id="wdt_' . $tbl->getId() . '_chart" class="wpDataTables wdt_chart"></div>'; } } // Generate the style block $output_str .= "<style>\n"; // Table layout $customCss = get_option('wdtCustomCss'); if ($table_data['fixed_layout'] || $table_data['word_wrap']) { $output_str .= $table_data['fixed_layout'] ? "table.wpDataTable { table-layout: fixed !important; }\n" : ''; $output_str .= $table_data['word_wrap'] ? "table.wpDataTable td, table.wpDataTable th { white-space: normal !important; }\n" : ''; } if ($customCss) { $output_str .= stripslashes_deep($customCss); } if (get_option('wdtNumbersAlign')) { $output_str .= "table.wpDataTable td.numdata { text-align: right !important; }\n"; } $output_str .= "</style>\n"; $customJs = get_option('wdtCustomJs'); if ($customJs) { $output_str .= '<script type="text/javascript">' . stripslashes_deep($customJs) . '</script>'; } // Color and font settings $wdtFontColorSettings = get_option('wdtFontColorSettings'); if (!empty($wdtFontColorSettings)) { $wdtFontColorSettings = unserialize($wdtFontColorSettings); $tpl = new PDTTpl(); $tpl->addData('wdtFontColorSettings', $wdtFontColorSettings); $tpl->setTemplate('style_block.inc.php'); $style_block_html = $tpl->returnData(); $style_block_html = apply_filters('wpdatatables_filter_style_block', $style_block_html, $id); $output_str .= $style_block_html; } $output_str = apply_filters('wpdatatables_filter_rendered_table', $output_str, $id); return $output_str; }
public function loadChildWPDataTable() { if (empty($this->_wpdatatable_id)) { return false; } $table_data = wdt_get_table_by_id($this->_wpdatatable_id); $column_data = wdt_get_columns_by_table_id($this->_wpdatatable_id); foreach ($column_data as $column) { $column_order[(int) $column->pos] = $column->orig_header; if ($column->display_header) { $column_titles[$column->orig_header] = $column->display_header; } if ($column->width) { $column_widths[$column->orig_header] = $column->width; } if ($column->column_type != 'autodetect') { $column_types[$column->orig_header] = $column->column_type; } $column_possible_values[$column->orig_header] = $column->possible_values; } $tbl = new WPDataTable(); $tbl->setWpId($this->_wpdatatable_id); switch ($table_data['table_type']) { case 'mysql': case 'manual': if ($this->getFollowFiltering() && $table_data['server_side']) { $tbl->enableServerProcessing(); } $tbl->queryBasedConstruct($table_data['content'], array(), array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xls': case 'csv': $tbl->excelBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xml': $tbl->XMLBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'json': $tbl->jsonBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'serialized': $array = unserialize(WDTTools::curlGetData($table_data['content'])); $tbl->arrayBasedConstruct($array, array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'google_spreadsheet': $array = WDTTools::extractGoogleSpreadsheetArray($table_data['content']); $tbl->arrayBasedConstruct($array, array('data_types' => $column_types, 'column_titles' => $column_titles)); break; } $this->_wpdatatable = $tbl; }
/** * Renders the browser of existing tables */ function wpdatatables_browse() { global $wpdb, $wdt_admin_translation_array; if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; if ($action == 'edit') { $id = $_GET['table_id']; $tpl = new PDTTpl(); $tpl->setTemplate('edit_table.inc.php'); // Admin JS wp_enqueue_script('wpdatatables-admin', WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js'); // Google Charts wp_enqueue_script('wdt_google_charts', 'https://www.google.com/jsapi'); // Selecter wp_enqueue_script('wpdatatables-selecter', WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js'); wp_enqueue_style('wpdatatables-selecter', WDT_CSS_PATH . 'jquery.fs.selecter.css'); // Picker wp_enqueue_script('wpdatatables-picker', WDT_JS_PATH . 'picker/jquery.fs.picker.min.js'); wp_enqueue_style('wpdatatables-picker', WDT_CSS_PATH . 'jquery.fs.picker.css'); // Popup wp_enqueue_script('wpdatatables-popup', WDT_JS_PATH . 'popup/jquery.remodal.min.js'); wp_enqueue_style('wpdatatables-popup', WDT_CSS_PATH . 'jquery.remodal.css'); // JsRender wp_enqueue_script('wpdatatables-jsrender', WDT_JS_PATH . 'jsrender/jsrender.min.js'); // Table create/edit JS wp_enqueue_script('wpdatatables-edit', WDT_JS_PATH . 'wpdatatables/wpdatatables_edit_table.js'); // Media upload wp_enqueue_script('media-upload'); // Localization wp_localize_script('wpdatatables-edit', 'wpdatatables_edit_strings', $wdt_admin_translation_array); $tpl->addData('wpShowTitle', __('Edit wpDataTable', 'wpdatatables')); $tpl->addData('table_id', $id); $tpl->addData('table_data', wdt_get_table_by_id($id)); $tpl->addData('column_data', wdt_get_columns_by_table_id($id)); $tpl->addData('wdtUserRoles', get_editable_roles()); $edit_page = $tpl->returnData(); $edit_page = apply_filters('wpdatatables_filter_edit_page', $edit_page); echo $edit_page; } else { if ($action == 'delete') { $id = $_REQUEST['table_id']; if (!is_array($id)) { $wpdb->query("DELETE \n\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}wpdatatables\n\t\t\t\t\t\t\t\t\tWHERE id={$id}"); } else { foreach ($id as $single_id) { $wpdb->query("DELETE \n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}wpdatatables\n\t\t\t\t\t\t\t\t\t\tWHERE id={$single_id}"); } } } $wdtBrowseTable = new WDTBrowseTable(); $wdtBrowseTable->prepare_items(); ob_start(); $wdtBrowseTable->search_box('search', 'search_id'); $wdtBrowseTable->display(); $tableHTML = ob_get_contents(); ob_end_clean(); $tpl = new PDTTpl(); // Popup $tpl->addJs(WDT_JS_PATH . 'popup/jquery.remodal.min.js'); $tpl->addCss(WDT_CSS_PATH . 'jquery.remodal.css'); // Admin JS $tpl->addJs(WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js'); $tpl->setTemplate('browse.inc.php'); $tpl->addData('tableHTML', $tableHTML); $browse_page = $tpl->returnData(); $browse_page = apply_filters('wpdatatables_filter_browse_page', $browse_page); echo $browse_page; } do_action('wpdatatables_browse_page'); }
/** * Handler for the table shortcode */ function wpdatatable_shortcode_handler( $atts, $content = null ) { global $wpdb, $wdt_var1, $wdt_var2, $wdt_var3; extract( shortcode_atts( array( 'id' => '0', 'show_only_chart' => false, 'no_scripts' => 0, 'var1' => '%%no_val%%', 'var2' => '%%no_val%%', 'var3' => '%%no_val%%' ), $atts ) ); // Protection if(!$id){ return false; } $table_data = wdt_get_table_by_id( $id ); $column_data = wdt_get_columns_by_table_id( $id ); // Do action before rendering a table do_action( 'wpdatatables_before_render_table', $id ); // Shortcode variables $wdt_var1 = $var1 !== '%%no_val%%' ? $var1 : $table_data['var1']; $wdt_var2 = $var2 !== '%%no_val%%' ? $var2 : $table_data['var2']; $wdt_var3 = $var3 !== '%%no_val%%' ? $var3 : $table_data['var3']; // Preparing column properties $column_order = array(); $column_titles = array(); $column_widths = array(); $column_types = array(); $column_possible_values = array(); $userid_column_header = ''; foreach($column_data as $column){ $column_order[(int)$column->pos] = $column->orig_header; if($column->display_header){ $column_titles[$column->orig_header] = $column->display_header; } if($column->width){ $column_widths[$column->orig_header] = $column->width; } if($column->column_type != 'autodetect'){ $column_types[$column->orig_header] = $column->column_type; } if( $table_data['edit_only_own_rows'] && ( $table_data['userid_column_id'] == $column->id ) ){ $userid_column_header = $column->orig_header; } $column_possible_values[$column->orig_header] = $column->possible_values; } $tbl = new WPDataTable(); $tbl->setWpId( $id ); if(empty($table_data['content'])){ return __('wpDataTable with provided ID not found!','wpdatatables'); } switch($table_data['table_type']){ case 'mysql' : case 'manual' : if($table_data['server_side']){ $tbl->enableServerProcessing(); } if($table_data['editable']){ if(wdt_current_user_can_edit( $table_data['editor_roles'], $id )){ $tbl->enableEditing(); } } if( !empty( $table_data['edit_only_own_rows'] ) ){ $tbl->setOnlyOwnRows( true ); $tbl->setUserIdColumn( $userid_column_header ); } $tbl->queryBasedConstruct($table_data['content'], array(), array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; case 'xls': case 'csv': $tbl->excelBasedConstruct($table_data['content'], array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; case 'xml': $tbl->XMLBasedConstruct($table_data['content'], array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; case 'json': $tbl->jsonBasedConstruct($table_data['content'], array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; case 'serialized': $array = unserialize( WDTTools::curlGetData( $table_data['content'] ) ); $tbl->arrayBasedConstruct( $array, array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; case 'google_spreadsheet': $array = WDTTools::extractGoogleSpreadsheetArray( $table_data['content'] ); $tbl->arrayBasedConstruct( $array, array( 'data_types'=>$column_types, 'column_titles'=>$column_titles ) ); break; } $tbl = apply_filters( 'wpdatatables_filter_initial_table_construct', $tbl );//can be used for creating new table type if($table_data['hide_before_load']){ $tbl->hideBeforeLoad(); }else{ $tbl->showBeforeLoad(); } $tbl->reorderColumns( $column_order ); $tbl->wdtDefineColumnsWidth( $column_widths ); $tbl->setColumnsPossibleValues( $column_possible_values ); // Applying form $tbl->setFilteringForm($table_data['filtering_form']); // Applying responsiveness if($table_data['responsive']){ $tbl->setResponsive(true); } // Applying filter, if enabled if($table_data['filtering']){ $tbl->enableAdvancedFilter(); } if(!$no_scripts){ wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-progressbar'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-ui-button'); wp_enqueue_style( 'dashicons' ); wp_enqueue_script('wdt_google_charts','//www.google.com/jsapi'); wp_enqueue_script('formstone-selecter',WDT_JS_PATH.'selecter/jquery.fs.selecter.min.js'); wp_enqueue_style('formstone-selecter',WDT_CSS_PATH.'jquery.fs.selecter.css'); wp_enqueue_script('wpdatatables-icheck',WDT_JS_PATH.'icheck/icheck.min.js'); wp_enqueue_style('wpdatatables-icheck',WDT_CSS_PATH.'icheck.minimal.css'); wp_enqueue_script('remodal-popup',WDT_JS_PATH.'popup/jquery.remodal.min.js'); wp_enqueue_style('remodal-popup',WDT_CSS_PATH.'jquery.remodal.css'); wp_enqueue_script('pickadate-main',WDT_JS_PATH.'datepicker/picker.js'); wp_enqueue_script('pickadate-date',WDT_JS_PATH.'datepicker/picker.date.js'); wp_enqueue_style('pickadate-main',WDT_CSS_PATH.'datepicker.default.css'); wp_enqueue_style('pickadate-date',WDT_CSS_PATH.'datepicker.default.date.css'); }else{ $tbl->disableScripts(); } $columnIndex = 1; $columnsCSS = ''; foreach($column_data as $column){ // Set filter types $tbl->getColumn($column->orig_header)->setFilterType($column->filter_type); // Set CSS class $tbl->getColumn($column->orig_header)->addCSSClass($column->css_class); // set visibility if(!$column->visible){ $tbl->getColumn($column->orig_header)->hide(); } // Set default value $tbl->getColumn($column->orig_header)->setDefaultValue($column->default_value); // Check the default values passed from URL if(isset($_GET['wdt_column_filter'])){ foreach($_GET['wdt_column_filter'] as $fltColKey => $fltDefVal){ $tbl->getColumn($fltColKey)->setDefaultValue($fltDefVal); } } // Set hiding on phones and tablets for responsiveness if($tbl->isResponsive()){ if($column->hide_on_phones){ $tbl->getColumn($column->orig_header)->hideOnPhones(); } if($column->hide_on_tablets){ $tbl->getColumn($column->orig_header)->hideOnTablets(); } } // if grouping enabled for this column, passing it to table class if($column->group_column){ $tbl->groupByColumn($column->orig_header); } if($column->sort_column !== '0'){ $tbl->setDefaultSortColumn($column->orig_header); if($column->sort_column == '1'){ $tbl->setDefaultSortDirection('ASC'); }elseif($column->sort_column == '2'){ $tbl->setDefaultSortDirection('DESC'); } } if($table_data['chart']!='none'){ if($column->use_in_chart){ $tbl->addChartSeries($column->orig_header); } if($column->chart_horiz_axis){ $tbl->setChartHorizontalAxis($column->orig_header); } } // Set ID column if specified if($column->id_column){ $tbl->setIdColumnKey($column->orig_header); } // Set front-end editor input type $tbl->getColumn($column->orig_header)->setInputType($column->input_type); // Define if input cannot be empty $tbl->getColumn($column->orig_header)->setNotNull( (bool) $column->input_mandatory ); if( $column->visible ){ // Get display before/after and color if( $column->text_before != '' ){ $columnsCSS .= "\n#{$tbl->getId()} > tbody > tr > td:nth-child({$columnIndex}):before { content: '{$column->text_before}' }"; } if( $column->text_after != '' ){ $columnsCSS .= "\n#{$tbl->getId()} > tbody > tr > td:nth-child({$columnIndex}):after { content: '{$column->text_after}' }"; } if( $column->color != '' ){ $columnsCSS .= "\n#{$tbl->getId()} > tbody > tr > td:nth-child({$columnIndex}), " . "#{$tbl->getId()} > thead > tr > th:nth-child({$columnIndex}), " . "#{$tbl->getId()} > tfoot > tr > th:nth-child({$columnIndex}) { background-color: {$column->color} !important; }"; } $columnIndex++; } } $output_str = ''; if(!$show_only_chart){ if( $table_data['show_title'] ){ if( $table_data['title'] ){ $output_str .= apply_filters('wpdatatables_filter_table_title', (empty($table_data['title']) ? '' : '<h2>'. $table_data['title'] .'</h2>'), $id ); } } if(!$table_data['sorting']){ $tbl->sortDisable(); } if(!$table_data['tools']){ $tbl->disableTT(); } // display length if($table_data['display_length'] != 0) { $tbl->setDisplayLength($table_data['display_length']); } else { $tbl->disablePagination(); } if(get_option('wdtInterfaceLanguage') != ''){ $tbl->setInterfaceLanguage(get_option('wdtInterfaceLanguage')); } $output_str .= $tbl->generateTable(); }else{ if( get_option('wdtMinifiedJs') ){ wp_enqueue_script( 'wpdatatables',WDT_JS_PATH.'wpdatatables/wpdatatables.min.js' ); }else{ wp_enqueue_script( 'wpdatatables',WDT_JS_PATH.'wpdatatables/wpdatatables.js' ); } } if($table_data['chart'] != 'none') { $tbl->setChartType(ucfirst($table_data['chart'])); $tbl->setChartTitle($table_data['chart_title']); $output_str = $tbl->renderChart('wdt_'.$tbl->getId().'_chart') . $output_str; if(get_option('wdtRenderCharts')=='above'){ $output_str = '<div id="wdt_'.$tbl->getId().'_chart" class="wpDataTables wdt_chart"></div>'.$output_str; }else{ $output_str .= '<div id="wdt_'.$tbl->getId().'_chart" class="wpDataTables wdt_chart"></div>'; } } // Generate the style block $output_str .= "<style>\n"; // Columns text before and after if( !empty( $columnsCSS ) ){ $output_str .= $columnsCSS; } // Table layout $customCss = get_option('wdtCustomCss'); if($table_data['fixed_layout'] || $table_data['word_wrap']) { $output_str .= ($table_data['fixed_layout'] ? "table.wpDataTable { table-layout: fixed !important; }\n" : ''); $output_str .= ($table_data['word_wrap'] ? "table.wpDataTable td, table.wpDataTable th { white-space: normal !important; }\n" : ''); } if($customCss){ $output_str .= stripslashes_deep($customCss); } if(get_option('wdtNumbersAlign')){ $output_str .= "table.wpDataTable td.numdata { text-align: right !important; }\n"; } $output_str .= "</style>\n"; add_action( 'wp_footer', 'wdt_render_script_style_block', 99999 ); $output_str = apply_filters( 'wpdatatables_filter_rendered_table', $output_str, $id ); return $output_str; }
/** * Returns the complete table for the range picker */ function wpdatatables_get_complete_table_json_by_id() { $table_id = filter_var($_POST['table_id'], FILTER_SANITIZE_NUMBER_INT); $table_data = wdt_get_table_by_id($table_id); $column_data = wdt_get_columns_by_table_id($table_id); $tbl = new WPDataTable(); $tbl->setWpId($table_id); $column_order = array(); $column_titles = array(); $column_types = array(); $column_possible_values = array(); foreach ($column_data as $column) { $column_order[(int) $column->pos] = $column->orig_header; if ($column->display_header) { $column_titles[$column->orig_header] = $column->display_header; } if ($column->column_type != 'autodetect') { $column_types[$column->orig_header] = $column->column_type; } $column_possible_values[$column->orig_header] = $column->possible_values; } switch ($table_data['table_type']) { case 'mysql': case 'manual': $tbl->queryBasedConstruct($table_data['content'], array(), array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xls': case 'csv': $tbl->excelBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'xml': $tbl->XMLBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'json': $tbl->jsonBasedConstruct($table_data['content'], array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'serialized': $array = unserialize(WDTTools::curlGetData($table_data['content'])); $tbl->arrayBasedConstruct($array, array('data_types' => $column_types, 'column_titles' => $column_titles)); break; case 'google_spreadsheet': $array = WDTTools::extractGoogleSpreadsheetArray($content); $tbl->arrayBasedConstruct($array, array('data_types' => $column_types, 'column_titles' => $column_titles)); break; } $tbl->reorderColumns($column_order); echo json_encode($tbl->getDataRows()); exit; }
/** * Handle uploaded file delete */ function wdt_delete_uploaded_file() { global $wpdb; $table_id = filter_var($_POST['table_id'], FILTER_SANITIZE_NUMBER_INT); $id_key = filter_var($_POST['id_key'], FILTER_SANITIZE_STRING); $id_val = filter_var($_POST['id_val'], FILTER_SANITIZE_STRING); $key = $_POST['key']; $table_data = wdt_get_table_by_id($table_id); $mysql_table_name = $table_data['mysql_table_name']; do_action('wpdatatables_before_delete_file', $id_val, $table_id); // First selecting and unlinking the exiting file (if exists); $rows = $wpdb->get_results("SELECT {$key} FROM {$mysql_table_name} WHERE {$id_key} = '{$id_val}'", ARRAY_A); if (!empty($rows)) { $filename = $rows[0][$key]; if (!empty($filename)) { $filename = urldecode($filename); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $filename = str_replace(site_url(), str_replace('\\', '/', ABSPATH), $filename); } else { $filename = str_replace(site_url(), ABSPATH, $filename); } if (file_exists($filename)) { unlink($filename); } } } // Updating the value in DB // If the plugin is using WP DB if (!get_option('wdtUseSeparateCon')) { $wpdb->update($mysql_table_name, array($key => ''), array($id_key => $id_val)); } else { $sql = new PDTSql(WDT_MYSQL_HOST, WDT_MYSQL_DB, WDT_MYSQL_USER, WDT_MYSQL_PASSWORD); $query = "UPDATE " . $mysql_table_name . "\n\t \t\t\t\t\tSET `" . $key . "`=''\n\t \t\t\t\t\tWHERE `" . $id_key . "`='" . $id_val . "'"; $sql->doQuery($query); } echo ''; exit; }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $file = new stdClass(); $file->name = $this->get_file_name($name, $type, $index, $content_range); $file->size = $this->fix_integer_overflow(intval($size)); $file->type = $type; if ($this->validate($uploaded_file, $file, $error, $index)) { $this->handle_form_data($file, $index); $upload_dir = $this->get_upload_path(); if (!is_dir($upload_dir)) { mkdir($upload_dir, $this->options['mkdir_mode'], true); } $file_path = $this->get_upload_path($file->name); $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); } $file_size = $this->get_file_size($file_path, $append_file); if ($file_size === $file->size) { $file->url = $this->get_download_url($file->name); //if ($this->is_valid_image_file($file_path)) { // $this->handle_image_file($file_path, $file); //} } else { $file->size = $file_size; if (!$content_range && $this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } } $this->set_additional_file_properties($file); } $table_id = $_GET['table_id']; $id_key = $_GET['id_key']; $id_val = $_GET['id_val']; $key = $_GET['key']; $table_data = wdt_get_table_by_id($table_id); $mysql_table_name = $table_data['mysql_table_name']; // If ID val is passed we update the row if (!empty($id_val)) { if (!get_option('wdtUseSeparateCon')) { global $wpdb; // First selecting and unlinking the exiting file (if exists); $rows = $wpdb->get_results("SELECT {$key} FROM {$mysql_table_name} WHERE {$id_key} = '{$id_val}'", ARRAY_A); if (!empty($rows)) { $filename = $rows[0][$key]; if (!empty($filename)) { $filename = urldecode($filename); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $filename = str_replace(site_url(), str_replace('\\', '/', ABSPATH), $filename); } else { $filename = str_replace(site_url(), ABSPATH, $filename); } if (file_exists($filename)) { unlink($filename); } } } // Updating the value in DB $wpdb->update($mysql_table_name, array($key => $file->url), array($id_key => $id_val)); } else { global $sql; $query = "SELECT {$key} FROM {$mysql_table_name} WHERE {$id_key} = '{$id_val}'"; $row = $sql->getRow($query, array()); $filename = $row[$key]; if (!empty($filename)) { $filename = urldecode($filename); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $filename = str_replace(site_url(), str_replace('\\', '/', ABSPATH), $filename); } else { $filename = str_replace(site_url(), ABSPATH, $filename); } if (file_exists($filename)) { unlink($filename); } } // Updating the value in DB $query = "UPDATE {$mysql_table_name} SET {$key} = '" . $file->url . "' WHERE {$id_key}={$id_val}"; $sql->doQuery($query); } } return $file; }
/** * Add a new column to manually generated table */ public static function addNewManualColumn($table_id, $column_data) { global $wpdb; $table_data = wdt_get_table_by_id($table_id); $existing_columns = wdt_get_columns_by_table_id($table_id); $existing_headers = array(); $column_index = 0; foreach ($existing_columns as $existing_column) { $existing_headers[] = $existing_column->orig_header; if ($existing_column->orig_header == $column_data['insert_after']) { $column_index = $existing_column->pos + 1; } } $new_column_mysql_name = self::generateMySQLColumnName($column_data['name'], $existing_headers); $columnProperties = self::defineColumnProperties($new_column_mysql_name, $column_data['type']); // Add the column to MySQL table $alter_table_statement = "ALTER TABLE {$table_data['mysql_table_name']} \n ADD COLUMN {$columnProperties['create_block']} "; if ($column_data['insert_after'] == '%%beginning%%') { $alter_table_statement .= " FIRST"; } else { if ($column_data['insert_after'] != '%%end%%') { $alter_table_statement .= " AFTER `{$column_data['insert_after']}`"; } } // Call the create statement on WPDB or on external DB if it is defined if (get_option('wdtUseSeparateCon')) { // External DB $Sql = new PDTSql(WDT_MYSQL_HOST, WDT_MYSQL_DB, WDT_MYSQL_USER, WDT_MYSQL_PASSWORD); $Sql->doQuery($alter_table_statement, array()); } else { $wpdb->query($alter_table_statement); } // Fill in with default value if requested if ($column_data['fill_default'] == 1) { $update_fill_default = "UPDATE {$table_data['mysql_table_name']} \n SET `{$new_column_mysql_name}` = '{$column_data['default_value']}' \n WHERE 1"; if (get_option('wdtUseSeparateCon')) { // External DB $this->_db->doQuery($update_fill_default, array()); } else { $wpdb->query($update_fill_default); } } // Move the existing columns if necessary if ($column_data['insert_after'] == '%%end%%') { $column_index = count($existing_columns); } else { $update_statement = "UPDATE " . $wpdb->prefix . "wpdatatables_columns \n SET pos = pos + 1 \n WHERE table_id = {$table_id} \n AND pos >= " . (int) $column_index; $wpdb->query($update_statement); } // Add the column to wp_wpdatatables_columns $wpdb->insert($wpdb->prefix . "wpdatatables_columns", array('table_id' => $table_id, 'orig_header' => $new_column_mysql_name, 'display_header' => $column_data['name'], 'filter_type' => $columnProperties['filter_type'], 'column_type' => $columnProperties['column_type'], 'pos' => $column_index, 'possible_values' => str_replace(',,;,|', '|', $column_data['possible_values']), 'default_value' => $column_data['default_value'], 'input_type' => $columnProperties['editor_type'])); }
/** * Editor page */ function wpdatatables_editor() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } wp_enqueue_script('wpdatatables-jsrender', WDT_JS_PATH . 'jsrender/jsrender.min.js'); wp_enqueue_script('wpdatatables-selecter', WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js'); wp_enqueue_style('wpdatatables-selecter', WDT_CSS_PATH . 'jquery.fs.selecter.css'); $table_id = $_GET['table_id']; $table_data = wdt_get_table_by_id($table_id); $column_data = wdt_get_columns_by_table_id($table_id); // Do action before rendering a table do_action('wpdatatables_before_render_table', $table_id); // Preparing column properties $column_order = array(); $column_titles = array(); $column_widths = array(); $column_types = array(); $column_possible_values = array(); foreach ($column_data as $column) { $column_order[(int) $column->pos] = $column->orig_header; if ($column->display_header) { $column_titles[$column->orig_header] = $column->display_header; } if ($column->width) { $column_widths[$column->orig_header] = $column->width; } if ($column->column_type != 'autodetect') { $column_types[$column->orig_header] = $column->column_type; } $column_possible_values[$column->orig_header] = $column->possible_values; } $tbl = new WPDataTable(); $tbl->setWpId($table_id); $tbl->queryBasedConstruct($table_data['content'], array(), array('data_types' => $column_types, 'column_titles' => $column_titles)); $tbl->reorderColumns($column_order); $tbl->wdtDefineColumnsWidth($column_widths); $tbl->setColumnsPossibleValues($column_possible_values); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-progressbar'); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('jquery-ui-button'); wp_enqueue_style('dashicons'); wp_enqueue_script('wdt_google_charts', 'https://www.google.com/jsapi'); wp_enqueue_script('formstone-selecter', WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js'); wp_enqueue_style('formstone-selecter', WDT_CSS_PATH . 'jquery.fs.selecter.css'); wp_enqueue_script('wpdatatables-icheck', WDT_JS_PATH . 'icheck/icheck.min.js'); wp_enqueue_style('wpdatatables-icheck', WDT_CSS_PATH . 'icheck.minimal.css'); wp_enqueue_script('remodal-popup', WDT_JS_PATH . 'popup/jquery.remodal.min.js'); wp_enqueue_style('remodal-popup', WDT_CSS_PATH . 'jquery.remodal.css'); wp_enqueue_script('pickadate-main', WDT_JS_PATH . 'datepicker/picker.js'); wp_enqueue_script('pickadate-date', WDT_JS_PATH . 'datepicker/picker.date.js'); wp_enqueue_style('pickadate-main', WDT_CSS_PATH . 'datepicker.default.css'); wp_enqueue_style('pickadate-date', WDT_CSS_PATH . 'datepicker.default.date.css'); wp_enqueue_script('wpdatatables-tagsinput', WDT_JS_PATH . 'tagsinput/jquery.tagsinput.min.js'); wp_enqueue_style('wpdatatables-tagsinput', WDT_CSS_PATH . 'jquery.tagsinput.min.css'); wp_enqueue_script('wpdatatables-editor', WDT_JS_PATH . 'wpdatatables/wpdatatables_editor.js'); wp_enqueue_media(); foreach ($column_data as $column) { // Set filter types $tbl->getColumn($column->orig_header)->setFilterType($column->filter_type); // Set CSS class $tbl->getColumn($column->orig_header)->addCSSClass($column->css_class); // set visibility if (!$column->visible) { $tbl->getColumn($column->orig_header)->hide(); } // Set default value $tbl->getColumn($column->orig_header)->setDefaultValue($column->default_value); // Check the default values passed from URL if (isset($_GET['wdt_column_filter'])) { foreach ($_GET['wdt_column_filter'] as $fltColKey => $fltDefVal) { $tbl->getColumn($fltColKey)->setDefaultValue($fltDefVal); } } // Set hiding on phones and tablets for responsiveness if ($tbl->isResponsive()) { if ($column->hide_on_phones) { $tbl->getColumn($column->orig_header)->hideOnPhones(); } if ($column->hide_on_tablets) { $tbl->getColumn($column->orig_header)->hideOnTablets(); } } // if grouping enabled for this column, passing it to table class if ($column->group_column) { $tbl->groupByColumn($column->orig_header); } if ($column->sort_column !== '0') { $tbl->setDefaultSortColumn($column->orig_header); if ($column->sort_column == '1') { $tbl->setDefaultSortDirection('ASC'); } elseif ($column->sort_column == '2') { $tbl->setDefaultSortDirection('DESC'); } } if ($table_data['chart'] != 'none') { if ($column->use_in_chart) { $tbl->addChartSeries($column->orig_header); } if ($column->chart_horiz_axis) { $tbl->setChartHorizontalAxis($column->orig_header); } } // Set ID column if specified if ($column->id_column) { $tbl->setIdColumnKey($column->orig_header); } // Set front-end editor input type $tbl->getColumn($column->orig_header)->setInputType($column->input_type); } $output_str = ''; if ($table_data['title']) { $output_str .= apply_filters('wpdatatables_filter_table_title', empty($table_data['title']) ? '' : '<h2>' . $table_data['title'] . '</h2>', $table_id); } $tbl->disableTT(); $tbl->enableEditing(); $tbl->enableServerProcessing(); if (get_option('wdtInterfaceLanguage') != '') { $tbl->setInterfaceLanguage(get_option('wdtInterfaceLanguage')); } $output_str .= $tbl->generateTable(); $tpl = new PDTTpl(); $tpl->addData('table_id', $table_id); $tpl->addData('table_to_edit', $output_str); $tpl->addData('column_data', $column_data); $tpl->setTemplate('editor.inc.php'); $editor_page = $tpl->returnData(); $editor_page = apply_filters('wpdatatables_filter_editor_page', $editor_page); echo $editor_page; do_action('wpdatatables_settings_page'); }