Spade

Mini Shell

Directory:~$ /proc/self/root/home/lmsyaran/public_html/css/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/home/lmsyaran/public_html/css/com_banners.tar

access.xml000064400000002575151165563350006552 0ustar00<?xml
version="1.0" encoding="utf-8"?>
<access component="com_banners">
	<section name="component">
		<action
			name="core.admin"
			description="JACTION_ADMIN_COMPONENT_DESC"
			title="JACTION_ADMIN"
		/>

		<action
			name="core.options"
			description="JACTION_OPTIONS_COMPONENT_DESC"
			title="JACTION_OPTIONS"
		/>

		<action
			name="core.manage"
			description="JACTION_MANAGE_COMPONENT_DESC"
			title="JACTION_MANAGE"
		/>

		<action
			name="core.create"
			description="JACTION_CREATE_COMPONENT_DESC"
			title="JACTION_CREATE"
		/>

		<action
			name="core.delete"
			description="JACTION_DELETE_COMPONENT_DESC"
			title="JACTION_DELETE"
		/>

		<action
			name="core.edit"
			description="JACTION_EDIT_COMPONENT_DESC"
			title="JACTION_EDIT"
		/>

		<action
			name="core.edit.state"
			description="JACTION_EDITSTATE_COMPONENT_DESC"
			title="JACTION_EDITSTATE"
		/>

	</section>
	<section name="category">
		<action
			name="core.create"
			description="COM_CATEGORIES_ACCESS_CREATE_DESC"
			title="JACTION_CREATE"
		/>

		<action
			name="core.delete"
			description="COM_CATEGORIES_ACCESS_DELETE_DESC"
			title="JACTION_DELETE"
		/>

		<action
			name="core.edit"
			description="COM_CATEGORIES_ACCESS_EDIT_DESC"
			title="JACTION_EDIT"
		/>

		<action
			name="core.edit.state"
			description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC"
			title="JACTION_EDITSTATE"
		/>
	</section>
</access>
banners.php000064400000000645151165563350006724 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

$controller = JControllerLegacy::getInstance('Banners');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();
banners.xml000064400000004612151165563350006733 0ustar00<?xml
version="1.0" encoding="utf-8"?>
<extension type="component" version="3.1"
method="upgrade">
	<name>com_banners</name>
	<author>Joomla! Project</author>
	<creationDate>April 2006</creationDate>
	<copyright>(C) 2005 - 2020 Open Source Matters. All rights
reserved.</copyright>
	<license>GNU General Public License version 2 or later; see
LICENSE.txt</license>
	<authorEmail>admin@joomla.org</authorEmail>
	<authorUrl>www.joomla.org</authorUrl>
	<version>3.0.0</version>
	<description>COM_BANNERS_XML_DESCRIPTION</description>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql"
charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql"
charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>

	<files folder="site">
		<filename>banners.php</filename>
		<filename>controller.php</filename>
		<filename>router.php</filename>
		<folder>helpers</folder>
		<folder>models</folder>
	</files>
	<administration>
		<menu img="class:banners">com_banners</menu>
		<submenu>
			<!--
				Note that all & must be escaped to &amp; for the file to be
valid
				XML and be parsed by the installer
			-->
			<menu
				link="option=com_banners"
				view="banners"
				img="class:banners"
				alt="Banners/Banners"
				>
				com_banners_banners
			</menu>
			<menu
				link="option=com_categories&amp;extension=com_banners"
				view="categories"
				img="class:banners-cat"
				alt="Banners/Categories"
				>
				com_banners_categories
			</menu>
			<menu
				link="option=com_banners&amp;view=clients"
				view="clients"
				img="class:banners-clients"
				alt="Banners/Clients"
				>
				com_banners_clients
			</menu>
			<menu
				link="option=com_banners&amp;view=tracks"
				view="tracks"
				img="class:banners-tracks"
				alt="Banners/Tracks"
				>
				com_banners_tracks
			</menu>
		</submenu>
		<files folder="admin">
			<filename>access.xml</filename>
			<filename>banners.php</filename>
			<filename>config.xml</filename>
			<filename>controller.php</filename>
			<folder>controllers</folder>
			<folder>helpers</folder>
			<folder>models</folder>
			<folder>tables</folder>
			<folder>views</folder>
		</files>
		<languages folder="admin">
			<language
tag="en-GB">language/en-GB.com_banners.ini</language>
			<language
tag="en-GB">language/en-GB.com_banners.sys.ini</language>
		</languages>
	</administration>
</extension>
config.xml000064400000005345151165563350006554 0ustar00<?xml
version="1.0" encoding="utf-8"?>
<config>
	<fieldset
		name="component"
		label="COM_BANNERS_FIELDSET_CONFIG_CLIENT_OPTIONS_LABEL"
		description="COM_BANNERS_FIELDSET_CONFIG_CLIENT_OPTIONS_DESC"
		>

		<field
			name="purchase_type"
			type="list"
			label="COM_BANNERS_FIELD_PURCHASETYPE_LABEL"
			description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
			id="purchase_type"
			default="1"
			>
			<option
value="1">COM_BANNERS_FIELD_VALUE_UNLIMITED</option>
			<option
value="2">COM_BANNERS_FIELD_VALUE_YEARLY</option>
			<option
value="3">COM_BANNERS_FIELD_VALUE_MONTHLY</option>
			<option
value="4">COM_BANNERS_FIELD_VALUE_WEEKLY</option>
			<option
value="5">COM_BANNERS_FIELD_VALUE_DAILY</option>
		</field>

		<field
			name="track_impressions"
			type="radio"
			label="COM_BANNERS_FIELD_TRACKIMPRESSION_LABEL"
			description="COM_BANNERS_FIELD_TRACKIMPRESSION_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="track_robots_impressions"
			type="radio"
			label="COM_BANNERS_FIELD_TRACKROBOTSIMPRESSION_LABEL"
			description="COM_BANNERS_FIELD_TRACKROBOTSIMPRESSION_DESC"
			class="btn-group btn-group-yesno"
			default="1"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="track_clicks"
			type="radio"
			label="COM_BANNERS_FIELD_TRACKCLICK_LABEL"
			description="COM_BANNERS_FIELD_TRACKCLICK_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="metakey_prefix"
			type="text"
			label="COM_BANNERS_FIELD_METAKEYWORDPREFIX_LABEL"
			description="COM_BANNERS_FIELD_METAKEYWORDPREFIX_DESC"
			default=""
		/>

	</fieldset>

	<fieldset
		name="banners"
		label="COM_BANNERS_FIELDSET_CONFIG_BANNER_OPTIONS_LABEL"
		description="COM_BANNERS_FIELDSET_CONFIG_BANNER_OPTIONS_DESC"
		>

		<field
			name="save_history"
			type="radio"
			label="JGLOBAL_SAVE_HISTORY_OPTIONS_LABEL"
			description="JGLOBAL_SAVE_HISTORY_OPTIONS_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="history_limit"
			type="number"
			label="JGLOBAL_HISTORY_LIMIT_OPTIONS_LABEL"
			description="JGLOBAL_HISTORY_LIMIT_OPTIONS_DESC"
			filter="integer"
			default="10"
			showon="save_history:1"
		/>

	</fieldset>

	<fieldset
		name="permissions"
		label="JCONFIG_PERMISSIONS_LABEL"
		description="JCONFIG_PERMISSIONS_DESC"
		>

		<field
			name="rules"
			type="rules"
			label="JCONFIG_PERMISSIONS_LABEL"
			filter="rules"
			validate="rules"
			component="com_banners"
			section="component"
		/>

	</fieldset>
</config>
controller.php000064400000001346151165563350007456 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Banners Controller
 *
 * @since  1.5
 */
class BannersController extends JControllerLegacy
{
	/**
	 * Method when a banner is clicked on.
	 *
	 * @return  void
	 *
	 * @since   1.5
	 */
	public function click()
	{
		$id = $this->input->getInt('id', 0);

		if ($id)
		{
			$model = $this->getModel('Banner',
'BannersModel', array('ignore_request' => true));
			$model->setState('banner.id', $id);
			$model->click();
			$this->setRedirect($model->getUrl());
		}
	}
}
controllers/banner.php000064400000005010151165563350011076 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
 * Banner controller class.
 *
 * @since  1.6
 */
class BannersControllerBanner extends JControllerForm
{
	/**
	 * The prefix to use with controller messages.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_BANNERS_BANNER';

	/**
	 * Method override to check if you can add a new record.
	 *
	 * @param   array  $data  An array of input data.
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	protected function allowAdd($data = array())
	{
		$filter     = $this->input->getInt('filter_category_id');
		$categoryId = ArrayHelper::getValue($data, 'catid', $filter,
'int');
		$allow      = null;

		if ($categoryId)
		{
			// If the category has been passed in the URL check it.
			$allow = JFactory::getUser()->authorise('core.create',
$this->option . '.category.' . $categoryId);
		}

		if ($allow !== null)
		{
			return $allow;
		}

		// In the absence of better information, revert to the component
permissions.
		return parent::allowAdd($data);
	}

	/**
	 * Method override to check if you can edit an existing record.
	 *
	 * @param   array   $data  An array of input data.
	 * @param   string  $key   The name of the key for the primary key.
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	protected function allowEdit($data = array(), $key = 'id')
	{
		$recordId   = (int) isset($data[$key]) ? $data[$key] : 0;
		$categoryId = 0;

		if ($recordId)
		{
			$categoryId = (int)
$this->getModel()->getItem($recordId)->catid;
		}

		if ($categoryId)
		{
			// The category has been set. Check the category permissions.
			return JFactory::getUser()->authorise('core.edit',
$this->option . '.category.' . $categoryId);
		}

		// Since there is no asset tracking, revert to the component permissions.
		return parent::allowEdit($data, $key);
	}

	/**
	 * Method to run batch operations.
	 *
	 * @param   string  $model  The model
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   2.5
	 */
	public function batch($model = null)
	{
		$this->checkToken();

		// Set the model
		$model = $this->getModel('Banner', '', array());

		// Preset the redirect
		$this->setRedirect(JRoute::_('index.php?option=com_banners&view=banners'
. $this->getRedirectToListAppend(), false));

		return parent::batch($model);
	}
}
controllers/banners.php000064400000004554151165563420011273
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
 * Banners list controller class.
 *
 * @since  1.6
 */
class BannersControllerBanners extends JControllerAdmin
{
	/**
	 * The prefix to use with controller messages.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_BANNERS_BANNERS';

	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration
settings.
	 *
	 * @see     JControllerLegacy
	 * @since   1.6
	 */
	public function __construct($config = array())
	{
		parent::__construct($config);

		$this->registerTask('sticky_unpublish',
'sticky_publish');
	}

	/**
	 * Method to get a model object, loading it if required.
	 *
	 * @param   string  $name    The model name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JModelLegacy  The model.
	 *
	 * @since   1.6
	 */
	public function getModel($name = 'Banner', $prefix =
'BannersModel', $config = array('ignore_request' =>
true))
	{
		return parent::getModel($name, $prefix, $config);
	}

	/**
	 * Stick items
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	public function sticky_publish()
	{
		// Check for request forgeries.
		$this->checkToken();

		$ids    = $this->input->get('cid', array(),
'array');
		$values = array('sticky_publish' => 1,
'sticky_unpublish' => 0);
		$task   = $this->getTask();
		$value  = ArrayHelper::getValue($values, $task, 0, 'int');

		if (empty($ids))
		{
			JError::raiseWarning(500,
JText::_('COM_BANNERS_NO_BANNERS_SELECTED'));
		}
		else
		{
			// Get the model.
			/** @var BannersModelBanner $model */
			$model = $this->getModel();

			// Change the state of the records.
			if (!$model->stick($ids, $value))
			{
				JError::raiseWarning(500, $model->getError());
			}
			else
			{
				if ($value == 1)
				{
					$ntext = 'COM_BANNERS_N_BANNERS_STUCK';
				}
				else
				{
					$ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK';
				}

				$this->setMessage(JText::plural($ntext, count($ids)));
			}
		}

		$this->setRedirect('index.php?option=com_banners&view=banners');
	}
}
controllers/client.php000064400000001027151165563420011111 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Client controller class.
 *
 * @since  1.6
 */
class BannersControllerClient extends JControllerForm
{
	/**
	 * The prefix to use with controller messages.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_BANNERS_CLIENT';
}
controllers/clients.php000064400000002014151165563420011271
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Clients list controller class.
 *
 * @since  1.6
 */
class BannersControllerClients extends JControllerAdmin
{
	/**
	 * The prefix to use with controller messages.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $text_prefix = 'COM_BANNERS_CLIENTS';

	/**
	 * Method to get a model object, loading it if required.
	 *
	 * @param   string  $name    The model name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JModelLegacy  The model.
	 *
	 * @since   1.6
	 */
	public function getModel($name = 'Client', $prefix =
'BannersModel', $config = array('ignore_request' =>
true))
	{
		return parent::getModel($name, $prefix, $config);
	}
}
controllers/tracks.php000064400000004401151165563420011121 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Tracks list controller class.
 *
 * @since  1.6
 */
class BannersControllerTracks extends JControllerLegacy
{
	/**
	 * The prefix to use with controller messages.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $context = 'com_banners.tracks';

	/**
	 * Method to get a model object, loading it if required.
	 *
	 * @param   string  $name    The model name. Optional.
	 * @param   string  $prefix  The class prefix. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JModelLegacy  The model.
	 *
	 * @since   1.6
	 */
	public function getModel($name = 'Tracks', $prefix =
'BannersModel', $config = array('ignore_request' =>
true))
	{
		return parent::getModel($name, $prefix, $config);
	}

	/**
	 * Method to remove a record.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	public function delete()
	{
		// Check for request forgeries.
		$this->checkToken();

		// Get the model.
		/** @var BannersModelTracks $model */
		$model = $this->getModel();

		// Load the filter state.
		$app = JFactory::getApplication();

		$model->setState('filter.type',
$app->getUserState($this->context . '.filter.type'));
		$model->setState('filter.begin',
$app->getUserState($this->context . '.filter.begin'));
		$model->setState('filter.end',
$app->getUserState($this->context . '.filter.end'));
		$model->setState('filter.category_id',
$app->getUserState($this->context .
'.filter.category_id'));
		$model->setState('filter.client_id',
$app->getUserState($this->context . '.filter.client_id'));
		$model->setState('list.limit', 0);
		$model->setState('list.start', 0);

		$count = $model->getTotal();

		// Remove the items.
		if (!$model->delete())
		{
			JError::raiseWarning(500, $model->getError());
		}
		elseif ($count > 0)
		{
			$this->setMessage(JText::plural('COM_BANNERS_TRACKS_N_ITEMS_DELETED',
$count));
		}
		else
		{
			$this->setMessage(JText::_('COM_BANNERS_TRACKS_NO_ITEMS_DELETED'));
		}

		$this->setRedirect('index.php?option=com_banners&view=tracks');
	}
}
controllers/tracks.raw.php000064400000006504151165563420011717
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Tracks list controller class.
 *
 * @since  1.6
 */
class BannersControllerTracks extends JControllerLegacy
{
	/**
	 * The context for persistent state.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $context = 'com_banners.tracks';

	/**
	 * Method to get a model object, loading it if required.
	 *
	 * @param   string  $name    The name of the model.
	 * @param   string  $prefix  The prefix for the model class name.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JModelLegacy
	 *
	 * @since   1.6
	 */
	public function getModel($name = 'Tracks', $prefix =
'BannersModel', $config = array())
	{
		return parent::getModel($name, $prefix, array('ignore_request'
=> true));
	}

	/**
	 * Display method for the raw track data.
	 *
	 * @param   boolean  $cachable   If true, the view output will be cached
	 * @param   array    $urlparams  An array of safe URL parameters and their
variable types, for valid values see {@link JFilterInput::clean()}.
	 *
	 * @return  BannersControllerTracks  This object to support chaining.
	 *
	 * @since   1.5
	 * @todo    This should be done as a view, not here!
	 */
	public function display($cachable = false, $urlparams = array())
	{
		// Get the document object.
		$vName = 'tracks';

		// Get and render the view.
		if ($view = $this->getView($vName, 'raw'))
		{
			// Get the model for the view.
			/** @var BannersModelTracks $model */
			$model = $this->getModel($vName);

			// Load the filter state.
			$app = JFactory::getApplication();

			$model->setState('filter.type',
$app->getUserState($this->context . '.filter.type'));
			$model->setState('filter.begin',
$app->getUserState($this->context . '.filter.begin'));
			$model->setState('filter.end',
$app->getUserState($this->context . '.filter.end'));
			$model->setState('filter.category_id',
$app->getUserState($this->context .
'.filter.category_id'));
			$model->setState('filter.client_id',
$app->getUserState($this->context . '.filter.client_id'));
			$model->setState('list.limit', 0);
			$model->setState('list.start', 0);

			$form = $this->input->get('jform', array(),
'array');

			$model->setState('basename', $form['basename']);
			$model->setState('compressed',
$form['compressed']);

			// Create one year cookies.
			$cookieLifeTime = time() + 365 * 86400;
			$cookieDomain   = $app->get('cookie_domain', '');
			$cookiePath     = $app->get('cookie_path', '/');
			$isHttpsForced  = $app->isHttpsForced();

			$app->input->cookie->set(
				JApplicationHelper::getHash($this->context . '.basename'),
				$form['basename'],
				$cookieLifeTime,
				$cookiePath,
				$cookieDomain,
				$isHttpsForced,
				true
			);

			$app->input->cookie->set(
				JApplicationHelper::getHash($this->context .
'.compressed'),
				$form['compressed'],
				$cookieLifeTime,
				$cookiePath,
				$cookieDomain,
				$isHttpsForced,
				true
			);

			// Push the model into the view (as default).
			$view->setModel($model, true);

			// Push document object into the view.
			$view->document = JFactory::getDocument();

			$view->display();
		}

		return $this;
	}
}
helpers/banners.php000064400000011155151165563420010362 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Banners component helper.
 *
 * @since  1.6
 */
class BannersHelper extends JHelperContent
{
	/**
	 * Configure the Linkbar.
	 *
	 * @param   string  $vName  The name of the active view.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	public static function addSubmenu($vName)
	{
		JHtmlSidebar::addEntry(
			JText::_('COM_BANNERS_SUBMENU_BANNERS'),
			'index.php?option=com_banners&view=banners',
			$vName == 'banners'
		);

		JHtmlSidebar::addEntry(
			JText::_('COM_BANNERS_SUBMENU_CATEGORIES'),
			'index.php?option=com_categories&extension=com_banners',
			$vName == 'categories'
		);

		JHtmlSidebar::addEntry(
			JText::_('COM_BANNERS_SUBMENU_CLIENTS'),
			'index.php?option=com_banners&view=clients',
			$vName == 'clients'
		);

		JHtmlSidebar::addEntry(
			JText::_('COM_BANNERS_SUBMENU_TRACKS'),
			'index.php?option=com_banners&view=tracks',
			$vName == 'tracks'
		);
	}

	/**
	 * Update / reset the banners
	 *
	 * @return  boolean
	 *
	 * @since   1.6
	 */
	public static function updateReset()
	{
		$db       = JFactory::getDbo();
		$nullDate = $db->getNullDate();
		$query    = $db->getQuery(true)
			->select('*')
			->from('#__banners')
			->where($db->quote(JFactory::getDate()) . ' >= ' .
$db->quote('reset'))
			->where($db->quoteName('reset') . ' != ' .
$db->quote($nullDate) . ' AND ' .
$db->quoteName('reset') . '!= NULL')
			->where(
				'(' . $db->quoteName('checked_out') . ' = 0
OR ' . $db->quoteName('checked_out') . ' = '
				. (int) $db->quote(JFactory::getUser()->id) . ')'
			);
		$db->setQuery($query);

		try
		{
			$rows = $db->loadObjectList();
		}
		catch (RuntimeException $e)
		{
			JError::raiseWarning(500, $e->getMessage());

			return false;
		}

		JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR .
'/tables');

