PageController.class.php 7.5 KB

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