心理咨询网
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.

ContentController.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年4月20日
  7. * 内容接口控制器
  8. */
  9. namespace app\api\controller;
  10. use core\basic\Controller;
  11. use app\api\model\CmsModel;
  12. use core\basic\Url;
  13. use app\home\controller\ParserController;
  14. class ContentController extends Controller
  15. {
  16. protected $model;
  17. public function __construct()
  18. {
  19. $this->model = new CmsModel();
  20. }
  21. public function index()
  22. {
  23. if (! ! $id = request('id', 'int')) {
  24. // 区域获取
  25. $acode = request('acode', 'var') ?: get_default_lg();
  26. // 读取数据
  27. if (! ! $data = $this->model->getContent($acode, $id)) {
  28. if ($data->outlink) {
  29. $data->link = $data->outlink;
  30. } else {
  31. $data->apilink = url('/api/content/index/id/' . $data->id, false);
  32. }
  33. $data->likeslink = url('/home/Do/likes/id/' . $data->id, false);
  34. $data->opposelink = url('/home/Do/oppose/id/' . $data->id, false);
  35. // 返回网页链接地址
  36. $Parser = new ParserController();
  37. $data->contentlink = $Parser->parserLink(2, $data->urlname, 'content', $data->scode, $data->sortfilename, $data->id, $data->filename);
  38. $data->content = str_replace(STATIC_DIR . '/upload/', get_http_url() . STATIC_DIR . '/upload/', $data->content);
  39. json(1, $data);
  40. } else {
  41. json(0, 'id为' . $id . '的内容已经不存在了!');
  42. }
  43. } else {
  44. json(1, '请求错误,传递的内容id有误!');
  45. }
  46. }
  47. }