		foreach ($rows as $row)
		{
			$purchaseType = $row->purchase_type;

			if ($purchaseType < 0 && $row->cid)
			{
				/** @var BannersTableClient $client */
				$client = JTable::getInstance('Client',
'BannersTable');
				$client->load($row->cid);
				$purchaseType = $client->purchase_type;
			}

			if ($purchaseType < 0)
			{
				$params = JComponentHelper::getParams('com_banners');
				$purchaseType = $params->get('purchase_type');
			}

			switch ($purchaseType)
			{
				case 1:
					$reset = $nullDate;
					break;
				case 2:
					$date = JFactory::getDate('+1 year ' .
date('Y-m-d'));
					$reset = $db->quote($date->toSql());
					break;
				case 3:
					$date = JFactory::getDate('+1 month ' .
date('Y-m-d'));
					$reset = $db->quote($date->toSql());
					break;
				case 4:
					$date = JFactory::getDate('+7 day ' .
date('Y-m-d'));
					$reset = $db->quote($date->toSql());
					break;
				case 5:
					$date = JFactory::getDate('+1 day ' .
date('Y-m-d'));
					$reset = $db->quote($date->toSql());
					break;
			}

			// Update the row ordering field.
			$query->clear()
				->update($db->quoteName('#__banners'))
				->set($db->quoteName('reset') . ' = ' .
$db->quote($reset))
				->set($db->quoteName('impmade') . ' = ' .
$db->quote(0))
				->set($db->quoteName('clicks') . ' = ' .
$db->quote(0))
				->where($db->quoteName('id') . ' = ' .
$db->quote($row->id));
			$db->setQuery($query);

			try
			{
				$db->execute();
			}
			catch (RuntimeException $e)
			{
				JError::raiseWarning(500, $db->getMessage());

				return false;
			}
		}

		return true;
	}

	/**
	 * Get client list in text/value format for a select field
	 *
	 * @return  array
	 */
	public static function getClientOptions()
	{
		$options = array();

		$db = JFactory::getDbo();
		$query = $db->getQuery(true)
			->select('id AS value, name AS text')
			->from('#__banner_clients AS a')
			->where('a.state = 1')
			->order('a.name');

		// Get the options.
		$db->setQuery($query);

		try
		{
			$options = $db->loadObjectList();
		}
		catch (RuntimeException $e)
		{
			JError::raiseWarning(500, $e->getMessage());
		}

		array_unshift($options, JHtml::_('select.option',
'0', JText::_('COM_BANNERS_NO_CLIENT')));

		return $options;
	}

	/**
	 * Adds Count Items for Category Manager.
	 *
	 * @param   stdClass[]  &$items  The category objects
	 *
	 * @return  stdClass[]
	 *
	 * @since   3.5
	 */
	public static function countItems(&$items)
	{
		$config = (object) array(
			'related_tbl'   => 'banners',
			'state_col'     => 'state',
			'group_col'     => 'catid',
			'relation_type' => 'category_or_group',
		);

		return parent::countRelations($items, $config);
	}
}
helpers/html/banner.php000064400000005350151165563420011143
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Banner HTML class.
 *
 * @since  2.5
 */
abstract class JHtmlBanner
{
	/**
	 * Display a batch widget for the client selector.
	 *
	 * @return  string  The necessary HTML for the widget.
	 *
	 * @since   2.5
	 */
	public static function clients()
	{
		JHtml::_('bootstrap.tooltip');

		// Create the batch selector to change the client on a selection list.
		return implode(
			"\n",
			array(
				'<label id="batch-client-lbl"
for="batch-client" class="hasTooltip"
title="'
					. JHtml::_('tooltipText',
'COM_BANNERS_BATCH_CLIENT_LABEL',
'COM_BANNERS_BATCH_CLIENT_LABEL_DESC')
					. '">',
				JText::_('COM_BANNERS_BATCH_CLIENT_LABEL'),
				'</label>',
				'<select name="batch[client_id]"
id="batch-client-id">',
				'<option value="">' .
JText::_('COM_BANNERS_BATCH_CLIENT_NOCHANGE') .
'</option>',
				'<option value="0">' .
JText::_('COM_BANNERS_NO_CLIENT') . '</option>',
				JHtml::_('select.options', static::clientlist(),
'value', 'text'),
				'</select>'
			)
		);
	}

	/**
	 * Method to get the field options.
	 *
	 * @return  array  The field option objects.
	 *
	 * @since   1.6
	 */
	public static function clientlist()
	{
		$db = JFactory::getDbo();
		$query = $db->getQuery(true)
			->select('id As value, name As text')
			->from('#__banner_clients AS a')
			->order('a.name');

		// Get the options.
		$db->setQuery($query);

		try
		{
			$options = $db->loadObjectList();
		}
		catch (RuntimeException $e)
		{
			JError::raiseWarning(500, $e->getMessage());
		}

		return $options;
	}

	/**
	 * Returns a pinned state on a grid
	 *
	 * @param   integer  $value     The state value.
	 * @param   integer  $i         The row index
	 * @param   boolean  $enabled   An optional setting for access control on
the action.
	 * @param   string   $checkbox  An optional prefix for checkboxes.
	 *
	 * @return  string   The Html code
	 *
	 * @see     JHtmlJGrid::state
	 * @since   2.5.5
	 */
	public static function pinned($value, $i, $enabled = true, $checkbox =
'cb')
	{
		$states = array(
			1 => array(
				'sticky_unpublish',
				'COM_BANNERS_BANNERS_PINNED',
				'COM_BANNERS_BANNERS_HTML_PIN_BANNER',
				'COM_BANNERS_BANNERS_PINNED',
				true,
				'publish',
				'publish'
			),
			0 => array(
				'sticky_publish',
				'COM_BANNERS_BANNERS_UNPINNED',
				'COM_BANNERS_BANNERS_HTML_UNPIN_BANNER',
				'COM_BANNERS_BANNERS_UNPINNED',
				true,
				'unpublish',
				'unpublish'
			),
		);

		return JHtml::_('jgrid.state', $states, $value, $i,
'banners.', $enabled, true, $checkbox);
	}
}
models/banner.php000064400000010126151165563420010015 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @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()->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;
	}
}
models/banners.php000064400000021035151165563420010201 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR .
'/tables');

/**
 * Banners model for the Joomla Banners component.
 *
 * @since  1.6
 */
class BannersModelBanners extends JModelList
{
	/**
	 * Method to get a store id based on model configuration state.
	 *
	 * This is necessary because the model is used by the component and
	 * different modules that might need different sets of data or different
	 * ordering requirements.
	 *
	 * @param   string  $id  A prefix for the store id.
	 *
	 * @return  string  A store id.
	 *
	 * @since   1.6
	 */
	protected function getStoreId($id = '')
	{
		// Compile the store id.
		$id .= ':' . $this->getState('filter.search');
		$id .= ':' . $this->getState('filter.tag_search');
		$id .= ':' . $this->getState('filter.client_id');
		$id .= ':' .
serialize($this->getState('filter.category_id'));
		$id .= ':' .
serialize($this->getState('filter.keywords'));

		return parent::getStoreId($id);
	}

