update
This commit is contained in:
@@ -0,0 +1,755 @@
|
||||
<?php
|
||||
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
class WPvivid_Snapshot_Function_Ex
|
||||
{
|
||||
public $options;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->options=new WPvivid_Snapshot_Option_Ex();
|
||||
}
|
||||
|
||||
public function check_manual_snapshot()
|
||||
{
|
||||
$snapshots=$this->options->get_option('wpvivid_snapshot');
|
||||
$manual_snapshots=array();
|
||||
if($snapshots !== false)
|
||||
{
|
||||
foreach ($snapshots as $snapshot)
|
||||
{
|
||||
if($snapshot['type']=='manual')
|
||||
{
|
||||
$manual_snapshots[]=$snapshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
$setting=$this->options->get_option('wpvivid_snapshot_setting');
|
||||
$count=isset($setting['snapshot_retention'])?$setting['snapshot_retention']:6;
|
||||
if(empty($count))
|
||||
{
|
||||
$count=6;
|
||||
}
|
||||
|
||||
usort($manual_snapshots, function ($a, $b)
|
||||
{
|
||||
if ($a['time'] == $b['time'])
|
||||
return 0;
|
||||
|
||||
if ($a['time'] > $b['time'])
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
});
|
||||
|
||||
while(count($manual_snapshots)>=$count)
|
||||
{
|
||||
$manual_snapshot=array_shift($manual_snapshots);
|
||||
$this->remove_snapshot($manual_snapshot['id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function create_merge_snapshot($comment='')
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$snapshot_id = 'wp'.$this->create_snapshot_uid();
|
||||
$tables = $wpdb->get_results('SHOW TABLE STATUS');
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_log';
|
||||
$exclude_tables[]=$wpdb->base_prefix."wpvivid_increment_big_ids";
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_merge_db';
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_options';
|
||||
$exclude_tables[]=$wpdb->base_prefix."wpvivid_record_task";
|
||||
$exclude_tables=apply_filters('wpvivid_create_snapshot_exclude_tables',$exclude_tables);
|
||||
|
||||
$snapshot_tables=array();
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
if (0 !== stripos($table->Name, $wpdb->prefix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (empty($table->Engine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(in_array($table->Name,$exclude_tables))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$snapshot_table['Name']=$table->Name;
|
||||
$snapshot_table['finished']=0;
|
||||
$snapshot_tables[$table->Name]=$snapshot_table;
|
||||
}
|
||||
|
||||
if (!empty($snapshot_tables))
|
||||
{
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
$new_table=$this->str_replace_first($wpdb->prefix,$snapshot_id,$table_name);
|
||||
|
||||
$wpdb->query("OPTIMIZE TABLE {$table_name}");
|
||||
$wpdb->query("CREATE TABLE `{$new_table}` LIKE `{$table_name}`");
|
||||
$wpdb->query("INSERT `{$new_table}` SELECT * FROM `{$table_name}`");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='create snapshot failed';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->update_snapshot($snapshot_id,'merge',$comment);
|
||||
$ret['result']='success';
|
||||
$ret['finished']=1;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function check_dev_snapshot()
|
||||
{
|
||||
$snapshots=$this->options->get_option('wpvivid_snapshot');
|
||||
$dev_snapshots=array();
|
||||
foreach ($snapshots as $snapshot)
|
||||
{
|
||||
if($snapshot['type']=='dev')
|
||||
{
|
||||
$dev_snapshots[]=$snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
$setting=$this->options->get_option('wpvivid_merge_setting');
|
||||
$count=isset($setting['snapshot_retention'])?$setting['snapshot_retention']:6;
|
||||
if(empty($count))
|
||||
{
|
||||
$count=6;
|
||||
}
|
||||
|
||||
while(count($dev_snapshots)>=$count)
|
||||
{
|
||||
usort($dev_snapshots, function ($a, $b)
|
||||
{
|
||||
if ($a['time'] == $b['time'])
|
||||
return 0;
|
||||
|
||||
if ($a['time'] > $b['time'])
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
});
|
||||
|
||||
$dev_snapshot=array_shift($dev_snapshots);
|
||||
$this->remove_snapshot($dev_snapshot['id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function create_dev_snapshot($task_data)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$snapshot_id = 'wp'.$this->create_snapshot_uid();
|
||||
$tables = $wpdb->get_results('SHOW TABLE STATUS');
|
||||
//$exclude_tables[]=$wpdb->prefix.'wpvivid_log';
|
||||
//$exclude_tables[]=$wpdb->prefix.'wpvivid_merge_db';
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_options';
|
||||
$exclude_tables[]=$wpdb->base_prefix."wpvivid_record_task";
|
||||
$exclude_tables=apply_filters('wpvivid_create_snapshot_exclude_tables',$exclude_tables);
|
||||
|
||||
$start_time=time();
|
||||
$snapshot_tables=array();
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
if (0 !== stripos($table->Name, $wpdb->prefix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (empty($table->Engine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(in_array($table->Name,$exclude_tables))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$snapshot_table['Name']=$table->Name;
|
||||
$snapshot_table['finished']=0;
|
||||
$snapshot_tables[$table->Name]=$snapshot_table;
|
||||
}
|
||||
|
||||
$this->init_task($snapshot_id,$snapshot_tables,'dev',$task_data['comment']);
|
||||
|
||||
if (!empty($snapshot_tables))
|
||||
{
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
if($snapshot_table['finished']==1)
|
||||
continue;
|
||||
|
||||
$new_table=$this->str_replace_first($wpdb->prefix,$snapshot_id,$table_name);
|
||||
|
||||
$wpdb->query("OPTIMIZE TABLE {$table_name}");
|
||||
$wpdb->query("CREATE TABLE `{$new_table}` LIKE `{$table_name}`");
|
||||
$wpdb->query("INSERT `{$new_table}` SELECT * FROM `{$table_name}`");
|
||||
|
||||
$snapshot_tables[$table_name]['finished']=1;
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
|
||||
if($this->is_time_limit_exceeded($start_time))
|
||||
{
|
||||
$ret['result']='success';
|
||||
$ret['finished']=0;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
$ret['snapshot_tables']=$snapshot_tables;
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='create snapshot failed';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->update_snapshot($snapshot_id,'dev',$task_data['comment']);
|
||||
$ret['result']='success';
|
||||
$ret['finished']=1;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function create_snapshot($type='',$comment='')
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$snapshot_id=$this->create_snapshot_uid();
|
||||
$snapshot_id = 'wp'.$snapshot_id;
|
||||
|
||||
$tables = $wpdb->get_results('SHOW TABLE STATUS');
|
||||
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_log';
|
||||
$exclude_tables[]=$wpdb->base_prefix."wpvivid_increment_big_ids";
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_merge_db';
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_options';
|
||||
$exclude_tables[]=$wpdb->base_prefix."wpvivid_record_task";
|
||||
$exclude_tables=apply_filters('wpvivid_create_snapshot_exclude_tables',$exclude_tables);
|
||||
|
||||
$start_time=time();
|
||||
$snapshot_tables=array();
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
if (0 !== stripos($table->Name, $wpdb->prefix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (empty($table->Engine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(in_array($table->Name,$exclude_tables))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$snapshot_table['Name']=$table->Name;
|
||||
$snapshot_table['finished']=0;
|
||||
$snapshot_tables[$table->Name]=$snapshot_table;
|
||||
}
|
||||
|
||||
if(empty($type))
|
||||
{
|
||||
$type='manual';
|
||||
}
|
||||
|
||||
$this->init_task($snapshot_id,$snapshot_tables,$type,$comment);
|
||||
|
||||
if (!empty($snapshot_tables))
|
||||
{
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
if($snapshot_table['finished']==1)
|
||||
continue;
|
||||
|
||||
$new_table=$this->str_replace_first($wpdb->prefix,$snapshot_id,$table_name);
|
||||
|
||||
$wpdb->query("OPTIMIZE TABLE {$table_name}");
|
||||
$wpdb->query("DROP TABLE IF EXISTS `{$new_table}`");
|
||||
$wpdb->query("CREATE TABLE `{$new_table}` LIKE `{$table_name}`");
|
||||
$wpdb->query("INSERT `{$new_table}` SELECT * FROM `{$table_name}`");
|
||||
|
||||
$snapshot_tables[$table_name]['finished']=1;
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
|
||||
if($this->is_time_limit_exceeded($start_time))
|
||||
{
|
||||
$ret['result']='success';
|
||||
$ret['finished']=0;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
$ret['snapshot_tables']=$snapshot_tables;
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Creating the snapshot failed.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
$this->update_snapshot($snapshot_id,$type,$comment);
|
||||
$ret['result']='success';
|
||||
$ret['finished']=1;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function resume_create_snapshot()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$start_time=time();
|
||||
|
||||
$ret=$this->get_task_data();
|
||||
if($ret['result']=='failed')
|
||||
{
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$snapshot_id=$ret['snapshot_id'];
|
||||
$snapshot_tables=$ret['snapshot_tables'];
|
||||
$type=$ret['type'];
|
||||
$comment=$ret['comment'];
|
||||
|
||||
if (!empty($snapshot_tables))
|
||||
{
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
if($snapshot_table['finished']==1)
|
||||
continue;
|
||||
|
||||
$new_table=$this->str_replace_first($wpdb->prefix,$snapshot_id,$table_name);
|
||||
|
||||
$wpdb->query("OPTIMIZE TABLE {$table_name}");
|
||||
$wpdb->query("DROP TABLE IF EXISTS `{$new_table}`");
|
||||
$wpdb->query("CREATE TABLE `{$new_table}` LIKE `{$table_name}`");
|
||||
$wpdb->query("INSERT `{$new_table}` SELECT * FROM `{$table_name}`");
|
||||
|
||||
$snapshot_tables[$table_name]['finished']=1;
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
if($this->is_time_limit_exceeded($start_time))
|
||||
{
|
||||
$ret['result']='success';
|
||||
$ret['finished']=0;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
$ret['snapshot_tables']=$snapshot_tables;
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Creating the snapshot failed.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->update_task($snapshot_id,$snapshot_tables);
|
||||
$this->update_snapshot($snapshot_id,$type,$comment);
|
||||
$ret['result']='success';
|
||||
$ret['finished']=1;
|
||||
$ret['snapshot_id']=$snapshot_id;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function init_task($snapshot_id,$snapshot_tables,$type,$comment)
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$snapshot_task=array();
|
||||
}
|
||||
|
||||
$snapshot_task['snapshot_id']=$snapshot_id;
|
||||
$snapshot_task['snapshot_tables']=$snapshot_tables;
|
||||
$snapshot_task['type']=$type;
|
||||
$snapshot_task['comment']=$comment;
|
||||
|
||||
$this->options->update_option('wpvivid_snapshot_task',$snapshot_task);
|
||||
}
|
||||
|
||||
public function get_progress()
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$progress['main_percent']='0%';
|
||||
$progress['doing']="Creating a snapshot.";
|
||||
}
|
||||
|
||||
$snapshot_tables=$snapshot_task['snapshot_tables'];
|
||||
$i_sum=count($snapshot_tables);
|
||||
$i_finished=0;
|
||||
$b_finished=true;
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
if($snapshot_table['finished']==1)
|
||||
{
|
||||
$i_finished++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$b_finished=false;
|
||||
}
|
||||
}
|
||||
|
||||
$i_progress=intval(($i_finished/$i_sum)*100);
|
||||
$progress['main_percent']=$i_progress.'%';
|
||||
if($b_finished)
|
||||
{
|
||||
$progress['doing']="Create snapshot completed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
$progress['doing']="Creating a snapshot.";
|
||||
}
|
||||
|
||||
return $progress;
|
||||
}
|
||||
|
||||
public function update_task($snapshot_id,$snapshot_tables)
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$snapshot_task=array();
|
||||
}
|
||||
|
||||
$snapshot_task['snapshot_id']=$snapshot_id;
|
||||
$snapshot_task['snapshot_tables']=$snapshot_tables;
|
||||
|
||||
$this->options->update_option('wpvivid_snapshot_task',$snapshot_task);
|
||||
}
|
||||
|
||||
public function get_task_data()
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Creating snapshot task not found.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if(empty($snapshot_task['snapshot_id'])||empty($snapshot_task['snapshot_tables']))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Creating snapshot task not found.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['snapshot_id']=$snapshot_task['snapshot_id'];
|
||||
$ret['snapshot_tables']=$snapshot_task['snapshot_tables'];
|
||||
$ret['type']=$snapshot_task['type'];
|
||||
$ret['comment']=$snapshot_task['comment'];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function get_snapshots($type='')
|
||||
{
|
||||
$snapshot_data=$this->options->get_option('wpvivid_snapshot');
|
||||
if(empty($snapshot_data))
|
||||
{
|
||||
$snapshot_data=array();
|
||||
}
|
||||
|
||||
if(empty($type))
|
||||
{
|
||||
return $snapshot_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$get_snapshot_data=array();
|
||||
foreach ($snapshot_data as $data)
|
||||
{
|
||||
if($data['type']==$type)
|
||||
{
|
||||
$get_snapshot_data[]=$data;
|
||||
}
|
||||
}
|
||||
return $snapshot_data;
|
||||
}
|
||||
}
|
||||
|
||||
public function restore_snapshot($snapshot_id)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$tables = $wpdb->get_results('SHOW TABLE STATUS');
|
||||
|
||||
//$exclude_tables[]=$wpdb->prefix.'wpvivid_log';
|
||||
//$exclude_tables[]=$wpdb->base_prefix."wpvivid_increment_big_ids";
|
||||
//$exclude_tables[]=$wpdb->prefix.'wpvivid_merge_db';
|
||||
$exclude_tables[]=$wpdb->prefix.'wpvivid_options';
|
||||
$exclude_tables=apply_filters('wpvivid_create_snapshot_exclude_tables',$exclude_tables);
|
||||
|
||||
add_filter('wpvivid_merge_query_lock', array($this,'query_lock'), 9999);
|
||||
|
||||
$new_tables = array();
|
||||
if (is_array($tables))
|
||||
{
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
if (0 !== stripos($table->Name, $snapshot_id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($table->Engine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(in_array($table->Name,$exclude_tables))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_table['Name']=$table->Name;
|
||||
$new_table['finished']=0;
|
||||
$new_tables[$table->Name] =$new_table;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Failed to retrieve list of database tables.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$this->init_restore_task($snapshot_id,$new_tables);
|
||||
|
||||
/*
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
if (0 !== stripos($table->Name, $wpdb->prefix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (empty($table->Engine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(in_array($table->Name,$exclude_tables))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$wpdb->query('DROP TABLE ' . $table->Name);
|
||||
}*/
|
||||
|
||||
foreach ($new_tables as $table_name=>$table)
|
||||
{
|
||||
$new_table=$this->str_replace_first($snapshot_id,$wpdb->prefix,$table_name);
|
||||
|
||||
$wpdb->query('DROP TABLE ' . $new_table);
|
||||
$wpdb->query("CREATE TABLE `{$new_table}` LIKE `{$table_name}`");
|
||||
$wpdb->query("INSERT `{$new_table}` SELECT * FROM `{$table_name}`");
|
||||
$new_tables[$table_name]['finished']=1;
|
||||
$this->update_restore_task($snapshot_id,$new_tables);
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function init_restore_task($snapshot_id,$snapshot_tables)
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_restore_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$snapshot_task=array();
|
||||
}
|
||||
|
||||
$snapshot_task['snapshot_id']=$snapshot_id;
|
||||
$snapshot_task['snapshot_tables']=$snapshot_tables;
|
||||
|
||||
$this->options->update_option('wpvivid_restore_snapshot_task',$snapshot_task);
|
||||
}
|
||||
|
||||
public function update_restore_task($snapshot_id,$snapshot_tables)
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_restore_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$snapshot_task=array();
|
||||
}
|
||||
|
||||
$snapshot_task['snapshot_id']=$snapshot_id;
|
||||
$snapshot_task['snapshot_tables']=$snapshot_tables;
|
||||
|
||||
$this->options->update_option('wpvivid_restore_snapshot_task',$snapshot_task);
|
||||
}
|
||||
|
||||
public function get_restore_task_data()
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_restore_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Restoring snapshot task not found.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if(empty($snapshot_task['snapshot_id'])||empty($snapshot_task['snapshot_tables']))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Restoring snapshot task not found.';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['snapshot_id']=$snapshot_task['snapshot_id'];
|
||||
$ret['snapshot_tables']=$snapshot_task['snapshot_tables'];
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function remove_snapshot($snapshot_id)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$tables = $wpdb->get_col($wpdb->prepare('SHOW TABLES LIKE %s', array($snapshot_id . '%')));
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
$wpdb->query('DROP TABLE IF EXISTS `' . $table.'`');
|
||||
}
|
||||
|
||||
$snapshot_data=$this->options->get_option('wpvivid_snapshot');
|
||||
unset($snapshot_data[$snapshot_id]);
|
||||
$this->options->update_option('wpvivid_snapshot',$snapshot_data);
|
||||
|
||||
$ret['result']='success';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function str_replace_first($from, $to, $content)
|
||||
{
|
||||
$from = '/'.preg_quote($from, '/').'/';
|
||||
|
||||
return preg_replace($from, $to, $content, 1);
|
||||
}
|
||||
|
||||
public function create_snapshot_uid()
|
||||
{
|
||||
global $wpdb;
|
||||
$count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
$count++;
|
||||
$uid = sprintf('%06x', wp_rand(0, 0xFFFFFF));
|
||||
|
||||
$verify_db = $wpdb->get_col($wpdb->prepare('SHOW TABLES LIKE %s', array('%' . $uid . '%')));
|
||||
|
||||
} while (!empty($verify_db) && $count < 10);
|
||||
|
||||
if ($count == 10)
|
||||
{
|
||||
$uid = false;
|
||||
}
|
||||
|
||||
return $uid;
|
||||
}
|
||||
|
||||
public function update_snapshot($snapshot_id,$type,$comment)
|
||||
{
|
||||
$snapshot_data=$this->options->get_option('wpvivid_snapshot');
|
||||
if(empty($snapshot_data))
|
||||
{
|
||||
$snapshot_data=array();
|
||||
}
|
||||
|
||||
$snapshot_data[$snapshot_id]['id']=$snapshot_id;
|
||||
$snapshot_data[$snapshot_id]['type']=$type;
|
||||
$snapshot_data[$snapshot_id]['time']=time();
|
||||
$snapshot_data[$snapshot_id]['comment']=$comment;
|
||||
|
||||
$this->options->update_option('wpvivid_snapshot',$snapshot_data);
|
||||
}
|
||||
|
||||
public function is_time_limit_exceeded($start_time)
|
||||
{
|
||||
$time_limit =20;
|
||||
$time_taken = microtime(true) -$start_time;
|
||||
if($time_taken >= $time_limit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_dev_progress()
|
||||
{
|
||||
$snapshot_task=$this->options->get_option('wpvivid_snapshot_task');
|
||||
if(empty($snapshot_task))
|
||||
{
|
||||
$progress['main_percent']='0%';
|
||||
$progress['text']="creating snapshot for dev site.";
|
||||
}
|
||||
|
||||
$snapshot_tables=$snapshot_task['snapshot_tables'];
|
||||
$i_sum=count($snapshot_tables);
|
||||
$i_finished=0;
|
||||
$b_finished=true;
|
||||
foreach ($snapshot_tables as $table_name=>$snapshot_table)
|
||||
{
|
||||
if($snapshot_table['finished']==1)
|
||||
{
|
||||
$i_finished++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$b_finished=false;
|
||||
}
|
||||
}
|
||||
|
||||
$i_progress=intval(($i_finished/$i_sum)*100);
|
||||
$progress['main_percent']=$i_progress.'%';
|
||||
if($b_finished)
|
||||
{
|
||||
$progress['text']="creating snapshot for dev site completed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
$progress['text']="creating snapshot for dev site - $i_finished/$i_sum tables";
|
||||
}
|
||||
|
||||
return $progress;
|
||||
}
|
||||
|
||||
public function query_lock($lock)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
class WPvivid_Snapshot_Option_Ex
|
||||
{
|
||||
public $options_table;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $wpdb;
|
||||
$this->options_table = $wpdb->base_prefix."wpvivid_options";
|
||||
//$this->check_tables();
|
||||
}
|
||||
|
||||
public function check_tables()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if($wpdb->get_var("SHOW TABLES LIKE '$this->options_table'") != $this->options_table)
|
||||
{
|
||||
$sql = "CREATE TABLE IF NOT EXISTS $this->options_table (
|
||||
`option_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`option_name` varchar(191) NOT NULL DEFAULT '',
|
||||
`option_value` longtext NOT NULL,
|
||||
PRIMARY KEY (`option_id`),
|
||||
UNIQUE KEY `option_name` (`option_name`)
|
||||
);";
|
||||
|
||||
$wpdb->query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_option($option_name)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if($wpdb->get_var("SHOW TABLES LIKE '$this->options_table'") != $this->options_table)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$query =$wpdb->prepare('select option_value from '.$this->options_table .' where option_name = %s', $option_name);
|
||||
|
||||
$result =$wpdb->get_var($query);
|
||||
if(empty($result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return maybe_unserialize($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function update_option($option_name,$value)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if($this->is_exists_option($option_name))
|
||||
{
|
||||
$option_value = maybe_serialize($value);
|
||||
return $wpdb->update($this->options_table, compact('option_name', 'option_value'), compact('option_name'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$option_value = maybe_serialize($value);
|
||||
return $wpdb->insert($this->options_table, compact('option_name', 'option_value'));
|
||||
}
|
||||
}
|
||||
|
||||
public function is_exists_option($option_name)
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$query = $wpdb->prepare('select option_value from '.$this->options_table.' where option_name = %s', $option_name);
|
||||
$result =$wpdb->get_row($query);
|
||||
return !empty($result);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_List_Table' ) )
|
||||
{
|
||||
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPvivid_Snapshots_List_Ex' ) )
|
||||
{
|
||||
class WPvivid_Snapshots_List_Ex extends WP_List_Table
|
||||
{
|
||||
public $page_num;
|
||||
public $Snapshots_list;
|
||||
|
||||
public function __construct( $args = array() )
|
||||
{
|
||||
parent::__construct(
|
||||
array(
|
||||
'plural' => 'snapshots',
|
||||
'screen' => 'snapshots'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_table_classes()
|
||||
{
|
||||
return array( 'widefat striped' );
|
||||
}
|
||||
|
||||
public function get_columns()
|
||||
{
|
||||
$columns = array();
|
||||
$columns['cb'] = __( 'cb', 'wpvivid-snapshot-database' );
|
||||
$columns['wpvivid_time'] = __( 'Time', 'wpvivid-snapshot-database' );
|
||||
$columns['wpvivid_type'] = __( 'Type', 'wpvivid-snapshot-database' );
|
||||
$columns['wpvivid_prefix'] = __( 'Prefix', 'wpvivid-snapshot-database' );
|
||||
$columns['wpvivid_comment'] = __( 'Comment', 'wpvivid-snapshot-database' );
|
||||
$columns['wpvivid_actions'] = __( 'Actions', 'wpvivid-snapshot-database' );
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function column_cb( $data )
|
||||
{
|
||||
echo '<input type="checkbox"/>';
|
||||
}
|
||||
|
||||
public function _column_wpvivid_time( $data )
|
||||
{
|
||||
$time = gmdate('M-d-Y H:i', $data['time']);
|
||||
echo '<td>' . esc_html( $time ) . '</td>';
|
||||
}
|
||||
|
||||
public function _column_wpvivid_type( $data )
|
||||
{
|
||||
echo '<td>' . esc_html( $data['type'] ) . '</td>';
|
||||
}
|
||||
|
||||
public function _column_wpvivid_prefix( $data )
|
||||
{
|
||||
echo '<td>' . esc_html( $data['id'] ) . '</td>';
|
||||
}
|
||||
|
||||
public function _column_wpvivid_comment( $data )
|
||||
{
|
||||
echo '<td>' . esc_html($data['comment'] ) . '</td>';
|
||||
}
|
||||
|
||||
public function _column_wpvivid_actions( $data )
|
||||
{
|
||||
echo '<td>
|
||||
<div style="cursor:pointer;float:left;">
|
||||
<span class="dashicons dashicons-update wpvivid-dashicons-green wpvivid-snapshot-restore"></span>
|
||||
<span class="wpvivid-snapshot-restore">Restore</span>
|
||||
<span style="width:1rem;">|</span>
|
||||
<span class="dashicons dashicons-trash wpvivid-dashicons-grey wpvivid-snapshot-delete"></span>
|
||||
<span class="wpvivid-snapshot-delete">Delete</span>
|
||||
</div>
|
||||
</td>';
|
||||
}
|
||||
|
||||
public function set_list($Snapshots_list,$page_num=1)
|
||||
{
|
||||
$this->Snapshots_list=$Snapshots_list;
|
||||
$this->page_num=$page_num;
|
||||
}
|
||||
|
||||
public function get_pagenum()
|
||||
{
|
||||
if($this->page_num=='first')
|
||||
{
|
||||
$this->page_num=1;
|
||||
}
|
||||
else if($this->page_num=='last')
|
||||
{
|
||||
$this->page_num=$this->_pagination_args['total_pages'];
|
||||
}
|
||||
$pagenum = $this->page_num ? $this->page_num : 0;
|
||||
|
||||
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
|
||||
{
|
||||
$pagenum = $this->_pagination_args['total_pages'];
|
||||
}
|
||||
|
||||
return max( 1, $pagenum );
|
||||
}
|
||||
|
||||
public function prepare_items()
|
||||
{
|
||||
$columns = $this->get_columns();
|
||||
$hidden = array();
|
||||
$sortable = array();
|
||||
$this->_column_headers = array($columns, $hidden, $sortable);
|
||||
|
||||
$total_items =sizeof($this->Snapshots_list);
|
||||
|
||||
$this->set_pagination_args(
|
||||
array(
|
||||
'total_items' => $total_items,
|
||||
'per_page' => 10,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function has_items()
|
||||
{
|
||||
return !empty($this->Snapshots_list);
|
||||
}
|
||||
|
||||
public function display_rows()
|
||||
{
|
||||
$this->_display_rows($this->Snapshots_list);
|
||||
}
|
||||
|
||||
private function _display_rows($Snapshots_list)
|
||||
{
|
||||
$page=$this->get_pagenum();
|
||||
|
||||
$page_file_list=array();
|
||||
$count=0;
|
||||
while ( $count<$page )
|
||||
{
|
||||
$page_file_list = array_splice( $Snapshots_list, 0, 10);
|
||||
$count++;
|
||||
}
|
||||
foreach ( $page_file_list as $data)
|
||||
{
|
||||
$this->single_row($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function single_row($data)
|
||||
{
|
||||
?>
|
||||
<tr class='wpvivid-snapshot-row' slug="<?php echo esc_attr($data['id']);?>">
|
||||
<?php $this->single_row_columns( $data ); ?>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function pagination( $which )
|
||||
{
|
||||
if ( empty( $this->_pagination_args ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$total_items = $this->_pagination_args['total_items'];
|
||||
$total_pages = $this->_pagination_args['total_pages'];
|
||||
$infinite_scroll = false;
|
||||
if ( isset( $this->_pagination_args['infinite_scroll'] ) )
|
||||
{
|
||||
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
|
||||
}
|
||||
|
||||
if ( 'top' === $which && $total_pages > 1 )
|
||||
{
|
||||
$this->screen->render_screen_reader_content( 'heading_pagination' );
|
||||
}
|
||||
|
||||
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
|
||||
|
||||
$current = $this->get_pagenum();
|
||||
|
||||
$page_links = array();
|
||||
|
||||
$total_pages_before = '<span class="paging-input">';
|
||||
$total_pages_after = '</span></span>';
|
||||
|
||||
$disable_first = $disable_last = $disable_prev = $disable_next = false;
|
||||
|
||||
if ( $current == 1 ) {
|
||||
$disable_first = true;
|
||||
$disable_prev = true;
|
||||
}
|
||||
if ( $current == 2 ) {
|
||||
$disable_first = true;
|
||||
}
|
||||
if ( $current == $total_pages ) {
|
||||
$disable_last = true;
|
||||
$disable_next = true;
|
||||
}
|
||||
if ( $current == $total_pages - 1 ) {
|
||||
$disable_last = true;
|
||||
}
|
||||
|
||||
if ( $disable_first ) {
|
||||
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>';
|
||||
} else {
|
||||
$page_links[] = sprintf(
|
||||
"<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
||||
__( 'First page' ),
|
||||
'«'
|
||||
);
|
||||
}
|
||||
|
||||
if ( $disable_prev ) {
|
||||
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>';
|
||||
} else {
|
||||
$page_links[] = sprintf(
|
||||
"<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
||||
$current,
|
||||
__( 'Previous page' ),
|
||||
'‹'
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'bottom' === $which ) {
|
||||
$html_current_page = $current;
|
||||
$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
|
||||
} else {
|
||||
$html_current_page = sprintf(
|
||||
"%s<input class='current-page' id='current-page-selector-filelist' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
|
||||
'<label for="current-page-selector-filelist" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
|
||||
$current,
|
||||
strlen( $total_pages )
|
||||
);
|
||||
}
|
||||
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
|
||||
$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
|
||||
|
||||
if ( $disable_next ) {
|
||||
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>';
|
||||
} else {
|
||||
$page_links[] = sprintf(
|
||||
"<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
||||
$current,
|
||||
__( 'Next page' ),
|
||||
'›'
|
||||
);
|
||||
}
|
||||
|
||||
if ( $disable_last ) {
|
||||
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>';
|
||||
} else {
|
||||
$page_links[] = sprintf(
|
||||
"<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
|
||||
__( 'Last page' ),
|
||||
'»'
|
||||
);
|
||||
}
|
||||
|
||||
$pagination_links_class = 'pagination-links';
|
||||
if ( ! empty( $infinite_scroll ) ) {
|
||||
$pagination_links_class .= ' hide-if-js';
|
||||
}
|
||||
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
|
||||
|
||||
if ( $total_pages ) {
|
||||
$page_class = $total_pages < 2 ? ' one-page' : '';
|
||||
} else {
|
||||
$page_class = ' no-pages';
|
||||
}
|
||||
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
|
||||
|
||||
echo $this->_pagination;
|
||||
}
|
||||
|
||||
protected function display_tablenav( $which ) {
|
||||
$css_type = '';
|
||||
if ( 'top' === $which ) {
|
||||
wp_nonce_field( 'bulk-' . $this->_args['plural'] );
|
||||
$css_type = 'margin: 0 0 10px 0';
|
||||
}
|
||||
else if( 'bottom' === $which ) {
|
||||
$css_type = 'margin: 10px 0 0 0';
|
||||
}
|
||||
|
||||
$total_pages = $this->_pagination_args['total_pages'];
|
||||
if ( $total_pages >1 && 'top' === $which)
|
||||
{
|
||||
?>
|
||||
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php echo esc_attr($css_type); ?>">
|
||||
<input type="submit" id="wpvivid_delete_snapshots_action" class="button action" value="Delete the selected snapshots">
|
||||
<?php
|
||||
$this->extra_tablenav( $which );
|
||||
$this->pagination( $which );
|
||||
?>
|
||||
|
||||
<br class="clear" />
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else if($total_pages >1)
|
||||
{
|
||||
?>
|
||||
<div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php echo esc_attr($css_type); ?>">
|
||||
<?php
|
||||
$this->extra_tablenav( $which );
|
||||
$this->pagination( $which );
|
||||
?>
|
||||
|
||||
<br class="clear" />
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else if($total_pages <=1 && 'top' === $which)
|
||||
{
|
||||
?>
|
||||
<input type="submit" id="wpvivid_delete_snapshots_action" class="button action" value="Delete the selected snapshots">
|
||||
<p></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$singular = $this->_args['singular'];
|
||||
|
||||
$this->display_tablenav( 'top' );
|
||||
|
||||
$this->screen->render_screen_reader_content( 'heading_list' );
|
||||
?>
|
||||
<table class="wp-list-table <?php echo esc_attr(implode( ' ', $this->get_table_classes() )); ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php $this->print_column_headers(); ?>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody id="the-list"
|
||||
<?php
|
||||
if ( $singular ) {
|
||||
echo esc_attr(" data-wp-lists='list:$singular'");
|
||||
}
|
||||
?>
|
||||
>
|
||||
<?php $this->display_rows_or_placeholder(); ?>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
<?php
|
||||
$this->display_tablenav( 'bottom' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
if (!defined('WPVIVID_PLUGIN_DIR'))
|
||||
{
|
||||
die;
|
||||
}
|
||||
|
||||
if(!class_exists('WPvivid_Tab_Page_Container'))
|
||||
{
|
||||
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tab-page-container.php';
|
||||
}
|
||||
|
||||
class WPvivid_Tab_Page_Container_Ex extends WPvivid_Tab_Page_Container
|
||||
{
|
||||
public $is_transparency=0;
|
||||
|
||||
public function add_tab($title,$slug,$callback,$args=array())
|
||||
{
|
||||
$new_tab['title']=$title;
|
||||
$new_tab['slug']=$slug;
|
||||
$new_tab['page']=$callback;
|
||||
foreach ($args as $key=>$arg)
|
||||
{
|
||||
$new_tab[$key]=$arg;
|
||||
if($key === 'is_parent_tab') {
|
||||
$this->is_parent_tab = $arg;
|
||||
}
|
||||
if($key === 'transparency'){
|
||||
$this->is_transparency = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$this->tabs[]=$new_tab;
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$class = '';
|
||||
if($this->is_transparency){
|
||||
$class .= ' wpvivid-intab-addon';
|
||||
}
|
||||
?>
|
||||
<div class="wpvivid-one-coloum" id="<?php echo esc_attr($this->container_id); ?>">
|
||||
<h2 class="nav-tab-wrapper wpvivid-nav-tab-wrapper">
|
||||
<?php
|
||||
$this->display_tabs();
|
||||
?>
|
||||
</h2>
|
||||
</div>
|
||||
<?php
|
||||
if($this->is_parent_tab){
|
||||
?>
|
||||
<div style="margin: 10px 0 0 2px;">
|
||||
<div id="poststuff" style="padding-top: 0;">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
<div id="post-body-content">
|
||||
<div class="inside" style="margin-top:0;">
|
||||
<div>
|
||||
<?php
|
||||
$this->display_page();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
<div class="meta-box-sortables">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
else{
|
||||
?>
|
||||
<?php
|
||||
$this->display_page();
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').on("click",".<?php echo esc_js($this->container_id)?>-tab",function()
|
||||
{
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').find( '.<?php echo esc_js($this->container_id)?>-tab' ).each(function()
|
||||
{
|
||||
jQuery(this).removeClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
|
||||
jQuery('.<?php echo esc_js($this->container_id)?>-content').each(function()
|
||||
{
|
||||
jQuery(this).hide();
|
||||
});
|
||||
|
||||
var id=jQuery(this).attr('id');
|
||||
id= id.substr(12);
|
||||
|
||||
jQuery("#wpvivid_page_"+id).show();
|
||||
jQuery(this).addClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
var top = jQuery(this).offset().top-jQuery(this).height();
|
||||
jQuery('html, body').animate({scrollTop:top}, 'slow');
|
||||
});
|
||||
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').on("click",".nav-tab-delete-img-addon",function(event)
|
||||
{
|
||||
event.stopPropagation();
|
||||
var redirect=jQuery(this).attr('redirect');
|
||||
jQuery(this).parent().hide();
|
||||
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').find( '.<?php echo esc_js($this->container_id)?>-tab' ).each(function()
|
||||
{
|
||||
jQuery(this).removeClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
|
||||
jQuery('.<?php echo esc_js($this->container_id)?>-content').each(function()
|
||||
{
|
||||
jQuery(this).hide();
|
||||
});
|
||||
|
||||
jQuery("#wpvivid_page_"+redirect).show();
|
||||
jQuery("#wpvivid_tab_"+redirect).addClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
//jQuery(this).addClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
|
||||
jQuery(document).ready(function($)
|
||||
{
|
||||
jQuery(document).on('<?php echo esc_js($this->container_id)?>-show', function(event,id,redirect)
|
||||
{
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').find( '.<?php echo esc_js($this->container_id)?>-tab' ).each(function()
|
||||
{
|
||||
jQuery(this).removeClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
|
||||
jQuery('.<?php echo esc_js($this->container_id); ?>-content').each(function()
|
||||
{
|
||||
jQuery(this).hide();
|
||||
});
|
||||
|
||||
jQuery("#wpvivid_page_"+id).show();
|
||||
jQuery("#wpvivid_tab_"+id).show();
|
||||
jQuery("#wpvivid_tab_"+id).find( '.nav-tab-delete-img-addon' ).each(function()
|
||||
{
|
||||
jQuery(this).attr('redirect',redirect);
|
||||
});
|
||||
jQuery("#wpvivid_tab_"+id).addClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
var top = jQuery("#wpvivid_tab_"+id).offset().top-jQuery("#wpvivid_tab_"+id).height();
|
||||
jQuery('html, body').animate({scrollTop:top}, 'slow');
|
||||
});
|
||||
|
||||
jQuery(document).on('<?php echo esc_js($this->container_id)?>-delete', function(event,id,redirect)
|
||||
{
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').find( '.<?php echo esc_js($this->container_id)?>-tab' ).each(function()
|
||||
{
|
||||
jQuery(this).removeClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
|
||||
jQuery('#<?php echo esc_js($this->container_id)?>').find( '.<?php echo esc_js($this->container_id)?>-content' ).each(function()
|
||||
{
|
||||
jQuery(this).hide();
|
||||
});
|
||||
|
||||
jQuery("#wpvivid_page_"+id).hide();
|
||||
jQuery("#wpvivid_tab_"+id).hide();
|
||||
jQuery("#wpvivid_page_"+redirect).show();
|
||||
jQuery("#wpvivid_tab_"+redirect).addClass( "nav-tab-active wpvivid-nav-tab-active" );
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function display_tabs()
|
||||
{
|
||||
$first=true;
|
||||
|
||||
foreach ($this->tabs as $tab)
|
||||
{
|
||||
$class='nav-tab wpvivid-nav-tab '.$this->container_id.'-tab';
|
||||
$span_class='';
|
||||
$span_style='';
|
||||
if($first)
|
||||
{
|
||||
$class.=' nav-tab-active wpvivid-nav-tab-active';
|
||||
$first=false;
|
||||
}
|
||||
|
||||
$style='cursor:pointer;';
|
||||
|
||||
if(isset($tab['hide']))
|
||||
{
|
||||
$style.=' display: none';
|
||||
}
|
||||
|
||||
if(isset($tab['span_class']))
|
||||
{
|
||||
$span_class.=$tab['span_class'];
|
||||
}
|
||||
if(isset($tab['span_style']))
|
||||
{
|
||||
$span_style.=$tab['span_style'];
|
||||
}
|
||||
if(isset($tab['can_delete']))
|
||||
{
|
||||
$class.=' delete';
|
||||
}
|
||||
if(isset($tab['transparency']))
|
||||
{
|
||||
$class.=' wpvivid-transparency-tab';
|
||||
}
|
||||
|
||||
echo '<a id="wpvivid_tab_'.esc_attr($tab['slug']).'" class="'.esc_attr($class).'" style="'.esc_attr($style).'">';
|
||||
|
||||
if(isset($tab['can_delete']))
|
||||
{
|
||||
echo '<span class="'.esc_attr($span_class).'" style="'.esc_attr($span_style).'"></span><span style="padding-right: 1em;">'.esc_attr($tab['title']).'</span>';
|
||||
if(isset($tab['redirect']))
|
||||
{
|
||||
echo '<div class="nav-tab-delete-img-addon" redirect="'.esc_attr($tab['redirect']).'">
|
||||
<span class="dashicons dashicons-no-alt wpvivid-dashicons-grey" style="width: 15px; height: 15px; font-size: 15px; padding-top: 0.4em;">
|
||||
</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<div class="nav-tab-delete-img-addon">
|
||||
<span class="dashicons dashicons-no-alt wpvivid-dashicons-grey" style="width: 15px; height: 15px; font-size: 15px; padding-top: 0.4em;">
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<span class="'.esc_attr($span_class).'" style="'.esc_attr($span_style).'"></span><span>'.esc_attr($tab['title']).'</span>';
|
||||
}
|
||||
echo '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
public function display_page()
|
||||
{
|
||||
$first=true;
|
||||
foreach ($this->tabs as $tab)
|
||||
{
|
||||
//delete
|
||||
/*$style='display: none;';
|
||||
if($first)
|
||||
{
|
||||
if(isset($tab['hide']))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$style='';
|
||||
$first=false;
|
||||
}
|
||||
}*/
|
||||
if(isset($tab['div_style']))
|
||||
{
|
||||
$style = $tab['div_style'];
|
||||
}
|
||||
else{
|
||||
$style='display: none;';
|
||||
}
|
||||
|
||||
$class='wpvivid-one-coloum wpvivid-tabcontent ';
|
||||
$class.=$this->container_id.'-content';
|
||||
echo '<div id="wpvivid_page_'.esc_attr($tab['slug']).'" class="'.esc_attr($class).'" style="'.esc_attr($style).'">';
|
||||
call_user_func($tab['page']);
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user