public function __construct($properties = array()) { $this->_cssClassArray = WDTTools::defineDefaultValue($properties, 'classes', array()); $this->_sort = WDTTools::defineDefaultValue($properties, 'sort', true); $this->_title = WDTTools::defineDefaultValue($properties, 'title', ''); $this->_isVisible = WDTTools::defineDefaultValue($properties, 'visible', true); $this->_width = WDTTools::defineDefaultValue($properties, 'width', ''); }
public function __construct($properties = array()) { $this->_cssClassArray = WDTTools::defineDefaultValue($properties, 'classes', array()); $this->_textBefore = WDTTools::defineDefaultValue($properties, 'text_before', ''); $this->_textAfter = WDTTools::defineDefaultValue($properties, 'text_after', ''); $this->_sort = WDTTools::defineDefaultValue($properties, 'sort', true); $this->_title = WDTTools::defineDefaultValue($properties, 'title', ''); $this->_isVisible = WDTTools::defineDefaultValue($properties, 'visible', true); $this->_width = WDTTools::defineDefaultValue($properties, 'width', ''); $this->_orig_header = WDTTools::defineDefaultValue($properties, 'orig_header', ''); }
public static function extractGoogleSpreadsheetArray($url) { if (empty($url)) { return ''; } $url_arr = explode('/', $url); $spreadsheet_key = $url_arr[count($url_arr) - 2]; $csv_url = "https://docs.google.com/spreadsheets/d/{$spreadsheet_key}/pub?hl=en_US&hl=en_US&single=true&gid=0&output=csv"; $csv_data = WDTTools::curlGetData($csv_url); $array = WDTTools::csvToArray($csv_data); return $array; }
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; }
function wpdatatables_plugins_api($false, $action, $arg) { global $wdt_plugin_slug; if (property_exists($arg, 'slug') && ($arg->slug === $wdt_plugin_slug || $arg->slug == 'wpdatatables.php')) { $information = WDTTools::checkRemoteInfo(); return $information; } return false; }
/** * 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; }
</span> </div> </td> </tr> <tr> <td> <label><span><strong><?php _e('Type', 'wpdatatables'); ?> </strong></span>:</label> </td> <td> <div class="columnType"> <select class="columnType"> <?php foreach (WDTTools::getPossibleColumnTypes() as $columnTypeKey => $columnTypeName) { ?> <option value="<?php echo $columnTypeKey; ?> "><?php echo $columnTypeName; ?> </option> <?php } ?> </select> </div> </td> </tr>
/** * Generates a table based on the provided file and shows a preview */ public function previewFileTable($table_data) { if (!empty($table_data['file'])) { $xls_url = urldecode($table_data['file']); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $xls_url = str_replace(site_url(), str_replace('\\', '/', ABSPATH), $xls_url); } else { $xls_url = str_replace(site_url(), ABSPATH, $xls_url); } } else { return _('Empty file', 'wpdatatables'); } require_once WDT_ROOT_PATH . '/lib/phpExcel/PHPExcel.php'; $objPHPExcel = new PHPExcel(); if (strpos(strtolower($xls_url), '.xlsx')) { $objReader = new PHPExcel_Reader_Excel2007(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.xls')) { $objReader = new PHPExcel_Reader_Excel5(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.ods')) { $objReader = new PHPExcel_Reader_OOCalc(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.csv')) { $objReader = new PHPExcel_Reader_CSV(); } else { return _('File format not supported!', 'wpdatatables'); } $objPHPExcel = $objReader->load($xls_url); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestRow = $highestRow > 5 ? 5 : $highestRow; $highestColumn = $objWorksheet->getHighestColumn(); $headingsArray = $objWorksheet->rangeToArray('A1:' . $highestColumn . '1', null, true, true, true); $headingsArray = $headingsArray[1]; $r = -1; $namedDataArray = array(); for ($row = 2; $row <= $highestRow; ++$row) { $dataRow = $objWorksheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, true, true); if (isset($dataRow[$row]['A']) && $dataRow[$row]['A'] > '') { ++$r; foreach ($headingsArray as $dataColumnIndex => $dataColumnHeading) { $namedDataArray[$r][$dataColumnHeading] = $dataRow[$row][$dataColumnIndex]; if (WDT_DETECT_DATES_IN_EXCEL) { $cellID = $dataColumnIndex . $row; if (PHPExcel_Shared_Date::isDateTime($objPHPExcel->getActiveSheet()->getCell($cellID))) { $namedDataArray[$r][$dataColumnHeading] = PHPExcel_Shared_Date::ExcelToPHP($dataRow[$row][$dataColumnIndex]); } } } } } $columnTypeArray = WDTTools::detectColumnDataTypes($namedDataArray, $headingsArray); $possibleColumnTypes = WDTTools::getPossibleColumnTypes(); $ret_val = ''; if (!empty($namedDataArray)) { ob_start(); include WDT_TEMPLATE_PATH . 'constructor_file_preview.inc.php'; $ret_val = ob_get_contents(); ob_end_clean(); } return $ret_val; }
private function _renderWithJSAndStyles() { $tpl = new PDTTpl(); $minified_js = get_option('wdtMinifiedJs'); if (true || $this->_firstOnPage && $this->scriptsEnabled) { if (WDT_INCLUDE_DATATABLES_CORE) { wp_register_script('datatables', WDT_JS_PATH . 'jquery-datatables/jquery.dataTables.min.js', array('jquery')); wp_enqueue_script('datatables'); } if ($this->TTEnabled()) { wp_register_script('tabletools', WDT_JS_PATH . 'jquery-datatables/TableTools.min.js', array('jquery', 'datatables')); wp_enqueue_script('tabletools'); } if ($minified_js) { wp_register_script('wpdatatables-funcs', WDT_JS_PATH . 'php-datatables/wpdatatables.funcs.min.js', array('jquery', 'datatables')); wp_register_script('wpdatatables-rowgrouping', WDT_JS_PATH . 'jquery-datatables/jquery.dataTables.rowGrouping.min.js', array('jquery', 'datatables')); } else { wp_register_script('wpdatatables-funcs', WDT_JS_PATH . 'php-datatables/wpdatatables.funcs.js', array('jquery', 'datatables')); wp_register_script('wpdatatables-rowgrouping', WDT_JS_PATH . 'jquery-datatables/jquery.dataTables.rowGrouping.js', array('jquery', 'datatables')); } wp_enqueue_script('wpdatatables-funcs'); wp_enqueue_script('wpdatatables-rowgrouping'); if ($this->filterEnabled()) { if ($minified_js) { wp_register_script('wpdatatables-advancedfilter', WDT_JS_PATH . 'jquery-datatables/jquery.dataTables.columnFilter.min.js'); } else { wp_register_script('wpdatatables-advancedfilter', WDT_JS_PATH . 'jquery-datatables/jquery.dataTables.columnFilter.js'); } wp_enqueue_script('wpdatatables-advancedfilter'); } if ($this->isEditable()) { wp_register_script('jquery-maskmoney', WDT_JS_PATH . 'maskmoney/jquery.maskMoney.js', array('jquery')); wp_enqueue_script('jquery-maskmoney'); // Media upload wp_enqueue_script('media-upload'); wp_enqueue_media(); } if ($this->isResponsive()) { wp_register_script('lodash', WDT_JS_PATH . 'responsive/lodash.min.js'); if ($minified_js) { wp_register_script('wpdatatables-responsive', WDT_JS_PATH . 'responsive/datatables.responsive.min.js'); } else { wp_register_script('wpdatatables-responsive', WDT_JS_PATH . 'responsive/datatables.responsive.js'); } wp_enqueue_script('lodash'); wp_enqueue_script('wpdatatables-responsive'); } wp_enqueue_script('jquery-effects-core'); wp_enqueue_script('jquery-effects-fade'); if ($minified_js) { wp_register_script('wpdatatables', WDT_JS_PATH . 'wpdatatables/wpdatatables.min.js', array('jquery', 'datatables')); } else { wp_register_script('wpdatatables', WDT_JS_PATH . 'wpdatatables/wpdatatables.js', array('jquery', 'datatables')); } wp_enqueue_script('wpdatatables'); // Localization wp_localize_script('wpdatatables', 'wpdatatables_frontend_strings', WDTTools::getTranslationStrings()); wp_localize_script('wpdatatables-advancedfilter', 'wpdatatables_frontend_strings', WDTTools::getTranslationStrings()); } $this->addCSSClass('data-t'); $tpl->setTemplate('wpdatatables_table_main.inc.php'); $tpl->addData('wpDataTable', $this); return $tpl->returnData(); }
function wpdatatables_enqueue_editing_scripts() { global $wdt_admin_translation_array; // 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'); // iCheck wp_enqueue_script('wpdatatables-icheck', WDT_JS_PATH . 'icheck/icheck.min.js'); wp_enqueue_style('wpdatatables-icheck', WDT_CSS_PATH . 'icheck.minimal.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'); // ACE syntax highlight wp_enqueue_script('wpdatatables-ace', WDT_JS_PATH . 'ace/ace.js'); // Localization wp_localize_script('wpdatatables-edit', 'wpdatatables_edit_strings', $wdt_admin_translation_array); wp_localize_script('wpdatatables-edit', 'wpdatatables_frontend_strings', WDTTools::getTranslationStrings()); }
public function XMLBasedConstruct($xml, $wdtParameters = array()) { if (!$xml) { throw new WDTException('File you provided cannot be found.'); } if (strpos($xml, '.xml') === false) { throw new WDTException('Non-XML file provided!'); } // checking if the table is existing in cache // and setting the flag if it does if (self::$mc) { $this->_cacheHash = 'bbxml_' . md5($xml); if (@self::$mc->get($this->_cacheHash)) { $this->_fromCache = $this->_cacheHash; return true; } } $XMLObject = simplexml_load_file($xml); $XMLObject = apply_filters('wpdatatables_filter_simplexml', $XMLObject, $this->getWpId()); $XMLArray = WDTTools::convertXMLtoArr($XMLObject); while (is_array($XMLArray) && count($XMLArray) == 1) { $XMLArray = $XMLArray[key($XMLArray)]; } foreach ($XMLArray as &$xml_el) { if (is_array($xml_el) && array_key_exists('attributes', $xml_el)) { $xml_el = $xml_el['attributes']; } } return $this->arrayBasedConstruct($XMLArray, $wdtParameters); }