Table Maker - Version 1.9

Version Description

  • Security improvements
Download this release

Release Info

Developer wpsoul
Plugin Icon 128x128 Table Maker
Version 1.9
Comparing to
See all releases

Code changes from version 1.6 to 1.9

css/table-maker.css CHANGED
@@ -1 +1 @@
1
- .wrap h2 { margin-bottom: 10px; }
2
  * jQuery UI CSS Framework 1.11.1
3
  * http://jqueryui.com
4
  *
5
  * Copyright 2014 jQuery Foundation and other contributors
6
  * Released under the MIT license.
7
  * http://jquery.org/license
8
  *
9
  * http://api.jqueryui.com/category/theming/
10
  */
11
- ---------------------------------*/
12
- ---------------------------------*/
13
- ---------------------------------*/
14
- ---------------------------------*/
15
  * jQuery UI CSS Framework 1.11.1
16
  * http://jqueryui.com
17
  *
18
  * Copyright 2014 jQuery Foundation and other contributors
19
  * Released under the MIT license.
20
  * http://jquery.org/license
21
  *
22
  * http://api.jqueryui.com/category/theming/
23
  */
24
- ---------------------------------*/
25
- ---------------------------------*/
26
- ---------------------------------*/
27
- ---------------------------------*/
 
1
  * jQuery UI CSS Framework 1.11.1
2
  * http://jqueryui.com
3
  *
4
  * Copyright 2014 jQuery Foundation and other contributors
5
  * Released under the MIT license.
6
  * http://jquery.org/license
7
  *
8
  * http://api.jqueryui.com/category/theming/
9
  */
10
+ .wrap h2 { margin-bottom: 10px; }
 
 
 
11
  * jQuery UI CSS Framework 1.11.1
12
  * http://jqueryui.com
13
  *
14
  * Copyright 2014 jQuery Foundation and other contributors
15
  * Released under the MIT license.
16
  * http://jquery.org/license
17
  *
18
  * http://api.jqueryui.com/category/theming/
19
  */
 
 
 
 
inc/class-wpsm-db-table.php CHANGED
@@ -4,19 +4,18 @@ if ( ! defined( 'WPINC' ) ) {
4
  die;
5
  }
6
 
