WP-Table Reloaded - Version 0.9.2

Version Description

Download this release

Release Info

Developer TobiasBg
Plugin Icon wp plugin WP-Table Reloaded
Version 0.9.2
Comparing to
See all releases

Version 0.9.2

css/admin-style.css ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ table.tb-wp-table-options td {
2
+ padding: 5px 0px 5px 0px;
3
+ }
4
+
5
+ table.tb-wp-table-options th {
6
+ font-weight: normal;
7
+ text-align: left;
8
+ padding: 5px 10px 5px 0px;
9
+ }
css/global-frontend-style.css ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Global CSS definitions for WP-Table Reloaded
2
+ inspired by "blue" theme of Tablesorter 2.0 Plugin
3
+ (won't be used unless option checked on plugin-options-screen!) */
4
+
5
+
6
+
7
+ /* general table styles */
8
+ table.wp-table-reloaded {
9
+ font-family:arial;
10
+ background-color: #CDCDCD;
11
+ margin:10px 0pt 15px;
12
+ font-size: 8pt;
13
+ width: 100%;
14
+ text-align: left;
15
+ }
16
+
17
+ /* Styles for the tablehead (<th>) (if enabled) */
18
+ table.wp-table-reloaded thead tr th, table.wp-table-reloaded tfoot tr th {
19
+ background-color: #e6EEEE;
20
+ border: 1px solid #FFF;
21
+ font-size: 8pt;
22
+ padding: 4px;
23
+ }
24
+
25
+ table.wp-table-reloaded thead tr .header {
26
+ background-image: url(../img/bg.gif);
27
+ background-repeat: no-repeat;
28
+ background-position: center right;
29
+ cursor: pointer;
30
+ }
31
+
32
+ table.wp-table-reloaded tbody td {
33
+ color: #3D3D3D;
34
+ padding: 4px;
35
+ background-color: #FFF;
36
+ vertical-align: top;
37
+ }
38
+
39
+
40
+ /* Styles for alternating row colors (if enabled) */
41
+ table.wp-table-reloaded tbody tr.even td {
42
+ background-color:#FFFFFF;
43
+ }
44
+ table.wp-table-reloaded tbody tr.odd td {
45
+ background-color:#F0F0F6;
46
+ }
47
+
48
+
49
+ /* Styles for the sorting (if Tablesorter is enabled) */
50
+ table.wp-table-reloaded thead tr .headerSortUp {
51
+ background-image: url(../img/asc.gif);
52
+ }
53
+
54
+ table.wp-table-reloaded thead tr .headerSortDown {
55
+ background-image: url(../img/desc.gif);
56
+ }
57
+
58
+ table.wp-table-reloaded thead tr .headerSortDown, table.wp-table-reloaded thead tr .headerSortUp {
59
+ background-color: #8dbdd8;
60
+ }
61
+
62
+
63
+ /* Style for the Table Name (in <h2>-Tag) (if printed above the table) */
64
+ h2.wp-table-reloaded-table-name {
65
+ font-size: 16px;
66
+ }
67
+
68
+ /* Style for the Table Description (if printed under the table) */
69
+ span.wp-table-reloaded-table-description {
70
+ font-size: 10px;
71
+ }
img/asc.gif ADDED
Binary file
img/bg.gif ADDED
Binary file
img/desc.gif ADDED
Binary file
js/jquery.tablesorter.min.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+
2
+ (function($){$.extend({tablesorter:new function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'.',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}var rows=table.tBodies[0].rows;if(table.tBodies[0].rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($($headers[i]).metadata()&&$($headers[i]).metadata().sorter)){p=getParserById($($headers[i]).metadata().sorter);}else if((table.config.headers[i]&&table.config.headers[i].sorter)){p=getParserById(table.config.headers[i].sorter);}if(!p){p=detectParserForColumn(table,cells[i]);}if(table.config.debug){parsersDebug+="column:"+i+" parser:"+p.id+"\n";}list.push(p);}}if(table.config.debug){log(parsersDebug);}return list;};function detectParserForColumn(table,node){var l=parsers.length;for(var i=1;i<l;i++){if(parsers[i].is($.trim(getElementText(table.config,node)),table,node)){return parsers[i];}}return parsers[0];}function getParserById(name){var l=parsers.length;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==name.toLowerCase()){return parsers[i];}}return false;}function buildCache(table){if(table.config.debug){var cacheTime=new Date();}var totalRows=(table.tBodies[0]&&table.tBodies[0].rows.length)||0,totalCells=(table.tBodies[0].rows[0]&&table.tBodies[0].rows[0].cells.length)||0,parsers=table.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<totalRows;++i){var c=table.tBodies[0].rows[i],cols=[];cache.row.push($(c));for(var j=0;j<totalCells;++j){cols.push(parsers[j].format(getElementText(table.config,c.cells[j]),table,c.cells[j]));}cols.push(i);cache.normalized.push(cols);cols=null;};if(table.config.debug){benchmark("Building cache for "+totalRows+" rows:",cacheTime);}return cache;};function getElementText(config,node){if(!node)return"";var t="";if(config.textExtraction=="simple"){if(node.childNodes[0]&&node.childNodes[0].hasChildNodes()){t=node.childNodes[0].innerHTML;}else{t=node.innerHTML;}}else{if(typeof(config.textExtraction)=="function"){t=config.textExtraction(node);}else{t=$(node).text();}}return t;}function appendToTable(table,cache){if(table.config.debug){var appendTime=new Date()}var c=cache,r=c.row,n=c.normalized,totalRows=n.length,checkCell=(n[0].length-1),tableBody=$(table.tBodies[0]),rows=[];for(var i=0;i<totalRows;i++){rows.push(r[n[i][checkCell]]);if(!table.config.appender){var o=r[n[i][checkCell]];var l=o.length;for(var j=0;j<l;j++){tableBody[0].appendChild(o[j]);}}}if(table.config.appender){table.config.appender(table,rows);}rows=null;if(table.config.debug){benchmark("Rebuilt table:",appendTime);}applyWidget(table);setTimeout(function(){$(table).trigger("sortEnd");},0);};function buildHeaders(table){if(table.config.debug){var time=new Date();}var meta=($.metadata)?true:false,tableHeadersRows=[];for(var i=0;i<table.tHead.rows.length;i++){tableHeadersRows[i]=0;};$tableHeaders=$("thead th",table);$tableHeaders.each(function(index){this.count=0;this.column=index;this.order=formatSortingOrder(table.config.sortInitialOrder);if(checkHeaderMetadata(this)||checkHeaderOptions(table,index))this.sortDisabled=true;if(!this.sortDisabled){$(this).addClass(table.config.cssHeader);}table.config.headerList[index]=this;});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders);}return $tableHeaders;};function checkCellColSpan(table,rows,row){var arr=[],r=table.tHead.rows,c=r[row].cells;for(var i=0;i<c.length;i++){var cell=c[i];if(cell.colSpan>1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(table);}}function getWidgetById(name){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==name.toLowerCase()){return widgets[i];}}};function formatSortingOrder(v){if(typeof(v)!="Number"){i=(v.toLowerCase()=="desc")?1:0;}else{i=(v==(0||1))?v:0;}return i;}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true;}}return false;}function setHeadersCss(table,$headers,list,css){$headers.removeClass(css[0]).removeClass(css[1]);var h=[];$headers.each(function(offset){if(!this.sortDisabled){h[this.column]=$(this);}});var l=list.length;for(var i=0;i<l;i++){h[list[i][0]].addClass(css[list[i][1]]);}}function fixColumnWidth(table,$headers){var c=table.config;if(c.widthFixed){var colgroup=$('<colgroup>');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('<col>').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i<l;i++){var s=sortList[i],o=c.headerList[s[0]];o.count=s[1];o.count++;}}function multisort(table,sortList,cache){if(table.config.debug){var sortTime=new Date();}var dynamicExp="var sortWrapper = function(a,b) {",l=sortList.length;for(var i=0;i<l;i++){var c=sortList[i][0];var order=sortList[i][1];var s=(getCachedSortType(table.config.parsers,c)=="text")?((order==0)?"sortText":"sortTextDesc"):((order==0)?"sortNumeric":"sortNumericDesc");var e="e"+i;dynamicExp+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";dynamicExp+="if("+e+") { return "+e+"; } ";dynamicExp+="else { ";}var orgOrderCol=cache.normalized[0].length-1;dynamicExp+="return a["+orgOrderCol+"]-b["+orgOrderCol+"];";for(var i=0;i<l;i++){dynamicExp+="}; ";}dynamicExp+="return 0; ";dynamicExp+="}; ";eval(dynamicExp);cache.normalized.sort(sortWrapper);if(table.config.debug){benchmark("Sorting on "+sortList.toString()+" and dir "+order+" time:",sortTime);}return cache;};function sortText(a,b){return((a<b)?-1:((a>b)?1:0));};function sortTextDesc(a,b){return((b<a)?-1:((b>a)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){$this.trigger("sortStart");var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){var $cell=$(this);var i=this.column;this.order=this.count++%2;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j]);}}}config.sortList.push([i,this.order]);}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2;}}}else{config.sortList.push([i,this.order]);}};setTimeout(function(){setHeadersCss($this[0],$headers,config.sortList,sortCSS);appendToTable($this[0],multisort($this[0],config.sortList,cache));},1);return false;}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false;}});$this.bind("update",function(){this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);}).bind("sorton",function(e,list){$(this).trigger("sortStart");config.sortList=list;var sortList=config.sortList;updateHeaderSortCount(this,sortList);setHeadersCss(this,$headers,sortList,sortCSS);appendToTable(this,multisort(this,sortList,cache));}).bind("appendCache",function(){appendToTable(this,cache);}).bind("applyWidgetId",function(e,id){getWidgetById(id).format(this);}).bind("applyWidgets",function(){applyWidget(this);});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist;}if(config.sortList.length>0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i<l;i++){if(parsers[i].id.toLowerCase()==parser.id.toLowerCase()){a=false;}}if(a){parsers.push(parser);};};this.addWidget=function(widget){widgets.push(widget);};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i;};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i;};this.isDigit=function(s,config){var DECIMAL='\\'+config.decimal;var exp='/(^[+]?0('+DECIMAL+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+DECIMAL+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+DECIMAL+'0+$)/';return RegExp(exp).test($.trim(s));};this.clearTableBody=function(table){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild);}empty.apply(table.tBodies[0]);}else{table.tBodies[0].innerHTML="";}};}});$.fn.extend({tablesorter:$.tablesorter.construct});var ts=$.tablesorter;ts.addParser({id:"text",is:function(s){return true;},format:function(s){return $.trim(s.toLowerCase());},type:"text"});ts.addParser({id:"digit",is:function(s,table){var c=table.config;return $.tablesorter.isDigit(s,c);},format:function(s){return $.tablesorter.formatFloat(s);},type:"numeric"});ts.addParser({id:"currency",is:function(s){return/^[£$€?.]/.test(s);},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""));},type:"numeric"});ts.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var item=a[i];if(item.length==2){r+="0"+item;}else{r+=item;}}return $.tablesorter.formatFloat(r);},type:"numeric"});ts.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s);},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''));},type:"text"});ts.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0");},type:"numeric"});ts.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s));},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""));},type:"numeric"});ts.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");}return $.tablesorter.formatFloat(new Date(s).getTime());},type:"numeric"});ts.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime());},type:"numeric"});ts.addParser({id:"metadata",is:function(s){return false;},format:function(s,table,cell){var c=table.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(cell).metadata()[p];},type:"numeric"});ts.addWidget({id:"zebra",format:function(table){if(table.config.debug){var time=new Date();}$("tr:visible",table.tBodies[0]).filter(':even').removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0]).end().filter(':odd').removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);if(table.config.debug){$.tablesorter.benchmark("Applying Zebra widget",time);}}});})(jQuery);
readme.txt ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP-Table Reloaded ===
2
+ Contributors: TobiasBg
3
+ Donate link:http://tobias.baethge.com/donate/
4
+ Tags: html,table,editor,csv,import,export,excel,admin
5
+ Requires at least: 2.5
6
+ Tested up to: 2.8-bleeding-edge
7
+ Stable tag: 0.9.2
8
+
9
+ This plugin allows you to create and manage tables in your WP's admin-area. You can then show them in your posts or on pages by using a shortcode.
10
+
11
+ == Description ==
12
+
13
+ This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin. You may also have both plugins installed at the same time!
14
+
15
+ More informatation: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
16
+
17
+ == Screenshots ==
18
+
19
+ 1. "List tables" screen
20
+ 2. "Add table" screen
21
+ 3. "Edit table" screen
22
+ 4. "Import table" screen
23
+ 5. "Export table" screen
24
+ 6. "Plugin Options" screen
25
+
26
+
27
+ == Installation ==
28
+
29
+ The easiest way would be through your WordPress Admin area. Go to the plugin section and search for "WP-Table Reloaded" in the WordPress Plugin Directory. Then you can click "Install now" and the following steps will be done for you automatically. You just have to activate the plugin (step 5).
30
+
31
+ Manual Installation works just as for most other WordPress plugins:
32
+
33
+ 1. Extract the zip file and just drop the folder "wp-table-reloaded" into the wp-content/plugins/ directory of your WordPress installation.
34
+
35
+ 1. Activate the Plugin "WP-Table Reloaded" on your "Plugins" page.
36
+
37
+ 1. Create and manage tables via "WP-Table Reloaded" in the "Tools" section.
38
+
39
+ 1. Include a table by adding the shortcode [table id=&lt;your-table's-id&gt; /] to your post or page.
40
+
41
+ 1. You might want to add styling features via your blog's theme's CSS file (probably style.css).
42
+
43
+
44
+ == Frequently Asked Questions ==
45
+
46
+ = Can I use WP-Table and WP-Table Reloaded together? =
47
+
48
+ Yes! You can have both WP-Table and WP-Table Reloaded installed in your WordPress! They will not interfere (as they are not using anything together). They are completely independent from each other. (At the moment, this also means that you can not edit/import your tables from WP-Table in WP-Table Reloaded. This might be included in future versions.)
49
+
50
+ = Support? =
51
+
52
+ If you experience trouble in using the plugin or find a bug, please don't hesitate to tell me about it. Right now the preferred way is the comments section of the [plugin page](http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/) (that way other users with the same problem could get help, too). I might add a support forum later. Till then you might also consider opening a new topic in the [WordPress Support Forums](http://wordpress.org/support/) and send me the link to your thread.
53
+
54
+ = Requirements? =
55
+
56
+ In short: WordPress 2.5 or higher
57
+
58
+ = Languages and Localization? =
59
+
60
+ As of the current version only the English language file is included.
61
+ The plugin is localization ready though (by using WordPress's localization features).
62
+
63
+ Upcoming versions will include (at least) German (by me), Turkish (thanks to Semih) and possibly Swedish (thanks to ZuperZed).
64
+
65
+ I'd really appreciate it, if you want to translate the plugin into your language! Using Heiko Rabe's WordPress plugin [Codestyling Localization](http://www.code-styling.de/english/development/wordpress-plugin-codestyling-localization-en) that really is as easy as pie. Just install the plugin, add your language, create the .po-file, translate the strings in the comfortable editor and create the .mo-file. It will automatically be saved in WP-Table Reloaded's plugin folder. If you send me the .mo- and .po-file, I will gladly include them into future plugin releases.
66
+
67
+ = Where can I get more information? =
68
+
69
+ Please visit the [official plugin website](http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/) for the latest information on this plugin.
70
+
71
+ == Usage ==
72
+
73
+ After installing the plugin, you can add, import, export, edit, copy, delete, ... tables via the "WP-Table Reloaded" screen which appears under the "Tools" section in your Admin menu.
74
+ Everything should be self-explaining there.
75
+ To show one of your tables in a post or on a page just include the shortcode [table id=&lt;the-id&gt; /] to your post/page, where &lt;the-id&gt is the ID of your table (can be found on the left side of the "List tables" screen.)
76
+ After that you might want to change the style of the table: Just edit the CSS-file "global-frontend-style.css" in the subfolder "css" of the plugin folder to fit your layout needs. Be sure to activate the option "Use global css-file?" in the plugin options for this to work!
77
+ You may also add certain features (like table-sorting, alternating row colors, print name and/or description, ...) by checking the appropriate options in the "Edit table" screen.
78
+
79
+
80
+ == Acknowledgements ==
81
+
82
+ Thanks go to [Alex Rabe](http://alexrabe.boelinger.com/) for the initial WP-Table plugin!
83
+
84
+ Thanks to every supporter and bug reporter!
85
+
86
+ == License ==
87
+
88
+ This plugins is Free Software, released under the GPL version 2.
89
+ You may use it free of charge for any purposes.
90
+ I kindly ask you for link somewhere on your website http://tobias.baethge.com/. This is not required!
91
+
92
+ == Changelog ==
93
+
94
+ * 0.9.2: fixed bug with plugin deactivation hook, added missing css-file
95
+ * 0.9.1: first good release with all mentioned functions working well
96
+ * 0.9 beta 1b: small bug which prevented showing of tables (but still not everything implemented)
97
+ * 0.9 beta 1: First release (not everything functional)
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file
screenshot-6.png ADDED
Binary file
wp-table-reloaded-admin.php ADDED
@@ -0,0 +1,1064 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ File Name: WP-Table Reloaded - Admin Class (see main file wp-table-reloaded.php)
4
+ Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
5
+ Description: This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.
6
+ Version: 0.9.2
7
+ Author: Tobias B&auml;thge
8
+ Author URI: http://tobias.baethge.com/
9
+ */
10
+
11
+ class WP_Table_Reloaded_Admin {
12
+
13
+ // ###################################################################################################################
14
+ var $plugin_version = '0.9.2';
15
+ // nonce for security of links/forms, try to prevent "CSRF"
16
+ var $nonce_base = 'wp-table-reloaded-nonce';
17
+ // names for the options which are stored in the WP database
18
+ var $optionname = array(
19
+ 'tables' => 'wp_table_reloaded_tables',
20
+ 'options' => 'wp_table_reloaded_options',
21
+ 'table' => 'wp_table_reloaded_data'
22
+ );
23
+ // allowed actions in this class
24
+ var $allowed_actions = array( 'list', 'add', 'edit', 'copy', 'delete', 'insert', 'import', 'export', 'options', 'uninstall', 'info' );
25
+
26
+ // init vars
27
+ var $tables = array();
28
+ var $options = array();
29
+
30
+ // default values, could be different in future plugin version
31
+ var $default_options = array(
32
+ 'installed_version' => '0',
33
+ 'uninstall_upon_deactivation' => false,
34
+ 'enable_tablesorter' => true,
35
+ 'use_global_css' => true,
36
+ 'last_id' => 0
37
+ );
38
+ var $default_tables = array();
39
+ var $default_table = array(
40
+ 'id' => 0,
41
+ 'data' => array( 0 => array( 0 => '' ) ),
42
+ 'name' => 'default',
43
+ 'description' => 'default',
44
+ 'options' => array(
45
+ 'alternating_row_colors' => true,
46
+ 'first_row_th' => true,
47
+ 'print_name' => false,
48
+ 'print_description' => false,
49
+ 'use_tablesorter' => true
50
+ )
51
+ );
52
+
53
+ // class instances
54
+ var $export_instance;
55
+ var $import_instance;
56
+
57
+ // ###################################################################################################################
58
+ // add admin-page to sidebar navigation, function called by PHP when class is constructed
59
+ function WP_Table_Reloaded_Admin() {
60
+ add_action( 'admin_menu', array( &$this, 'add_manage_page' ) );
61
+ }
62
+
63
+ // ###################################################################################################################
64
+ // add page, and what happens when page is loaded or shown
65
+ function add_manage_page() {
66
+ $hook = add_management_page( 'WP-Table Reloaded', 'WP-Table Reloaded', 'manage_options', 'wp_table_reloaded_manage_page', array( &$this, 'show_manage_page' ) );
67
+ add_action('load-' . $hook, array( &$this, 'load_manage_page' ) );
68
+ }
69
+
70
+ // ###################################################################################################################
71
+ // only load the scripts, stylesheets and language by hook, if this admin page will be shown
72
+ // all of this will be done before the page is shown by show_manage_page()
73
+ function load_manage_page() {
74
+ // load css
75
+ $this->add_manage_page_css();
76
+
77
+ // init language support (add later)
78
+ define( 'WP_TABLE_RELOADED_TEXTDOMAIN', 'wp-table-reloaded' );
79
+ $this->init_language_support();
80
+
81
+ // init plugin (means: load plugin options and existing tables)
82
+ $this->init_plugin();
83
+ }
84
+
85
+ // ###################################################################################################################
86
+ function show_manage_page() {
87
+ // get and check action parameter from passed variables
88
+ $action = ( isset( $_REQUEST['action'] ) and !empty( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : 'list';
89
+ // check if action is in allowed actions and if method is callable, if yes, call it
90
+ if ( in_array( $action, $this->allowed_actions ) && is_callable( array( &$this, 'do_action_' . $action ) ) )
91
+ call_user_func( array( &$this, 'do_action_' . $action ) );
92
+ else
93
+ call_user_func( array( &$this, 'do_action_list' ) );
94
+ }
95
+
96
+ // ###################################################################################################################
97
+ // ########################################## ######################################################
98
+ // ########################################## ACTIONS ######################################################
99
+ // ########################################## ######################################################
100
+ // ###################################################################################################################
101
+ // list all tables
102
+ function do_action_list() {
103
+ $this->print_list_tables_form();
104
+ }
105
+
106
+ // ###################################################################################################################
107
+ function do_action_add() {
108
+ if ( isset( $_POST['submit'] ) && isset( $_POST['table'] ) ) {
109
+ check_admin_referer( $this->get_nonce( 'add' ) );
110
+
111
+ $rows = ( 0 < $_POST['table']['rows'] ) ? $_POST['table']['rows'] : 1;
112
+ $cols = ( 0 < $_POST['table']['cols'] ) ? $_POST['table']['cols'] : 1;
113
+
114
+ $table = $this->default_table;
115
+
116
+ $table['id'] = $this->get_new_table_id();
117
+ $table['data'] = $this->create_empty_table( $rows, $cols );
118
+ $table['name'] = $_POST['table']['name'];
119
+ $table['description'] = $_POST['table']['description'];
120
+
121
+ $this->save_table( $table );
122
+
123
+ $this->print_success_message( sprintf( __( 'Table "%s" added successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->safe_output( $table['name'] ) ) );
124
+ $this->print_edit_table_form( $table['id'] );
125
+ } else
126
+ $this->print_add_table_form();
127
+ }
128
+
129
+ // ###################################################################################################################
130
+ function do_action_edit() {
131
+ if ( isset( $_POST['submit'] ) && isset( $_POST['table'] ) ) {
132
+ check_admin_referer( $this->get_nonce( 'edit' ) );
133
+
134
+ $subactions = array_keys( $_POST['submit'] );
135
+ $subaction = $subactions[0];
136
+
137
+ switch( $subaction ) {
138
+ case 'update':
139
+ case 'save_back':
140
+ $table = $_POST['table']; // careful here to not miss any stuff!!! (options, etc.)
141
+ $table['options']['alternating_row_colors'] = isset( $_POST['table']['options']['alternating_row_colors'] );
142
+ $table['options']['first_row_th'] = isset( $_POST['table']['options']['first_row_th'] );
143
+ $table['options']['print_name'] = isset( $_POST['table']['options']['print_name'] );
144
+ $table['options']['print_description'] = isset( $_POST['table']['options']['print_description'] );
145
+ $this->save_table( $table );
146
+ $message = __( 'Table edited successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
147
+ break;
148
+ case 'swap_rows':
149
+ $table_id = $_POST['table']['id'];
150
+ $row_id1 = ( isset( $_POST['swap']['row'][1] ) ) ? $_POST['swap']['row'][1] : -1;
151
+ $row_id2 = ( isset( $_POST['swap']['row'][2] ) ) ? $_POST['swap']['row'][2] : -1;
152
+ $table = $this->load_table( $table_id );
153
+ $rows = count( $table['data'] );
154
+ // swap rows $row_id1 and $row_id2
155
+ if ( ( 1 < $rows ) && ( -1 < $row_id1 ) && ( -1 < $row_id2 ) ) {
156
+ $temp_row = $table['data'][$row_id1];
157
+ $table['data'][$row_id1] = $table['data'][$row_id2];
158
+ $table['data'][$row_id2] = $temp_row;
159
+ unset($temp_row);
160
+ }
161
+ $this->save_table( $table );
162
+ $message = __( 'Rows swapped successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
163
+ break;
164
+ case 'swap_cols':
165
+ $table_id = $_POST['table']['id'];
166
+ $col_id1 = ( isset( $_POST['swap']['col'][1] ) ) ? $_POST['swap']['col'][1] : -1;
167
+ $col_id2 = ( isset( $_POST['swap']['col'][2] ) ) ? $_POST['swap']['col'][2] : -1;
168
+ $table = $this->load_table( $table_id );
169
+ $rows = count( $table['data'] );
170
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
171
+ // swap rows $col_id1 and $col_id2
172
+ if ( ( 1 < $cols ) && ( -1 < $col_id1 ) && ( -1 < $col_id2 ) ) {
173
+ foreach( $table['data'] as $row_idx => $row) {
174
+ $temp_col = $table['data'][$row_idx][$col_id1];
175
+ $table['data'][$row_idx][$col_id1] = $table['data'][$row_idx][$col_id2];
176
+ $table['data'][$row_idx][$col_id2] = $temp_col;
177
+ }
178
+ unset($temp_col);
179
+ }
180
+ $this->save_table( $table );
181
+ $message = __( 'Columns swapped successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
182
+ break;
183
+ default:
184
+ $this->do_action_list();
185
+ }
186
+
187
+ $this->print_success_message( $message );
188
+ if ( 'save_back' == $subaction ) {
189
+ $this->do_action_list();
190
+ } else {
191
+ $this->print_edit_table_form( $table['id'] );
192
+ }
193
+ } elseif ( isset( $_GET['table_id'] ) ) {
194
+ $this->print_edit_table_form( $_GET['table_id'] );
195
+ } else {
196
+ $this->do_action_list();
197
+ }
198
+ }
199
+
200
+ // ###################################################################################################################
201
+ function do_action_copy() {
202
+ if ( isset( $_GET['table_id'] ) ) {
203
+ check_admin_referer( $this->get_nonce( 'copy' ) );
204
+
205
+ $table_to_copy = $this->load_table( $_GET['table_id'] );
206
+
207
+ // new table
208
+ $new_table = $table_to_copy;
209
+ $new_table['id'] = $this->get_new_table_id();
210
+ unset( $table_to_copy );
211
+
212
+ $this->save_table( $new_table );
213
+
214
+ $this->print_success_message( sprintf( __( 'Table "%s" copied successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->safe_output( $new_table['name'] ) ) );
215
+ }
216
+ $this->do_action_list();
217
+ }
218
+
219
+ // ###################################################################################################################
220
+ function do_action_delete() {
221
+ if ( isset( $_GET['table_id'] ) && isset( $_GET['item'] ) ) {
222
+ check_admin_referer( $this->get_nonce( 'delete', $_GET['item'] ) );
223
+
224
+ $table_id = $_GET['table_id'];
225
+ $table = $this->load_table( $table_id );
226
+
227
+ switch( $_GET['item'] ) {
228
+ case 'table':
229
+ $this->tables[ $table_id ] = ( isset( $this->tables[ $table_id ] ) ) ? $this->tables[ $table_id ] : $this->optionname['table'] . '_' . $table_id;
230
+ delete_option( $this->tables[ $table_id ] );
231
+ unset( $this->tables[ $table_id ] );
232
+ $this->update_tables();
233
+ $this->print_success_message( sprintf( __( 'Table "%s" deleted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->safe_output( $table['name'] ) ) );
234
+ $this->do_action_list();
235
+ break;
236
+ case 'row':
237
+ $row_id = ( isset( $_GET['element_id'] ) ) ? $_GET['element_id'] : -1;
238
+ $rows = count( $table['data'] );
239
+ // delete row with key $row_id, if there are at least 2 rows
240
+ if ( ( 1 < $rows ) && ( -1 < $row_id ) ) {
241
+ array_splice( $table['data'], $row_id, 1 );
242
+ $this->save_table( $table );
243
+ $this->print_success_message( __( 'Row deleted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
244
+ }
245
+ $this->print_edit_table_form( $table_id );
246
+ break;
247
+ case 'col':
248
+ $col_id = ( isset( $_GET['element_id'] ) ) ? $_GET['element_id'] : -1;
249
+ $rows = count( $table['data'] );
250
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
251
+ // delete column with key $col_id, if there are at least 2 columns
252
+ if ( ( 1 < $cols ) && ( -1 < $col_id ) ) {
253
+ foreach( $table['data'] as $row_idx => $row)
254
+ array_splice( $table['data'][$row_idx], $col_id, 1 );
255
+ $this->save_table( $table );
256
+ $this->print_success_message( __( 'Column deleted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
257
+ }
258
+ $this->print_edit_table_form( $table_id );
259
+ break;
260
+ default:
261
+ $this->print_success_message( __( 'Delete failed.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
262
+ $this->do_action_list();
263
+ } // end switch
264
+ } else
265
+ $this->do_action_list();
266
+ }
267
+
268
+ // ###################################################################################################################
269
+ function do_action_insert() {
270
+ if ( isset( $_GET['table_id'] ) && isset( $_GET['item'] ) && isset( $_GET['element_id'] ) ) {
271
+ check_admin_referer( $this->get_nonce( 'insert', $_GET['item'] ) );
272
+
273
+ $table_id = $_GET['table_id'];
274
+ $table = $this->load_table( $table_id );
275
+
276
+ switch( $_GET['item'] ) {
277
+ case 'row':
278
+ $row_id = $_GET['element_id'];
279
+ $rows = count( $table['data'] );
280
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
281
+ // init new empty row (with all columns) and insert it before row with key $row_id
282
+ $new_row = array( array_fill( 0, $cols, '' ) );
283
+ array_splice( $table['data'], $row_id, 0, $new_row );
284
+ $this->save_table( $table );
285
+ $message = __( 'Row inserted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
286
+ break;
287
+ case 'col':
288
+ $col_id = $_GET['element_id'];
289
+ // init new empty row (with all columns) and insert it before row with key $row_id
290
+ $new_col = '';
291
+ foreach( $table['data'] as $row_idx => $row)
292
+ array_splice( $table['data'][$row_idx], $col_id, 0, $new_col );
293
+ $this->save_table( $table );
294
+ $message = __( 'Column inserted successfully.', WP_TABLE_RELOADED_TEXTDOMAIN );
295
+ break;
296
+ default:
297
+ $message = __( 'Insert failed.', WP_TABLE_RELOADED_TEXTDOMAIN );
298
+ }
299
+ $this->print_success_message( $message );
300
+ $this->print_edit_table_form( $table_id );
301
+ } else
302
+ $this->do_action_list();
303
+ }
304
+
305
+ // ###################################################################################################################
306
+ function do_action_import() {
307
+ $this->import_instance = $this->create_class_instance( 'WP_Table_Reloaded_Import', 'wp-table-reloaded-import.php' );
308
+ if ( isset( $_POST['submit'] ) && isset( $_FILES['import_file'] ) ) {
309
+ check_admin_referer( $this->get_nonce( 'import' ) );
310
+
311
+ // do import
312
+
313
+ $this->import_instance->tempname = $_FILES['import_file']['tmp_name'];
314
+ $this->import_instance->filename = $_FILES['import_file']['name'];
315
+ $this->import_instance->mimetype = $_FILES['import_file']['type'];
316
+ $this->import_instance->delimiter = $_POST['delimiter'];
317
+ $this->import_instance->import_table();
318
+ $imported_table = $this->import_instance->imported_table;
319
+ $this->import_instance->unlink_csv_file();
320
+
321
+ $table = array_merge( $this->default_table, $imported_table );
322
+
323
+ $table['id'] = $this->get_new_table_id();
324
+
325
+ $this->save_table( $table );
326
+
327
+ $this->print_success_message( __( 'Table imported successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
328
+ $this->print_edit_table_form( $table['id'] );
329
+ } else
330
+ $this->print_import_table_form();
331
+ }
332
+
333
+ // ###################################################################################################################
334
+ function do_action_export() {
335
+ $this->export_instance = $this->create_class_instance( 'WP_Table_Reloaded_Export', 'wp-table-reloaded-export.php' );
336
+ if ( isset( $_POST['submit'] ) && isset( $_POST['table_id'] ) && isset( $_POST['export_format'] ) ) {
337
+ check_admin_referer( $this->get_nonce( 'export' ) );
338
+
339
+ $table_to_export = $this->load_table( $_POST['table_id'] );
340
+
341
+ $this->export_instance->table_to_export = $table_to_export;
342
+ $this->export_instance->export_format = $_POST['export_format'];
343
+ $this->export_instance->delimiter = $_POST['delimiter'];
344
+ $this->export_instance->export_table();
345
+ $exported_table = $this->export_instance->exported_table;
346
+
347
+ $this->print_success_message( sprintf( __( 'Table "%s" exported successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ), $this->safe_output( $table_to_export['name'] ) ) );
348
+ $this->print_export_table_form( $_POST['table_id'], $exported_table );
349
+ } else {
350
+ $this->print_export_table_form( $_REQUEST['table_id'] );
351
+ }
352
+ }
353
+
354
+ // ###################################################################################################################
355
+ function do_action_options() {
356
+ if ( isset( $_POST['submit'] ) && isset( $_POST['options'] ) ) {
357
+ check_admin_referer( $this->get_nonce( 'options' ) );
358
+
359
+ $new_options = $_POST['options'];
360
+ // checkboxes: option value is defined by whether option isset (e.g. was checked) or not
361
+ $this->options['uninstall_upon_deactivation'] = isset( $new_options['uninstall_upon_deactivation'] );
362
+ $this->options['enable_tablesorter'] = isset( $new_options['enable_tablesorter'] );
363
+ $this->options['use_global_css'] = isset( $new_options['use_global_css'] );
364
+ $this->update_options();
365
+
366
+ $this->print_success_message( __( 'Options saved successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
367
+ }
368
+ $this->print_plugin_options_form();
369
+ }
370
+
371
+ // ###################################################################################################################
372
+ function do_action_uninstall() {
373
+ check_admin_referer( $this->get_nonce( 'uninstall' ) );
374
+ $this->plugin_uninstall();
375
+ $this->print_success_message( __( 'Plugin uninstalled successfully.', WP_TABLE_RELOADED_TEXTDOMAIN ) );
376
+ }
377
+
378
+ // ###################################################################################################################
379
+ function do_action_info() {
380
+ $this->print_plugin_info_form();
381
+ }
382
+
383
+ // ###################################################################################################################
384
+ // ########################################## ####################################################
385
+ // ########################################## Print Forms ####################################################
386
+ // ########################################## ####################################################
387
+ // ###################################################################################################################
388
+
389
+ // list all tables
390
+ function print_list_tables_form() {
391
+ $this->print_page_header( __( 'List of Tables', WP_TABLE_RELOADED_TEXTDOMAIN ) );
392
+ $this->print_submenu_navigation( 'list' );
393
+ ?>
394
+ <div style="clear:both;"><p><?php _e( 'This is a list of all available tables. You may add, edit, copy or delete tables here.', WP_TABLE_RELOADED_TEXTDOMAIN ) ?><br />
395
+ <?php _e( 'If you want to show a table in your pages or posts, use the shortcode: <strong>[table id=&lt;the_table_ID&gt; /]</strong>', WP_TABLE_RELOADED_TEXTDOMAIN ) ?></p></div>
396
+ <?php
397
+ if ( 0 < count($this->tables) ) {
398
+ ?>
399
+ <div style="clear:both;">
400
+ <table class="widefat">
401
+ <thead>
402
+ <tr>
403
+ <th scope="col"><?php _e( 'ID', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></th>
404
+ <th scope="col"><?php _e( 'Table Name', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></th>
405
+ <th scope="col"><?php _e( 'Description', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></th>
406
+ <th scope="col"><?php _e( 'Action', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></th>
407
+ </tr>
408
+ </thead>
409
+ <tbody>
410
+ <?php
411
+ $bg_style_index = 0;
412
+ foreach ( $this->tables as $id => $tableoptionname ) {
413
+ $bg_style_index++;
414
+ $bg_style = ( 0 == ($bg_style_index % 2) ) ? ' class="alternate"' : '';
415
+
416
+ // get name and description to show in list
417
+ $table = $this->load_table( $id );
418
+ $name = $this->safe_output( $table['name'] );
419
+ $description = $this->safe_output( $table['description'] );
420
+ unset( $table );
421
+
422
+ $edit_url = $this->get_action_url( array( 'action' => 'edit', 'table_id' => $id ), false );
423
+ $copy_url = $this->get_action_url( array( 'action' => 'copy', 'table_id' => $id ), true );
424
+ $export_url = $this->get_action_url( array( 'action' => 'export', 'table_id' => $id ), false );
425
+ $delete_url = $this->get_action_url( array( 'action' => 'delete', 'table_id' => $id, 'item' => 'table' ), true );
426
+
427
+ echo "<tr{$bg_style}>\n";
428
+ echo "\t<th scope=\"row\">{$id}</th>";
429
+ echo "<td>{$name}</td>";
430
+ echo "<td>{$description}</td>";
431
+ echo "<td><a href=\"{$edit_url}\">" . __( 'Edit', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>" . " | ";
432
+ echo "<a href=\"{$copy_url}\" onclick=\"javascript:return confirm( '".__( 'Do you want to copy this table?', WP_TABLE_RELOADED_TEXTDOMAIN )."' );\">" . __( 'Copy', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>" . " | ";
433
+ echo "<a href=\"{$export_url}\">" . __( 'Export', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>" . " | ";
434
+ echo "<a href=\"{$delete_url}\" class=\"delete\" onclick=\"javascript:return confirm( '".__( 'The complete table and all content will be erased. Do you really want to delete it?', WP_TABLE_RELOADED_TEXTDOMAIN )."' );\">" . __( 'Delete', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a></td>\n";
435
+ echo "</tr>\n";
436
+
437
+ }
438
+ echo "</tbody>\n";
439
+ echo "</table>\n";
440
+ echo "</div>";
441
+ } else { // end if $tables
442
+ $add_url = $this->get_action_url( array( 'action' => 'add' ), false );
443
+ $import_url = $this->get_action_url( array( 'action' => 'import' ), false );
444
+ echo "<div style=\"clear:both;\"><p>" . __( 'No tables found.', WP_TABLE_RELOADED_TEXTDOMAIN ) . '<br/>' . sprintf( __( 'You might <a href="%s">add</a> or <a href="%s">import</a> one!', WP_TABLE_RELOADED_TEXTDOMAIN ), $add_url, $import_url ) . "</p></div>";
445
+ }
446
+ $this->print_page_footer();
447
+ }
448
+
449
+ // ###################################################################################################################
450
+ function print_add_table_form() {
451
+ // Begin Add Table Form
452
+ $this->print_page_header( __( 'Add new Table', WP_TABLE_RELOADED_TEXTDOMAIN ) );
453
+ $this->print_submenu_navigation( 'add' );
454
+ ?>
455
+ <p></p>
456
+ <div style="clear:both;"><p>
457
+ <?php _e( 'You can add a new table here. Just enter it\'s name, a description (optional) and the number of rows and columns.<br/>You may add, insert or delete rows and columns later.', WP_TABLE_RELOADED_TEXTDOMAIN ) ?><br />
458
+ </p></div>
459
+ <div style="clear:both;">
460
+ <form method="post" action="<?php echo $this->get_action_url(); ?>">
461
+ <?php wp_nonce_field( $this->get_nonce( 'add' ) ); ?>
462
+
463
+ <table class="tb-wp-table-options">
464
+ <tr valign="top">
465
+ <th scope="row"><label for="table[name]"><?php _e( 'Table Name', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
466
+ <td><input type="text" name="table[name]" value="<?php echo _c( 'Enter Table Name|Default Table Name', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>" style="width:250px;" /></td>
467
+ </tr>
468
+ <tr valign="top">
469
+ <th scope="row"><label for="table[description]"><?php _e( 'Description', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
470
+ <td><textarea name="table[description]" id="table[description]" style="width:250px;height:85px;"><?php echo _c( 'Enter Description|Default Table Description', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></textarea></td>
471
+ </tr>
472
+ <tr valign="top">
473
+ <th scope="row"><label for="table[rows]"><?php _e( 'Number of Rows', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
474
+ <td><input type="text" name="table[rows]" id="table[rows]" value="5" /></td>
475
+ </tr>
476
+ <tr valign="top">
477
+ <th scope="row"><label for="table[cols]"><?php _e( 'Number of Columns', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
478
+ <td><input type="text" name="table[cols]" id="table[cols]" value="5" /></td>
479
+ </tr>
480
+ </table>
481
+
482
+ <input type="hidden" name="action" value="add" />
483
+ <p class="submit">
484
+ <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Add Table', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
485
+ </p>
486
+
487
+ </form>
488
+ </div>
489
+ <?php
490
+ $this->print_page_footer();
491
+ }
492
+
493
+ // ###################################################################################################################
494
+ function print_edit_table_form( $table_id ) {
495
+
496
+ $table = $this->load_table( $table_id );
497
+
498
+ $rows = count( $table['data'] );
499
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
500
+
501
+ $this->print_page_header( __( sprintf( 'Edit Table "%s"', $this->safe_output( $table['name'] ) ), WP_TABLE_RELOADED_TEXTDOMAIN ) );
502
+ $this->print_submenu_navigation( 'edit' );
503
+ ?><div style="clear:both;"><p><?php _e( 'You may edit the content of the table here. It is also possible to add or delete columns and rows.', WP_TABLE_RELOADED_TEXTDOMAIN ) ?><br />
504
+ <?php _e( sprintf( 'If you want to show a table in your pages or posts, use this shortcode: <strong>[table id=%s /]</strong>', $this->safe_output( $table_id ) ), WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p></div>
505
+ <form method="post" action="<?php echo $this->get_action_url(); ?>">
506
+ <?php wp_nonce_field( $this->get_nonce( 'edit' ) ); ?>
507
+
508
+ <div style="clear:both;">
509
+ <h3><?php _e( 'Table Information', WP_TABLE_RELOADED_TEXTDOMAIN ) ?></h3>
510
+ <table class="tb-wp-table-options">
511
+ <tr valign="top">
512
+ <th scope="row"><label for="table[name]"><?php _e( 'Table Name', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
513
+ <td><input type="text" name="table[name]" id="table[name]" value="<?php echo $this->safe_output( $table['name'] ); ?>" style="width:250px" /></td>
514
+ </tr>
515
+ <tr valign="top">
516
+ <th scope="row"><label for="table[description]"><?php _e( 'Description', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
517
+ <td><textarea name="table[description]" id="table[description]" style="width:250px;height:85px;"><?php echo $this->safe_output( $table['description'] ); ?></textarea></td>
518
+ </tr>
519
+ </table>
520
+ </div>
521
+ <div style="clear:both;">
522
+ <?php if ( 0 < $cols && 0 < $rows ) { ?>
523
+ <h3><?php _e( 'Table Contents', WP_TABLE_RELOADED_TEXTDOMAIN ) ?></h3>
524
+ <table class="widefat" style="width:auto;">
525
+ <thead>
526
+ <tr>
527
+ <th>&nbsp;</th>
528
+ <?php
529
+ // Table Header (Columns get a Letter between A and A+$cols-1)
530
+ foreach ( range( 'A', chr( ord( 'A' ) + $cols - 1 ) ) as $letter)
531
+ echo "<th scope=\"col\">".$letter."</th>";
532
+ ?>
533
+ <th>&nbsp;</th>
534
+ </tr>
535
+ </thead>
536
+ <tbody>
537
+ <?php
538
+ foreach( $table['data'] as $row_idx => $table_row ) {
539
+ echo "<tr>\n";
540
+ // Table Header (Rows get a Number between 1 and $rows)
541
+ $output_idx = $row_idx + 1;
542
+ echo "\t<th scope=\"row\">{$output_idx}</th>\n";
543
+ foreach( $table_row as $col_idx => $cell_content ) {
544
+ $cell_content = $this->safe_output( $cell_content );
545
+ $cell_name = "table[data][{$row_idx}][{$col_idx}]";
546
+ echo "\t<td><input type=\"text\" name=\"{$cell_name}\" value=\"{$cell_content}\" /></td>\n";
547
+ }
548
+ $insert_row_url = $this->get_action_url( array( 'action' => 'insert', 'table_id' => $table['id'], 'item' => 'row', 'element_id' => $row_idx ), true );
549
+ $delete_row_url = $this->get_action_url( array( 'action' => 'delete', 'table_id' => $table['id'], 'item' => 'row', 'element_id' => $row_idx ), true );
550
+ echo "\t<td><a href=\"{$insert_row_url}\">" . __( 'Insert Row', WP_TABLE_RELOADED_TEXTDOMAIN )."</a>";
551
+ if ( 1 < $rows ) // don't show delete link for last and only row
552
+ echo " | <a href=\"{$delete_row_url}\" onclick=\"javascript:return confirm( '".__( 'Do you really want to delete this row?', WP_TABLE_RELOADED_TEXTDOMAIN )."' );\">".__( 'Delete Row', WP_TABLE_RELOADED_TEXTDOMAIN )."</a>";
553
+ echo "</td>\n</tr>";
554
+ }
555
+ ?>
556
+ <?php
557
+ echo "<tr>\n";
558
+ echo "\t<th scope=\"row\">&nbsp;</th>\n";
559
+ foreach( $table['data'][0] as $col_idx => $cell_content ) {
560
+ $insert_col_url = $this->get_action_url( array( 'action' => 'insert', 'table_id' => $table['id'], 'item' => 'col', 'element_id' => $col_idx ), true );
561
+ $delete_col_url = $this->get_action_url( array( 'action' => 'delete', 'table_id' => $table['id'], 'item' => 'col', 'element_id' => $col_idx ), true );
562
+ echo "\t<td><a href=\"{$insert_col_url}\">" . __( 'Insert Column', WP_TABLE_RELOADED_TEXTDOMAIN )."</a>";
563
+ if ( 1 < $cols ) // don't show delete link for last and only column
564
+ echo " | <a href=\"{$delete_col_url}\" onclick=\"javascript:return confirm( '" . __( 'Do you really want to delete this column?', WP_TABLE_RELOADED_TEXTDOMAIN )."' );\">" . __('Delete Column', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>";
565
+ echo "</td>\n";
566
+ }
567
+ $add_row_url = $this->get_action_url( array( 'action' => 'insert', 'table_id' => $table['id'],'item' => 'row', 'element_id' => $rows ), true ); // number of $rows is equal to new row's id
568
+ $add_col_url = $this->get_action_url( array( 'action' => 'insert', 'table_id' => $table['id'],'item' => 'col', 'element_id' => $cols ), true ); // number of $cols is equal to new col's id
569
+ echo "\t<td><a href=\"{$add_row_url}\">" . __( 'Add Row', WP_TABLE_RELOADED_TEXTDOMAIN )."</a> | <a href=\"{$add_col_url}\">" . __( 'Add Column', WP_TABLE_RELOADED_TEXTDOMAIN )."</a></td>\n";
570
+ echo "</tr>";
571
+ ?>
572
+ </tbody>
573
+ </table>
574
+ <?php } //endif ?>
575
+ </div>
576
+ <div style="clear:both;">
577
+ <?php if ( 1 < $rows ) { // swap rows form?>
578
+ <br/>
579
+ <?php _e( 'Swap rows', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>
580
+ <select name="swap[row][1]">
581
+ <?php foreach( $table['data'] as $row_idx => $table_row )
582
+ echo "<option value=\"{$row_idx}\">" . ( $row_idx + 1 ) . "</option>"; ?>
583
+ </select>
584
+ <?php _e( 'and', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>
585
+ <select name="swap[row][2]">
586
+ <?php foreach( $table['data'] as $row_idx => $table_row )
587
+ echo "<option value=\"{$row_idx}\">" . ( $row_idx + 1 ) . "</option>"; ?>
588
+ </select>
589
+ <input type="submit" name="submit[swap_rows]" class="button-primary" value="<?php _e( 'Swap', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
590
+ <?php } // end if form swap rows ?>
591
+
592
+ <?php if ( 1 < $cols ) { // swap cols form ?>
593
+ <br/>
594
+ <?php _e( 'Swap columns', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>
595
+ <select name="swap[col][1]">
596
+ <?php foreach( $table['data'][0] as $col_idx => $cell_content )
597
+ echo "<option value=\"{$col_idx}\">" . ( chr( ord( 'A' ) + $col_idx ) ) . "</option>"; ?>
598
+ </select>
599
+ <?php _e( 'and', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>
600
+ <select name="swap[col][2]">
601
+ <?php foreach( $table['data'][0] as $col_idx => $cell_content )
602
+ echo "<option value=\"{$col_idx}\">" . ( chr( ord( 'A' ) + $col_idx ) ) . "</option>"; ?>
603
+ </select>
604
+ <input type="submit" name="submit[swap_cols]" class="button-primary" value="<?php _e( 'Swap', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
605
+ <?php } // end if form swap cols ?>
606
+ </div>
607
+ <div style="clear:both;">
608
+ <h3><?php _e( 'Table Settings', WP_TABLE_RELOADED_TEXTDOMAIN ) ?></h3>
609
+ <p><?php _e( 'These settings will only be used for this table.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
610
+ <table class="tb-wp-table-options">
611
+ <tr valign="top">
612
+ <th scope="row"><?php _e( 'Alternating row colors', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
613
+ <td><input type="checkbox" name="table[options][alternating_row_colors]" id="table[options][alternating_row_colors]"<?php echo ( true == $table['options']['alternating_row_colors'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="table[options][alternating_row_colors]"><?php _e( 'Every second row will have an alternating background color.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
614
+ </tr>
615
+ <tr valign="top">
616
+ <th scope="row"><?php _e( 'Use Table Headline', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
617
+ <td><input type="checkbox" name="table[options][first_row_th]" id="table[options][first_row_th]"<?php echo ( true == $table['options']['first_row_th'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="table[options][first_row_th]"><?php _e( 'The first row of your table will use the [th] tag.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
618
+ </tr>
619
+ <tr valign="top">
620
+ <th scope="row"><?php _e( 'Print Table Name', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
621
+ <td><input type="checkbox" name="table[options][print_name]" id="table[options][print_name]"<?php echo ( true == $table['options']['print_name'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="table[options][print_name]"><?php _e( 'The Table Name will be written above the table in a [h2] tag.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
622
+ </tr>
623
+ <tr valign="top">
624
+ <th scope="row"><?php _e( 'Print Table Description', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
625
+ <td><input type="checkbox" name="table[options][print_description]" id="table[options][print_description]"<?php echo ( true == $table['options']['print_description'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="table[options][print_description]"><?php _e( 'The Table Description will be written under the table.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
626
+ </tr>
627
+ <tr valign="top">
628
+ <th scope="row"><?php _e( 'Use Tablesorter', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
629
+ <td><input type="checkbox" name="table[options][use_tablesorter]" id="table[options][use_tablesorter]"<?php echo ( true == $table['options']['use_tablesorter'] ) ? ' checked="checked"': '' ;?><?php echo ( false == $this->options['enable_tablesorter'] ) ? ' disabled="disabled"': '' ;?> value="true" /> <label for="table[options][use_tablesorter]"><?php _e( 'You may sort a table using the <a href="http://www.tablesorter.com/">Tablesorter-jQuery-Plugin</a>. <small>Attention: You must have Tablesorter enabled on the "Plugin Options" page and the option "Use Table Headline" has to be enabled above for this to work!</small>', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
630
+ </tr>
631
+ </table>
632
+ </div>
633
+
634
+ <input type="hidden" name="table[id]" value="<?php echo $table['id']; ?>" />
635
+ <input type="hidden" name="action" value="edit" />
636
+ <p class="submit">
637
+ <input type="submit" name="submit[update]" class="button-primary" value="<?php _e( 'Update Changes', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
638
+ <input type="submit" name="submit[save_back]" class="button-primary" value="<?php _e( 'Save and go back', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
639
+ <?php
640
+ $list_url = $this->get_action_url( array( 'action' => 'list' ) );
641
+ echo " <a class=\"button-primary\" href=\"{$list_url}\">" . __( 'Cancel', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>";
642
+
643
+ echo '<br/><br/>' . __( 'Other actions', WP_TABLE_RELOADED_TEXTDOMAIN ) . ':';
644
+ $delete_url = $this->get_action_url( array( 'action' => 'delete', 'table_id' => $table['id'], 'item' => 'table' ), true );
645
+ $export_url = $this->get_action_url( array( 'action' => 'export', 'table_id' => $table['id'] ), false );
646
+ echo " <a class=\"button-secondary\" href=\"{$delete_url}\" onclick=\"javascript:return confirm( '".__( 'The complete table and all content will be erased. Do you really want to delete it?', WP_TABLE_RELOADED_TEXTDOMAIN )."' );\">" . __( 'Delete Table', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>";
647
+ echo " <a class=\"button-secondary\" href=\"{$export_url}\">" . __( 'Export Table', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>";
648
+ ?>
649
+ </p>
650
+ </form>
651
+ <?php
652
+ $this->print_page_footer();
653
+ }
654
+
655
+ // ###################################################################################################################
656
+ function print_import_table_form() {
657
+ // Begin Import Table Form
658
+ $this->print_page_header( __( 'Import a Table', WP_TABLE_RELOADED_TEXTDOMAIN ) );
659
+ $this->print_submenu_navigation( 'import' );
660
+ ?>
661
+ <div style="clear:both;">
662
+ <p><?php _e( 'You may import a table from existing data here.<br/>It has to be a CSV file. You can select the used delimiter below.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
663
+ </div>
664
+ <div style="clear:both;">
665
+ <form method="post" enctype="multipart/form-data" action="<?php echo $this->get_action_url(); ?>">
666
+ <?php wp_nonce_field( $this->get_nonce( 'import' ) ); ?>
667
+ <table class="tb-wp-table-options">
668
+ <tr valign="top">
669
+ <th scope="row"><label for="import_file"><?php _e( 'Select File with Table to Import', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
670
+ <td><input name="import_file" id="import_file" type="file" /></td>
671
+ </tr>
672
+ <tr valign="top">
673
+ <th scope="row"><label for="delimiter"><?php _e( 'Used Delimiter', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
674
+ <td><select id="delimiter" name="delimiter">
675
+ <?php
676
+ $delimiters = $this->import_instance->delimiters;
677
+ foreach( $delimiters as $delimiter => $longname )
678
+ echo "<option" . ( ( $delimiter == $_POST['delimiter'] ) ? ' selected="selected"': '' ) . " value=\"{$delimiter}\">{$longname}</option>";
679
+ ?>
680
+ </select></td>
681
+ </tr>
682
+ </table>
683
+ <input type="hidden" name="action" value="import" />
684
+ <p class="submit">
685
+ <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Import Table', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
686
+ </p>
687
+ </form>
688
+ </div>
689
+ <?php
690
+ $this->print_page_footer();
691
+ }
692
+
693
+ // ###################################################################################################################
694
+ function print_export_table_form( $table_id, $output = false ) {
695
+ // Begin Export Table Form
696
+ $table = $this->load_table( $table_id );
697
+
698
+ $rows = count( $table['data'] );
699
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
700
+
701
+ $this->print_page_header( __( 'Export a Table', WP_TABLE_RELOADED_TEXTDOMAIN ) );
702
+ $this->print_submenu_navigation( 'export' );
703
+ ?>
704
+ <div style="clear:both;">
705
+ <p><?php _e( 'You may export a table here.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
706
+ </div>
707
+ <?php if( 0 < count( $this->tables ) ) { ?>
708
+ <div style="clear:both;">
709
+ <form method="post" action="<?php echo $this->get_action_url(); ?>">
710
+ <?php wp_nonce_field( $this->get_nonce( 'export' ) ); ?>
711
+ <table class="tb-wp-table-options">
712
+ <tr valign="top">
713
+ <th scope="row"><label for="table_id"><?php _e( 'Select Table to Export', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
714
+ <td><select id="table_id" name="table_id">
715
+ <?php
716
+ foreach( $this->tables as $id => $tableoptionname ) {
717
+ // get name and description to show in list
718
+ $table = $this->load_table( $id );
719
+ $name = $this->safe_output( $table['name'] );
720
+ //$description = $this->safe_output( $table['description'] );
721
+ unset( $table );
722
+ echo "<option" . ( ( $id == $table_id ) ? ' selected="selected"': '' ) . " value=\"{$id}\">{$name}</option>";
723
+ }
724
+ ?>
725
+ </select></td>
726
+ </tr>
727
+ <tr valign="top">
728
+ <th scope="row"><label for="export_format"><?php _e( 'Select Export Format', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
729
+ <td><select id="export_format" name="export_format">
730
+ <?php
731
+ $export_formats = $this->export_instance->export_formats;
732
+ foreach( $export_formats as $export_format => $longname )
733
+ echo "<option" . ( ( $export_format == $_POST['export_format'] ) ? ' selected="selected"': '' ) . " value=\"{$export_format}\">{$longname}</option>";
734
+ ?>
735
+ </select></td>
736
+ </tr>
737
+ <tr valign="top">
738
+ <th scope="row"><label for="delimiter"><?php _e( 'Select Delimiter to use', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</label></th>
739
+ <td><select id="delimiter" name="delimiter">
740
+ <?php
741
+ $delimiters = $this->export_instance->delimiters;
742
+ foreach( $delimiters as $delimiter => $longname )
743
+ echo "<option" . ( ( $delimiter == $_POST['delimiter'] ) ? ' selected="selected"': '' ) . " value=\"{$delimiter}\">{$longname}</option>";
744
+ ?>
745
+ </select></td>
746
+ </tr>
747
+ </table>
748
+ <input type="hidden" name="action" value="export" />
749
+ <p class="submit">
750
+ <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Export Table', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
751
+ </p>
752
+ <?php if ( false != $output ) { ?>
753
+ <textarea style="width:600px;height:300px;"><?php echo htmlspecialchars( $output ); ?></textarea>
754
+ <?php } ?>
755
+ </form>
756
+ </div>
757
+ <?php
758
+ } else { // end if $tables
759
+ $add_url = $this->get_action_url( array( 'action' => 'add' ), false );
760
+ $import_url = $this->get_action_url( array( 'action' => 'import' ), false );
761
+ echo "<div style=\"clear:both;\"><p>" . __( 'No tables found.', WP_TABLE_RELOADED_TEXTDOMAIN ) . '<br/>' . sprintf( __( 'You might <a href="%s">add</a> or <a href="%s">import</a> one!', WP_TABLE_RELOADED_TEXTDOMAIN ), $add_url, $import_url ) . "</p></div>";
762
+ }
763
+
764
+ $this->print_page_footer();
765
+ }
766
+
767
+ // ###################################################################################################################
768
+ function print_plugin_options_form() {
769
+ // Begin Add Table Form
770
+ $this->print_page_header( __( 'General Plugin Options', WP_TABLE_RELOADED_TEXTDOMAIN ) );
771
+ $this->print_submenu_navigation( 'options' );
772
+ ?>
773
+ <div style="clear:both;">
774
+ <p><?php _e( 'You may change these global options.<br/>They will effect all tables or the general plugin behaviour.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
775
+ </div>
776
+
777
+ <div style="clear:both;">
778
+ <form method="post" action="<?php echo $this->get_action_url(); ?>">
779
+ <?php wp_nonce_field( $this->get_nonce( 'options' ) ); ?>
780
+
781
+ <table class="tb-wp-table-options">
782
+ <tr valign="top">
783
+ <th scope="row"><?php _e( 'Uninstall Plugin upon Deactivation?', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
784
+ <td><input type="checkbox" name="options[uninstall_upon_deactivation]" id="options[uninstall_upon_deactivation]"<?php echo ( true == $this->options['uninstall_upon_deactivation'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="options[uninstall_upon_deactivation]"><?php _e( 'Yes, uninstall everything when plugin is deactivated.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
785
+ </tr>
786
+ <tr valign="top">
787
+ <th scope="row"><?php _e( 'Enable Tablesorter-JavaScript?', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
788
+ <td><input type="checkbox" name="options[enable_tablesorter]" id="options[enable_tablesorter]"<?php echo ( true == $this->options['enable_tablesorter'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="options[enable_tablesorter]"><?php _e( 'Yes, enable <a href="http://www.tablesorter.com/">Tablesorter-jQuery-Plugin</a> to be used to make table sortable (can be changed for every table separatly).', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
789
+ </tr>
790
+ <tr valign="top">
791
+ <th scope="row"><?php _e( 'Use global CSS-file?', WP_TABLE_RELOADED_TEXTDOMAIN ); ?>:</th>
792
+ <td><input type="checkbox" name="options[use_global_css]" id="options[use_global_css]"<?php echo ( true == $this->options['use_global_css'] ) ? ' checked="checked"': '' ;?> value="true" /> <label for="options[use_global_css]"><?php _e( 'Yes, load the global CSS-file wp-table-reloaded.css, which contains basic styles and graphics for the Tablesorter. (File "global-frontend-style.css" in subfolder "css")', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></label></td>
793
+ </tr>
794
+ </table>
795
+ <input type="hidden" name="options[installed_version]" value="<?php echo $this->options['installed_version']; ?>" />
796
+ <input type="hidden" name="options[last_id]" value="<?php echo $this->options['last_id']; ?>" />
797
+ <input type="hidden" name="action" value="options" />
798
+ <p class="submit">
799
+ <input type="submit" name="submit[form]" class="button-primary" value="<?php _e( 'Save Options', WP_TABLE_RELOADED_TEXTDOMAIN ) ?>" />
800
+ </p>
801
+
802
+ </form>
803
+ </div>
804
+
805
+ <h2><?php _e( 'Uninstall Plugin', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></h2>
806
+ <div style="clear:both;">
807
+ <p><?php _e( 'You may uninstall the plugin here. This will delete all tables, data, options, etc., that belong to the plugin, including all tables you added or imported.<br/> Be very careful with this and only click the button if you know what you are doing!', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
808
+ <?php
809
+ $uninstall_url = $this->get_action_url( array( 'action' => 'uninstall' ), true );
810
+ echo " <a class=\"button-secondary delete\" href=\"{$uninstall_url}\" onclick=\"javascript:if ( confirm( '".__( 'Do you really want to uninstall the plugin and delete ALL data?', WP_TABLE_RELOADED_TEXTDOMAIN )."' ) ) { return confirm( '".__( 'Are you really sure?', WP_TABLE_RELOADED_TEXTDOMAIN )."' ); } else { return false; }\">" . __( 'Uninstall TB-WP-Table Plugin', WP_TABLE_RELOADED_TEXTDOMAIN ) . "</a>";
811
+ ?>
812
+ </div>
813
+ <?php
814
+ $this->print_page_footer();
815
+ }
816
+
817
+ // ###################################################################################################################
818
+ function print_plugin_info_form() {
819
+ // Begin Add Table Form
820
+ $this->print_page_header( __( 'Information about the plugin', WP_TABLE_RELOADED_TEXTDOMAIN ) );
821
+ $this->print_submenu_navigation( 'info' );
822
+ ?>
823
+ <div style="clear:both;">
824
+ <p><?php _e( 'This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
825
+ <p><?php _e( 'More information can be found on the <a href="http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/">plugin\'s website</a>. A documentation and certain support and help request possibilities will be available soon.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
826
+ <p><?php _e( 'This plugin was written by <a href="http://tobias.baethge.com/">Tobias B&auml;thge</a>. It is licenced as Free Software under GPL 2.', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></p>
827
+ </div>
828
+ <?php
829
+ $this->print_page_footer();
830
+ }
831
+
832
+ // ###################################################################################################################
833
+ // ######################################### ####################################################
834
+ // ######################################### Print Support ####################################################
835
+ // ######################################### ####################################################
836
+ // ###################################################################################################################
837
+
838
+ // ###################################################################################################################
839
+ function print_success_message( $text ) {
840
+ echo "<div id='message' class='updated fade'><p><strong>{$text}</strong></p></div>";
841
+ }
842
+
843
+ // ###################################################################################################################
844
+ function print_page_header( $text = 'WP-Table Reloaded' ) {
845
+ echo "<div class='wrap'>
846
+ <h2>{$text}</h2>";
847
+ }
848
+
849
+ // ###################################################################################################################
850
+ function print_page_footer() {
851
+ echo "</div>";
852
+ }
853
+
854
+ // ###################################################################################################################
855
+ function print_submenu_navigation( $action ) {
856
+ ?>
857
+ <ul class="subsubsub">
858
+ <li><a <?php if ( 'list' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'list' ) ); ?>"><?php _e( 'List Tables', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a> | </li>
859
+ <li><a <?php if ( 'add' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'add' ) ); ?>"><?php _e( 'Add new Table', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a> | </li>
860
+ <li><a <?php if ( 'import' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'import' ) ); ?>"><?php _e( 'Import a Table', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a> | </li>
861
+ <li><a <?php if ( 'export' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'export' ) ); ?>"><?php _e( 'Export a Table', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a></li>
862
+ <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
863
+ <li><a <?php if ( 'options' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'options' ) ); ?>"><?php _e( 'Plugin Options', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a> | </li>
864
+ <li><a <?php if ( 'info' == $action ) echo 'class="current" '; ?>href="<?php echo $this->get_action_url( array( 'action' => 'info' ) ); ?>"><?php _e( 'About the Plugin', WP_TABLE_RELOADED_TEXTDOMAIN ); ?></a></li>
865
+ </ul>
866
+ <br class="clear" />
867
+ <?php
868
+ }
869
+
870
+ // ###################################################################################################################
871
+ function safe_output( $string ) {
872
+ return htmlspecialchars( stripslashes( $string ) );
873
+ }
874
+
875
+ // ###################################################################################################################
876
+ // ######################################### ####################################################
877
+ // ######################################### Options Funcs ####################################################
878
+ // ######################################### ####################################################
879
+ // ###################################################################################################################
880
+
881
+ // ###################################################################################################################
882
+ function get_new_table_id() {
883
+ $this->options['last_id'] = $this->options['last_id'] + 1;
884
+ $this->update_options();
885
+ return $this->options['last_id'];
886
+ }
887
+
888
+ // ###################################################################################################################
889
+ // create new two-dimensional array with $num_rows rows and $num_cols columns, each cell filled with $default_cell_content
890
+ function create_empty_table( $num_rows = 1, $num_cols = 1, $default_cell_content = '' ) {
891
+ return array_fill( 0, $num_rows, array_fill( 0, $num_cols, $default_cell_content ) );
892
+ }
893
+
894
+
895
+ // ###################################################################################################################
896
+ function update_options() {
897
+ update_option( $this->optionname['options'], $this->options );
898
+ }
899
+
900
+ // ###################################################################################################################
901
+ function update_tables() {
902
+ update_option( $this->optionname['tables'], $this->tables );
903
+ }
904
+
905
+ // ###################################################################################################################
906
+ function save_table( $table ) {
907
+ if ( 0 < $table['id'] ) {
908
+ $this->tables[ $table['id'] ] = ( isset( $this->tables[ $table['id'] ] ) ) ? $this->tables[ $table['id'] ] : $this->optionname['table'] . '_' . $table['id'];
909
+ update_option( $this->tables[ $table['id'] ], $table );
910
+ $this->update_tables();
911
+ }
912
+ }
913
+
914
+ // ###################################################################################################################
915
+ function load_table( $table_id ) {
916
+ if ( 0 < $table_id ) {
917
+ $this->tables[ $table_id ] = ( isset( $this->tables[ $table_id ] ) ) ? $this->tables[ $table_id ] : $this->optionname['table'] . '_' . $table_id;
918
+ $table = get_option( $this->tables[ $table_id ], $this->default_table);
919
+ return $table;
920
+ } else
921
+ return $this->default_table;
922
+ }
923
+
924
+ // ###################################################################################################################
925
+ // ######################################### ####################################################
926
+ // ######################################### URL Support ####################################################
927
+ // ######################################### ####################################################
928
+ // ###################################################################################################################
929
+
930
+ // ###################################################################################################################
931
+ function get_nonce( $action, $item = false ) {
932
+ return ( false !== $item ) ? $this->nonce_base . '_' . $action . '_' . $item : $this->nonce_base . '_' . $action;
933
+ }
934
+
935
+ // ###################################################################################################################
936
+ function get_action_url( $params = array(), $add_nonce = false ) {//$action = false, $table_id = false, $add_nonce = false, $element_id = false ) {
937
+ $default_params = array(
938
+ 'page' => $_REQUEST['page'],
939
+ 'action' => false,
940
+ 'item' => false
941
+ );
942
+ $url_params = array_merge( $default_params, $params );
943
+
944
+ $action_url = add_query_arg( $url_params, $_SERVER['PHP_SELF'] );
945
+ $action_url = ( true == $add_nonce ) ? wp_nonce_url( $action_url, $this->get_nonce( $url_params['action'], $url_params['item'] ) ) : $action_url;
946
+ return $action_url;
947
+ }
948
+
949
+ // ###################################################################################################################
950
+ // ####################################### ###################################################
951
+ // ####################################### Plugin Management ###################################################
952
+ // ####################################### ###################################################
953
+ // ###################################################################################################################
954
+
955
+ // ###################################################################################################################
956
+ function create_class_instance( $class, $file) {
957
+ if ( !class_exists( $class ) ) {
958
+ include_once ( WP_TABLE_RELOADED_ABSPATH . $file );
959
+ if ( class_exists( $class ) ) {
960
+ return new $class;
961
+ }
962
+ }
963
+ }
964
+
965
+ // ###################################################################################################################
966
+ function init_plugin() {
967
+ // load options and table information from database, if not available: default
968
+ $this->options = get_option( $this->optionname['options'] );
969
+ $this->tables = get_option( $this->optionname['tables'] );
970
+ if ( false === $this->options || false === $this->tables ) {
971
+ $this->plugin_install();
972
+ }
973
+ }
974
+
975
+ // ###################################################################################################################
976
+ function plugin_activation_hook() {
977
+ $this->options = get_option( $this->optionname['options'] );
978
+ if ( false !== $this->options && isset( $this->options['installed_version'] ) ) {
979
+ // check if update needed, or just reactivated the latest version of it
980
+ if ( version_compare($this->options['installed_version'], $this->plugin_version, '<') ) {
981
+ $this->plugin_update();
982
+ } else {
983
+ // just reactivating, but latest version of plugin installed
984
+ }
985
+ } else {
986
+ // plugin has never been installed before
987
+ $this->plugin_install();
988
+ }
989
+ }
990
+
991
+ // ###################################################################################################################
992
+ function plugin_deactivation_hook() {
993
+ $this->options = get_option( $this->optionname['options'] );
994
+ $this->tables = get_option( $this->optionname['tables'] );
995
+ if ( false !== $this->options && isset( $this->options['uninstall_upon_deactivation'] ) ) {
996
+ if ( true == $this->options['uninstall_upon_deactivation'] )
997
+ $this->plugin_uninstall();
998
+ }
999
+ }
1000
+
1001
+ // ###################################################################################################################
1002
+ function plugin_install() {
1003
+ $this->options = $this->default_options;
1004
+ $this->options['installed_version'] = $this->plugin_version;
1005
+ $this->update_options();
1006
+ $this->tables = $this->default_tables;
1007
+ $this->update_tables();
1008
+ }
1009
+
1010
+ // ###################################################################################################################
1011
+ function plugin_update() {
1012
+ // update general plugin options
1013
+ // 1. step: by adding/overwriting existing options
1014
+ $this->options = get_option( $this->optionname['options'] );
1015
+ $new_options = array_merge( $this->default_options, $this->options );
1016
+ // 2. step: by removing options which are deprecated (and thus not in_array(default_options)
1017
+ $new_options = array_intersect_key( $new_options, $this->default_options );
1018
+ // 3. step: update installed version number
1019
+ $new_options['installed_version'] = $this->plugin_version;
1020
+ // 4. step: save the new options
1021
+ $this->options = $new_options;
1022
+ $this->update_options();
1023
+
1024
+ // update individual table options
1025
+ $this->tables = get_option( $this->optionname['tables'] );
1026
+ foreach( $this->tables as $id => $tableoptionname ) {
1027
+ $table = $this->load_table( $id );
1028
+ $new_table = array_merge( $this->default_table, $table );
1029
+ $new_table = array_intersect_key( $new_table, $this->default_table );
1030
+ $new_table['options'] = array_merge( $this->default_table['options'], $new_table['options'] );
1031
+ $new_table['options'] = array_intersect_key( $new_table['options'], $this->default_table['options'] );
1032
+ $this->save_table( $new_table );
1033
+ }
1034
+ }
1035
+
1036
+ // ###################################################################################################################
1037
+ function plugin_uninstall() {
1038
+ // delete all options and tables
1039
+ foreach ( $this->tables as $id => $tableoptionname ) {
1040
+ delete_option( $tableoptionname );
1041
+ }
1042
+ delete_option( $this->optionname['tables'] );
1043
+ delete_option( $this->optionname['options'] );
1044
+ }
1045
+
1046
+ // ###################################################################################################################
1047
+ // initialize i18n support, load textdomain
1048
+ function init_language_support() {
1049
+ $language_directory = basename( dirname( __FILE__ ) );// . '/language';
1050
+ load_plugin_textdomain( WP_TABLE_RELOADED_TEXTDOMAIN, 'wp-content/plugins/' . $language_directory, $language_directory );
1051
+ }
1052
+
1053
+ // ###################################################################################################################
1054
+ // enqueue css-stylesheet-file, if it exists
1055
+ function add_manage_page_css() {
1056
+ $cssfile = 'admin-style.css';
1057
+ if ( file_exists( dirname ( __FILE__ ) . '/css/' . $cssfile ) ) {
1058
+ wp_enqueue_style( 'wp-table-reloaded-admin-css', WP_PLUGIN_URL . '/' . basename( dirname( __FILE__ ) ) . '/css/' . $cssfile );
1059
+ }
1060
+ }
1061
+
1062
+ } // class WP_Table_Reloaded_Admin
1063
+
1064
+ ?>
wp-table-reloaded-export.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ File Name: WP-Table Reloaded - Export Class (see main file wp-table-reloaded.php)
4
+ Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
5
+ Description: This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.
6
+ Version: 0.9
7
+ Author: Tobias B&auml;thge
8
+ Author URI: http://tobias.baethge.com/
9
+ */
10
+
11
+ // should be included by WP_Table_Reloaded_Admin!
12
+ class WP_Table_Reloaded_Export {
13
+
14
+ // ###################################################################################################################
15
+ var $export_class_version = '0.9';
16
+
17
+ var $export_formats = array();
18
+ var $delimiters = array();
19
+
20
+ var $export_format = '';
21
+ var $delimiter = ';';
22
+ var $table_to_export = array();
23
+ var $exported_table = '';
24
+
25
+ // ###################################################################################################################
26
+ // constructor class
27
+ function WP_Table_Reloaded_Export() {
28
+ // initiate here, because function call __() not allowed outside function
29
+ $this->export_formats = array(
30
+ 'csv' => __( 'CSV - Character-Separated Values', TB_WP_TABLE_TEXTDOMAIN ),
31
+ //'xml' => __( 'XML - eXtended Markup Language', TB_WP_TABLE_TEXTDOMAIN ),
32
+ );
33
+ $this->delimiters = array(
34
+ ';' => __( '; (semicolon)', TB_WP_TABLE_TEXTDOMAIN ),
35
+ ',' => __( ', (comma)', TB_WP_TABLE_TEXTDOMAIN ),
36
+ ':' => __( ': (colon)', TB_WP_TABLE_TEXTDOMAIN )
37
+ );
38
+ }
39
+
40
+ // ###################################################################################################################
41
+ function export_table() {
42
+ $output = '';
43
+
44
+ $data = $this->table_to_export['data'];
45
+
46
+ $rows = count( $data );
47
+ $cols = (0 < $rows) ? count( $data[0] ) : 0;
48
+
49
+ switch( $this->export_format ) {
50
+ case 'csv':
51
+ if ( 0 < $rows && 0 < $cols) {
52
+ if ( function_exists( 'fputcsv' ) ) { // introduced in PHP 5.1.0
53
+ if ( function_exists( 'sys_get_temp_dir' ) ) { // introduced in PHP 5.2.1
54
+ $temp_file = tempnam( sys_get_temp_dir(), 'export_table_' . $this->table_to_export['id'] . '_' );
55
+ $handle = fopen( $temp_file, 'w' );
56
+ foreach ( $data as $row_idx => $row ) {
57
+ $row = array_map( 'stripslashes', $row );
58
+ fputcsv( $handle, $row, $this->delimiter, '"' );
59
+ }
60
+ fclose( $handle );
61
+ $output = file_get_contents( $temp_file );
62
+ } else {
63
+ $handle = tmpfile();
64
+ foreach ( $data as $row_idx => $row ) {
65
+ $row = array_map( 'stripslashes', $row );
66
+ fputcsv( $handle, $row, $this->delimiter, '"' );
67
+ }
68
+ fseek($handle, 0);
69
+ while ( !feof( $handle ) ) {
70
+ $output .= fread( $handle, 1024);
71
+ }
72
+ fclose( $handle );
73
+ }
74
+ } else { // should word for all PHP versions
75
+ foreach( $data as $row_idx => $row ) {
76
+ $row = array_map( array( &$this, 'wrap_and_escape' ), $row );
77
+ $output .= implode( $this->delimiter, $row ) . "\n";
78
+ }
79
+ }
80
+ }
81
+ break;
82
+ // case 'xml':
83
+ default:
84
+ $output = __( 'The Table could not be exported due to a wrong export format.', TB_WP_TABLE_TEXTDOMAIN );
85
+ }
86
+ $this->exported_table = $output;
87
+ }
88
+
89
+ // ###################################################################################################################
90
+ function wrap_and_escape( $string ) {
91
+ $string = stripslashes( $string );
92
+ $string = str_replace( '"', '""', $string );
93
+ return ( false !== strpos( $string, $this->delimiter ) || false !== strpos( $string, '""' ) ) ? ( '"' . $string . '"' ) : $string;
94
+ }
95
+
96
+ } // class WP_Table_Reloaded_Export
97
+
98
+ ?>
wp-table-reloaded-frontend.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ File Name: WP-Table Reloaded - Frontend Class (see main file wp-table-reloaded.php)
4
+ Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
5
+ Description: This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.
6
+ Version: 0.9.2
7
+ Author: Tobias B&auml;thge
8
+ Author URI: http://tobias.baethge.com/
9
+ */
10
+
11
+ class WP_Table_Reloaded_Frontend {
12
+
13
+ // ###################################################################################################################
14
+ // plugin variables
15
+ var $options = array();
16
+ var $tables = array();
17
+
18
+ var $optionname = array(
19
+ 'tables' => 'wp_table_reloaded_tables',
20
+ 'options' => 'wp_table_reloaded_options',
21
+ 'table' => 'wp_table_reloaded_data'
22
+ );
23
+ var $shortcode = 'table';
24
+
25
+ // ###################################################################################################################
26
+ function WP_Table_Reloaded_Frontend() {
27
+ // load options and table information from database, if not available: default
28
+ $this->options = get_option( $this->optionname['options'], false );
29
+ $this->tables = get_option( $this->optionname['tables'], false );
30
+
31
+ if ( false === $this->options || false === $this->tables )
32
+ return '';
33
+
34
+ // front-end function
35
+ add_shortcode( $this->shortcode, array( &$this, 'handle_shortcode' ) );
36
+
37
+ // if tablesorter enabled (globally) include javascript
38
+ if ( true == $this->options['enable_tablesorter'] )
39
+ $this->add_head_tablesorter_js();
40
+
41
+ // if global css shall be used
42
+ if ( true == $this->options['use_global_css'] )
43
+ $this->add_head_global_css();
44
+ }
45
+
46
+ // ###################################################################################################################
47
+ // handle [table id=<the_table_id> /]
48
+ function handle_shortcode( $attr ) {
49
+ $table_id = $attr['id'];
50
+
51
+ if ( !is_numeric( $table_id ) || 1 > $table_id)
52
+ return '';
53
+
54
+ $table = $this->load_table( $table_id );
55
+
56
+ $output = $this->render_table( $table );
57
+
58
+ return $output;
59
+ }
60
+
61
+ // ###################################################################################################################
62
+ function load_table( $table_id ) {
63
+ $this->tables[ $table_id ] = ( isset( $this->tables[ $table_id ] ) ) ? $this->tables[ $table_id ] : $this->optionname['table'] . '_' . $table_id;
64
+ $table = get_option( $this->tables[ $table_id ], $this->default_table);
65
+ return $table;
66
+ }
67
+
68
+ // ###################################################################################################################
69
+ // echo content of array
70
+ function render_table( $table ) {
71
+ // classes that will be added to <table class=...>, can be used for css-styling
72
+ $cssclasses = array( 'wp-table-reloaded', "wp-table-reloaded-id-{$table['id']}" );
73
+ $cssclasses = implode( ' ', $cssclasses );
74
+
75
+ $rows = count( $table['data'] );
76
+ $cols = (0 < $rows) ? count( $table['data'][0] ) : 0;
77
+
78
+ $output = '';
79
+
80
+ if ( 0 < $rows && 0 < $cols) {
81
+
82
+ if ( true == $table['options']['print_name'] )
83
+ $output .= '<h2 class="wp-table-reloaded-table-name">' . $this->safe_output( $table['name'] ) . "</h2>\n";
84
+
85
+ $output .= "<table class=\"{$cssclasses}\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\">\n";
86
+
87
+ foreach( $table['data'] as $row_idx => $row ) {
88
+ if ( true == $table['options']['alternating_row_colors'] )
89
+ $row_class = ( 1 == ($row_idx % 2) ) ? ' class="even"' : ' class="odd"';
90
+ if( 0 == $row_idx ) {
91
+ if ( true == $table['options']['first_row_th'] ) {
92
+ $output .= "<thead>\n";
93
+ $output .= "\t<tr{$row_class}>\n\t\t";
94
+ foreach( $row as $col_idx => $cell_content ) {
95
+ $cell_content = $this->safe_output( $cell_content );
96
+ $output .= "<th>" . "{$cell_content}" . "</th>";
97
+ }
98
+ $output .= "\n\t</tr>\n";
99
+ $output .= "</thead>\n";
100
+ $output .= "<tbody>\n";
101
+ } else {
102
+ $output .= "<tbody>\n";
103
+ $output .= "\t<tr{$row_class}>\n\t\t";
104
+ foreach( $row as $col_idx => $cell_content ) {
105
+ $cell_content = $this->safe_output( $cell_content );
106
+ $output .= "<td>" . "{$cell_content}" . "</td>";
107
+ }
108
+ $output .= "\n\t</tr>\n";
109
+ }
110
+ } else {
111
+ $output .= "\t<tr{$row_class}>\n\t\t";
112
+ foreach( $row as $col_idx => $cell_content ) {
113
+ $cell_content = $this->safe_output( $cell_content );
114
+ $output .= "<td>" . "{$cell_content}" . "</td>";
115
+ }
116
+ $output .= "\n\t</tr>\n";
117
+ }
118
+ }
119
+ $output .= "</tbody>\n";
120
+ $output .= "</table>\n";
121
+
122
+ if ( true == $table['options']['print_description'] )
123
+ $output .= '<span class="wp-table-reloaded-table-description">' . $this->safe_output( $table['description'] ) . "</span>\n";
124
+
125
+ $widgets = ( true == $table['options']['alternating_row_colors'] ) ? "{widgets: ['zebra']}" : '';
126
+ if ( true == $table['options']['use_tablesorter'] ) {
127
+ $output .= <<<JSSCRIPT
128
+ <script type="text/javascript">
129
+ jQuery(document).ready(function($){
130
+ $(".wp-table-reloaded-id-{$table['id']}").tablesorter({$widgets});
131
+ });
132
+ </script>
133
+ JSSCRIPT;
134
+ }
135
+ }
136
+ return $output;
137
+ }
138
+
139
+ // ###################################################################################################################
140
+ function safe_output( $string ) {
141
+ return stripslashes( $string );
142
+ }
143
+
144
+ // ###################################################################################################################
145
+ // enqueue tablesorter-js-file, if it exists
146
+ function add_head_tablesorter_js() {
147
+ $jsfile = 'jquery.tablesorter.min.js';
148
+ if ( file_exists( dirname ( __FILE__ ) . '/js/' . $jsfile ) ) {
149
+ wp_enqueue_script( 'wp-table-reloaded-tablesorter-js', WP_PLUGIN_URL . '/' . basename( dirname( __FILE__ ) ) . '/js/' . $jsfile, array( 'jquery' ) );
150
+ }
151
+ }
152
+ // ###################################################################################################################
153
+ // enqueue tablesorter-css-file, if it exists, may be modified by user
154
+ function add_head_global_css() {
155
+ $cssfile = 'global-frontend-style.css';
156
+ if ( file_exists( dirname ( __FILE__ ) . '/css/' . $cssfile ) ) {
157
+ wp_enqueue_style( 'wp-table-reloaded-global-css', WP_PLUGIN_URL . '/' . basename( dirname( __FILE__ ) ) . '/css/' . $cssfile );
158
+ }
159
+ }
160
+
161
+ } // class WP_Table_Reloaded_Frontend
162
+
163
+ ?>
wp-table-reloaded-import.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ File Name: WP-Table Reloaded - Import Class (see main file wp-table-reloaded.php)
4
+ Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
5
+ Description: This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.
6
+ Version: 0.9
7
+ Author: Tobias B&auml;thge
8
+ Author URI: http://tobias.baethge.com/
9
+ */
10
+
11
+ // should be included by WP_Table_Reloaded_Admin!
12
+ class WP_Table_Reloaded_Import {
13
+
14
+ // ###################################################################################################################
15
+ var $import_class_version = '0.9';
16
+
17
+ var $delimiters = array();
18
+
19
+ var $filename = '';
20
+ var $tempname = '';
21
+ var $mimetype = '';
22
+ var $delimiter = ';';
23
+ var $imported_table = array();
24
+
25
+
26
+ // ###################################################################################################################
27
+ // constructor class
28
+ function WP_Table_Reloaded_Import() {
29
+ // initiate here, because function call __() not allowed outside function
30
+ $this->delimiters = array(
31
+ ';' => __( '; (semicolon)', TB_WP_TABLE_TEXTDOMAIN ),
32
+ ',' => __( ', (comma)', TB_WP_TABLE_TEXTDOMAIN ),
33
+ ':' => __( ': (colon)', TB_WP_TABLE_TEXTDOMAIN )
34
+ );
35
+ }
36
+
37
+ // ###################################################################################################################
38
+ function import_table() {
39
+ $table['name'] = $this->filename;
40
+ $table['description'] = $this->filename . ' (' . $this->mimetype . ')';
41
+
42
+ $temp_data = $this->csv_file_to_array( $this->tempname, $this->delimiter, '"' );
43
+ $table['data'] = $this->pad_array_to_max_cols( $temp_data );
44
+ $this->imported_table = $table;
45
+ }
46
+
47
+ // ###################################################################################################################
48
+ function unlink_csv_file() {
49
+ unlink( $this->tempname );
50
+ }
51
+
52
+ // ###################################################################################################################
53
+ function csv_file_to_array( $filename, $delimiter = ';', $enclosure = '"' ) {
54
+ $data = array();
55
+ $handle = fopen( $filename, 'r' );
56
+ while ( false !== ( $read_line = fgetcsv( $handle, 1024, $delimiter, $enclosure ) ) ) {
57
+ $data[] = $this->add_slashes( $read_line );
58
+ }
59
+ fclose($handle);
60
+ return $data;
61
+ }
62
+
63
+ // ###################################################################################################################
64
+ // make sure array is rectangular with $max_cols columns in every row
65
+ function pad_array_to_max_cols( $array_to_pad ){
66
+ $rows = count( $array_to_pad );
67
+ $max_columns = $this->count_max_columns( $array_to_pad );
68
+ // array_map wants arrays as additional parameters (so we create one with the max_cols to pad to and one with the value to use (empty string)
69
+ $max_columns_array = array_fill( 1, $rows, $max_columns );
70
+ $pad_values_array = array_fill( 1, $rows, '' );
71
+ return array_map( 'array_pad', $array_to_pad, $max_columns_array, $pad_values_array );
72
+ }
73
+
74
+ // ###################################################################################################################
75
+ // find out how many cols the longest row has
76
+ function count_max_columns( $array ){
77
+ $max_cols = 0 ;
78
+ if ( is_array( $array ) && 0 < count( $array ) ) {
79
+ foreach ( $array as $row_idx => $row ) {
80
+ $cols = count( $row );
81
+ $max_cols = ( $cols > $max_cols ) ? $cols : $max_cols;
82
+ }
83
+ }
84
+ return $max_cols;
85
+ }
86
+
87
+ // ###################################################################################################################
88
+ function add_slashes( $array ) {
89
+ return array_map( 'addslashes', $array );
90
+ }
91
+
92
+ } // class WP_Table_Reloaded_Import
93
+
94
+ ?>
wp-table-reloaded.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Table Reloaded
4
+ Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded/
5
+ Description: This plugin allows you to create and manage tables in the admin-area of WordPress. You can then show them in your posts or on your pages by using a shortcode. The plugin is greatly influenced by the plugin "WP-Table" by Alex Rabe, but was completely rewritten and uses the state-of-the-art WordPress techniques which makes it faster and lighter than the original plugin.
6
+ Version: 0.9.2
7
+ Author: Tobias B&auml;thge
8
+ Author URI: http://tobias.baethge.com/
9
+ */
10
+
11
+ /* Copyright 2009 Tobias B&auml;thge (email: mail@tobias.baethge.com )
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; version 2 of the License (GPL v2) only.
16
+
17
+ This program is distributed in the hope that it will be useful,
18
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ GNU General Public License for more details.
21
+
22
+ You should have received a copy of the GNU General Public License
23
+ along with this program; if not, write to the Free Software
24
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
+
27
+ // folder definitions as constants
28
+ if ( !defined( 'WP_CONTENT_DIR' ) )
29
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
30
+ if ( !defined( 'WP_TABLE_RELOADED_ABSPATH' ) )
31
+ define( 'WP_TABLE_RELOADED_ABSPATH', WP_CONTENT_DIR . '/plugins/' . basename( dirname ( __FILE__ ) ) . '/' );
32
+
33
+ // decide whether admin or frontend
34
+ if ( is_admin() ) {
35
+ // we are in admin mode
36
+ if ( !class_exists( 'WP_Table_Reloaded_Admin' ) ) {
37
+ include_once ( WP_TABLE_RELOADED_ABSPATH . 'wp-table-reloaded-admin.php' );
38
+ if ( class_exists( 'WP_Table_Reloaded_Admin' ) ) {
39
+ $WP_Table_Reloaded_Admin = new WP_Table_Reloaded_Admin();
40
+ register_activation_hook( __FILE__, array( &$WP_Table_Reloaded_Admin, 'plugin_activation_hook' ));
41
+ register_deactivation_hook( __FILE__, array( &$WP_Table_Reloaded_Admin, 'plugin_deactivation_hook' ));
42
+ }
43
+ }
44
+ } else {
45
+ // we are in frontend mode
46
+ if ( !class_exists( 'WP_Table_Reloaded_Frontend' ) ) {
47
+ include_once ( WP_TABLE_RELOADED_ABSPATH . 'wp-table-reloaded-frontend.php' );
48
+ if ( class_exists( 'WP_Table_Reloaded_Frontend' ) ) {
49
+ $WP_Table_Reloaded_Frontend = new WP_Table_Reloaded_Frontend();
50
+ }
51
+ }
52
+ }
53
+
54
+ ?>