diff --git a/Application/Home/Controller/ItemController.class.php b/Application/Home/Controller/ItemController.class.php
index e25abb8ab..7cf80a695 100644
--- a/Application/Home/Controller/ItemController.class.php
+++ b/Application/Home/Controller/ItemController.class.php
@@ -2,10 +2,10 @@
namespace Home\Controller;
use Think\Controller;
class ItemController extends BaseController {
- //项目列表页
+ //项目列表页
public function index(){
- $login_user = $this->checkLogin();
- $items = D("Item")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->select();
+ $login_user = $this->checkLogin();
+ $items = D("Item")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->select();
$share_url = get_domain().__APP__.'/uid/'.$login_user['uid'];
@@ -40,16 +40,20 @@ public function showByUid(){
//新建项目
public function add(){
- $login_user = $this->checkLogin();
+ $login_user = $this->checkLogin();
$item_id = I("item_id/d");
- if (!IS_POST) {
+ if (!IS_POST) {
$item = D("Item")->where("item_id = '$item_id' ")->find();
$this->assign("item" , $item);
- $this->display ();
+ $this->display ();
- }else{
+ }else{
$item_name = I("item_name");
- $item_domain = I("item_domain");
+ $item_domain = I("item_domain") ? I("item_domain") : '';
+ $copy_item_id = I("copy_item_id");
+ $password = I("password");
+ $item_description = I("item_description");
+ $item_type = I("item_type");
if ($item_domain) {
$item = D("Item")->where("item_domain = '$item_domain' and item_id !='$item_id' ")->find();
@@ -64,11 +68,22 @@ public function add(){
return false;
}
}
-
-
- $password = I("password");
- $item_description = I("item_description");
- if ($item_id > 0 ) {
+
+ //如果是复制项目
+ if ($copy_item_id > 0) {
+ if (!$this->checkItemPermn($login_user['uid'] , $copy_item_id)) {
+ $this->message(L('no_permissions'));
+ return;
+ }
+ $ret = D("Item")->copy($copy_item_id,$login_user['uid'],$item_name,$item_description,$password,$item_domain);
+ if ($ret) {
+ $this->message(L('operation_succeeded'),U('Home/Item/index'));
+ }else{
+ $this->message(L('operation_failed'),U('Home/Item/index'));
+ }
+ return ;
+ }
+ if ($item_id > 0 ) {
$data = array(
"item_name" => $item_name ,
"item_domain" => $item_domain ,
@@ -84,20 +99,34 @@ public function add(){
"password" => $password ,
"item_description" => $item_description ,
"item_domain" => $item_domain ,
+ "item_type" => $item_type ,
"addtime" =>time()
);
- $ret = D("Item")->add($insert);
+ $item_id = D("Item")->add($insert);
}
- if ($ret) {
- $this->message(L('operation_succeeded'),U('Home/Item/index'));
- }else{
- $this->message(L('operation_failed'),U('Home/Item/index'));
- }
- }
+ if ($item_id) {
+ //如果是单页应用,则新建一个默认页
+ if ($item_type == 2 ) {
+ $insert = array(
+ 'author_uid' => $login_user['uid'] ,
+ 'author_username' => $login_user['username'],
+ "page_title" => $item_name ,
+ "item_id" => $item_id ,
+ "cat_id" => 0 ,
+ "page_content" => '欢迎使用showdoc。点击右上方的编辑按钮进行编辑吧!' ,
+ "addtime" =>time()
+ );
+ D("Page")->add($insert);
+ }
+ $this->message(L('operation_succeeded'),U('Home/Item/index'));
+ }else{
+ $this->message(L('operation_failed'),U('Home/Item/index'));
+ }
+ }
}
- //展示单个项目
+ //根据项目类型展示项目
public function show(){
$this->checkLogin(false);
$item_id = I("item_id/d");
@@ -110,7 +139,6 @@ public function show(){
$item_id = $item['item_id'] ;
}
}
- $keyword = I("keyword");
$login_user = session("login_user");
$uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
@@ -118,20 +146,41 @@ public function show(){
$item = D("Item")->where("item_id = '$item_id' ")->find();
+ if ($item['item_type'] == 1 ) {
+ $this->_show_regular_item($item);
+ }
+ elseif ($item['item_type'] == 2 ) {
+ $this->_show_single_page_item($item);
+ }else{
+ $this->_show_regular_item($item);
+ }
+
+ }
+
+ //展示常规项目
+ private function _show_regular_item($item){
+ $item_id = $item['item_id'];
+
+ $current_page_id = I("page_id/d");
+ $keyword = I("keyword");
+
+ $login_user = session("login_user");
+ $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
+
//是否有搜索词
if ($keyword) {
- $pages = D("Page")->where("item_id = '$item_id' and ( page_title like '%{$keyword}%' or page_content like '%{$keyword}%' ) ")->order(" `s_number` asc ")->select();
+ $pages = D("Page")->where("item_id = '$item_id' and ( page_title like '%{$keyword}%' or page_content like '%{$keyword}%' ) ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
}else{
//获取所有父目录id为0的页面
- $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' ")->order(" `s_number` asc ")->select();
+ $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
//获取所有二级目录
$catalogs = D("Catalog")->where("item_id = '$item_id' and level = 2 ")->order(" `s_number` asc ")->select();
if ($catalogs) {
foreach ($catalogs as $key => &$catalog) {
//该二级目录下的所有子页面
- $temp = D("Page")->where("cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc ")->select();
+ $temp = D("Page")->where("cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
$catalog['pages'] = $temp ? $temp: array();
//该二级目录下的所有子目录
@@ -141,7 +190,7 @@ public function show(){
//获取所有三级目录的子页面
foreach ($catalog['catalogs'] as $key3 => &$catalog3) {
//该二级目录下的所有子页面
- $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' ")->order(" `s_number` asc ")->select();
+ $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
$catalog3['pages'] = $temp ? $temp: array();
}
}
@@ -162,7 +211,7 @@ public function show(){
else{
$help_url = "http://www.showdoc.cc/help";
}
-
+
$this->assign("help_url" , $help_url);
$this->assign("current_page_id" , $current_page_id);
$this->assign("keyword" , $keyword);
@@ -173,9 +222,38 @@ public function show(){
$this->assign("pages" , $pages);
$this->assign("item" , $item);
$this->assign("login_user" , $login_user);
- $this->display();
+ $this->display("show_regular");
}
+ //展示单页项目
+ private function _show_single_page_item($item){
+ $item_id = $item['item_id'];
+
+ $current_page_id = I("page_id/d");
+
+ $login_user = session("login_user");
+ $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
+
+ //获取页面
+ $page = D("Page")->where(" item_id = '$item_id' ")->find();
+
+ $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
+ $share_url = get_domain().__APP__.'/'.$domain;
+
+ $ItemPermn = $this->checkItemPermn($uid , $item_id) ;
+
+ $ItemCreator = $this->checkItemCreator($uid , $item_id);
+
+ $this->assign("current_page_id" , $current_page_id);
+ $this->assign("ItemPermn" , $ItemPermn);
+ $this->assign("ItemCreator" , $ItemCreator);
+ $this->assign("share_url" , $share_url);
+ $this->assign("catalogs" , $catalogs);
+ $this->assign("page" , $page);
+ $this->assign("item" , $item);
+ $this->assign("login_user" , $login_user);
+ $this->display("show_single_page");
+ }
//删除项目
public function delete(){
$item_id = I("item_id");
@@ -346,4 +424,12 @@ public function word(){
output_word($data,$item['item_name']);
}
+ public function itemList(){
+ $login_user = $this->checkLogin();
+ $items = D("Item")->where("uid = '$login_user[uid]' ")->select();
+ $items = $items ? $items : array();
+ $this->sendResult($items);
+ }
+
+
}
\ No newline at end of file
diff --git a/Application/Home/Controller/PageController.class.php b/Application/Home/Controller/PageController.class.php
index 47833f79d..f79299953 100644
--- a/Application/Home/Controller/PageController.class.php
+++ b/Application/Home/Controller/PageController.class.php
@@ -16,7 +16,7 @@ public function index(){
$ItemPermn = $this->checkItemPermn($login_user['uid'] , $page['item_id']) ;
$ItemCreator = $this->checkItemCreator($login_user['uid'],$page['item_id']);
-
+ $page['page_md_content'] = $page['page_content'];
//$Parsedown = new \Parsedown();
//$page['page_content'] = $Parsedown->text(htmlspecialchars_decode($page['page_content']));
@@ -41,6 +41,7 @@ public function single(){
$page['page_md_content'] = $page['page_content'];
//$page['page_html_content'] = $Parsedown->text(htmlspecialchars_decode($page['page_content']));
$this->assign("page" , $page);
+ $this->assign("login_user" , $login_user);
$this->display();
}
@@ -285,6 +286,4 @@ public function diff(){
$this->assign("history_page_content" , $history_page_content);
$this->display();
}
-
-
}
diff --git a/Application/Home/Controller/UpdateController.class.php b/Application/Home/Controller/UpdateController.class.php
index 0b39beb27..c9096dcaa 100644
--- a/Application/Home/Controller/UpdateController.class.php
+++ b/Application/Home/Controller/UpdateController.class.php
@@ -112,7 +112,7 @@ public function sqlite(){
}
}
- //item_member表增加level字段
+ //item_member表增加member_group_id字段
$columns = M("ItemMember")->getDbFields();
if ($columns) {
$has_it = 0 ;//是否存在该字段
@@ -127,6 +127,21 @@ public function sqlite(){
}
}
+ //item表增加item_type字段
+ $columns = M("Item")->getDbFields();
+ if ($columns) {
+ $has_it = 0 ;//是否存在该字段
+ foreach ($columns as $key => $value) {
+ if ($value == 'item_type') {
+ $has_it = 1 ;
+ }
+ }
+ if ($has_it === 0) {
+ $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_type INT( 1 ) NOT NULL DEFAULT '1' ;";
+ D("Item")->execute($sql);
+ }
+ }
+
echo 'OK!';
}
diff --git a/Application/Home/Model/ItemModel.class.php b/Application/Home/Model/ItemModel.class.php
new file mode 100644
index 000000000..2cc082853
--- /dev/null
+++ b/Application/Home/Model/ItemModel.class.php
@@ -0,0 +1,182 @@
+where("item_id = '$item_id' ")->field(" item_type, item_name ,item_description,password ")->find();
+ //获取所有父目录id为0的页面
+ $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' ")->field(" page_title ,page_content,s_number,page_comments ")->order(" `s_number` asc ")->select();
+ //获取所有二级目录
+ $catalogs = D("Catalog")->where("item_id = '$item_id' and level = 2 ")->field("cat_id, cat_name ,level,s_number ")->order(" `s_number` asc ")->select();
+ if ($catalogs) {
+ foreach ($catalogs as $key => &$catalog) {
+ //该二级目录下的所有子页面
+ $temp = D("Page")->where("cat_id = '$catalog[cat_id]' ")->field(" page_title ,page_content,s_number,page_comments ")->order(" `s_number` asc ")->select();
+ $catalog['pages'] = $temp ? $temp: array();
+ //该二级目录下的所有子目录
+ $temp = D("catalog")->where("parent_cat_id = '$catalog[cat_id]' ")->field(" cat_id,cat_name ,level,s_number ")->order(" `s_number` asc ")->select();
+ $catalog['catalogs'] = $temp ? $temp: array();
+ if($catalog['catalogs']){
+ //获取所有三级目录的子页面
+ foreach ($catalog['catalogs'] as $key3 => &$catalog3) {
+ //该二级目录下的所有子页面
+ $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' ")->field(" page_title ,page_content,s_number,page_comments ")->order(" `s_number` asc ")->select();
+ $catalog3['pages'] = $temp ? $temp: array();
+ unset($catalog3['cat_id']);
+ }
+ }
+ unset($catalog['cat_id']);
+ }
+ }
+ $item['pages'] = array(
+ "pages" =>$pages,
+ "catalogs" =>$catalogs,
+ );
+ unset($pages);
+ unset($catalogs);
+ $item['members'] = D("ItemMember")->where("item_id = '$item_id' ")->field(" member_group_id ,uid,username ")->select();
+ return json_encode($item);
+
+ }
+ public function import($json,$uid,$item_name= '',$item_description= '',$item_password = '',$item_domain = ''){
+ $userInfo = D("User")->userInfo($uid);
+ $item = json_decode($json ,1 );
+ unset($json);
+ if ($item) {
+ if ($item['item_domain']) {
+ $item2 = D("Item")->where("item_domain = '$item[item_domain]' ")->find();
+ if ($item2) {
+ //个性域名已经存在
+ return false;
+ }
+ if(!ctype_alnum($item_domain) || is_numeric($item_domain) ){
+ //echo '个性域名只能是字母或数字的组合';exit;
+ return false;
+ }
+ }else{
+ $item['item_domain'] = '';
+ }
+ $item_data = array(
+ "item_name"=>$item_name ? $item_name :$item['item_name'],
+ "item_domain"=>$item_domain ? $item_domain :$item['item_domain'],
+ "item_type"=>$item['item_type'],
+ "item_description"=>$item_description ? $item_description :$item['item_description'],
+ "password"=>$item_password ? $item_password :$item['password'],
+ "uid"=>$userInfo['uid'],
+ "username"=>$userInfo['username'],
+ "addtime"=>time(),
+ );
+ $item_id = D("Item")->add($item_data);
+ }
+ if ($item['pages']) {
+ //父页面们(一级目录)
+ if ($item['pages']['pages']) {
+ foreach ($item['pages']['pages'] as $key => &$value) {
+ $page_data = array(
+ "author_uid"=>$userInfo['uid'],
+ "author_username"=>$userInfo['username'],
+ "page_title" =>$value['page_title'],
+ "page_content" =>$value['page_content'],
+ "s_number" =>$value['s_number'],
+ "page_comments" =>$value['page_comments'],
+ "item_id" => $item_id,
+ "cat_id" => 0 ,
+ "addtime" =>time(),
+ );
+ D("Page")->add($page_data);
+ unset($page_data);
+ }
+ unset($item['pages']['pages']);
+ }
+ //二级目录
+ if ($item['pages']['catalogs']) {
+ foreach ($item['pages']['catalogs'] as $key => &$value) {
+ $catalog_data = array(
+ "cat_name" => $value['cat_name'],
+ "level" => $value['level'],
+ "s_number" => $value['s_number'],
+ "item_id" => $item_id,
+ "addtime" =>time(),
+ );
+ $cat_id = D("Catalog")->add($catalog_data);
+ //二级目录的页面们
+ if ($value['pages']) {
+ foreach ($value['pages'] as $key2 => &$value2) {
+ $page_data = array(
+ "author_uid"=>$userInfo['uid'],
+ "author_username"=>$userInfo['username'],
+ "page_title" =>$value2['page_title'],
+ "page_content" =>$value2['page_content'],
+ "s_number" =>$value2['s_number'],
+ "page_comments" =>$value2['page_comments'],
+ "item_id" => $item_id,
+ "cat_id" => $cat_id ,
+ "addtime" =>time(),
+ );
+ D("Page")->add($page_data);
+ unset($page_data);
+ unset($value2);
+ }
+ }
+ //判断是否存在三级目录
+ if ($value['catalogs']) {
+ foreach ($value['catalogs'] as $key3 => &$value3) {
+ $catalog_data = array(
+ "cat_name" => $value3['cat_name'],
+ "level" => $value3['level'],
+ "s_number" => $value3['s_number'],
+ "parent_cat_id" => $cat_id,
+ "item_id" => $item_id,
+ "addtime" =>time(),
+ );
+ $cat_id2 = D("Catalog")->add($catalog_data);
+ //三级目录的页面们
+ if ($value3['pages']) {
+ foreach ($value3['pages'] as $key4 => &$value4) {
+ $page_data = array(
+ "author_uid"=>$userInfo['uid'],
+ "author_username"=>$userInfo['username'],
+ "page_title" =>$value4['page_title'],
+ "page_content" =>$value4['page_content'],
+ "s_number" =>$value4['s_number'],
+ "page_comments" =>$value4['page_comments'],
+ "item_id" => $item_id,
+ "cat_id" => $cat_id2 ,
+ "addtime" =>time(),
+ );
+ D("Page")->add($page_data);
+ unset($page_data);
+ unset($value4);
+ }
+ }
+ unset($value3);
+ }
+ }
+ unset($value);
+ }
+
+ }
+ }
+
+ if ($item['members']) {
+ foreach ($item['members'] as $key => $value) {
+ $member_data = array(
+ "member_group_id"=>$value['member_group_id'],
+ "uid"=>$value['uid'],
+ "username"=>$value['username'],
+ "item_id"=>$item_id,
+ "addtime"=>time(),
+ );
+ D("ItemMember")->add($member_data);
+ }
+ }
+ return $item_id;
+ }
+
+ public function copy($item_id,$uid,$item_name= '',$item_description= '',$item_password = '',$item_domain){
+ return $this->import($this->export($item_id),$uid,$item_name,$item_description,$item_password,$item_domain);
+ }
+
+}
\ No newline at end of file
diff --git a/Application/Home/View/Item/add.html b/Application/Home/View/Item/add.html
index 2bd492f8c..dbcd2c4c6 100644
--- a/Application/Home/View/Item/add.html
+++ b/Application/Home/View/Item/add.html
@@ -1,17 +1,49 @@