-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy patheasy-table.php
1202 lines (1096 loc) · 47.6 KB
/
easy-table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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
195
196
197
198
199
200
201
202
203
204
205
206
207
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
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Easy Table
Plugin URI: http://takien.com/
Description: Create table in post, page, or widget in easy way.
Author: Takien
Version: 1.1.1
Author URI: http://takien.com/
*/
/* Copyright 2013 takien.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For a copy of the GNU General Public License, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if(!defined('ABSPATH')) die();
if (!class_exists('EasyTable')) {
class EasyTable {
/**
* Default settings
* Plugin will use this setting if user not made custom setting via settings page or tag.
*/
var $settings = Array(
'shortcodetag' => 'table',
'attrtag' => 'attr',
'tablewidget' => false,
'scriptloadin' => Array('is_single','is_page'),
'class' => '',
'caption' => false,
'width' => '100%',
'th' => true,
'tf' => false,
'border' => 0,
'id' => false,
'theme' => 'default',
'tablesorter' => false,
'loadcss' => true,
'scriptinfooter'=> false,
'delimiter' => ',',
'file' => false,
'trim' => false, /*trim, since 1.0*/
'enclosure' => '"',
'escape' => '\\',
'nl' => '~~',
'csvfile' => false,
'terminator' => '\n', /*row terminator, since 1.0*/
'limit' => 0 /*max row to be included to table, 0 = unlimited, since 1.0*/
);
function EasyTable(){
$this->__construct();
}
function __construct(){
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", array(&$this,'easy_table_settings_link' ));
load_plugin_textdomain('easy-table', false, basename( dirname( __FILE__ ) ) . '/languages' );
add_action('admin_init', array(&$this,'easy_table_register_setting'));
add_action('admin_head', array(&$this,'easy_table_admin_script'));
add_action('wp_enqueue_scripts', array(&$this,'easy_table_script'));
add_action('wp_enqueue_scripts', array(&$this,'easy_table_style'));
add_action('admin_menu', array(&$this,'easy_table_add_page'));
add_action('contextual_help', array(&$this,'easy_table_help'));
add_shortcode($this->option('shortcodetag'), array(&$this,'easy_table_short_code'));
add_shortcode($this->option('attrtag'), array(&$this,'easy_table_short_code_attr'));
if($this->option('tablewidget')){
add_filter('widget_text', 'do_shortcode');
}
}
private function easy_table_base($return){
$easy_table_base = Array(
'name' => 'Easy Table',
'version' => '1.1.1',
'plugin-domain' => 'easy-table'
);
return $easy_table_base[$return];
}
function easy_table_short_code($atts, $content="") {
$shortcode_atts = shortcode_atts(array(
'class' => $this->option('class'),
'caption' => $this->option('caption'),
'width' => $this->option('width'),
'th' => $this->option('th'),
'tf' => $this->option('tf'),
'border' => $this->option('border'),
'id' => $this->option('id'),
'theme' => $this->option('theme'),
'tablesorter' => $this->option('tablesorter'),
'delimiter' => $this->option('delimiter'),
'enclosure' => $this->option('enclosure'),
'escape' => $this->option('escape'),
'file' => $this->option('file'),
'trim' => $this->option('trim'),
'sort' => '',
'nl' => $this->option('nl'),
'ai' => false,
'terminator' => $this->option('terminator'),
'limit' => $this->option('limit'),
'style' => '', /*table inline style, since 1.0*/
'colalign' => '', /*column align, ex: [table colalign="left|right|center"], @since 1.0*/
'colwidth' => '', /*column width, ex: [table colwidth="100|200|300"], @since 1.0*/
), $atts);
/**
* because clean_pre is deprecated since WordPress 3.4, then replace it manually
$content = clean_pre($content);*/
$content = str_replace(array('<br />', '<br/>', '<br>'), array('', '', ''), $content);
$content = str_replace('<p>', "\n", $content);
$content = str_replace('</p>', '', $content);
$content = str_replace(' ','',$content);
$char_codes = array( '‘', '’', '“', '”', '′', '″' );
$replacements = array( "'", "'", '"', '"', "'", '"' );
$content = str_replace( $char_codes, $replacements, $content );
return $this->csv_to_table($content,$shortcode_atts);
}
/**
* Just return to strip attr shortcode for table cell, since we use custom regex for attr shortcode.
* @since 0.5
*/
function easy_table_short_code_attr($atts){
return;
}
/**
* Convert CSV to table
* @param array|string $data could be CSV string or array
* @param array @args
* @return string
*/
private function csv_to_table($data,$args){
extract($args);
if( $this->option('csvfile') AND $file ){
/*$data = @file_get_contents($file);*/
/** use wp_remote_get
* @since 0.8
*/
$data = '';
$response = wp_remote_get($file);
/**
notify if error reading file.
@since 0.9
*/
if( is_wp_error( $response ) ) {
return '<div style="color:red">Error reading file/URL.</div>';
} else if( $response['response']['code'] == 200 ) {
$data = $response['body'];
}
}
if(!is_array($data)){
/**
normalize nl, since it may contains new line.
@since 0.9
*/
$data = preg_replace('/'.preg_quote($nl).'([\s\r\n\t]+)?/i',$nl,$data);
/*
Fix encoding?
@since: 1.0 beta
*/
require_once (dirname(__FILE__).'/inc/Encoding.php');
//$data = ForceEncode::fixUTF8($data);
$data = ForceEncode::toUTF8($data);
/*
convert csv to array.
*/
$data = $this->csv_to_array(trim($data), $delimiter, $enclosure, $escape,$terminator);
}
if(empty($data)) return false;
$max_cols = count(max($data));
$r=0;
/**
* initialize inline sort,
* extract header sort if any, and equalize with max column number
* @since 0.8
*/
if( $tablesorter ) {
$inline_sort = Array();
$header_sort = explode(',',$sort);
$header_sort = array_pad($header_sort,$max_cols,NULL);
}
/**
* tfoot position
* @since 0.4
*/
$tfpos = ($tf == 'last') ? count($data) : ($th?2:1);
$width = (stripos($width,'%') === false) ? (int)$width.'px' : (int)$width.'%';
/*colalign & colwidth
@since 1.0
*/
if($colalign) {
$c_align = explode('|',$colalign);
}
if($colwidth) {
$c_width = explode('|',$colwidth);
}
$margin_left = $margin_right = 0;
if( 'center' == $align ) {
$margin_left = $margin_right = 'auto';
}
$output = '<table '.($id ? 'id="'.$id.'"':'');
$output .= 'style="width:'.$width.';margin:'.$margin_top.' '.$margin_right.' '.$margin_bottom.' '.$margin_left.';'.$style.'"';
$output .= ' class="easy-table easy-table-'.$theme.' '.($tablesorter ? 'tablesorter __sortlist__ ':'').$class.'" '.
(($border !=='0') ? 'border="'.$border.'"' : '').
'>'."\n";
$output .= $caption ? '<caption>'.$caption.'</caption>'."\n" : '';
$output .= $th ? '<thead>' : (($tf !== 'last') ? '' : '<tbody>');
$output .= (!$th AND !$tf) ? '<tbody>':'';
foreach($data as $k=>$cols){ $r++;
//$cols = array_pad($cols,$max_cols,'');
$output .= (($r==$tfpos) AND $tf) ? (($tf=='last')?'</tbody>':'').'<tfoot>': '';
$output .= "\r\n".'<tr>';
$thtd = ((($r==1) AND $th) OR (($r==$tfpos) AND $tf)) ? 'th' : 'td';
/**
ai is auto index
@since 0.9
add auto numbering in the begining of each row
ai="true" or ai="1" number will start from 1,
ai="n", n = any number, number will start from that.
Another possible value.
ai="n/head/width"
n = index start
head = head text, default is No.
width = column width, in pixel. Default is 20px
ai head, text to shown in the table head row, default is No.
*/
$index = explode('/',$ai);
$indexnum = ((int)$index[0])+$r;
$indexnum = $th ? $indexnum-2 : $indexnum-1;
$indexnum = ($tf AND ($tf !== 'last')) ? $indexnum-1 : $indexnum;
$indexhead = isset($index[1]) ? $index[1] : 'No.';
$indexwidth = isset($index[2]) ? (int)$index[2] : 30;
$output .= ($ai AND ($thtd == 'td')) ? '<'.$thtd.' style="width:'.$indexwidth.'px">'.$indexnum."</$thtd>" : ($ai ? "<$thtd>".$indexhead."</$thtd>" : '');
foreach($cols as $c=>$cell){
/**
* Add attribute for each cell
* @since 0.5
*/
preg_match('/\['.$this->option('attrtag').' ([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)/',$cell,$matchattr);
$attr = isset($matchattr[1]) ? $matchattr[1] : '';
/**
* extract $attr value
* @since 0.8
* this is for inline sorting option,
* eg [attr sort="desc"],[attr sort="asc"] or [attr sort="none"]
* only affect if it's TH and $tablesorter enabled
* extract sort value and insert appropriate class value.
*/
if( ('th' == $thtd) AND $tablesorter ) {
$attrs = $attr ? shortcode_parse_atts($attr) : Array();
$attrs['sort'] = isset($attrs['sort']) ? $attrs['sort'] : $header_sort[$c];
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] : '';
$inline_sort[$c] = $attrs['sort'];
$attr = '';
$sorter = in_array(strtolower($attrs['sort']),array('desc','asc')) ? '' : (!empty($attrs['sort']) ? 'false' : '');
foreach($attrs as $katr => $vatr){
if($katr == 'sort') {
}
else if(($katr == 'class')){
$attr .= "$katr='$vatr ";
$attr .= $sorter ? "{sorter: $sorter}":'';
$attr .= "' ";
}
else {
$attr .= "$katr='$vatr' ";
}
}
}
/**
nl, replace nl with new line
@since 0.9
*/
$cell = str_replace($nl,'<br />',$cell);
/*trim cell content?
@since 1.0
*/
$cell = $trim ? trim(str_replace(' ','',$cell)) : $cell;
/*nl2br? only if terminator is not \n or \r*/
if(( '\n' !== $terminator ) OR ( '\r' !== $terminator )) {
$cell = nl2br($cell);
}
/*colalign
@since 1.0
*/
if (isset($c_align[$c]) AND (stripos($attr,'text-align') === false)) {
if(stripos($attr,'style') === false) {
$attr = $attr. ' style="text-align:'.$c_align[$c].'" ';
}
else {
$attr = preg_replace('/style(\s+)?=(\s+)?("|\')(\s+)?/i','style=${3}text-align:'.$c_align[$c].';',$attr);
}
}
/*colwidth
@since 1.0
*/
if (isset($c_width[$c]) AND (stripos($attr,'width') === false) AND ($r == 1)) {
$c_width[$c] = (stripos($c_width[$c],'%') === false) ? (int)$c_width[$c].'px' : (int)$c_width[$c].'%';
if(stripos($attr,'style') === false) {
$attr = $attr. ' style="width:'.$c_width[$c].'" ';
}
else {
$attr = preg_replace('/style(\s+)?=(\s+)?("|\')(\s+)?/i','style=${3}width:'.$c_width[$c].';',$attr);
}
}
$output .= "<$thtd $attr>".do_shortcode($cell)."</$thtd>\n";
}
$output .= '</tr>'."\n";
$output .= (($r==1) AND $th) ? '</thead>'."\n".'<tbody>' : '';
$output .= (($r==$tfpos) AND $tf) ? '</tfoot>'.((($tf==1) AND !$th) ? '<tbody>':''): '';
}
$output .= (($tf!=='last')?'</tbody>':'').'</table>';
/**
* Build sortlist metadata and append it to the table class
* @since 0.8
* This intended to $tablesorter,
* so don't bother if $tablesorter is false/disabled
*/
if( $tablesorter ) {
$sortlist = '';
$all_sort = array_replace($header_sort,$inline_sort);
if(implode('',$all_sort)) {
$sortlist = '{sortlist: [';
foreach($all_sort as $k=>$v){
$v = (($v == 'desc') ? 1 : (($v == 'asc') ? 0 : '' ));
if($v !=='') {
$sortlist .= '['.$k.','.$v.'], ';
}
}
$sortlist .= ']}';
}
$output = str_replace('__sortlist__',$sortlist,$output);
}
return $output;
}
/**
* Convert CSV to array
*/
private function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n", $limit = 0 ) {
$r = array();
$terminator = ($terminator == '\n') ? "\n" : $terminator;
$terminator = ($terminator == '\r') ? "\r" : $terminator;
$terminator = ($terminator == '\t') ? "\t" : $terminator;
$rows = easy_table_str_getcsv($csv, $terminator,$enclosure,$escape);
$rows = array_diff($rows,Array(''));
/*
* limit how many rows will be included?
* default 0, means ulimited.
* @since 1.0
*/
if($limit > 0) {
$rows = array_slice($rows, 0, $limit);
}
foreach($rows as &$row) {
$r[] = easy_table_str_getcsv($row,$delimiter);
}
return $r;
}
/**
* Retrieve options from database if any, or use default options instead.
*/
function option($key=''){
$option = get_option('easy_table_plugin_option') ? get_option('easy_table_plugin_option') : Array();
$option = array_merge($this->settings,$option);
if($key){
$return = $option[$key];
}
else{
$return = $option;
}
return $return;
}
/**
* Retrieve themes directory
* @since: 0.8
*/
function themes(){
/**
* delete theme cache on setting updated.
*/
if( ( 'easy-table' == $_GET['page']) AND isset($_GET['settings-updated']) ) {
delete_transient('easy_table_themes');
}
if(!function_exists('scandir')){
return Array('default');
}
if ( false === ( $themes = get_transient( 'easy_table_themes' ) )) {
$dir = plugin_dir_path(__FILE__).'themes/';
$dirs = scandir($dir);
foreach($dirs as $d){
if( (substr($d,0,1) !=='.') AND (is_dir($dir.$d)) ) {
$themes[] = $d;
}
}
set_transient( 'easy_table_themes', $themes , 86400 );
}
return $themes;
}
function theme_content() {
if(!isset($_GET['edit'])) {
return false;
}
$theme = $_GET['edit'];
$dir = plugin_dir_path(__FILE__).'themes/';
if(is_writable($dir.$theme.'/style.css')) {
return file_get_contents($dir.$theme.'/style.css');
}
}
/**
* Register plugin setting
*/
function easy_table_register_setting() {
register_setting('easy_table_option_field', 'easy_table_plugin_option');
}
/**
* Render form
* @param array
*/
function render_form($fields){
$output ='<table class="form-table">';
foreach($fields as $field){
$field['rowclass'] = isset($field['rowclass']) ? $field['rowclass'] : false;
$field['label'] = isset($field['label']) ? $field['label'] : '';
if($field['type']=='text'){
$output .= '<tr '.($field['rowclass'] ? 'class="'.$field['rowclass'].'"': '').'><th><label for="'.$field['name'].'">'.$field['label'].'</label></th>';
$output .= '<td><input type="text" id="'.$field['name'].'" name="'.$field['name'].'" value="'.$field['value'].'" />';
$output .= ' <a href="#" class="help-btn ttt" data-title="'.$field['label'].'" data-content="'.$field['description'].'">?</a></td></tr>';
}
if($field['type']=='checkbox'){
$output .= '<tr '.($field['rowclass'] ? 'class="'.$field['rowclass'].'"': '').'><th><label for="'.$field['name'].'">'.$field['label'].'</label></th>';
$output .= '<td><input type="hidden" name="'.$field['name'].'" value="" /><input type="checkbox" id="'.$field['name'].'" name="'.$field['name'].'" value="'.$field['value'].'" '.$field['attr'].' />';
$output .= ' <a href="#" class="help-btn ttt" data-title="'.$field['label'].'" data-content="'.$field['description'].'">?</a></td></tr>';
}
if($field['type']=='checkboxgroup'){
$output .= '<tr '.($field['rowclass'] ? 'class="'.$field['rowclass'].'"': '').'><th><label>'.$field['grouplabel'].'</label></th>';
$output .= '<td>';
foreach($field['groupitem'] as $key=>$item){
$output .= '<input type="hidden" name="'.$item['name'].'" value="" /><input type="checkbox" id="'.$item['name'].'" name="'.$item['name'].'" value="'.$item['value'].'" '.$item['attr'].' /> <label for="'.$item['name'].'">'.$item['label'].'</label><br />';
}
$output .= ' <a href="#" class="help-btn ttt" data-title="'.$field['label'].'" data-content="'.$field['description'].'">?</a></td></tr>';
}
if($field['type'] == 'select'){
$output .= '<tr '.($field['rowclass'] ? 'class="'.$field['rowclass'].'"': '').'><th><label>'.$field['label'].'</label></th>';
$output .= '<td>';
$output .= '<select name="'.$field['name'].'">';
foreach( (array)$field['values'] as $val=>$name ) {
$output .= '<option '.(($val==$field['value']) ? 'selected="selected"' : '' ).' value="'.$val.'">'.$name.'</option>';
}
$output .= '</select>';
$output .= ' <a href="#" class="help-btn ttt" data-title="'.$field['label'].'" data-content="'.$field['description'].'">?</a></td></tr>';
}
}
$output .= '</table>';
return $output;
}
/**
* Register javascript
*/
function easy_table_script() {
if( is_single() AND in_array('is_single',$this->option('scriptloadin')) OR
is_page() AND in_array('is_page',$this->option('scriptloadin')) OR
is_home() AND in_array('is_home',$this->option('scriptloadin')) OR
is_archive() AND in_array('is_archive',$this->option('scriptloadin')) OR
is_search() AND in_array('is_search',$this->option('scriptloadin'))
)
{
if($this->option('tablesorter')) {
wp_enqueue_script('easy_table_script',plugins_url( 'js/easy-table-script.js' , __FILE__ ),array('jquery'),$this->easy_table_base('version'),$this->option('scriptinfooter'));
}
}
}
/**
* Register stylesheet
*/
function easy_table_style() {
if( is_single() AND in_array('is_single',$this->option('scriptloadin')) OR
is_page() AND in_array('is_page',$this->option('scriptloadin')) OR
is_home() AND in_array('is_home',$this->option('scriptloadin')) OR
is_archive() AND in_array('is_archive',$this->option('scriptloadin')) OR
is_search() AND in_array('is_search',$this->option('scriptloadin'))
)
{
if($this->option('loadcss')) {
wp_enqueue_style('easy_table_style', plugins_url('themes/'.$this->option('theme').'/style.css', __FILE__),false,$this->easy_table_base('version'));
}
}
}
function easy_table_admin_script(){
$page = isset($_GET['page']) ? $_GET['page'] : '';
if($page == $this->easy_table_base('plugin-domain')) {
if($this->option('tablesorter')) { ?>
<script src="<?php echo plugins_url( 'js/easy-table-script.js' , __FILE__);?>"></script>
<?php }
if($this->option('loadcss')) { ?>
<link rel="stylesheet" href="<?php echo plugins_url('themes/'.$this->option('theme').'/style.css?ver='.$this->easy_table_base('version'), __FILE__);?>" />
<?php } ?>
<link rel="stylesheet" href="<?php echo plugins_url( 'css/admin-style.css?ver='.$this->easy_table_base('version') , __FILE__);?>" />
<script src="<?php echo plugins_url( 'js/ttooltip/script/jquery-ttooltip.min.js' , __FILE__);?>"></script>
<link rel="stylesheet" href="<?php echo plugins_url( 'js/ttooltip/style/jquery-ttooltip.css?ver='.$this->easy_table_base('version') , __FILE__);?>" />
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
$('.ttt').ttooltip({
maxwidth:300,
timeout:500,
template:'<div class="ttooltip-wrap"><div class="ttooltip-arrow ttooltip-arrow-border"></div><div class="ttooltip-arrow"></div><div class="ttooltip-inner"><h3 class="ttooltip-title"></h3><div class="ttooltip-content"><p></p></div><div class="ttooltip-footer"></div></div></div>'
});
$('.togglethis a').click(function(e){
var target = $(this).attr('data-target');
$(target).toggle();
e.preventDefault();
});
});
//]]>
</script>
<?php
}
} /* end easy_table_admin_script*/
/**
* Add action link to plugins page
* from plugins listing.
*/
function easy_table_settings_link($links) {
$settings_link = '<a href="options-general.php?page='.$this->easy_table_base('plugin-domain').'">'.__('Settings','easy-table').'</a>';
array_unshift($links, $settings_link);
return $links;
}
/**
* Contextual help
*/
function easy_table_help($help) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
if($page == $this->easy_table_base('plugin-domain')) {
$help = '<h2>'.$this->easy_table_base('name').' '.$this->easy_table_base('version').'</h2>';
$help .= '<h5>'.__('Instruction','easy-table').':</h5>
<ol><li>'.__('Once plugin installed, go to plugin options page to configure some options','easy-table').'</li>';
$help .= '<li>'.__('You are ready to write a table in post or page.','easy-table').'</li>';
$help .= '<li>'.__('To be able write table in widget you have to check <em>Enable render table in widget</em> option in the option page.','easy-table').'</li></ol>';
return $help;
}
}
/**
* Add plugin page
*/
function easy_table_add_page() {
add_options_page($this->easy_table_base('name'), $this->easy_table_base('name'), 'administrator', $this->easy_table_base('plugin-domain'), array(&$this,'easy_table_page'));
}
/**
* Plugin option page
*/
function easy_table_page() { ?>
<div class="wrap easy-table-wrap">
<div class="icon32"><img src="<?php echo plugins_url('/images/icon-table.png', __FILE__);?>" /></div>
<h2 class="nav-tab-wrapper">
<a href="options-general.php?page=<?php echo $this->easy_table_base('plugin-domain');?>" class="nav-tab <?php echo !isset($_GET['gettab']) ? 'nav-tab-active' : '';?>"><?php printf(__('%s Option','easy-table'), $this->easy_table_base('name'));?></a>
<?php
/** currently not available
<a href="options-general.php?page=<?php echo $this->easy_table_base('plugin-domain');?>&gettab=themes" class="nav-tab <?php echo (isset($_GET['gettab']) AND ($_GET['gettab'] == 'themes')) ? 'nav-tab-active' : '';?>"><?php _e('Themes','easy-table');?></a>
*/?>
<a href="options-general.php?page=<?php echo $this->easy_table_base('plugin-domain');?>&gettab=support" class="nav-tab <?php echo (isset($_GET['gettab']) AND ($_GET['gettab'] == 'support')) ? 'nav-tab-active' : '';?>"><?php _e('Support','easy-table');?></a>
<a href="options-general.php?page=<?php echo $this->easy_table_base('plugin-domain');?>&gettab=about" class="nav-tab <?php echo (isset($_GET['gettab']) AND ($_GET['gettab'] == 'about')) ? 'nav-tab-active' : '';?>"><?php _e('About','easy-table');?></a>
</h2>
<?php if(!isset($_GET['gettab'])) : ?>
<div class="left">
<form method="post" action="options.php">
<?php
wp_nonce_field('update-options');
settings_fields('easy_table_option_field');
?>
<span class="togglethis toggledesc"><em><a href="#" data-target=".help-btn"><?php _e('Show/hide help button');?></a></em></span>
<h3><?php _e('General options','easy-table');?></h3>
<?php
$fields = Array(
Array(
'name' => 'easy_table_plugin_option[shortcodetag]',
'label' => __('Short code tag','easy-table'),
'type' => 'text',
'description' => __('Shortcode tag, type \'table\' if you want to use [table] short tag.','easy-table'),
'value' => $this->option('shortcodetag')
)
,
Array(
'name' => 'easy_table_plugin_option[attrtag]',
'label' => __('Cell attribute tag','easy-table'),
'type' => 'text',
'description' => __('Cell attribute tag, default is attr.','easy-table'),
'value' => $this->option('attrtag')
)
,Array(
'name' => 'easy_table_plugin_option[tablewidget]',
'label' => __('Also render table in widget?','easy-table'),
'type' => 'checkbox',
'description' => __('Check this if you want the table could be rendered in widget.','easy-table'),
'value' => 1,
'attr' => $this->option('tablewidget') ? 'checked="checked"' : '')
,Array(
'type' => 'checkboxgroup',
'grouplabel' => __('Only load JS/CSS when in this condition','easy-table'),
'description' => __('Please check in where JavaScript and CSS should be loaded','easy-table'),
'groupitem' => Array(
Array(
'name' => 'easy_table_plugin_option[scriptloadin][]',
'label' => __('Single','easy-table'),
'value' => 'is_single',
'attr' => in_array('is_single',$this->option('scriptloadin')) ? 'checked="checked"' : ''
),
Array(
'name' => 'easy_table_plugin_option[scriptloadin][]',
'label' => __('Page','easy-table'),
'value' => 'is_page',
'attr' => in_array('is_page',$this->option('scriptloadin')) ? 'checked="checked"' : ''
),
Array(
'name' => 'easy_table_plugin_option[scriptloadin][]',
'label' => __('Front page','easy-table'),
'value' => 'is_home',
'attr' => in_array('is_home',$this->option('scriptloadin')) ? 'checked="checked"' : ''
),
Array(
'name' => 'easy_table_plugin_option[scriptloadin][]',
'label' => __('Archive page','easy-table'),
'value' => 'is_archive',
'attr' => in_array('is_archive',$this->option('scriptloadin')) ? 'checked="checked"' : ''
),
Array(
'name' => 'easy_table_plugin_option[scriptloadin][]',
'label' => __('Search page','easy-table'),
'value' => 'is_search',
'attr' => in_array('is_search',$this->option('scriptloadin')) ? 'checked="checked"' : ''
)
)
)
,Array(
'name' => 'easy_table_plugin_option[scriptinfooter]',
'label' => __('Load script on footer?','easy-table'),
'type' => 'checkbox',
'description' => __('Check this if you want the script to be rendered in footer. Try to check or uncheck this if you experienced conflict with another JavaScript library (not guaranteed though).','easy-table'),
'value' => 1,
'attr' => $this->option('scriptinfooter') ? 'checked="checked"' : ''
)
);
echo $this->render_form($fields);
$fields = Array(
Array(
'name' => 'easy_table_plugin_option[tablesorter]',
'label' => __('Use tablesorter?','easy-table'),
'type' => 'checkbox',
'value' => 1,
'description' => __('Check this to use tablesorter jQuery plugin','easy-table'),
'attr' => $this->option('tablesorter') ? 'checked="checked"':'')
,Array(
'name' => 'easy_table_plugin_option[th]',
'label' => __('Use TH for the first row?','easy-table'),
'type' => 'checkbox',
'value' => 1,
'description' => __('Check this if you want to use first row as table head (required by tablesorter)','easy-table'),
'attr' => $this->option('th') ? 'checked="checked"' : '')
,Array(
'name' => 'easy_table_plugin_option[loadcss]',
'label' => __('Load CSS?','easy-table'),
'type' => 'checkbox',
'value' => 1,
'description' => __('Check this to use CSS included in this plugin to styling table, you may unceck if you want to write your own style.','easy-table'),
'attr' => $this->option('loadcss') ? 'checked="checked"':'')
,Array(
'name' => 'easy_table_plugin_option[class]',
'label' => __('Table class','easy-table'),
'type' => 'text',
'description' => __('Additional table class attribute.','easy-table'),
'value' => $this->option('class'))
,Array(
'name' => 'easy_table_plugin_option[width]',
'label' => __('Table width','easy-table'),
'type' => 'text',
'description' => __('Table width, in pixel or percent (may be overriden by CSS)','easy-table'),
'value' => $this->option('width'))
,Array(
'name' =>'easy_table_plugin_option[border]',
'label' => __('Table border','easy-table'),
'type' => 'text',
'description' => __('Table border (may be overriden by CSS)','easy-table'),
'value' => $this->option('border'))
);
?>
<h3><?php _e('Table options','easy-table');?></h3>
<?php
echo $this->render_form($fields);
?>
<h3><?php _e('Theme selector','easy-table');?></h3>
<?php
$fields = Array(
Array(
'name' => 'easy_table_plugin_option[theme]',
'label' => __('Default theme','easy-table'),
'type' => 'select',
'value' => $this->option('theme'),
'values' => array_combine($this->themes(),$this->themes()),
'description' => __('Select default theme of the table','easy-table')
)
);
echo $this->render_form($fields);
?>
<h3><?php _e('Data options','easy-table');?></h3>
<?php
$fields = Array(
Array(
'name' => 'easy_table_plugin_option[limit]',
'label' => __('Row limit','easy-table'),
'type' => 'text',
'value' => $this->option('limit'),
'rowclass' => 'new',
'description' =>__('Max row to convert to table, default 0 (unlimited)','easy-table')
),
Array(
'name' => 'easy_table_plugin_option[trim]',
'label' => __('Trim cell data?','easy-table'),
'type' => 'checkbox',
'value' => 1,
'attr' => $this->option('trim') ? 'checked="checked"':'',
'rowclass' => 'new',
'description' =>__('Trim empty character around cell data','easy-table')
),
);
echo $this->render_form($fields);
?>
<h3><?php _e('Parser options','easy-table');?></h3>
<p><em><?php _e('Do not change this unless you know what you\'re doing','easy-table');?></em>
</p>
<?php
$fields = Array(
Array(
'name' => 'easy_table_plugin_option[nl]',
'label' => __('New line replacement','easy-table'),
'type' => 'text',
'value' => $this->option('nl'),
'description' => __('Since new line is used by parser, you need specify character as a replacement.','easy-table'))
,Array(
'name' => 'easy_table_plugin_option[terminator]',
'label' => __('Row terminator','easy-table'),
'type' => 'text',
'value' => $this->option('terminator'),
'rowclass' => 'new',
'description' => __('This caharacter will converted into new row. Default value \n (this is invisible character when you press Enter). If your new line not converted as new row in the table, try use \r instead.','easy-table'))
,Array(
'name' => 'easy_table_plugin_option[delimiter]',
'label' => __('Delimiter','easy-table'),
'type' => 'text',
'value' => $this->option('delimiter'),
'description' => __('CSV delimiter (default is comma)','easy-table'))
,Array(
'name' => 'easy_table_plugin_option[enclosure]',
'label' => __('Enclosure','easy-table'),
'type' => 'text',
'value' => htmlentities($this->option('enclosure')),
'description' => __('CSV enclosure (default is double quote)','easy-table'))
,Array(
'name' => 'easy_table_plugin_option[escape]',
'label' => __('Escape','easy-table'),
'type' => 'text',
'value' => $this->option('escape'),
'description' =>__('CSV escape (default is backslash)','easy-table'))
,Array(
'name' => 'easy_table_plugin_option[csvfile]',
'label' => __('Allow read CSV from file?','easy-table'),
'type' => 'checkbox',
'value' => 1,
'description' => __('Check this if you also want to convert CSV file to table','easy-table'),
'attr' => $this->option('csvfile') ? 'checked="checked"' : '')
);
echo $this->render_form($fields);
?>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="easy_table_option_field" value="easy_table_plugin_option" />
<p><input type="submit" class="button-primary" value="<?php _e('Save','easy-table');?>" /> </p>
</form>
</div>
<div class="right">
<?php
$defaulttableexample = '
[table caption="Just test table" width="500" colwidth="20|100|50" colalign="left|left|center|left|right"]
no,head1,head2,head3,head4
1,row1col1,row1col2,row1col3,100
2,row2col1,row2col2,row2col3,20000
3,row3col1,,row3col3,1405
4,row4col1,row4col2,row4col3,23023
[/table] ';
$tableexample = $defaulttableexample;
if(isset($_POST['test-easy-table'])){
$tableexample = $_POST['easy-table-test-area'];
}
if(isset($_POST['test-easy-table-reset'])){
$tableexample = $defaulttableexample;
}
?>
<h3><?php _e('Possible parameter','easy-table');?></h3>
<p><?php _e('These parameters commonly can override global options in the left side of this page. Example usage:','easy-table');?></p>
<p> <code>[table param1="param-value1" param2="param-value2"]table data[/table]</code></p>
<ol>
<li><strong>class</strong>, <?php _e('default value','easy-table');?> <em>'table-striped'</em>, <?php _e('another value','easy-table');?> <em>table-bordered, table-striped, table-condensed</em></li>
<li><strong>caption</strong>,<?php _e('default value','easy-table');?> <em>''</em></li>
<li><strong>width</strong>, <?php _e('default value','easy-table');?> <em>'100%'</em></li>
<li><strong>align</strong>, <?php _e('default value','easy-table');?> <em>'left'</em></li>
<li><strong>th</strong>, <?php _e('default value','easy-table');?> <em>'true'</em></li>
<li><strong>tf</strong>, <?php _e('default value','easy-table');?> <em>'false'</em></li>
<li><strong>border</strong>, <?php _e('default value','easy-table');?> <em>'0'</em></li>
<li><strong>id</strong>, <?php _e('default value','easy-table');?> <em>'false'</em></li>
<li><strong>tablesorter</strong>, <?php _e('default value','easy-table');?> <em>'false'</em></li>
<li><strong>file</strong>, <?php _e('default value','easy-table');?> <em>'false'</em></li>
<li><strong>sort</strong>, <?php _e('default value','easy-table');?> <em>''</em></li>
<li class="new"><strong>trim</strong>, <?php _e('default value','easy-table');?> <em>false</em></li>
<li class="new"><strong>style</strong>, <?php _e('default value','easy-table');?> <em>''</em></li>
<li class="new"><strong>limit</strong>, <?php _e('default value','easy-table');?> <em>0</em></li>
<li class="new"><strong>terminator</strong>, <?php _e('default value','easy-table');?> <em>\n</em></li>
<li class="new"><strong>colalign</strong>, <?php _e('default value','easy-table');?> <em>''</em>, see example on the test area</li>
<li class="new"><strong>colwidth</strong>, <?php _e('default value','easy-table');?> <em>''</em>, see example on the test area</li>
</ol>
<h3><?php printf('Example usage of %s parameter','sort','easy-table');?></h3>
<p><em>sort</em> <?php _e('parameter is for initial sorting order. Value for each column separated by comma. See example below:','easy-table');?></p>
<ol>
<li><?php _e('Set initial order of first column descending and second column ascending:','easy-table');?>
<pre><code>[table sort="desc,asc"]
col1,col2,col3
col4,col5,col6
[/table]</code></pre>
</li>
<li><?php _e('Set initial order of second column descending:','easy-table');?>
<pre><code>[table sort=",desc,asc"]
col1,col2,col3
col4,col5,col6
[/table]</code></pre>
</li>
<li><?php _e('Additionaly, sort option also can be set via sort attr in a cell. See example below','easy-table');?></li>
</ol>
<h3><?php _e('Cell attribute tag','easy-table');?></h3>
<ol>
<li><p><strong>attr</strong>, <?php _e('To set attribute for cell eg. class, colspan, rowspan, etc','easy-table');?></p>
<p><?php _e('Example','easy-table');?>: </p>
<pre><code>[table]
col1,col2[attr style="width:200px" class="someclass"],col3
col4,col5,col6
[/table]
</code></pre>
</li>
<li><p><strong>attr sort</strong>, <?php _e('To set initial sort order, this is intended to TH (first row) only.','easy-table');?></p>
<p><?php _e('Example: sort second column descending ','easy-table');?> </p>
<pre><code>[table]
col1,col2[attr sort="desc"],col3
col4,col5,col6
[/table]
</code></pre>
<p><?php printf('To disable sort, use "%s". In the example below first column is not sortable','false','easy-table');?> </p>
<pre><code>[table]
col1[attr sort="false"],col2,col3
col4,col5,col6
[/table]
</code></pre>
</li>
</ol>
<h3><?php _e('Test area:','easy-table');?></h3>
<form action="" method="post">
<textarea name="easy-table-test-area" style="width:500px;height:200px;border:1px solid #ccc"><?php echo trim(htmlentities(stripslashes($tableexample)));?>
</textarea>
<input type="hidden" name="test-easy-table" value="1" />
<p><input class="button" type="submit" name="test-easy-table-reset" value="<?php _e('Reset','easy-table');?>" />
<input class="button-primary" type="submit" value="<?php _e('Update preview','easy-table');?> »" /></p></form>
<div>
<h3><?php _e('Preview','easy-table');?></h3>
<?php echo do_shortcode(stripslashes($tableexample));?>
</div>
</div>
<div class="clear"></div>
<?php elseif($_GET['gettab'] == 'themes') : ?>
<h3><?php _e('Easy Table theme editor');?></h3>
<div class="row">
<div class="columns nine">
<textarea name="" id="easy-table-theme-editor"><?php echo esc_textarea($this->theme_content());?></textarea>
<input type="submit" class="button primary" value="Save"/>
</div>
<div class="columns three">
<ul>
<?php
foreach($this->themes() as $theme) {
echo '
<li><a href="#">'.$theme.'</a>
<a href="options-general.php?page=easy-table&gettab=themes&edit='.$theme.'">edit</a>
<a href="&edit-theme=1&clone=1#">clone</a>
<a href="#">delete</a>
<a href="#">preview</a>
</li>';
}
?>
</ul>
<form action="">
New theme: <br/>
<input type="text" value="" placeholder="Theme name" name="themename"/>
<input type="submit" value="Create"/>
</form>
</div>
</div>
<?php elseif($_GET['gettab'] == 'support') : ?>
<p><?php _e('I have tried to make this plugin can be used as easy as possible and documentation as complete as possible. However it is also possible that you are still confused. Therefore feel free to ask. I would be happy to answer.','easy-table');?></p>
<p><?php _e('You can use this discussion to get support, request feature or reporting bug.','easy-table');?></p>
<p><a target="_blank" href="http://takien.com/plugins/easy-table"><?php _e('Before you ask something, make sure you have read documentation here!','easy-table');?></a></p>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* <![CDATA[ */
var disqus_url = 'http://takien.com/1126/easy-table-is-the-easiest-way-to-create-table-in-wordpress.php';
var disqus_identifier = '1126 http://takien.com/?p=1126';
var disqus_container_id = 'disqus_thread';