Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1497
 
1669
 
1669
 
banner.php
_> 11 <?php
  22 /*
<> 3 -  $Id: banner.php 1497 2007-03-29 13:40:05Z hpdl $
   3+  $Id: banner.php 1669 2007-07-20 20:38:29Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2004 osCommerce
   8+  Copyright (c) 2007 osCommerce
99 
  1010   This program is free software; you can redistribute it and/or modify
  1111   it under the terms of the GNU General Public License v2 (1991)
  1212   as published by the Free Software Foundation.
  1313 */
  1414 
<>  15+/**
   16+ * The osC_Banner class manages the banners shown throughout the online store
   17+ */
   18+
1519   class osC_Banner {
  1620 
<> 17 -/* Public variables */
  18 -    var $show_duplicates_in_group = false;
   21+/**
   22+ * Controls whether banners should be shown multiple times on the page
   23+ *
   24+ * @var boolean
   25+ * @access private
   26+ */
1927 
<> 20 -/* Private variables */
  21 -    var $_exists_id,
  22 -        $_shown_ids = array();
   28+    private $_show_duplicates_in_group = false;
2329 
<> 24 -/* Class constructor */
   30+/**
   31+ * A placeholder that keeps the banner ID in memory when checking if a banner exists before showing it
   32+ *
   33+ * @var id
   34+ * @access private
   35+ */
2536 
<> 26 -    function osC_Banner() {
  27 -      if (SERVICE_BANNER_SHOW_DUPLICATE == 'True') {
  28 -        $this->show_duplicates_in_group = true;
   37+    private $_exists_id;
   38+
   39+/**
   40+ * An array containing the banner IDs already shown on the page
   41+ *
   42+ * @var array
   43+ * @access private
   44+ */
   45+
   46+    private $_shown_ids = array();
   47+
   48+/**
   49+ * Constructor
   50+ *
   51+ * @access public
   52+ */
   53+
   54+    public function __construct() {
   55+      if ( SERVICE_BANNER_SHOW_DUPLICATE == 'True' ) {
   56+        $this->_show_duplicates_in_group = true;
2957       }
  3058     }
  3159 
<> 32 -/* Public methods */
   60+/**
   61+ * Activate a banner that has been on schedule
   62+ *
   63+ * @param int $id The ID of the banner to activate
   64+ * @access public
   65+ * @return boolean
   66+ */
3367 
<> 34 -    function activate($id) {
  35 -      $this->_setStatus($id, true);
   68+    public function activate($id) {
   69+      return $this->_setStatus($id, true);
3670     }
  3771 
<> 38 -    function activateAll() {
   72+/**
   73+ * Activate all banners on schedule
   74+ *
   75+ * @access public
   76+ */
   77+
   78+    public function activateAll() {
3979       global $osC_Database;
  4080 
  4181       $Qbanner = $osC_Database->query('select banners_id, date_scheduled from :table_banners where date_scheduled != ""');
  4282       $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  4383       $Qbanner->execute();
  4484 
<> 45 -      if ($Qbanner->numberOfRows() > 0) {
  46 -        while ($Qbanner->next()) {
  47 -          if (osC_DateTime::getNow() >= $Qbanner->value('date_scheduled')) {
  48 -            $this->activate($Qbanner->valueInt('banners_id'));
  49 -          }
   85+      while ( $Qbanner->next() ) {
   86+        if ( osC_DateTime::getNow() >= $Qbanner->value('date_scheduled') ) {
   87+          $this->activate($Qbanner->valueInt('banners_id'));
5088         }
  5189       }
<> 52 -
  53 -      $Qbanner->freeResult();
5490     }
  5591 
<> 56 -    function expire($id) {
  57 -      $this->_setStatus($id, false);
   92+/**
   93+ * Deactivate a banner
   94+ *
   95+ * @param int $id The ID of the banner to deactivate
   96+ * @access public
   97+ * @return boolean
   98+ */
   99+
   100+    public function expire($id) {
   101+      return $this->_setStatus($id, false);
58102     }
  59103 
<> 60 -    function expireAll() {
   104+/**
   105+ * Deactivate all banners that have passed their schedule
   106+ *
   107+ * @access public
   108+ */
   109+
   110+    public function expireAll() {
61111       global $osC_Database;
  62112 
  63113       $Qbanner = $osC_Database->query('select b.banners_id, b.expires_date, b.expires_impressions, sum(bh.banners_shown) as banners_shown from :table_banners b, :table_banners_history bh where b.status = 1 and b.banners_id = bh.banners_id group by b.banners_id');
  64114       $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  65115       $Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
  66116       $Qbanner->execute();
  67117 
<> 68 -      if ($Qbanner->numberOfRows() > 0) {
  69 -        while ($Qbanner->next()) {
  70 -          if (!osc_empty($Qbanner->value('expires_date'))) {
  71 -            if (osC_DateTime::getNow() >= $Qbanner->value('expires_date')) {
  72 -              $this->expire($Qbanner->valueInt('banners_id'));
  73 -            }
  74 -          } elseif (!osc_empty($Qbanner->valueInt('expires_impressions'))) {
  75 -            if ( ($Qbanner->valueInt('expires_impressions') > 0) && ($Qbanner->valueInt('banners_shown') >= $Qbanner->valueInt('expires_impressions')) ) {
  76 -              $this->expire($Qbanner->valueInt('banners_id'));
  77 -            }
   118+      while ( $Qbanner->next() ) {
   119+        if ( !osc_empty($Qbanner->value('expires_date')) ) {
   120+          if ( osC_DateTime::getNow() >= $Qbanner->value('expires_date') ) {
   121+            $this->expire($Qbanner->valueInt('banners_id'));
78122           }
<>  123+        } elseif ( !osc_empty($Qbanner->valueInt('expires_impressions')) ) {
   124+          if ( ($Qbanner->valueInt('expires_impressions') > 0) && ($Qbanner->valueInt('banners_shown') >= $Qbanner->valueInt('expires_impressions')) ) {
   125+            $this->expire($Qbanner->valueInt('banners_id'));
   126+          }
79127         }
  80128       }
<> 81 -
  82 -      $Qbanner->freeResult();
83129     }
  84130 
<> 85 -    function isActive($id) {
   131+/**
   132+ * Check if an existing banner is active
   133+ *
   134+ * @param int $id The ID of the banner to check
   135+ * @access public
   136+ * @return boolean
   137+ */
   138+
   139+    public function isActive($id) {
86140       global $osC_Database;
  87141 
<> 88 -      $Qbanner = $osC_Database->query('select banners_id from :table_banners where status = 1 and banners_id = :banners_id');
   142+      $Qbanner = $osC_Database->query('select status from :table_banners where banners_id = :banners_id');
89143       $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  90144       $Qbanner->bindInt(':banners_id', $id);
  91145       $Qbanner->execute();
  92146 
<> 93 -      if ($Qbanner->numberOfRows() > 0) {
  94 -        return true;
  95 -      }
  96 -
  97 -      return false;
   147+      return ( $Qbanner->valueInt('status') === 1 );
98148     }
  99149 
<> 100 -    function exists($group) {
   150+/**
   151+ * Check if banners exist in a group. If banners exists, select a random entry and assign its ID to $_exists_id.
   152+ *
   153+ * @param string $group The group to check in
   154+ * @access public
   155+ * @return boolean
   156+ */
   157+
   158+    public function exists($group) {
101159       global $osC_Database;
  102160 
  103161       $Qbanner = $osC_Database->query('select banners_id from :table_banners where status = 1 and banners_group = :banners_group');
  104162 
<> 105 -      if ( ($this->show_duplicates_in_group === false) && (sizeof($this->_shown_ids) > 0) ) {
   163+      if ( ($this->_show_duplicates_in_group === false) && (sizeof($this->_shown_ids) > 0) ) {
106164         $Qbanner->appendQuery('and banners_id not in (:banner_ids)');
  107165         $Qbanner->bindRaw(':banner_ids', implode(',', $this->_shown_ids));
  108166       }
     
 !
111169       $Qbanner->bindValue(':banners_group', $group);
  112170       $Qbanner->executeRandom();
  113171 
<> 114 -      if ($Qbanner->numberOfRows() > 0) {
   172+      if ( $Qbanner->numberOfRows() > 0 ) {
115173         $this->_exists_id = $Qbanner->valueInt('banners_id');
  116174 
  117175         return true;
     
 !
120178       return false;
  121179     }
  122180 
<> 123 -    function display($id = '') {
   181+/**
   182+ * Display a banner. If no ID is passed, the value defined in $_exists_id is used.
   183+ *
   184+ * @param int $id The ID of the banner to show
   185+ * @access public
   186+ * @return string
   187+ */
   188+
   189+    public function display($id = null) {
124190       global $osC_Database;
  125191 
<> 126 -      $banner_string = false;
   192+      $banner_string = '';
127193 
<> 128 -      if (empty($id) && isset($this->_exists_id) && is_numeric($this->_exists_id)) {
   194+      if ( empty($id) && isset($this->_exists_id) && is_numeric($this->_exists_id) ) {
129195         $id = $this->_exists_id;
  130196 
  131197         unset($this->_exists_id);
     
 !
136202       $Qbanner->bindInt(':banners_id', $id);
  137203       $Qbanner->execute();
  138204 
<> 139 -      if ($Qbanner->numberOfRows() > 0) {
  140 -        if (!osc_empty($Qbanner->value('banners_html_text'))) {
   205+      if ( $Qbanner->numberOfRows() > 0 ) {
   206+        if ( !osc_empty($Qbanner->value('banners_html_text')) ) {
141207           $banner_string = $Qbanner->value('banners_html_text');
  142208         } else {
  143209           $banner_string = osc_link_object(osc_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $Qbanner->valueInt('banners_id')), osc_image(DIR_WS_IMAGES . $Qbanner->value('banners_image'), $Qbanner->value('banners_title')), 'target="_blank"');
  144210         }
  145211 
  146212         $this->_updateDisplayCount($Qbanner->valueInt('banners_id'));
  147213 
<> 148 -        if ($this->show_duplicates_in_group === false) {
   214+        if ( $this->_show_duplicates_in_group === false ) {
149215           $this->_shown_ids[] = $Qbanner->valueInt('banners_id');
  150216         }
  151217       }
  152218 
<> 153 -      $Qbanner->freeResult();
  154 -
155219       return $banner_string;
  156220     }
  157221 
<> 158 -    function getURL($id, $increment_click = false) {
   222+/**
   223+ * Return the URL assigned to the banner
   224+ *
   225+ * @param int $id The ID of the banner
   226+ * @param boolean $increment_click_flag A flag to state if the banner click count should be incremented
   227+ * @access public
   228+ * @return string
   229+ */
   230+
   231+    public function getURL($id, $increment_click_flag = false) {
159232       global $osC_Database;
  160233 
<> 161 -      $url = false;
   234+      $url = '';
162235 
  163236       $Qbanner = $osC_Database->query('select banners_url from :table_banners where banners_id = :banners_id and status = 1');
  164237       $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  165238       $Qbanner->bindInt(':banners_id', $id);
  166239       $Qbanner->execute();
  167240 
<> 168 -      if ($Qbanner->numberOfRows() > 0) {
   241+      if ( $Qbanner->numberOfRows() > 0 ) {
169242         $url = $Qbanner->value('banners_url');
  170243 
<> 171 -        if ($increment_click === true) {
   244+        if ( $increment_click_flag === true ) {
172245           $this->_updateClickCount($id);
  173246         }
  174247       }
  175248 
<> 176 -      $Qbanner->freeResult();
  177 -
178249       return $url;
  179250     }
  180251 
<> 181 -/* Private methods */
   252+/**
   253+ * Sets the status of a banner
   254+ *
   255+ * @param int $id The ID of the banner to set the status to
   256+ * @param boolean $active_flag A flag that enables or disables the banner
   257+ * @access private
   258+ * @return boolean
   259+ */
182260 
<> 183 -    function _setStatus($id, $active) {
   261+    private function _setStatus($id, $active_flag) {
184262       global $osC_Database;
  185263 
<> 186 -      if ($active === true) {
   264+      if ( $active_flag === true ) {
187265         $Qbanner = $osC_Database->query('update :table_banners set status = 1, date_status_change = now(), date_scheduled = NULL where banners_id = :banners_id');
<> 188 -        $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  189 -        $Qbanner->bindInt(':banners_id', $id);
  190 -        $Qbanner->execute();
191266       } else {
  192267         $Qbanner = $osC_Database->query('update :table_banners set status = 0, date_status_change = now() where banners_id = :banners_id');
<> 193 -        $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
  194 -        $Qbanner->bindInt(':banners_id', $id);
  195 -        $Qbanner->execute();
196268       }
  197269 
<> 198 -      $Qbanner->freeResult();
   270+      $Qbanner->bindTable(':table_banners', TABLE_BANNERS);
   271+      $Qbanner->bindInt(':banners_id', $id);
   272+      $Qbanner->execute();
   273+
   274+      return ( $Qbanner->affectedRows() === 1 );
199275     }
  200276 
<> 201 -    function _updateDisplayCount($id) {
   277+/**
   278+ * Increment the display count of the banner
   279+ *
   280+ * @param int $id The ID of the banner
   281+ * @access private
   282+ */
   283+
   284+    private function _updateDisplayCount($id) {
202285       global $osC_Database;
  203286 
  204287       $Qcheck = $osC_Database->query('select count(*) as count from :table_banners_history where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
  205288       $Qcheck->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
  206289       $Qcheck->bindInt(':banners_id', $id);
  207290       $Qcheck->execute();
  208291 
<> 209 -      if ($Qcheck->valueInt('count') > 0) {
   292+      if ( $Qcheck->valueInt('count') > 0 ) {
210293         $Qbanner = $osC_Database->query('update :table_banners_history set banners_shown = banners_shown + 1 where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
  211294       } else {
  212295         $Qbanner = $osC_Database->query('insert into :table_banners_history (banners_id, banners_shown, banners_history_date) values (:banners_id, 1, now())');
  213296       }
<>  297+
214298       $Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
  215299       $Qbanner->bindInt(':banners_id', $id);
  216300       $Qbanner->execute();
<> 217 -
  218 -      $Qcheck->freeResult();
  219 -      $Qbanner->freeResult();
220301     }
  221302 
<> 222 -    function _updateClickCount($id) {
   303+/**
   304+ * Increment the click count of the banner
   305+ *
   306+ * @param int $id The ID of the banner
   307+ * @access private
   308+ */
   309+
   310+    private function _updateClickCount($id) {
223311       global $osC_Database;
  224312 
  225313       $Qcheck = $osC_Database->query('select count(*) as count from :table_banners_history where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
  226314       $Qcheck->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
  227315       $Qcheck->bindInt(':banners_id', $id);
  228316       $Qcheck->execute();
  229317 
<> 230 -      if ($Qcheck->valueInt('count') > 0) {
   318+      if ( $Qcheck->valueInt('count') > 0 ) {
231319         $Qbanner = $osC_Database->query('update :table_banners_history set banners_clicked = banners_clicked + 1 where banners_id = :banners_id and date_format(banners_history_date, "%Y%m%d") = date_format(now(), "%Y%m%d")');
  232320       } else {
  233321         $Qbanner = $osC_Database->query('insert into :table_banners_history (banners_id, banners_clicked, banners_history_date) values (:banners_id, 1, now())');
  234322       }
<>  323+
235324       $Qbanner->bindTable(':table_banners_history', TABLE_BANNERS_HISTORY);
  236325       $Qbanner->bindInt(':banners_id', $id);
  237326       $Qbanner->execute();
<> 238 -
  239 -      $Qcheck->freeResult();
  240 -      $Qbanner->freeResult();
<_ 241327     }
  242328   }
  243329 ?>