index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. class index {
  4. function __construct() {
  5. $this->db = pc_base::load_model('poster_model');
  6. $this->s_db = pc_base::load_model('poster_stat_model');
  7. }
  8. public function init() {
  9. }
  10. /**
  11. * 统计广告点击次数
  12. *
  13. */
  14. public function poster_click() {
  15. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  16. $r = $this->db->get_one(array('id'=>$id));
  17. if (!is_array($r) && empty($r)) return false;
  18. $ip_area = pc_base::load_sys_class('ip_area');
  19. $ip = ip();
  20. $area = $ip_area->get($ip);
  21. $username = param::get_cookie('username') ? param::get_cookie('username') : '';
  22. if($id) {
  23. $siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : get_siteid();
  24. $this->s_db->insert(array('siteid'=>$siteid, 'pid'=>$id, 'username'=>$username, 'area'=>$area, 'ip'=>$ip, 'referer'=>safe_replace(HTTP_REFERER), 'clicktime'=>SYS_TIME, 'type'=> 1));
  25. }
  26. $this->db->update(array('clicks'=>'+=1'), array('id'=>$id));
  27. $setting = string2array($r['setting']);
  28. if (count($setting)==1) {
  29. $url = $setting['1']['linkurl'];
  30. } else {
  31. $url = isset($_GET['url']) ? $_GET['url'] : $setting['1']['linkurl'];
  32. }
  33. header('Location: '.$url);
  34. }
  35. /**
  36. * php方式展示广告
  37. */
  38. public function show_poster() {
  39. if(!$_GET['id']) exit();
  40. $id = intval($_GET['id']);
  41. $sdb = pc_base::load_model('poster_space_model');
  42. $now = SYS_TIME;
  43. $siteid = get_siteid();
  44. $r = $sdb->get_one(array('siteid'=>$siteid, 'spaceid'=>$id));
  45. if(!$r) exit();
  46. if($r['setting']) $r['setting'] = string2array($r['setting']);
  47. $poster_template = getcache('poster_template_'.$siteid, 'commons');
  48. if ($poster_template[$r['type']]['option']) {
  49. $where = "`spaceid`='".$id."' AND `disabled`=0 AND `startdate`<='".$now."' AND (`enddate`>='".$now."' OR `enddate`=0) ";
  50. $pinfo = $this->db->select($where, '*', '', '`listorder` ASC, `id` DESC');
  51. if (is_array($pinfo) && !empty($pinfo)) {
  52. foreach ($pinfo as $k => $rs) {
  53. if ($rs['setting']) {
  54. $rs['setting'] = string2array($rs['setting']);
  55. $pinfo[$k] = $rs;
  56. } else {
  57. unset($pinfo[$k]);
  58. }
  59. }
  60. extract($r);
  61. } else {
  62. return true;
  63. }
  64. } else {
  65. $where = " `spaceid`='".$id."' AND `disabled`=0 AND `startdate`<='".$now."' AND (`enddate`>='".$now."' OR `enddate`=0)";
  66. $pinfo = $this->db->get_one($where, '*', '`listorder` ASC, `id` DESC');
  67. if (is_array($pinfo) && $pinfo['setting']) {
  68. $pinfo['setting'] = string2array($pinfo['setting']);
  69. }
  70. extract($r);
  71. if (!is_array($pinfo) || empty($pinfo)) return true;
  72. extract($pinfo, EXTR_PREFIX_SAME , 'p');
  73. }
  74. include template('poster', $type);
  75. }
  76. /**
  77. * js传值,统计展示次数
  78. */
  79. public function show() {
  80. $siteid = $_GET['siteid'] ? intval($_GET['siteid']) : get_siteid();
  81. $spaceid = $_GET['spaceid'] ? intval($_GET['spaceid']) : 0;
  82. $id = $_GET['id'] ? intval($_GET['id']) : 0;
  83. if (!$spaceid || !$id) {
  84. exit(0);
  85. } else {
  86. $this->show_stat($siteid, $spaceid, $id);
  87. }
  88. }
  89. /**
  90. * 统计广告展示次数
  91. * @param intval $siteid 站点ID
  92. * @param intval $spaceid 广告版位ID
  93. * @param intval $id 广告ID
  94. * @return boolen
  95. */
  96. protected function show_stat($siteid = 0, $spaceid = 0, $id = 0) {
  97. $M = new_html_special_chars(getcache('poster', 'commons'));
  98. if(isset($M[$siteid]['enablehits']) && $M[$siteid]['enablehits']==0) return true;
  99. //$siteid = intval($siteid);
  100. $spaceid = intval($spaceid);
  101. $id = intval($id);
  102. if(!$id) return false;
  103. if(!$siteid || !$spaceid) {
  104. $r = $this->db->get_one(array('id'=>$id), 'siteid, spaceid');
  105. $siteid = $r['id'];
  106. $spaceid = $r['spaceid'];
  107. }
  108. $ip = ip();
  109. $ip_area = pc_base::load_sys_class('ip_area');
  110. $area = $ip_area->get($ip);
  111. $username = param::get_cookie('username') ? param::get_cookie('username') : '';
  112. $this->db->update(array('hits'=>'+=1'), array('id'=>$id));
  113. $this->s_db->insert(array('pid'=>$id, 'siteid'=>$siteid, 'spaceid'=>$spaceid, 'username'=>$username, 'area'=>$area, 'ip'=>$ip, 'referer'=>safe_replace(HTTP_REFERER), 'clicktime'=>SYS_TIME, 'type'=>0));
  114. return true;
  115. }
  116. }
  117. ?>