Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/components/com_banners/models/banner.php
f43d1a4680a9
4.7 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <?php
/**
* @version $Id: banner.php 11393 2009-01-05 02:11:06Z ian $
* @package Joomla
* @subpackage Banners
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
jimport( 'joomla.application.component.helper' );
/**
* @package Joomla
* @subpackage Banners
*/
class BannersModelBanner extends JModel
{
/**
* Gets a list of banners
* @param array An array of filters
* @return array An array of banner objects
*/
function getList( $filters )
{
$db = &$this->getDBO();
$ordering = @$filters['ordering'];
$tagSearch = @$filters['tag_search'];
$randomise = ($ordering == 'random');
$wheres = array();
$wheres[] = 'showBanner = 1';
$wheres[] = '(imptotal = 0 OR impmade < imptotal)';
if (@$filters['cid'])
{
$wheres[] = 'cid = ' . (int) $filters['cid'];
}
if (@$filters['catid'])
{
$wheres[] = 'catid = ' . (int) $filters['catid'];
}
if (is_array( $tagSearch ))
{
$temp = array();
$n = count( $tagSearch );
if ($n == 0)
{
// if tagsearch is an array, and empty, fail the query
$result = array();
return $result;
}
for ($i = 0; $i < $n; $i++)
{
$temp[] = "tags REGEXP '[[:<:]]".$db->getEscaped( $tagSearch[$i] ) . "[[:>:]]'";
}
if ($n)
{
$wheres[] = '(' . implode( ' OR ', $temp). ')';
}
}
$query = "SELECT *"
. ($randomise ? ', RAND() AS ordering' : '')
. ' FROM #__banner'
. ' WHERE ' . implode( ' AND ', $wheres )
. ' ORDER BY sticky DESC, ordering ';
$db->setQuery( $query, 0, $filters['limit'] );
$result = $db->loadObjectList();
// if($db->getErrorNum()) {
// JError::raiseError( 500, $db->stderr());
// }
return $result;
}
/**
* Makes impressions on a list of banners
*/
function impress( $list )
{
$config =& JComponentHelper::getParams( 'com_banners' );
$db = &$this->getDBO();
$n = count( $list );
$trackImpressions = $config->get( 'track_impressions' );
$date =& JFactory::getDate();
$trackDate = $date->toFormat( '%Y-%m-%d' );
// TODO: Change loop single sql with where bid = x OR bid = y format
for ($i = 0; $i < $n; $i++) {
$item = &$list[$i];
$item->impmade++;
$expire = ($item->impmade >= $item->imptotal) && ($item->imptotal != 0);
$query = 'UPDATE #__banner'
. ' SET impmade = impmade + 1'
. ($expire ? ', showBanner=0' : '')
. ' WHERE bid = '.(int) $item->bid
;
$db->setQuery( $query );
if(!$db->query()) {
JError::raiseError( 500, $db->stderror());
}
if ($trackImpressions)
{
// TODO: Add impression tracking
/*
$query = 'UPDATE #__bannertrack SET' .
' track_type = 1,' .
' banner_id = ' . $item->bid;
*/
$query = 'INSERT INTO #__bannertrack ( track_type, banner_id, track_date )' .
' VALUES ( 1, '.(int) $item->bid.', '.$db->Quote($trackDate).' )'
;
$db->setQuery( $query );
if(!$db->query()) {
JError::raiseError( 500, $db->stderror() );
}
}
}
}
/**
* Clicks the URL, incrementing the counter
*/
function click( $id = 0 )
{
$config =& JComponentHelper::getParams( 'com_banners' );
$db = &$this->getDBO();
$trackClicks = $config->get( 'track_clicks' );
$date =& JFactory::getDate();
$trackDate = $date->toFormat( '%Y-%m-%d' );
// update click count
$query = 'UPDATE #__banner' .
' SET clicks = ( clicks + 1 )' .
' WHERE bid = ' . (int)$id;
$db->setQuery( $query );
if(!$db->query()) {
JError::raiseError( 500, $db->stderror());
}
if ($trackClicks)
{
$query = 'INSERT INTO #__bannertrack ( track_type, banner_id, track_date )' .
' VALUES ( 2, '.(int)$id.', '.$db->Quote($trackDate).' )'
;
$db->setQuery( $query );
if(!$db->query()) {
JError::raiseError( 500, $db->stderror() );
}
}
}
/**
* Get the URL for a
*/
function getUrl( $id = 0 )
{
global $mainframe;
$db = &$this->getDBO();
// redirect to banner url
$query = 'SELECT clickurl, bid FROM #__banner' .
' WHERE bid = ' . (int) $id;
$db->setQuery( $query );
if(!$db->query())
{
JError::raiseError( 500, $db->stderr());
}
$url = $db->loadResult();
// check for links
if (!preg_match( '#http[s]?://|index[2]?\.php#', $url ))
{
$url = "http://$url";
}
return $url;
}
}
|