	/**
	 * Method to get a JDatabaseQuery object for retrieving the data set from
a database.
	 *
	 * @return  JDatabaseQuery   A JDatabaseQuery object to retrieve the data
set.
	 *
	 * @since   1.6
	 */
	protected function getListQuery()
	{
		$db         = $this->getDbo();
		$query      = $db->getQuery(true);
		$ordering   = $this->getState('filter.ordering');
		$tagSearch  = $this->getState('filter.tag_search');
		$cid        = $this->getState('filter.client_id');
		$categoryId = $this->getState('filter.category_id');
		$keywords   = $this->getState('filter.keywords');
		$randomise  = ($ordering === 'random');
		$nullDate   = $db->quote($db->getNullDate());
		$nowDate    = $db->quote(JFactory::getDate()->toSql());

		$query->select(
			'a.id as id,'
				. 'a.type as type,'
				. 'a.name as name,'
				. 'a.clickurl as clickurl,'
				. 'a.cid as cid,'
				. 'a.description as description,'
				. 'a.params as params,'
				. 'a.custombannercode as custombannercode,'
				. 'a.track_impressions as track_impressions,'
				. 'cl.track_impressions as client_track_impressions'
		)
			->from('#__banners as a')
			->join('LEFT', '#__banner_clients AS cl ON cl.id =
a.cid')
			->where('a.state=1')
			->where('(a.publish_up = ' . $nullDate . ' OR
a.publish_up <= ' . $nowDate . ')')
			->where('(a.publish_down = ' . $nullDate . ' OR
a.publish_down >= ' . $nowDate . ')')
			->where('(a.imptotal = 0 OR a.impmade < a.imptotal)');

		if ($cid)
		{
			$query->where('a.cid = ' . (int) $cid)
				->where('cl.state = 1');
		}

		// Filter by a single or group of categories
		if (is_numeric($categoryId))
		{
			$type = $this->getState('filter.category_id.include', true)
? '= ' : '<> ';

			// Add subcategory check
			$includeSubcategories =
$this->getState('filter.subcategories', false);
			$categoryEquals = 'a.catid ' . $type . (int) $categoryId;

			if ($includeSubcategories)
			{
				$levels = (int)
$this->getState('filter.max_category_levels', '1');

				// Create a subquery for the subcategory list
				$subQuery = $db->getQuery(true);
				$subQuery->select('sub.id')
					->from('#__categories as sub')
					->join('INNER', '#__categories as this ON sub.lft
> this.lft AND sub.rgt < this.rgt')
					->where('this.id = ' . (int) $categoryId)
					->where('sub.level <= this.level + ' . $levels);

				// Add the subquery to the main query
				$query->where('(' . $categoryEquals . ' OR a.catid IN
(' . (string) $subQuery . '))');
			}
			else
			{
				$query->where($categoryEquals);
			}
		}
		elseif (is_array($categoryId) && (count($categoryId) > 0))
		{
			$categoryId = ArrayHelper::toInteger($categoryId);
			$categoryId = implode(',', $categoryId);

			if ($categoryId != '0')
			{
				$type = $this->getState('filter.category_id.include',
true) ? 'IN' : 'NOT IN';
				$query->where('a.catid ' . $type . ' (' .
$categoryId . ')');
			}
		}

		if ($tagSearch)
		{
			if (!$keywords)
			{
				$query->where('0 != 0');
			}
			else
			{
				$temp   = array();
				$config = JComponentHelper::getParams('com_banners');
				$prefix = $config->get('metakey_prefix');

				if ($categoryId)
				{
					$query->join('LEFT', '#__categories as cat ON
a.catid = cat.id');
				}

				foreach ($keywords as $keyword)
				{
					$condition1 = 'a.own_prefix=1 '
						. ' AND a.metakey_prefix=SUBSTRING(' .
$db->quote($keyword) . ',1,LENGTH( a.metakey_prefix)) '
						. ' OR a.own_prefix=0 '
						. ' AND cl.own_prefix=1 '
						. ' AND cl.metakey_prefix=SUBSTRING(' .
$db->quote($keyword) . ',1,LENGTH(cl.metakey_prefix)) '
						. ' OR a.own_prefix=0 '
						. ' AND cl.own_prefix=0 '
						. ' AND ' . ($prefix == substr($keyword, 0,
strlen($prefix)) ? '0 = 0' : '0 != 0');

					$regexp = $db->quote("[[:<:]]" .
$db->escape($keyword) . "[[:>:]]");
					$condition2 = "a.metakey " . $query->regexp($regexp) .
" ";

					if ($cid)
					{
						$condition2 .= " OR cl.metakey " .
$query->regexp($regexp) . " ";
					}

					if ($categoryId)
					{
						$condition2 .= " OR cat.metakey " .
$query->regexp($regexp) . " ";
					}

					$temp[] = "($condition1) AND ($condition2)";
				}

				$query->where('(' . implode(' OR ', $temp) .
')');
			}
		}

		// Filter by language
		if ($this->getState('filter.language'))
		{
			$query->where('a.language in (' .
$db->quote(JFactory::getLanguage()->getTag()) . ',' .
$db->quote('*') . ')');
		}

		$query->order('a.sticky DESC,' . ($randomise ?
$query->Rand() : 'a.ordering'));

		return $query;
	}

	/**
	 * Get a list of banners.
	 *
	 * @return  array
	 *
	 * @since   1.6
	 */
	public function getItems()
	{
		if ($this->getState('filter.tag_search'))
		{
			// Filter out empty keywords.
			$keywords = array_values(array_filter(array_map('trim',
$this->getState('filter.keywords')), 'strlen'));

			// Re-set state before running the query.
			$this->setState('filter.keywords', $keywords);

			// If no keywords are provided, avoid running the query.
			if (!$keywords)
			{
				$this->cache['items'] = array();

				return $this->cache['items'];
			}
		}

		if (!isset($this->cache['items']))
		{
			$this->cache['items'] = parent::getItems();

			foreach ($this->cache['items'] as &$item)
			{
				$item->params = new Registry($item->params);
			}
		}

		return $this->cache['items'];
	}

	/**
	 * Makes impressions on a list of banners
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	public function impress()
	{
		$trackDate = JFactory::getDate()->toSql();
		$items     = $this->getItems();
		$db        = $this->getDbo();
		$query     = $db->getQuery(true);

		if (!count($items))
		{
			return;
		}

		foreach ($items as $item)
		{
			$bid[] = (int) $item->id;
		}

		// Increment impression made
		$query->clear()
			->update('#__banners')
			->set('impmade = (impmade + 1)')
			->where('id IN (' . implode(',', $bid) .
')');
		$db->setQuery($query);

		try
		{
			$db->execute();
		}
		catch (JDatabaseExceptionExecuting $e)
		{
			JError::raiseError(500, $e->getMessage());
		}

		foreach ($items as $item)
		{
			// Track impressions
			$trackImpressions = $item->track_impressions;

			if ($trackImpressions < 0 && $item->cid)
			{
				$trackImpressions = $item->client_track_impressions;
			}

			if ($trackImpressions < 0)
			{
				$config           =
JComponentHelper::getParams('com_banners');
				$trackImpressions = $config->get('track_impressions');
			}

			if ($trackImpressions > 0)
			{
				// Is track already created?
				// Update count
				$query->clear();
				$query->update('#__banner_tracks')
					->set($db->quoteName('count') . ' = (' .
$db->quoteName('count') . ' + 1)')
					->where('track_type=1')
					->where('banner_id=' . (int) $item->id)
					->where('track_date=' . $db->quote($trackDate));

				$db->setQuery($query);

				try
				{
					$db->execute();
				}
				catch (JDatabaseExceptionExecuting $e)
				{
					JError::raiseError(500, $e->getMessage());
				}

				if ($db->getAffectedRows() === 0)
				{
					// Insert new count
					$query->clear();

					$query->insert('#__banner_tracks')
						->columns(
							array(
								$db->quoteName('count'),
$db->quoteName('track_type'),
								$db->quoteName('banner_id'),
$db->quoteName('track_date')
							)
						)
						->values('1, 1, ' . (int) $item->id . ', '
. $db->quote($trackDate));

					$db->setQuery($query);

					try
					{
						$db->execute();
					}
					catch (JDatabaseExceptionExecuting $e)
					{
						JError::raiseError(500, $e->getMessage());
					}
				}
			}
		}
	}
}
models/client.php000064400000006537151165563420010041 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Client model.
 *
 * @since  1.6
 */
class BannersModelClient extends JModelAdmin
{
	/**
	 * The type alias for this content type.
	 *
	 * @var    string
	 * @since  3.2
	 */
	public $typeAlias = 'com_banners.client';

	/**
	 * Method to test whether a record can be deleted.
	 *
	 * @param   object  $record  A record object.
	 *
	 * @return  boolean  True if allowed to delete the record. Defaults to the
permission set in the component.
	 *
	 * @since   1.6
	 */
	protected function canDelete($record)
	{
		if (empty($record->id) || $record->state != -2)
		{
			return false;
		}

		if (!empty($record->catid))
		{
			return JFactory::getUser()->authorise('core.delete',
'com_banners.category.' . (int) $record->catid);
		}

		return parent::canDelete($record);
	}

	/**
	 * Method to test whether a record can have its state changed.
	 *
	 * @param   object  $record  A record object.
	 *
	 * @return  boolean  True if allowed to change the state of the record.
	 *                   Defaults to the permission set in the component.
	 *
	 * @since   1.6
	 */
	protected function canEditState($record)
	{
		$user = JFactory::getUser();

		if (!empty($record->catid))
		{
			return $user->authorise('core.edit.state',
'com_banners.category.' . (int) $record->catid);
		}

		return $user->authorise('core.edit.state',
'com_banners');
	}

	/**
	 * Returns a reference to the a Table object, always creating it.
	 *
	 * @param   string  $type    The table type to instantiate
	 * @param   string  $prefix  A prefix for the table class name. Optional.
	 * @param   array   $config  Configuration array for model. Optional.
	 *
	 * @return  JTable	A JTable object
	 *
	 * @since   1.6
	 */
	public function getTable($type = 'Client', $prefix =
'BannersTable', $config = array())
	{
		return JTable::getInstance($type, $prefix, $config);
	}

	/**
	 * Method to get the record form.
	 *
	 * @param   array    $data      Data for the form.
	 * @param   boolean  $loadData  True if the form is to load its own data
(default case), false if not.
	 *
	 * @return  JForm|boolean  A JForm object on success, false on failure
	 *
	 * @since   1.6
	 */
	public function getForm($data = array(), $loadData = true)
	{
		// Get the form.
		$form = $this->loadForm('com_banners.client',
'client', array('control' => 'jform',
'load_data' => $loadData));

		if (empty($form))
		{
			return false;
		}

		return $form;
	}

	/**
	 * Method to get the data that should be injected in the form.
	 *
	 * @return  mixed  The data for the form.
	 *
	 * @since   1.6
	 */
	protected function loadFormData()
	{
		// Check the session for previously entered form data.
		$data =
JFactory::getApplication()->getUserState('com_banners.edit.client.data',
array());

		if (empty($data))
		{
			$data = $this->getItem();
		}

		$this->preprocessData('com_banners.client', $data);

		return $data;
	}

	/**
	 * Prepare and sanitise the table prior to saving.
	 *
	 * @param   JTable  $table  A JTable object.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function prepareTable($table)
	{
		$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
	}
}
models/clients.php000064400000017231151165563420010215 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
 * Methods supporting a list of banner records.
 *
 * @since  1.6
 */
class BannersModelClients extends JModelList
{
	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration
settings.
	 *
	 * @see     JControllerLegacy
	 * @since   1.6
	 */
	public function __construct($config = array())
	{
		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
				'id', 'a.id',
				'name', 'a.name',
				'contact', 'a.contact',
				'state', 'a.state',
				'checked_out', 'a.checked_out',
				'checked_out_time', 'a.checked_out_time',
				'purchase_type', 'a.purchase_type'
			);
		}

		parent::__construct($config);
	}

	/**
	 * Method to auto-populate the model state.
	 *
	 * Note. Calling getState in this method will result in recursion.
	 *
	 * @param   string  $ordering   An optional ordering field.
	 * @param   string  $direction  An optional direction (asc|desc).
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function populateState($ordering = 'a.name',
$direction = 'asc')
	{
		// Load the filter state.
		$this->setState('filter.search',
$this->getUserStateFromRequest($this->context .
'.filter.search', 'filter_search', '',
'string'));
		$this->setState('filter.state',
$this->getUserStateFromRequest($this->context .
'.filter.state', 'filter_state', '',
'string'));
		$this->setState('filter.purchase_type',
$this->getUserStateFromRequest($this->context .
'.filter.purchase_type', 'filter_purchase_type'));

		// Load the parameters.
		$this->setState('params',
JComponentHelper::getParams('com_banners'));

		// List state information.
		parent::populateState($ordering, $direction);
	}

	/**
	 * Method to get a store id based on model configuration state.
	 *
	 * This is necessary because the model is used by the component and
	 * different modules that might need different sets of data or different
	 * ordering requirements.
	 *
	 * @param   string  $id  A prefix for the store id.
	 *
	 * @return  string  A store id.
	 */
	protected function getStoreId($id = '')
	{
		// Compile the store id.
		$id .= ':' . $this->getState('filter.search');
		$id .= ':' . $this->getState('filter.state');
		$id .= ':' .
$this->getState('filter.purchase_type');

		return parent::getStoreId($id);
	}

	/**
	 * Build an SQL query to load the list data.
	 *
	 * @return  JDatabaseQuery
	 */
	protected function getListQuery()
	{
		// Create a new query object.
		$db    = $this->getDbo();
		$query = $db->getQuery(true);

		$defaultPurchase =
JComponentHelper::getParams('com_banners')->get('purchase_type',
3);

		// Select the required fields from the table.
		$query->select(
			$this->getState(
				'list.select',
				'a.id AS id,'
				. 'a.name AS name,'
				. 'a.contact AS contact,'
				. 'a.checked_out AS checked_out,'
				. 'a.checked_out_time AS checked_out_time, '
				. 'a.state AS state,'
				. 'a.metakey AS metakey,'
				. 'a.purchase_type as purchase_type'
			)
		);

		$query->from($db->quoteName('#__banner_clients') . '
AS a');

		// Join over the banners for counting
		$query->select('COUNT(b.id) as nbanners')
			->join('LEFT', '#__banners AS b ON a.id =
b.cid');

		// Join over the users for the checked out user.
		$query->select('uc.name AS editor')
			->join('LEFT', '#__users AS uc ON
uc.id=a.checked_out');

		// Filter by published state
		$published = $this->getState('filter.state');

		if (is_numeric($published))
		{
			$query->where('a.state = ' . (int) $published);
		}
		elseif ($published === '')
		{
			$query->where('(a.state IN (0, 1))');
		}

		$query->group('a.id, a.name, a.contact, a.checked_out,
a.checked_out_time, a.state, a.metakey, a.purchase_type, uc.name');

		// Filter by search in title
		$search = $this->getState('filter.search');

		if (!empty($search))
		{
			if (stripos($search, 'id:') === 0)
			{
				$query->where('a.id = ' . (int) substr($search, 3));
			}
			else
			{
				$search = $db->quote('%' . str_replace(' ',
'%', $db->escape(trim($search), true) . '%'));
				$query->where('a.name LIKE ' . $search);
			}
		}

		// Filter by purchase type
		$purchaseType = $this->getState('filter.purchase_type');

		if (!empty($purchaseType))
		{
			if ($defaultPurchase == $purchaseType)
			{
				$query->where('(a.purchase_type = ' . (int) $purchaseType
. ' OR a.purchase_type = -1)');
			}
			else
			{
				$query->where('a.purchase_type = ' . (int) $purchaseType);
			}
		}

		// Add the list ordering clause.
		$query->order($db->escape($this->getState('list.ordering',
'a.name')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));

		return $query;
	}

	/**
	 * Overrides the getItems method to attach additional metrics to the list.
	 *
	 * @return  mixed  An array of data items on success, false on failure.
	 *
	 * @since   3.6
	 */
	public function getItems()
	{
		// Get a storage key.
		$store = $this->getStoreId('getItems');

		// Try to load the data from internal storage.
		if (!empty($this->cache[$store]))
		{
			return $this->cache[$store];
		}

		// Load the list items.
		$items = parent::getItems();

		// If empty or an error, just return.
		if (empty($items))
		{
			return array();
		}

		// Getting the following metric by joins is WAY TOO SLOW.
		// Faster to do three queries for very large banner trees.

		// Get the clients in the list.
		$db = $this->getDbo();
		$clientIds = ArrayHelper::getColumn($items, 'id');

		// Quote the strings.
		$clientIds = implode(
			',',
			array_map(array($db, 'quote'), $clientIds)
		);

		// Get the published banners count.
		$query = $db->getQuery(true)
			->select('cid, COUNT(cid) AS count_published')
			->from('#__banners')
			->where('state = 1')
			->where('cid IN (' . $clientIds . ')')
			->group('cid');

		$db->setQuery($query);

		try
		{
			$countPublished = $db->loadAssocList('cid',
'count_published');
		}
		catch (RuntimeException $e)
		{
			$this->setError($e->getMessage());

			return false;
		}

		// Get the unpublished banners count.
		$query->clear('where')
			->where('state = 0')
			->where('cid IN (' . $clientIds . ')');
		$db->setQuery($query);

		try
		{
			$countUnpublished = $db->loadAssocList('cid',
'count_published');
		}
		catch (RuntimeException $e)
		{
			$this->setError($e->getMessage());

			return false;
		}

		// Get the trashed banners count.
		$query->clear('where')
			->where('state = -2')
			->where('cid IN (' . $clientIds . ')');
		$db->setQuery($query);

		try
		{
			$countTrashed = $db->loadAssocList('cid',
'count_published');
		}
		catch (RuntimeException $e)
		{
			$this->setError($e->getMessage());

			return false;
		}

		// Get the archived banners count.
		$query->clear('where')
			->where('state = 2')
			->where('cid IN (' . $clientIds . ')');
		$db->setQuery($query);

		try
		{
			$countArchived = $db->loadAssocList('cid',
'count_published');
		}
		catch (RuntimeException $e)
		{
			$this->setError($e->getMessage());

			return false;
		}

		// Inject the values back into the array.
		foreach ($items as $item)
		{
			$item->count_published   = isset($countPublished[$item->id]) ?
$countPublished[$item->id] : 0;
			$item->count_unpublished = isset($countUnpublished[$item->id]) ?
$countUnpublished[$item->id] : 0;
			$item->count_trashed     = isset($countTrashed[$item->id]) ?
$countTrashed[$item->id] : 0;
			$item->count_archived    = isset($countArchived[$item->id]) ?
$countArchived[$item->id] : 0;
		}

		// Add the items to the internal cache.
		$this->cache[$store] = $items;

		return $this->cache[$store];
	}
}
models/download.php000064400000003611151165563420010360 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Download model.
 *
 * @since  1.5
 */
class BannersModelDownload extends JModelForm
{
	/**
	 * The model context
	 *
	 * @var  string
	 */
	protected $_context = 'com_banners.tracks';

	/**
	 * Auto-populate the model state.
	 *
	 * Note. Calling getState in this method will result in recursion.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function populateState()
	{
		$input = JFactory::getApplication()->input;

		$this->setState('basename',
$input->cookie->getString(JApplicationHelper::getHash($this->_context
. '.basename'), '__SITE__'));
		$this->setState('compressed',
$input->cookie->getInt(JApplicationHelper::getHash($this->_context
. '.compressed'), 1));
	}

	/**
	 * Method to get the record form.
	 *
	 * @param   array    $data      Data for the form.
	 * @param   boolean  $loadData  True if the form is to load its own data
(default case), false if not.
	 *
	 * @return  JForm|boolean  A JForm object on success, false on failure
	 *
	 * @since   1.6
	 */
	public function getForm($data = array(), $loadData = true)
	{
		// Get the form.
		$form = $this->loadForm('com_banners.download',
'download', array('control' => 'jform',
'load_data' => $loadData));

		if (empty($form))
		{
			return false;
		}

		return $form;
	}

	/**
	 * Method to get the data that should be injected in the form.
	 *
	 * @return  mixed  The data for the form.
	 *
	 * @since   1.6
	 */
	protected function loadFormData()
	{
		$data = (object) array(
			'basename'   => $this->getState('basename'),
			'compressed' => $this->getState('compressed'),
		);

		$this->preprocessData('com_banners.download', $data);

		return $data;
	}
}
models/fields/bannerclient.php000064400000001546151165563430012471
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

JFormHelper::loadFieldClass('list');

/**
 * Bannerclient field.
 *
 * @since  1.6
 */
class JFormFieldBannerClient extends JFormFieldList
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $type = 'BannerClient';

	/**
	 * Method to get the field options.
	 *
	 * @return  array  The field option objects.
	 *
	 * @since   1.6
	 */
	public function getOptions()
	{
		return array_merge(parent::getOptions(),
BannersHelper::getClientOptions());
	}
}
models/fields/clicks.php000064400000002037151165563430011271
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Clicks field.
 *
 * @since  1.6
 */
class JFormFieldClicks extends JFormField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $type = 'Clicks';

	/**
	 * Method to get the field input markup.
	 *
	 * @return  string	The field input markup.
	 *
	 * @since   1.6
	 */
	protected function getInput()
	{
		$onclick = ' onclick="document.getElementById(\'' .
$this->id . '\').value=\'0\';"';

		return '<input class="input-small"
type="text" name="' . $this->name . '"
id="' . $this->id . '" value="'
			. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'" readonly="readonly" /> <a
class="btn" ' . $onclick . '>'
			. '<span class="icon-refresh"
aria-hidden="true"></span> ' .
JText::_('COM_BANNERS_RESET_CLICKS') . '</a>';
	}
}
models/fields/impmade.php000064400000002047151165563430011436
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Impressions field.
 *
 * @since  1.6
 */
class JFormFieldImpMade extends JFormField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $type = 'ImpMade';

	/**
	 * Method to get the field input markup.
	 *
	 * @return  string	The field input markup.
	 *
	 * @since   1.6
	 */
	protected function getInput()
	{
		$onclick = ' onclick="document.getElementById(\'' .
$this->id . '\').value=\'0\';"';

		return '<input class="input-small"
type="text" name="' . $this->name . '"
id="' . $this->id . '" value="'
			. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
'" readonly="readonly" /> <a
class="btn" ' . $onclick . '>'
			. '<span class="icon-refresh"
aria-hidden="true"></span> ' .
JText::_('COM_BANNERS_RESET_IMPMADE') . '</a>';
	}
}
models/fields/imptotal.php000064400000003063151165563430011652
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Total Impressions field.
 *
 * @since  1.6
 */
class JFormFieldImpTotal extends JFormField
{
	/**
	 * The form field type.
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $type = 'ImpTotal';

	/**
	 * Method to get the field input markup.
	 *
	 * @return  string	The field input markup.
	 *
	 * @since   1.6
	 */
	protected function getInput()
	{
		$class    = ' class="validate-numeric text_area"';
		$onchange = ' onchange="document.getElementById(\'' .
$this->id .
'_unlimited\').checked=document.getElementById(\'' .
$this->id
			. '\').value==\'\';"';
		$onclick  = ' onclick="if
(document.getElementById(\'' . $this->id .
'_unlimited\').checked) document.getElementById(\'' .
$this->id
			. '\').value=\'\';"';
		$value    = empty($this->value) ? '' : $this->value;
		$checked  = empty($this->value) ? '
checked="checked"' : '';

		return '<input type="text" name="' .
$this->name . '" id="' . $this->id . '"
size="9" value="' . htmlspecialchars($value,
ENT_COMPAT, 'UTF-8')
			. '" ' . $class . $onchange . ' />'
			. '<fieldset class="checkbox
impunlimited"><input id="' . $this->id .
'_unlimited" type="checkbox"' . $checked .
$onclick . ' />'
			. '<label for="' . $this->id .
'_unlimited" id="jform-imp"
type="text">' .
JText::_('COM_BANNERS_UNLIMITED') .
'</label></fieldset>';
	}
}
models/forms/banner.xml000064400000020526151165563430011162
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>
	<fieldset name="details"
addfieldpath="/administrator/components/com_banners/models/fields">

		<field
			name="id"
			type="number"
			label="JGLOBAL_FIELD_ID_LABEL"
			description="JGLOBAL_FIELD_ID_DESC"
			default="0"
			readonly="true"
			class="readonly"
		/>

		<field
			name="name"
			type="text"
			label="COM_BANNERS_FIELD_NAME_LABEL"
			description="COM_BANNERS_FIELD_NAME_DESC"
			class="input-xxlarge input-large-text"
			size="40"
			required="true"
		/>

		<field
			name="alias"
			type="text"
			label="JFIELD_ALIAS_LABEL"
			description="COM_BANNERS_FIELD_ALIAS_DESC"
			size="40"
			hint="JFIELD_ALIAS_PLACEHOLDER"
		/>

		<field
			name="catid"
			type="categoryedit"
			label="JCATEGORY"
			description="COM_BANNERS_FIELD_CATEGORY_DESC"
			extension="com_banners"
			required="true"
			addfieldpath="/administrator/components/com_categories/models/fields"
			default=""
		/>

		<field
			name="state"
			type="list"
			label="JSTATUS"
			description="COM_BANNERS_FIELD_STATE_DESC"
			class="chzn-color-state"
			size="1"
			default="1"
			>
			<option value="1">JPUBLISHED</option>
			<option value="0">JUNPUBLISHED</option>
			<option value="2">JARCHIVED</option>
			<option value="-2">JTRASHED</option>
		</field>

		<field
			name="ordering"
			type="ordering"
			label="JFIELD_ORDERING_LABEL"
			description="JFIELD_ORDERING_DESC"
			table="#__banners"
		/>

		<field
			name="language"
			type="contentlanguage"
			label="JFIELD_LANGUAGE_LABEL"
			description="COM_BANNERS_FIELD_LANGUAGE_DESC"
			>
			<option value="*">JALL</option>
		</field>

		<field
			name="version_note"
			type="text"
			label="JGLOBAL_FIELD_VERSION_NOTE_LABEL"
			description="JGLOBAL_FIELD_VERSION_NOTE_DESC"
			maxlength="255"
			class="span12"
			size="45"
			labelclass="control-label"
		/>

		<field
			name="description"
			type="editor"
			label="JGLOBAL_DESCRIPTION"
			description="COM_BANNERS_FIELD_DESCRIPTION_DESC"
			filter="JComponentHelper::filterText"
			buttons="true"
			hide="readmore,pagebreak,module,article,contact,menu"
		/>

		<field
			name="type"
			type="list"
			label="COM_BANNERS_FIELD_TYPE_LABEL"
			description="COM_BANNERS_FIELD_TYPE_DESC"
			default="0"
			>
			<option
value="0">COM_BANNERS_FIELD_VALUE_IMAGE</option>
			<option
value="1">COM_BANNERS_FIELD_VALUE_CUSTOM</option>
		</field>

		<field
			name="custombannercode"
			type="textarea"
			label="COM_BANNERS_FIELD_CUSTOMCODE_LABEL"
			description="COM_BANNERS_FIELD_CUSTOMCODE_DESC"
			rows="3"
			cols="30"
			filter="raw"
		/>

		<field
			name="clickurl"
			type="url"
			label="COM_BANNERS_FIELD_CLICKURL_LABEL"
			description="COM_BANNERS_FIELD_CLICKURL_DESC"
			filter="url"
			validate="url"
		/>
	</fieldset>

	<fieldset name="publish"
label="COM_BANNERS_GROUP_LABEL_PUBLISHING_DETAILS">

		<field
			name="created"
			type="calendar"
			label="COM_BANNERS_FIELD_CREATED_LABEL"
			description="COM_BANNERS_FIELD_CREATED_DESC"
			size="22"
			translateformat="true"
			showtime="true"
			filter="user_utc"
		/>

		<field
			name="created_by"
			type="user"
			label="COM_BANNERS_FIELD_CREATED_BY_LABEL"
			description="COM_BANNERS_FIELD_CREATED_BY_DESC"
		/>

		<field
			name="created_by_alias"
			type="text"
			label="COM_BANNERS_FIELD_CREATED_BY_ALIAS_LABEL"
			description="COM_BANNERS_FIELD_CREATED_BY_ALIAS_DESC"
			size="20"
		/>

		<field
			name="modified"
			type="calendar"
			label="JGLOBAL_FIELD_MODIFIED_LABEL"
			description="COM_BANNERS_FIELD_MODIFIED_DESC"
			class="readonly"
			size="22"
			readonly="true"
			translateformat="true"
			showtime="true"
			filter="user_utc"
		/>

		<field
			name="modified_by"
			type="user"
			label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
			description="COM_BANNERS_FIELD_MODIFIED_BY_DESC"
			class="readonly"
			readonly="true"
			filter="unset"
		/>

		<field
			name="version"
			type="text"
			label="COM_BANNERS_FIELD_VERSION_LABEL"
			description="COM_BANNERS_FIELD_VERSION_DESC"
			class="readonly"
			size="6"
			readonly="true"
			filter="unset"
		/>

		<field
			name="publish_up"
			type="calendar"
			label="COM_BANNERS_FIELD_PUBLISH_UP_LABEL"
			description="COM_BANNERS_FIELD_PUBLISH_UP_DESC"
			translateformat="true"
			showtime="true"
			size="22"
			filter="user_utc"
		/>

		<field
			name="publish_down"
			type="calendar"
			label="COM_BANNERS_FIELD_PUBLISH_DOWN_LABEL"
			description="COM_BANNERS_FIELD_PUBLISH_DOWN_DESC"
			translateformat="true"
			showtime="true"
			size="22"
			filter="user_utc"
		/>
	</fieldset>

	<fieldset name="bannerdetails"
label="COM_BANNERS_GROUP_LABEL_BANNER_DETAILS">

		<field
			name="sticky"
			type="radio"
			label="COM_BANNERS_FIELD_STICKY_LABEL"
			description="COM_BANNERS_FIELD_STICKY_DESC"
			default="0"
			class="btn-group btn-group-yesno"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>
	</fieldset>

	<fieldset name="otherparams">
		<field
			name="imptotal"
			type="imptotal"
			label="COM_BANNERS_FIELD_IMPTOTAL_LABEL"
			description="COM_BANNERS_FIELD_IMPTOTAL_DESC"
			default="0"
		/>

		<field
			name="impmade"
			type="impmade"
			label="COM_BANNERS_FIELD_IMPMADE_LABEL"
			description="COM_BANNERS_FIELD_IMPMADE_DESC"
			default="0"
		/>

		<field
			name="clicks"
			type="clicks"
			label="COM_BANNERS_FIELD_CLICKS_LABEL"
			description="COM_BANNERS_FIELD_CLICKS_DESC"
			default="0"
		/>

		<field
			name="cid"
			type="bannerclient"
			label="COM_BANNERS_FIELD_CLIENT_LABEL"
			description="COM_BANNERS_FIELD_CLIENT_DESC"
		/>

		<field
			name="purchase_type"
			type="list"
			label="COM_BANNERS_FIELD_PURCHASETYPE_LABEL"
			description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
			default="0"
			>
			<option
value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT</option>
			<option
value="1">COM_BANNERS_FIELD_VALUE_UNLIMITED</option>
			<option
value="2">COM_BANNERS_FIELD_VALUE_YEARLY</option>
			<option
value="3">COM_BANNERS_FIELD_VALUE_MONTHLY</option>
			<option
value="4">COM_BANNERS_FIELD_VALUE_WEEKLY</option>
			<option
value="5">COM_BANNERS_FIELD_VALUE_DAILY</option>
		</field>

		<field
			name="track_impressions"
			type="list"
			label="COM_BANNERS_FIELD_TRACKIMPRESSION_LABEL"
			description="COM_BANNERS_FIELD_TRACKIMPRESSION_DESC"
			default="0"
			>
			<option
value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT</option>
			<option value="0">JNO</option>
			<option value="1">JYES</option>
		</field>

		<field
			name="track_clicks"
			type="list"
			label="COM_BANNERS_FIELD_TRACKCLICK_LABEL"
			description="COM_BANNERS_FIELD_TRACKCLICK_DESC"
			default="0"
			>
			<option
value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT</option>
			<option value="0">JNO</option>
			<option value="1">JYES</option>
		</field>
	</fieldset>

	<fieldset name="metadata"
label="JGLOBAL_FIELDSET_METADATA_OPTIONS">

		<field
			name="metakey"
			type="textarea"
			label="JFIELD_META_KEYWORDS_LABEL"
			description="COM_BANNERS_FIELD_METAKEYWORDS_DESC"
			rows="3"
			cols="30"
		/>

		<field
			name="own_prefix"
			type="radio"
			label="COM_BANNERS_FIELD_BANNEROWNPREFIX_LABEL"
			description="COM_BANNERS_FIELD_BANNEROWNPREFIX_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="metakey_prefix"
			type="text"
			label="COM_BANNERS_FIELD_METAKEYWORDPREFIX_LABEL"
			description="COM_BANNERS_FIELD_METAKEYWORDPREFIX_DESC"
		/>
	</fieldset>

	<fields name="params"
label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS">
		<fieldset name="image">
			<field
				name="imageurl"
				type="media"
				label="COM_BANNERS_FIELD_IMAGE_LABEL"
				description="COM_BANNERS_FIELD_IMAGE_DESC"
				directory="banners"
				hide_none="1"
				size="40"
			/>

			<field
				name="width"
				type="number"
				label="COM_BANNERS_FIELD_WIDTH_LABEL"
				description="COM_BANNERS_FIELD_WIDTH_DESC"
				class="input-mini validate-numeric"
			/>

			<field
				name="height"
				type="number"
				label="COM_BANNERS_FIELD_HEIGHT_LABEL"
				description="COM_BANNERS_FIELD_HEIGHT_DESC"
				class="input-mini validate-numeric"
			/>

			<field
				name="alt"
				type="text"
				label="COM_BANNERS_FIELD_ALT_LABEL"
				description="COM_BANNERS_FIELD_ALT_DESC"
			/>
		</fieldset>
	</fields>

	<fieldset name="custom">
		<field
			name="bannercode"
			type="textarea"
			label="COM_BANNERS_FIELD_CUSTOMCODE_LABEL"
			description="COM_BANNERS_FIELD_CUSTOMCODE_DESC"
			rows="3"
			cols="30"
			filter="raw"
		/>
	</fieldset>

</form>
models/forms/client.xml000064400000007033151165563430011171
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>
	<fieldset name="details"
addfieldpath="/administrator/components/com_banners/models/fields">
		<field
			name="id"
			type="number"
			label="JGLOBAL_FIELD_ID_LABEL"
			description="JGLOBAL_FIELD_ID_DESC"
			default="0"
			readonly="true"
			class="readonly"
		/>

		<field
			name="name"
			type="text"
			label="COM_BANNERS_FIELD_NAME_LABEL"
			description="COM_BANNERS_FIELD_CLIENT_NAME_DESC"
			class="input-xxlarge input-large-text"
			size="40"
			required="true"
		/>

		<field
			name="contact"
			type="text"
			label="COM_BANNERS_FIELD_CONTACT_LABEL"
			description="COM_BANNERS_FIELD_CONTACT_DESC"
			size="40"
			required="true"
		/>

		<field
			name="email"
			type="email"
			label="COM_BANNERS_FIELD_EMAIL_LABEL"
			description="COM_BANNERS_FIELD_EMAIL_DESC"
			size="40"
			validate="email"
		/>

		<field
			name="state"
			type="list"
			label="JSTATUS"
			description="COM_BANNERS_FIELD_CLIENT_STATE_DESC"
			class="chzn-color-state"
			size="1"
			default="1"
			>
			<option value="1">JPUBLISHED</option>
			<option value="0">JUNPUBLISHED</option>
			<option value="2">JARCHIVED</option>
			<option value="-2">JTRASHED</option>
		</field>

		<field
			name="version_note"
			type="text"
			label="JGLOBAL_FIELD_VERSION_NOTE_LABEL"
			description="JGLOBAL_FIELD_VERSION_NOTE_DESC"
			maxlength="255"
			size="45"
			labelclass="control-label"
		/>

		<field
			name="purchase_type"
			type="list"
			label="COM_BANNERS_FIELD_PURCHASETYPE_LABEL"
			description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
			default="0"
			>
			<option value="-1">JGLOBAL_USE_GLOBAL</option>
			<option
value="1">COM_BANNERS_FIELD_VALUE_UNLIMITED</option>
			<option
value="2">COM_BANNERS_FIELD_VALUE_YEARLY</option>
			<option
value="3">COM_BANNERS_FIELD_VALUE_MONTHLY</option>
			<option
value="4">COM_BANNERS_FIELD_VALUE_WEEKLY</option>
			<option
value="5">COM_BANNERS_FIELD_VALUE_DAILY</option>
		</field>

		<field
			name="track_impressions"
			type="list"
			label="COM_BANNERS_FIELD_TRACKIMPRESSION_LABEL"
			description="COM_BANNERS_FIELD_TRACKIMPRESSION_DESC"
			default="0"
			class="chzn-color"
			>
			<option value="-1">JGLOBAL_USE_GLOBAL</option>
			<option value="0">JNO</option>
			<option value="1">JYES</option>
		</field>

		<field
			name="track_clicks"
			type="list"
			label="COM_BANNERS_FIELD_TRACKCLICK_LABEL"
			description="COM_BANNERS_FIELD_TRACKCLICK_DESC"
			default="0"
			class="chzn-color"
			>
			<option value="-1">JGLOBAL_USE_GLOBAL</option>
			<option value="0">JNO</option>
			<option value="1">JYES</option>
		</field>

	</fieldset>

	<fieldset name="metadata"
label="JGLOBAL_FIELDSET_METADATA_OPTIONS">
		<field
			name="metakey"
			type="textarea"
			label="JFIELD_META_KEYWORDS_LABEL"
			description="COM_BANNERS_FIELD_CLIENT_METAKEYWORDS_DESC"
			rows="3"
			cols="30"
		/>

		<field
			name="own_prefix"
			type="radio"
			label="COM_BANNERS_FIELD_CLIENTOWNPREFIX_LABEL"
			description="COM_BANNERS_FIELD_CLIENTOWNPREFIX_DESC"
			class="btn-group btn-group-yesno"
			default="0"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="metakey_prefix"
			type="text"
			label="COM_BANNERS_FIELD_CLIENT_METAKEYWORDPREFIX_LABEL"
			description="COM_BANNERS_FIELD_CLIENT_METAKEYWORDPREFIX_DESC"
		/>
	</fieldset>

	<fieldset name="extra"
label="COM_BANNERS_EXTRA">
		<field
			name="extrainfo"
			type="textarea"
			label="COM_BANNERS_FIELD_EXTRAINFO_LABEL"
			description="COM_BANNERS_FIELD_EXTRAINFO_DESC"
			class="span12"
			rows="5"
			cols="80"
		/>
	</fieldset>
</form>
models/forms/download.xml000064400000001145151165563430011520
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>

	<fieldset name="details">

		<field
			name="compressed"
			type="radio"
			label="COM_BANNERS_FIELD_COMPRESSED_LABEL"
			description="COM_BANNERS_FIELD_COMPRESSED_DESC"
			default="0"
			class="btn-group btn-group-yesno"
			>
			<option value="1">JYES</option>
			<option value="0">JNO</option>
		</field>

		<field
			name="basename"
			type="text"
			label="COM_BANNERS_FIELD_BASENAME_LABEL"
			size="40"
		/>

		<field
			name="basename_info"
			type="note"
			description="COM_BANNERS_FIELD_BASENAME_DESC"
			class="alert alert-info"
		/>
	</fieldset>
</form>
models/forms/filter_banners.xml000064400000006732151165563430012715
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>
	<fields name="filter"
addfieldpath="/administrator/components/com_banners/models/fields">
		<field
			name="search"
			type="text"
			inputmode="search"
			label="COM_BANNERS_BANNERS_FILTER_SEARCH_LABEL"
			description="COM_BANNERS_BANNERS_FILTER_SEARCH_DESC"
			hint="JSEARCH_FILTER"
		/>

		<field
			name="published"
			type="status"
			label="JOPTION_SELECT_PUBLISHED"
			description="JOPTION_SELECT_PUBLISHED_DESC"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_PUBLISHED</option>
		</field>

		<field
			name="category_id"
			type="category"
			label="JOPTION_FILTER_CATEGORY"
			description="JOPTION_FILTER_CATEGORY_DESC"
			extension="com_banners"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_CATEGORY</option>
		</field>

		<field
			name="client_id"
			type="bannerclient"
			label="COM_BANNERS_FILTER_CLIENT"
			description="COM_BANNERS_FILTER_CLIENT_DESC"
			extension="com_content"
			onchange="this.form.submit();"
			>
			<option
value="">COM_BANNERS_SELECT_CLIENT</option>
		</field>

		<field
			name="language"
			type="contentlanguage"
			label="JOPTION_FILTER_LANGUAGE"
			description="JOPTION_FILTER_LANGUAGE_DESC"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_LANGUAGE</option>
			<option value="*">JALL</option>
		</field>

		<field
			name="level"
			type="integer"
			label="JOPTION_FILTER_LEVEL"
			description="JOPTION_FILTER_LEVEL_DESC"
			first="1"
			last="10"
			step="1"
			languages="*"
			onchange="this.form.submit();"
			>
			<option
value="">JOPTION_SELECT_MAX_LEVELS</option>
		</field>
	</fields>
	<fields name="list">
		<field
			name="fullordering"
			type="list"
			label="JGLOBAL_SORT_BY"
			description="JGLOBAL_SORT_BY"
			statuses="*,0,1,2,-2"
			onchange="this.form.submit();"
			default="a.name ASC"
			validate="options"
			>
			<option value="">JGLOBAL_SORT_BY</option>
			<option value="a.ordering
ASC">JGRID_HEADING_ORDERING_ASC</option>
			<option value="a.ordering
DESC">JGRID_HEADING_ORDERING_DESC</option>
			<option value="a.state ASC">JSTATUS_ASC</option>
			<option value="a.state DESC">JSTATUS_DESC</option>
			<option value="a.name
ASC">COM_BANNERS_HEADING_NAME_ASC</option>
			<option value="a.name
DESC">COM_BANNERS_HEADING_NAME_DESC</option>
			<option value="category_title
ASC">JCATEGORY_ASC</option>
			<option value="category_title
DESC">JCATEGORY_DESC</option>
			<option value="a.sticky
ASC">COM_BANNERS_HEADING_STICKY_ASC</option>
			<option value="a.sticky
DESC">COM_BANNERS_HEADING_STICKY_DESC</option>
			<option value="client_name
ASC">COM_BANNERS_HEADING_CLIENT_ASC</option>
			<option value="client_name
DESC">COM_BANNERS_HEADING_CLIENT_DESC</option>
			<option value="impmade
ASC">COM_BANNERS_HEADING_IMPRESSIONS_ASC</option>
			<option value="impmade
DESC">COM_BANNERS_HEADING_IMPRESSIONS_DESC</option>
			<option value="clicks
ASC">COM_BANNERS_HEADING_CLICKS_ASC</option>
			<option value="clicks
DESC">COM_BANNERS_HEADING_CLICKS_DESC</option>
			<option value="a.language
ASC">JGRID_HEADING_LANGUAGE_ASC</option>
			<option value="a.language
DESC">JGRID_HEADING_LANGUAGE_DESC</option>
			<option value="a.id
ASC">JGRID_HEADING_ID_ASC</option>
			<option value="a.id
DESC">JGRID_HEADING_ID_DESC</option>
		</field>

		<field
			name="limit"
			type="limitbox"
			label="COM_BANNERS_LIST_LIMIT"
			description="COM_BANNERS_LIST_LIMIT_DESC"
			class="input-mini"
			default="25"
			onchange="this.form.submit();"
		/>
	</fields>
</form>
models/forms/filter_clients.xml000064400000004363151165563430012724
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>
	<fields name="filter">
		<field
			name="search"
			type="text"
			inputmode="search"
			label="COM_BANNERS_CLIENTS_FILTER_SEARCH_LABEL"
			description="COM_BANNERS_CLIENTS_FILTER_SEARCH_DESC"
			hint="JSEARCH_FILTER"
		/>

		<field
			name="state"
			type="status"
			label="JOPTION_SELECT_PUBLISHED"
			description="JOPTION_SELECT_PUBLISHED_DESC"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_PUBLISHED</option>
		</field>

		<field
			name="purchase_type"
			type="list"
			label="COM_BANNERS_FILTER_PURCHASETYPE_LABEL"
			description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
			default="0"
			onchange="this.form.submit();"
			>
			<option value="">COM_BANNERS_SELECT_TYPE</option>
			<option
value="1">COM_BANNERS_FIELD_VALUE_UNLIMITED</option>
			<option
value="2">COM_BANNERS_FIELD_VALUE_YEARLY</option>
			<option
value="3">COM_BANNERS_FIELD_VALUE_MONTHLY</option>
			<option
value="4">COM_BANNERS_FIELD_VALUE_WEEKLY</option>
			<option
value="5">COM_BANNERS_FIELD_VALUE_DAILY</option>
		</field>
	</fields>
	<fields name="list">
		<field
			name="fullordering"
			type="list"
			label="JGLOBAL_SORT_BY"
			description="JGLOBAL_SORT_BY"
			statuses="*,0,1,2,-2"
			onchange="this.form.submit();"
			default="a.name ASC"
			validate="options"
			>
			<option value="">JGLOBAL_SORT_BY</option>
			<option value="a.state ASC">JSTATUS_ASC</option>
			<option value="a.state DESC">JSTATUS_DESC</option>
			<option value="a.name
ASC">COM_BANNERS_HEADING_CLIENT_ASC</option>
			<option value="a.name
DESC">COM_BANNERS_HEADING_CLIENT_DESC</option>
			<option value="a.contact
ASC">COM_BANNERS_HEADING_CONTACT_ASC</option>
			<option value="a.contact
DESC">COM_BANNERS_HEADING_CONTACT_DESC</option>
			<option value="a.purchase_type
ASC">COM_BANNERS_HEADING_PURCHASETYPE_ASC</option>
			<option value="a.purchase_type
DESC">COM_BANNERS_HEADING_PURCHASETYPE_DESC</option>
			<option value="a.id
ASC">JGRID_HEADING_ID_ASC</option>
			<option value="a.id
DESC">JGRID_HEADING_ID_DESC</option>
		</field>

		<field
			name="limit"
			type="limitbox"
			label="COM_BANNERS_LIST_LIMIT"
			description="COM_BANNERS_LIST_LIMIT_DESC"
			class="input-mini"
			default="25"
			onchange="this.form.submit();"
		/>
	</fields>
</form>
models/forms/filter_tracks.xml000064400000005631151165563430012551
0ustar00<?xml version="1.0" encoding="utf-8"?>
<form>
	<fields name="filter"
addfieldpath="/administrator/components/com_banners/models/fields">
		<field
			name="search"
			type="text"
			inputmode="search"
			label="COM_BANNERS_TRACKS_FILTER_SEARCH_LABEL"
			description="COM_BANNERS_TRACKS_FILTER_SEARCH_DESC"
			hint="JSEARCH_FILTER"
		/>

		<field
			name="category_id"
			type="category"
			label="JOPTION_FILTER_CATEGORY"
			description="JOPTION_FILTER_CATEGORY_DESC"
			extension="com_banners"
			onchange="this.form.submit();"
			>
			<option value="">JOPTION_SELECT_CATEGORY</option>
		</field>

		<field
			name="client_id"
			type="bannerclient"
			label="COM_BANNERS_FILTER_CLIENT"
			description="COM_BANNERS_FILTER_CLIENT_DESC"
			extension="com_content"
			onchange="this.form.submit();"
			>
			<option
value="">COM_BANNERS_SELECT_CLIENT</option>
		</field>

		<field
			name="type"
			type="list"
			onchange="this.form.submit();"
			>
			<option value="">COM_BANNERS_SELECT_TYPE</option>
			<option value="1">COM_BANNERS_TYPE1</option>
			<option value="2">COM_BANNERS_TYPE2</option>
		</field>

		<field
			name="level"
			type="integer"
			label="JOPTION_FILTER_LEVEL"
			description="JOPTION_FILTER_LEVEL_DESC"
			first="1"
			last="10"
			step="1"
			languages="*"
			onchange="this.form.submit();"
			>
			<option
value="">JOPTION_SELECT_MAX_LEVELS</option>
		</field>

		<field
			name="begin"
			type="calendar"
			label="COM_BANNERS_BEGIN_LABEL"
			description="COM_BANNERS_BEGIN_DESC"
			hint="COM_BANNERS_BEGIN_HINT"
			format="%Y-%m-%d"
			size="10"
			filter="user_utc"
		/>

		<field
			name="end"
			type="calendar"
			label="COM_BANNERS_END_LABEL"
			description="COM_BANNERS_END_DESC"
			hint="COM_BANNERS_END_HINT"
			format="%Y-%m-%d"
			size="10"
			filter="user_utc"
		/>
    </fields>
	<fields name="list">
		<field
			name="fullordering"
			type="list"
			label="JGLOBAL_SORT_BY"
			description="JGLOBAL_SORT_BY"
			onchange="this.form.submit();"
			default="b.name ASC"
			validate="options"
			>
			<option value="">JGLOBAL_SORT_BY</option>
			<option value="b.name
ASC">COM_BANNERS_HEADING_NAME_ASC</option>
			<option value="b.name
DESC">COM_BANNERS_HEADING_NAME_DESC</option>
			<option value="cl.name
ASC">COM_BANNERS_HEADING_CLIENT_ASC</option>
			<option value="cl.name
DESC">COM_BANNERS_HEADING_CLIENT_DESC</option>
			<option value="a.track_type
ASC">COM_BANNERS_HEADING_TYPE_ASC</option>
			<option value="a.track_type
DESC">COM_BANNERS_HEADING_TYPE_DESC</option>
			<option value="a.count
ASC">COM_BANNERS_HEADING_COUNT_ASC</option>
			<option value="a.count
DESC">COM_BANNERS_HEADING_COUNT_DESC</option>
			<option value="a.track_date
ASC">JDATE_ASC</option>
			<option value="a.track_date
DESC">JDATE_DESC</option>
		</field>

		<field
			name="limit"
			type="limitbox"
			label="JGLOBAL_LIMIT"
			description="JGLOBAL_LIMIT"
			class="input-mini"
			default="5"
			onchange="this.form.submit();"
		/>
	</fields>
</form>
models/tracks.php000064400000031776151165563430010056 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Archive\Archive;
use Joomla\String\StringHelper;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

/**
 * Methods supporting a list of tracks.
 *
 * @since  1.6
 */
class BannersModelTracks extends JModelList
{
	/**
	 * The base name
	 *
	 * @var    string
	 * @since  1.6
	 */
	protected $basename;

	/**
	 * Constructor.
	 *
	 * @param   array  $config  An optional associative array of configuration
settings.
	 *
	 * @see     JControllerLegacy
	 * @since   1.6
	 */
	public function __construct($config = array())
	{
		if (empty($config['filter_fields']))
		{
			$config['filter_fields'] = array(
				'b.name', 'banner_name',
				'cl.name', 'client_name', 'client_id',
				'c.title', 'category_title',
'category_id',
				'track_type', 'a.track_type', 'type',
				'count', 'a.count',
				'track_date', 'a.track_date', 'end',
'begin',
				'level', 'c.level',
			);
		}

		parent::__construct($config);
	}

	/**
	 * Method to auto-populate the model state.
	 *
	 * Note. Calling getState in this method will result in recursion.
	 *
	 * @param   string  $ordering   An optional ordering field.
	 * @param   string  $direction  An optional direction (asc|desc).
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function populateState($ordering = 'b.name',
$direction = 'asc')
	{
		// Load the filter state.
		$this->setState('filter.search',
$this->getUserStateFromRequest($this->context .
'.filter.search', 'filter_search', '',
'string'));
		$this->setState('filter.category_id',
$this->getUserStateFromRequest($this->context .
'.filter.category_id', 'filter_category_id',
'', 'cmd'));
		$this->setState('filter.client_id',
$this->getUserStateFromRequest($this->context .
'.filter.client_id', 'filter_client_id', '',
'cmd'));
		$this->setState('filter.type',
$this->getUserStateFromRequest($this->context .
'.filter.type', 'filter_type', '',
'cmd'));
		$this->setState('filter.level',
$this->getUserStateFromRequest($this->context .
'.filter.level', 'filter_level', '',
'cmd'));
		$this->setState('filter.begin',
$this->getUserStateFromRequest($this->context .
'.filter.begin', 'filter_begin', '',
'string'));
		$this->setState('filter.end',
$this->getUserStateFromRequest($this->context .
'.filter.end', 'filter_end', '',
'string'));

		// Load the parameters.
		$this->setState('params',
JComponentHelper::getParams('com_banners'));

		// List state information.
		parent::populateState($ordering, $direction);
	}

	/**
	 * Build an SQL query to load the list data.
	 *
	 * @return  JDatabaseQuery
	 *
	 * @since   1.6
	 */
	protected function getListQuery()
	{
		// Create a new query object.
		$db = $this->getDbo();
		$query = $db->getQuery(true);

		// Select the required fields from the table.
		$query->select($db->quoteName(array('a.track_date',
'a.track_type', 'a.count')))
			->select($db->quoteName('b.name',
'banner_name'))
			->select($db->quoteName('cl.name',
'client_name'))
			->select($db->quoteName('c.title',
'category_title'));

		// From tracks table.
		$query->from($db->quoteName('#__banner_tracks',
'a'));

		// Join with the banners.
		$query->join('LEFT',
$db->quoteName('#__banners', 'b') . ' ON '
. $db->quoteName('b.id') . ' = ' .
$db->quoteName('a.banner_id'));

		// Join with the client.
		$query->join('LEFT',
$db->quoteName('#__banner_clients', 'cl') . '
ON ' . $db->quoteName('cl.id') . ' = ' .
$db->quoteName('b.cid'));

		// Join with the category.
		$query->join('LEFT',
$db->quoteName('#__categories', 'c') . ' ON
' . $db->quoteName('c.id') . ' = ' .
$db->quoteName('b.catid'));

		// Filter by type.
		$type = $this->getState('filter.type');

		if (!empty($type))
		{
			$query->where($db->quoteName('a.track_type') . ' =
' . (int) $type);
		}

		// Filter by client.
		$clientId = $this->getState('filter.client_id');

		if (is_numeric($clientId))
		{
			$query->where($db->quoteName('b.cid') . ' = '
. (int) $clientId);
		}

		// Filter by category.
		$categoryId = $this->getState('filter.category_id');

		if (is_numeric($categoryId))
		{
			$query->where($db->quoteName('b.catid') . ' =
' . (int) $categoryId);
		}

		// Filter by begin date.

		$begin = $this->getState('filter.begin');

		if (!empty($begin))
		{
			$query->where($db->quoteName('a.track_date') . '
>= ' . $db->quote($begin));
		}

		// Filter by end date.
		$end = $this->getState('filter.end');

		if (!empty($end))
		{
			$query->where($db->quoteName('a.track_date') . '
<= ' . $db->quote($end));
		}

		// Filter on the level.
		if ($level = $this->getState('filter.level'))
		{
			$query->where($db->quoteName('c.level') . ' <=
' . (int) $level);
		}

		// Filter by search in banner name or client name.
		$search = $this->getState('filter.search');

		if (!empty($search))
		{
			$search = $db->quote('%' .
StringHelper::strtolower($search) . '%');
			$query->where('(LOWER(b.name) LIKE ' . $search . ' OR
LOWER(cl.name) LIKE ' . $search . ')');
		}

		// Add the list ordering clause.
		$query->order($db->escape($this->getState('list.ordering',
'b.name')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));

		return $query;
	}

	/**
	 * Method to delete rows.
	 *
	 * @return  boolean  Returns true on success, false on failure.
	 */
	public function delete()
	{
		$user       = JFactory::getUser();
		$categoryId = $this->getState('category_id');

		// Access checks.
		if ($categoryId)
		{
			$allow = $user->authorise('core.delete',
'com_banners.category.' . (int) $categoryId);
		}
		else
		{
			$allow = $user->authorise('core.delete',
'com_banners');
		}

		if ($allow)
		{
			// Delete tracks from this banner
			$db    = $this->getDbo();
			$query = $db->getQuery(true)
				->delete($db->quoteName('#__banner_tracks'));

			// Filter by type
			$type = $this->getState('filter.type');

			if (!empty($type))
			{
				$query->where('track_type = ' . (int) $type);
			}

			// Filter by begin date
			$begin = $this->getState('filter.begin');

			if (!empty($begin))
			{
				$query->where('track_date >= ' .
$db->quote($begin));
			}

			// Filter by end date
			$end = $this->getState('filter.end');

			if (!empty($end))
			{
				$query->where('track_date <= ' . $db->quote($end));
			}

			$where = '1 = 1';

			// Filter by client
			$clientId = $this->getState('filter.client_id');

			if (!empty($clientId))
			{
				$where .= ' AND cid = ' . (int) $clientId;
			}

			// Filter by category
			if (!empty($categoryId))
			{
				$where .= ' AND catid = ' . (int) $categoryId;
			}

			$query->where('banner_id IN (SELECT id FROM ' .
$db->quoteName('#__banners') . ' WHERE ' . $where .
')');

			$db->setQuery($query);
			$this->setError((string) $query);

			try
			{
				$db->execute();
			}
			catch (RuntimeException $e)
			{
				$this->setError($e->getMessage());

				return false;
			}
		}
		else
		{
			JError::raiseWarning(403,
JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
		}

		return true;
	}

	/**
	 * Get file name
	 *
	 * @return  string  The file name
	 *
	 * @since   1.6
	 */
	public function getBaseName()
	{
		if (!isset($this->basename))
		{
			$basename   = str_replace('__SITE__',
JFactory::getApplication()->get('sitename'),
$this->getState('basename'));
			$categoryId = $this->getState('filter.category_id');

			if (is_numeric($categoryId))
			{
				if ($categoryId > 0)
				{
					$basename = str_replace('__CATID__', $categoryId,
$basename);
				}
				else
				{
					$basename = str_replace('__CATID__', '',
$basename);
				}

				$categoryName = $this->getCategoryName();
				$basename = str_replace('__CATNAME__', $categoryName,
$basename);
			}
			else
			{
				$basename = str_replace(array('__CATID__',
'__CATNAME__'), '', $basename);
			}

			$clientId = $this->getState('filter.client_id');

			if (is_numeric($clientId))
			{
				if ($clientId > 0)
				{
					$basename = str_replace('__CLIENTID__', $clientId,
$basename);
				}
				else
				{
					$basename = str_replace('__CLIENTID__', '',
$basename);
				}

				$clientName = $this->getClientName();
				$basename = str_replace('__CLIENTNAME__', $clientName,
$basename);
			}
			else
			{
				$basename = str_replace(array('__CLIENTID__',
'__CLIENTNAME__'), '', $basename);
			}

			$type = $this->getState('filter.type');

			if ($type > 0)
			{
				$basename = str_replace('__TYPE__', $type, $basename);
				$typeName = JText::_('COM_BANNERS_TYPE' . $type);
				$basename = str_replace('__TYPENAME__', $typeName,
$basename);
			}
			else
			{
				$basename = str_replace(array('__TYPE__',
'__TYPENAME__'), '', $basename);
			}

			$begin = $this->getState('filter.begin');

			if (!empty($begin))
			{
				$basename = str_replace('__BEGIN__', $begin, $basename);
			}
			else
			{
				$basename = str_replace('__BEGIN__', '',
$basename);
			}

			$end = $this->getState('filter.end');

			if (!empty($end))
			{
				$basename = str_replace('__END__', $end, $basename);
			}
			else
			{
				$basename = str_replace('__END__', '', $basename);
			}

			$this->basename = $basename;
		}

		return $this->basename;
	}

	/**
	 * Get the category name.
	 *
	 * @return  string  The category name
	 *
	 * @since   1.6
	 */
	protected function getCategoryName()
	{
		$categoryId = $this->getState('filter.category_id');

		if ($categoryId)
		{
			$db    = $this->getDbo();
			$query = $db->getQuery(true)
				->select('title')
				->from($db->quoteName('#__categories'))
				->where($db->quoteName('id') . '=' .
$db->quote($categoryId));
			$db->setQuery($query);

			try
			{
				$name = $db->loadResult();
			}
			catch (RuntimeException $e)
			{
				$this->setError($e->getMessage());

				return false;
			}

			return $name;
		}

		return JText::_('COM_BANNERS_NOCATEGORYNAME');
	}

	/**
	 * Get the client name
	 *
	 * @return  string  The client name.
	 *
	 * @since   1.6
	 */
	protected function getClientName()
	{
		$clientId = $this->getState('filter.client_id');

		if ($clientId)
		{
			$db    = $this->getDbo();
			$query = $db->getQuery(true)
				->select('name')
				->from($db->quoteName('#__banner_clients'))
				->where($db->quoteName('id') . '=' .
$db->quote($clientId));
			$db->setQuery($query);

			try
			{
				$name = $db->loadResult();
			}
			catch (RuntimeException $e)
			{
				$this->setError($e->getMessage());

				return false;
			}

			return $name;
		}

		return JText::_('COM_BANNERS_NOCLIENTNAME');
	}

	/**
	 * Get the file type.
	 *
	 * @return  string  The file type
	 *
	 * @since   1.6
	 */
	public function getFileType()
	{
		return $this->getState('compressed') ? 'zip' :
'csv';
	}

	/**
	 * Get the mime type.
	 *
	 * @return  string  The mime type.
	 *
	 * @since   1.6
	 */
	public function getMimeType()
	{
		return $this->getState('compressed') ?
'application/zip' : 'text/csv';
	}

	/**
	 * Get the content
	 *
	 * @return  string  The content.
	 *
	 * @since   1.6
	 */
	public function getContent()
	{
		if (!isset($this->content))
		{
			$this->content = '"' . str_replace('"',
'""', JText::_('COM_BANNERS_HEADING_NAME')) .
'","'
				. str_replace('"', '""',
JText::_('COM_BANNERS_HEADING_CLIENT')) .
'","'
				. str_replace('"', '""',
JText::_('JCATEGORY')) . '","'
				. str_replace('"', '""',
JText::_('COM_BANNERS_HEADING_TYPE')) . '","'
				. str_replace('"', '""',
JText::_('COM_BANNERS_HEADING_COUNT')) .
'","'
				. str_replace('"', '""',
JText::_('JDATE')) . '"' . "\n";

			foreach ($this->getItems() as $item)
			{
				$this->content .= '"' .
str_replace('"', '""',
$item->banner_name) . '","'
					. str_replace('"', '""',
$item->client_name) . '","'
					. str_replace('"', '""',
$item->category_title) . '","'
					. str_replace('"', '""',
($item->track_type == 1 ? JText::_('COM_BANNERS_IMPRESSION') :
JText::_('COM_BANNERS_CLICK'))) . '","'
					. str_replace('"', '""',
$item->count) . '","'
					. str_replace('"', '""',
$item->track_date) . '"' . "\n";
			}

			if ($this->getState('compressed'))
			{
				$app = JFactory::getApplication('administrator');

				$files = array(
					'track' => array(
						'name' => $this->getBasename() . '.csv',
						'data' => $this->content,
						'time' => time()
					)
				);
				$ziproot = $app->get('tmp_path') . '/' .
uniqid('banners_tracks_') . '.zip';

				// Run the packager
				jimport('joomla.filesystem.folder');
				jimport('joomla.filesystem.file');
				$delete = JFolder::files($app->get('tmp_path') .
'/', uniqid('banners_tracks_'), false, true);

				if (!empty($delete))
				{
					if (!JFile::delete($delete))
					{
						// JFile::delete throws an error
						$this->setError(JText::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE'));

						return false;
					}
				}

				$archive = new Archive;

				if (!$packager = $archive->getAdapter('zip'))
				{
					$this->setError(JText::_('COM_BANNERS_ERR_ZIP_ADAPTER_FAILURE'));

					return false;
				}
				elseif (!$packager->create($ziproot, $files))
				{
					$this->setError(JText::_('COM_BANNERS_ERR_ZIP_CREATE_FAILURE'));

					return false;
				}

				$this->content = file_get_contents($ziproot);
			}
		}

		return $this->content;
	}
}
sql/install.mysql.utf8.sql000064400000006637151165563430011610 0ustar00--
-- Table structure for table `#__banners`
--

CREATE TABLE IF NOT EXISTS `#__banners` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cid` int(11) NOT NULL DEFAULT 0,
  `type` int(11) NOT NULL DEFAULT 0,
  `name` varchar(255) NOT NULL DEFAULT '',
  `alias` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL
DEFAULT '',
  `imptotal` int(11) NOT NULL DEFAULT 0,
  `impmade` int(11) NOT NULL DEFAULT 0,
  `clicks` int(11) NOT NULL DEFAULT 0,
  `clickurl` varchar(200) NOT NULL DEFAULT '',
  `state` tinyint(3) NOT NULL DEFAULT 0,
  `catid` int(10) unsigned NOT NULL DEFAULT 0,
  `description` text NOT NULL,
  `custombannercode` varchar(2048) NOT NULL,
  `sticky` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `ordering` int(11) NOT NULL DEFAULT 0,
  `metakey` text NOT NULL,
  `params` text NOT NULL,
  `own_prefix` tinyint(1) NOT NULL DEFAULT 0,
  `metakey_prefix` varchar(400) NOT NULL DEFAULT '',
  `purchase_type` tinyint(4) NOT NULL DEFAULT -1,
  `track_clicks` tinyint(4) NOT NULL DEFAULT -1,
  `track_impressions` tinyint(4) NOT NULL DEFAULT -1,
  `checked_out` int(10) unsigned NOT NULL DEFAULT 0,
  `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00
00:00:00',
  `publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `reset` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `language` char(7) NOT NULL DEFAULT '',
  `created_by` int(10) unsigned NOT NULL DEFAULT 0,
  `created_by_alias` varchar(255) NOT NULL DEFAULT '',
  `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified_by` int(10) unsigned NOT NULL DEFAULT 0,
  `version` int(10) unsigned NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `idx_state` (`state`),
  KEY `idx_own_prefix` (`own_prefix`),
  KEY `idx_metakey_prefix` (`metakey_prefix`(100)),
  KEY `idx_banner_catid` (`catid`),
  KEY `idx_language` (`language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `#__banner_clients`
--

CREATE TABLE IF NOT EXISTS `#__banner_clients` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL DEFAULT '',
  `contact` varchar(255) NOT NULL DEFAULT '',
  `email` varchar(255) NOT NULL DEFAULT '',
  `extrainfo` text NOT NULL,
  `state` tinyint(3) NOT NULL DEFAULT 0,
  `checked_out` int(10) unsigned NOT NULL DEFAULT 0,
  `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00
00:00:00',
  `metakey` text NOT NULL,
  `own_prefix` tinyint(4) NOT NULL DEFAULT 0,
  `metakey_prefix` varchar(400) NOT NULL DEFAULT '',
  `purchase_type` tinyint(4) NOT NULL DEFAULT -1,
  `track_clicks` tinyint(4) NOT NULL DEFAULT -1,
  `track_impressions` tinyint(4) NOT NULL DEFAULT -1,
  PRIMARY KEY (`id`),
  KEY `idx_own_prefix` (`own_prefix`),
  KEY `idx_metakey_prefix` (`metakey_prefix`(100))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `#__banner_tracks`
--

CREATE TABLE IF NOT EXISTS `#__banner_tracks` (
  `track_date` datetime NOT NULL,
  `track_type` int(10) unsigned NOT NULL,
  `banner_id` int(10) unsigned NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`track_date`,`track_type`,`banner_id`),
  KEY `idx_track_date` (`track_date`),
  KEY `idx_track_type` (`track_type`),
  KEY `idx_banner_id` (`banner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
sql/uninstall.mysql.utf8.sql000064400000000171151165563430012136
0ustar00DROP TABLE IF EXISTS `#__banners`;

DROP TABLE IF EXISTS `#__banner_clients`;

DROP TABLE IF EXISTS `#__banner_tracks`;

tables/banner.php000064400000017624151165563430010017 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @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;
	}
}
tables/client.php000064400000006162151165563430010023 0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
 * Client table
 *
 * @since  1.6
 */
class BannersTableClient extends JTable
{
	/**
	 * Constructor
	 *
	 * @param   JDatabaseDriver  $db  Database connector object
	 *
	 * @since   1.5
	 */
	public function __construct(&$db)
	{
		$this->checked_out_time = $db->getNullDate();
		parent::__construct('#__banner_clients', 'id', $db);

		$this->setColumnAlias('published', 'state');

		JTableObserverContenthistory::createObserver($this,
array('typeAlias' => 'com_banners.client'));
	}

	/**
	 * Method to set the publishing 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 publishing state. eg. [0 = unpublished,
1 = published, 2=archived, -2=trashed]
	 * @param   integer  $userId  The user id of the user performing the
operation.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   1.0.4
	 */
	public function publish($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;
			}
		}

		// Build the WHERE clause for the primary keys.
		$where = $k . '=' . implode(' OR ' . $k .
'=', $pks);

		// Determine if there is checkin support for the table.
		if (!property_exists($this, 'checked_out') ||
!property_exists($this, 'checked_out_time'))
		{
			$checkin = '';
		}
		else
		{
			$checkin = ' AND (checked_out = 0 OR checked_out = ' . (int)
$userId . ')';
		}

		// Update the publishing state for rows with the given primary keys.
		$this->_db->setQuery(
			'UPDATE ' . $this->_db->quoteName($this->_tbl)
			. ' SET ' . $this->_db->quoteName('state') .
' = ' . (int) $state
			. ' WHERE (' . $where . ')'
			. $checkin
		);

		try
		{
			$this->_db->execute();
		}
		catch (RuntimeException $e)
		{
			$this->setError($e->getMessage());

			return false;
		}

		// If checkin is supported and all rows were adjusted, check them in.
		if ($checkin && (count($pks) ==
$this->_db->getAffectedRows()))
		{
			// Checkin the rows.
			foreach ($pks as $pk)
			{
				$this->checkin($pk);
			}
		}

		// If the JTable instance value is in the list of primary keys that were
set, set the instance.
		if (in_array($this->$k, $pks))
		{
			$this->state = $state;
		}

		$this->setError('');

		return true;
	}
}
views/banner/tmpl/edit.php000064400000006103151165563430011571
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('jquery.framework');
JHtml::_('behavior.formvalidator');
JHtml::_('formbehavior.chosen', '#jform_catid', null,
array('disable_search_threshold' => 0 ));
JHtml::_('formbehavior.chosen', 'select');

JFactory::getDocument()->addScriptDeclaration('
	Joomla.submitbutton = function(task)
	{
		if (task == "banner.cancel" ||
document.formvalidator.isValid(document.getElementById("banner-form")))
		{
			Joomla.submitform(task,
document.getElementById("banner-form"));
		}
	};
	jQuery(document).ready(function ($){
		$("#jform_type").on("change", function (a, params) {

			var v = typeof(params) !== "object" ?
$("#jform_type").val() : params.selected;

			var img_url = $("#image, #url");
			var custom  = $("#custom");

			switch (v) {
				case "0":
					// Image
					img_url.show();
					custom.hide();
					break;
				case "1":
					// Custom
					img_url.hide();
					custom.show();
					break;
			}
		}).trigger("change");
	});
');
?>

<form action="<?php echo
JRoute::_('index.php?option=com_banners&layout=edit&id='
. (int) $this->item->id); ?>" method="post"
name="adminForm" id="banner-form"
class="form-validate">

	<?php echo JLayoutHelper::render('joomla.edit.title_alias',
$this); ?>

	<div class="form-horizontal">
		<?php echo JHtml::_('bootstrap.startTabSet',
'myTab', array('active' => 'details'));
?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab',
'details', JText::_('COM_BANNERS_BANNER_DETAILS'));
?>
		<div class="row-fluid">
			<div class="span9">
				<?php echo $this->form->renderField('type'); ?>
				<div id="image">
					<?php echo $this->form->renderFieldset('image');
?>
				</div>
				<div id="custom">
					<?php echo
$this->form->renderField('custombannercode'); ?>
				</div>
				<?php
				echo $this->form->renderField('clickurl');
				echo $this->form->renderField('description');
				?>
			</div>
			<div class="span3">
				<?php echo JLayoutHelper::render('joomla.edit.global',
$this); ?>
			</div>
		</div>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab',
'otherparams',
JText::_('COM_BANNERS_GROUP_LABEL_BANNER_DETAILS')); ?>
		<?php echo $this->form->renderFieldset('otherparams');
?>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab',
'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING'));
?>
		<div class="row-fluid form-horizontal-desktop">
			<div class="span6">
				<?php echo
JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
			</div>
			<div class="span6">
				<?php echo $this->form->renderFieldset('metadata');
?>
			</div>
		</div>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.endTabSet'); ?>
	</div>

	<input type="hidden" name="task" value=""
/>
	<?php echo JHtml::_('form.token'); ?>
</form>
views/banner/view.html.php000064400000005625151165563430011615
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

/**
 * View to edit a banner.
 *
 * @since  1.5
 */
class BannersViewBanner extends JViewLegacy
{
	/**
	 * The JForm object
	 *
	 * @var  JForm
	 */
	protected $form;

	/**
	 * The active item
	 *
	 * @var  object
	 */
	protected $item;

	/**
	 * The model state
	 *
	 * @var  object
	 */
	protected $state;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		// Initialize variables.
		$this->form  = $this->get('Form');
		$this->item  = $this->get('Item');
		$this->state = $this->get('State');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		$this->addToolbar();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		JFactory::getApplication()->input->set('hidemainmenu',
true);

		$user       = JFactory::getUser();
		$userId     = $user->id;
		$isNew      = ($this->item->id == 0);
		$checkedOut = !($this->item->checked_out == 0 ||
$this->item->checked_out == $userId);

		// Since we don't track these assets at the item level, use the
category id.
		$canDo = JHelperContent::getActions('com_banners',
'category', $this->item->catid);

		JToolbarHelper::title($isNew ?
JText::_('COM_BANNERS_MANAGER_BANNER_NEW') :
JText::_('COM_BANNERS_MANAGER_BANNER_EDIT'), 'bookmark
banners');

		// If not checked out, can save the item.
		if (!$checkedOut && ($canDo->get('core.edit') ||
count($user->getAuthorisedCategories('com_banners',
'core.create')) > 0))
		{
			JToolbarHelper::apply('banner.apply');
			JToolbarHelper::save('banner.save');

			if ($canDo->get('core.create'))
			{
				JToolbarHelper::save2new('banner.save2new');
			}
		}

		// If an existing item, can save to a copy.
		if (!$isNew && $canDo->get('core.create'))
		{
			JToolbarHelper::save2copy('banner.save2copy');
		}

		if (empty($this->item->id))
		{
			JToolbarHelper::cancel('banner.cancel');
		}
		else
		{
			if (JComponentHelper::isEnabled('com_contenthistory')
&& $this->state->params->get('save_history', 0)
&& $canDo->get('core.edit'))
			{
				JToolbarHelper::versions('com_banners.banner',
$this->item->id);
			}

			JToolbarHelper::cancel('banner.cancel',
'JTOOLBAR_CLOSE');
		}

		JToolbarHelper::divider();
		JToolbarHelper::help('JHELP_COMPONENTS_BANNERS_BANNERS_EDIT');
	}
}
views/banners/tmpl/default.php000064400000017623151165563430012464
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');

$user      = JFactory::getUser();
$userId    = $user->get('id');
$listOrder =
$this->escape($this->state->get('list.ordering'));
$listDirn  =
$this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';

if ($saveOrder)
{
	$saveOrderingUrl =
'index.php?option=com_banners&task=banners.saveOrderAjax&tmpl=component';
	JHtml::_('sortablelist.sortable', 'articleList',
'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
?>
<form action="<?php echo
JRoute::_('index.php?option=com_banners&view=banners');
?>" method="post" name="adminForm"
id="adminForm">
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
		<?php
		// Search tools bar
		echo JLayoutHelper::render('joomla.searchtools.default',
array('view' => $this));
		?>
		<?php if (empty($this->items)) : ?>
			<div class="alert alert-no-items">
				<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
			</div>
		<?php else : ?>
			<table class="table table-striped"
id="articleList">
				<thead>
					<tr>
						<th width="1%" class="nowrap center
hidden-phone">
							<?php echo JHtml::_('searchtools.sort', '',
'a.ordering', $listDirn, $listOrder, null, 'asc',
'JGRID_HEADING_ORDERING', 'icon-menu-2'); ?>
						</th>
						<th width="1%" class="center">
							<?php echo JHtml::_('grid.checkall'); ?>
						</th>
						<th width="1%" class="nowrap center">
							<?php echo JHtml::_('searchtools.sort',
'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
						</th>
						<th>
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_NAME', 'a.name', $listDirn,
$listOrder); ?>
						</th>
						<th width="1%" class="nowrap center
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_STICKY', 'a.sticky', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_CLIENT', 'client_name', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_IMPRESSIONS', 'impmade',
$listDirn, $listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_CLICKS', 'clicks', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'JGRID_HEADING_LANGUAGE', 'a.language', $listDirn,
$listOrder); ?>
						</th>
						<th width="1%" class="nowrap hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder);
?>
						</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="13">
							<?php echo $this->pagination->getListFooter(); ?>
						</td>
					</tr>
				</tfoot>
				<tbody>
					<?php foreach ($this->items as $i => $item) :
						$ordering  = ($listOrder == 'ordering');
						$item->cat_link =
JRoute::_('index.php?option=com_categories&extension=com_banners&task=edit&type=other&cid[]='
. $item->catid);
						$canCreate  = $user->authorise('core.create',    
'com_banners.category.' . $item->catid);
						$canEdit    = $user->authorise('core.edit',      
'com_banners.category.' . $item->catid);
						$canCheckin = $user->authorise('core.manage',    
'com_checkin') || $item->checked_out == $userId ||
$item->checked_out == 0;
						$canChange  = $user->authorise('core.edit.state',
'com_banners.category.' . $item->catid) &&
$canCheckin;
						?>
						<tr class="row<?php echo $i % 2; ?>"
sortable-group-id="<?php echo $item->catid; ?>">
							<td class="order nowrap center hidden-phone">
								<?php
								$iconClass = '';

								if (!$canChange)
								{
									$iconClass = ' inactive';
								}
								elseif (!$saveOrder)
								{
									$iconClass = ' inactive tip-top hasTooltip"
title="' . JHtml::_('tooltipText',
'JORDERINGDISABLED');
								}
								?>
								<span class="sortable-handler <?php echo $iconClass
?>">
									<span class="icon-menu"
aria-hidden="true"></span>
								</span>
								<?php if ($canChange && $saveOrder) : ?>
									<input type="text" style="display:none"
name="order[]" size="5"
										value="<?php echo $item->ordering; ?>"
class="width-20 text-area-order" />
								<?php endif; ?>
							</td>
							<td class="center">
								<?php echo JHtml::_('grid.id', $i, $item->id);
?>
							</td>
							<td class="center">
								<div class="btn-group">
									<?php echo JHtml::_('jgrid.published',
$item->state, $i, 'banners.', $canChange, 'cb',
$item->publish_up, $item->publish_down); ?>
									<?php // Create dropdown items and render the dropdown list.
									if ($canChange)
									{
										JHtml::_('actionsdropdown.' . ((int) $item->state
=== 2 ? 'un' : '') . 'archive',
'cb' . $i, 'banners');
										JHtml::_('actionsdropdown.' . ((int) $item->state
=== -2 ? 'un' : '') . 'trash', 'cb'
. $i, 'banners');
										echo JHtml::_('actionsdropdown.render',
$this->escape($item->name));
									}
									?>
								</div>
							</td>
							<td class="has-context">
								<div class="pull-left break-word">
									<?php if ($item->checked_out) : ?>
										<?php echo JHtml::_('jgrid.checkedout', $i,
$item->editor, $item->checked_out_time, 'banners.',
$canCheckin); ?>
									<?php endif; ?>
									<?php if ($canEdit) : ?>
										<a href="<?php echo
JRoute::_('index.php?option=com_banners&task=banner.edit&id='
. (int) $item->id); ?>">
											<?php echo $this->escape($item->name); ?></a>
									<?php else : ?>
										<?php echo $this->escape($item->name); ?>
									<?php endif; ?>
									<span class="small break-word">
										<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS',
$this->escape($item->alias)); ?>
									</span>
									<div class="small">
										<?php echo JText::_('JCATEGORY') . ': ' .
$this->escape($item->category_title); ?>
									</div>
								</div>
							</td>
							<td class="center hidden-phone">
								<?php echo JHtml::_('banner.pinned', $item->sticky,
$i, $canChange); ?>
							</td>
							<td class="small hidden-phone">
								<?php echo $item->client_name; ?>
							</td>
							<td class="small hidden-phone">
								<?php echo JText::sprintf('COM_BANNERS_IMPRESSIONS',
$item->impmade, $item->imptotal ?:
JText::_('COM_BANNERS_UNLIMITED')); ?>
							</td>
							<td class="small hidden-phone">
								<?php echo $item->clicks; ?> -
								<?php echo sprintf('%.2f%%', $item->impmade ? 100 *
$item->clicks / $item->impmade : 0); ?>
							</td>
							<td class="small nowrap hidden-phone">
								<?php echo
JLayoutHelper::render('joomla.content.language', $item); ?>
							</td>
							<td class="hidden-phone">
								<?php echo $item->id; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
			<?php // Load the batch processing form. ?>
			<?php if ($user->authorise('core.create',
'com_banners')
				&& $user->authorise('core.edit',
'com_banners')
				&& $user->authorise('core.edit.state',
'com_banners')) : ?>
				<?php echo JHtml::_(
					'bootstrap.renderModal',
					'collapseModal',
					array(
						'title'  =>
JText::_('COM_BANNERS_BATCH_OPTIONS'),
						'footer' =>
$this->loadTemplate('batch_footer'),
					),
					$this->loadTemplate('batch_body')
				); ?>
			<?php endif; ?>
		<?php endif; ?>

		<input type="hidden" name="task"
value="" />
		<input type="hidden" name="boxchecked"
value="0" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
views/banners/tmpl/default_batch_body.php000064400000001566151165563430014641
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

$published = $this->state->get('filter.published');
?>

<div class="container-fluid">
	<div class="row-fluid">
		<div class="control-group span6">
			<div class="controls">
				<?php echo JHtml::_('batch.language'); ?>
			</div>
		</div>
		<div class="control-group span6">
			<div class="controls">
				<?php echo JHtml::_('banner.clients'); ?>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<?php if ($published >= 0) : ?>
			<div class="control-group span6">
				<div class="controls">
					<?php echo JHtml::_('batch.item',
'com_banners'); ?>
				</div>
			</div>
		<?php endif; ?>
	</div>
</div>
views/banners/tmpl/default_batch_footer.php000064400000001317151165563430015174
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;
?>
<button type="button" class="btn"
onclick="document.getElementById('batch-category-id').value='';document.getElementById('batch-client-id').value='';document.getElementById('batch-language-id').value=''"
data-dismiss="modal">
	<?php echo JText::_('JCANCEL'); ?>
</button>
<button type="submit" class="btn btn-success"
onclick="Joomla.submitbutton('banner.batch');return
false;">
	<?php echo JText::_('JGLOBAL_BATCH_PROCESS'); ?>
</button>
views/banners/view.html.php000064400000011156151165563430011774
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * View class for a list of banners.
 *
 * @since  1.6
 */
class BannersViewBanners extends JViewLegacy
{
	/**
	 * Category data
	 *
	 * @var  array
	 */
	protected $categories;

	/**
	 * An array of items
	 *
	 * @var  array
	 */
	protected $items;

	/**
	 * The pagination object
	 *
	 * @var  JPagination
	 */
	protected $pagination;

	/**
	 * The model state
	 *
	 * @var  object
	 */
	protected $state;

	/**
	 * Method to display the view.
	 *
	 * @param   string  $tpl  A template file to load. [optional]
	 *
	 * @return  mixed  A string if successful, otherwise a JError object.
	 *
	 * @since   1.6
	 */
	public function display($tpl = null)
	{
		$this->categories    = $this->get('CategoryOrders');
		$this->items         = $this->get('Items');
		$this->pagination    = $this->get('Pagination');
		$this->state         = $this->get('State');
		$this->filterForm    = $this->get('FilterForm');
		$this->activeFilters = $this->get('ActiveFilters');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		BannersHelper::addSubmenu('banners');

		$this->addToolbar();

		// Include the component HTML helpers.
		JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

		$this->sidebar = JHtmlSidebar::render();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

		$canDo = JHelperContent::getActions('com_banners',
'category',
$this->state->get('filter.category_id'));
		$user  = JFactory::getUser();

		JToolbarHelper::title(JText::_('COM_BANNERS_MANAGER_BANNERS'),
'bookmark banners');

		if (count($user->getAuthorisedCategories('com_banners',
'core.create')) > 0)
		{
			JToolbarHelper::addNew('banner.add');
		}

		if ($canDo->get('core.edit'))
		{
			JToolbarHelper::editList('banner.edit');
		}

		if ($canDo->get('core.edit.state'))
		{
			if ($this->state->get('filter.published') != 2)
			{
				JToolbarHelper::publish('banners.publish',
'JTOOLBAR_PUBLISH', true);
				JToolbarHelper::unpublish('banners.unpublish',
'JTOOLBAR_UNPUBLISH', true);
			}

			if ($this->state->get('filter.published') != -1)
			{
				if ($this->state->get('filter.published') != 2)
				{
					JToolbarHelper::archiveList('banners.archive');
				}
				elseif ($this->state->get('filter.published') == 2)
				{
					JToolbarHelper::unarchiveList('banners.publish');
				}
			}
		}

		if ($canDo->get('core.edit.state'))
		{
			JToolbarHelper::checkin('banners.checkin');
		}

		// Add a batch button
		if ($user->authorise('core.create', 'com_banners')
			&& $user->authorise('core.edit',
'com_banners')
			&& $user->authorise('core.edit.state',
'com_banners'))
		{
			$title = JText::_('JTOOLBAR_BATCH');

			// Instantiate a new JLayoutFile instance and render the batch button
			$layout = new JLayoutFile('joomla.toolbar.batch');

			$dhtml = $layout->render(array('title' => $title));
			JToolbar::getInstance('toolbar')->appendButton('Custom',
$dhtml, 'batch');
		}

		if ($this->state->get('filter.published') == -2
&& $canDo->get('core.delete'))
		{
			JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE',
'banners.delete', 'JTOOLBAR_EMPTY_TRASH');
		}
		elseif ($canDo->get('core.edit.state'))
		{
			JToolbarHelper::trash('banners.trash');
		}

		if ($user->authorise('core.admin', 'com_banners')
|| $user->authorise('core.options', 'com_banners'))
		{
			JToolbarHelper::preferences('com_banners');
		}

		JToolbarHelper::help('JHELP_COMPONENTS_BANNERS_BANNERS');
	}

	/**
	 * Returns an array of fields the table can be sorted by
	 *
	 * @return  array  Array containing the field name to sort by as the key
and display text as value
	 *
	 * @since   3.0
	 */
	protected function getSortFields()
	{
		return array(
			'ordering'    =>
JText::_('JGRID_HEADING_ORDERING'),
			'a.state'     => JText::_('JSTATUS'),
			'a.name'      =>
JText::_('COM_BANNERS_HEADING_NAME'),
			'a.sticky'    =>
JText::_('COM_BANNERS_HEADING_STICKY'),
			'client_name' =>
JText::_('COM_BANNERS_HEADING_CLIENT'),
			'impmade'     =>
JText::_('COM_BANNERS_HEADING_IMPRESSIONS'),
			'clicks'      =>
JText::_('COM_BANNERS_HEADING_CLICKS'),
			'a.language'  =>
JText::_('JGRID_HEADING_LANGUAGE'),
			'a.id'        => JText::_('JGRID_HEADING_ID'),
		);
	}
}
views/client/tmpl/edit.php000064400000004136151165563430011606
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.formvalidator');
JHtml::_('formbehavior.chosen', 'select');

JFactory::getDocument()->addScriptDeclaration('
	Joomla.submitbutton = function(task)
	{
		if (task == "client.cancel" ||
document.formvalidator.isValid(document.getElementById("client-form")))
		{
			Joomla.submitform(task,
document.getElementById("client-form"));
		}
	};
');
?>

<form action="<?php echo
JRoute::_('index.php?option=com_banners&layout=edit&id='
. (int) $this->item->id); ?>" method="post"
name="adminForm" id="client-form"
class="form-validate">

	<?php echo JLayoutHelper::render('joomla.edit.title_alias',
$this); ?>

	<div class="form-horizontal">
		<?php echo JHtml::_('bootstrap.startTabSet',
'myTab', array('active' => 'general'));
?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab',
'general', empty($this->item->id) ?
JText::_('COM_BANNERS_NEW_CLIENT') :
JText::_('COM_BANNERS_EDIT_CLIENT')); ?>
		<div class="row-fluid">
			<div class="span9">
				<?php
				echo $this->form->renderField('contact');
				echo $this->form->renderField('email');
				echo $this->form->renderField('purchase_type');
				echo $this->form->renderField('track_impressions');
				echo $this->form->renderField('track_clicks');
				echo $this->form->renderFieldset('extra');
				?>
			</div>
			<div class="span3">
				<?php echo JLayoutHelper::render('joomla.edit.global',
$this); ?>
			</div>
		</div>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab',
'metadata',
JText::_('JGLOBAL_FIELDSET_METADATA_OPTIONS')); ?>
		<?php echo $this->form->renderFieldset('metadata');
?>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.endTabSet'); ?>
	</div>

	<input type="hidden" name="task" value=""
/>
	<?php echo JHtml::_('form.token'); ?>
</form>
views/client/view.html.php000064400000005551151165563430011624
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

/**
 * View to edit a client.
 *
 * @since  1.5
 */
class BannersViewClient extends JViewLegacy
{
	/**
	 * The JForm object
	 *
	 * @var  JForm
	 */
	protected $form;

	/**
	 * The active item
	 *
	 * @var  object
	 */
	protected $item;

	/**
	 * The model state
	 *
	 * @var  object
	 */
	protected $state;

	/**
	 * Object containing permissions for the item
	 *
	 * @var  JObject
	 */
	protected $canDo;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		$this->form  = $this->get('Form');
		$this->item  = $this->get('Item');
		$this->state = $this->get('State');
		$this->canDo = JHelperContent::getActions('com_banners');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		$this->addToolbar();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		JFactory::getApplication()->input->set('hidemainmenu',
true);

		$user       = JFactory::getUser();
		$isNew      = ($this->item->id == 0);
		$checkedOut = !($this->item->checked_out == 0 ||
$this->item->checked_out == $user->id);
		$canDo      = $this->canDo;

		JToolbarHelper::title(
			$isNew ? JText::_('COM_BANNERS_MANAGER_CLIENT_NEW') :
JText::_('COM_BANNERS_MANAGER_CLIENT_EDIT'),
			'bookmark banners-clients'
		);

		// If not checked out, can save the item.
		if (!$checkedOut && ($canDo->get('core.edit') ||
$canDo->get('core.create')))
		{
			JToolbarHelper::apply('client.apply');
			JToolbarHelper::save('client.save');
		}

		if (!$checkedOut && $canDo->get('core.create'))
		{
			JToolbarHelper::save2new('client.save2new');
		}

		// If an existing item, can save to a copy.
		if (!$isNew && $canDo->get('core.create'))
		{
			JToolbarHelper::save2copy('client.save2copy');
		}

		if (empty($this->item->id))
		{
			JToolbarHelper::cancel('client.cancel');
		}
		else
		{
			if (JComponentHelper::isEnabled('com_contenthistory')
&& $this->state->params->get('save_history', 0)
&& $canDo->get('core.edit'))
			{
				JToolbarHelper::versions('com_banners.client',
$this->item->id);
			}

			JToolbarHelper::cancel('client.cancel',
'JTOOLBAR_CLOSE');
		}

		JToolbarHelper::divider();
		JToolbarHelper::help('JHELP_COMPONENTS_BANNERS_CLIENTS_EDIT');
	}
}
views/clients/tmpl/default.php000064400000017240151165563430012470
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', 'select');

$purchaseTypes = array(
		'1' => 'UNLIMITED',
		'2' => 'YEARLY',
		'3' => 'MONTHLY',
		'4' => 'WEEKLY',
		'5' => 'DAILY',
);

$user       = JFactory::getUser();
$userId     = $user->get('id');
$listOrder  =
$this->escape($this->state->get('list.ordering'));
$listDirn   =
$this->escape($this->state->get('list.direction'));
$params     = isset($this->state->params) ?
$this->state->params : new JObject;
?>
<form action="<?php echo
JRoute::_('index.php?option=com_banners&view=clients');
?>" method="post" name="adminForm"
id="adminForm">
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
		<?php
		// Search tools bar
		echo JLayoutHelper::render('joomla.searchtools.default',
array('view' => $this));
		?>
		<?php if (empty($this->items)) : ?>
			<div class="alert alert-no-items">
				<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
			</div>
		<?php else : ?>
			<table class="table table-striped">
				<thead>
					<tr>
						<th width="1%" class="center">
							<?php echo JHtml::_('grid.checkall'); ?>
						</th>
						<th width="5%" class="nowrap center">
							<?php echo JHtml::_('searchtools.sort',
'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
						</th>
						<th>
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_CLIENT', 'a.name', $listDirn,
$listOrder); ?>
						</th>
						<th width="20%" class="hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_CONTACT', 'a.contact', $listDirn,
$listOrder); ?>
						</th>
						<th width="1%" class="nowrap center hidden-phone
hidden-tablet">
							<span class="icon-publish hasTooltip"
aria-hidden="true" title="<?php echo
JText::_('COM_BANNERS_COUNT_PUBLISHED_ITEMS');
?>"><span class="element-invisible"><?php
echo JText::_('COM_BANNERS_COUNT_PUBLISHED_ITEMS');
?></span></span>
						</th>
						<th width="1%" class="nowrap center hidden-phone
hidden-tablet">
							<span class="icon-unpublish hasTooltip"
aria-hidden="true" title="<?php echo
JText::_('COM_BANNERS_COUNT_UNPUBLISHED_ITEMS');
?>"><span class="element-invisible"><?php
echo JText::_('COM_BANNERS_COUNT_UNPUBLISHED_ITEMS');
?></span></span>
						</th>
						<th width="1%" class="nowrap center hidden-phone
hidden-tablet">
							<span class="icon-archive hasTooltip"
aria-hidden="true" title="<?php echo
JText::_('COM_BANNERS_COUNT_ARCHIVED_ITEMS');
?>"><span class="element-invisible"><?php
echo JText::_('COM_BANNERS_COUNT_ARCHIVED_ITEMS');
?></span></span>
						</th>
						<th width="1%" class="nowrap center hidden-phone
hidden-tablet">
							<span class="icon-trash hasTooltip"
aria-hidden="true" title="<?php echo
JText::_('COM_BANNERS_COUNT_TRASHED_ITEMS');
?>"><span class="element-invisible"><?php
echo JText::_('COM_BANNERS_COUNT_TRASHED_ITEMS');
?></span></span>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_PURCHASETYPE', 'a.purchase_type',
$listDirn, $listOrder); ?>
						</th>
						<th width="1%" class="nowrap hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder);