7
- class WPSM_DB_Table
8
- {
9
  private $db;
10
 
11
- function __construct()
12
- {
13
  global $wpdb;
14
  $this->db = $wpdb;
15
- $this->table_name = "wpsm_tables";
16
- $this->db_version = "1.0";
 
17
  }
18
 
19
- public static function get_instance(){
20
  static $instance = null;
21
  if($instance == null){
22
  $instance = new WPSM_DB_Table();
@@ -24,7 +23,7 @@ class WPSM_DB_Table
24
  return $instance;
25
  }
26
 
27
- public function create_table(){
28
  $current_version = get_option('wpsm_db_table_version');
29
  if($current_version && $current_version == $this->db_version && $this->db->get_var("SHOW TABLES LIKE '$this->table_name'") == $this->table_name){
30
  return;
@@ -45,10 +44,16 @@ class WPSM_DB_Table
45
  ";
46
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
47
  dbDelta( $sql );
 
 
 
 
 
 
48
  update_option('wpsm_db_table_version', $this->db_version);
49
  }
50
 
51
- public function add($name, $rows, $cols, $subs, $color, $responsive, $tvalues){
52
  $name = wp_strip_all_tags(wp_unslash($name));
53
  $rows = intval(wp_unslash($rows));
54
  $cols = intval(wp_unslash($cols));
@@ -63,7 +68,7 @@ class WPSM_DB_Table
63
  return false;
64
  }
65
 
66
- public function update($id, $name, $rows, $cols, $subs, $color, $responsive, $tvalues){
67
  $name = wp_strip_all_tags(wp_unslash($name));
68
  $rows = intval(wp_unslash($rows));
69
  $cols = intval(wp_unslash($cols));
@@ -80,29 +85,19 @@ class WPSM_DB_Table
80
  return $this->db->query($query);
81
  }
82
 
83
- public function delete($id){
84
- if(is_array($id))
85
- $id = sprintf('(%s)', implode(',', $id));
86
- else {
87
- $id = sprintf('(%d)', $id);
88
- }
89
-
90
- $query = "DELETE FROM $this->table_name WHERE id IN $id";
91
  return $this->db->query($query);
92
  }
93
 
94
  public function get($id){
95
- if( is_array($id) ){
96
- $id = sprintf('(%s)', implode(',', $id));
97
- }
98
- else {
99
- $id = sprintf('(%d)', $id);
100
- }
101
- $row = $this->db->get_row("SELECT * FROM $this->table_name WHERE id IN $id", ARRAY_A);
102
  if($row){
103
  $row['tvalues'] = $this->unserialize($row['tvalues']);
 
104
  }
105
- return $row;
106
  }
107
 
108
  public function get_page_items($curr_page, $per_page){
@@ -113,7 +108,7 @@ class WPSM_DB_Table
113
 
114
  public function get_count(){
115
  $count = $this->db->get_var("SELECT COUNT(*) FROM $this->table_name");
116
- return isset($count)?$count:0;
117
  }
118
 
119
  private function serialize($item){
@@ -123,6 +118,18 @@ class WPSM_DB_Table
123
  private function unserialize($item){
124
  return unserialize(base64_decode($item));
125
  }
 
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
 
128
  ?>
4
  die;
5
  }
6
 
7
+ class WPSM_DB_Table {
 
8
  private $db;
9
 
10
+ function __construct() {
 
11
  global $wpdb;
12
  $this->db = $wpdb;
13
+ $this->table_name = $this->db->prefix ."wpsm_tables";
14
+ $this->old_table_name = "wpsm_tables"; // since v.1.1
15
+ $this->db_version = "1.1";
16
  }
17
 
18
+ public static function get_instance() {
19
  static $instance = null;
20
  if($instance == null){
21
  $instance = new WPSM_DB_Table();
23
  return $instance;
24
  }
25
 
26
+ public function create_table() {
27
  $current_version = get_option('wpsm_db_table_version');
28
  if($current_version && $current_version == $this->db_version && $this->db->get_var("SHOW TABLES LIKE '$this->table_name'") == $this->table_name){
29
  return;
44
  ";
45
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
46
  dbDelta( $sql );
47
+
48
+ // since v.1.1
49
+ if($this->db->get_var("SHOW TABLES LIKE '$this->old_table_name'") == $this->old_table_name){
50
+ $this->upgrade_new_name_table();
51
+ }
52
+
53
  update_option('wpsm_db_table_version', $this->db_version);
54
  }
55
 
56
+ public function add($name, $rows, $cols, $subs, $color, $responsive, $tvalues) {
57
  $name = wp_strip_all_tags(wp_unslash($name));
58
  $rows = intval(wp_unslash($rows));
59
  $cols = intval(wp_unslash($cols));
68
  return false;
69
  }
70
 
71
+ public function update($id, $name, $rows, $cols, $subs, $color, $responsive, $tvalues) {
72
  $name = wp_strip_all_tags(wp_unslash($name));
73
  $rows = intval(wp_unslash($rows));
74
  $cols = intval(wp_unslash($cols));
85
  return $this->db->query($query);
86
  }
87
 
88
+ public function delete($id) {
89
+ $query = $this->db->prepare("DELETE FROM $this->table_name WHERE id IN (%d)", $id);
 
 
 
 
 
 
90
  return $this->db->query($query);
91
  }
92
 
93
  public function get($id){
94
+ $query = $this->db->prepare("SELECT * FROM $this->table_name WHERE id IN (%d)", $id);
95
+ $row = $this->db->get_row($query, ARRAY_A);
 
 
 
 
 
96
  if($row){
97
  $row['tvalues'] = $this->unserialize($row['tvalues']);
98
+ return $row;
99
  }
100
+ return false;
101
  }
102
 
103
  public function get_page_items($curr_page, $per_page){
108
 
109
  public function get_count(){
110
  $count = $this->db->get_var("SELECT COUNT(*) FROM $this->table_name");
111
+ return isset($count) ? $count : 0;
112
  }
113
 
114
  private function serialize($item){
118
  private function unserialize($item){
119
  return unserialize(base64_decode($item));
120
  }
121
+
122
+ /**
123
+ * Removes old table and moves its data into renamed one
124
+ *
125
+ * @since v.1.1
126
+ **/
127
+ public function upgrade_new_name_table(){
128
+ $copy_query = "INSERT INTO $this->table_name SELECT * FROM $this->old_table_name";
129
+ $this->db->query($copy_query);
130
+ $delete_query = "DROP TABLE $this->old_table_name";
131
+ $this->db->query($delete_query);
132
+ }
133
  }
134
 
135
  ?>
inc/class-wpsm-list-table.php CHANGED
@@ -51,10 +51,9 @@ class WPSM_List_Table extends WP_List_Table {
51
  }
52
 
53
  function column_name($item){
54
- //Build row actions
55
  $actions = array(
56
- 'edit' => sprintf('<a href="?page=%s&action=%s&table=%s">%s</a>', $_REQUEST['page'],'edit',$item['id'], __('Edit', 'wpsm-tableplugin') ),
57
- 'delete' => sprintf('<a href="?page=%s&action=%s&table=%s">%s</a>', $_REQUEST['page'],'delete',$item['id'], __('Delete', 'wpsm-tableplugin') )
58
  );
59
 
60
  //Return the title contents
51
  }
52
 
53
  function column_name($item){
 
54
  $actions = array(
55
+ 'edit' => sprintf('<a href="%s">%s</a>', wp_nonce_url(admin_url('admin.php?page='.$_REQUEST['page'].'&action=edit&table='.$item['id']), 'edit_table'), __('Edit', 'wpsm-tableplugin') ),
56
+ 'delete' => sprintf('<a href="%s">%s</a>', wp_nonce_url(admin_url('admin.php?page='.$_REQUEST['page'].'&action=delete&table='.$item['id']), 'delete_table'), __('Delete', 'wpsm-tableplugin') )
57
  );
58
 
59
  //Return the title contents
inc/class-wpsm-table-maker.php CHANGED
@@ -7,31 +7,25 @@ if ( ! defined( 'WPINC' ) ) {
7
  class WPSM_Table_Maker
8
  {
9
  private $version;
10
-
11
  private $page_slug;
12
-
13
  private $page_hook;
14
-
15
  private $base_url;
16
-
17
  private $db;
18
 
19
  function __construct($_version, $_base_url = false ) {
20
  $this->load_dependencies();
21
-
22
- $this->version = $_version;
23
- $this->page_slug = 'wpsm_table_maker';
24
-
25
- $this->db = WPSM_DB_Table::get_instance();
26
-
27
- add_action( 'admin_menu', array($this, 'add_menu_items') );
28
- add_action( 'admin_enqueue_scripts', array($this, 'backend_enqueue') );
29
- add_action( 'admin_init', array($this, 'handle_requests') );
30
- add_action('plugins_loaded', array($this, 'xml_download'));
31
- add_action( 'admin_notices', array($this, 'admin_notices') );
32
- add_shortcode( 'wpsm_comparison_table', array($this, 'comparison_table_callback') );
33
- add_action( 'init', array($this, 'wpsm_table_frontend_scripts') );
34
- add_action( 'wp_enqueue_scripts', array($this, 'wpsm_table_frontend_styles') );
35
 
36
  if(!$_base_url)
37
  $this->base_url = plugins_url( '', dirname(__FILE__) );
@@ -46,7 +40,7 @@ class WPSM_Table_Maker
46
  }
47
 
48
  public function add_menu_items() {
49
- $this->page_hook = add_menu_page( __('Table Maker', 'wpsm-tableplugin'), __('Table Maker', 'wpsm-tableplugin'), 'manage_options', $this->page_slug, array($this, 'print_page'), $this->base_url . "/img/icon.png" );
50
  }
51
 
52
  public function wpsm_table_frontend_scripts() {
@@ -62,12 +56,13 @@ class WPSM_Table_Maker
62
  public function backend_enqueue($hook) {
63
  if( $this->page_hook != $hook )
64
  return;
65
- wp_enqueue_style( 'wpsm-stylesheet', $this->base_url . '/css/table-maker.css', false, $this->version, 'all' );
66
- wp_enqueue_script( 'wpsm-comptable-script', $this->base_url . '/js/table-maker.js', array('jquery'), $this->version );
67
- wp_enqueue_script( 'jquery-ui-dialog' );
68
  wp_enqueue_script('jquery-effects-bounce');
69
- if (function_exists('wp_enqueue_media')) {wp_enqueue_media();}
70
-
 
71
  $wpsm_js_strings = array(
72
  'placeholder' => __('Click to edit', 'wpsm-tableplugin'),
73
  'resize_error' => __('Please enter valid numbers', 'wpsm-tableplugin'),
@@ -84,17 +79,15 @@ class WPSM_Table_Maker
84
  <div class="wrap">
85
  <?php
86
  if(isset($_GET['action']) && $_GET['action'] == 'add'){
87
- echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Add Table', 'wpsm-tableplugin'), admin_url('admin.php?page='.$this->page_slug), __('View All', 'wpsm-tableplugin') );
88
  $this->create_ui();
89
- }
90
- elseif(isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['table']) && is_numeric($_GET['table'])){
91
- echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Edit Table', 'wpsm-tableplugin'), admin_url('admin.php?page='.$this->page_slug), __('View All', 'wpsm-tableplugin') );
92
  $table = $this->db->get($_GET['table']);
93
  if($table)
94
  $this->create_ui($table);
95
- }
96
- else{
97
- echo sprintf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Tables', 'wpsm-tableplugin'), admin_url('admin.php?page='.$this->page_slug.'&action=add'), __('Add New', 'wpsm-tableplugin') );
98
  $list_table = new WPSM_List_Table();
99
  $list_table->show();
100
  }
@@ -104,14 +97,14 @@ class WPSM_Table_Maker
104
  }
105
 
106
  private function create_ui($table = false){
107
- $table_id = $table ? $table['id'] : '';
108
- $name = $table ? $table['name'] : '';
109
- $rows = $table ? $table['rows'] : 4;
110
- $cols = $table ? $table['cols'] : 4;
111
- $subs = $table ? $table['subs'] : '';
112
- $color = $table ? $table['color'] : 'default';
113
- $responsive = $table ? $table['responsive'] : '';
114
- $curr_values = $table ? $table['tvalues'] : '';
115
  $col_span = $cols;
116
  $sub_array = explode(',', $subs);
117
  ?>
@@ -302,114 +295,126 @@ class WPSM_Table_Maker
302
  return true;
303
  }
304
 
305
- public function handle_requests() {
306
- if( !$this->is_plugin_page() )
307
- return;
308
 
309
- if(isset($_GET['action2']) && $_GET['action2'] != -1 && $_GET['action'] == -1)
310
- $_GET['action'] = $_GET['action2'];
 
311
 
312
- if($_GET['action'] == 'add' && isset($_POST['wpsm-create-table'])){
313
- if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
314
- $result = $this->db->add( $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
315
- if($result){
316
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
317
- wp_redirect($sendback);
318
- }
319
- }
320
 
321
- if($_GET['action'] == 'edit' && isset($_POST['wpsm-save-changes']) && isset($_GET['table'])){
322
- if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
323
- $result = $this->db->update( $_GET['table'], $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
324
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $_GET['table'], 'updated' => $result ), '' );
325
- wp_redirect($sendback);
326
- }
327
-
328
- if($_GET['action'] == 'edit' && isset($_POST['wpsm-create-table'])){
329
- if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
330
- $result = $this->db->add( $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
331
- if($result){
332
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
333
- wp_redirect($sendback);
334
  }
335
- }
336
 
337
- if($_GET['action'] == 'delete' && isset($_GET['table']) ){
338
- if(is_array($_GET['table']) || is_numeric($_GET['table'])) {
339
- $result = $this->db->delete( $_GET['table'] );
340
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'deleted' => $result ), '' );
341
- wp_redirect($sendback);
 
 
 
 
 
 
 
 
342
  }
343
- }
344
 
345
-
346
- if(isset($_POST['wpsm-import-table'])) {
347
- if(is_uploaded_file($_FILES['upload_file']['tmp_name']) && $_FILES['upload_file']['type'] == 'text/xml') {
348
- $xml = simplexml_load_file($_FILES['upload_file']['tmp_name']);
349
- $array = xml2array($xml);
350
- } else {
351
- exit('Can\'t open file: ' . $_FILES['userfile']['name'] . '. Error: '. $_FILES['upload_file']['error'] .'.');
 
 
 
 
 
 
 
 
 
 
352
  }
353
- $result = $this->db->add($array['name'], $array['rows'], $array['cols'], $array['subs'], $array['color'], $array['responsive'], $array['tvalues'] );
354
- if($result){
355
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
356
- wp_redirect($sendback);
 
 
 
 
 
 
 
 
357
  }
358
- }
359
-
360
- if(isset($_POST['wpsm-import-csv'])) {
361
- if(is_uploaded_file($_FILES['upload_file']['tmp_name']) && $_FILES['upload_file']['type'] == 'text/csv' && isset($_POST['csv_delimiter'])) {
362
- if (($handle = fopen($_FILES['upload_file']['tmp_name'], "r")) !== FALSE) {
363
- $array = csv2array( $handle, $_POST['csv_delimiter'] );
364
- fclose($handle);
 
 
 
 
 
 
365
  }
366
- } else {
367
- exit('Can\'t open file: ' . $_FILES['userfile']['name'] . '. Error: '. $_FILES['upload_file']['error'] .'.');
368
  }
369
- $array['subs'] = '';
370
- $result = $this->db->add(__('Noname Table', 'wpsm-tableplugin'), $array['rows'], $array['cols'], $array['subs'], 'default', '0', $array['tvalues'] );
371
- if($result){
372
- $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
373
- wp_redirect($sendback);
 
374
  }
375
  }
 
376
  }
377
 
378
-
379
  public function admin_notices(){
380
  if( !$this->is_plugin_page() )
381
  return;
382
-
383
- $format = '<div class="updated"><p>%s</p></div>';
384
-
 
 
 
 
 
 
385
  if(isset($_GET['added']) && $_GET['added']):
386
- echo sprintf($format, __('The table has been created successfully!', 'wpsm-tableplugin') );
387
  elseif(isset($_GET['updated']) && $_GET['updated']):
388
- echo sprintf($format, __('The table has been updated successfully!', 'wpsm-tableplugin') );
389
  elseif(isset($_GET['deleted']) && $_GET['deleted']):
390
- echo sprintf($format, __('The table has been deleted successfully!', 'wpsm-tableplugin') );
391
  endif;
392
  }
393
 
394
-
395
- function xml_download() {
396
- if(isset($_POST['wpsm-export-table'])) {
397
- $result = $this->db->get( $_GET['table'] );
398
-
399
- if(!$result)
400
- return;
401
-
402
- $converter = new Array_XML();
403
- $xmlStr = $converter->convert($result);
404
-
405
- header("Content-type: txt/xml",true,200);
406
- header("Content-Disposition: attachment; filename=" . $_POST['table_name'] . ".xml" );
407
- //header('Content-Length: ' . ob_get_length($xmlStr));
408
- header("Pragma: no-cache");
409
- header("Expires: 0");
410
- echo $xmlStr;
411
- exit();
412
- }
413
  }
414
 
415
  function comparison_table_callback( $atts ){
@@ -427,6 +432,7 @@ class WPSM_Table_Maker
427
  }
428
 
429
  $table = $this->db->get($atts['id']);
 
430
  if(!$table)
431
  return;
432
 
7
  class WPSM_Table_Maker
8
  {
9
  private $version;
 
10
  private $page_slug;
 
11
  private $page_hook;
 
12
  private $base_url;
 
13
  private $db;
14
 
15
  function __construct($_version, $_base_url = false ) {
16
  $this->load_dependencies();
17
+ $this->version = $_version;
18
+ $this->page_slug = 'wpsm_table_maker';
19
+ $this->db = WPSM_DB_Table::get_instance();
20
+
21
+ add_action('admin_menu', array($this, 'add_menu_items'));
22
+ add_action('admin_enqueue_scripts', array($this, 'backend_enqueue'));
23
+ add_action('current_screen', array($this, 'handle_requests'));
24
+ //add_action('current_screen', array($this, 'xml_download'));
25
+ add_action('admin_notices', array($this, 'admin_notices') );
26
+ add_shortcode('wpsm_comparison_table', array($this, 'comparison_table_callback'));
27
+ add_action('init', array($this, 'wpsm_table_frontend_scripts') );
28
+ add_action('wp_enqueue_scripts', array($this, 'wpsm_table_frontend_styles'));
 
 
29
 
30
  if(!$_base_url)
31
  $this->base_url = plugins_url( '', dirname(__FILE__) );
40
  }
41
 
42
  public function add_menu_items() {
43
+ $this->page_hook = add_menu_page( __('Table Maker', 'wpsm-tableplugin'), __('Table Maker', 'wpsm-tableplugin'), 'publish_posts', $this->page_slug, array($this, 'print_page'), $this->base_url . "/img/icon.png" );
44
  }
45
 
46
  public function wpsm_table_frontend_scripts() {
56
  public function backend_enqueue($hook) {
57
  if( $this->page_hook != $hook )
58
  return;
59
+ wp_enqueue_style('wpsm-stylesheet', $this->base_url . '/css/table-maker.css', false, $this->version, 'all' );
60
+ wp_enqueue_script('wpsm-comptable-script', $this->base_url . '/js/table-maker.js', array('jquery'), $this->version );
61
+ wp_enqueue_script('jquery-ui-dialog' );
62
  wp_enqueue_script('jquery-effects-bounce');
63
+ if (function_exists('wp_enqueue_media')) {
64
+ wp_enqueue_media();
65
+ }
66
  $wpsm_js_strings = array(
67
  'placeholder' => __('Click to edit', 'wpsm-tableplugin'),
68
  'resize_error' => __('Please enter valid numbers', 'wpsm-tableplugin'),
79
  <div class="wrap">
80
  <?php
81
  if(isset($_GET['action']) && $_GET['action'] == 'add'){
82
+ printf('<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Add Table', 'wpsm-tableplugin'), wp_nonce_url(admin_url('admin.php?page='.$this->page_slug), 'add_table'), __('View All', 'wpsm-tableplugin'));
83
  $this->create_ui();
84
+ } elseif(isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['table']) && is_numeric($_GET['table'])) {
85
+ printf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Edit Table', 'wpsm-tableplugin'), admin_url('admin.php?page='.$this->page_slug), __('View All', 'wpsm-tableplugin') );
 
86
  $table = $this->db->get($_GET['table']);
87
  if($table)
88
  $this->create_ui($table);
89
+ } else {
90
+ printf( '<h2>%s <a class="add-new-h2" href="%s">%s</a></h2>', __('Tables', 'wpsm-tableplugin'), wp_nonce_url(admin_url('admin.php?page='.$this->page_slug.'&action=add'), 'add_table'), __('Add New', 'wpsm-tableplugin') );
 
91
  $list_table = new WPSM_List_Table();
92
  $list_table->show();
93
  }
97
  }
98
 
99
  private function create_ui($table = false){
100
+ $table_id = $table ? $table['id'] : '';
101
+ $name = $table ? $table['name'] : '';
102
+ $rows = $table ? $table['rows'] : 4;
103
+ $cols = $table ? $table['cols'] : 4;
104
+ $subs = $table ? $table['subs'] : '';
105
+ $color = $table ? $table['color'] : 'default';
106
+ $responsive = $table ? $table['responsive'] : '';
107
+ $curr_values = $table ? $table['tvalues'] : '';
108
  $col_span = $cols;
109
  $sub_array = explode(',', $subs);
110
  ?>
295
  return true;
296
  }
297
 
298
+ public function handle_requests($current_screen) {
 
 
299
 
300
+ if(current_user_can('publish_posts') && $current_screen->base == 'toplevel_page_wpsm_table_maker') { //Check if user have enough rights
301
+ if(!$this->is_plugin_page())
302
+ return;
303
 
304
+ if(isset($_GET['action2']) && $_GET['action2'] != -1 && $_GET['action'] == -1)
305
+ $_GET['action'] = $_GET['action2'];
 
 
 
 
 
 
306
 
307
+ if($_GET['action'] == 'add' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'add_table') && isset($_POST['wpsm-create-table'])){
308
+ if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
309
+ $result = $this->db->add( $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
310
+ if($result){
311
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
312
+ wp_redirect(wp_nonce_url($sendback, 'edit_table'));
313
+ }
 
 
 
 
 
 
314
  }
 
315
 
316
+ if($_GET['action'] == 'edit' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'edit_table') && isset($_POST['wpsm-save-changes'])){
317
+ if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
318
+ $result = $this->db->update( $_GET['table'], $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
319
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $_GET['table'], 'updated' => $result ), '' );
320
+ }
321
+
322
+ if($_GET['action'] == 'edit' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'add_table') && isset($_POST['wpsm-create-table'])){
323
+ if (!isset ($_POST['table_respon'])) {$_POST['table_respon'] = '';}
324
+ $result = $this->db->add( $_POST['table_name'], $_POST['table_rows'], $_POST['table_cols'], $_POST['table_subs'], $_POST['table_color'], $_POST['table_respon'], $_POST['table_values'] );
325
+ if($result){
326
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
327
+ $sendback = wp_nonce_url($sendback, 'edit_table');
328
+ }
329
  }
 
330
 
331
+ if($_GET['action'] == 'delete' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'delete_table') && isset($_GET['table']) ){
332
+ if(is_numeric($_GET['table'])) {
333
+ $result = $this->db->delete($_GET['table']);
334
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'deleted' => $result ), '' );
335
+ wp_redirect($sendback);
336
+ }
337
+ }
338
+ if($_GET['action'] == 'delete' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'bulk-tables') && isset($_GET['table']) ){
339
+ if(is_array($_GET['table'])) {
340
+ $ids = $_GET['table'];
341
+ $count = count($ids);
342
+ for($i = 0; $i < $count; $i++) {
343
+ $result = $this->db->delete($ids[$i]);
344
+ }
345
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'deleted' => $result ), '' );
346
+ wp_redirect($sendback);
347
+ }
348
  }
349
+
350
+ if(isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'add_table') && isset($_POST['wpsm-import-table'])) {
351
+ if(is_uploaded_file($_FILES['upload_file']['tmp_name']) && $_FILES['upload_file']['type'] == 'text/xml') {
352
+ $xml = simplexml_load_file($_FILES['upload_file']['tmp_name']);
353
+ $array = xml2array($xml);
354
+ }
355
+ if(!empty($array)) {
356
+ $array['subs'] = isset($array['subs']) ? $array['subs'] : '';
357
+ $result = $this->db->add($array['name'], $array['rows'], $array['cols'], $array['subs'], $array['color'], $array['responsive'], $array['tvalues'] );
358
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
359
+ wp_redirect($sendback);
360
+ }
361
  }
362
+
363
+ if(isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'add_table') && isset($_POST['wpsm-import-csv'])) {
364
+ if(is_uploaded_file($_FILES['upload_file']['tmp_name']) && $_FILES['upload_file']['type'] == 'text/csv' && isset($_POST['csv_delimiter'])) {
365
+ if (($handle = fopen($_FILES['upload_file']['tmp_name'], "r")) !== FALSE) {
366
+ $array = csv2array( $handle, $_POST['csv_delimiter'] );
367
+ fclose($handle);
368
+ }
369
+ }
370
+ if(!empty($array)) {
371
+ $array['subs'] = isset($array['subs']) ? $array['subs'] : '';
372
+ $result = $this->db->add(__('Noname Table', 'wpsm-tableplugin'), $array['rows'], $array['cols'], $array['subs'], 'default', '0', $array['tvalues'] );
373
+ $sendback = add_query_arg( array( 'page' => $_GET['page'], 'action' => 'edit', 'table' => $result, 'added' => true ), '' );
374
+ wp_redirect($sendback);
375
  }
 
 
376
  }
377
+
378
+ if($_GET['action'] == 'edit' && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'edit_table') && isset($_POST['wpsm-export-table'])) {
379
+ $result = $this->db->get($_GET['table']);
380
+ if($result) {
381
+ $this->xml_download($result);
382
+ }
383
  }
384
  }
385
+
386
  }
