ItemController.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class ItemController extends BaseController {
  5. //项目列表页
  6. public function index(){
  7. $login_user = $this->checkLogin();
  8. $share_url = get_domain().__APP__.'/uid/'.$login_user['uid'];
  9. $this->assign("login_user" , $login_user);
  10. $this->assign("share_url" , $share_url);
  11. $this->display();
  12. }
  13. //我公开的项目列表
  14. public function showByUid(){
  15. $login_user = $this->checkLogin(false); //如果用户有登录,则赋值给$login_user
  16. $uid = I("uid/d");
  17. $show_user = D("User")->where(" uid = '$uid' ")->find();
  18. if ($show_user) {
  19. $items = D("Item")->where(" password = '' and ( uid = '$show_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$show_user[uid]' ) ) ")->select();
  20. $this->assign("items" , $items);
  21. $this->assign("show_user" , $show_user);
  22. $this->assign("login_user" , $login_user);
  23. }
  24. if (LANG_SET == 'en-us') {
  25. $help_url = "https://www.showdoc.cc/help-en";
  26. }
  27. else{
  28. $help_url = "https://www.showdoc.cc/help";
  29. }
  30. $this->assign("help_url" , $help_url);
  31. $this->display();
  32. }
  33. //新建项目
  34. public function add(){
  35. $login_user = $this->checkLogin();
  36. $this->display ();
  37. }
  38. //根据项目类型展示项目
  39. public function show(){
  40. $this->checkLogin(false);
  41. $item_id = I("item_id/d");
  42. $item_domain = I("item_domain/s");
  43. $current_page_id = I("page_id/d");
  44. //判断个性域名
  45. if ($item_domain) {
  46. $item = D("Item")->where("item_domain = '%s'",array($item_domain))->find();
  47. if ($item['item_id']) {
  48. $item_id = $item['item_id'] ;
  49. }
  50. }
  51. $login_user = session("login_user");
  52. $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
  53. $this->checkItemVisit($uid , $item_id);
  54. $item = D("Item")->where("item_id = '$item_id' ")->find();
  55. if ($item['item_type'] == 1 ) {
  56. $this->_show_regular_item($item);
  57. }
  58. elseif ($item['item_type'] == 2 ) {
  59. $this->_show_single_page_item($item);
  60. }else{
  61. $this->_show_regular_item($item);
  62. }
  63. }
  64. //展示常规项目
  65. private function _show_regular_item($item){
  66. $item_id = $item['item_id'];
  67. $current_page_id = I("page_id/d");
  68. $keyword = I("keyword");
  69. $login_user = session("login_user");
  70. $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
  71. //是否有搜索词
  72. if ($keyword) {
  73. $keyword = \SQLite3::escapeString($keyword) ;
  74. $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();
  75. }else{
  76. //获取所有父目录id为0的页面
  77. $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();
  78. //获取所有二级目录
  79. $catalogs = D("Catalog")->where("item_id = '$item_id' and level = 2 ")->order(" `s_number` asc ")->select();
  80. if ($catalogs) {
  81. foreach ($catalogs as $key => &$catalog) {
  82. //该二级目录下的所有子页面
  83. $temp = D("Page")->where("cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
  84. $catalog['pages'] = $temp ? $temp: array();
  85. //该二级目录下的所有子目录
  86. $temp = D("catalog")->where("parent_cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc ")->select();
  87. $catalog['catalogs'] = $temp ? $temp: array();
  88. if($catalog['catalogs']){
  89. //获取所有三级目录的子页面
  90. foreach ($catalog['catalogs'] as $key3 => &$catalog3) {
  91. //该二级目录下的所有子页面
  92. $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' ")->order(" `s_number` asc ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
  93. $catalog3['pages'] = $temp ? $temp: array();
  94. }
  95. }
  96. }
  97. }
  98. }
  99. $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
  100. $share_url = get_domain().__APP__.'/'.$domain;
  101. $ItemPermn = $this->checkItemPermn($uid , $item_id) ;
  102. $ItemCreator = $this->checkItemCreator($uid , $item_id);
  103. if (LANG_SET == 'en-us') {
  104. $help_url = "https://www.showdoc.cc/help-en";
  105. }
  106. else{
  107. $help_url = "https://www.showdoc.cc/help";
  108. }
  109. $this->assign("help_url" , $help_url);
  110. $this->assign("current_page_id" , $current_page_id);
  111. $this->assign("keyword" , $keyword);
  112. $this->assign("ItemPermn" , $ItemPermn);
  113. $this->assign("ItemCreator" , $ItemCreator);
  114. $this->assign("share_url" , $share_url);
  115. $this->assign("catalogs" , $catalogs);
  116. $this->assign("pages" , $pages);
  117. $this->assign("item" , $item);
  118. $this->assign("login_user" , $login_user);
  119. $this->display("show_regular");
  120. }
  121. //展示单页项目
  122. private function _show_single_page_item($item){
  123. $item_id = $item['item_id'];
  124. $current_page_id = I("page_id/d");
  125. $login_user = session("login_user");
  126. $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
  127. //获取页面
  128. $page = D("Page")->where(" item_id = '$item_id' ")->find();
  129. $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
  130. $share_url = get_domain().__APP__.'/'.$domain;
  131. $ItemPermn = $this->checkItemPermn($uid , $item_id) ;
  132. $ItemCreator = $this->checkItemCreator($uid , $item_id);
  133. $this->assign("current_page_id" , $current_page_id);
  134. $this->assign("ItemPermn" , $ItemPermn);
  135. $this->assign("ItemCreator" , $ItemCreator);
  136. $this->assign("share_url" , $share_url);
  137. $this->assign("catalogs" , $catalogs);
  138. $this->assign("page" , $page);
  139. $this->assign("item" , $item);
  140. $this->assign("login_user" , $login_user);
  141. $this->display("show_single_page");
  142. }
  143. //删除项目
  144. public function delete(){
  145. $item_id = I("item_id");
  146. $login_user = $this->checkLogin();
  147. if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
  148. $this->message(L('no_permissions'));
  149. return;
  150. }
  151. $this->assign("item_id" , $item_id);
  152. $this->display();
  153. }
  154. //删除项目
  155. public function ajaxDelete(){
  156. $login_user = $this->checkLogin();
  157. $item_id = I("item_id/d");
  158. $password = I("password");
  159. $item = D("Item")->where("item_id = '$item_id' ")->find();
  160. if(! D("User")-> checkLogin($item['username'],$password)){
  161. $return['error_code'] = 10102 ;
  162. $return['error_message'] = L('incorrect_password') ;
  163. $this->sendResult($return);
  164. return ;
  165. }
  166. D("Page")->where("item_id = '$item_id' ")->delete();
  167. D("Catalog")->where("item_id = '$item_id' ")->delete();
  168. D("PageHistory")->where("item_id = '$item_id' ")->delete();
  169. D("ItemMember")->where("item_id = '$item_id' ")->delete();
  170. $return = D("Item")->where("item_id = '$item_id' ")->delete();
  171. if (!$return) {
  172. $return['error_code'] = 10103 ;
  173. $return['error_message'] = 'request fail' ;
  174. }
  175. $this->sendResult($return);
  176. }
  177. //输入访问密码
  178. public function pwd(){
  179. $item_id = I("item_id/d");
  180. $CloseVerify = C('CloseVerify');
  181. $refer_url = I('refer_url');
  182. //var_dump(urldecode($refer_url));
  183. $this->assign('CloseVerify',$CloseVerify);
  184. $this->assign('refer_url',$refer_url);
  185. if (!IS_POST) {
  186. $this->assign("item_id" , $item_id);
  187. $this->display ();
  188. }else{
  189. $password = I("password");
  190. $v_code = I("v_code");
  191. if ( $CloseVerify || ( $v_code && $v_code == session('v_code') )) {
  192. $item = D("Item")->where("item_id = '$item_id' ")->find();
  193. if ($item['password'] == $password) {
  194. session("visit_item_".$item_id , 1 );
  195. if ($refer_url) {
  196. header("location:".base64_decode($refer_url));
  197. }else{
  198. header("location:".U("Home/Item/show").'&item_id='.$item_id);
  199. }
  200. }else{
  201. $this->message(L('access_password_are_incorrect'));
  202. }
  203. }else{
  204. $this->message(L('verification_code_are_incorrect'));
  205. }
  206. }
  207. }
  208. //导出word
  209. public function export(){
  210. $login_user = $this->checkLogin();
  211. $item_id = I("item_id/d");
  212. $uid = $login_user['uid'] ;
  213. $this->checkItemPermn($uid , $item_id) ;
  214. $item = D("Item")->where("item_id = '$item_id' ")->find();
  215. //对于单页项目,直接导出。对于普通项目,则让其选择目录
  216. if ($item['item_type'] == 2 ) {
  217. $url = 'server/index.php?s=/api/export/word&item_id='.$item_id ;
  218. header("location:{$url}");
  219. }else{
  220. $this->assign("item_id",$item_id);
  221. $this->display();
  222. }
  223. }
  224. public function setting(){
  225. $login_user = $this->checkLogin();
  226. $item_id = I("item_id/d");
  227. $uid = $login_user['uid'] ;
  228. $this->checkItemPermn($uid , $item_id) ;
  229. $this->assign("item_id",$item_id);
  230. $this->display();
  231. }
  232. }