public function index() { //安全验证 $this->checksafeauth(); if (isset($_GET['title'])) { $this->assign("title", $_GET['title']); } if (!empty($_GET['status'])) { $map['status'] = $_GET['status']; } $map['id'] = array('gt', 0); import('@.ORG.Page'); $install = $this->_get('install', false); if ($install != 1) { $model = M('plugin'); $count = $model->where($map)->count(); $fenye = 20; $p = new Page($count, $fenye); $list = $model->where($map)->order('pubdate desc')->limit($p->firstRow . ',' . $p->listRows)->select(); //echo $model->getLastSql();exit; $p->setConfig('prev', '上一页'); $p->setConfig('header', '条记录'); $p->setConfig('first', '首 页'); $p->setConfig('last', '末 页'); $p->setConfig('next', '下一页'); $p->setConfig('theme', "%first%%upPage%%linkPage%%downPage%%end%<li><span>共<font color='#009900'><b>%totalRow%</b></font>条记录 " . $fenye . "条/每页</span></li>"); $this->assign('page', $p->show()); $this->assign("list", $list); $this->display(); } else { $model = M('plugin'); $pluginlist = $model->field('title')->select(); $plist = array(); foreach ($pluginlist as $v) { $plist[] = $v['title']; } //未安装插件 $path = './Public/Plugin'; $dir = File::get_dirs($path); foreach ($dir['dir'] as $k => $v) { if (!in_array($v, $plist) && $v != '.' && $v != '..') { $list['title'] = $v; if (file_exists($path . '/' . $v . '/plugin.xml')) { $tag = simplexml_load_file($path . '/' . $v . '/plugin.xml'); $list['author'] = (string) $tag->author; $list['description'] = (string) $tag->description; $list['copyright'] = (string) $tag->copyright; } $list2[] = $list; } } $this->assign("list", $list2); $this->display('index2'); } }
public function setdefault() { $name = $this->_get('name'); $demo = $this->_get('demo'); $backup = $this->_get('backup'); $plugin = $this->_get('plugin'); if (empty($name)) { $this->error('参数不正确!'); } $model = M('config'); $map['varname'] = 'cfg_wap_tpl_default'; $list = $model->field('id')->where($map)->find(); $map['id'] = $list['id']; $map['value'] = $name; $model->save($map); if ($demo == 1) { //检测演示数据安装 $demosqlpath = './Public/Wap/' . $name . '/demo.sql'; if (file_exists($demosqlpath)) { $rs = new Model(); $sql = File::read_file($demosqlpath); $sql = str_replace("\r\n", "\n", $sql); foreach (explode(";\n", trim($sql)) as $query) { $rs->query(trim($query)); } } } if ($backup == 1) { //数据备份 global $cfg_wap_tpl_default; $rs = new Model(); $list = $rs->query("SHOW TABLES FROM " . "`" . C('DB_NAME') . "`"); $filesize = 2048; $file = './Public/Backup/'; $random = mt_rand(1000, 9999); $sql = ''; $p = 1; foreach ($list as $k => $v) { $table = current($v); //仅备份当前系统的数据库表 $prefix = C('DB_PREFIX'); if (substr($table, 0, strlen($prefix)) == $prefix) { $rs = D(str_replace(C('DB_PREFIX'), '', $table)); $array = $rs->select(); $sql .= "TRUNCATE TABLE `{$table}`;\n"; foreach ($array as $value) { $sql .= $this->insertsql($table, $value); if (strlen($sql) >= $filesize * 1000) { $filename = $file . 'theme_' . $cfg_df_style . '_' . date('Ymd') . '_' . $random . '_' . $p . '.sql'; File::write_file($filename, $sql); $p++; $sql = ''; } } } } if (!empty($sql)) { $filename = $file . 'waptheme_' . $cfg_wap_tpl_default . '_' . date('Ymd') . '_' . $random . '_' . $p . '.sql'; File::write_file($filename, $sql); } } if ($plugin == 1) { //依赖插件安装 $prepluginpath = './Public/Wap/' . $name . '/plugin'; $list = File::get_dirs($prepluginpath); if (!empty($list['file'])) { import('ORG.PclZip'); foreach ($list['file'] as $v) { $filename = substr($v, 0, -4); $model = M('plugin'); if (!$model->where("title='" . $filename . "'")->find()) { //插件解压缩 $zip = new PclZip($prepluginpath . '/' . $v); $zip->extract(PCLZIP_OPT_PATH, './Public/Plugin/' . $filename); //安装插件 $data['description'] = ''; $data['author'] = ''; $data['copyright'] = ''; $xmlpath = './Public/Plugin/' . $filename . '/plugin.xml'; if (file_exists($xmlpath)) { $tag = simplexml_load_file($xmlpath); $data['author'] = (string) $tag->author; $data['copyright'] = (string) $tag->copyright; $data['description'] = (string) $tag->description; } $data['status'] = 0; $data['title'] = $filename; $data['pubdate'] = time(); $model->add($data); $path = './Public/Plugin/' . $filename . '/admin.php'; if (file_exists($path)) { set_include_path(__ROOT__); include $path; call_user_func(array($title . 'Plugin', '__install')); } } } } } $this->success('操作成功!', U('Wap/index')); }