1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class BannerRender
23: {
24: 25: 26:
27: public function __construct()
28: {
29: }
30:
31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
41: public function displayBanner($nb_banner = 1, $align = 'H', $client = array(), $ids = '')
42: {
43: $xoops = Xoops::getInstance();
44: XoopsLoad::addMap(array('banners' => __DIR__ . '/helper.php'));
45: $helper = Banners::getInstance();
46: if ($xoops->isActiveModule('banners')) {
47:
48: $banner_Handler = $helper->getHandlerBanner();
49:
50: $criteria = new CriteriaCompo();
51: $criteria->add(new Criteria('banner_status', 0, '!='));
52: $sort = ('sqlite' === \XoopsBaseConfig::get('db-type')) ? 'RANDOM()' : 'RAND()';
53: $criteria->setSort($sort);
54: if (!empty($client)) {
55: if (!in_array(0, $client)) {
56: $criteria->add(new Criteria('banner_cid', '(' . implode(',', $client) . ')', 'IN'));
57: }
58: }
59: if ($ids == '') {
60: $criteria->setLimit($nb_banner);
61: $criteria->setStart(0);
62: } else {
63: $criteria->add(new Criteria('banner_bid', '(' . $ids . ')', 'IN'));
64: }
65: $banner_arr = $banner_Handler->getAll($criteria);
66: $numrows = count($banner_arr);
67: $bannerobject = '';
68: if ($numrows > 0) {
69: foreach (array_keys($banner_arr) as $i) {
70: $imptotal = $banner_arr[$i]->getVar("banner_imptotal");
71: $impmade = $banner_arr[$i]->getVar("banner_impmade");
72: $htmlbanner = $banner_arr[$i]->getVar("banner_htmlbanner");
73: $htmlcode = $banner_arr[$i]->getVar("banner_htmlcode");
74: $imageurl = $banner_arr[$i]->getVar("banner_imageurl");
75: $bid = $banner_arr[$i]->getVar("banner_bid");
76: $clickurl = $banner_arr[$i]->getVar("banner_clickurl");
77: 78: 79:
80: if ($htmlbanner) {
81: $bannerobject .= $htmlcode;
82: } else {
83: if (stristr($imageurl, '.swf')) {
84: $bannerobject .= '<a href="' . \XoopsBaseConfig::get('url') . '/modules/banners/index.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"></a>' . '<object type="application/x-shockwave-flash" width="468" height="60" data="' . $imageurl . '" style="z-index:100;">' . '<param name="movie" value="' . $imageurl . '" />' . '<param name="wmode" value="opaque" />' . '</object>';
85: } else {
86: $bannerobject .= '<a href="' . \XoopsBaseConfig::get('url') . '/modules/banners/index.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"><img src="' . $imageurl . '" alt="' . $clickurl . '" /></a>';
87: }
88: }
89: if ($align === 'V') {
90: $bannerobject .= '<br /><br />';
91: } else {
92: $bannerobject .= ' ';
93: }
94: if ($helper->getConfig('banners_myip') == $xoops->getEnv('REMOTE_ADDR')) {
95:
96: } else {
97: 98: 99:
100: $impmade = $impmade + 1;
101: $qb = $xoops->db()->createXoopsQueryBuilder();
102: if ($imptotal > 0 && $impmade >= $imptotal) {
103: $query = $qb->updatePrefix('banners_banner')
104: ->set('banner_impmade', ':impr')
105: ->set('banner_status', ':stat')
106: ->set('banner_dateend', ':dateend')
107: ->where('banner_bid = :bid')
108: ->setParameter(':impr', $impmade, \PDO::PARAM_INT)
109: ->setParameter(':stat', 0, \PDO::PARAM_INT)
110: ->setParameter(':dateend', time(), \PDO::PARAM_INT)
111: ->setParameter(':bid', $bid, \PDO::PARAM_INT);
112: $result = $query->execute();
113: } else {
114: $query = $qb->updatePrefix('banners_banner')
115: ->set('banner_impmade', ':impr')
116: ->where('banner_bid = :bid')
117: ->setParameter(':impr', $impmade, \PDO::PARAM_INT)
118: ->setParameter(':bid', $bid, \PDO::PARAM_INT);
119: $result = $query->execute();
120: }
121: }
122: }
123: return $bannerobject;
124: }
125: }
126: }
127: }
128: