Core.php 5.0 KB

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