Skip to content

Commit

Permalink
增加复制项目功能和支持创建单页项目功能
Browse files Browse the repository at this point in the history
  • Loading branch information
star7th committed Nov 5, 2016
1 parent 5b1d8d8 commit 681162d
Show file tree
Hide file tree
Showing 11 changed files with 842 additions and 38 deletions.
142 changes: 114 additions & 28 deletions Application/Home/Controller/ItemController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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();
Expand All @@ -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 ,
Expand All @@ -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");
Expand All @@ -110,28 +139,48 @@ public function show(){
$item_id = $item['item_id'] ;
}
}
$keyword = I("keyword");
$login_user = session("login_user");
$uid = $login_user['uid'] ? $login_user['uid'] : 0 ;

$this->checkItemVisit($uid , $item_id);


$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();

//该二级目录下的所有子目录
Expand All @@ -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();
}
}
Expand All @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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);
}


}
5 changes: 2 additions & 3 deletions Application/Home/Controller/PageController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
Expand All @@ -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();
}

Expand Down Expand Up @@ -285,6 +286,4 @@ public function diff(){
$this->assign("history_page_content" , $history_page_content);
$this->display();
}


}
17 changes: 16 additions & 1 deletion Application/Home/Controller/UpdateController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function sqlite(){
}
}

//item_member表增加level字段
//item_member表增加member_group_id字段
$columns = M("ItemMember")->getDbFields();
if ($columns) {
$has_it = 0 ;//是否存在该字段
Expand All @@ -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!';
}
Expand Down
Loading

0 comments on commit 681162d

Please sign in to comment.