?>
						</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="11">
							<?php echo $this->pagination->getListFooter(); ?>
						</td>
					</tr>
				</tfoot>
				<tbody>
					<?php foreach ($this->items as $i => $item) :
						$canCreate  = $user->authorise('core.create',    
'com_banners');
						$canEdit    = $user->authorise('core.edit',      
'com_banners');
						$canCheckin = $user->authorise('core.manage',    
'com_checkin') || $item->checked_out ==
$user->get('id') || $item->checked_out == 0;
						$canChange  = $user->authorise('core.edit.state',
'com_banners') && $canCheckin;
						?>
						<tr class="row<?php echo $i % 2; ?>">
							<td class="center">
								<?php echo JHtml::_('grid.id', $i, $item->id);
?>
							</td>
							<td class="center">
								<div class="btn-group">
									<?php echo JHtml::_('jgrid.published',
$item->state, $i, 'clients.', $canChange); ?>
									<?php // Create dropdown items and render the dropdown list.

									if ($canChange)
									{
										JHtml::_('actionsdropdown.' . ((int) $item->state
=== 2 ? 'un' : '') . 'archive',
'cb' . $i, 'clients');
										JHtml::_('actionsdropdown.' . ((int) $item->state
=== -2 ? 'un' : '') . 'trash', 'cb'
. $i, 'clients');
										echo JHtml::_('actionsdropdown.render',
$this->escape($item->name));
									}
									?>
								</div>
							</td>
							<td class="nowrap has-context">
								<div class="pull-left">
									<?php if ($item->checked_out) : ?>
										<?php echo JHtml::_('jgrid.checkedout', $i,
$item->editor, $item->checked_out_time, 'clients.',
$canCheckin); ?>
									<?php endif; ?>
									<?php if ($canEdit) : ?>
										<a href="<?php echo
