Version Description
- Added import of table from CSV
Download this release
Release Info
Developer | wpsoul |
Plugin | Table Maker |
Version | 1.5 |
Comparing to | |
See all releases |
Code changes from version 1.4 to 1.5
- css/style.css +1 -3
- css/table-maker.css +1 -9
- inc/class-wpsm-db-table.php +127 -127
- inc/class-wpsm-list-table.php +109 -109
- inc/class-wpsm-table-maker.php +505 -476
- inc/class-wpsm-table-xml.php +102 -81
- js/table-maker-front.js +46 -34
- js/table-maker.js +483 -483
- readme.txt +75 -71
- table-maker.php +39 -39
css/style.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
@font-face { font-family: 'wpsm-icons'; src: url('../font/wpsm-icons.eot?-jgkfsj'); src: url('../font/wpsm-icons.eot?#iefix-jgkfsj') format('embedded-opentype'), url('../font/wpsm-icons.woff?-jgkfsj') format('woff'), url('../font/wpsm-icons.ttf?-jgkfsj') format('truetype'), url('../font/wpsm-icons.svg?-jgkfsj#wpsm-icons') format('svg'); font-weight: normal; font-style: normal; }
|
2 |
-
webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
|
3 |
|
|
|
4 |
-
webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
|
5 |
|
|
|
|
|
1 |
|
2 |
+
@font-face { font-family: 'wpsm-icons'; src: url('../font/wpsm-icons.eot?-jgkfsj'); src: url('../font/wpsm-icons.eot?#iefix-jgkfsj') format('embedded-opentype'), url('../font/wpsm-icons.woff?-jgkfsj') format('woff'), url('../font/wpsm-icons.ttf?-jgkfsj') format('truetype'), url('../font/wpsm-icons.svg?-jgkfsj#wpsm-icons') format('svg'); font-weight: normal; font-style: normal; }
|
|
|
3 |
|
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
@@ -1,128 +1,128 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
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();
|
23 |
-
}
|
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;
|
31 |
-
}
|
32 |
-
|
33 |
-
$sql = "
|
34 |
-
CREATE TABLE $this->table_name (
|
35 |
-
id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
|
36 |
-
name TINYTEXT NOT NULL,
|
37 |
-
rows MEDIUMINT(9) NOT NULL,
|
38 |
-
cols MEDIUMINT(9) NOT NULL,
|
39 |
-
subs TINYTEXT NOT NULL,
|
40 |
-
color TINYTEXT NOT NULL,
|
41 |
-
responsive tinyint(1) NOT NULL DEFAULT '0',
|
42 |
-
tvalues LONGTEXT NOT NULL,
|
43 |
-
UNIQUE KEY id (id)
|
44 |
-
);
|
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));
|
55 |
-
$subs = strval(wp_unslash($subs));
|
56 |
-
$color = strval(wp_unslash($color));
|
57 |
-
$responsive = intval(wp_unslash($responsive));
|
58 |
-
$tvalues = $this->serialize(wp_unslash($tvalues));
|
59 |
-
|
60 |
-
$result = $this->db->insert( $this->table_name, array('name' => $name, 'rows' => $rows, 'cols' => $cols, 'subs' => $subs, 'color' => $color, 'responsive' => $responsive, 'tvalues' => $tvalues ) );
|
61 |
-
if($result)
|
62 |
-
return $this->db->insert_id;
|
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));
|
70 |
-
$subs = strval(wp_unslash($subs));
|
71 |
-
$color = strval(wp_unslash($color));
|
72 |
-
$responsive = intval(wp_unslash($responsive));
|
73 |
-
$tvalues = $this->serialize(wp_unslash($tvalues));
|
74 |
-
|
75 |
-
return $this->db->update( $this->table_name, array('name' => $name, 'rows' => $rows, 'cols' => $cols, 'subs' => $subs, 'color' => $color, 'responsive' => $responsive, 'tvalues' => $tvalues ), array( 'id' => $id ) );
|
76 |
-
}
|
77 |
-
|
78 |
-
public function drop_table() {
|
79 |
-
$query = "DROP TABLE $this->table_name";
|
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){
|
109 |
-
$start = (($curr_page-1)*$per_page);
|
110 |
-
$query = "SELECT * FROM $this->table_name ORDER BY id DESC LIMIT $start, $per_page";
|
111 |
-
return $this->db->get_results( $query, ARRAY_A );
|
112 |
-
}
|
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){
|
120 |
-
return base64_encode(serialize($item));
|
121 |
-
}
|
122 |
-
|
123 |
-
private function unserialize($item){
|
124 |
-
return unserialize(base64_decode($item));
|
125 |
-
}
|
126 |
-
}
|
127 |
-
|
128 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
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();
|
23 |
+
}
|
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;
|
31 |
+
}
|
32 |
+
|
33 |
+
$sql = "
|
34 |
+
CREATE TABLE $this->table_name (
|
35 |
+
id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
|
36 |
+
name TINYTEXT NOT NULL,
|
37 |
+
rows MEDIUMINT(9) NOT NULL,
|
38 |
+
cols MEDIUMINT(9) NOT NULL,
|
39 |
+
subs TINYTEXT NOT NULL,
|
40 |
+
color TINYTEXT NOT NULL,
|
41 |
+
responsive tinyint(1) NOT NULL DEFAULT '0',
|
42 |
+
tvalues LONGTEXT NOT NULL,
|
43 |
+
UNIQUE KEY id (id)
|
44 |
+
);
|
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));
|
55 |
+
$subs = strval(wp_unslash($subs));
|
56 |
+
$color = strval(wp_unslash($color));
|
57 |
+
$responsive = intval(wp_unslash($responsive));
|
58 |
+
$tvalues = $this->serialize(wp_unslash($tvalues));
|
59 |
+
|
60 |
+
$result = $this->db->insert( $this->table_name, array('name' => $name, 'rows' => $rows, 'cols' => $cols, 'subs' => $subs, 'color' => $color, 'responsive' => $responsive, 'tvalues' => $tvalues ) );
|
61 |
+
if($result)
|
62 |
+
return $this->db->insert_id;
|
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));
|
70 |
+
$subs = strval(wp_unslash($subs));
|
71 |
+
$color = strval(wp_unslash($color));
|
72 |
+
$responsive = intval(wp_unslash($responsive));
|
73 |
+
$tvalues = $this->serialize(wp_unslash($tvalues));
|
74 |
+
|
75 |
+
return $this->db->update( $this->table_name, array('name' => $name, 'rows' => $rows, 'cols' => $cols, 'subs' => $subs, 'color' => $color, 'responsive' => $responsive, 'tvalues' => $tvalues ), array( 'id' => $id ) );
|
76 |
+
}
|
77 |
+
|
78 |
+
public function drop_table() {
|
79 |
+
$query = "DROP TABLE $this->table_name";
|
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){
|
109 |
+
$start = (($curr_page-1)*$per_page);
|
110 |
+
$query = "SELECT * FROM $this->table_name ORDER BY id DESC LIMIT $start, $per_page";
|
111 |
+
return $this->db->get_results( $query, ARRAY_A );
|
112 |
+
}
|
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){
|
120 |
+
return base64_encode(serialize($item));
|
121 |
+
}
|
122 |
+
|
123 |
+
private function unserialize($item){
|
124 |
+
return unserialize(base64_decode($item));
|
125 |
+
}
|
126 |
+
}
|
127 |
+
|
128 |
?>
|
inc/class-wpsm-list-table.php
CHANGED
@@ -1,110 +1,110 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'WPINC' ) ) {
|
4 |
-
die;
|
5 |
-
}
|
6 |
-
|
7 |
-
if(!class_exists('WP_List_Table')){
|
8 |
-
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
9 |
-
}
|
10 |
-
|
11 |
-
class WPSM_List_Table extends WP_List_Table {
|
12 |
-
|
13 |
-
private $db;
|
14 |
-
|
15 |
-
public function __construct(){
|
16 |
-
|
17 |
-
$this->load_dependencies();
|
18 |
-
|
19 |
-
$this->db = WPSM_DB_Table::get_instance();
|
20 |
-
|
21 |
-
global $status, $page;
|
22 |
-
|
23 |
-
parent::__construct( array(
|
24 |
-
'singular' => 'table',
|
25 |
-
'plural' => 'tables',
|
26 |
-
'ajax' => false,
|
27 |
-
'screen' => $_REQUEST['page']
|
28 |
-
) );
|
29 |
-
}
|
30 |
-
|
31 |
-
function load_dependencies(){
|
32 |
-
require_once( 'class-wpsm-db-table.php' );
|
33 |
-
}
|
34 |
-
|
35 |
-
function get_columns(){
|
36 |
-
$columns = array(
|
37 |
-
'cb' => '<input type="checkbox" />',
|
38 |
-
'id' => __('ID', 'wpsm-tableplugin'),
|
39 |
-
'name' => __('Name', 'wpsm-tableplugin'),
|
40 |
-
'rows' => __('Rows', 'wpsm-tableplugin'),
|
41 |
-
'cols' => __('Columns', 'wpsm-tableplugin'),
|
42 |
-
'subs' => __('Sub-headers', 'wpsm-tableplugin'),
|
43 |
-
'color' => __('Color','wpsm-tableplugin'),
|
44 |
-
'responsive' => __('Responsive','wpsm-tableplugin')
|
45 |
-
);
|
46 |
-
return $columns;
|
47 |
-
}
|
48 |
-
|
49 |
-
function column_default($item, $column_name){
|
50 |
-
return stripslashes($item[$column_name]);
|
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
|
61 |
-
return sprintf('%1$s %2$s',
|
62 |
-
/*$1%s*/ stripslashes($item['name']),
|
63 |
-
/*$2%s*/ $this->row_actions($actions)
|
64 |
-
);
|
65 |
-
}
|
66 |
-
|
67 |
-
function column_cb($item){
|
68 |
-
return sprintf(
|
69 |
-
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
|
70 |
-
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
|
71 |
-
/*$2%s*/ $item['id'] //The value of the checkbox should be the record's id
|
72 |
-
);
|
73 |
-
}
|
74 |
-
|
75 |
-
function get_bulk_actions() {
|
76 |
-
$actions = array(
|
77 |
-
'delete' => __('Delete', 'wpsm-tableplugin')
|
78 |
-
);
|
79 |
-
return $actions;
|
80 |
-
}
|
81 |
-
|
82 |
-
function prepare_items() {
|
83 |
-
$per_page = 25;
|
84 |
-
$hidden = array();
|
85 |
-
$columns = $this->get_columns();
|
86 |
-
$sortable = array();
|
87 |
-
$curr_page = $this->get_pagenum();
|
88 |
-
$total_items = $this->db->get_count();
|
89 |
-
$data = $this->db->get_page_items($curr_page, $per_page);
|
90 |
-
$this->items = $data;
|
91 |
-
$this->_column_headers = array($columns, $hidden, $sortable);
|
92 |
-
$this->set_pagination_args( array(
|
93 |
-
'total_items' => $total_items,
|
94 |
-
'per_page' => $per_page,
|
95 |
-
'total_pages' => ceil($total_items/$per_page)
|
96 |
-
) );
|
97 |
-
}
|
98 |
-
|
99 |
-
function show(){
|
100 |
-
?>
|
101 |
-
<form method="GET">
|
102 |
-
<input type="hidden" name="page" value="<?php echo $_GET['page'] ?>">
|
103 |
-
<?php
|
104 |
-
$this->prepare_items();
|
105 |
-
$this->display();
|
106 |
-
?>
|
107 |
-
</form>
|
108 |
-
<?php
|
109 |
-
}
|
110 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'WPINC' ) ) {
|
4 |
+
die;
|
5 |
+
}
|
6 |
+
|
7 |
+
if(!class_exists('WP_List_Table')){
|
8 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
9 |
+
}
|
10 |
+
|
11 |
+
class WPSM_List_Table extends WP_List_Table {
|
12 |
+
|
13 |
+
private $db;
|
14 |
+
|
15 |
+
public function __construct(){
|
16 |
+
|
17 |
+
$this->load_dependencies();
|
18 |
+
|
19 |
+
$this->db = WPSM_DB_Table::get_instance();
|
20 |
+
|
21 |
+
global $status, $page;
|
22 |
+
|
23 |
+
parent::__construct( array(
|
24 |
+
'singular' => 'table',
|
25 |
+
'plural' => 'tables',
|
26 |
+
'ajax' => false,
|
27 |
+
'screen' => $_REQUEST['page']
|
28 |
+
) );
|
29 |
+
}
|
30 |
+
|
31 |
+
function load_dependencies(){
|
32 |
+
require_once( 'class-wpsm-db-table.php' );
|
33 |
+
}
|
34 |
+
|
35 |
+
function get_columns(){
|
36 |
+
$columns = array(
|
37 |
+
'cb' => '<input type="checkbox" />',
|
38 |
+
'id' => __('ID', 'wpsm-tableplugin'),
|
39 |
+
'name' => __('Name', 'wpsm-tableplugin'),
|
40 |
+
'rows' => __('Rows', 'wpsm-tableplugin'),
|
41 |
+
'cols' => __('Columns', 'wpsm-tableplugin'),
|
42 |
+
'subs' => __('Sub-headers', 'wpsm-tableplugin'),
|
43 |
+
'color' => __('Color','wpsm-tableplugin'),
|
44 |
+
'responsive' => __('Responsive','wpsm-tableplugin')
|
45 |
+
);
|
46 |
+
return $columns;
|
47 |
+
}
|
48 |
+
|
49 |
+
function column_default($item, $column_name){
|
50 |
+
return stripslashes($item[$column_name]);
|
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
|
61 |
+
return sprintf('%1$s %2$s',
|
62 |
+
/*$1%s*/ stripslashes($item['name']),
|
63 |
+
/*$2%s*/ $this->row_actions($actions)
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
function column_cb($item){
|
68 |
+
return sprintf(
|
69 |
+
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
|
70 |
+
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
|
71 |
+
/*$2%s*/ $item['id'] //The value of the checkbox should be the record's id
|
72 |
+
);
|
73 |
+
}
|
74 |
+
|
75 |
+
function get_bulk_actions() {
|
76 |
+
$actions = array(
|
77 |
+
'delete' => __('Delete', 'wpsm-tableplugin')
|
78 |
+
);
|
79 |
+
return $actions;
|
80 |
+
}
|
81 |
+
|
82 |
+
function prepare_items() {
|
83 |
+
$per_page = 25;
|
84 |
+
$hidden = array();
|
85 |
+
$columns = $this->get_columns();
|
86 |
+
$sortable = array();
|
87 |
+
$curr_page = $this->get_pagenum();
|
88 |
+
$total_items = $this->db->get_count();
|
89 |
+
$data = $this->db->get_page_items($curr_page, $per_page);
|
90 |
+
$this->items = $data;
|
91 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
92 |
+
$this->set_pagination_args( array(
|
93 |
+
'total_items' => $total_items,
|
94 |
+
'per_page' => $per_page,
|
95 |
+
'total_pages' => ceil($total_items/$per_page)
|
96 |
+
) );
|
97 |
+
}
|
98 |
+
|
99 |
+
function show(){
|
100 |
+
?>
|
101 |
+
<form method="GET">
|
102 |
+
<input type="hidden" name="page" value="<?php echo $_GET['page'] ?>">
|
103 |
+
<?php
|
104 |
+
$this->prepare_items();
|
105 |
+
$this->display();
|
106 |
+
?>
|
107 |
+
</form>
|
108 |
+
<?php
|
109 |
+
}
|
110 |
}
|
inc/class-wpsm-table-maker.php
CHANGED
@@ -1,477 +1,506 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'WPINC' ) ) {
|
4 |
-
die;
|
5 |
-
}
|
6 |
-
|
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__) );
|
38 |
-
else
|
39 |
-
$this->base_url = $_base_url;
|
40 |
-
}
|
41 |
-
|
42 |
-
private function load_dependencies(){
|
43 |
-
require_once 'class-wpsm-list-table.php';
|
44 |
-
require_once 'class-wpsm-db-table.php';
|
45 |
-
require_once 'class-wpsm-table-xml.php';
|
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() {
|
53 |
-
wp_register_script( 'table-maker-front', $this->base_url . '/js/table-maker-front.js', array('jquery'), $this->version, true );
|
54 |
-
wp_register_script( 'jquery-stacktable', $this->base_url . '/js/stacktable.js', array('jquery'), '0.1.0', true );
|
55 |
-
|
56 |
-
}
|
57 |
-
|
58 |
-
public function wpsm_table_frontend_styles() {
|
59 |
-
wp_enqueue_style( "wpsm-comptable-styles", plugins_url( "css/style.css" , dirname(__FILE__) ), null, $this->version, "all" );
|
60 |
-
}
|
61 |
-
|
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'),
|
74 |
-
'only_one' => __('Please fill only one field', 'wpsm-tableplugin'),
|
75 |
-
'insert_error_row' => __('Please specify number less than existing rows count', 'wpsm-tableplugin'),
|
76 |
-
'insert_error_col' => __('Please specify number less than existing cols count', 'wpsm-tableplugin'),
|
77 |
-
'switch_error' => __('Please enter valid numbers between 1 and', 'wpsm-tableplugin')
|
78 |
-
);
|
79 |
-
wp_localize_script( 'wpsm-comptable-script', 'wpsm_js_strings', $wpsm_js_strings );
|
80 |
-
}
|
81 |
-
|
82 |
-
public function print_page() {
|
83 |
-
?>
|
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 |
-
}
|
101 |
-
?>
|
102 |
-
</div>
|
103 |
-
<?php
|
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 |
-
?>
|
118 |
-
<form autocomplete="off" method="POST" class="wpsm-form">
|
119 |
-
<input type="text" class="wpsm-comptable-title" placeholder="<?php _e('Table Name', 'wpsm-tableplugin'); ?>" name="table_name" value="<?php echo esc_attr($name); ?>" required="required" />
|
120 |
-
<input type="hidden" class="wpsm-rows" value="<?php echo esc_attr($rows); ?>" name="table_rows" />
|
121 |
-
<input type="hidden" class="wpsm-cols" value="<?php echo esc_attr($cols); ?>" name="table_cols" />
|
122 |
-
<input type="hidden" class="wpsm-subs" value="<?php echo esc_attr($subs); ?>" name="table_subs" />
|
123 |
-
<div class="wpsm-options">
|
124 |
-
<p class="description">
|
125 |
-
<
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
<
|
131 |
-
|
132 |
-
|
133 |
-
<
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
<option value="
|
140 |
-
<option value="
|
141 |
-
<option value="
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
<
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
<
|
159 |
-
<
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
echo '<
|
195 |
-
_e('
|
196 |
-
echo '<br/><br/>';
|
197 |
-
echo '<strong>[
|
198 |
-
_e('Possible
|
199 |
-
echo '<br/><br/>';
|
200 |
-
echo '<strong>[
|
201 |
-
_e('
|
202 |
-
echo '<br/><br/>';
|
203 |
-
echo '<strong>[
|
204 |
-
_e('
|
205 |
-
echo '<br/><br/>';
|
206 |
-
echo '<strong>[
|
207 |
-
_e('
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
<
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
echo '
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
<
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
<
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
<
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
<
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'WPINC' ) ) {
|
4 |
+
die;
|
5 |
+
}
|
6 |
+
|
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__) );
|
38 |
+
else
|
39 |
+
$this->base_url = $_base_url;
|
40 |
+
}
|
41 |
+
|
42 |
+
private function load_dependencies(){
|
43 |
+
require_once 'class-wpsm-list-table.php';
|
44 |
+
require_once 'class-wpsm-db-table.php';
|
45 |
+
require_once 'class-wpsm-table-xml.php';
|
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() {
|
53 |
+
wp_register_script( 'table-maker-front', $this->base_url . '/js/table-maker-front.js', array('jquery'), $this->version, true );
|
54 |
+
wp_register_script( 'jquery-stacktable', $this->base_url . '/js/stacktable.js', array('jquery'), '0.1.0', true );
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
public function wpsm_table_frontend_styles() {
|
59 |
+
wp_enqueue_style( "wpsm-comptable-styles", plugins_url( "css/style.css" , dirname(__FILE__) ), null, $this->version, "all" );
|
60 |
+
}
|
61 |
+
|
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'),
|
74 |
+
'only_one' => __('Please fill only one field', 'wpsm-tableplugin'),
|
75 |
+
'insert_error_row' => __('Please specify number less than existing rows count', 'wpsm-tableplugin'),
|
76 |
+
'insert_error_col' => __('Please specify number less than existing cols count', 'wpsm-tableplugin'),
|
77 |
+
'switch_error' => __('Please enter valid numbers between 1 and', 'wpsm-tableplugin')
|
78 |
+
);
|
79 |
+
wp_localize_script( 'wpsm-comptable-script', 'wpsm_js_strings', $wpsm_js_strings );
|
80 |
+
}
|
81 |
+
|
82 |
+
public function print_page() {
|
83 |
+
?>
|
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 |
+
}
|
101 |
+
?>
|
102 |
+
</div>
|
103 |
+
<?php
|
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 |
+
?>
|
118 |
+
<form autocomplete="off" method="POST" class="wpsm-form">
|
119 |
+
<input type="text" class="wpsm-comptable-title" placeholder="<?php _e('Table Name', 'wpsm-tableplugin'); ?>" name="table_name" value="<?php echo esc_attr($name); ?>" required="required" />
|
120 |
+
<input type="hidden" class="wpsm-rows" value="<?php echo esc_attr($rows); ?>" name="table_rows" />
|
121 |
+
<input type="hidden" class="wpsm-cols" value="<?php echo esc_attr($cols); ?>" name="table_cols" />
|
122 |
+
<input type="hidden" class="wpsm-subs" value="<?php echo esc_attr($subs); ?>" name="table_subs" />
|
123 |
+
<div class="wpsm-options">
|
124 |
+
<p class="description">
|
125 |
+
<select name="table_respon" id="wpsm_respon">
|
126 |
+
<option value="0" <?php selected( $responsive, 0 ); ?>><?php _e('No', 'wpsm-tableplugin') ?></option>
|
127 |
+
<option value="1" <?php selected( $responsive, 1 ); ?>><?php _e('Table row stack', 'wpsm-tableplugin') ?></option>
|
128 |
+
<option value="2" <?php selected( $responsive, 2 ); ?>><?php _e('Table column stack', 'wpsm-tableplugin') ?></option>
|
129 |
+
</select>
|
130 |
+
<label for="wpsm_respon"> - <?php _e('enable responsive stack style for mobile devices','wpsm-tableplugin'); ?></label>
|
131 |
+
</p>
|
132 |
+
<div class="wpsm-controls">
|
133 |
+
<button id="wpsm-comptable-resize-btn" type="button" class="button"><?php _e('Resize Table', 'wpsm-tableplugin') ?></button>
|
134 |
+
<button id="wpsm-row-switcher-btn" type="button" class="button"><?php _e('Switch Rows', 'wpsm-tableplugin') ?></button>
|
135 |
+
<button id="wpsm-col-switcher-btn" type="button" class="button"><?php _e('Switch Cols', 'wpsm-tableplugin') ?></button>
|
136 |
+
<button id="wpsm-comptable-addnew-btn" type="button" class="button"><?php _e('Add Inside', 'wpsm-tableplugin') ?></button>
|
137 |
+
<button id="wpsm-comptable-remove-btn" type="button" class="button"><?php _e('Remove', 'wpsm-tableplugin') ?></button>
|
138 |
+
<select id="wpsm-colors" name="table_color" class="wpsm-select-color">
|
139 |
+
<option value="default" <?php if($color == 'default') echo 'selected'; ?>><?php _e('Grey', 'wpsm-tableplugin') ;?></option>
|
140 |
+
<option value="black" <?php if($color == 'black') echo 'selected'; ?>><?php _e('Black', 'wpsm-tableplugin') ;?></option>
|
141 |
+
<option value="yellow" <?php if($color == 'yellow') echo 'selected'; ?>><?php _e('Yellow', 'wpsm-tableplugin') ;?></option>
|
142 |
+
<option value="blue" <?php if($color == 'blue') echo 'selected'; ?>><?php _e('Blue', 'wpsm-tableplugin') ;?></option>
|
143 |
+
<option value="red" <?php if($color == 'red') echo 'selected'; ?>><?php _e('Red', 'wpsm-tableplugin') ;?></option>
|
144 |
+
<option value="green" <?php if($color == 'green') echo 'selected'; ?>><?php _e('Green', 'wpsm-tableplugin') ;?></option>
|
145 |
+
<option value="orange" <?php if($color == 'orange') echo 'selected'; ?>><?php _e('Orange', 'wpsm-tableplugin') ;?></option>
|
146 |
+
<option value="purple" <?php if($color == 'purple') echo 'selected'; ?>><?php _e('Purple', 'wpsm-tableplugin') ;?></option>
|
147 |
+
</select>
|
148 |
+
<?php if($table) submit_button( __('Save Changes', 'wpsm-plugin'), 'primary right', 'wpsm-save-changes', false ); ?>
|
149 |
+
</div>
|
150 |
+
</div>
|
151 |
+
<div class="wpsm_comptable_admin_description">
|
152 |
+
<div class="wpsm_comptable_shortcode_echo">
|
153 |
+
[wpsm_comparison_table id="<?php echo $table_id; ?>" class=""]
|
154 |
+
</div>
|
155 |
+
<div class="wpsm_comptable_shortcode_hidden">
|
156 |
+
[wpsm_comparison_table id="<?php echo $table_id; ?>" class="<span id='wpsm_comp_shortcode_firsthover'></span><span id='wpsm_comp_shortcode_calign'></span>"]
|
157 |
+
</div>
|
158 |
+
<p class="description">
|
159 |
+
<input type="checkbox" id="wpsm_first_col_hover_check" /><label for="wpsm_first_col_hover_check"> - <?php _e('Add "mark the first column" class to shortcode', 'wpsm-tableplugin'); ?></label>
|
160 |
+
<input type="checkbox" id="wpsm_calign_check" /><label for="wpsm_calign_check"> - <?php _e('Add "center text align" class to shortcode', 'wpsm-tableplugin'); ?></label>
|
161 |
+
</p>
|
162 |
+
</div>
|
163 |
+
<table class="wpsm-comptable">
|
164 |
+
<thead class="wpsm-thead">
|
165 |
+
<tr>
|
166 |
+
<?php for ($j=1; $j <= $cols; $j++): ?>
|
167 |
+
<th><input placeholder="<?php _e('Click to edit', 'wpsm-tableplugin') ?>" type="text" name="table_values[0][<?php echo $j; ?>]" value="<?php echo isset($curr_values[0][$j]) ? esc_attr($curr_values[0][$j]) : ''; ?>" /></th>
|
168 |
+
<?php endfor; ?>
|
169 |
+
</tr>
|
170 |
+
</thead>
|
171 |
+
<tbody class="wpsm-tbody">
|
172 |
+
<?php for ($i=1; $i <= $rows; $i++): ?>
|
173 |
+
<?php echo in_array($i, $sub_array) ? '<tr class="subheader">' : '<tr>'; ?>
|
174 |
+
<?php for ($j=1; $j <= $cols; $j++): ?>
|
175 |
+
<?php echo in_array($i, $sub_array) ? '<td colspan="'.$col_span.'">' : '<td>'; ?>
|
176 |
+
<?php if ($j==1) {echo '<span class="num_row_wpsm_table">'.$i.'</span>' ;} ;?>
|
177 |
+
<textarea placeholder="<?php _e('Click to edit', 'wpsm-tableplugin') ?>" type="text" name="table_values[<?php echo $i; ?>][<?php echo $j; ?>]" ><?php echo isset($curr_values[$i][$j]) ? esc_attr($curr_values[$i][$j]) : ''; ?></textarea>
|
178 |
+
|
179 |
+
</td>
|
180 |
+
<?php if(in_array($i, $sub_array)) break; ?>
|
181 |
+
<?php endfor; ?>
|
182 |
+
</tr>
|
183 |
+
<?php endfor; ?>
|
184 |
+
</tbody>
|
185 |
+
</table>
|
186 |
+
<div class="wpsm_comptable_description">
|
187 |
+
<span class="wpsm_comptable_info_span">ℹ</span>
|
188 |
+
<?php _e('Each cell supports html and shortcodes. ', 'wpsm-tableplugin'); ?>
|
189 |
+
<br/>
|
190 |
+
<?php $placeholders = array('tick', 'cross', 'info', 'warning', 'heart', 'lock', 'star', 'star-empty'); ?>
|
191 |
+
<?php _e('To add icons you can use these placeholders: ', 'wpsm-tableplugin'); foreach($placeholders as $p){ echo "<strong>%".strtoupper($p)."%</strong> "; } ?>
|
192 |
+
<?php echo '<br/><br/>'; echo ' <strong>%COL-CHOICE% %COL-CHOICE-IMAGE% %ROW-CHOICE% %ROW-CHOICE-IMAGE%</strong>'; _e(' makes row or col as featured.', 'wpsm-tableplugin'); ?>
|
193 |
+
<?php if( function_exists('wpsm_shortcode_button') ) {
|
194 |
+
echo '<br/><br/>';
|
195 |
+
_e('Useful shortcodes:', 'wpsm-tableplugin');
|
196 |
+
echo '<br/><br/>';
|
197 |
+
echo '<strong>[wpsm_button color="green" size="big" link="" icon="" target="_blank" rel="nofollow"]Button[/wpsm_button]</strong><br/>';
|
198 |
+
_e('Possible color attribute:', 'wpsm-tableplugin'); echo ' orange, blue, green, black, rosy, brown, pink, purple, gold, teal. <br/>'; _e('Possible sizes:', 'wpsm-tableplugin'); echo ' small, medium, big, giant. <br/>'; _e('Possible icons:', 'wpsm-tableplugin'); echo ' download, check-circle, link, map-marker, star, heart, save, check-circle. ';
|
199 |
+
echo '<br/><br/>';
|
200 |
+
echo '<strong>[wpsm_numcircle num="1" style="2"]</strong><br/>';
|
201 |
+
_e('Nembered circle. Place number in', 'wpsm-tableplugin'); echo ' num';
|
202 |
+
echo '<br/><br/>';
|
203 |
+
echo '<strong>[wpsm_highlight color="yellow"]Content[/wpsm_highlight]</strong><br/>';
|
204 |
+
_e('Possible colors: ', 'wpsm-tableplugin'); echo ' yellow, blue, red, green, black';
|
205 |
+
echo '<br/><br/>';
|
206 |
+
echo '<strong>[wpsm_bar title="Design" percentage="60" color="#fb7203"]</strong><br/>';
|
207 |
+
_e('Animated bar. You can use any color', 'wpsm-tableplugin');
|
208 |
+
echo '<br/><br/>';
|
209 |
+
echo '<strong>[wpsm_is_user]Content[/wpsm_is_user]</strong><br/>';
|
210 |
+
_e('Shows content only for logged users', 'wpsm-tableplugin');
|
211 |
+
echo '<br/><br/>';
|
212 |
+
echo '<strong>[wpsm_is_guest]Content[/wpsm_is_guest]</strong><br/>';
|
213 |
+
_e('Shows content only for not logged users', 'wpsm-tableplugin');
|
214 |
+
|
215 |
+
}
|
216 |
+
?>
|
217 |
+
</div>
|
218 |
+
<div class="wpsm_table_helper_image">
|
219 |
+
<img src="" class="wpsm_table_helper_preview_image" alt="" style="max-width: 80px" width="80" height="80" />
|
220 |
+
<strong><?php _e('Image Helper', 'wpsm-tableplugin'); ?></strong>
|
221 |
+
<p class="description"><?php _e('Upload or choose image here and copy code to table', 'wpsm-tableplugin'); ?></p>
|
222 |
+
<input type="text" size="70" class="wpsm_table_helper_upload_image" value="" />
|
223 |
+
<a href="#" class="wpsm_table_helper_upload_image_button button" rel=""><?php _e('Choose Image', 'wpsm-tableplugin'); ?></a>
|
224 |
+
<small> <a href="#" class="wpsm_table_helper_clear_image_button button">X</a></small>
|
225 |
+
<br /><br />
|
226 |
+
|
227 |
+
</div>
|
228 |
+
|
229 |
+
<div class="clear"></div>
|
230 |
+
<?php
|
231 |
+
if($table) {
|
232 |
+
echo '<p class="submit">';
|
233 |
+
submit_button( __('Save Changes', 'wpsm-plugin'), 'primary', 'wpsm-save-changes', false );
|
234 |
+
echo ' ';
|
235 |
+
submit_button( __('Dublicate Table', 'wpsm-plugin'), 'primary', 'wpsm-create-table', false );
|
236 |
+
echo ' ';
|
237 |
+
submit_button( __('Export XML', 'wpsm-plugin'), 'primary', 'wpsm-export-table', false );
|
238 |
+
echo '</p>';
|
239 |
+
} else {
|
240 |
+
submit_button( __('Create Table', 'wpsm-plugin'), 'primary', 'wpsm-create-table', true );
|
241 |
+
}
|
242 |
+
?>
|
243 |
+
</form>
|
244 |
+
|
245 |
+
<?php if(!$table) : ?>
|
246 |
+
<form enctype="multipart/form-data" method="POST">
|
247 |
+
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
|
248 |
+
<p class="submit">
|
249 |
+
<input name="upload_file" type="file" />
|
250 |
+
<?php submit_button( __('Import XML', 'wpsm-plugin'), 'primary', 'wpsm-import-table', false ); echo ' '; ?>
|
251 |
+
<?php submit_button( __('Import CSV', 'wpsm-plugin'), 'primary', 'wpsm-import-csv', false ); echo ' '; ?>
|
252 |
+
<select id="wpsm-delimiter" name="csv_delimiter" class="wpsm-select-delimiter">
|
253 |
+
<option value=","><?php _e('"," (comma)', 'wpsm-tableplugin') ;?></option>
|
254 |
+
<option value=";"><?php _e('";" (semi-colon)', 'wpsm-tableplugin') ;?></option>
|
255 |
+
</select>
|
256 |
+
</p>
|
257 |
+
</form>
|
258 |
+
<?php endif; ?>
|
259 |
+
|
260 |
+
<div id="wpsm-comptable-resize-dialog" class="wpsm-dialog" title="<?php _e('Change Table Size', 'wpsm-tableplugin') ?>">
|
261 |
+
<div class="wpsm-dialog-error"></div>
|
262 |
+
<?php _e('Cols', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-col-count" />
|
263 |
+
<?php _e('Rows', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-row-count" />
|
264 |
+
<?php _e('Sub-header Rows (e.g.1,3,6)', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-sub-array" />
|
265 |
+
<button class="button button-primary"><?php _e('Apply', 'wpsm-tableplugin') ?></button>
|
266 |
+
</div>
|
267 |
+
|
268 |
+
<div id="wpsm-row-switcher-dialog" class="wpsm-dialog" title="Switch Rows">
|
269 |
+
<div class="wpsm-dialog-error"></div>
|
270 |
+
<?php _e('Row 1', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-row1" />
|
271 |
+
<?php _e('Row 2', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-row2" />
|
272 |
+
<button class="button button-primary"><?php _e('Switch', 'wpsm-tableplugin') ?></button>
|
273 |
+
</div>
|
274 |
+
|
275 |
+
<div id="wpsm-col-switcher-dialog" class="wpsm-dialog" title="Switch Columns">
|
276 |
+
<div class="wpsm-dialog-error"></div>
|
277 |
+
<?php _e('Col 1', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-col1" />
|
278 |
+
<?php _e('Col 2', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-col2" />
|
279 |
+
<button class="button button-primary"><?php _e('Switch', 'wpsm-tableplugin') ?></button>
|
280 |
+
</div>
|
281 |
+
|
282 |
+
<div id="wpsm-comptable-addnew-dialog" class="wpsm-dialog" title="<?php _e('Add Empty Row/Column', 'wpsm-tableplugin') ?>">
|
283 |
+
<div class="wpsm-dialog-error"></div>
|
284 |
+
<?php _e('Add empty col after (number)', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-col-after" />
|
285 |
+
<?php _e('Add empty row after (number)', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-row-after" />
|
286 |
+
<button class="button button-primary"><?php _e('Apply', 'wpsm-tableplugin') ?></button>
|
287 |
+
</div>
|
288 |
+
|
289 |
+
<div id="wpsm-comptable-remove-dialog" class="wpsm-dialog" title="<?php _e('Delete Row/Column', 'wpsm-tableplugin') ?>">
|
290 |
+
<div class="wpsm-dialog-error"></div>
|
291 |
+
<?php _e('Remove col (number)', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-col-remove" />
|
292 |
+
<?php _e('Remove row (number)', 'wpsm-tableplugin') ?>: <input type="text" class="wpsm-row-remove" />
|
293 |
+
<button class="button button-primary"><?php _e('Apply', 'wpsm-tableplugin') ?></button>
|
294 |
+
</div>
|
295 |
+
|
296 |
+
<?php
|
297 |
+
}
|
298 |
+
|
299 |
+
private function is_plugin_page() {
|
300 |
+
if( !is_admin() || !isset($_GET['page']) || $this->page_slug != $_GET['page'] || (!isset($_GET['action']) && !isset($_GET['action2'])) )
|
301 |
+
return false;
|
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 ){
|
416 |
+
|
417 |
+
$atts = shortcode_atts(
|
418 |
+
array(
|
419 |
+
'id' => false,
|
420 |
+
'color' => '',
|
421 |
+
'class' => ''
|
422 |
+
), $atts );
|
423 |
+
|
424 |
+
if(!$atts['id']){
|
425 |
+
_e("Please specify the table ID", 'wpsm-tableplugin');
|
426 |
+
return;
|
427 |
+
}
|
428 |
+
|
429 |
+
$table = $this->db->get($atts['id']);
|
430 |
+
if(!$table)
|
431 |
+
return;
|
432 |
+
|
433 |
+
ob_start();
|
434 |
+
wp_enqueue_script('table-maker-front');
|
435 |
+
wp_enqueue_script('jquery-columnhover');
|
436 |
+
?>
|
437 |
+
<?php if($table['responsive']) wp_enqueue_script('jquery-stacktable'); ?>
|
438 |
+
<div class="wpsm-comptable-wrap">
|
439 |
+
<table id="wpsm-table-<?php echo $atts['id'];?>" class="wpsm-comptable<?php echo ' '. $atts['class'].'' ; ?><?php if($table['responsive'] == 1) echo ' wpsm-comptable-responsive'; elseif($table['responsive'] == 2) echo ' wpsmt-column-stack'; ?>">
|
440 |
+
<?php $change_color = ($atts['color']) ? $atts['color'] : $table['color'] ; ?>
|
441 |
+
<thead class="wpsm-thead<?php echo ' wpsm-thead-'. $change_color; ?>">
|
442 |
+
<tr>
|
443 |
+
<?php for ($j=1; $j <= $table['cols']; $j++): ?>
|
444 |
+
<?php if ($j==1 && empty($table['tvalues'][0][1])) :?>
|
445 |
+
<th class="placeholder wpsm-placeholder"></th>
|
446 |
+
<?php else :?>
|
447 |
+
<th><?php echo $this->replace_placeholders($table['tvalues'][0][$j]); ?></th>
|
448 |
+
<?php endif;?>
|
449 |
+
|
450 |
+
<?php endfor; ?>
|
451 |
+
</tr>
|
452 |
+
</thead>
|
453 |
+
<tbody class="wpsm-tbody">
|
454 |
+
<?php for($i=1; $i <= $table['rows']; $i++): ?>
|
455 |
+
<?php $sub_array = explode(',', $table['subs']); ?>
|
456 |
+
<?php echo in_array($i, $sub_array) ? '<tr class="subheader">' : '<tr>'; ?>
|
457 |
+
<?php for ($j=1; $j <= $table['cols']; $j++): ?>
|
458 |
+
<?php echo in_array($i, $sub_array) ? '<td colspan="'.$table['cols'].'">' : '<td>'; ?>
|
459 |
+
<?php if (!empty ($table['tvalues'][$i][$j])):?>
|
460 |
+
<?php $table_cell_echo = $this->replace_placeholders($table['tvalues'][$i][$j]); ?>
|
461 |
+
<?php echo do_shortcode($table_cell_echo); ?>
|
462 |
+
<?php endif;?>
|
463 |
+
</td>
|
464 |
+
<?php if(in_array($i, $sub_array)) break; ?>
|
465 |
+
<?php endfor; ?>
|
466 |
+
</tr>
|
467 |
+
<?php endfor; ?>
|
468 |
+
</tbody>
|
469 |
+
</table>
|
470 |
+
</div>
|
471 |
+
<?php
|
472 |
+
return ob_get_clean();
|
473 |
+
}
|
474 |
+
|
475 |
+
public function replace_placeholders($str){
|
476 |
+
$values = array();
|
477 |
+
$values['tick'] = '<i class="wpsm-table-icon wpsm-icon-tick"></i>';
|
478 |
+
$values['cross'] = '<i class="wpsm-table-icon wpsm-icon-cross"></i>';
|
479 |
+
$values['info'] = '<i class="wpsm-table-icon wpsm-icon-info"></i>';
|
480 |
+
$values['warning'] = '<i class="wpsm-table-icon wpsm-icon-warning"></i>';
|
481 |
+
$values['heart'] = '<i class="wpsm-table-icon wpsm-icon-heart"></i>';
|
482 |
+
$values['lock'] = '<i class="wpsm-table-icon wpsm-icon-lock"></i>';
|
483 |
+
$values['star'] = '<i class="wpsm-table-icon wpsm-icon-star"></i>';
|
484 |
+
$values['star-empty'] = '<i class="wpsm-table-icon wpsm-icon-star-empty"></i>';
|
485 |
+
$values['col-choice'] = '<span class="badge_div_col"></span>';
|
486 |
+
$values['col-choice-image'] = '<span class="badge_div_col badge_div_col_img"></span>';
|
487 |
+
$values['row-choice'] = '<span class="badge_div_row"></span>';
|
488 |
+
$values['row-choice-image'] = '<span class="badge_div_row badge_div_col_img"></span>';
|
489 |
+
|
490 |
+
foreach ($values as $key => $value) {
|
491 |
+
$str = str_replace('%'.strtoupper($key).'%', $value, $str);
|
492 |
+
}
|
493 |
+
return $str;
|
494 |
+
}
|
495 |
+
|
496 |
+
public function initialize()
|
497 |
+
{
|
498 |
+
$this->db->create_table();
|
499 |
+
}
|
500 |
+
|
501 |
+
public function rollback()
|
502 |
+
{
|
503 |
+
$table = WPSM_DB_Table::get_instance();
|
504 |
+
$table->drop_table();
|
505 |
+
}
|
506 |
}
|
inc/class-wpsm-table-xml.php
CHANGED
@@ -1,82 +1,103 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if ( ! defined( 'WPINC' ) ) {
|
4 |
-
die;
|
5 |
-
}
|
6 |
-
|
7 |
-
class Array_XML {
|
8 |
-
|
9 |
-
private $writer;
|
10 |
-
private $version = '1.0';
|
11 |
-
private $encoding = 'UTF-8';
|
12 |
-
private $rootName = 'wpsm';
|
13 |
-
|
14 |
-
function __construct() {
|
15 |
-
$this->writer = new XMLWriter();
|
16 |
-
}
|
17 |
-
|
18 |
-
public function convert($data) {
|
19 |
-
$this->writer->openMemory();
|
20 |
-
$this->writer->startDocument($this->version, $this->encoding);
|
21 |
-
$this->writer->startElement($this->rootName);
|
22 |
-
if (is_array($data)) {
|
23 |
-
$this->getXML($data);
|
24 |
-
}
|
25 |
-
$this->writer->endElement();
|
26 |
-
return $this->writer->outputMemory();
|
27 |
-
}
|
28 |
-
|
29 |
-
public function setVersion($version) {
|
30 |
-
$this->version = $version;
|
31 |
-
}
|
32 |
-
|
33 |
-
public function setEncoding($encoding) {
|
34 |
-
$this->encoding = $encoding;
|
35 |
-
}
|
36 |
-
|
37 |
-
public function setRootName($rootName) {
|
38 |
-
$this->rootName = $rootName;
|
39 |
-
}
|
40 |
-
|
41 |
-
private function getXML($data) {
|
42 |
-
foreach ($data as $key => $val) {
|
43 |
-
if (!is_array($val) && $val == '') {
|
44 |
-
continue;
|
45 |
-
} else {
|
46 |
-
if (is_numeric($key)) {
|
47 |
-
$key = 'key'.$key;
|
48 |
-
}
|
49 |
-
if (is_array($val)) {
|
50 |
-
$this->writer->startElement($key);
|
51 |
-
$this->getXML($val);
|
52 |
-
$this->writer->endElement();
|
53 |
-
}
|
54 |
-
else {
|
55 |
-
$this->writer->writeElement($key, $val);
|
56 |
-
}
|
57 |
-
}
|
58 |
-
}
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
function xml2array($xml) {
|
63 |
-
$json = json_encode($xml);
|
64 |
-
$array = json_decode($json,TRUE);
|
65 |
-
$tvalues = $array['tvalues'];
|
66 |
-
|
67 |
-
foreach($tvalues as $_key0=>$_v0) {
|
68 |
-
$key1 = str_ireplace('key', '', $_key0);
|
69 |
-
|
70 |
-
foreach($_v0 as $_key1=>$_val) {
|
71 |
-
$key2 = str_ireplace('key', '', $_key1);
|
72 |
-
$_v[$key1][$key2] = $_val;
|
73 |
-
}
|
74 |
-
}
|
75 |
-
$array['tvalues'] = $_v;
|
76 |
-
unset($_key0, $_v0, $_key, $_key1, $_val, $_v);
|
77 |
-
|
78 |
-
if(isset($array['id']) ) {
|
79 |
-
unset( $array['id'] );
|
80 |
-
}
|
81 |
-
return $array;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if ( ! defined( 'WPINC' ) ) {
|
4 |
+
die;
|
5 |
+
}
|
6 |
+
|
7 |
+
class Array_XML {
|
8 |
+
|
9 |
+
private $writer;
|
10 |
+
private $version = '1.0';
|
11 |
+
private $encoding = 'UTF-8';
|
12 |
+
private $rootName = 'wpsm';
|
13 |
+
|
14 |
+
function __construct() {
|
15 |
+
$this->writer = new XMLWriter();
|
16 |
+
}
|
17 |
+
|
18 |
+
public function convert($data) {
|
19 |
+
$this->writer->openMemory();
|
20 |
+
$this->writer->startDocument($this->version, $this->encoding);
|
21 |
+
$this->writer->startElement($this->rootName);
|
22 |
+
if (is_array($data)) {
|
23 |
+
$this->getXML($data);
|
24 |
+
}
|
25 |
+
$this->writer->endElement();
|
26 |
+
return $this->writer->outputMemory();
|
27 |
+
}
|
28 |
+
|
29 |
+
public function setVersion($version) {
|
30 |
+
$this->version = $version;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function setEncoding($encoding) {
|
34 |
+
$this->encoding = $encoding;
|
35 |
+
}
|
36 |
+
|
37 |
+
public function setRootName($rootName) {
|
38 |
+
$this->rootName = $rootName;
|
39 |
+
}
|
40 |
+
|
41 |
+
private function getXML($data) {
|
42 |
+
foreach ($data as $key => $val) {
|
43 |
+
if (!is_array($val) && $val == '') {
|
44 |
+
continue;
|
45 |
+
} else {
|
46 |
+
if (is_numeric($key)) {
|
47 |
+
$key = 'key'.$key;
|
48 |
+
}
|
49 |
+
if (is_array($val)) {
|
50 |
+
$this->writer->startElement($key);
|
51 |
+
$this->getXML($val);
|
52 |
+
$this->writer->endElement();
|
53 |
+
}
|
54 |
+
else {
|
55 |
+
$this->writer->writeElement($key, $val);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
function xml2array($xml) {
|
63 |
+
$json = json_encode($xml);
|
64 |
+
$array = json_decode($json,TRUE);
|
65 |
+
$tvalues = $array['tvalues'];
|
66 |
+
|
67 |
+
foreach($tvalues as $_key0=>$_v0) {
|
68 |
+
$key1 = str_ireplace('key', '', $_key0);
|
69 |
+
|
70 |
+
foreach($_v0 as $_key1=>$_val) {
|
71 |
+
$key2 = str_ireplace('key', '', $_key1);
|
72 |
+
$_v[$key1][$key2] = $_val;
|
73 |
+
}
|
74 |
+
}
|
75 |
+
$array['tvalues'] = $_v;
|
76 |
+
unset($_key0, $_v0, $_key, $_key1, $_val, $_v);
|
77 |
+
|
78 |
+
if(isset($array['id']) ) {
|
79 |
+
unset( $array['id'] );
|
80 |
+
}
|
81 |
+
return $array;
|
82 |
+
}
|
83 |
+
|
84 |
+
function csv2array($handle, $delimiter) {
|
85 |
+
|
86 |
+
$row = 0;
|
87 |
+
while (($line_array = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
|
88 |
+
$cols = count($line_array);
|
89 |
+
for ($j=0; $j<$cols; $j++) {
|
90 |
+
$col = $j + 1;
|
91 |
+
if (!is_array($line_array[$j]) && $line_array[$j] == '') {
|
92 |
+
continue;
|
93 |
+
} else {
|
94 |
+
$table_array[$row][$col] = $line_array[$j];
|
95 |
+
}
|
96 |
+
}
|
97 |
+
$row++;
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
$rows = $row - 1;
|
102 |
+
return $data = array( 'rows' => $rows, 'cols' => $cols, 'tvalues' => $table_array );
|
103 |
}
|
js/table-maker-front.js
CHANGED
@@ -1,35 +1,47 @@
|
|
1 |
-
jQuery(document).ready(function($) {
|
2 |
-
$('.wpsm-comptable').columnHover({eachCell:true, hoverClass:'betterhover', includeSpans:false}); // cross hover column and row
|
3 |
-
|
4 |
-
$('.wpsm-comptable').each(function(){
|
5 |
-
var badge_col = $(this).find('.badge_div_col').closest('td');
|
6 |
-
var selected_cols = badge_col.parent().children().index(badge_col) + 1;
|
7 |
-
$(this).find('tr > td:nth-child('+selected_cols+')').addClass('editor_selected_col');
|
8 |
-
$(this).find('tr > th:nth-child('+selected_cols+')').addClass('editor_selected_col');
|
9 |
-
|
10 |
-
var selected_rows = $(this).find('tr').index($('.badge_div_row').closest('tr'));
|
11 |
-
if (selected_rows != -1) {
|
12 |
-
$(this).find('tr:eq('+selected_rows+')').addClass('editor_selected_row');
|
13 |
-
//$(this).find('tr:eq('+selected_rows+')').prev().addClass('editor_prev_selected_row');
|
14 |
-
}
|
15 |
-
|
16 |
-
});
|
17 |
-
|
18 |
-
$('.wpsm-comptable-responsive').each(function(){
|
19 |
-
$(this).stacktable();
|
20 |
-
});
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
!function(e){var o=function(e){for(var o=e.rows,n=o.length,r=[],l=0;n>l;l++)for(var a=o[l].cells,t=a.length,s=0;t>s;s++){var i=a[s],c=i.rowSpan||1,h=i.colSpan||1,d=-1;r[l]||(r[l]=[]);for(var f=r[l];f[++d];);i.realIndex=d;for(var u=l;l+c>u;u++){r[u]||(r[u]=[]);for(var v=r[u],C=d;d+h>C;C++)v[C]=1}}};e.fn.columnHover=function(n){var r=e.extend({hoverClass:"hover",eachCell:!1,includeSpans:!0,ignoreCols:[]},n),l=function(o,n,l){var a=n[o.realIndex],t=0;if(-1==e(r.ignoreCols).index(o.realIndex+1)){for(;++t<o.colSpan;)a=a.concat(n[o.realIndex+t]);l?e(a).addClass(r.hoverClass):e(a).removeClass(r.hoverClass)}},a=function(e,o){e.bind("mouseover",function(){l(this,o,!0)}).bind("mouseout",function(){l(this,o,!1)})};return this.each(function(){var n,l,t,s,i,c,h,d,f=[],u=this;if(u.tBodies&&u.tBodies.length&&u.tHead&&r.hoverClass.length){for(o(u),s=0;s<u.tBodies.length;s++)for(n=u.tBodies[s],i=0;i<n.rows.length;i++)for(l=n.rows[i],c=0;c<l.cells.length;c++)if(t=l.cells[c],r.includeSpans||!(t.colSpan>1)){for(d=r.includeSpans?t.colSpan:1;--d>=0;)h=t.realIndex+d,f[h]||(f[h]=[]),f[h].push(t);r.eachCell&&a(e(t),f)}a(e("td, th",u.tHead),f),r.eachCell&&u.tFoot&&a(e("td, th",u.tFoot),f)}})}}(jQuery);
|
1 |
+
jQuery(document).ready(function($) {
|
2 |
+
$('.wpsm-comptable').columnHover({eachCell:true, hoverClass:'betterhover', includeSpans:false}); // cross hover column and row
|
3 |
+
|
4 |
+
$('.wpsm-comptable').each(function(){
|
5 |
+
var badge_col = $(this).find('.badge_div_col').closest('td');
|
6 |
+
var selected_cols = badge_col.parent().children().index(badge_col) + 1;
|
7 |
+
$(this).find('tr > td:nth-child('+selected_cols+')').addClass('editor_selected_col');
|
8 |
+
$(this).find('tr > th:nth-child('+selected_cols+')').addClass('editor_selected_col');
|
9 |
+
|
10 |
+
var selected_rows = $(this).find('tr').index($('.badge_div_row').closest('tr'));
|
11 |
+
if (selected_rows != -1) {
|
12 |
+
$(this).find('tr:eq('+selected_rows+')').addClass('editor_selected_row');
|
13 |
+
//$(this).find('tr:eq('+selected_rows+')').prev().addClass('editor_prev_selected_row');
|
14 |
+
}
|
15 |
+
|
16 |
+
});
|
17 |
+
|
18 |
+
$('.wpsm-comptable-responsive').each(function(){
|
19 |
+
$(this).stacktable();
|
20 |
+
});
|
21 |
+
|
22 |
+
$('.wpsmt-column-stack').each(function(){
|
23 |
+
$(this).stackcolumns({myClass:'wpsmt-column-stack-mobile'});
|
24 |
+
});
|
25 |
+
|
26 |
+
$('.wpsmt-column-stack-mobile').each(function(){
|
27 |
+
$(this).addClass('wpsm-comptable');
|
28 |
+
var tdfix = $(this).find('td.st-key[colspan]');
|
29 |
+
tdfix.attr('colspan', '2');
|
30 |
+
tdfix.addClass('wpsm-spec-heading');
|
31 |
+
tdfix.next('td').remove();
|
32 |
+
});
|
33 |
+
|
34 |
+
});
|
35 |
+
/*
|
36 |
+
* jQuery columnHover plugin
|
37 |
+
* Version: 0.1.1
|
38 |
+
*
|
39 |
+
* Copyright (c) 2007 Roman Weich
|
40 |
+
* http://p.sohei.org
|
41 |
+
*
|
42 |
+
* Dual licensed under the MIT and GPL licenses
|
43 |
+
* (This means that you can choose the license that best suits your project, and use it accordingly):
|
44 |
+
* http://www.opensource.org/licenses/mit-license.php
|
45 |
+
* http://www.gnu.org/licenses/gpl.html
|
46 |
+
*/
|
47 |
!function(e){var o=function(e){for(var o=e.rows,n=o.length,r=[],l=0;n>l;l++)for(var a=o[l].cells,t=a.length,s=0;t>s;s++){var i=a[s],c=i.rowSpan||1,h=i.colSpan||1,d=-1;r[l]||(r[l]=[]);for(var f=r[l];f[++d];);i.realIndex=d;for(var u=l;l+c>u;u++){r[u]||(r[u]=[]);for(var v=r[u],C=d;d+h>C;C++)v[C]=1}}};e.fn.columnHover=function(n){var r=e.extend({hoverClass:"hover",eachCell:!1,includeSpans:!0,ignoreCols:[]},n),l=function(o,n,l){var a=n[o.realIndex],t=0;if(-1==e(r.ignoreCols).index(o.realIndex+1)){for(;++t<o.colSpan;)a=a.concat(n[o.realIndex+t]);l?e(a).addClass(r.hoverClass):e(a).removeClass(r.hoverClass)}},a=function(e,o){e.bind("mouseover",function(){l(this,o,!0)}).bind("mouseout",function(){l(this,o,!1)})};return this.each(function(){var n,l,t,s,i,c,h,d,f=[],u=this;if(u.tBodies&&u.tBodies.length&&u.tHead&&r.hoverClass.length){for(o(u),s=0;s<u.tBodies.length;s++)for(n=u.tBodies[s],i=0;i<n.rows.length;i++)for(l=n.rows[i],c=0;c<l.cells.length;c++)if(t=l.cells[c],r.includeSpans||!(t.colSpan>1)){for(d=r.includeSpans?t.colSpan:1;--d>=0;)h=t.realIndex+d,f[h]||(f[h]=[]),f[h].push(t);r.eachCell&&a(e(t),f)}a(e("td, th",u.tHead),f),r.eachCell&&u.tFoot&&a(e("td, th",u.tFoot),f)}})}}(jQuery);
|
js/table-maker.js
CHANGED
@@ -1,484 +1,484 @@
|
|
1 |
-
jQuery(document).ready(function ($) {
|
2 |
-
var field_name_prefix = 'table_values';
|
3 |
-
|
4 |
-
function get_effective(curr, index) {
|
5 |
-
if(!index)
|
6 |
-
return curr;
|
7 |
-
|
8 |
-
if(curr == index[0])
|
9 |
-
return index[1];
|
10 |
-
else if(curr == index[1])
|
11 |
-
return index[0];
|
12 |
-
else
|
13 |
-
return curr;
|
14 |
-
}
|
15 |
-
|
16 |
-
function get_curr_row_count(){
|
17 |
-
return parseInt($('.wpsm-rows').val());
|
18 |
-
}
|
19 |
-
|
20 |
-
function get_curr_col_count(){
|
21 |
-
return parseInt($('.wpsm-cols').val());
|
22 |
-
}
|
23 |
-
|
24 |
-
function get_curr_sub_array(){
|
25 |
-
return $('.wpsm-subs').val();
|
26 |
-
}
|
27 |
-
|
28 |
-
function is_valid_num(x){
|
29 |
-
if(parseInt(x) == x && x > 0)
|
30 |
-
return true;
|
31 |
-
return false;
|
32 |
-
}
|
33 |
-
|
34 |
-
function is_valid_row(x){
|
35 |
-
if(is_valid_num(x) && parseInt(x) <= get_curr_row_count())
|
36 |
-
return true;
|
37 |
-
return false;
|
38 |
-
}
|
39 |
-
|
40 |
-
function is_valid_col(x){
|
41 |
-
if(is_valid_num(x) && parseInt(x) <= get_curr_col_count())
|
42 |
-
return true;
|
43 |
-
return false;
|
44 |
-
}
|
45 |
-
|
46 |
-
function in_array(value, array) {
|
47 |
-
for(var i=0; i<array.length; i++){
|
48 |
-
if(value == array[i]) return true;
|
49 |
-
}
|
50 |
-
return false;
|
51 |
-
}
|
52 |
-
|
53 |
-
function rebuildTable(switch_rows, switch_cols){
|
54 |
-
switch_rows = (typeof switch_rows !== 'undefined') ? switch_rows : false;
|
55 |
-
switch_cols = (typeof switch_cols !== 'undefined') ? switch_cols : false;
|
56 |
-
var row_count = $('.wpsm-rows').val();
|
57 |
-
var col_count = $('.wpsm-cols').val();
|
58 |
-
var sub_array = $('.wpsm-subs').val();
|
59 |
-
sub_array = sub_array.split( ',' );
|
60 |
-
|
61 |
-
var table = $('.wpsm-comptable');
|
62 |
-
var effective_row, effective_col;
|
63 |
-
|
64 |
-
var table_html = '<thead><tr>';
|
65 |
-
for(var i = 1; i <= col_count; i++){
|
66 |
-
effective_col = get_effective(i, switch_cols);
|
67 |
-
var selector = 'input[name="'+field_name_prefix+'[0]['+effective_col+']"]';
|
68 |
-
var curr_val = ( $(selector).val() ) ? $(selector).val() : '';
|
69 |
-
table_html += '<th><input name="'+field_name_prefix+'[0]['+i+']" value="'+curr_val+'" placeholder="'+wpsm_js_strings.placeholder+'" /></th>';
|
70 |
-
}
|
71 |
-
table_html += '</tr></thead><tbody>';
|
72 |
-
|
73 |
-
for(var i = 1; i <= row_count; i++){
|
74 |
-
|
75 |
-
table_html += in_array(i, sub_array) ? '<tr class="subheader">' : '<tr>';
|
76 |
-
|
77 |
-
for(var j = 1; j <= col_count; j++){
|
78 |
-
|
79 |
-
effective_row = get_effective(i, switch_rows);
|
80 |
-
effective_col = get_effective(j, switch_cols);
|
81 |
-
|
82 |
-
var selector = 'textarea[name="'+field_name_prefix+'['+effective_row+']['+effective_col+']"]';
|
83 |
-
var curr_val = ( $(selector).val() ) ? $(selector).val() : '';
|
84 |
-
var col_span = col_count;
|
85 |
-
|
86 |
-
table_html += in_array(i, sub_array) ? '<td colspan="'+col_span+'">' : '<td>';
|
87 |
-
if (j == 1) {
|
88 |
-
table_html += '<span class="num_row_wpsm_table">'+i+'</span>';
|
89 |
-
}
|
90 |
-
table_html += '<textarea name="'+field_name_prefix+'['+i+']['+j+']" placeholder="'+wpsm_js_strings.placeholder+'">'+curr_val+'</textarea></td>';
|
91 |
-
if(in_array(i, sub_array)) break;
|
92 |
-
}
|
93 |
-
table_html += '</tr>';
|
94 |
-
|
95 |
-
}
|
96 |
-
table_html += '</tbody>';
|
97 |
-
table.html(table_html);
|
98 |
-
}
|
99 |
-
|
100 |
-
//Table resize dialog
|
101 |
-
|
102 |
-
$('#wpsm-comptable-resize-btn').click(function(e) {
|
103 |
-
$( "#wpsm-comptable-resize-dialog" ).dialog({
|
104 |
-
modal:true,
|
105 |
-
draggable: false,
|
106 |
-
open: function(e, ui) {
|
107 |
-
$(this).children('.wpsm-row-count').val(get_curr_row_count());
|
108 |
-
$(this).children('.wpsm-col-count').val(get_curr_col_count());
|
109 |
-
$(this).children('.wpsm-sub-array').val(get_curr_sub_array());
|
110 |
-
$(this).children('.wpsm-dialog-error').hide();
|
111 |
-
}
|
112 |
-
});
|
113 |
-
});
|
114 |
-
|
115 |
-
$('#wpsm-comptable-resize-dialog button').click(function(e) {
|
116 |
-
var row_count = $(this).siblings('.wpsm-row-count').val();
|
117 |
-
var col_count = $(this).siblings('.wpsm-col-count').val();
|
118 |
-
var sub_array = $(this).siblings('.wpsm-sub-array').val();
|
119 |
-
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
120 |
-
if(is_valid_num(row_count) && is_valid_num(col_count)){
|
121 |
-
error_cont.hide();
|
122 |
-
$('.wpsm-rows').val(row_count);
|
123 |
-
$('.wpsm-cols').val(col_count);
|
124 |
-
$('.wpsm-subs').val(sub_array);
|
125 |
-
rebuildTable();
|
126 |
-
$('#wpsm-comptable-resize-dialog').dialog("close");
|
127 |
-
}
|
128 |
-
else{
|
129 |
-
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
130 |
-
}
|
131 |
-
});
|
132 |
-
|
133 |
-
//Switch Rows Dialog
|
134 |
-
|
135 |
-
$('#wpsm-row-switcher-btn').click(function(e) {
|
136 |
-
$( "#wpsm-row-switcher-dialog" ).dialog({
|
137 |
-
modal:true,
|
138 |
-
draggable: false,
|
139 |
-
open: function(e, ui) {
|
140 |
-
$(this).children('input[type="text"]').val('');
|
141 |
-
$(this).children('.wpsm-dialog-error').hide();
|
142 |
-
}
|
143 |
-
});
|
144 |
-
});
|
145 |
-
|
146 |
-
$( "#wpsm-row-switcher-dialog button" ).click(function(e) {
|
147 |
-
var row_1 = $(this).siblings('.wpsm-row1').val();
|
148 |
-
var row_2 = $(this).siblings('.wpsm-row2').val();
|
149 |
-
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
150 |
-
if(is_valid_row(row_1) && is_valid_row(row_2)){
|
151 |
-
error_cont.hide();
|
152 |
-
rebuildTable([row_1, row_2], false);
|
153 |
-
$( "#wpsm-row-switcher-dialog" ).dialog("close");
|
154 |
-
}
|
155 |
-
else{
|
156 |
-
error_cont.html(wpsm_js_strings.switch_error + ' ' + get_curr_row_count()).show().effect( "bounce" );
|
157 |
-
}
|
158 |
-
});
|
159 |
-
|
160 |
-
//Switch Cols Dialog
|
161 |
-
|
162 |
-
$('#wpsm-col-switcher-btn').click(function(e) {
|
163 |
-
$( "#wpsm-col-switcher-dialog" ).dialog({
|
164 |
-
modal:true,
|
165 |
-
draggable: false,
|
166 |
-
open: function(e, ui) {
|
167 |
-
$(this).children('input[type="text"]').val('');
|
168 |
-
$(this).children('.wpsm-dialog-error').hide();
|
169 |
-
}
|
170 |
-
});
|
171 |
-
});
|
172 |
-
|
173 |
-
$( "#wpsm-col-switcher-dialog button" ).click(function(e) {
|
174 |
-
var col_1 = $(this).siblings('.wpsm-col1').val();
|
175 |
-
var col_2 = $(this).siblings('.wpsm-col2').val();
|
176 |
-
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
177 |
-
if(is_valid_col(col_1) && is_valid_col(col_2)){
|
178 |
-
error_cont.hide();
|
179 |
-
rebuildTable(false, [col_1, col_2]);
|
180 |
-
$( "#wpsm-col-switcher-dialog" ).dialog("close");
|
181 |
-
}
|
182 |
-
else{
|
183 |
-
error_cont.html(wpsm_js_strings.switch_error + ' ' + get_curr_col_count()).show().effect( "bounce" );
|
184 |
-
}
|
185 |
-
});
|
186 |
-
|
187 |
-
//Table add empty dialog
|
188 |
-
|
189 |
-
$('#wpsm-comptable-addnew-btn').click(function(e) {
|
190 |
-
$( "#wpsm-comptable-addnew-dialog" ).dialog({
|
191 |
-
modal:true,
|
192 |
-
draggable: false,
|
193 |
-
open: function(e, ui) {
|
194 |
-
$(this).children('input[type="text"]').val('');
|
195 |
-
$(this).children('.wpsm-dialog-error').hide();
|
196 |
-
}
|
197 |
-
});
|
198 |
-
});
|
199 |
-
|
200 |
-
$('#wpsm-comptable-addnew-dialog button').click(function(e) {
|
201 |
-
var row_after = $(this).siblings('.wpsm-row-after').val();
|
202 |
-
var col_after = $(this).siblings('.wpsm-col-after').val();
|
203 |
-
var col_count = get_curr_col_count();
|
204 |
-
var row_count = get_curr_row_count();
|
205 |
-
var sub_array = $('.wpsm-subs').val();
|
206 |
-
sub_array = sub_array.split( ',' );
|
207 |
-
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
208 |
-
|
209 |
-
if(is_valid_col(col_after) || is_valid_row(row_after)){
|
210 |
-
error_cont.hide();
|
211 |
-
|
212 |
-
if (row_after && col_after) {
|
213 |
-
error_cont.html(wpsm_js_strings.only_one).show().effect( "bounce" );
|
214 |
-
return;
|
215 |
-
}
|
216 |
-
|
217 |
-
if (row_after) {
|
218 |
-
if (row_after < row_count) {
|
219 |
-
// Increment indexes of all rows after row_after
|
220 |
-
var row_index = row_insert_index = parseInt(row_after) + 1;
|
221 |
-
for(row_index; row_index <= row_count; row_index++){
|
222 |
-
var row_tr_index = $('.wpsm-comptable tr:eq('+row_index+') textarea');
|
223 |
-
row_increment = parseInt(row_index) + 1;
|
224 |
-
row_tr_index.each(function(i){
|
225 |
-
i++;
|
226 |
-
$(this).attr('name', field_name_prefix+'['+row_increment+']['+i+']');
|
227 |
-
});
|
228 |
-
}
|
229 |
-
// Add empty row
|
230 |
-
table_html = '<tr>';
|
231 |
-
for(var j = 1; j <= col_count; j++){
|
232 |
-
table_html += '<td><textarea name="'+field_name_prefix+'['+row_insert_index+']['+j+']" placeholder="'+wpsm_js_strings.placeholder+'"></textarea></td>';
|
233 |
-
}
|
234 |
-
table_html += '</tr>';
|
235 |
-
$('.wpsm-comptable tr:eq('+row_insert_index+')').before(table_html);
|
236 |
-
// Increment hidden input value
|
237 |
-
$('.wpsm-rows').val(row_count + 1);
|
238 |
-
// Rebuild sub headers
|
239 |
-
var subheaderarray = [];
|
240 |
-
$.each(sub_array, function(index, value) {
|
241 |
-
if (parseInt(value) >= row_insert_index) {
|
242 |
-
subheaderarray.push(parseInt(value) + 1);
|
243 |
-
}
|
244 |
-
else {
|
245 |
-
subheaderarray.push(parseInt(value));
|
246 |
-
}
|
247 |
-
});
|
248 |
-
subheaderarray = subheaderarray.join(',');
|
249 |
-
$('.wpsm-subs').val(subheaderarray);
|
250 |
-
// Close popup
|
251 |
-
$('#wpsm-comptable-addnew-dialog').dialog("close");
|
252 |
-
// Rebuild values
|
253 |
-
$('.num_row_wpsm_table').remove();
|
254 |
-
for (var num_index = 1; num_index <= row_count+1; num_index++) {
|
255 |
-
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
256 |
-
}
|
257 |
-
|
258 |
-
}
|
259 |
-
else{
|
260 |
-
error_cont.html(wpsm_js_strings.insert_error_row).show().effect( "bounce" );
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
-
if (col_after) {
|
265 |
-
if (col_after < col_count) {
|
266 |
-
for(var j = 1; j <= row_count; j++){
|
267 |
-
// Increment indexes of all cols after col_after
|
268 |
-
var col_index = col_insert_index = parseInt(col_after) + 1;
|
269 |
-
for(col_index; col_index <= col_count; col_index++){
|
270 |
-
var col_td_index = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_index+') textarea');
|
271 |
-
col_increment = parseInt(col_index) + 1;
|
272 |
-
col_td_index.each(function(){
|
273 |
-
$(this).attr('name', field_name_prefix+'['+j+']['+col_increment+']');
|
274 |
-
});
|
275 |
-
$('.wpsm-comptable tr > th:nth-child('+col_index+') input').attr('name', field_name_prefix+'[0]['+col_increment+']');
|
276 |
-
}
|
277 |
-
|
278 |
-
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_insert_index+')');
|
279 |
-
table_html = '<td><textarea name="'+field_name_prefix+'['+j+']['+col_insert_index+']" placeholder="'+wpsm_js_strings.placeholder+'"></textarea></td>';
|
280 |
-
col_td_foreach.before(table_html);
|
281 |
-
|
282 |
-
}
|
283 |
-
// Add empty col
|
284 |
-
$('.wpsm-comptable tr > th:nth-child('+col_insert_index+')').before('<th><input name="'+field_name_prefix+'[0]['+col_insert_index+']" value="" placeholder="'+wpsm_js_strings.placeholder+'" /></th>');
|
285 |
-
|
286 |
-
// Increment hidden input value and close
|
287 |
-
$('.wpsm-cols').val(col_count + 1);
|
288 |
-
$('#wpsm-comptable-addnew-dialog').dialog("close");
|
289 |
-
$('.wpsm-comptable tr.subheader').each(function(){
|
290 |
-
$(this).find('td').attr('colspan', col_count + 1)
|
291 |
-
});
|
292 |
-
}
|
293 |
-
else{
|
294 |
-
error_cont.html(wpsm_js_strings.insert_error_col).show().effect( "bounce" );
|
295 |
-
}
|
296 |
-
}
|
297 |
-
|
298 |
-
}
|
299 |
-
else{
|
300 |
-
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
301 |
-
}
|
302 |
-
});
|
303 |
-
|
304 |
-
|
305 |
-
//Table remove dialog
|
306 |
-
|
307 |
-
$('#wpsm-comptable-remove-btn').click(function(e) {
|
308 |
-
$( "#wpsm-comptable-remove-dialog" ).dialog({
|
309 |
-
modal:true,
|
310 |
-
draggable: false,
|
311 |
-
open: function(e, ui) {
|
312 |
-
$(this).children('input[type="text"]').val('');
|
313 |
-
$(this).children('.wpsm-dialog-error').hide();
|
314 |
-
}
|
315 |
-
});
|
316 |
-
});
|
317 |
-
|
318 |
-
$('#wpsm-comptable-remove-dialog button').click(function(e) {
|
319 |
-
var row_remove = $(this).siblings('.wpsm-row-remove').val();
|
320 |
-
var col_remove = $(this).siblings('.wpsm-col-remove').val();
|
321 |
-
var col_count = get_curr_col_count();
|
322 |
-
var row_count = get_curr_row_count();
|
323 |
-
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
324 |
-
var sub_array = $('.wpsm-subs').val();
|
325 |
-
sub_array = sub_array.split( ',' );
|
326 |
-
|
327 |
-
if(is_valid_col(col_remove) || is_valid_row(row_remove)){
|
328 |
-
error_cont.hide();
|
329 |
-
|
330 |
-
if (row_remove && col_remove) {
|
331 |
-
error_cont.html(wpsm_js_strings.only_one).show().effect( "bounce" );
|
332 |
-
return;
|
333 |
-
}
|
334 |
-
|
335 |
-
if (row_remove) {
|
336 |
-
if (row_remove < row_count) {
|
337 |
-
// Reduce indexes of all rows after row_remove
|
338 |
-
var row_index = parseInt(row_remove) + 1;
|
339 |
-
var row_remove_index = parseInt(row_remove);
|
340 |
-
for(row_index; row_index <= row_count; row_index++){
|
341 |
-
var row_tr_index = $('.wpsm-comptable tr:eq('+row_index+') textarea');
|
342 |
-
row_reduce = parseInt(row_index) - 1;
|
343 |
-
row_tr_index.each(function(i){
|
344 |
-
i++;
|
345 |
-
$(this).attr('name', field_name_prefix+'['+row_reduce+']['+i+']');
|
346 |
-
});
|
347 |
-
}
|
348 |
-
// Remove row
|
349 |
-
$('.wpsm-comptable tr:eq('+row_remove_index+')').remove();
|
350 |
-
|
351 |
-
// Reduce hidden input value, recreate subheaders and close popup
|
352 |
-
$('.wpsm-rows').val(row_count - 1);
|
353 |
-
|
354 |
-
var subheaderarray = [];
|
355 |
-
$.each(sub_array, function(index, value) {
|
356 |
-
if (parseInt(value) > row_remove_index) {
|
357 |
-
subheaderarray.push(parseInt(value) - 1);
|
358 |
-
}
|
359 |
-
else if (parseInt(value) == row_remove_index) {
|
360 |
-
}
|
361 |
-
else {
|
362 |
-
subheaderarray.push(parseInt(value));
|
363 |
-
}
|
364 |
-
});
|
365 |
-
subheaderarray = subheaderarray.join(',');
|
366 |
-
$('.wpsm-subs').val(subheaderarray);
|
367 |
-
|
368 |
-
$('#wpsm-comptable-remove-dialog').dialog("close");
|
369 |
-
|
370 |
-
$('.num_row_wpsm_table').remove();
|
371 |
-
for (var num_index = 1; num_index <= row_count-1; num_index++) {
|
372 |
-
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
373 |
-
}
|
374 |
-
|
375 |
-
}
|
376 |
-
else{ //if removed row is last
|
377 |
-
var row_remove_index = parseInt(row_remove);
|
378 |
-
$('.wpsm-comptable tr:eq('+row_remove_index+')').remove();
|
379 |
-
$('.wpsm-rows').val(row_count - 1);
|
380 |
-
var subheaderarray = [];
|
381 |
-
$.each(sub_array, function(index, value) {
|
382 |
-
if (parseInt(value) > row_remove_index) {
|
383 |
-
subheaderarray.push(parseInt(value) - 1);
|
384 |
-
}
|
385 |
-
else if (parseInt(value) == row_remove_index) {
|
386 |
-
}
|
387 |
-
else {
|
388 |
-
subheaderarray.push(parseInt(value));
|
389 |
-
}
|
390 |
-
});
|
391 |
-
subheaderarray = subheaderarray.join(',');
|
392 |
-
$('.wpsm-subs').val(subheaderarray);
|
393 |
-
$('#wpsm-comptable-remove-dialog').dialog("close");
|
394 |
-
$('.num_row_wpsm_table').remove();
|
395 |
-
for (var num_index = 1; num_index <= row_count-1; num_index++) {
|
396 |
-
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
397 |
-
}
|
398 |
-
}
|
399 |
-
}
|
400 |
-
|
401 |
-
if (col_remove) {
|
402 |
-
if (col_remove < col_count) {
|
403 |
-
for(var j = 1; j <= row_count; j++){
|
404 |
-
// Reduce indexes of all cols after col_remove
|
405 |
-
var col_index = parseInt(col_remove) + 1;
|
406 |
-
var col_remove_index = parseInt(col_remove);
|
407 |
-
for(col_index; col_index <= col_count; col_index++){
|
408 |
-
var col_td_index = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_index+') textarea');
|
409 |
-
col_reduce = parseInt(col_index) - 1;
|
410 |
-
col_td_index.each(function(){
|
411 |
-
$(this).attr('name', field_name_prefix+'['+j+']['+col_reduce+']');
|
412 |
-
});
|
413 |
-
$('.wpsm-comptable tr > th:nth-child('+col_index+') input').attr('name', field_name_prefix+'[0]['+col_reduce+']');
|
414 |
-
}
|
415 |
-
|
416 |
-
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+'):not(.subheader) > td:nth-child('+col_remove_index+')');
|
417 |
-
col_td_foreach.remove();
|
418 |
-
|
419 |
-
}
|
420 |
-
// Remove col in header
|
421 |
-
$('.wpsm-comptable tr > th:nth-child('+col_remove_index+')').remove();
|
422 |
-
|
423 |
-
// Reduce hidden input value and close
|
424 |
-
$('.wpsm-cols').val(col_count - 1);
|
425 |
-
$('#wpsm-comptable-remove-dialog').dialog("close");
|
426 |
-
$('.wpsm-comptable tr.subheader').each(function(){
|
427 |
-
$(this).find('td').attr('colspan', col_count - 1)
|
428 |
-
});
|
429 |
-
$('.num_row_wpsm_table').remove();
|
430 |
-
for (var num_index = 1; num_index <= row_count; num_index++) {
|
431 |
-
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
432 |
-
}
|
433 |
-
}
|
434 |
-
else{
|
435 |
-
var col_remove_index = parseInt(col_remove);
|
436 |
-
for(var j = 1; j <= row_count; j++){
|
437 |
-
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+'):not(.subheader) > td:nth-child('+col_remove_index+')');
|
438 |
-
col_td_foreach.remove();
|
439 |
-
}
|
440 |
-
$('.wpsm-comptable tr > th:nth-child('+col_remove_index+')').remove();
|
441 |
-
$('.wpsm-cols').val(col_count - 1);
|
442 |
-
$('#wpsm-comptable-remove-dialog').dialog("close");
|
443 |
-
$('.wpsm-comptable tr.subheader').each(function(){
|
444 |
-
$(this).find('td').attr('colspan', col_count - 1)
|
445 |
-
});
|
446 |
-
}
|
447 |
-
}
|
448 |
-
|
449 |
-
}
|
450 |
-
else{
|
451 |
-
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
452 |
-
}
|
453 |
-
});
|
454 |
-
|
455 |
-
|
456 |
-
//Shortcode helper
|
457 |
-
|
458 |
-
$('#wpsm_first_col_hover_check').click(function() {
|
459 |
-
if ($(this).is(':checked')) {
|
460 |
-
$('#wpsm_comp_shortcode_firsthover').html('hover-col1 ');
|
461 |
-
}
|
462 |
-
else {
|
463 |
-
$('#wpsm_comp_shortcode_firsthover').html('');
|
464 |
-
}
|
465 |
-
var shortcode_strip_tags = $('.wpsm_comptable_shortcode_hidden').text();
|
466 |
-
$('.wpsm_comptable_shortcode_echo').html(shortcode_strip_tags);
|
467 |
-
});
|
468 |
-
|
469 |
-
$('#wpsm_calign_check').click(function() {
|
470 |
-
if ($(this).is(':checked')) {
|
471 |
-
$('#wpsm_comp_shortcode_calign').html('center-table-align');
|
472 |
-
}
|
473 |
-
else {
|
474 |
-
$('#wpsm_comp_shortcode_calign').html('');
|
475 |
-
}
|
476 |
-
var shortcode_strip_tags = $('.wpsm_comptable_shortcode_hidden').text();
|
477 |
-
$('.wpsm_comptable_shortcode_echo').html(shortcode_strip_tags);
|
478 |
-
});
|
479 |
-
|
480 |
-
//Image helper
|
481 |
-
var imageFrame;jQuery(".wpsm_table_helper_upload_image_button").click(function(e){e.preventDefault();return $self=jQuery(e.target),$div=$self.closest("div.wpsm_table_helper_image"),imageFrame?void imageFrame.open():(imageFrame=wp.media({title:"Choose Image",multiple:!1,library:{type:"image"},button:{text:"Use This Image"}}),imageFrame.on("select",function(){selection=imageFrame.state().get("selection"),selection&&selection.each(function(e){console.log(e);{var t=e.attributes.sizes.full.url;e.id}$div.find(".wpsm_table_helper_preview_image").attr("src",t),$div.find(".wpsm_table_helper_upload_image").val('<img src ="'+t+'" alt="" />')})}),void imageFrame.open())}),jQuery(".wpsm_table_helper_clear_image_button").click(function(){var e='';return jQuery(this).parent().siblings(".wpsm_table_helper_upload_image").val(""),jQuery(this).parent().siblings(".wpsm_table_helper_preview_image").attr("src",e),!1});
|
482 |
-
|
483 |
-
|
484 |
});
|
1 |
+
jQuery(document).ready(function ($) {
|
2 |
+
var field_name_prefix = 'table_values';
|
3 |
+
|
4 |
+
function get_effective(curr, index) {
|
5 |
+
if(!index)
|
6 |
+
return curr;
|
7 |
+
|
8 |
+
if(curr == index[0])
|
9 |
+
return index[1];
|
10 |
+
else if(curr == index[1])
|
11 |
+
return index[0];
|
12 |
+
else
|
13 |
+
return curr;
|
14 |
+
}
|
15 |
+
|
16 |
+
function get_curr_row_count(){
|
17 |
+
return parseInt($('.wpsm-rows').val());
|
18 |
+
}
|
19 |
+
|
20 |
+
function get_curr_col_count(){
|
21 |
+
return parseInt($('.wpsm-cols').val());
|
22 |
+
}
|
23 |
+
|
24 |
+
function get_curr_sub_array(){
|
25 |
+
return $('.wpsm-subs').val();
|
26 |
+
}
|
27 |
+
|
28 |
+
function is_valid_num(x){
|
29 |
+
if(parseInt(x) == x && x > 0)
|
30 |
+
return true;
|
31 |
+
return false;
|
32 |
+
}
|
33 |
+
|
34 |
+
function is_valid_row(x){
|
35 |
+
if(is_valid_num(x) && parseInt(x) <= get_curr_row_count())
|
36 |
+
return true;
|
37 |
+
return false;
|
38 |
+
}
|
39 |
+
|
40 |
+
function is_valid_col(x){
|
41 |
+
if(is_valid_num(x) && parseInt(x) <= get_curr_col_count())
|
42 |
+
return true;
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
|
46 |
+
function in_array(value, array) {
|
47 |
+
for(var i=0; i<array.length; i++){
|
48 |
+
if(value == array[i]) return true;
|
49 |
+
}
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
|
53 |
+
function rebuildTable(switch_rows, switch_cols){
|
54 |
+
switch_rows = (typeof switch_rows !== 'undefined') ? switch_rows : false;
|
55 |
+
switch_cols = (typeof switch_cols !== 'undefined') ? switch_cols : false;
|
56 |
+
var row_count = $('.wpsm-rows').val();
|
57 |
+
var col_count = $('.wpsm-cols').val();
|
58 |
+
var sub_array = $('.wpsm-subs').val();
|
59 |
+
sub_array = sub_array.split( ',' );
|
60 |
+
|
61 |
+
var table = $('.wpsm-comptable');
|
62 |
+
var effective_row, effective_col;
|
63 |
+
|
64 |
+
var table_html = '<thead><tr>';
|
65 |
+
for(var i = 1; i <= col_count; i++){
|
66 |
+
effective_col = get_effective(i, switch_cols);
|
67 |
+
var selector = 'input[name="'+field_name_prefix+'[0]['+effective_col+']"]';
|
68 |
+
var curr_val = ( $(selector).val() ) ? $(selector).val() : '';
|
69 |
+
table_html += '<th><input name="'+field_name_prefix+'[0]['+i+']" value="'+curr_val+'" placeholder="'+wpsm_js_strings.placeholder+'" /></th>';
|
70 |
+
}
|
71 |
+
table_html += '</tr></thead><tbody>';
|
72 |
+
|
73 |
+
for(var i = 1; i <= row_count; i++){
|
74 |
+
|
75 |
+
table_html += in_array(i, sub_array) ? '<tr class="subheader">' : '<tr>';
|
76 |
+
|
77 |
+
for(var j = 1; j <= col_count; j++){
|
78 |
+
|
79 |
+
effective_row = get_effective(i, switch_rows);
|
80 |
+
effective_col = get_effective(j, switch_cols);
|
81 |
+
|
82 |
+
var selector = 'textarea[name="'+field_name_prefix+'['+effective_row+']['+effective_col+']"]';
|
83 |
+
var curr_val = ( $(selector).val() ) ? $(selector).val() : '';
|
84 |
+
var col_span = col_count;
|
85 |
+
|
86 |
+
table_html += in_array(i, sub_array) ? '<td colspan="'+col_span+'">' : '<td>';
|
87 |
+
if (j == 1) {
|
88 |
+
table_html += '<span class="num_row_wpsm_table">'+i+'</span>';
|
89 |
+
}
|
90 |
+
table_html += '<textarea name="'+field_name_prefix+'['+i+']['+j+']" placeholder="'+wpsm_js_strings.placeholder+'">'+curr_val+'</textarea></td>';
|
91 |
+
if(in_array(i, sub_array)) break;
|
92 |
+
}
|
93 |
+
table_html += '</tr>';
|
94 |
+
|
95 |
+
}
|
96 |
+
table_html += '</tbody>';
|
97 |
+
table.html(table_html);
|
98 |
+
}
|
99 |
+
|
100 |
+
//Table resize dialog
|
101 |
+
|
102 |
+
$('#wpsm-comptable-resize-btn').click(function(e) {
|
103 |
+
$( "#wpsm-comptable-resize-dialog" ).dialog({
|
104 |
+
modal:true,
|
105 |
+
draggable: false,
|
106 |
+
open: function(e, ui) {
|
107 |
+
$(this).children('.wpsm-row-count').val(get_curr_row_count());
|
108 |
+
$(this).children('.wpsm-col-count').val(get_curr_col_count());
|
109 |
+
$(this).children('.wpsm-sub-array').val(get_curr_sub_array());
|
110 |
+
$(this).children('.wpsm-dialog-error').hide();
|
111 |
+
}
|
112 |
+
});
|
113 |
+
});
|
114 |
+
|
115 |
+
$('#wpsm-comptable-resize-dialog button').click(function(e) {
|
116 |
+
var row_count = $(this).siblings('.wpsm-row-count').val();
|
117 |
+
var col_count = $(this).siblings('.wpsm-col-count').val();
|
118 |
+
var sub_array = $(this).siblings('.wpsm-sub-array').val();
|
119 |
+
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
120 |
+
if(is_valid_num(row_count) && is_valid_num(col_count)){
|
121 |
+
error_cont.hide();
|
122 |
+
$('.wpsm-rows').val(row_count);
|
123 |
+
$('.wpsm-cols').val(col_count);
|
124 |
+
$('.wpsm-subs').val(sub_array);
|
125 |
+
rebuildTable();
|
126 |
+
$('#wpsm-comptable-resize-dialog').dialog("close");
|
127 |
+
}
|
128 |
+
else{
|
129 |
+
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
130 |
+
}
|
131 |
+
});
|
132 |
+
|
133 |
+
//Switch Rows Dialog
|
134 |
+
|
135 |
+
$('#wpsm-row-switcher-btn').click(function(e) {
|
136 |
+
$( "#wpsm-row-switcher-dialog" ).dialog({
|
137 |
+
modal:true,
|
138 |
+
draggable: false,
|
139 |
+
open: function(e, ui) {
|
140 |
+
$(this).children('input[type="text"]').val('');
|
141 |
+
$(this).children('.wpsm-dialog-error').hide();
|
142 |
+
}
|
143 |
+
});
|
144 |
+
});
|
145 |
+
|
146 |
+
$( "#wpsm-row-switcher-dialog button" ).click(function(e) {
|
147 |
+
var row_1 = $(this).siblings('.wpsm-row1').val();
|
148 |
+
var row_2 = $(this).siblings('.wpsm-row2').val();
|
149 |
+
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
150 |
+
if(is_valid_row(row_1) && is_valid_row(row_2)){
|
151 |
+
error_cont.hide();
|
152 |
+
rebuildTable([row_1, row_2], false);
|
153 |
+
$( "#wpsm-row-switcher-dialog" ).dialog("close");
|
154 |
+
}
|
155 |
+
else{
|
156 |
+
error_cont.html(wpsm_js_strings.switch_error + ' ' + get_curr_row_count()).show().effect( "bounce" );
|
157 |
+
}
|
158 |
+
});
|
159 |
+
|
160 |
+
//Switch Cols Dialog
|
161 |
+
|
162 |
+
$('#wpsm-col-switcher-btn').click(function(e) {
|
163 |
+
$( "#wpsm-col-switcher-dialog" ).dialog({
|
164 |
+
modal:true,
|
165 |
+
draggable: false,
|
166 |
+
open: function(e, ui) {
|
167 |
+
$(this).children('input[type="text"]').val('');
|
168 |
+
$(this).children('.wpsm-dialog-error').hide();
|
169 |
+
}
|
170 |
+
});
|
171 |
+
});
|
172 |
+
|
173 |
+
$( "#wpsm-col-switcher-dialog button" ).click(function(e) {
|
174 |
+
var col_1 = $(this).siblings('.wpsm-col1').val();
|
175 |
+
var col_2 = $(this).siblings('.wpsm-col2').val();
|
176 |
+
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
177 |
+
if(is_valid_col(col_1) && is_valid_col(col_2)){
|
178 |
+
error_cont.hide();
|
179 |
+
rebuildTable(false, [col_1, col_2]);
|
180 |
+
$( "#wpsm-col-switcher-dialog" ).dialog("close");
|
181 |
+
}
|
182 |
+
else{
|
183 |
+
error_cont.html(wpsm_js_strings.switch_error + ' ' + get_curr_col_count()).show().effect( "bounce" );
|
184 |
+
}
|
185 |
+
});
|
186 |
+
|
187 |
+
//Table add empty dialog
|
188 |
+
|
189 |
+
$('#wpsm-comptable-addnew-btn').click(function(e) {
|
190 |
+
$( "#wpsm-comptable-addnew-dialog" ).dialog({
|
191 |
+
modal:true,
|
192 |
+
draggable: false,
|
193 |
+
open: function(e, ui) {
|
194 |
+
$(this).children('input[type="text"]').val('');
|
195 |
+
$(this).children('.wpsm-dialog-error').hide();
|
196 |
+
}
|
197 |
+
});
|
198 |
+
});
|
199 |
+
|
200 |
+
$('#wpsm-comptable-addnew-dialog button').click(function(e) {
|
201 |
+
var row_after = $(this).siblings('.wpsm-row-after').val();
|
202 |
+
var col_after = $(this).siblings('.wpsm-col-after').val();
|
203 |
+
var col_count = get_curr_col_count();
|
204 |
+
var row_count = get_curr_row_count();
|
205 |
+
var sub_array = $('.wpsm-subs').val();
|
206 |
+
sub_array = sub_array.split( ',' );
|
207 |
+
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
208 |
+
|
209 |
+
if(is_valid_col(col_after) || is_valid_row(row_after)){
|
210 |
+
error_cont.hide();
|
211 |
+
|
212 |
+
if (row_after && col_after) {
|
213 |
+
error_cont.html(wpsm_js_strings.only_one).show().effect( "bounce" );
|
214 |
+
return;
|
215 |
+
}
|
216 |
+
|
217 |
+
if (row_after) {
|
218 |
+
if (row_after < row_count) {
|
219 |
+
// Increment indexes of all rows after row_after
|
220 |
+
var row_index = row_insert_index = parseInt(row_after) + 1;
|
221 |
+
for(row_index; row_index <= row_count; row_index++){
|
222 |
+
var row_tr_index = $('.wpsm-comptable tr:eq('+row_index+') textarea');
|
223 |
+
row_increment = parseInt(row_index) + 1;
|
224 |
+
row_tr_index.each(function(i){
|
225 |
+
i++;
|
226 |
+
$(this).attr('name', field_name_prefix+'['+row_increment+']['+i+']');
|
227 |
+
});
|
228 |
+
}
|
229 |
+
// Add empty row
|
230 |
+
table_html = '<tr>';
|
231 |
+
for(var j = 1; j <= col_count; j++){
|
232 |
+
table_html += '<td><textarea name="'+field_name_prefix+'['+row_insert_index+']['+j+']" placeholder="'+wpsm_js_strings.placeholder+'"></textarea></td>';
|
233 |
+
}
|
234 |
+
table_html += '</tr>';
|
235 |
+
$('.wpsm-comptable tr:eq('+row_insert_index+')').before(table_html);
|
236 |
+
// Increment hidden input value
|
237 |
+
$('.wpsm-rows').val(row_count + 1);
|
238 |
+
// Rebuild sub headers
|
239 |
+
var subheaderarray = [];
|
240 |
+
$.each(sub_array, function(index, value) {
|
241 |
+
if (parseInt(value) >= row_insert_index) {
|
242 |
+
subheaderarray.push(parseInt(value) + 1);
|
243 |
+
}
|
244 |
+
else {
|
245 |
+
subheaderarray.push(parseInt(value));
|
246 |
+
}
|
247 |
+
});
|
248 |
+
subheaderarray = subheaderarray.join(',');
|
249 |
+
$('.wpsm-subs').val(subheaderarray);
|
250 |
+
// Close popup
|
251 |
+
$('#wpsm-comptable-addnew-dialog').dialog("close");
|
252 |
+
// Rebuild values
|
253 |
+
$('.num_row_wpsm_table').remove();
|
254 |
+
for (var num_index = 1; num_index <= row_count+1; num_index++) {
|
255 |
+
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
256 |
+
}
|
257 |
+
|
258 |
+
}
|
259 |
+
else{
|
260 |
+
error_cont.html(wpsm_js_strings.insert_error_row).show().effect( "bounce" );
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
if (col_after) {
|
265 |
+
if (col_after < col_count) {
|
266 |
+
for(var j = 1; j <= row_count; j++){
|
267 |
+
// Increment indexes of all cols after col_after
|
268 |
+
var col_index = col_insert_index = parseInt(col_after) + 1;
|
269 |
+
for(col_index; col_index <= col_count; col_index++){
|
270 |
+
var col_td_index = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_index+') textarea');
|
271 |
+
col_increment = parseInt(col_index) + 1;
|
272 |
+
col_td_index.each(function(){
|
273 |
+
$(this).attr('name', field_name_prefix+'['+j+']['+col_increment+']');
|
274 |
+
});
|
275 |
+
$('.wpsm-comptable tr > th:nth-child('+col_index+') input').attr('name', field_name_prefix+'[0]['+col_increment+']');
|
276 |
+
}
|
277 |
+
|
278 |
+
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_insert_index+')');
|
279 |
+
table_html = '<td><textarea name="'+field_name_prefix+'['+j+']['+col_insert_index+']" placeholder="'+wpsm_js_strings.placeholder+'"></textarea></td>';
|
280 |
+
col_td_foreach.before(table_html);
|
281 |
+
|
282 |
+
}
|
283 |
+
// Add empty col
|
284 |
+
$('.wpsm-comptable tr > th:nth-child('+col_insert_index+')').before('<th><input name="'+field_name_prefix+'[0]['+col_insert_index+']" value="" placeholder="'+wpsm_js_strings.placeholder+'" /></th>');
|
285 |
+
|
286 |
+
// Increment hidden input value and close
|
287 |
+
$('.wpsm-cols').val(col_count + 1);
|
288 |
+
$('#wpsm-comptable-addnew-dialog').dialog("close");
|
289 |
+
$('.wpsm-comptable tr.subheader').each(function(){
|
290 |
+
$(this).find('td').attr('colspan', col_count + 1)
|
291 |
+
});
|
292 |
+
}
|
293 |
+
else{
|
294 |
+
error_cont.html(wpsm_js_strings.insert_error_col).show().effect( "bounce" );
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
}
|
299 |
+
else{
|
300 |
+
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
301 |
+
}
|
302 |
+
});
|
303 |
+
|
304 |
+
|
305 |
+
//Table remove dialog
|
306 |
+
|
307 |
+
$('#wpsm-comptable-remove-btn').click(function(e) {
|
308 |
+
$( "#wpsm-comptable-remove-dialog" ).dialog({
|
309 |
+
modal:true,
|
310 |
+
draggable: false,
|
311 |
+
open: function(e, ui) {
|
312 |
+
$(this).children('input[type="text"]').val('');
|
313 |
+
$(this).children('.wpsm-dialog-error').hide();
|
314 |
+
}
|
315 |
+
});
|
316 |
+
});
|
317 |
+
|
318 |
+
$('#wpsm-comptable-remove-dialog button').click(function(e) {
|
319 |
+
var row_remove = $(this).siblings('.wpsm-row-remove').val();
|
320 |
+
var col_remove = $(this).siblings('.wpsm-col-remove').val();
|
321 |
+
var col_count = get_curr_col_count();
|
322 |
+
var row_count = get_curr_row_count();
|
323 |
+
var error_cont = $(this).siblings('.wpsm-dialog-error').first();
|
324 |
+
var sub_array = $('.wpsm-subs').val();
|
325 |
+
sub_array = sub_array.split( ',' );
|
326 |
+
|
327 |
+
if(is_valid_col(col_remove) || is_valid_row(row_remove)){
|
328 |
+
error_cont.hide();
|
329 |
+
|
330 |
+
if (row_remove && col_remove) {
|
331 |
+
error_cont.html(wpsm_js_strings.only_one).show().effect( "bounce" );
|
332 |
+
return;
|
333 |
+
}
|
334 |
+
|
335 |
+
if (row_remove) {
|
336 |
+
if (row_remove < row_count) {
|
337 |
+
// Reduce indexes of all rows after row_remove
|
338 |
+
var row_index = parseInt(row_remove) + 1;
|
339 |
+
var row_remove_index = parseInt(row_remove);
|
340 |
+
for(row_index; row_index <= row_count; row_index++){
|
341 |
+
var row_tr_index = $('.wpsm-comptable tr:eq('+row_index+') textarea');
|
342 |
+
row_reduce = parseInt(row_index) - 1;
|
343 |
+
row_tr_index.each(function(i){
|
344 |
+
i++;
|
345 |
+
$(this).attr('name', field_name_prefix+'['+row_reduce+']['+i+']');
|
346 |
+
});
|
347 |
+
}
|
348 |
+
// Remove row
|
349 |
+
$('.wpsm-comptable tr:eq('+row_remove_index+')').remove();
|
350 |
+
|
351 |
+
// Reduce hidden input value, recreate subheaders and close popup
|
352 |
+
$('.wpsm-rows').val(row_count - 1);
|
353 |
+
|
354 |
+
var subheaderarray = [];
|
355 |
+
$.each(sub_array, function(index, value) {
|
356 |
+
if (parseInt(value) > row_remove_index) {
|
357 |
+
subheaderarray.push(parseInt(value) - 1);
|
358 |
+
}
|
359 |
+
else if (parseInt(value) == row_remove_index) {
|
360 |
+
}
|
361 |
+
else {
|
362 |
+
subheaderarray.push(parseInt(value));
|
363 |
+
}
|
364 |
+
});
|
365 |
+
subheaderarray = subheaderarray.join(',');
|
366 |
+
$('.wpsm-subs').val(subheaderarray);
|
367 |
+
|
368 |
+
$('#wpsm-comptable-remove-dialog').dialog("close");
|
369 |
+
|
370 |
+
$('.num_row_wpsm_table').remove();
|
371 |
+
for (var num_index = 1; num_index <= row_count-1; num_index++) {
|
372 |
+
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
373 |
+
}
|
374 |
+
|
375 |
+
}
|
376 |
+
else{ //if removed row is last
|
377 |
+
var row_remove_index = parseInt(row_remove);
|
378 |
+
$('.wpsm-comptable tr:eq('+row_remove_index+')').remove();
|
379 |
+
$('.wpsm-rows').val(row_count - 1);
|
380 |
+
var subheaderarray = [];
|
381 |
+
$.each(sub_array, function(index, value) {
|
382 |
+
if (parseInt(value) > row_remove_index) {
|
383 |
+
subheaderarray.push(parseInt(value) - 1);
|
384 |
+
}
|
385 |
+
else if (parseInt(value) == row_remove_index) {
|
386 |
+
}
|
387 |
+
else {
|
388 |
+
subheaderarray.push(parseInt(value));
|
389 |
+
}
|
390 |
+
});
|
391 |
+
subheaderarray = subheaderarray.join(',');
|
392 |
+
$('.wpsm-subs').val(subheaderarray);
|
393 |
+
$('#wpsm-comptable-remove-dialog').dialog("close");
|
394 |
+
$('.num_row_wpsm_table').remove();
|
395 |
+
for (var num_index = 1; num_index <= row_count-1; num_index++) {
|
396 |
+
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
397 |
+
}
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
if (col_remove) {
|
402 |
+
if (col_remove < col_count) {
|
403 |
+
for(var j = 1; j <= row_count; j++){
|
404 |
+
// Reduce indexes of all cols after col_remove
|
405 |
+
var col_index = parseInt(col_remove) + 1;
|
406 |
+
var col_remove_index = parseInt(col_remove);
|
407 |
+
for(col_index; col_index <= col_count; col_index++){
|
408 |
+
var col_td_index = $('.wpsm-comptable tr:eq('+j+') > td:nth-child('+col_index+') textarea');
|
409 |
+
col_reduce = parseInt(col_index) - 1;
|
410 |
+
col_td_index.each(function(){
|
411 |
+
$(this).attr('name', field_name_prefix+'['+j+']['+col_reduce+']');
|
412 |
+
});
|
413 |
+
$('.wpsm-comptable tr > th:nth-child('+col_index+') input').attr('name', field_name_prefix+'[0]['+col_reduce+']');
|
414 |
+
}
|
415 |
+
|
416 |
+
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+'):not(.subheader) > td:nth-child('+col_remove_index+')');
|
417 |
+
col_td_foreach.remove();
|
418 |
+
|
419 |
+
}
|
420 |
+
// Remove col in header
|
421 |
+
$('.wpsm-comptable tr > th:nth-child('+col_remove_index+')').remove();
|
422 |
+
|
423 |
+
// Reduce hidden input value and close
|
424 |
+
$('.wpsm-cols').val(col_count - 1);
|
425 |
+
$('#wpsm-comptable-remove-dialog').dialog("close");
|
426 |
+
$('.wpsm-comptable tr.subheader').each(function(){
|
427 |
+
$(this).find('td').attr('colspan', col_count - 1)
|
428 |
+
});
|
429 |
+
$('.num_row_wpsm_table').remove();
|
430 |
+
for (var num_index = 1; num_index <= row_count; num_index++) {
|
431 |
+
$('.wpsm-comptable tr:eq('+num_index+') > td:nth-child(1)').prepend('<span class="num_row_wpsm_table">'+num_index+'</span>');
|
432 |
+
}
|
433 |
+
}
|
434 |
+
else{
|
435 |
+
var col_remove_index = parseInt(col_remove);
|
436 |
+
for(var j = 1; j <= row_count; j++){
|
437 |
+
var col_td_foreach = $('.wpsm-comptable tr:eq('+j+'):not(.subheader) > td:nth-child('+col_remove_index+')');
|
438 |
+
col_td_foreach.remove();
|
439 |
+
}
|
440 |
+
$('.wpsm-comptable tr > th:nth-child('+col_remove_index+')').remove();
|
441 |
+
$('.wpsm-cols').val(col_count - 1);
|
442 |
+
$('#wpsm-comptable-remove-dialog').dialog("close");
|
443 |
+
$('.wpsm-comptable tr.subheader').each(function(){
|
444 |
+
$(this).find('td').attr('colspan', col_count - 1)
|
445 |
+
});
|
446 |
+
}
|
447 |
+
}
|
448 |
+
|
449 |
+
}
|
450 |
+
else{
|
451 |
+
error_cont.html(wpsm_js_strings.resize_error).show().effect( "bounce" );
|
452 |
+
}
|
453 |
+
});
|
454 |
+
|
455 |
+
|
456 |
+
//Shortcode helper
|
457 |
+
|
458 |
+
$('#wpsm_first_col_hover_check').click(function() {
|
459 |
+
if ($(this).is(':checked')) {
|
460 |
+
$('#wpsm_comp_shortcode_firsthover').html('hover-col1 ');
|
461 |
+
}
|
462 |
+
else {
|
463 |
+
$('#wpsm_comp_shortcode_firsthover').html('');
|
464 |
+
}
|
465 |
+
var shortcode_strip_tags = $('.wpsm_comptable_shortcode_hidden').text();
|
466 |
+
$('.wpsm_comptable_shortcode_echo').html(shortcode_strip_tags);
|
467 |
+
});
|
468 |
+
|
469 |
+
$('#wpsm_calign_check').click(function() {
|
470 |
+
if ($(this).is(':checked')) {
|
471 |
+
$('#wpsm_comp_shortcode_calign').html('center-table-align');
|
472 |
+
}
|
473 |
+
else {
|
474 |
+
$('#wpsm_comp_shortcode_calign').html('');
|
475 |
+
}
|
476 |
+
var shortcode_strip_tags = $('.wpsm_comptable_shortcode_hidden').text();
|
477 |
+
$('.wpsm_comptable_shortcode_echo').html(shortcode_strip_tags);
|
478 |
+
});
|
479 |
+
|
480 |
+
//Image helper
|
481 |
+
var imageFrame;jQuery(".wpsm_table_helper_upload_image_button").click(function(e){e.preventDefault();return $self=jQuery(e.target),$div=$self.closest("div.wpsm_table_helper_image"),imageFrame?void imageFrame.open():(imageFrame=wp.media({title:"Choose Image",multiple:!1,library:{type:"image"},button:{text:"Use This Image"}}),imageFrame.on("select",function(){selection=imageFrame.state().get("selection"),selection&&selection.each(function(e){console.log(e);{var t=e.attributes.sizes.full.url;e.id}$div.find(".wpsm_table_helper_preview_image").attr("src",t),$div.find(".wpsm_table_helper_upload_image").val('<img src ="'+t+'" alt="" />')})}),void imageFrame.open())}),jQuery(".wpsm_table_helper_clear_image_button").click(function(){var e='';return jQuery(this).parent().siblings(".wpsm_table_helper_upload_image").val(""),jQuery(this).parent().siblings(".wpsm_table_helper_preview_image").attr("src",e),!1});
|
482 |
+
|
483 |
+
|
484 |
});
|
readme.txt
CHANGED
@@ -1,72 +1,76 @@
|
|
1 |
-
=== Table Maker ===
|
2 |
-
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:
|
5 |
-
Requires at least: 3.0
|
6 |
-
Tested up to: 4.3.3
|
7 |
-
Stable tag: 1.
|
8 |
-
License: License: GPLv2 or later
|
9 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
-
|
11 |
-
Create awesome responsive comparison tables.
|
12 |
-
|
13 |
-
== Description ==
|
14 |
-
Plugin helps you to create different comparison tables. It has some unique functions which allow you to use plugin to create different type of awesome tables: comparison tables, TOP tables, specification tables, etc. Table looks awesome with adding data as rows and as columns.
|
15 |
-
|
16 |
-
[Demo of some tables of plugin](https://wpsoul.com/responsive-comparison-table-wordpress/)
|
17 |
-
|
18 |
-
**Features:**
|
19 |
-
|
20 |
-
* Responsive option (stacks)
|
21 |
-
* Predefined icons
|
22 |
-
* Rows or cols lines
|
23 |
-
* Option to mark first column for specification labels
|
24 |
-
* Option to add labels and featured row and cols
|
25 |
-
* Works with shortcodes
|
26 |
-
* Option to add subheaders
|
27 |
-
* Option to choose color of header
|
28 |
-
* Great and simple design
|
29 |
-
* Option to upload and use images
|
30 |
-
* Optional center aligning
|
31 |
-
|
32 |
-
|
33 |
-
>
|
34 |
-
>
|
35 |
-
>
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
*
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
*
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
* Initial release
|
1 |
+
=== Table Maker ===
|
2 |
+
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.4
|
8 |
+
License: License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Create awesome responsive comparison tables.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
Plugin helps you to create different comparison tables. It has some unique functions which allow you to use plugin to create different type of awesome tables: comparison tables, TOP tables, specification tables, etc. Table looks awesome with adding data as rows and as columns.
|
15 |
+
|
16 |
+
[Demo of some tables of plugin](https://wpsoul.com/responsive-comparison-table-wordpress/)
|
17 |
+
|
18 |
+
**Features:**
|
19 |
+
|
20 |
+
* Responsive option (stacks)
|
21 |
+
* Predefined icons
|
22 |
+
* Rows or cols lines
|
23 |
+
* Option to mark first column for specification labels
|
24 |
+
* Option to add labels and featured row and cols
|
25 |
+
* Works with shortcodes
|
26 |
+
* Option to add subheaders
|
27 |
+
* Option to choose color of header
|
28 |
+
* Great and simple design
|
29 |
+
* Option to upload and use images
|
30 |
+
* Optional center aligning
|
31 |
+
* Export tables to XML. Import ones from XML/CSV
|
32 |
+
|
33 |
+
> <strong>Additional functions</strong><br>
|
34 |
+
>Our themes have some additional functions for plugin: buttons, text highlights, countdown, option to hide values from non logged users.
|
35 |
+
>
|
36 |
+
>Check our theme if you need [best moneymaking solutions](http://themeforest.net/item/rehub-directory-shop-coupon-affiliate-theme/7646339 "Rehub theme").
|
37 |
+
|
38 |
+
**How it works:**
|
39 |
+
|
40 |
+
[youtube https://www.youtube.com/watch?v=Z4r6TzWv8gU]
|
41 |
+
|
42 |
+
If you like this plugin please give it a good rating.
|
43 |
+
|
44 |
+
== Installation ==
|
45 |
+
1. Use WordPress' plugin installer to install the plugin.
|
46 |
+
2. Go to the admin panel and click on the Table Maker menu item.
|
47 |
+
3. To create your first table click on the 'Add New' button.
|
48 |
+
4. Once the table is ready add it to any post or page using the `[wpsm_comparison_table id="1"]` shortcode.
|
49 |
+
|
50 |
+
== Screenshots ==
|
51 |
+
|
52 |
+
1. Overview of interface
|
53 |
+
2. Table example
|
54 |
+
3. How it looks on mobile
|
55 |
+
|
56 |
+
== Changelog ==
|
57 |
+
|
58 |
+
= 1.5 =
|
59 |
+
* Added import of table from CSV
|
60 |
+
|
61 |
+
= 1.4 =
|
62 |
+
* Fix export/import for some hostings
|
63 |
+
* Better icon compatibility and some css fixes
|
64 |
+
* Small improvements in admin UI
|
65 |
+
|
66 |
+
= 1.3 =
|
67 |
+
* Added export/import of table and some fixes
|
68 |
+
|
69 |
+
= 1.2 =
|
70 |
+
* some fixes
|
71 |
+
|
72 |
+
= 1.1 =
|
73 |
+
* Update readme and some fixes
|
74 |
+
|
75 |
+
= 1.0 =
|
76 |
* Initial release
|
table-maker.php
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
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.
|
7 |
-
Author: Wpsoul
|
8 |
-
Author URI: https://wpsoul.com
|
9 |
-
License: GPL2
|
10 |
-
Text Domain: wpsm-tableplugin
|
11 |
-
Domain Path: /languages/
|
12 |
-
*/
|
13 |
-
|
14 |
-
if ( ! defined( 'WPINC' ) ) {
|
15 |
-
die;
|
16 |
-
}
|
17 |
-
|
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.
|
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 |
-
}
|
38 |
-
add_action( 'plugins_loaded', 'wpsm_load_plugin_textdomain' );
|
39 |
-
|
40 |
?>
|
1 |
+
<?php
|
2 |
+
/*
|
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.5
|
7 |
+
Author: Wpsoul
|
8 |
+
Author URI: https://wpsoul.com
|
9 |
+
License: GPL2
|
10 |
+
Text Domain: wpsm-tableplugin
|
11 |
+
Domain Path: /languages/
|
12 |
+
*/
|
13 |
+
|
14 |
+
if ( ! defined( 'WPINC' ) ) {
|
15 |
+
die;
|
16 |
+
}
|
17 |
+
|
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.5');
|
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 |
+
}
|
38 |
+
add_action( 'plugins_loaded', 'wpsm_load_plugin_textdomain' );
|
39 |
+
|
40 |
?>
|