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 @@ - +
@@ -28,5 +60,63 @@ $("#password").val(password); }; +$("#choose_item").hide(); + +//如果是编辑项目,则禁用复制项目功能 +if ($("#item_id").val()) { + $("#show_copy").parent().hide(); + $(".choose_type").html(""); +}; + +$("#show_copy").change(function(){ + if ($("#show_copy").is(':checked')) { + $("#choose_item").show(); + $("#item_type1").attr("disabled","disabled"); + $("#item_type2").attr("disabled","disabled"); + $("#item_type1").removeAttr("checked"); + $("#item_type2").removeAttr("checked"); + }else{ + $("#choose_item").hide(); + $("#item_type1").removeAttr("disabled"); + $("#item_type2").removeAttr("disabled"); + $("#item_name").val(""); + $("#item_description").val(''); + $("#password").val(''); + } + get_item_list(); +}); + + +function get_item_list(){ + //获取已有项目列表 + $.get( + "?s=/home/item/itemList", + {}, + function(data){ + if (data.error_code === 0) { + var json = data.data ; + var html = ''; + for (var i = 0; i < json.length; i++) { + html += ''; + }; + $("#choose_item").html(html); + + }; + }, + "json" + ); +} + + +//当用户选择了某个复制项目,则填充信息 +$("#choose_item").change(function(){ + var a = $(this).find("option:selected"); + var item_name = a.text(); + var item_description = a.attr("item_description"); + var password = a.attr("password"); + $("#item_name").val(item_name+"--copy"); + $("#item_description").val(item_description); + $("#password").val(password); +}); diff --git a/Application/Home/View/Item/show_regular.html b/Application/Home/View/Item/show_regular.html new file mode 100644 index 000000000..ca1a83451 --- /dev/null +++ b/Application/Home/View/Item/show_regular.html @@ -0,0 +1,176 @@ + + + + + +
+ +
+ +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + diff --git a/Application/Home/View/Item/show_single_page.html b/Application/Home/View/Item/show_single_page.html new file mode 100644 index 000000000..95dcf9149 --- /dev/null +++ b/Application/Home/View/Item/show_single_page.html @@ -0,0 +1,90 @@ + + + + + + +
+ +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + diff --git a/Public/css/item/show_single_page.css b/Public/css/item/show_single_page.css new file mode 100644 index 000000000..806634c00 --- /dev/null +++ b/Public/css/item/show_single_page.css @@ -0,0 +1,69 @@ +body{ + background: #F1F0F1; + height: auto; + overflow: auto; + margin: 0 auto; +} + +#page_content{ + + padding: 11px 0 90px 0; + overflow: hidden; + font-size: 11pt; + line-height: 1.7; + color: #333; +} +#doc-body{ + background-color: #fff; +} + +.doc-container { + position: static; + -webkit-box-shadow: 0px 1px 6px #ccc; + -moz-box-shadow: 0px 1px 6px #ccc; + -ms-box-shadow: 0px 1px 6px #ccc; + -o-box-shadow: 0px 1px 6px #ccc; + box-shadow: 0px 1px 6px #ccc; + background-color: #fff; + border-bottom: 1px solid #d9d9d9; + margin-bottom: 20px; + width: 800px; + min-height: 500px; + +} + +#header{ + height: 80px; +} + +#doc-body{ + width: 600px; + margin: 0 auto; +} + +.doc-title-box{ + height: auto; + margin: 30px 100px 10px 100px; + width: auto; + border-bottom: 1px solid #ebebeb; + padding-bottom: 10px; +} +#footer{ + margin: 0 auto; + width: 180px; + font-size: 8px; + color: #959595; +} + +#doc-title{ + display: inline-block; +} + +.tool-bar{ + font-size: 14px; + padding-top: 15px; +} + +.tool-bar .btn-link{ + padding: 0px; +} \ No newline at end of file diff --git a/Public/js/item/show_single_page.js b/Public/js/item/show_single_page.js new file mode 100644 index 000000000..2ddc00537 --- /dev/null +++ b/Public/js/item/show_single_page.js @@ -0,0 +1,97 @@ + +$(function(){ + hljs.initHighlightingOnLoad(); + + var EditormdView = editormd.markdownToHTML("page_md_content", { + htmlDecode : "style,script,iframe", // you can filter tags decode + emoji : true, + taskList : true, + tex : true, // 默认不解析 + flowChart : true, // 默认不解析 + sequenceDiagram : true, // 默认不解析 + }); + + //为所有table标签添加bootstap支持的表格类 + $("table").addClass("table table-bordered table-hover"); + //当表格列数过长时将自动出现滚动条 + $.each($('table'), function() { + $(this).prop('outerHTML', '
'+$(this).prop('outerHTML')+'
'); + }); + + //超链接都在新窗口打开 + $('a[href^="http"]').each(function() { + $(this).attr('target', '_blank'); + }); + if (!isMobile()) { + $("th").css("min-width","77px"); + }; + + //lightbox + //增加返回顶部按钮 + $.goup({ + trigger: 100, + bottomOffset: 150, + locationOffset: 100, + title: lang["back_to_top"] , + titleAsText: true, + containerColor:"#08c", + }); + + if( isMobile() || $(window).width() < 1000){ + AdaptToMobile(); + } + + $(window).resize(function(){ + if( isMobile()){ + AdaptToMobile(); + } + + else if($(window).width() < 1000){ + AdaptToMobile(); + }else{ + window.location.reload(); + } + }); + + history.replaceState(null, null, $("#share-item-link").html()); + + //分享项目 + $("#share").click(function(){ + $("#share-modal").modal(); + //延迟绑定分享事件 + setTimeout(function(){ + $('#copy-item-link').zclip( + { + path: DocConfig.pubile +'/jquery.zclip/ZeroClipboard.swf', + copy:function() + { + return $('#share-item-link').html(); + }, + afterCopy: function() { + show_top_msg("已经成功复制到剪切板",2000); + } + }); + + },500); + return false; + }); + + $("table thead tr").css({"background-color":"#08c","color":"#fff"}); + $("table tr").each(function(){ + if($(this).find("td").eq(1).html()=="object") + { + $(this).css({"background-color":"#99CC99","color":"#000"}); + } + + }); + +}); + +function AdaptToMobile(){ + $(".doc-container").css("width","90%"); + $("#doc-body").css("width","90%"); + $("#header").css("height","20px"); + $(".doc-title-box").css("margin","20px 20px 0px 20px"); + $("#footer").css("font-size","11pt"); + $(".tool-bar").hide(); +} \ No newline at end of file diff --git a/Sqlite/showdoc.db.php b/Sqlite/showdoc.db.php index 6027dde15..e169056c8 100644 Binary files a/Sqlite/showdoc.db.php and b/Sqlite/showdoc.db.php differ diff --git a/composer.json b/composer.json index 25f290a7c..06fc81246 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "description": "ShowDoc is a tool greatly applicable for an IT team to share documents online", "keywords": ["showdoc","documents","Api"], "homepage": "https://github.com/star7th/showdoc", - "version":"v1.1.5", + "version":"v1.2.0", "license": "Apache-2.0", "authors": [ {