JRoute::_('index.php?option=com_banners&task=client.edit&id='
. (int) $item->id); ?>">
											<?php echo $this->escape($item->name); ?></a>
									<?php else : ?>
										<?php echo $this->escape($item->name); ?>
									<?php endif; ?>
								</div>
							</td>
							<td class="small hidden-phone">
								<?php echo $item->contact; ?>
							</td>
							<td class="center btns hidden-phone hidden-tablet">
								<a class="badge <?php if ($item->count_published >
0) echo 'badge-success'; ?>" href="<?php echo
JRoute::_('index.php?option=com_banners&view=banners&filter[client_id]='
. (int) $item->id . '&filter[published]=1');
?>">
									<?php echo $item->count_published; ?></a>
							</td>
							<td class="center btns hidden-phone hidden-tablet">
								<a class="badge <?php if ($item->count_unpublished
> 0) echo 'badge-important'; ?>" href="<?php
echo
JRoute::_('index.php?option=com_banners&view=banners&filter[client_id]='
. (int) $item->id . '&filter[published]=0');
?>">
									<?php echo $item->count_unpublished; ?></a>
							</td>
							<td class="center btns hidden-phone hidden-tablet">
								<a class="badge <?php if ($item->count_archived >
0) echo 'badge-info'; ?>" href="<?php echo
JRoute::_('index.php?option=com_banners&view=banners&filter[client_id]='
. (int) $item->id . '&filter[published]=2');
?>">
									<?php echo $item->count_archived; ?></a>
							</td>
							<td class="center btns hidden-phone hidden-tablet">
								<a class="badge <?php if ($item->count_trashed >
