Spade
Mini Shell
Article.php000064400000002513151165736540006656 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Model\Model;
use OSL\Utils\Database as DatabaseUtils;
use Ossolution\HelpdeskPro\Site\Helper\Helper as HelpdeskproHelper;
defined('_JEXEC') or die;
class Article extends Model
{
/**
* Initialize the model, add new states
*/
protected function initialize()
{
$this->state->insert('id', 'int', 0);
}
/**
*
*/
public function getData()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from('#__helpdeskpro_articles')
->where('id = ' . $this->state->id)
->where('published = 1');
if ($fieldSuffix = HelpdeskproHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, array('title',
'text'), $fieldSuffix);
}
$db->setQuery($query);
return $db->loadObject();
}
public function hits()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->update('#__helpdeskpro_articles')
->set('hits = hits + 1')
->where('id = ' . $this->state->id);
$db->setQuery($query);
$db->execute();
}
}Articles.php000064400000003352151165736540007043 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Container\Container;
use OSL\Model\ListModel;
use OSL\Utils\Database as DatabaseUtils;
use OSSolution\HelpdeskPro\Site\Helper\Helper as HelpdeskProHelper;
defined('_JEXEC') or die;
class Articles extends ListModel
{
protected $clearJoin = false;
/**
* Constructor.
*
* @param Container $container
* @param array $options
*/
public function __construct(Container $container, $options = [])
{
$options['search_fields'] = ['tbl.id',
'tbl.title', 'tbl.text'];
$options['remember_states'] = true;
parent::__construct($container, $options);
}
/**
* Initialize the model, add new states
*/
protected function initialize()
{
$this->state->insert('id', 'int', 0);
}
/**
* Build the query object which is used to get list of records from
database
*
* @return \JDatabaseQuery
*/
protected function buildListQuery()
{
$query = parent::buildListQuery();
if ($fieldSuffix = HelpdeskProHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, ['tbl.title'],
$fieldSuffix);
}
$query->innerJoin('#__helpdeskpro_categories AS c ON
tbl.category_id = c.id')
->where('tbl.published = 1')
->where('c.published = 1')
->where('c.access IN (' . implode(',',
$this->container->user->getAuthorisedViewLevels()) .
')');
if ($this->state->id)
{
$query->where('tbl.category_id = ' .
$this->state->id);
}
return $query;
}
}Categories.php000064400000004021151165736540007354 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Model\ListModel;
use OSL\Utils\Database as DatabaseUtils;
use Ossolution\HelpdeskPro\Site\Helper\Helper as HelpdeskproHelper;
defined('_JEXEC') or die;
class Categories extends ListModel
{
/**
* Clear join clause for getTotal method
*
* @var bool
*/
protected $clearJoin = false;
/**
* Build the query object which is used to get list of records from
database
*
* @return \JDatabaseQuery
*/
protected function buildListQuery()
{
$query = parent::buildListQuery();
$user = $this->container->user;
$query->select('COUNT(b.id) AS total_articles')
->innerJoin('#__helpdeskpro_articles AS b ON tbl.id =
b.category_id')
->where('tbl.published = 1')
->where('tbl.access IN (' . implode(',',
$user->getAuthorisedViewLevels()) . ')')
->where('b.published = 1')
->group('tbl.id');
if ($fieldSuffix = HelpdeskproHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, ['tbl.title'],
$fieldSuffix);
}
return $query;
}
/**
* Get list of articles belong to each category, max 10 articles per
category
*
* @param array $rows
*/
protected function beforeReturnData($rows)
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$fieldSuffix = HelpdeskproHelper::getFieldSuffix();
$query->select('id, title')
->from('#__helpdeskpro_articles')
->order('ordering');
if ($fieldSuffix)
{
DatabaseUtils::getMultilingualFields($query, ['title'],
$fieldSuffix);
}
foreach ($rows as $row)
{
$query->where('category_id = ' . $row->id)
->where('published = 1');
$db->setQuery($query, 0, 10);
$row->articles = $db->loadObjectList();
$query->clear('where');
}
}
}CategoriesModel.php000064400000010304151176062320010324 0ustar00<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2008 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* This models supports retrieving lists of contact categories.
*
* @since 1.6
*/
class CategoriesModel extends ListModel
{
/**
* Model context string.
*
* @var string
*/
public $_context = 'com_contact.categories';
/**
* The category context (allows other extensions to derived from this
model).
*
* @var string
*/
protected $_extension = 'com_contact';
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
private $_parent = null;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
private $_items = null;
/**
* 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 = null, $direction = null)
{
$app = Factory::getApplication();
$this->setState('filter.extension',
$this->_extension);
// Get the parent id if defined.
$parentId = $app->getInput()->getInt('id');
$this->setState('filter.parentId', $parentId);
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('filter.published', 1);
$this->setState('filter.access', true);
}
/**
* 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.extension');
$id .= ':' .
$this->getState('filter.published');
$id .= ':' .
$this->getState('filter.access');
$id .= ':' .
$this->getState('filter.parentId');
return parent::getStoreId($id);
}
/**
* Redefine the function and add some properties to make the styling
easier
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
if ($this->_items === null) {
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
if ($active) {
$params = $active->getParams();
} else {
$params = new Registry();
}
$options = [];
$options['countItems'] =
$params->get('show_cat_items_cat', 1) ||
!$params->get('show_empty_categories_cat', 0);
$categories =
Categories::getInstance('Contact', $options);
$this->_parent =
$categories->get($this->getState('filter.parentId',
'root'));
if (\is_object($this->_parent)) {
$this->_items = $this->_parent->getChildren();
} else {
$this->_items = false;
}
}
return $this->_items;
}
/**
* Gets the id of the parent category for the selected list of
categories
*
* @return integer The id of the parent category
*
* @since 1.6.0
*/
public function getParent()
{
if (!\is_object($this->_parent)) {
$this->getItems();
}
return $this->_parent;
}
}
ContactModel.php000064400000040014151176062330007634 0ustar00<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @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\Contact\Site\Model;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Single item model for a contact
*
* @package Joomla.Site
* @subpackage com_contact
* @since 1.5
*/
class ContactModel extends FormModel
{
/**
* The name of the view for a single item
*
* @var string
* @since 1.6
*/
protected $view_item = 'contact';
/**
* A loaded item
*
* @var \stdClass[]
* @since 1.6
*/
protected $_item = [];
/**
* Model context string.
*
* @var string
*/
protected $_context = 'com_contact.contact';
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
/** @var SiteApplication $app */
$app = Factory::getContainer()->get(SiteApplication::class);
if (Factory::getApplication()->isClient('api')) {
// @todo: remove this
$app->loadLanguage();
$this->setState('contact.id',
Factory::getApplication()->getInput()->post->getInt('id'));
} else {
$this->setState('contact.id',
$app->getInput()->getInt('id'));
}
$this->setState('params', $app->getParams());
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
}
/**
* Method to get the contact form.
* The base form is loaded from XML and then an event is fired
*
* @param array $data An optional array of data for the form
to interrogate.
* @param boolean $loadData True if the form is to load its own
data (default case), false if not.
*
* @return Form A Form object on success, false on failure
*
* @since 1.6
*/
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm('com_contact.contact',
'contact', ['control' => 'jform',
'load_data' => $loadData]);
if (empty($form)) {
return false;
}
$temp = clone $this->getState('params');
$contact =
$this->getItem($this->getState('contact.id'));
$active =
Factory::getContainer()->get(SiteApplication::class)->getMenu()->getActive();
if ($active) {
// If the current view is the active item and a contact view
for this contact, then the menu item params take priority
if (strpos($active->link, 'view=contact')
&& strpos($active->link, '&id=' . (int)
$contact->id)) {
// $contact->params are the contact params, $temp are
the menu item params
// Merge so that the menu item params take priority
$contact->params->merge($temp);
} else {
// Current view is not a single contact, so the contact
params take priority here
// Merge the menu item params with the contact params so
that the contact params take priority
$temp->merge($contact->params);
$contact->params = $temp;
}
} else {
// Merge so that contact params take priority
$temp->merge($contact->params);
$contact->params = $temp;
}
if (!$contact->params->get('show_email_copy', 0)) {
$form->removeField('contact_email_copy');
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 1.6.2
*/
protected function loadFormData()
{
$data = (array)
Factory::getApplication()->getUserState('com_contact.contact.data',
[]);
if (empty($data['language']) &&
Multilanguage::isEnabled()) {
$data['language'] =
Factory::getLanguage()->getTag();
}
// Add contact catid to contact form data, so fields plugin can
work properly
if (empty($data['catid'])) {
$data['catid'] = $this->getItem()->catid;
}
$this->preprocessData('com_contact.contact', $data);
return $data;
}
/**
* Gets a contact
*
* @param integer $pk Id for the contact
*
* @return mixed \stdClass or null
*
* @since 1.6.0
*/
public function getItem($pk = null)
{
$pk = $pk ?: (int) $this->getState('contact.id');
if (!isset($this->_item[$pk])) {
try {
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select($this->getState('item.select',
'a.*'))
->select($this->getSlugColumn($query,
'a.id', 'a.alias') . ' AS slug')
->select($this->getSlugColumn($query,
'c.id', 'c.alias') . ' AS catslug')
->from($db->quoteName('#__contact_details', 'a'))
// Join on category table.
->select('c.title AS category_title, c.alias AS
category_alias, c.access AS category_access')
->leftJoin($db->quoteName('#__categories', 'c'),
'c.id = a.catid')
// Join over the categories to get parent category
titles
->select('parent.title AS parent_title,
parent.id AS parent_id, parent.path AS parent_route, parent.alias AS
parent_alias')
->leftJoin($db->quoteName('#__categories',
'parent'), 'parent.id = c.parent_id')
->where($db->quoteName('a.id') . '
= :id')
->bind(':id', $pk,
ParameterType::INTEGER);
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
// Filter by published state.
$published =
$this->getState('filter.published');
$archived =
$this->getState('filter.archived');
if (is_numeric($published)) {
$queryString =
$db->quoteName('a.published') . ' = :published';
if ($archived !== null) {
$queryString = '(' . $queryString .
' OR ' . $db->quoteName('a.published') . ' =
:archived)';
$query->bind(':archived', $archived,
ParameterType::INTEGER);
}
$query->where($queryString)
->where('(' .
$db->quoteName('a.publish_up') . ' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down') . ' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':published', $published,
ParameterType::INTEGER)
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
$db->setQuery($query);
$data = $db->loadObject();
if (empty($data)) {
throw new
\Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
}
// Check for published state if filter set.
if ((is_numeric($published) || is_numeric($archived))
&& (($data->published != $published) &&
($data->published != $archived))) {
throw new
\Exception(Text::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404);
}
/**
* In case some entity params have been set to "use
global", those are
* represented as an empty string and must be
"overridden" by merging
* the component and / or menu params here.
*/
$registry = new Registry($data->params);
$data->params = clone
$this->getState('params');
$data->params->merge($registry);
$registry = new Registry($data->metadata);
$data->metadata = $registry;
// Some contexts may not use tags data at all, so we allow
callers to disable loading tag data
if ($this->getState('load_tags', true)) {
$data->tags = new TagsHelper();
$data->tags->getItemTags('com_contact.contact',
$data->id);
}
// Compute access permissions.
if (($access =
$this->getState('filter.access'))) {
// If the access filter has been set, we already know
this user can view.
$data->params->set('access-view',
true);
} else {
// If no access filter is set, the layout takes some
responsibility for display of limited information.
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
if ($data->catid == 0 || $data->category_access
=== null) {
$data->params->set('access-view',
\in_array($data->access, $groups));
} else {
$data->params->set('access-view',
\in_array($data->access, $groups) &&
\in_array($data->category_access, $groups));
}
}
$this->_item[$pk] = $data;
} catch (\Exception $e) {
if ($e->getCode() == 404) {
// Need to go through the error handler to allow
Redirect to work.
throw $e;
}
$this->setError($e);
$this->_item[$pk] = false;
}
}
if ($this->_item[$pk]) {
$this->buildContactExtendedData($this->_item[$pk]);
}
return $this->_item[$pk];
}
/**
* Load extended data (profile, articles) for a contact
*
* @param object $contact The contact object
*
* @return void
*/
protected function buildContactExtendedData($contact)
{
$db = $this->getDatabase();
$nowDate = Factory::getDate()->toSql();
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
$published = $this->getState('filter.published');
$query = $db->getQuery(true);
// If we are showing a contact list, then the contact parameters
take priority
// So merge the contact parameters with the merged parameters
if
($this->getState('params')->get('show_contact_list'))
{
$this->getState('params')->merge($contact->params);
}
// Get the com_content articles by the linked user
if ((int) $contact->user_id &&
$this->getState('params')->get('show_articles'))
{
$query->select('a.id')
->select('a.title')
->select('a.state')
->select('a.access')
->select('a.catid')
->select('a.created')
->select('a.language')
->select('a.publish_up')
->select('a.introtext')
->select('a.images')
->select($this->getSlugColumn($query,
'a.id', 'a.alias') . ' AS slug')
->select($this->getSlugColumn($query,
'c.id', 'c.alias') . ' AS catslug')
->from($db->quoteName('#__content',
'a'))
->leftJoin($db->quoteName('#__categories',
'c') . ' ON a.catid = c.id')
->where($db->quoteName('a.created_by') .
' = :created_by')
->whereIn($db->quoteName('a.access'),
$groups)
->bind(':created_by', $contact->user_id,
ParameterType::INTEGER)
->order('a.publish_up DESC');
// Filter per language if plugin published
if (Multilanguage::isEnabled()) {
$language = [Factory::getLanguage()->getTag(),
'*'];
$query->whereIn($db->quoteName('a.language'), $language,
ParameterType::STRING);
}
if (is_numeric($published)) {
$query->where('a.state IN (1,2)')
->where('(' .
$db->quoteName('a.publish_up') . ' IS NULL' .
' OR ' .
$db->quoteName('a.publish_up') . ' <= :now1)')
->where('(' .
$db->quoteName('a.publish_down') . ' IS NULL' .
' OR ' .
$db->quoteName('a.publish_down') . ' >= :now2)')
->bind([':now1', ':now2'],
$nowDate);
}
// Number of articles to display from config/menu params
$articles_display_num =
$this->getState('params')->get('articles_display_num',
10);
// Use contact setting?
if ($articles_display_num === 'use_contact') {
$articles_display_num =
$contact->params->get('articles_display_num', 10);
// Use global?
if ((string) $articles_display_num === '') {
$articles_display_num =
ComponentHelper::getParams('com_contact')->get('articles_display_num',
10);
}
}
$query->setLimit((int) $articles_display_num);
$db->setQuery($query);
$contact->articles = $db->loadObjectList();
} else {
$contact->articles = null;
}
// Get the profile information for the linked user
$userModel =
$this->bootComponent('com_users')->getMVCFactory()
->createModel('User', 'Administrator',
['ignore_request' => true]);
$data = $userModel->getItem((int) $contact->user_id);
PluginHelper::importPlugin('user');
// Get the form.
Form::addFormPath(JPATH_SITE .
'/components/com_users/forms');
$form = Form::getInstance('com_users.profile',
'profile');
// Trigger the form preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareForm',
[$form, $data]);
// Trigger the data preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareData',
['com_users.profile', $data]);
// Load the data into the form after the plugins have operated.
$form->bind($data);
$contact->profile = $form;
}
/**
* Generate column expression for slug or catslug.
*
* @param QueryInterface $query Current query instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
*
* @return string
*
* @since 4.0.0
*/
private function getSlugColumn($query, $id, $alias)
{
return 'CASE WHEN '
. $query->charLength($alias, '!=', '0')
. ' THEN '
. $query->concatenate([$query->castAsChar($id), $alias],
':')
. ' ELSE '
. $query->castAsChar($id) . ' END';
}
/**
* Increment the hit counter for the contact.
*
* @param integer $pk Optional primary key of the contact to
increment.
*
* @return boolean True if successful; false otherwise and internal
error set.
*
* @since 3.0
*/
public function hit($pk = 0)
{
$input = Factory::getApplication()->getInput();
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount) {
$pk = $pk ?: (int) $this->getState('contact.id');
$table = $this->getTable('Contact');
$table->hit($pk);
}
return true;
}
}
FeaturedModel.php000064400000015122151176062330010002 0ustar00<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2010 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Featured contact model class.
*
* @since 1.6.0
*/
class FeaturedModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of
configuration settings.
*
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'name', 'a.name',
'con_position', 'a.con_position',
'suburb', 'a.suburb',
'state', 'a.state',
'country', 'a.country',
'ordering', 'a.ordering',
];
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
// Convert the params field into an object, saving original in
_params
for ($i = 0, $n = \count($items); $i < $n; $i++) {
$item = &$items[$i];
if (!isset($this->_params)) {
$item->params = new Registry($item->params);
}
}
return $items;
}
/**
* Method to build an SQL query to load the list data.
*
* @return DatabaseQuery An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select required fields from the categories.
$query->select($this->getState('list.select',
'a.*'))
->from($db->quoteName('#__contact_details',
'a'))
->where($db->quoteName('a.featured') . ' =
1')
->whereIn($db->quoteName('a.access'), $groups)
->innerJoin($db->quoteName('#__categories',
'c') . ' ON c.id = a.catid')
->whereIn($db->quoteName('c.access'), $groups);
// Filter by category.
if ($categoryId = $this->getState('category.id')) {
$query->where($db->quoteName('a.catid') .
' = :catid');
$query->bind(':catid', $categoryId,
ParameterType::INTEGER);
}
$query->select('c.published as cat_published, c.published
AS parents_published')
->where('c.published = 1');
// Filter by state
$state = $this->getState('filter.published');
if (is_numeric($state)) {
$query->where($db->quoteName('a.published') .
' = :published');
$query->bind(':published', $state,
ParameterType::INTEGER);
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
$query->where('(' .
$db->quoteName('a.publish_up') .
' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down') .
' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by search in title
$search = $this->getState('list.filter');
// Filter by search in title
if (!empty($search)) {
$search = '%' . trim($search) . '%';
$query->where($db->quoteName('a.name') . '
LIKE :name ');
$query->bind(':name', $search);
}
// Filter by language
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'),
[Factory::getLanguage()->getTag(), '*'],
ParameterType::STRING);
}
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering',
'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));
return $query;
}
/**
* 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 = null, $direction = null)
{
$app = Factory::getApplication();
$input = $app->getInput();
$params = ComponentHelper::getParams('com_contact');
// List state information
$limit =
$app->getUserStateFromRequest('global.list.limit',
'limit', $app->get('list_limit'), 'uint');
$this->setState('list.limit', $limit);
$limitstart = $input->get('limitstart', 0,
'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$this->setState('list.filter',
$input->getString('filter-search'));
$orderCol = $input->get('filter_order',
'ordering');
if (!\in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $input->get('filter_order_Dir',
'ASC');
if (!\in_array(strtoupper($listOrder), ['ASC',
'DESC', ''])) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
// Limit to published for people who can't edit or
edit.state.
$this->setState('filter.published', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language',
Multilanguage::isEnabled());
// Load the parameters.
$this->setState('params', $params);
}
}
CategoryModel.php000064400000037173151176062330010032 0ustar00<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @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\Contact\Site\Model;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Categories\CategoryNode;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Single item model for a contact
*
* @package Joomla.Site
* @subpackage com_contact
* @since 1.5
*/
class CategoryModel extends ListModel
{
/**
* Category item data
*
* @var CategoryNode
*/
protected $_item;
/**
* Category left and right of this one
*
* @var CategoryNode[]|null
*/
protected $_siblings;
/**
* Array of child-categories
*
* @var CategoryNode[]|null
*/
protected $_children;
/**
* Parent category of the current one
*
* @var CategoryNode|null
*/
protected $_parent;
/**
* The category that applies.
*
* @var object
*/
protected $_category;
/**
* The list of other contact categories.
*
* @var array
*/
protected $_categories;
/**
* Constructor.
*
* @param array $config An optional associative array of
configuration settings.
*
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'name', 'a.name',
'con_position', 'a.con_position',
'suburb', 'a.suburb',
'state', 'a.state',
'country', 'a.country',
'ordering', 'a.ordering',
'sortname',
'sortname1', 'a.sortname1',
'sortname2', 'a.sortname2',
'sortname3', 'a.sortname3',
'featuredordering', 'a.featured',
];
}
parent::__construct($config);
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
if ($items === false) {
return false;
}
$taggedItems = [];
// Convert the params field into an object, saving original in
_params
foreach ($items as $item) {
if (!isset($this->_params)) {
$item->params = new Registry($item->params);
}
// Some contexts may not use tags data at all, so we allow
callers to disable loading tag data
if ($this->getState('load_tags', true)) {
$item->tags = new TagsHelper();
$taggedItems[$item->id] = $item;
}
}
// Load tags of all items.
if ($taggedItems) {
$tagsHelper = new TagsHelper();
$itemIds = array_keys($taggedItems);
foreach
($tagsHelper->getMultipleItemTags('com_contact.contact',
$itemIds) as $id => $tags) {
$taggedItems[$id]->tags->itemTags = $tags;
}
}
return $items;
}
/**
* Method to build an SQL query to load the list data.
*
* @return \Joomla\Database\DatabaseQuery An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
$user = $this->getCurrentUser();
$groups = $user->getAuthorisedViewLevels();
// Create a new query object.
$db = $this->getDatabase();
/** @var \Joomla\Database\DatabaseQuery $query */
$query = $db->getQuery(true);
$query->select($this->getState('list.select',
'a.*'))
->select($this->getSlugColumn($query, 'a.id',
'a.alias') . ' AS slug')
->select($this->getSlugColumn($query, 'c.id',
'c.alias') . ' AS catslug')
/**
* @todo: we actually should be doing it but it's wrong this
way
* . ' CASE WHEN CHAR_LENGTH(a.alias) THEN
CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '
* . ' CASE WHEN CHAR_LENGTH(c.alias) THEN
CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug ');
*/
->from($db->quoteName('#__contact_details',
'a'))
->leftJoin($db->quoteName('#__categories',
'c') . ' ON c.id = a.catid')
->whereIn($db->quoteName('a.access'), $groups);
// Filter by category.
$categoryId = (int)
$this->getState('category.id');
$includeSubcategories = (int)
$this->getState('filter.max_category_levels', 1) !== 0;
if ($includeSubcategories) {
$levels = (int)
$this->getState('filter.max_category_levels', 1);
// Create a subquery for the subcategory list
$subQuery = $db->getQuery(true)
->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') . '
= :subCategoryId');
$query->bind(':subCategoryId', $categoryId,
ParameterType::INTEGER);
if ($levels >= 0) {
$subQuery->where($db->quoteName('sub.level') . ' <=
' . $db->quoteName('this.level') . ' +
:levels');
$query->bind(':levels', $levels,
ParameterType::INTEGER);
}
// Add the subquery to the main query
$query->where(
'(' . $db->quoteName('a.catid') .
' = :categoryId OR ' . $db->quoteName('a.catid') .
' IN (' . $subQuery . '))'
);
$query->bind(':categoryId', $categoryId,
ParameterType::INTEGER);
} else {
$query->where($db->quoteName('a.catid') .
' = :acatid')
->whereIn($db->quoteName('c.access'),
$groups);
$query->bind(':acatid', $categoryId,
ParameterType::INTEGER);
}
// Join over the users for the author and modified_by names.
$query->select("CASE WHEN a.created_by_alias > '
' THEN a.created_by_alias ELSE ua.name END AS author")
->select('ua.email AS author_email')
->leftJoin($db->quoteName('#__users',
'ua') . ' ON ua.id = a.created_by')
->leftJoin($db->quoteName('#__users',
'uam') . ' ON uam.id = a.modified_by');
// Filter by state
$state = $this->getState('filter.published');
if (is_numeric($state)) {
$query->where($db->quoteName('a.published') .
' = :published');
$query->bind(':published', $state,
ParameterType::INTEGER);
} else {
$query->whereIn($db->quoteName('c.published'),
[0,1,2]);
}
// Filter by start and end dates.
$nowDate = Factory::getDate()->toSql();
if ($this->getState('filter.publish_date')) {
$query->where('(' .
$db->quoteName('a.publish_up')
. ' IS NULL OR ' .
$db->quoteName('a.publish_up') . ' <=
:publish_up)')
->where('(' .
$db->quoteName('a.publish_down')
. ' IS NULL OR ' .
$db->quoteName('a.publish_down') . ' >=
:publish_down)')
->bind(':publish_up', $nowDate)
->bind(':publish_down', $nowDate);
}
// Filter by search in title
$search = $this->getState('list.filter');
if (!empty($search)) {
$search = '%' . trim($search) . '%';
$query->where($db->quoteName('a.name') . '
LIKE :name ');
$query->bind(':name', $search);
}
// Filter on the language.
if ($this->getState('filter.language')) {
$query->whereIn($db->quoteName('a.language'),
[Factory::getApplication()->getLanguage()->getTag(), '*'],
ParameterType::STRING);
}
// Set sortname ordering if selected
if ($this->getState('list.ordering') ===
'sortname') {
$query->order($db->escape('a.sortname1') .
' ' .
$db->escape($this->getState('list.direction',
'ASC')))
->order($db->escape('a.sortname2') . '
' . $db->escape($this->getState('list.direction',
'ASC')))
->order($db->escape('a.sortname3') . '
' . $db->escape($this->getState('list.direction',
'ASC')));
} elseif ($this->getState('list.ordering') ===
'featuredordering') {
$query->order($db->escape('a.featured') .
' DESC')
->order($db->escape('a.ordering') . '
ASC');
} else {
$query->order($db->escape($this->getState('list.ordering',
'a.ordering')) . ' ' .
$db->escape($this->getState('list.direction',
'ASC')));
}
return $query;
}
/**
* 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 = null, $direction = null)
{
$app = Factory::getApplication();
$input = $app->getInput();
$params = $app->getParams();
$this->setState('params', $params);
// List state information
$format = $input->getWord('format');
if ($format === 'feed') {
$limit = $app->get('feed_limit');
} else {
$limit = $app->getUserStateFromRequest(
'com_contact.category.list.limit',
'limit',
$params->get('contacts_display_num',
$app->get('list_limit')),
'uint'
);
}
$this->setState('list.limit', $limit);
$limitstart = $input->get('limitstart', 0,
'uint');
$this->setState('list.start', $limitstart);
// Optional filter text
$itemid = $input->get('Itemid', 0, 'int');
$search =
$app->getUserStateFromRequest('com_contact.category.list.' .
$itemid . '.filter-search', 'filter-search',
'', 'string');
$this->setState('list.filter', $search);
$orderCol = $input->get('filter_order',
$params->get('initial_sort', 'ordering'));
if (!\in_array($orderCol, $this->filter_fields)) {
$orderCol = 'ordering';
}
$this->setState('list.ordering', $orderCol);
$listOrder = $input->get('filter_order_Dir',
'ASC');
if (!\in_array(strtoupper($listOrder), ['ASC',
'DESC', ''])) {
$listOrder = 'ASC';
}
$this->setState('list.direction', $listOrder);
$id = $input->get('id', 0, 'int');
$this->setState('category.id', $id);
$this->setState('filter.max_category_levels',
$params->get('maxLevel', 1));
$user = $this->getCurrentUser();
if ((!$user->authorise('core.edit.state',
'com_contact')) &&
(!$user->authorise('core.edit', 'com_contact'))) {
// Limit to published for people who can't edit or
edit.state.
$this->setState('filter.published', 1);
// Filter by start and end dates.
$this->setState('filter.publish_date', true);
}
$this->setState('filter.language',
Multilanguage::isEnabled());
}
/**
* Method to get category data for the current category
*
* @return object The category object
*
* @since 1.5
*/
public function getCategory()
{
if (!\is_object($this->_item)) {
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
if ($active) {
$params = $active->getParams();
} else {
$params = new Registry();
}
$options = [];
$options['countItems'] =
$params->get('show_cat_items', 1) ||
$params->get('show_empty_categories', 0);
$categories =
Categories::getInstance('Contact', $options);
$this->_item =
$categories->get($this->getState('category.id',
'root'));
if (\is_object($this->_item)) {
$this->_children = $this->_item->getChildren();
$this->_parent = false;
if ($this->_item->getParent()) {
$this->_parent = $this->_item->getParent();
}
$this->_rightsibling = $this->_item->getSibling();
$this->_leftsibling =
$this->_item->getSibling(false);
} else {
$this->_children = false;
$this->_parent = false;
}
}
return $this->_item;
}
/**
* Get the parent category.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function getParent()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_parent;
}
/**
* Get the sibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getLeftSibling()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_leftsibling;
}
/**
* Get the sibling (adjacent) categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getRightSibling()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_rightsibling;
}
/**
* Get the child categories.
*
* @return mixed An array of categories or false if an error occurs.
*/
public function &getChildren()
{
if (!\is_object($this->_item)) {
$this->getCategory();
}
return $this->_children;
}
/**
* Generate column expression for slug or catslug.
*
* @param \Joomla\Database\DatabaseQuery $query Current query
instance.
* @param string $id Column id name.
* @param string $alias Column alias name.
*
* @return string
*
* @since 4.0.0
*/
private function getSlugColumn($query, $id, $alias)
{
return 'CASE WHEN '
. $query->charLength($alias, '!=', '0')
. ' THEN '
. $query->concatenate([$query->castAsChar($id), $alias],
':')
. ' ELSE '
. $query->castAsChar($id) . ' END';
}
/**
* Increment the hit counter for the category.
*
* @param integer $pk Optional primary key of the category to
increment.
*
* @return boolean True if successful; false otherwise and internal
error set.
*
* @since 3.2
*/
public function hit($pk = 0)
{
$input = Factory::getApplication()->getInput();
$hitcount = $input->getInt('hitcount', 1);
if ($hitcount) {
$pk = (!empty($pk)) ? $pk : (int)
$this->getState('category.id');
$table = Table::getInstance('Category');
$table->hit($pk);
}
return true;
}
}
FormModel.php000064400000014677151176062330007164 0ustar00<?php
/**
* @package Joomla.Site
* @subpackage com_contact
*
* @copyright (C) 2020 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Component\Contact\Site\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Contact Component Contact Model
*
* @since 4.0.0
*/
class FormModel extends
\Joomla\Component\Contact\Administrator\Model\ContactModel
{
/**
* Model typeAlias string. Used for version history.
*
* @var string
*
* @since 4.0.0
*/
public $typeAlias = 'com_contact.contact';
/**
* Name of the form
*
* @var string
*
* @since 4.0.0
*/
protected $formName = 'form';
/**
* Method to get the row 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 Form|boolean A Form object on success, false on failure
*
* @since 4.0.0
*/
public function getForm($data = [], $loadData = true)
{
$form = parent::getForm($data, $loadData);
// Prevent messing with article language and category when editing
existing contact with associations
if ($id = $this->getState('contact.id') &&
Associations::isEnabled()) {
$associations =
Associations::getAssociations('com_contact',
'#__contact_details', 'com_contact.item', $id);
// Make fields read only
if (!empty($associations)) {
$form->setFieldAttribute('language',
'readonly', 'true');
$form->setFieldAttribute('language',
'filter', 'unset');
}
}
return $form;
}
/**
* Method to get contact data.
*
* @param integer $itemId The id of the contact.
*
* @return mixed Contact item data object on success, false on
failure.
*
* @throws \Exception
*
* @since 4.0.0
*/
public function getItem($itemId = null)
{
$itemId = (int) (!empty($itemId)) ? $itemId :
$this->getState('contact.id');
// Get a row instance.
$table = $this->getTable();
// Attempt to load the row.
try {
if (!$table->load($itemId)) {
return false;
}
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
$properties = $table->getProperties();
$value = ArrayHelper::toObject($properties,
\Joomla\CMS\Object\CMSObject::class);
// Convert field to Registry.
$value->params = new Registry($value->params);
// Convert the metadata field to an array.
$registry = new Registry($value->metadata);
$value->metadata = $registry->toArray();
if ($itemId) {
$value->tags = new TagsHelper();
$value->tags->getTagIds($value->id,
'com_contact.contact');
$value->metadata['tags'] = $value->tags;
}
return $value;
}
/**
* Get the return URL.
*
* @return string The return URL.
*
* @since 4.0.0
*/
public function getReturnPage()
{
return base64_encode($this->getState('return_page',
''));
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 4.0.0
*
* @throws \Exception
*/
public function save($data)
{
// Associations are not edited in frontend ATM so we have to
inherit them
if (
Associations::isEnabled() &&
!empty($data['id'])
&& $associations =
Associations::getAssociations('com_contact',
'#__contact_details', 'com_contact.item',
$data['id'])
) {
foreach ($associations as $tag => $associated) {
$associations[$tag] = (int) $associated->id;
}
$data['associations'] = $associations;
}
return parent::save($data);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 4.0.0
*
* @throws \Exception
*/
protected function populateState()
{
$app = Factory::getApplication();
$input = $app->getInput();
// Load state from the request.
$pk = $input->getInt('id');
$this->setState('contact.id', $pk);
$this->setState('contact.catid',
$input->getInt('catid'));
$return = $input->get('return', '',
'base64');
$this->setState('return_page',
base64_decode($return));
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout',
$input->getString('layout'));
}
/**
* Allows preprocessing of the JForm object.
*
* @param Form $form The form object
* @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed
*
* @return void
*
* @since 4.0.0
*/
protected function preprocessForm(Form $form, $data, $group =
'contact')
{
if (!Multilanguage::isEnabled()) {
$form->setFieldAttribute('language',
'type', 'hidden');
$form->setFieldAttribute('language',
'default', '*');
}
parent::preprocessForm($form, $data, $group);
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
*
* @return bool|Table A Table object
*
* @since 4.0.0
* @throws \Exception
*/
public function getTable($name = 'Contact', $prefix =
'Administrator', $options = [])
{
return parent::getTable($name, $prefix, $options);
}
}