Core.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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['config'] = 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. $version['source_type'] = $source_type;
  28. $this->data['version'] = Dever::db('main/version')->getOne($version);
  29. }
  30. }
  31. # 图片处理
  32. public function pic($data, $type = 't1')
  33. {
  34. //?imageView2/1/w/100/h/100/q/75
  35. $config = array
  36. (
  37. 'pic','pic_cover', 'pic_cover_169', 'content', 'share_pic'
  38. );
  39. foreach ($config as $k => $v) {
  40. if (isset($data[$v]) && $data[$v]) {
  41. $data[$v] = $this->replacePic($data[$v], $type);
  42. }
  43. }
  44. return $data;
  45. }
  46. public function replacePic($pic, $type = 't1')
  47. {
  48. //$pic = Dever::pic($pic, $type);
  49. if (strstr($pic, 'http://')) {
  50. $pic = str_replace('http://', 'https://', $pic);
  51. }
  52. return $pic;
  53. }
  54. # 列表页里的数据 根据类型,解析内容
  55. protected function content($data, $content = false)
  56. {
  57. $type = $id = false;
  58. if (isset($data['type']) && isset($data['data_id'])) {
  59. $type = $data['type'];
  60. $id = $data['data_id'];
  61. }
  62. if ($type && $id) {
  63. $table = Dever::config('base')->type_table[$type];
  64. //$info = Dever::db($table)->getOne($id);
  65. $info = Dever::db($table)->one($id);
  66. if ($info) {
  67. return $this->getInfo($type, $info, $content);
  68. } else {
  69. return array();
  70. }
  71. }
  72. return array();
  73. }
  74. protected function getInfo($type, $info, $content = false)
  75. {
  76. $info = $this->pic($info);
  77. $info['type'] = $type;
  78. $info['data_id'] = $info['id'];
  79. if (isset($info['content']) && !$content) {
  80. unset($info['content']);
  81. }
  82. if (isset($info['pdate']) && $info['pdate'] > 0) {
  83. } else {
  84. $info['pdate'] = time();
  85. }
  86. $info['pdate'] = date('Y-m-d', $info['pdate']);
  87. if (isset($info['cate_id']) && $info['cate_id']) {
  88. $cate = Dever::db('content/cate')->one($info['cate_id']);
  89. $info['cate_name'] = $cate['name'];
  90. }
  91. if (isset($info['author_id']) && $info['author_id']) {
  92. $author = Dever::db('content/author')->one($info['author_id']);
  93. $info['author_name'] = $author['name'];
  94. }
  95. if (isset($info['num_add_view']) && isset($info['num_view'])) {
  96. $info['num_view'] = $info['num_add_view'] + $info['num_view'];
  97. unset($info['num_add_view']);
  98. }
  99. if (isset($info['num_add_up']) && isset($info['num_up'])) {
  100. $info['num_up'] = $info['num_add_up'] + $info['num_up'];
  101. unset($info['num_add_up']);
  102. }
  103. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  104. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  105. unset($info['num_add_user']);
  106. }
  107. if (isset($info['num_add_user']) && isset($info['num_user'])) {
  108. $info['num_user'] = $info['num_add_user'] + $info['num_user'];
  109. unset($info['num_add_user']);
  110. }
  111. if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
  112. $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
  113. unset($info['num_add_ding']);
  114. }
  115. if (isset($info['name']) && $info['name']) {
  116. $info['name'] = Dever::cut($info['name'], 20, '...');
  117. }
  118. return $info;
  119. }
  120. protected function getSourceUid($error = true)
  121. {
  122. return Dever::load('invite/api')->getSourceUid($this->data['uid'], $error);
  123. }
  124. protected function log()
  125. {
  126. $input = Dever::json_encode(Dever::input());
  127. $url = Dever::url();
  128. Dever::log($url . '||' . $input, 'request');
  129. }
  130. }