0) echo 'badge-inverse'; ?>" href="<?php echo
JRoute::_('index.php?option=com_banners&view=banners&filter[client_id]='
. (int) $item->id . '&filter[published]=-2');
?>">
									<?php echo $item->count_trashed; ?></a>
							</td>
							<td class="small hidden-phone">
								<?php if ($item->purchase_type < 0) : ?>
									<?php echo JText::sprintf('COM_BANNERS_DEFAULT',
JText::_('COM_BANNERS_FIELD_VALUE_' .
$purchaseTypes[$params->get('purchase_type')])); ?>
								<?php else : ?>
									<?php echo JText::_('COM_BANNERS_FIELD_VALUE_' .
$purchaseTypes[$item->purchase_type]); ?>
								<?php endif; ?>
							</td>
							<td class="hidden-phone">
								<?php echo $item->id; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>

		<input type="hidden" name="task"
value="" />
		<input type="hidden" name="boxchecked"
value="0" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
views/clients/view.html.php000064400000006354151165563430012011
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

/**
 * View class for a list of clients.
 *
 * @since  1.6
 */
class BannersViewClients extends JViewLegacy
{
	/**
	 * An array of items
	 *
	 * @var  array
	 */
	protected $items;

	/**
	 * The pagination object
	 *
	 * @var  JPagination
	 */
	protected $pagination;

