$message_bool = false; } } /** * 删除文件 * @since 1 */ if (isset($_GET['del']) == true) { $del_view = $oapost->view($_GET['del']); if ($del_view) { $del_view_list = $oapost->view_list_row(null, null, null, null, $post_type, $del_view['post_parent']); if ($del_view_list < 2) { $del_parent = $oapost->view($del_view['post_parent']); if ($del_parent) { if ($oapost->del($del_parent['id']) == true) { if (!corefile::delete_file($del_parent['post_url'])) { $message = '无法删除该文件。'; $message_bool = false; } } else { $message = '无法删除该文件。'; $message_bool = false; } } } //删除引用ID if ($oapost->del($_GET['del']) == true && $message == '') { $message = '删除成功。'; $message_bool = true; } else { $message = '无法删除该文件。';
/** * 添加文件到压缩包 * @since 2 * @param ZipArchive $zip 压缩操作句柄 * @param string $src 源文件路径 * @param string $dest 压缩包内的路径 * @return boolean */ public static function create_zip_add(&$zip, $src, $dest = null) { $return = false; if ($dest == null) { $dest = basename($src); } if (corefile::is_dir($src)) { if ($zip->addEmptyDir($dest) == true) { $dir_list = corefile::list_dir($src, '*'); foreach ($dir_list as $v) { $v_src = basename($v); $v_dest = $dest . DS . $v_src; $return = corefile::create_zip_add($zip, $v, $v_dest); } } } else { $return = $zip->addFile($src, $dest); } return $return; }
if (corefile::is_file($backup_filename) == true) { if (corefile::delete_file($backup_filename) == true) { $message = '删除成功!'; $message_bool = true; } } if (!$message) { $message = '无法删除该备份文件!'; $message_bool = false; } } /** * 获取备份文件列表 * @since 1 */ $table_list = corefile::list_dir($backup_dir, '*.zip'); /** * 获取上一次自动备份时间 * @since 1 */ ?> <!-- 管理表格 --> <h2>备份文件</h2> <p><a href="<?php echo $page_url; ?> &backup=1" class="btn btn-large btn-warning"><i class="icon-hdd icon-white"></i> 开始备份</a></p> <p><?php if ($config_backup_date) { echo '上一次自动备份时间:' . $config_backup_date; }
/** * 还原备份 * @since 2 * @param coredb $db * @param string $backup_file 备份的文件路径 * @return boolean */ function plugbackup_return(&$db, $backup_file, $return_dir, $content_dir) { $return = false; //清空return目录所有文件夹 $dir_list = corefile::list_dir($return_dir, '*', GLOB_ONLYDIR); if ($dir_list) { foreach ($dir_list as $v) { $v_src = basename($v); $return = corefile::delete_dir($v); if ($return == false) { return $return; } } } else { $return = true; } //解压备份文件到return目录 if ($return == true) { $return = corefile::extract_zip($backup_file, $return_dir); } //获取临时文件夹路径 $ls_dir = ''; if ($return == true) { $dir_list = corefile::list_dir($return_dir, '*', GLOB_ONLYDIR); if ($dir_list) { $ls_dir = $dir_list[0]; } } //检查数据是否正确 if ($return == true) { $v_dirs = array($ls_dir . DS . 'content', $ls_dir . DS . 'sql', $ls_dir . DS . 'content' . DS . 'files', $ls_dir . DS . 'content' . DS . 'logs'); foreach ($v_dirs as $v) { if (corefile::is_dir($v) == false) { $return = false; break; } } foreach ($db->tables as $v) { if (corefile::is_dir($v_dirs[1] . DS . $v) == false) { $return = false; break; } } } //删除现有数据 if ($return == true) { if (corefile::delete_dir($content_dir . DS . 'files') == true && corefile::delete_dir($content_dir . DS . 'logs') == true) { $return = true; } else { $return = false; } } //拷贝备份数据 if ($return == true) { if (corefile::copy_dir($ls_dir . DS . 'content' . DS . 'files', $content_dir . DS . 'files') == true && corefile::copy_dir($ls_dir . DS . 'content' . DS . 'logs', $content_dir . DS . 'logs') == true) { $return = true; } else { $return = false; } } //清空所有表 if ($return == true) { $sql = 'TRUNCATE '; foreach ($db->tables as $v) { if ($db->exec($sql . $v) === false) { $return = false; break; } } } //根据文件次序执行sql if ($return == true) { foreach ($db->tables as $v) { $v_table_dir = $ls_dir . DS . 'sql' . DS . $v; $dir_list = corefile::list_dir($v_table_dir, '*.sql'); if ($dir_list) { foreach ($dir_list as $v_i) { $i_content = corefile::read_file($v_i); if ($db->exec($i_content) === false) { $return = false; break; } $i_content = null; } } } } //删除临时文件夹 if ($return == true) { $return = corefile::delete_dir($ls_dir); } return $return; }