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