387
 
 
388
  public function admin_notices(){
389
  if( !$this->is_plugin_page() )
390
  return;
391
+ $warning = '<div class="notice notice-warning"><p>%s</p></div>';
392
+ $success = '<div class="notice notice-success"><p>%s</p></div>';
393
+ if(isset($_FILES['upload_file'])){
394
+ if(!is_uploaded_file($_FILES['upload_file']['tmp_name']) || !isset($_POST['csv_delimiter'])) {
395
+ if(!isset($_FILES['userfile']['name']) || $_FILES['upload_file']['type'] != 'text/xml' || $_FILES['upload_file']['type'] != 'text/csv') {
396
+ echo sprintf($warning, __('Can not open file!', 'wpsm-tableplugin') );
397
+ }
398
+ }
399
+ }
400
  if(isset($_GET['added']) && $_GET['added']):
401
+ echo sprintf($success, __('The table has been created successfully!', 'wpsm-tableplugin') );
402
  elseif(isset($_GET['updated']) && $_GET['updated']):
403
+ echo sprintf($success, __('The table has been updated successfully!', 'wpsm-tableplugin') );
404
  elseif(isset($_GET['deleted']) && $_GET['deleted']):
405
+ echo sprintf($success, __('The table has been deleted successfully!', 'wpsm-tableplugin') );
406
  endif;
407
  }
