📄 pluginbackup.php
字号:
<?php/** * class pluginBackup * * * * */include_once(MODOSDATE_DIR . 'modPlugin.php');class pluginBackup extends modPlugin { /** * Holds the language phrases * * @access private */ var $lang; /** * Holds the user id * * @access private */ var $uid; /** * Holds the user name * * @access private */ var $username; /** * Timestamp * * @access private */ var $time; /** * Backup Table * * @access private */ var $lang_backup_table = "pluginBackup_backup"; /** * The name name of the plugin class. * * @access private */ var $plugin_class_name = "pluginBackup"; /** * The text that appears in the admin plugin list * * @access private */ var $display_name; /** * The link text that appears on the user's menu * * @access private */ var $user_menu_text ; /** * Appear on users menu (true or false) * * @access private */ var $user_menu_appear = true; /** * The link text that appears on the admin's menu * * @access private */ var $admin_menu_text = ""; /** * Appear on admin's menu (true or false) * * @access private */ var $admin_menu_appear = false; /** * Constructor * * @return * @access public */ function pluginBackup() { $this->modPlugin(); $pluginDir = dirname(__FILE__).'/../'; $this->lang = $this->modLoadLang($pluginDir); $this->user_menu_text=$this->lang['user_title']; $this->display_name=$this->lang['user_title']; } // end of member method pluginClass function getHash() { $vars=array( 0 => md5($HTTP_USER_AGENT.$REMOTE_ADDR.$this->time), 1 => md5($HTTP_USER_AGENT.$this->time.$REMOTE_ADDR), 2 => md5($REMOTE_ADDR.$HTTP_USER_AGENT.$this->time), 3 => md5($REMOTE_ADDR.$this->time.$HTTP_USER_AGENT), 4 => md5($this->time.$REMOTE_ADDR.$HTTP_USER_AGENT), 5 => md5($this->time.$HTTP_USER_AGENT.$REMOTE_ADDR), 6 => md5($this->time.$this->time.$REMOTE_ADDR), 7 => md5($this->time.$this->time.$HTTP_USER_AGENT), 8 => md5($this->time.$REMOTE_ADDR.$this->time), 9 => md5($REMOTE_ADDR.$HTTP_USER_AGENT.$REMOTE_ADDR)); $var=substr(time(),(strlen(time())-1)); return $vars[$var]; } /** * Backup main function * * @return none * @access public */ function backup() { $date=date("Y_m_d_H_i_s",$this->time); $hash=$this->getHash(); $max=$this->getOne("SELECT count(*) FROM ! WHERE ts>? AND uid=?",array($this->lang_backup_table,$this->time-$this->config['backup_limit_time'],$this->uid)); $error=1; if($max<$this->config['backup_limit_op']) { $file=TEMP_DIR."backup_{$hash}_{$this->uid}_{$date}.xml"; $this->modSmartyAssign('path',"temp/backup_{$hash}_{$this->uid}_{$date}.xml"); $this->modSmartyAssign('hash',$hash); $this->modSmartyAssign('ts',$this->time); $ok=1; $text=$this->modSmartyFetch("xmltop.tpl"); if($_POST['b1']) {$text.=$this->backup1();$ok=0;} if($_POST['b2']) {$text.=$this->backup2();$ok=0;} if($_POST['b3']) {$text.=$this->backup3();$ok=0;} if($_POST['b4']) {$text.=$this->backup4();$ok=0;} if($_POST['b5']) {$text.=$this->backup5();$ok=0;} if($_POST['b6']) {$text.=$this->backup6();$ok=0;} if($ok) return $this->modSmartyFetch("backuprestore.tpl"); $text.=$this->modSmartyFetch("xmlbottom.tpl"); $handle=fopen("$file","w"); fwrite($handle,$text); fclose($handle); $this->query("INSERT INTO !(hash,uid,ts,size) VALUES(?,?,?,?)",array($this->lang_backup_table,$hash,$this->uid,$this->time,filesize($file))); $file2="backup_{$hash}_{$this->uid}_{$date}.xml";header('Content-type: application/xml');header("Content-Disposition: attachment; filename=\"$file2\"");readfile($file);exit; $error=0; } if($error) { $this->modSmartyAssign('error',$error); return $this->modSmartyFetch("backup2.tpl"); } else return $this->modSmartyFetch("backuprestore.tpl"); } /** * Remove certain fields from an array * * @return none * @access public */ function except($data,$fields) { foreach($data as $item=>$key) { if(!in_array($item,$fields)) $data2[$item]=htmlspecialchars($key); } return $data2; } /** * Backup the profile data of user * * @return none * @access public */ function backup1() { $profile=$this->modGetProfile(array('id'=>$this->uid)); $data=$this->getRow("SELECT * FROM ".USER_TABLE." WHERE id='$this->uid'"); $fields=array('id','active','username','password','lastvisit','regdate','level','rank','actkey','picture','status','levelend'); //except these fields $data=$this->except($data,$fields); $this->modSmartyAssign('data',$data); $data2=$this->getAll("SELECT * FROM ".USER_PREFERENCE_TABLE." WHERE userid='$this->uid' ORDER BY questionid ASC"); $this->modSmartyAssign('data2',$data2); $data3=$this->getAll("SELECT * FROM ".USER_CHOICES_TABLE." WHERE userid='$this->uid'"); $fields=array('id','userid','last_act_value','last_act_date'); $data3=$this->except($data3,$fields); $this->modSmartyAssign('data3',$data3); $text=$this->modSmartyFetch('xmlbackup1.tpl'); return $text; } /** * Backup pictures * * @return none * @access public */ function backup2() { $data=$this->getAll("SELECT * FROM ".USER_SNAP_TABLE." WHERE userid='$this->uid'"); $this->modSmartyAssign("data",$data); $text=$this->modSmartyFetch('xmlbackup2.tpl'); return $text; } /** * Backup messages * * @return none * @access public */ function backup3() { $data=$this->getAll("SELECT * FROM ".MAILBOX_TABLE." WHERE owner='$this->uid'"); $fields=array('id','owner'); foreach ($data as $item=>$key) { $item2=$this->except($key,$fields); $data[$item]=$item2; } $this->modSmartyAssign("data",$data); $text=$this->modSmartyFetch('xmlbackup3.tpl'); return $text; } /** * Backup views & winks * * @return none * @access public */ function backup4() { $data=$this->getAll("SELECT * FROM ".VIEWS_WINKS_TABLE." WHERE userid='$this->uid'"); $fields=array('id','userid'); foreach ($data as $item=>$key) { $item2=$this->except($key,$fields); $data[$item]=$item2; } $this->modSmartyAssign("data",$data); $text=$this->modSmartyFetch('xmlbackup4.tpl'); return $text; } /** * Backup buddy & ban list * * @return none * @access public */ function backup5() { $data=$this->getAll("SELECT * FROM ".BUDDY_BAN_TABLE." WHERE username='$this->username'"); $fields=array('id','username'); foreach ($data as $item=>$key) { $item2=$this->except($key,$fields); $data[$item]=$item2; } $this->modSmartyAssign("data",$data); $text=$this->modSmartyFetch('xmlbackup5.tpl'); return $text; } /** * Backup blog data * * @return none * @access public */ function backup6() { $data=$this->getRow("SELECT * FROM ".BLOG_PREFERENCES_TABLE." WHERE userid='$this->uid'"); $fields=array('id','userid','adminid'); //except these fields $data=$this->except($data,$fields); $this->modSmartyAssign('data',$data); $data=$this->getAll("SELECT * FROM ".BLOG_STORY_TABLE." WHERE userid='$this->uid'"); $fields=array('id','userid','adminid','views'); //except these fields foreach ($data as $item=>$key) { $item2=$this->except($key,$fields); $item2['title']=htmlspecialchars($item2['title']); $item2['story']=htmlspecialchars($item2['story']); $data[$item]=$item2; } $this->modSmartyAssign("data2",$data); $text=$this->modSmartyFetch('xmlbackup6.tpl'); return $text; }/** * XML Parser * $data will contain the parsed xml file */ var $parser; var $data = array(); var $datas = array(); function parse($data) { $this->parser = xml_parser_create('UTF-8'); xml_set_object($this->parser, $this); xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -