| Current Path : /home/w/u/e/wuectly/www/03cbe/ |
| Current File : /home/w/u/e/wuectly/www/03cbe/banner.php.tar |
home/wuectly/www/components/com_banners/models/banner.php 0000604 00000010221 15245551674 0017736 0 ustar 00 <?php
/**
* @package Joomla.Site
* @subpackage com_banners
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
/**
* Banner model for the Joomla Banners component.
*
* @since 1.5
*/
class BannersModelBanner extends JModelLegacy
{
/**
* Cached item object
*
* @var object
* @since 1.6
*/
protected $_item;
/**
* Clicks the URL, incrementing the counter
*
* @return void
*
* @since 1.5
*/
public function click()
{
$item = $this->getItem();
if (empty($item))
{
throw new Exception(JText::_('JERROR_PAGE_NOT_FOUND'), 404);
}
$id = $this->getState('banner.id');
// Update click count
$db = $this->getDbo();
$query = $db->getQuery(true)
->update('#__banners')
->set('clicks = (clicks + 1)')
->where('id = ' . (int) $id);
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
JError::raiseError(500, $e->getMessage());
}
// Track clicks
$trackClicks = $item->track_clicks;
if ($trackClicks < 0 && $item->cid)
{
$trackClicks = $item->client_track_clicks;
}
if ($trackClicks < 0)
{
$config = JComponentHelper::getParams('com_banners');
$trackClicks = $config->get('track_clicks');
}
if ($trackClicks > 0)
{
$trackDate = JFactory::getDate()->format('Y-m-d H:00:00');
$trackDate = JFactory::getDate($trackDate)->toSql();
$query->clear()
->select($db->quoteName('count'))
->from('#__banner_tracks')
->where('track_type=2')
->where('banner_id=' . (int) $id)
->where('track_date=' . $db->quote($trackDate));
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
JError::raiseError(500, $e->getMessage());
}
$count = $db->loadResult();
$query->clear();
if ($count)
{
// Update count
$query->update('#__banner_tracks')
->set($db->quoteName('count') . ' = (' . $db->quoteName('count') . ' + 1)')
->where('track_type=2')
->where('banner_id=' . (int) $id)
->where('track_date=' . $db->quote($trackDate));
}
else
{
// Insert new count
$query->insert('#__banner_tracks')
->columns(
array(
$db->quoteName('count'), $db->quoteName('track_type'),
$db->quoteName('banner_id'), $db->quoteName('track_date')
)
)
->values('1, 2,' . (int) $id . ',' . $db->quote($trackDate));
}
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
JError::raiseError(500, $e->getMessage());
}
}
}
/**
* Get the data for a banner.
*
* @return object
*
* @since 1.6
*/
public function &getItem()
{
if (!isset($this->_item))
{
/** @var JCacheControllerCallback $cache */
$cache = JFactory::getCache('com_banners', 'callback');
$id = $this->getState('banner.id');
// For PHP 5.3 compat we can't use $this in the lambda function below, so grab the database driver now to use it
$db = $this->getDbo();
$loader = function ($id) use ($db)
{
$query = $db->getQuery(true)
->select(
array(
$db->quoteName('a.clickurl', 'clickurl'),
$db->quoteName('a.cid', 'cid'),
$db->quoteName('a.track_clicks', 'track_clicks'),
$db->quoteName('cl.track_clicks', 'client_track_clicks'),
)
)
->from($db->quoteName('#__banners', 'a'))
->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid')
->where('a.id = ' . (int) $id);
$db->setQuery($query);
return $db->loadObject();
};
try
{
$this->_item = $cache->get($loader, array($id), md5(__METHOD__ . $id));
}
catch (JCacheException $e)
{
$this->_item = $loader($id);
}
}
return $this->_item;
}
/**
* Get the URL for a banner
*
* @return string
*
* @since 1.5
*/
public function getUrl()
{
$item = $this->getItem();
$url = $item->clickurl;
// Check for links
if (!preg_match('#http[s]?://|index[2]?\.php#', $url))
{
$url = "http://$url";
}
return $url;
}
}
home/wuectly/www/components/com_banners/helpers/banner.php 0000604 00000001721 15245561663 0020121 0 ustar 00 <?php
/**
* @package Joomla.Site
* @subpackage com_banners
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Banner Helper Class
*
* @since 1.6
*/
abstract class BannerHelper
{
/**
* Checks if a URL is an image
*
* @param string $url The URL path to the potential image
*
* @return boolean True if an image of type bmp, gif, jp(e)g or png, false otherwise
*
* @since 1.6
*/
public static function isImage($url)
{
return preg_match('#\.(?:bmp|gif|jpe?g|png)$#i', $url);
}
/**
* Checks if a URL is a Flash file
*
* @param string $url The URL path to the potential flash file
*
* @return boolean True if an image of type bmp, gif, jp(e)g or png, false otherwise
*
* @since 1.6
*/
public static function isFlash($url)
{
return preg_match('#\.swf$#i', $url);
}
}
home/wuectly/www/administrator/components/com_banners/tables/banner.php 0000604 00000017607 15245664033 0022616 0 ustar 00 <?php
/**
* @package Joomla.Administrator
* @subpackage com_banners
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
/**
* Banner table
*
* @since 1.5
*/
class BannersTableBanner extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database connector object
*
* @since 1.5
*/
public function __construct(&$db)
{
parent::__construct('#__banners', 'id', $db);
JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_banners.banner'));
$this->created = JFactory::getDate()->toSql();
$this->setColumnAlias('published', 'state');
}
/**
* Increase click count
*
* @return void
*/
public function clicks()
{
$query = 'UPDATE #__banners'
. ' SET clicks = (clicks + 1)'
. ' WHERE id = ' . (int) $this->id;
$this->_db->setQuery($query);
$this->_db->execute();
}
/**
* Overloaded check function
*
* @return boolean
*
* @see JTable::check
* @since 1.5
*/
public function check()
{
// Set name
$this->name = htmlspecialchars_decode($this->name, ENT_QUOTES);
// Set alias
if (trim($this->alias) == '')
{
$this->alias = $this->name;
}
$this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up)
{
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
// Set ordering
if ($this->state < 0)
{
// Set ordering to 0 if state is archived or trashed
$this->ordering = 0;
}
elseif (empty($this->ordering))
{
// Set ordering to last if ordering was 0
$this->ordering = self::getNextOrder($this->_db->quoteName('catid') . '=' . $this->_db->quote($this->catid) . ' AND state>=0');
}
if (empty($this->publish_up))
{
$this->publish_up = $this->getDbo()->getNullDate();
}
if (empty($this->publish_down))
{
$this->publish_down = $this->getDbo()->getNullDate();
}
if (empty($this->modified))
{
$this->modified = $this->getDbo()->getNullDate();
}
return true;
}
/**
* Overloaded bind function
*
* @param mixed $array An associative array or object to bind to the JTable instance.
* @param mixed $ignore An optional array or space separated list of properties to ignore while binding.
*
* @return boolean True on success
*
* @since 1.5
*/
public function bind($array, $ignore = array())
{
if (isset($array['params']) && is_array($array['params']))
{
$registry = new Registry($array['params']);
if ((int) $registry->get('width', 0) < 0)
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_WIDTH_LABEL')));
return false;
}
if ((int) $registry->get('height', 0) < 0)
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_NEGATIVE_NOT_PERMITTED', JText::_('COM_BANNERS_FIELD_HEIGHT_LABEL')));
return false;
}
// Converts the width and height to an absolute numeric value:
$width = abs((int) $registry->get('width', 0));
$height = abs((int) $registry->get('height', 0));
// Sets the width and height to an empty string if = 0
$registry->set('width', $width ?: '');
$registry->set('height', $height ?: '');
$array['params'] = (string) $registry;
}
if (isset($array['imptotal']))
{
$array['imptotal'] = abs((int) $array['imptotal']);
}
return parent::bind($array, $ignore);
}
/**
* Method to store a row
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success, false on failure.
*/
public function store($updateNulls = false)
{
$db = $this->getDbo();
if (empty($this->id))
{
$purchaseType = $this->purchase_type;
if ($purchaseType < 0 && $this->cid)
{
/** @var BannersTableClient $client */
$client = JTable::getInstance('Client', 'BannersTable', array('dbo' => $db));
$client->load($this->cid);
$purchaseType = $client->purchase_type;
}
if ($purchaseType < 0)
{
$purchaseType = JComponentHelper::getParams('com_banners')->get('purchase_type');
}
switch ($purchaseType)
{
case 1:
$this->reset = $this->_db->getNullDate();
break;
case 2:
$date = JFactory::getDate('+1 year ' . date('Y-m-d'));
$this->reset = $date->toSql();
break;
case 3:
$date = JFactory::getDate('+1 month ' . date('Y-m-d'));
$this->reset = $date->toSql();
break;
case 4:
$date = JFactory::getDate('+7 day ' . date('Y-m-d'));
$this->reset = $date->toSql();
break;
case 5:
$date = JFactory::getDate('+1 day ' . date('Y-m-d'));
$this->reset = $date->toSql();
break;
}
// Store the row
parent::store($updateNulls);
}
else
{
// Get the old row
/** @var BannersTableBanner $oldrow */
$oldrow = JTable::getInstance('Banner', 'BannersTable', array('dbo' => $db));
if (!$oldrow->load($this->id) && $oldrow->getError())
{
$this->setError($oldrow->getError());
}
// Verify that the alias is unique
/** @var BannersTableBanner $table */
$table = JTable::getInstance('Banner', 'BannersTable', array('dbo' => $db));
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('COM_BANNERS_ERROR_UNIQUE_ALIAS'));
return false;
}
// Store the new row
parent::store($updateNulls);
// Need to reorder ?
if ($oldrow->state >= 0 && ($this->state < 0 || $oldrow->catid != $this->catid))
{
// Reorder the oldrow
$this->reorder($this->_db->quoteName('catid') . '=' . $this->_db->quote($oldrow->catid) . ' AND state>=0');
}
}
return count($this->getErrors()) == 0;
}
/**
* Method to set the sticky state for a row or list of rows in the database
* table. The method respects checked out rows by other users and will attempt
* to checkin rows that it can after adjustments are made.
*
* @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used.
* @param integer $state The sticky state. eg. [0 = unsticked, 1 = sticked]
* @param integer $userId The user id of the user performing the operation.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function stick($pks = null, $state = 1, $userId = 0)
{
$k = $this->_tbl_key;
// Sanitize input.
$pks = ArrayHelper::toInteger($pks);
$userId = (int) $userId;
$state = (int) $state;
// If there are no primary keys set check to see if the instance key is set.
if (empty($pks))
{
if ($this->$k)
{
$pks = array($this->$k);
}
// Nothing to set publishing state on, return false.
else
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
return false;
}
}
// Get an instance of the table
/** @var BannersTableBanner $table */
$table = JTable::getInstance('Banner', 'BannersTable');
// For all keys
foreach ($pks as $pk)
{
// Load the banner
if (!$table->load($pk))
{
$this->setError($table->getError());
}
// Verify checkout
if ($table->checked_out == 0 || $table->checked_out == $userId)
{
// Change the state
$table->sticky = $state;
$table->checked_out = 0;
$table->checked_out_time = $this->_db->getNullDate();
// Check the row
$table->check();
// Store the row
if (!$table->store())
{
$this->setError($table->getError());
}
}
}
return count($this->getErrors()) == 0;
}
}