'table',
'attrtag' => 'attr',
'tablewidget' => false,
'scriptloadin' => Array('is_single','is_page'),
'class' => '',
'caption' => false,
'width' => '100%',
'align' => 'left',
'th' => true,
'tf' => false,
'border' => 0,
'id' => false,
'theme' => 'default',
'tablesorter' => false,
'loadcss' => true,
'scriptinfooter'=> false,
'delimiter' => ',',
'file' => false,
'trim' => false, /*trim, since 1.0*/
'enclosure' => '"',
'escape' => '\\',
'nl' => '~~',
'csvfile' => false,
'terminator' => '\n', /*row terminator, since 1.0*/
'limit' => 0, /*max row to be included to table, 0 = unlimited, since 1.0*/
'fixlinebreak' => false
);
function __construct(){
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", array(&$this,'easy_table_settings_link' ));
load_plugin_textdomain('easy-table', false, basename( dirname( __FILE__ ) ) . '/languages' );
add_action('admin_init', array(&$this,'easy_table_register_setting'));
add_action('admin_head', array(&$this,'easy_table_admin_script'));
add_action('wp_enqueue_scripts', array(&$this,'easy_table_script'));
add_action('wp_enqueue_scripts', array(&$this,'easy_table_style'));
add_action('admin_menu', array(&$this,'easy_table_add_page'));
add_action('contextual_help', array(&$this,'easy_table_help'));
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
include_once( dirname(__FILE__) . '/inc/compatibility.php' ); /* since 1.5.2 */
$conflict = false;
if ( shortcode_exists( $this->option('shortcodetag') ) ) {
add_action('admin_notices', array(&$this,'easy_table_shortcode_check_notice'));
$conflict = true;
}
if (is_plugin_active('tablepress/tablepress.php') AND ('table' == strtolower($this->option('shortcodetag')) ) ) {
add_action('admin_notices', array(&$this,'easy_table_shortcode_check_notice_tablepress'));
$conflict = true;
}
if ( !$conflict ) {
add_shortcode($this->option('shortcodetag'), array(&$this,'easy_table_short_code'));
}
if ( shortcode_exists( $this->option('attrtag') ) ) {
add_action('admin_notices', array(&$this,'easy_table_attr_shortcode_check_notice'));
}
else {
add_shortcode($this->option('attrtag'), array(&$this,'easy_table_short_code_attr'));
}
if($this->option('tablewidget')){
add_filter('widget_text', 'do_shortcode');
}
$table_shortcodetag_already_exists = false;
}
private function easy_table_base($return){
$easy_table_base = Array(
'name' => 'Easy Table',
'version' => '1.8',
'plugin-domain' => 'easy-table'
);
return $easy_table_base[$return];
}
function easy_table_shortcode_check_notice() {
$shortcode = $this->option('shortcodetag');
?>
Easy Table : Click here to fix it.','easy-table'), '['.$shortcode.']
','Easy Table','Easy Table short code tag ',''.$shortcode.'
','options-general.php?page=easy-table');?>
Easy Table : Click here to fix it.','easy-table'), '['.$shortcode.']
','Easy Table','Easy Table short code tag ',''.$shortcode.'
','options-general.php?page=easy-table');?>
option('attrtag');
?>
Easy Table : Click here to fix it.','easy-table'), '['.$shortcode.']
','Easy Table','Easy Table cell attribute tag ',''.$shortcode.'
','options-general.php?page=easy-table');?>
$this->option('class'),
'caption' => $this->option('caption'),
'width' => $this->option('width'),
'th' => $this->option('th'),
'tf' => $this->option('tf'),
'border' => $this->option('border'),
'id' => $this->option('id'),
'theme' => $this->option('theme'),
'tablesorter' => $this->option('tablesorter'),
'delimiter' => $this->option('delimiter'),
'enclosure' => $this->option('enclosure'),
'escape' => $this->option('escape'),
'file' => $this->option('file'),
'trim' => $this->option('trim'),
'sort' => '',
'nl' => $this->option('nl'),
'ai' => false,
'terminator' => $this->option('terminator'),
'limit' => $this->option('limit'),
'align' => $this->option('align'),
'style' => '', /*table inline style, since 1.0*/
'colalign' => '', /*column align, ex: [table colalign="left|right|center"], @since 1.0*/
'colwidth' => '', /*column width, ex: [table colwidth="100|200|300"], @since 1.0*/
'fixlinebreak' => $this->option('fixlinebreak'), /* fix linebreak on cell if terminator is not \n or \r @since 1.1.4 */
'exclude_row' => '',
'exclude_col' => '',
), $atts);
/**
* because clean_pre is deprecated since WordPress 3.4, then replace it manually
$content = clean_pre($content);*/
$content = str_replace(array(' ', ' ', ' '), array('', '', ''), $content);
$content = str_replace('', "\n", $content);
$content = str_replace('
', '', $content);
$content = str_replace(' ','',$content);
$char_codes = array( '‘', '’', '“', '”', '′', '″' );
$replacements = array( "'", "'", '"', '"', "'", '"' );
$content = str_replace( $char_codes, $replacements, $content );
return $this->csv_to_table($content,$shortcode_atts);
}
/**
* Just return to strip attr shortcode for table cell, since we use custom regex for attr shortcode.
* @since 0.5
*/
function easy_table_short_code_attr($atts){
return;
}
/**
* Convert CSV to table
* @param array|string $data could be CSV string or array
* @param array @args
* @return string
*/
private function csv_to_table($data,$args){
extract($args);
/** check param value if it is expected to be boolean
* @since: 1.6
**/
$th = filter_var($th, FILTER_VALIDATE_BOOLEAN);
$trim = filter_var($trim, FILTER_VALIDATE_BOOLEAN);
if($tf !== 'last') {
$tf = filter_var($tf, FILTER_VALIDATE_BOOLEAN);
}
if( $this->option('csvfile') AND $file ){
/*$data = @file_get_contents($file);*/
/** use wp_remote_get
* @since 0.8
*/
$data = '';
$response = wp_remote_get( $file, array('sslverify'=>false) );
/**
notify if error reading file.
@since 0.9
*/
if( is_wp_error( $response ) ) {
return 'Error reading file/URL.
';
} else if( $response['response']['code'] == 200 ) {
$data = $response['body'];
}
}
if(!is_array($data)){
/**
normalize nl, since it may contains new line.
@since 0.9
*/
$data = preg_replace('/'.preg_quote($nl).'([\s\r\n\t]+)?/i',$nl,$data);
/*
Fix encoding?
@since: 1.0 beta
*/
require_once (dirname(__FILE__).'/inc/Encoding.php');
//$data = ForceEncode::fixUTF8($data);
$data = ForceEncode::toUTF8($data);
/*
convert csv to array.
*/
$data = $this->csv_to_array(trim($data), $delimiter, $enclosure, $escape, $terminator, $limit);
}
if(empty($data)) return false;
/** exclude row or col
* @since: 1.6
**/
if( $exclude_row ) {
$exclude_row = explode(',',$exclude_row);
foreach( $exclude_row as $x_row ) {
if(isset($data[$x_row-1])) {
unset($data[$x_row-1]);
}
}
}
if( $exclude_col ) {
$exclude_col = explode(',',$exclude_col);
}
$max_cols = count(max($data));
$r=0;
/**
* initialize inline sort,
* extract header sort if any, and equalize with max column number
* @since 0.8
*/
if( $tablesorter ) {
$inline_sort = Array();
$header_sort = explode(',',$sort);
$header_sort = array_pad($header_sort,$max_cols,NULL);
}
/**
* tfoot position
* @since 0.4
*/
$tfpos = ($tf == 'last') ? count($data) : ($th?2:1);
/**
* add auto width
* @since 1.1.3
*/
if ( 'auto' !== $width ) {
$width = (stripos($width,'%') === false) ? (int)$width.'px' : (int)$width.'%';
}
/*colalign & colwidth
@since 1.0
*/
if($colalign) {
$c_align = explode('|',$colalign);
}
if($colwidth) {
$c_width = explode('|',$colwidth);
}
/* added back $align, with new way of implementation,
* @since 1.4
*/
$style = rtrim($style, ';');
switch ($align) :
case 'center':
$alignstyle = '; margin-left:auto;margin-right:auto';
break;
case 'right':
$alignstyle = '; margin-left:auto;margin-right:0';
break;
default:
$alignstyle = '';
break;
endswitch;
$style = $style.$alignstyle;
/* wrap with .table-responsive div, since 1.5 */
$output = '';
$output .= '
'."\n";
$output .= $caption ? ''.$caption.' '."\n" : '';
$output .= $th ? '' : (($tf !== 'last') ? '' : ' ');
$output .= (!$th AND !$tf) ? ' ':'';
foreach($data as $k=>$cols){ $r++;
//$cols = array_pad($cols,$max_cols,'');
// exclude cols, @since: 1.6
if(is_array($exclude_col)) {
foreach( $exclude_col as $x_col ) {
if(isset($cols[$x_col-1])) {
unset($cols[$x_col-1]);
}
}
}
$output .= (($r==$tfpos) AND $tf) ? (($tf=='last')?' ':'').'': '';
$output .= "\r\n".'';
$thtd = ((($r==1) AND $th) OR (($r==$tfpos) AND $tf)) ? 'th' : 'td';
/**
ai is auto index
@since 0.9
add auto numbering in the begining of each row
ai="true" or ai="1" number will start from 1,
ai="n", n = any number, number will start from that.
Another possible value.
ai="n/head/width"
n = index start
head = head text, default is No.
width = column width, in pixel. Default is 20px
ai head, text to shown in the table head row, default is No.
*/
$index = explode('/',$ai);
$indexnum = ((int)$index[0])+$r;
$indexnum = $th ? $indexnum-2 : $indexnum-1;
$indexnum = ($tf AND ($tf !== 'last')) ? $indexnum-1 : $indexnum;
$indexhead = isset($index[1]) ? $index[1] : 'No.';
$indexwidth = isset($index[2]) ? (int)$index[2] : 30;
$output .= ($ai AND ($thtd == 'td')) ? '<'.$thtd.' style="width:'.$indexwidth.'px">'.$indexnum."$thtd>" : ($ai ? "<$thtd>".$indexhead."$thtd>" : '');
foreach($cols as $c=>$cell){
/**
* Add attribute for each cell
* @since 0.5
*/
//preg_match('/\['.$this->option('attrtag').' ([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)/',$cell,$matchattr);
preg_match('/\['.$this->option('attrtag').' ([^\\]]*)/',$cell,$matchattr);
$attr = isset($matchattr[1]) ? $matchattr[1] : '';
/**
* extract $attr value
* @since 0.8
* this is for inline sorting option,
* eg [attr sort="desc"],[attr sort="asc"] or [attr sort="none"]
* only affect if it's TH and $tablesorter enabled
* extract sort value and insert appropriate class value.
*/
if( ('th' == $thtd) AND $tablesorter ) {
$attrs = $attr ? shortcode_parse_atts($attr) : Array();
$attrs['sort'] = isset($attrs['sort']) ? $attrs['sort'] : $header_sort[$c];
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] : '';
$inline_sort[$c] = $attrs['sort'];
$attr = '';
$sorter = in_array(strtolower($attrs['sort']),array('desc','asc')) ? '' : (!empty($attrs['sort']) ? 'false' : '');
foreach($attrs as $katr => $vatr){
if($katr == 'sort') {
}
else if(($katr == 'class')){
$attr .= "$katr='$vatr ";
$attr .= $sorter ? "{sorter: $sorter}":'';
$attr .= "' ";
}
else {
$attr .= "$katr='$vatr' ";
}
}
}
/**
nl, replace nl with new line
@since 0.9
*/
$cell = str_replace($nl,' ',$cell);
/*trim cell content?
@since 1.0
*/
$cell = $trim ? trim(str_replace(' ','',$cell)) : $cell;
/*nl2br? only if terminator is not \n or \r*/
/* optionally, if $fixlinebreak is set. @since 1.1.4 */
if ( $fixlinebreak ) {
if(( '\n' !== $terminator ) OR ( '\r' !== $terminator )) {
$cell = nl2br($cell);
}
}
/*colalign
@since 1.0
*/
if (isset($c_align[$c]) AND (stripos($attr,'text-align') === false)) {
if(stripos($attr,'style') === false) {
$attr = $attr. ' style="text-align:'.$c_align[$c].'" ';
}
else {
$attr = preg_replace('/style(\s+)?=(\s+)?("|\')(\s+)?/i','style=${3}text-align:'.$c_align[$c].';',$attr);
}
}
/*colwidth
@since 1.0
*/
if (isset($c_width[$c]) AND (stripos($attr,'width') === false) AND ($r == 1)) {
$c_width[$c] = (stripos($c_width[$c],'%') === false) ? (int)$c_width[$c].'px' : (int)$c_width[$c].'%';
if(stripos($attr,'style') === false) {
$attr = $attr. ' style="width:'.$c_width[$c].'" ';
}
else {
$attr = preg_replace('/style(\s+)?=(\s+)?("|\')(\s+)?/i','style=${3}width:'.$c_width[$c].';',$attr);
}
}
$output .= "<$thtd $attr>".do_shortcode($cell)."$thtd>\n";
}
$output .= ' '."\n";
$output .= (($r==1) AND $th) ? ''."\n".' ' : '';
$output .= (($r==$tfpos) AND $tf) ? ''.((($tf==1) AND !$th) ? ' ':''): '';
}
$output .= (($tf!=='last')?' ':'').'
';
/**
* Build sortlist metadata and append it to the table class
* @since 0.8
* This intended to $tablesorter,
* so don't bother if $tablesorter is false/disabled
*/
if( $tablesorter ) {
$sortlist = '';
$all_sort = array_replace($header_sort,$inline_sort);
if(implode('',$all_sort)) {
$sortlist = '{sortlist: [';
foreach($all_sort as $k=>$v){
$v = (($v == 'desc') ? 1 : (($v == 'asc') ? 0 : '' ));
if($v !=='') {
$sortlist .= '['.$k.','.$v.'], ';
}
}
$sortlist .= ']}';
}
$output = str_replace('__sortlist__',$sortlist,$output);
}
return $output;
}
/**
* Convert CSV to array
*/
private function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n", $limit = 0 ) {
$r = array();
$terminator = ($terminator == '\n') ? "\n" : $terminator;
$terminator = ($terminator == '\r') ? "\r" : $terminator;
$terminator = ($terminator == '\t') ? "\t" : $terminator;
$rows = easy_table_str_getcsv($csv, $terminator,$enclosure,$escape);
$rows = array_diff($rows,Array(''));
/*
* limit how many rows will be included?
* default 0, means ulimited.
* @since 1.0
*/
if($limit > 0) {
$rows = array_slice($rows, 0, $limit);
}
foreach($rows as &$row) {
$r[] = easy_table_str_getcsv($row,$delimiter);
}
return $r;
}
/**
* Retrieve options from database if any, or use default options instead.
*/
function option($key=''){
$option = get_option('easy_table_plugin_option') ? get_option('easy_table_plugin_option') : Array();
$option = array_merge($this->settings,$option);
if($key){
$return = $option[$key];
}
else{
$return = $option;
}
return $return;
}
/**
* Retrieve themes directory
* @since: 0.8
*/
function themes(){
/**
* delete theme cache on setting updated.
*/
if( ( 'easy-table' == $_GET['page']) AND isset($_GET['settings-updated']) ) {
delete_transient('easy_table_themes');
}
if(!function_exists('scandir')){
return Array('default');
}
if ( false === ( $themes = get_transient( 'easy_table_themes' ) )) {
$dir = plugin_dir_path(__FILE__).'themes/';
$dirs = scandir($dir);
foreach($dirs as $d){
if( (substr($d,0,1) !=='.') AND (is_dir($dir.$d)) ) {
$themes[] = $d;
}
}
set_transient( 'easy_table_themes', $themes , 86400 );
}
return $themes;
}
/**
* Register plugin setting
* @since: 1.7 add sanitize_callback
*/
function easy_table_register_setting() {
$args = array('sanitize_callback'=> array(&$this,'easy_table_sanitize_callback'));
register_setting('easy_table_option_field', 'easy_table_plugin_option', $args);
}
/**
* Add sanitize_callback to register_setting to filter the options value
* @since: 1.7
*/
function easy_table_sanitize_callback ( $value ) {
return filter_var( $value,FILTER_CALLBACK, array("options"=>"strip_tags"));
}
/**
* Render form
* @param array
*/
function render_form($fields){
$output ='';
return $output;
}
/**
* Register javascript
*/
function easy_table_script() {
if( is_single() AND in_array('is_single',$this->option('scriptloadin')) OR
is_page() AND in_array('is_page',$this->option('scriptloadin')) OR
is_home() AND in_array('is_home',$this->option('scriptloadin')) OR
is_archive() AND in_array('is_archive',$this->option('scriptloadin')) OR
is_search() AND in_array('is_search',$this->option('scriptloadin'))
)
{
if($this->option('tablesorter')) {
wp_enqueue_script('easy_table_script',plugins_url( 'js/easy-table-script.js' , __FILE__ ),array('jquery'),$this->easy_table_base('version'),$this->option('scriptinfooter'));
}
}
}
/**
* Register stylesheet
*/
function easy_table_style() {
if( is_single() AND in_array('is_single',$this->option('scriptloadin')) OR
is_page() AND in_array('is_page',$this->option('scriptloadin')) OR
is_home() AND in_array('is_home',$this->option('scriptloadin')) OR
is_archive() AND in_array('is_archive',$this->option('scriptloadin')) OR
is_search() AND in_array('is_search',$this->option('scriptloadin'))
)
{
if($this->option('loadcss')) {
wp_enqueue_style('easy_table_style', plugins_url('themes/'.$this->option('theme').'/style.css', __FILE__),false,$this->easy_table_base('version'));
}
}
}
function easy_table_admin_script(){
$page = isset($_GET['page']) ? $_GET['page'] : '';
if($page == $this->easy_table_base('plugin-domain')) {
if($this->option('tablesorter')) { ?>
option('loadcss')) { ?>
easy_table_base('plugin-domain').'">'.__('Settings','easy-table').'';
array_unshift($links, $settings_link);
return $links;
}
/**
* Contextual help
*/
function easy_table_help($help) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
if($page == $this->easy_table_base('plugin-domain')) {
$help = ''.$this->easy_table_base('name').' '.$this->easy_table_base('version').' ';
$help .= ''.__('Instruction','easy-table').':
'.__('Once plugin installed, go to plugin options page to configure some options','easy-table').' ';
$help .= ''.__('You are ready to write a table in post or page.','easy-table').' ';
$help .= ''.__('To be able write table in widget you have to check Enable render table in widget option in the option page.','easy-table').' ';
return $help;
}
}
/**
* Add plugin page
*/
function easy_table_add_page() {
add_options_page($this->easy_table_base('name'), $this->easy_table_base('name'), 'administrator', $this->easy_table_base('plugin-domain'), array(&$this,'easy_table_page'));
}
/**
* Plugin option page
*/
function easy_table_page() { ?>
easy_table_base('name'));?>
easy_table_base('plugin-domain');?>&gettab=themes" class="nav-tab ">
*/?>
');
}
if(isset($_POST['test-easy-table-reset'])){
$tableexample = $defaulttableexample;
}
?>
[table param1="param-value1" param2="param-value2"]table data[/table]
class , 'table-striped' , table-bordered, table-striped, table-condensed
caption , ''
width , '100%'
align , 'left'
th , 'true'
tf , 'false'
border , '0'
id , 'false'
tablesorter , 'false'
file , 'false'
sort , ''
trim , false
style , ''
limit , 0
terminator , \n
colalign , '' , see example on the test area
colwidth , '' , see example on the test area
exclude_row , '' , comma separated value, ex: exclude_row="1,3,5"
exclude_col , '' , comma separated value, ex: exclude_col="1,3,5"
sort
[table sort="desc,asc"]
col1,col2,col3
col4,col5,col6
[/table]
[table sort=",desc,asc"]
col1,col2,col3
col4,col5,col6
[/table]
attr ,
:
[table]
col1,col2[attr style="width:200px" class="someclass"],col3
col4,col5,col6
[/table]
attr sort ,
[table]
col1,col2[attr sort="desc"],col3
col4,col5,col6
[/table]
[table]
col1[attr sort="false"],col2,col3
col4,col5,col6
[/table]
To ask question, please visit this plugin support on WordPress.org
'easy-table' ));
?>
easy_table_base('name') .' ' . $this->easy_table_base('version'); ?>
download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>
' . __('Install Now') . '';
break;
case 'update_available':
if ( $status['url'] )
echo '' . __('Install Update Now') .' ';
break;
case 'newer_installed':
echo '' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . ' ';
break;
case 'latest_installed':
echo '' . __('Latest Version Installed') . ' ';
break;
}
?>
version) ) : ?>
version ?>
author) ) : ?>
author, '_blank') ?>
last_updated) ) : ?>
last_updated)) ) ?>
requires) ) : ?>
requires) ?>
tested) ) : ?>
tested ?>
downloaded) ) : ?>
downloaded), number_format_i18n($api->downloaded)) ?>
slug) && empty($api->external) ) : ?>
homepage) ) : ?>
rating) ) : ?>
num_ratings), number_format_i18n($api->num_ratings)); ?>
:
:
0) {
$array+=func_get_arg($n);
}
return $array;
}
}