You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
10 KiB

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