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