function widget($args, $instance)
 {
     // Widget output
     if (!isset($instance['title'])) {
         $title = 'Filter';
     }
     $title = apply_filters('widget_title', $title);
     echo $args['before_widget'];
     $title = $args['before_title'] . $title . $args['after_title'];
     $tpl = new PDTTpl();
     $tpl->setTemplate('filter_widget.inc.php');
     $tpl->addData('title', $title);
     echo $tpl->showData();
     echo $args['after_widget'];
 }
Ejemplo n.º 2
0
/**
 * 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;
}
Ejemplo n.º 3
0
 function wdt_render_script_style_block(){
     
     $customJs = get_option('wdtCustomJs');
     if($customJs){
          $script_block_html .= '<script type="text/javascript">'.stripslashes_deep($customJs).'</script>';
     }
     echo $script_block_html;
     
     // 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 );
     }
     echo $style_block_html;
 }
Ejemplo n.º 4
0
function wpdatatables_settings()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    wp_enqueue_script('wdt-colorpicker');
    $languages = array();
    foreach (glob(WDT_ROOT_PATH . 'source/lang/*.inc.php') as $lang_filename) {
        $lang_filename = str_replace(WDT_ROOT_PATH . 'source/lang/', '', $lang_filename);
        $name = ucwords(str_replace('_', ' ', $lang_filename));
        $name = str_replace('.inc.php', '', $name);
        $languages[] = array('file' => $lang_filename, 'name' => $name);
    }
    $tpl = new PDTTpl();
    $tpl->setTemplate('settings.inc.php');
    $tpl->addData('wpUseSeparateCon', get_option('wdtUseSeparateCon'));
    $tpl->addData('wpMySqlHost', get_option('wdtMySqlHost'));
    $tpl->addData('wpMySqlDB', get_option('wdtMySqlDB'));
    $tpl->addData('wpMySqlUser', get_option('wdtMySqlUser'));
    $tpl->addData('wpMySqlPwd', get_option('wdtMySqlPwd'));
    $tpl->addData('wpRenderCharts', get_option('wdtRenderCharts'));
    $tpl->addData('wpRenderFilter', get_option('wdtRenderFilter'));
    $tpl->addData('wdtTablesPerPage', get_option('wdtTablesPerPage'));
    $tpl->addData('wdtNumberFormat', get_option('wdtNumberFormat'));
    $tpl->addData('wdtDecimalPlaces', get_option('wdtDecimalPlaces'));
    $tpl->addData('wdtNumbersAlign', get_option('wdtNumbersAlign'));
    $tpl->addData('wdtTabletWidth', get_option('wdtTabletWidth'));
    $tpl->addData('wdtMobileWidth', get_option('wdtMobileWidth'));
    $tpl->addData('wdtPurchaseCode', get_option('wdtPurchaseCode'));
    $tpl->addData('wdtCustomJs', get_option('wdtCustomJs'));
    $tpl->addData('wdtCustomCss', get_option('wdtCustomCss'));
    $tpl->addData('wpDateFormat', get_option('wdtDateFormat'));
    $tpl->addData('wpTopOffset', get_option('wdtTopOffset'));
    $tpl->addData('wpLeftOffset', get_option('wdtLeftOffset'));
    $tpl->addData('languages', $languages);
    $tpl->addData('wpInterfaceLanguage', get_option('wdtInterfaceLanguage'));
    $tpl->addData('wdtFonts', wdt_get_system_fonts());
    $tpl->addData('wdtBaseSkin', get_option('wdtBaseSkin'));
    $wpFontColorSettings = get_option('wdtFontColorSettings');
    if (!empty($wpFontColorSettings)) {
        $wpFontColorSettings = unserialize($wpFontColorSettings);
    } else {
        $wpFontColorSettings = array();
    }
    // Admin JS
    $tpl->addJs(WDT_JS_PATH . 'wpdatatables/wpdatatables_admin.js');
    // Selecter
    $tpl->addJs(WDT_JS_PATH . 'selecter/jquery.fs.selecter.min.js');
    $tpl->addCss(WDT_CSS_PATH . 'jquery.fs.selecter.css');
    // Picker
    $tpl->addJs(WDT_JS_PATH . 'picker/jquery.fs.picker.min.js');
    $tpl->addCss(WDT_CSS_PATH . 'jquery.fs.picker.css');
    // Popup
    $tpl->addJs(WDT_JS_PATH . 'popup/jquery.remodal.min.js');
    $tpl->addCss(WDT_CSS_PATH . 'jquery.remodal.css');
    $tpl->addData('wdtFontColorSettings', $wpFontColorSettings);
    $settings_page = $tpl->returnData();
    $settings_page = apply_filters('wpdatatables_filter_settings_page', $settings_page);
    echo $settings_page;
    do_action('wpdatatables_settings_page');
}
 /**
  * Renders the chart block, which will be supposed to render in the
  * div with provided ID
  * @param string Container div ID 
  */
 public function renderChart($divId)
 {
     if (!$divId) {
         throw new WDTException('No div ID provided!');
     }
     do_action('wpdatatable_before_render_chart', $this->getWpId());
     $tpl = new PDTTpl();
     $tpl->setTemplate('chart_js_template.inc.php');
     $series_headers = array();
     $series_values = array();
     foreach ($this->_chartSeriesArr as $dataColumnIndex) {
         $series_headers[] = $this->getColumn($dataColumnIndex)->getTitle();
     }
     $chartProperties = array();
     $chartProperties['values'] = array();
     $chartProperties['values'][] = $series_headers;
     foreach ($this->getDataRows() as $row) {
         $series_values_entry = array();
         foreach ($this->_chartSeriesArr as $dataColumnIndex) {
             $val = $row[$dataColumnIndex];
             if (($dataType = $this->getColumn($dataColumnIndex)->getDataType()) != 'string') {
                 if ($dataType == 'date') {
                     $val = str_replace('/', '-', $val);
                     $val = date(get_option('wdtDateFormat'), strtotime($val));
                 } elseif ($dataType == 'int') {
                     $val = (int) $val;
                 } elseif ($dataType == 'float') {
                     $val = (double) $val;
                 }
                 $series_values_entry[] = $val;
             } else {
                 $series_values_entry[] = $val;
             }
         }
         $chartProperties['values'][] = $series_values_entry;
     }
     $chartProperties['type'] = $this->getChartType();
     $chartProperties['container'] = $divId;
     $chartProperties['options'] = array();
     $chartProperties['options']['title'] = $this->getChartTitle();
     if (!empty($this->_horAxisCol)) {
         $chartProperties['options']['hAxis'] = array('title' => $this->getColumn($this->_horAxisCol)->getTitle());
     }
     if (!empty($this->_verAxisCol)) {
         $chartProperties['options']['vAxis'] = array('title' => $this->getColumn($this->_verAxisCol)->getTitle());
     }
     $tpl->addData('tableId', $this->getId());
     $tpl->addData('chartProperties', json_encode($chartProperties, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG));
     $return_data = $tpl->returnData();
     $return_data = apply_filters('wpdatatables_filter_chart', $return_data, $series_headers, $series_values, $this->getWpId());
     return $return_data;
 }
/**
 * 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');
}