25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

189 satır
7.0 KiB

3 yıl önce
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class PageController extends BaseController {
  5. //展示某个项目的单个页面
  6. public function index(){
  7. import("Vendor.Parsedown.Parsedown");
  8. $page_id = I("page_id/d");
  9. $this->assign("page_id" , $page_id);
  10. $this->display();
  11. }
  12. //展示单个页面
  13. public function single(){
  14. $page_id = I("page_id/d");
  15. //跳转到web目录
  16. header("location:./web/#/page/".$page_id);
  17. exit();
  18. import("Vendor.Parsedown.Parsedown");
  19. $page = D("Page")->where(" page_id = '$page_id' ")->find();
  20. $login_user = $this->checkLogin(false);
  21. if (!$this->checkItemVisit($login_user['uid'] , $page['item_id'],$_SERVER['REQUEST_URI'])) {
  22. $this->message(L('no_permissions'));
  23. return;
  24. }
  25. $ItemPermn = $this->checkItemPermn($login_user['uid'] , $page['item_id']) ;
  26. $ItemCreator = $this->checkItemCreator($login_user['uid'],$page['item_id']);
  27. $page['page_md_content'] = $page['page_content'];
  28. //$page['page_html_content'] = $Parsedown->text(htmlspecialchars_decode($page['page_content']));
  29. $this->assign("page" , $page);
  30. $this->assign("page_id" , $page_id);
  31. $this->assign("login_user" , $login_user);
  32. $this->display();
  33. }
  34. //返回单个页面的源markdown代码
  35. public function md(){
  36. $page_id = I("page_id/d");
  37. $page = D("Page")->where(" page_id = '$page_id' ")->find();
  38. echo $page['page_content'];
  39. }
  40. //编辑页面
  41. public function edit(){
  42. $login_user = $this->checkLogin();
  43. $page_id = I("page_id/d");
  44. $item_id = I("item_id/d");
  45. $page_history_id = I("page_history_id/d");
  46. $copy_page_id = I("copy_page_id/d");
  47. if ($page_id > 0 ) {
  48. if ($page_history_id) {
  49. $page = D("PageHistory")->where(" page_history_id = '$page_history_id' ")->find();
  50. $page_content = gzuncompress(base64_decode($page['page_content']));
  51. $page['page_content'] = $page_content ? $page_content : $page['page_content'] ;
  52. }else{
  53. $page = D("Page")->where(" page_id = '$page_id' ")->find();
  54. }
  55. $default_cat_id = $page['cat_id'];
  56. }
  57. //如果是复制接口
  58. elseif ($copy_page_id) {
  59. $copy_page = D("Page")->where(" page_id = '$copy_page_id' ")->find();
  60. $page['page_title'] = $copy_page['page_title']."-copy";
  61. $page['page_content'] = $copy_page['page_content'];
  62. $page['item_id'] = $copy_page['item_id'];
  63. $default_cat_id = $copy_page['cat_id'];
  64. }else{
  65. //查找用户上一次设置的目录
  66. $last_page = D("Page")->where(" author_uid ='$login_user[uid]' and $item_id = '$item_id' ")->order(" addtime desc ")->limit(1)->find();
  67. $default_cat_id = $last_page['cat_id'];
  68. }
  69. $item_id = $page['item_id'] ?$page['item_id'] :$item_id;
  70. if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
  71. $this->message(L('no_permissions'));
  72. return;
  73. }
  74. $Catalog = D("Catalog")->where(" cat_id = '$default_cat_id' ")->find();
  75. if ($Catalog['parent_cat_id']) {
  76. $default_second_cat_id = $Catalog['parent_cat_id'];
  77. $default_child_cat_id = $default_cat_id;
  78. }else{
  79. $default_second_cat_id = $default_cat_id;
  80. }
  81. $this->assign("api_doc_templ" , 'MdTemplate/api-doc.'.LANG_SET);
  82. $this->assign("database_doc_templ" , 'MdTemplate/database.'.LANG_SET);
  83. $this->assign("page" , $page);
  84. $this->assign("item_id" , $item_id);
  85. $this->assign("default_second_cat_id" , $default_second_cat_id);
  86. $this->assign("default_child_cat_id" , $default_child_cat_id);
  87. $this->display();
  88. }
  89. //历史版本
  90. public function history(){
  91. $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
  92. $this->assign("page_id" , $page_id);
  93. $PageHistory = D("PageHistory")->where("page_id = '$page_id' ")->order(" addtime desc")->limit(10)->select();
  94. if ($PageHistory) {
  95. foreach ($PageHistory as $key => &$value) {
  96. $page_content = gzuncompress(base64_decode($value['page_content']));
  97. $value['page_content'] = $page_content ? $page_content : $value['page_content'] ;
  98. $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
  99. }
  100. }
  101. $this->assign("PageHistory" , $PageHistory);
  102. $this->display();
  103. }
  104. //上传图片
  105. public function uploadImg(){
  106. return false ;
  107. $qiniu_config = C('UPLOAD_SITEIMG_QINIU') ;
  108. if ($_FILES['editormd-image-file']['name'] == 'blob') {
  109. $_FILES['editormd-image-file']['name'] .= '.jpg';
  110. }
  111. if (strstr(strtolower($_FILES['editormd-image-file']['name']), ".php") ) {
  112. return false;
  113. }
  114. if (!empty($qiniu_config['driverConfig']['secrectKey'])) {
  115. //上传到七牛
  116. $Upload = new \Think\Upload(C('UPLOAD_SITEIMG_QINIU'));
  117. $info = $Upload->upload($_FILES);
  118. $url = $info['editormd-image-file']['url'] ;
  119. echo json_encode(array("url"=>$url,"success"=>1));
  120. }else{
  121. $upload = new \Think\Upload();// 实例化上传类
  122. $upload->maxSize = 3145728 ;// 设置附件上传大小
  123. $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
  124. $upload->rootPath = './Public/Uploads/';// 设置附件上传目录
  125. $upload->savePath = '';// 设置附件上传子目录
  126. $info = $upload->upload() ;
  127. if(!$info) {// 上传错误提示错误信息
  128. $this->error($upload->getError());
  129. return;
  130. }else{// 上传成功 获取上传文件信息
  131. $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['editormd-image-file']['savepath'].$info['editormd-image-file']['savename'] ;
  132. echo json_encode(array("url"=>$url,"success"=>1));
  133. }
  134. }
  135. }
  136. public function diff(){
  137. $login_user = $this->checkLogin();
  138. $page_history_id = I("page_history_id/d");
  139. $page_id = I("page_id/d");
  140. $page = D("Page")->where(" page_id = '$page_id' ")->find();
  141. $cur_page_content = $page['page_content'];
  142. $item_id = $page['item_id'] ?$page['item_id'] :$item_id;
  143. if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
  144. $this->message(L('no_permissions'));
  145. return;
  146. }
  147. $page = D("PageHistory")->where(" page_history_id = '$page_history_id' ")->find();
  148. $page_content = gzuncompress(base64_decode($page['page_content']));
  149. $history_page_content = $page_content ? $page_content : $page['page_content'] ;
  150. $this->assign("cur_page_content" , $cur_page_content);
  151. $this->assign("history_page_content" , $history_page_content);
  152. $this->display();
  153. }
  154. }