PageController.class.php 6.9 KB

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