	/**
	 * The model state
	 *
	 * @var  object
	 */
	protected $state;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		$this->items         = $this->get('Items');
		$this->pagination    = $this->get('Pagination');
		$this->state         = $this->get('State');
		$this->filterForm    = $this->get('FilterForm');
		$this->activeFilters = $this->get('ActiveFilters');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		BannersHelper::addSubmenu('clients');

		$this->addToolbar();
		$this->sidebar = JHtmlSidebar::render();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		$canDo = JHelperContent::getActions('com_banners');

		JToolbarHelper::title(JText::_('COM_BANNERS_MANAGER_CLIENTS'),
'bookmark banners-clients');

		if ($canDo->get('core.create'))
		{
			JToolbarHelper::addNew('client.add');
		}

		if ($canDo->get('core.edit'))
		{
			JToolbarHelper::editList('client.edit');
		}

		if ($canDo->get('core.edit.state'))
		{
			JToolbarHelper::publish('clients.publish',
'JTOOLBAR_PUBLISH', true);
			JToolbarHelper::unpublish('clients.unpublish',
'JTOOLBAR_UNPUBLISH', true);
			JToolbarHelper::archiveList('clients.archive');
			JToolbarHelper::checkin('clients.checkin');
		}

		if ($this->state->get('filter.state') == -2 &&
$canDo->get('core.delete'))
		{
			JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE',
'clients.delete', 'JTOOLBAR_EMPTY_TRASH');
		}
		elseif ($canDo->get('core.edit.state'))
		{
			JToolbarHelper::trash('clients.trash');
		}

		if ($canDo->get('core.admin') ||
$canDo->get('core.options'))
		{
			JToolbarHelper::preferences('com_banners');
		}

		JToolbarHelper::help('JHELP_COMPONENTS_BANNERS_CLIENTS');
	}

	/**
	 * Returns an array of fields the table can be sorted by
	 *
	 * @return  array  Array containing the field name to sort by as the key
and display text as value
	 *
	 * @since   3.0
	 */
	protected function getSortFields()
	{
		return array(
			'a.status'    => JText::_('JSTATUS'),
			'a.name'      =>
JText::_('COM_BANNERS_HEADING_CLIENT'),
			'contact'     =>
JText::_('COM_BANNERS_HEADING_CONTACT'),
			'client_name' =>
JText::_('COM_BANNERS_HEADING_CLIENT'),
			'nbanners'    =>
JText::_('COM_BANNERS_HEADING_ACTIVE'),
			'a.id'        => JText::_('JGRID_HEADING_ID')
		);
	}
}
views/download/tmpl/default.php000064400000002100151165563430012623
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::_('bootstrap.tooltip', '.hasTooltip',
array('placement' => 'bottom'));
?>
<div class="container-popup">
	<form
		class="form-horizontal form-validate"
		id="download-form"
		name="adminForm"
		action="<?php echo
JRoute::_('index.php?option=com_banners&task=tracks.display&format=raw');
?>"
		method="post">

		<?php foreach ($this->form->getFieldset() as $field) : ?>
			<?php echo $this->form->renderField($field->fieldname);
?>
		<?php endforeach; ?>

		<button class="hidden"
			id="closeBtn"
			type="button"
			onclick="window.parent.jQuery('#modal-download').modal('hide');">
		</button>
		<button class="hidden"
			id="exportBtn"
			type="button"
			onclick="this.form.submit();window.top.setTimeout('window.parent.jQuery(\'#downloadModal\').modal(\'hide\')',
700);">
		</button>
	</form>
</div>
views/download/view.html.php000064400000001654151165563430012155
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * View class for download a list of tracks.
 *
 * @since  1.6
 */
class BannersViewDownload extends JViewLegacy
{
	/**
	 * The JForm object
	 *
	 * @var  JForm
	 */
	protected $form;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		$this->form = $this->get('Form');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		return parent::display($tpl);
	}
}
views/tracks/tmpl/default.php000064400000007620151165563430012317
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::_('formbehavior.chosen', 'select');
JHtml::_('bootstrap.tooltip');

$listOrder  =
$this->escape($this->state->get('list.ordering'));
$listDirn   =
$this->escape($this->state->get('list.direction'));
?>
<form action="<?php echo
JRoute::_('index.php?option=com_banners&view=tracks');
?>" method="post" name="adminForm"
id="adminForm">
<?php if (!empty( $this->sidebar)) : ?>
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
<?php else : ?>
	<div id="j-main-container">
<?php endif; ?>
		<?php echo
JLayoutHelper::render('joomla.searchtools.default',
array('view' => $this)); ?>
		<?php if (empty($this->items)) : ?>
			<div class="alert alert-no-items">
				<?php echo JText::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
			</div>
		<?php else : ?>
			<table class="table table-striped">
				<thead>
					<tr>
						<th class="title">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_NAME', 'b.name', $listDirn,
$listOrder); ?>
						</th>
						<th width="20%" class="nowrap">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_CLIENT', 'cl.name', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_TYPE', 'a.track_type', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'COM_BANNERS_HEADING_COUNT', 'a.count', $listDirn,
$listOrder); ?>
						</th>
						<th width="10%" class="nowrap
hidden-phone">
							<?php echo JHtml::_('searchtools.sort',
'JDATE', 'a.track_date', $listDirn, $listOrder); ?>
						</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="5">
							<?php echo $this->pagination->getListFooter(); ?>
						</td>
					</tr>
				</tfoot>
				<tbody>
					<?php foreach ($this->items as $i => $item) : ?>
						<tr class="row<?php echo $i % 2; ?>">
							<td>
								<?php echo $item->banner_name; ?>
								<div class="small">
									<?php echo JText::_('JCATEGORY') . ': ' .
$this->escape($item->category_title); ?>
								</div>
							</td>
							<td>
								<?php echo $item->client_name; ?>
							</td>
							<td class="small hidden-phone">
								<?php echo $item->track_type == 1 ?
JText::_('COM_BANNERS_IMPRESSION') :
JText::_('COM_BANNERS_CLICK'); ?>
							</td>
							<td class="hidden-phone">
								<?php echo $item->count; ?>
							</td>
							<td class="hidden-phone">
								<?php echo JHtml::_('date', $item->track_date,
JText::_('DATE_FORMAT_LC5')); ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>

		<?php // Load the export form ?>
		<?php echo JHtml::_(
			'bootstrap.renderModal',
			'downloadModal',
			array(
				'title'       =>
JText::_('COM_BANNERS_TRACKS_DOWNLOAD'),
				'url'         =>
JRoute::_('index.php?option=com_banners&amp;view=download&amp;tmpl=component'),
				'height'      => '370px',
				'width'       => '300px',
				'modalWidth'  => '40',
				'footer'      => '<button type="button"
class="btn" data-dismiss="modal"'
						. ' onclick="jQuery(\'#downloadModal
iframe\').contents().find(\'#closeBtn\').click();">'
						. JText::_('COM_BANNERS_CANCEL') .
'</button>'
						. '<button type="button" class="btn
btn-success"'
						. ' onclick="jQuery(\'#downloadModal
iframe\').contents().find(\'#exportBtn\').click();">'
						. JText::_('COM_BANNERS_TRACKS_EXPORT') .
'</button>',
			)
		); ?>

		<input type="hidden" name="task"
value="" />
		<input type="hidden" name="boxchecked"
value="0" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>
views/tracks/view.html.php000064400000006241151165563430011632
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR .
'/components/com_banners/helpers/banners.php');

/**
 * View class for a list of tracks.
 *
 * @since  1.6
 */
class BannersViewTracks extends JViewLegacy
{
	/**
	 * An array of items
	 *
	 * @var  array
	 */
	protected $items;

	/**
	 * The pagination object
	 *
	 * @var  JPagination
	 */
	protected $pagination;

	/**
	 * The model state
	 *
	 * @var  object
	 */
	protected $state;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		$this->items         = $this->get('Items');
		$this->pagination    = $this->get('Pagination');
		$this->state         = $this->get('State');
		$this->filterForm    = $this->get('FilterForm');
		$this->activeFilters = $this->get('ActiveFilters');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		BannersHelper::addSubmenu('tracks');

		$this->addToolbar();

		$this->sidebar = JHtmlSidebar::render();

		return parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		$canDo = JHelperContent::getActions('com_banners',
'category',
$this->state->get('filter.category_id'));

		JToolbarHelper::title(JText::_('COM_BANNERS_MANAGER_TRACKS'),
'bookmark banners-tracks');

		$bar = JToolbar::getInstance('toolbar');

		// Instantiate a new JLayoutFile instance and render the export button
		$layout = new JLayoutFile('joomla.toolbar.modal');

		$dhtml  = $layout->render(
			array(
				'selector' => 'downloadModal',
				'icon'     => 'download',
				'text'     => JText::_('JTOOLBAR_EXPORT'),
			)
		);

		$bar->appendButton('Custom', $dhtml, 'download');

		if ($canDo->get('core.delete'))
		{
			$bar->appendButton('Confirm',
'COM_BANNERS_DELETE_MSG', 'delete',
'COM_BANNERS_TRACKS_DELETE', 'tracks.delete', false);
			JToolbarHelper::divider();
		}

		if ($canDo->get('core.admin') ||
$canDo->get('core.options'))
		{
			JToolbarHelper::preferences('com_banners');
			JToolbarHelper::divider();
		}

		JToolbarHelper::help('JHELP_COMPONENTS_BANNERS_TRACKS');

		JHtmlSidebar::setAction('index.php?option=com_banners&view=tracks');
	}

	/**
	 * Returns an array of fields the table can be sorted by
	 *
	 * @return  array  Array containing the field name to sort by as the key
and display text as value
	 *
	 * @since   3.0
	 */
	protected function getSortFields()
	{
		return array(
			'b.name'     =>
JText::_('COM_BANNERS_HEADING_NAME'),
			'cl.name'    =>
JText::_('COM_BANNERS_HEADING_CLIENT'),
			'track_type' =>
JText::_('COM_BANNERS_HEADING_TYPE'),
			'count'      =>
JText::_('COM_BANNERS_HEADING_COUNT'),
			'track_date' => JText::_('JDATE')
		);
	}
}
views/tracks/view.raw.php000064400000002254151165563430011457
0ustar00<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * View class for a list of tracks.
 *
 * @since  1.6
 */
class BannersViewTracks extends JViewLegacy
{
	/**
	 * Display the view
	 *
	 * @param   string  $tpl  The name of the template file to parse;
automatically searches through the template paths.
	 *
	 * @return  void
	 */
	public function display($tpl = null)
	{
		$basename = $this->get('BaseName');
		$filetype = $this->get('FileType');
		$mimetype = $this->get('MimeType');
		$content  = $this->get('Content');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors), 500);
		}

		$document = JFactory::getDocument();
		$document->setMimeEncoding($mimetype);
		JFactory::getApplication()
			->setHeader(
				'Content-disposition',
				'attachment; filename="' . $basename . '.' .
$filetype . '"; creation-date="' .
JFactory::getDate()->toRFC822() . '"',
				true
			);
		echo $content;
	}
}
helpers/banner.php000064400000001736151166047710010203 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @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);
	}
}
helpers/category.php000064400000001206151166047710010543 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Banners Component Category Tree
 *
 * @since  1.6
 */
class BannersCategories extends JCategories
{
	/**
	 * Constructor
	 *
	 * @param   array  $options  Array of options
	 *
	 * @since   1.6
	 */
	public function __construct($options = array())
	{
		$options['table']     = '#__banners';
		$options['extension'] = 'com_banners';

		parent::__construct($options);
	}
}
router.php000064400000005247151166050000006577 0ustar00<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_banners
 *
 * @copyright   Copyright (C) 2005 - 2020 Open Source Matters, Inc. All
rights reserved.
 * @license     GNU General Public License version 2 or later; see
LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Routing class from com_banners
 *
 * @since  3.3
 */
class BannersRouter extends JComponentRouterBase
{
	/**
	 * Build the route for the com_banners component
	 *
	 * @param   array  &$query  An array of URL arguments
	 *
	 * @return  array  The URL arguments to use to assemble the subsequent
URL.
	 *
	 * @since   3.3
	 */
	public function build(&$query)
	{
		$segments = array();

		if (isset($query['task']))
		{
			$segments[] = $query['task'];
			unset($query['task']);
		}

		if (isset($query['id']))
		{
			$segments[] = $query['id'];
			unset($query['id']);
		}

		$total = count($segments);

		for ($i = 0; $i < $total; $i++)
		{
			$segments[$i] = str_replace(':', '-',
$segments[$i]);
		}

		return $segments;
	}

	/**
	 * Parse the segments of a URL.
	 *
	 * @param   array  &$segments  The segments of the URL to parse.
	 *
	 * @return  array  The URL attributes to be used by the application.
	 *
	 * @since   3.3
	 */
	public function parse(&$segments)
	{
		$total = count($segments);
		$vars = array();

		for ($i = 0; $i < $total; $i++)
		{
			$segments[$i] = preg_replace('/-/', ':',
$segments[$i], 1);
		}

		// View is always the first element of the array
		$count = count($segments);

		if ($count)
		{
			$count--;
			$segment = array_shift($segments);

			if (is_numeric($segment))
			{
				$vars['id'] = $segment;
			}
			else
			{
				$vars['task'] = $segment;
			}
		}

		if ($count)
		{
			$segment = array_shift($segments);

			if (is_numeric($segment))
			{
				$vars['id'] = $segment;
			}
		}

		return $vars;
	}
}

/**
 * Build the route for the com_banners component
 *
 * This function is a proxy for the new router interface
 * for old SEF extensions.
 *
 * @param   array  &$query  An array of URL arguments
 *
 * @return  array  The URL arguments to use to assemble the subsequent URL.
 *
 * @since   3.3
 * @deprecated  4.0  Use Class based routers instead
 */
function bannersBuildRoute(&$query)
{
	$router = new BannersRouter;

	return $router->build($query);
}

/**
 * Parse the segments of a URL.
 *
 * This function is a proxy for the new router interface
 * for old SEF extensions.
 *
 * @param   array  $segments  The segments of the URL to parse.
 *
 * @return  array  The URL attributes to be used by the application.
 *
 * @since   3.3
 * @deprecated  4.0  Use Class based routers instead
 */
function bannersParseRoute($segments)
{
	$router = new BannersRouter;

	return $router->parse($segments);
}
src/Service/Category.php000064400000001504151167156200011225
0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Service;

use Joomla\CMS\Categories\Categories;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Banners Component Category Tree
 *
 * @since  1.6
 */
class Category extends Categories
{
    /**
     * Constructor
     *
     * @param   array  $options  Array of options
     *
     * @since   1.6
     */
    public function __construct($options = [])
    {
        $options['table']     = '#__banners';
        $options['extension'] = 'com_banners';

        parent::__construct($options);
    }
}
src/Service/Router.php000064400000004364151167156200010737 0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Service;

use Joomla\CMS\Component\Router\RouterBase;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Routing class from com_banners
 *
 * @since  3.3
 */