408
 
409
+ private function xml_download($result) {
410
+ $converter = new Array_XML();
411
+ $xmlStr = $converter->convert($result);
412
+ header("Content-type: txt/xml",true,200);
413
+ header("Content-Disposition: attachment; filename=" . $_POST['table_name'] . ".xml" );
414
+ header("Pragma: no-cache");
415
+ header("Expires: 0");
416
+ echo $xmlStr;
417
+ exit();
 
 
 
 
 
 
 
 
 
 
418
  }
419
 
420
  function comparison_table_callback( $atts ){
432
  }
433
 
434
  $table = $this->db->get($atts['id']);
435
+
436
  if(!$table)
437
  return;
438
 
js/table-maker.js CHANGED
@@ -1,4 +1,5 @@
1
  jQuery(document).ready(function ($) {
 
2
  var field_name_prefix = 'table_values';
3
 
4
  function get_effective(curr, index) {
1
  jQuery(document).ready(function ($) {
2
+
3
  var field_name_prefix = 'table_values';
4
 
5
  function get_effective(curr, index) {
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: wpsoul
3
  Tags: responsive tables, pricing tables, comparison tables, wordpress tables, table maker, top list table, pricing table maker, table generator, price comparison
4
  Donate link: https://wpsoul.com/
5
  Requires at least: 3.0
6
- Tested up to: 4.3.3
7
- Stable tag: 1.5
8
  License: License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -55,6 +55,13 @@ If you like this plugin please give it a good rating.
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
 
58
  = 1.6 =
59
  * Added responsive for columns of tables
60
 
3
  Tags: responsive tables, pricing tables, comparison tables, wordpress tables, table maker, top list table, pricing table maker, table generator, price comparison
4
  Donate link: https://wpsoul.com/
5
  Requires at least: 3.0
6
+ Tested up to: 4.9.1
7
+ Stable tag: 1.9
8
  License: License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
55
 
56
  == Changelog ==
57
 
58
+ = 1.9 =
59
+ * Security improvements
60
+
61
+ = 1.7 =
62
+ * Fixed DB table name
63
+ * Fixed language template
64
+
65
  = 1.6 =
66
  * Added responsive for columns of tables
67
 
table-maker.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Table Maker
4
  Plugin URI: https://wordpress.org/plugins/table-maker/
5
  Description: Create tables with just a few clicks.
6
- Version: 1.6
7
  Author: Wpsoul
8
  Author URI: https://wpsoul.com
9
  License: GPL2
@@ -18,20 +18,13 @@ if ( ! defined( 'WPINC' ) ) {
18
  require_once plugin_dir_path( __FILE__ ) . 'inc/class-wpsm-table-maker.php';
19
 
20
  function wpsm_run_table_maker() {
21
- $plugin_instance = new WPSM_Table_Maker('1.6');
22
  register_activation_hook( __FILE__, array($plugin_instance, 'initialize') );
23
  register_uninstall_hook( __FILE__, array('WPSM_Table_Maker', 'rollback') );
24
  }
25
 
26
  wpsm_run_table_maker();
27
 
28
- function wpsm_get_table($id)
29
- {
30
- $db = WPSM_DB_Table::get_instance();
31
- $table = $db->get($id);
32
- return $table['tvalues'];
33
- }
34
-
35
  function wpsm_load_plugin_textdomain() {
36
  load_plugin_textdomain( 'wpsm-tableplugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
37
  }
3
  Plugin Name: Table Maker
4
  Plugin URI: https://wordpress.org/plugins/table-maker/
5
  Description: Create tables with just a few clicks.
6
+ Version: 1.9
7
  Author: Wpsoul
8
  Author URI: https://wpsoul.com
9
  License: GPL2
18
  require_once plugin_dir_path( __FILE__ ) . 'inc/class-wpsm-table-maker.php';
19
 
20
  function wpsm_run_table_maker() {
21
+ $plugin_instance = new WPSM_Table_Maker('1.9');
22
  register_activation_hook( __FILE__, array($plugin_instance, 'initialize') );
23
  register_uninstall_hook( __FILE__, array('WPSM_Table_Maker', 'rollback') );
24
  }
25
 
26
  wpsm_run_table_maker();
27
 
 
 
 
 
 
 
 
28
  function wpsm_load_plugin_textdomain() {
29
  load_plugin_textdomain( 'wpsm-tableplugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
30
  }