Core.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace Main\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. protected $checkUser = false;
  7. protected $data;
  8. public function __construct()
  9. {
  10. # 获取用户信息
  11. if ($this->checkUser) {
  12. $this->data['uid'] = Dever::load('passport/applet')->check();
  13. } else {
  14. $this->data['uid'] = Dever::load('passport/applet')->check(false);
  15. }
  16. if ($this->data['uid'] < 0) {
  17. $this->data['uid'] = 0;
  18. }
  19. //$this->data['uid'] = 1;
  20. # 获取基本配置
  21. $this->data['setting'] = Dever::db('main/config')->one();
  22. $this->data['system'] = Dever::input('system', 1);
  23. $source_type = Dever::input('source_type');
  24. $this->app = false;
  25. if ($source_type == 'ios' || $source_type == 'android') {
  26. $this->app = true;
  27. }
  28. }
  29. # 图片处理
  30. public function pic($data, $type = 't1')
  31. {
  32. //?imageView2/1/w/100/h/100/q/75
  33. $config = array
  34. (
  35. 'pic','pic_cover', 'content', 'share_pic'
  36. );
  37. foreach ($config as $k => $v) {
  38. if (isset($data[$v]) && $data[$v]) {
  39. $data[$v] = $this->replacePic($data[$v], $type);
  40. }
  41. }
  42. return $data;
  43. }
  44. public function replacePic($pic, $type = 't1')
  45. {
  46. //$pic = Dever::pic($pic, $type);
  47. if (strstr($pic, 'http://')) {
  48. $pic = str_replace('http://', 'https://', $pic);
  49. }
  50. return $pic;
  51. }
  52. # 列表页里的数据 根据类型,解析内容
  53. protected function content($data, $content = false)
  54. {
  55. $type = $id = false;
  56. if (isset($data['type']) && isset($data['data_id'])) {
  57. $type = $data['type'];
  58. $id = $data['data_id'];
  59. }
  60. if ($type && $id) {
  61. $table = Dever::config('base')->type_table[$type];
  62. //$info = Dever::db($table)->getOne($id);
  63. $info = Dever::db($table)->one($id);
  64. if ($info) {
  65. return $this->getInfo($type, $info, $content);
  66. } else {
  67. return array();
  68. }
  69. }
  70. return array();
  71. }
  72. protected function getInfo($type, $info, $content = false)
  73. {
  74. $info = $this->pic($info);
  75. $info['type'] = $type;
  76. $info['data_id'] = $info['id'];
  77. if (isset($info['pdate']) && $info['pdate'] > 0) {
  78. } else {
  79. $info['pdate'] = time();
  80. }
  81. $info['pdate_str'] = Dever::mdate($info['pdate'], 2);
  82. $info['pdate'] = date('Y-m-d H:i', $info['pdate']);
  83. /*
  84. if (isset($info['share_content'])) {
  85. $source = Dever::db('source/info')->one(1);
  86. $info['share_link'] = $source['code'];
  87. }
  88. */
  89. if (isset($info['cate_id']) && $info['cate_id']) {
  90. $info['cate'] = Dever::db('content/cate')->one($info['cate_id']);
  91. }
  92. if (isset($info['num_view']) && $info['num_view'] > 100000) {
  93. $info['num_view'] = '10w+';
  94. }
  95. if (isset($info['author_id']) && $info['author_id'] > 0) {
  96. $info['author'] = Dever::db('content/author')->one($info['author_id']);
  97. } elseif (isset($info['uid']) && $info['uid'] > 0) {
  98. $info['author'] = Dever::db('passport/user')->one($info['uid']);
  99. $info['author']['name'] = $info['author']['username'];
  100. }
  101. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  102. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  103. unset($info['num_add_view']);
  104. }
  105. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  106. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  107. unset($info['num_add_up']);
  108. }
  109. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  110. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  111. unset($info['num_add_user']);
  112. }
  113. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  114. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  115. unset($info['num_add_ding']);
  116. }
  117. if (isset($info['name']) && $info['name']) {
  118. $info['name'] = Dever::cut($info['name'], 20, '...');
  119. }
  120. return $info;
  121. }
  122. protected function getSourceUid($error = true)
  123. {
  124. return Dever::load('invite/api')->getSourceUid($this->data['uid'], $error);
  125. }
  126. protected function log()
  127. {
  128. $input = Dever::json_encode(Dever::input());
  129. $url = Dever::url();
  130. Dever::log($url . '||' . $input, 'request');
  131. }
  132. }