class Router extends RouterBase
{
    /**
     * Build the route for the com_banners component
     *
     * @param   array  $query  An array of URL arguments
     *
     * @return  array  The URL arguments to use to assemble the subsequent
URL.
     *
     * @since   3.3
     */
    public function build(&$query)
    {
        $segments = [];

        if (isset($query['task'])) {
            $segments[] = $query['task'];
            unset($query['task']);
        }

        if (isset($query['id'])) {
            $segments[] = $query['id'];
            unset($query['id']);
        }

        $total = \count($segments);

        for ($i = 0; $i < $total; $i++) {
            $segments[$i] = str_replace(':', '-',
$segments[$i]);
        }

        return $segments;
    }

    /**
     * Parse the segments of a URL.
     *
     * @param   array  $segments  The segments of the URL to parse.
     *
     * @return  array  The URL attributes to be used by the application.
     *
     * @since   3.3
     */
    public function parse(&$segments)
    {
        $total = \count($segments);
        $vars  = [];

        for ($i = 0; $i < $total; $i++) {
            $segments[$i] = preg_replace('/-/', ':',
$segments[$i], 1);
        }

        // View is always the first element of the array
        $count = \count($segments);

        if ($count) {
            $count--;
            $segment = array_shift($segments);

            if (is_numeric($segment)) {
                $vars['id'] = $segment;
            } else {
                $vars['task'] = $segment;
            }
        }

        if ($count) {
            $segment = array_shift($segments);

            if (is_numeric($segment)) {
                $vars['id'] = $segment;
            }
        }

        return $vars;
    }
}
src/Helper/BannerHelper.php000064400000002672151167156200011643
0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Helper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Banner Helper Class
 *
 * @since  1.6
 *
 * @deprecated  5.1 will be removed in 7.0
 */
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, png or
webp, false otherwise
     *
     * @since   1.6
     *
     * @deprecated  5.1 will be removed in 7.0
     *              When testing the image file, use
Joomla\CMS\Helper\MediaHelper::isImage($url) for pixel-based image files
     *              in combination with
Joomla\CMS\Helper\MediaHelper::getMimeType($url) ===
'image/svg+xml' for vector based image files
     *              Be aware that the image url should first be sanitized
with the helper function
Joomla\CMS\HTML\HTMLHelper::cleanImageURL($imageurl)
     */
    public static function isImage($url)
    {
        $urlCheck = explode('?', $url);

        if (preg_match('#\.(?:bmp|gif|jpe?g|png|webp)$#i',
$urlCheck[0])) {
            return true;
        }

        return false;
    }
}
src/Model/BannerModel.php000064400000015034151167156210011302
0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Model;

use Joomla\CMS\Cache\Exception\CacheExceptionInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\Database\ParameterType;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Banner model for the Joomla Banners component.
 *
 * @since  1.5
 */
class BannerModel extends BaseDatabaseModel
{
    /**
     * Cached item object
     *
     * @var    object
     * @since  1.6
     */
    protected $_item;

    /**
     * Clicks the URL, incrementing the counter
     *
     * @return  void
     *
     * @since   1.5
     * @throws  \Exception
     */
    public function click()
    {
        $item = $this->getItem();

        if (empty($item)) {
            throw new
\Exception(Text::_('JERROR_PAGE_NOT_FOUND'), 404);
        }

        $id = (int) $this->getState('banner.id');

        // Update click count
        $db    = $this->getDatabase();
        $query = $db->getQuery(true);

        $query->update($db->quoteName('#__banners'))
            ->set($db->quoteName('clicks') . ' =
' . $db->quoteName('clicks') . ' + 1')
            ->where($db->quoteName('id') . ' =
:id')
            ->bind(':id', $id, ParameterType::INTEGER);

        $db->setQuery($query);

        try {
            $db->execute();
        } catch (\RuntimeException $e) {
            throw new \Exception($e->getMessage(), 500);
        }

        // Track clicks
        $trackClicks = $item->track_clicks;

        if ($trackClicks < 0 && $item->cid) {
            $trackClicks = $item->client_track_clicks;
        }

        if ($trackClicks < 0) {
            $config      =
ComponentHelper::getParams('com_banners');
            $trackClicks = $config->get('track_clicks');
        }

        if ($trackClicks > 0) {
            $trackDate = Factory::getDate()->format('Y-m-d
H:00:00');
            $trackDate = Factory::getDate($trackDate)->toSql();

            $query = $db->getQuery(true);

            $query->select($db->quoteName('count'))
                ->from($db->quoteName('#__banner_tracks'))
                ->where(
                    [
                        $db->quoteName('track_type') . '
= 2',
                        $db->quoteName('banner_id') . ' =
:id',
                        $db->quoteName('track_date') . '
= :trackDate',
                    ]
                )
                ->bind(':id', $id, ParameterType::INTEGER)
                ->bind(':trackDate', $trackDate);

            $db->setQuery($query);

            try {
                $db->execute();
            } catch (\RuntimeException $e) {
                throw new \Exception($e->getMessage(), 500);
            }

            $count = $db->loadResult();

            $query = $db->getQuery(true);

            if ($count) {
                // Update count
               
$query->update($db->quoteName('#__banner_tracks'))
                    ->set($db->quoteName('count') . '
= ' . $db->quoteName('count') . ' + 1')
                    ->where(
                        [
                            $db->quoteName('track_type') .
' = 2',
                            $db->quoteName('banner_id') .
' = :id',
                            $db->quoteName('track_date') .
' = :trackDate',
                        ]
                    )
                    ->bind(':id', $id, ParameterType::INTEGER)
                    ->bind(':trackDate', $trackDate);
            } else {
                // Insert new count
               
$query->insert($db->quoteName('#__banner_tracks'))
                    ->columns(
                        [
                            $db->quoteName('count'),
                            $db->quoteName('track_type'),
                            $db->quoteName('banner_id'),
                            $db->quoteName('track_date'),
                        ]
                    )
                    ->values('1, 2 , :id, :trackDate')
                    ->bind(':id', $id, ParameterType::INTEGER)
                    ->bind(':trackDate', $trackDate);
            }

            $db->setQuery($query);

            try {
                $db->execute();
            } catch (\RuntimeException $e) {
                throw new \Exception($e->getMessage(), 500);
            }
        }
    }

    /**
     * Get the data for a banner.
     *
     * @return  object
     *
     * @since   1.6
     */
    public function &getItem()
    {
        if (!isset($this->_item)) {
            /** @var \Joomla\CMS\Cache\Controller\CallbackController $cache
*/
            $cache = Factory::getCache('com_banners',
'callback');

            $id = (int) $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->getDatabase();

            $loader = function ($id) use ($db) {
                $query = $db->getQuery(true);

                $query->select(
                    [
                        $db->quoteName('a.clickurl'),
                        $db->quoteName('a.cid'),
                        $db->quoteName('a.track_clicks'),
                        $db->quoteName('cl.track_clicks',
'client_track_clicks'),
                    ]
                )
                    ->from($db->quoteName('#__banners',
'a'))
                    ->join('LEFT',
$db->quoteName('#__banner_clients', 'cl'),
$db->quoteName('cl.id') . ' = ' .
$db->quoteName('a.cid'))
                    ->where($db->quoteName('a.id') . '
= :id')
                    ->bind(':id', $id,
ParameterType::INTEGER);

                $db->setQuery($query);

                return $db->loadObject();
            };

            try {
                $this->_item = $cache->get($loader, [$id],
md5(__METHOD__ . $id));
            } catch (CacheExceptionInterface $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;
    }
}
src/Model/BannersModel.php000064400000034044151167156210011467
0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Model;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Banners model for the Joomla Banners component.
 *
 * @since  1.6
 */
class BannersModel extends ListModel
{
    /**
     * Method to get a store id based on model configuration state.
     *
     * This is necessary because the model is used by the component and
     * different modules that might need different sets of data or
different
     * ordering requirements.
     *
     * @param   string  $id  A prefix for the store id.
     *
     * @return  string  A store id.
     *
     * @since   1.6
     */
    protected function getStoreId($id = '')
    {
        // Compile the store id.
        $id .= ':' .
$this->getState('filter.search');
        $id .= ':' .
$this->getState('filter.tag_search');
        $id .= ':' .
$this->getState('filter.client_id');
        $id .= ':' .
serialize($this->getState('filter.category_id'));
        $id .= ':' .
serialize($this->getState('filter.keywords'));

        return parent::getStoreId($id);
    }

    /**
     * Method to get a DatabaseQuery object for retrieving the data set
from a database.
     *
     * @return  DatabaseQuery   A DatabaseQuery object to retrieve the data
set.
     *
     * @since   1.6
     */
    protected function getListQuery()
    {
        $db         = $this->getDatabase();
        $query      = $db->getQuery(true);
        $ordering   = $this->getState('filter.ordering');
        $tagSearch  = $this->getState('filter.tag_search');
        $cid        = (int)
$this->getState('filter.client_id');
        $categoryId = $this->getState('filter.category_id');
        $keywords   = $this->getState('filter.keywords');
        $randomise  = ($ordering === 'random');
        $nowDate    = Factory::getDate()->toSql();

        $query->select(
            [
                $db->quoteName('a.id'),
                $db->quoteName('a.type'),
                $db->quoteName('a.name'),
                $db->quoteName('a.clickurl'),
                $db->quoteName('a.sticky'),
                $db->quoteName('a.cid'),
                $db->quoteName('a.description'),
                $db->quoteName('a.params'),
                $db->quoteName('a.custombannercode'),
                $db->quoteName('a.track_impressions'),
                $db->quoteName('cl.track_impressions',
'client_track_impressions'),
            ]
        )
            ->from($db->quoteName('#__banners',
'a'))
            ->join('LEFT',
$db->quoteName('#__banner_clients', 'cl'),
$db->quoteName('cl.id') . ' = ' .
$db->quoteName('a.cid'))
            ->where($db->quoteName('a.state') . ' =
1')
            ->extendWhere(
                'AND',
                [
                    $db->quoteName('a.publish_up') . ' IS
NULL',
                    $db->quoteName('a.publish_up') . '
<= :nowDate1',
                ],
                'OR'
            )
            ->extendWhere(
                'AND',
                [
                    $db->quoteName('a.publish_down') . '
IS NULL',
                    $db->quoteName('a.publish_down') . '
>= :nowDate2',
                ],
                'OR'
            )
            ->extendWhere(
                'AND',
                [
                    $db->quoteName('a.imptotal') . ' =
0',
                    $db->quoteName('a.impmade') . ' <
' . $db->quoteName('a.imptotal'),
                ],
                'OR'
            )
            ->bind([':nowDate1', ':nowDate2'],
$nowDate);

        if ($cid) {
            $query->where(
                [
                    $db->quoteName('a.cid') . ' =
:clientId',
                    $db->quoteName('cl.state') . ' =
1',
                ]
            )
                ->bind(':clientId', $cid,
ParameterType::INTEGER);
        }

        // Filter by a single or group of categories
        if (is_numeric($categoryId)) {
            $categoryId = (int) $categoryId;
            $type       =
$this->getState('filter.category_id.include', true) ? ' =
' : ' <> ';

            // Add subcategory check
            if ($this->getState('filter.subcategories',
false)) {
                $levels = (int)
$this->getState('filter.max_category_levels', '1');

                // Create a subquery for the subcategory list
                $subQuery = $db->getQuery(true);
                $subQuery->select($db->quoteName('sub.id'))
                    ->from($db->quoteName('#__categories',
'sub'))
                    ->join(
                        'INNER',
                        $db->quoteName('#__categories',
'this'),
                        $db->quoteName('sub.lft') . '
> ' . $db->quoteName('this.lft')
                        . ' AND ' .
$db->quoteName('sub.rgt') . ' < ' .
$db->quoteName('this.rgt')
                    )
                    ->where(
                        [
                            $db->quoteName('this.id') . '
= :categoryId1',
                            $db->quoteName('sub.level') .
' <= ' . $db->quoteName('this.level') . ' +
:levels',
                        ]
                    );

                // Add the subquery to the main query
                $query->extendWhere(
                    'AND',
                    [
                        $db->quoteName('a.catid') . $type .
':categoryId2',
                        $db->quoteName('a.catid') . ' IN
(' . $subQuery . ')',
                    ],
                    'OR'
                )
                    ->bind([':categoryId1',
':categoryId2'], $categoryId, ParameterType::INTEGER)
                    ->bind(':levels', $levels,
ParameterType::INTEGER);
            } else {
                $query->where($db->quoteName('a.catid') .
$type . ':categoryId')
                    ->bind(':categoryId', $categoryId,
ParameterType::INTEGER);
            }
        } elseif (\is_array($categoryId) && (\count($categoryId)
> 0)) {
            $categoryId = ArrayHelper::toInteger($categoryId);

            if ($this->getState('filter.category_id.include',
true)) {
                $query->whereIn($db->quoteName('a.catid'),
$categoryId);
            } else {
               
$query->whereNotIn($db->quoteName('a.catid'), $categoryId);
            }
        }

        if ($tagSearch) {
            if (!$keywords) {
                // No keywords, select nothing.
                $query->where('0 != 0');
            } else {
                $temp   = [];
                $config =
ComponentHelper::getParams('com_banners');
                $prefix = $config->get('metakey_prefix');

                if ($categoryId) {
                    $query->join('LEFT',
$db->quoteName('#__categories', 'cat'),
$db->quoteName('a.catid') . ' = ' .
$db->quoteName('cat.id'));
                }

                foreach ($keywords as $key => $keyword) {
                    $regexp       = '[[:<:]]' . $keyword .
'[[:>:]]';
                    $valuesToBind = [$keyword, $keyword, $regexp];

                    if ($cid) {
                        $valuesToBind[] = $regexp;
                    }

                    if ($categoryId) {
                        $valuesToBind[] = $regexp;
                    }

                    // Because values to $query->bind() are passed by
reference, using $query->bindArray() here instead to prevent
overwriting.
                    $bounded = $query->bindArray($valuesToBind,
ParameterType::STRING);

                    $condition1 =
$db->quoteName('a.own_prefix') . ' = 1'
                        . ' AND ' .
$db->quoteName('a.metakey_prefix')
                        . ' = SUBSTRING(' . $bounded[0] .
',1,LENGTH(' . $db->quoteName('a.metakey_prefix') .
'))'
                        . ' OR ' .
$db->quoteName('a.own_prefix') . ' = 0'
                        . ' AND ' .
$db->quoteName('cl.own_prefix') . ' = 1'
                        . ' AND ' .
$db->quoteName('cl.metakey_prefix')
                        . ' = SUBSTRING(' . $bounded[1] .
',1,LENGTH(' . $db->quoteName('cl.metakey_prefix') .
'))'
                        . ' OR ' .
$db->quoteName('a.own_prefix') . ' = 0'
                        . ' AND ' .
$db->quoteName('cl.own_prefix') . ' = 0'
                        . ' AND ' . ($prefix == substr($keyword,
0, \strlen($prefix)) ? '0 = 0' : '0 != 0');

                    $condition2 = $db->quoteName('a.metakey')
. ' ' . $query->regexp($bounded[2]);

                    if ($cid) {
                        $condition2 .= ' OR ' .
$db->quoteName('cl.metakey') . ' ' .
$query->regexp($bounded[3]) . ' ';
                    }

                    if ($categoryId) {
                        $condition2 .= ' OR ' .
$db->quoteName('cat.metakey') . ' ' .
$query->regexp($bounded[4]) . ' ';
                    }

                    $temp[] = "($condition1) AND ($condition2)";
                }

                $query->where('(' . implode(' OR ',
$temp) . ')');
            }
        }

        // Filter by language
        if ($this->getState('filter.language')) {
            $query->whereIn($db->quoteName('a.language'),
[Factory::getLanguage()->getTag(), '*'],
ParameterType::STRING);
        }

        $query->order($db->quoteName('a.sticky') . '
DESC, ' . ($randomise ? $query->rand() :
$db->quoteName('a.ordering')));

        return $query;
    }

    /**
     * Get a list of banners.
     *
     * @return  array
     *
     * @since   1.6
     */
    public function getItems()
    {
        if ($this->getState('filter.tag_search')) {
            // Filter out empty keywords.
            $keywords =
array_values(array_filter(array_map('trim',
$this->getState('filter.keywords')), 'strlen'));

            // Re-set state before running the query.
            $this->setState('filter.keywords', $keywords);

            // If no keywords are provided, avoid running the query.
            if (!$keywords) {
                $this->cache['items'] = [];

                return $this->cache['items'];
            }
        }

        if (!isset($this->cache['items'])) {
            $this->cache['items'] = parent::getItems();

            foreach ($this->cache['items'] as &$item) {
                $item->params = new Registry($item->params);
            }
        }

        return $this->cache['items'];
    }

    /**
     * Makes impressions on a list of banners
     *
     * @return  void
     *
     * @since   1.6
     * @throws  \Exception
     */
    public function impress()
    {
        $trackDate = Factory::getDate()->format('Y-m-d
H:00:00');
        $trackDate = Factory::getDate($trackDate)->toSql();
        $items     = $this->getItems();
        $db        = $this->getDatabase();
        $bid       = [];

        if (!\count($items)) {
            return;
        }

        foreach ($items as $item) {
            $bid[] = (int) $item->id;
        }

        // Increment impression made
        $query = $db->getQuery(true);
        $query->update($db->quoteName('#__banners'))
            ->set($db->quoteName('impmade') . ' =
' . $db->quoteName('impmade') . ' + 1')
            ->whereIn($db->quoteName('id'), $bid);
        $db->setQuery($query);

        try {
            $db->execute();
        } catch (ExecutionFailureException $e) {
            throw new \Exception($e->getMessage(), 500);
        }

        foreach ($items as $item) {
            // Track impressions
            $trackImpressions = $item->track_impressions;

            if ($trackImpressions < 0 && $item->cid) {
                $trackImpressions = $item->client_track_impressions;
            }

            if ($trackImpressions < 0) {
                $config           =
ComponentHelper::getParams('com_banners');
                $trackImpressions =
$config->get('track_impressions');
            }

            if ($trackImpressions > 0) {
                // Is track already created?
                // Update count
                $query = $db->getQuery(true);
               
$query->update($db->quoteName('#__banner_tracks'))
                    ->set($db->quoteName('count') . '
= ' . $db->quoteName('count') . ' + 1')
                    ->where(
                        [
                            $db->quoteName('track_type') .
' = 1',
                            $db->quoteName('banner_id') .
' = :id',
                            $db->quoteName('track_date') .
' = :trackDate',
                        ]
                    )
                    ->bind(':id', $item->id,
ParameterType::INTEGER)
                    ->bind(':trackDate', $trackDate);

                $db->setQuery($query);

                try {
                    $db->execute();
                } catch (ExecutionFailureException $e) {
                    throw new \Exception($e->getMessage(), 500);
                }

                if ($db->getAffectedRows() === 0) {
                    // Insert new count
                    $query = $db->getQuery(true);
                   
$query->insert($db->quoteName('#__banner_tracks'))
                        ->columns(
                            [
                                $db->quoteName('count'),
                                $db->quoteName('track_type'),
                                $db->quoteName('banner_id'),
                                $db->quoteName('track_date'),
                            ]
                        )
                        ->values('1, 1, :id, :trackDate')
                        ->bind(':id', $item->id,
ParameterType::INTEGER)
                        ->bind(':trackDate', $trackDate);

                    $db->setQuery($query);

                    try {
                        $db->execute();
                    } catch (ExecutionFailureException $e) {
                        throw new \Exception($e->getMessage(), 500);
                    }
                }
            }
        }
    }
}
src/Controller/DisplayController.php000064400000002040151167156210013641
0ustar00<?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
 */

namespace Joomla\Component\Banners\Site\Controller;

use Joomla\CMS\MVC\Controller\BaseController;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Banners Controller
 *
 * @since  1.5
 */
class DisplayController extends BaseController
{
    /**
     * Method when a banner is clicked on.
     *
     * @return  void
     *
     * @since   1.5
     */
    public function click()
    {
        $id = $this->input->getInt('id', 0);

        if ($id) {
            /** @var \Joomla\Component\Banners\Site\Model\BannerModel
$model */
            $model = $this->getModel('Banner',
'Site', ['ignore_request' => true]);
            $model->setState('banner.id', $id);
            $model->click();
            $this->setRedirect($model->getUrl());
        }
    }
}