219 lines
5.9 KiB
PHP
219 lines
5.9 KiB
PHP
|
<?php
|
||
|
/*----------------------------------------------------------------------------------| www.vdm.io |----/
|
||
|
Agence Agerix
|
||
|
/-------------------------------------------------------------------------------------------------------/
|
||
|
|
||
|
@version 1.x.x
|
||
|
@build 2nd June, 2022
|
||
|
@created 12th December, 2020
|
||
|
@package Extension Distributor
|
||
|
@subpackage keys.php
|
||
|
@author Emmanuel Danan <https://agerix.fr>
|
||
|
@copyright Copyright (C) 2021. All Rights Reserved.
|
||
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||
|
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
|
||
|
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
|
||
|
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
|
||
|
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
|
||
|
|
||
|
/------------------------------------------------------------------------------------------------------*/
|
||
|
|
||
|
// No direct access to this file
|
||
|
defined('_JEXEC') or die('Restricted access');
|
||
|
|
||
|
use Joomla\CMS\MVC\Model\ItemModel;
|
||
|
use Joomla\Utilities\ArrayHelper;
|
||
|
|
||
|
/**
|
||
|
* Extensiondistributor Keys Item Model
|
||
|
*/
|
||
|
class ExtensiondistributorModelKeys extends ItemModel
|
||
|
{
|
||
|
/**
|
||
|
* Model context string.
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $_context = 'com_extensiondistributor.keys';
|
||
|
|
||
|
/**
|
||
|
* Model user data.
|
||
|
*
|
||
|
* @var strings
|
||
|
*/
|
||
|
protected $user;
|
||
|
protected $userId;
|
||
|
protected $guest;
|
||
|
protected $groups;
|
||
|
protected $levels;
|
||
|
protected $app;
|
||
|
protected $input;
|
||
|
protected $uikitComp;
|
||
|
|
||
|
/**
|
||
|
* @var object item
|
||
|
*/
|
||
|
protected $item;
|
||
|
|
||
|
/**
|
||
|
* Method to auto-populate the model state.
|
||
|
*
|
||
|
* Note. Calling getState in this method will result in recursion.
|
||
|
*
|
||
|
* @since 1.6
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
protected function populateState()
|
||
|
{
|
||
|
$this->app = JFactory::getApplication();
|
||
|
$this->input = $this->app->input;
|
||
|
// Get the itme main id
|
||
|
$id = $this->input->getInt('id', null);
|
||
|
$this->setState('keys.id', $id);
|
||
|
|
||
|
// Load the parameters.
|
||
|
$params = $this->app->getParams();
|
||
|
$this->setState('params', $params);
|
||
|
parent::populateState();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Method to get article data.
|
||
|
*
|
||
|
* @param integer $pk The id of the article.
|
||
|
*
|
||
|
* @return mixed Menu item data object on success, false on failure.
|
||
|
*/
|
||
|
public function getItem($pk = null)
|
||
|
{
|
||
|
$this->user = JFactory::getUser();
|
||
|
// check if this user has permission to access item
|
||
|
if (!$this->user->authorise('site.keys.access', 'com_extensiondistributor'))
|
||
|
{
|
||
|
$app = JFactory::getApplication();
|
||
|
$app->enqueueMessage(JText::_('COM_EXTENSIONDISTRIBUTOR_NOT_AUTHORISED_TO_VIEW_KEYS'), 'error');
|
||
|
// redirect away to the home page if no access allowed.
|
||
|
$app->redirect(JURI::root());
|
||
|
return false;
|
||
|
}
|
||
|
$this->userId = $this->user->get('id');
|
||
|
$this->guest = $this->user->get('guest');
|
||
|
$this->groups = $this->user->get('groups');
|
||
|
$this->authorisedGroups = $this->user->getAuthorisedGroups();
|
||
|
$this->levels = $this->user->getAuthorisedViewLevels();
|
||
|
$this->initSet = true;
|
||
|
|
||
|
$pk = (!empty($pk)) ? $pk : (int) $this->getState('keys.id');
|
||
|
|
||
|
if ($this->_item === null)
|
||
|
{
|
||
|
$this->_item = array();
|
||
|
}
|
||
|
|
||
|
if (!isset($this->_item[$pk]))
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
// Get a db connection.
|
||
|
$db = JFactory::getDbo();
|
||
|
|
||
|
// Create a new query object.
|
||
|
$query = $db->getQuery(true);
|
||
|
|
||
|
// Get data
|
||
|
return false;
|
||
|
|
||
|
// Reset the query using our newly populated query object.
|
||
|
$db->setQuery($query);
|
||
|
// Load the results as a stdClass object.
|
||
|
$data = $db->loadObject();
|
||
|
|
||
|
if (empty($data))
|
||
|
{
|
||
|
$app = JFactory::getApplication();
|
||
|
// If no data is found redirect to default page and show warning.
|
||
|
$app->enqueueMessage(JText::_('COM_EXTENSIONDISTRIBUTOR_NOT_FOUND_OR_ACCESS_DENIED'), 'warning');
|
||
|
$app->redirect(JURI::root());
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// set data object to item.
|
||
|
$this->_item[$pk] = $data;
|
||
|
}
|
||
|
catch (Exception $e)
|
||
|
{
|
||
|
if ($e->getCode() == 404)
|
||
|
{
|
||
|
// Need to go thru the error handler to allow Redirect to work.
|
||
|
JError::raiseWarning(404, $e->getMessage());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$this->setError($e);
|
||
|
$this->_item[$pk] = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $this->_item[$pk];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Custom Method
|
||
|
*
|
||
|
* @return mixed An array of objects on success, false on failure.
|
||
|
*
|
||
|
*/
|
||
|
public function getUserKeys()
|
||
|
{
|
||
|
|
||
|
if (!isset($this->initSet) || !$this->initSet)
|
||
|
{
|
||
|
$this->user = JFactory::getUser();
|
||
|
$this->userId = $this->user->get('id');
|
||
|
$this->guest = $this->user->get('guest');
|
||
|
$this->groups = $this->user->get('groups');
|
||
|
$this->authorisedGroups = $this->user->getAuthorisedGroups();
|
||
|
$this->levels = $this->user->getAuthorisedViewLevels();
|
||
|
$this->initSet = true;
|
||
|
}
|
||
|
|
||
|
// Get the global params
|
||
|
$globalParams = JComponentHelper::getParams('com_extensiondistributor', true);
|
||
|
// Get a db connection.
|
||
|
$db = JFactory::getDbo();
|
||
|
|
||
|
// Create a new query object.
|
||
|
$query = $db->getQuery(true);
|
||
|
|
||
|
// Get from #__extensiondistributor_key as a
|
||
|
$query->select($db->quoteName(
|
||
|
array('a.id','a.user','a.website','a.key','a.published','a.created_by','a.modified_by','a.created','a.modified','a.version','a.hits','a.ordering'),
|
||
|
array('id','user','website','key','published','created_by','modified_by','created','modified','version','hits','ordering')));
|
||
|
$query->from($db->quoteName('#__extensiondistributor_key', 'a'));
|
||
|
$query->where('a.user = ' . (int) $this->userId);
|
||
|
|
||
|
// Reset the query using our newly populated query object.
|
||
|
$db->setQuery($query);
|
||
|
$items = $db->loadObjectList();
|
||
|
|
||
|
if (empty($items))
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// Insure all item fields are adapted where needed.
|
||
|
if (ExtensiondistributorHelper::checkArray($items))
|
||
|
{
|
||
|
foreach ($items as $nr => &$item)
|
||
|
{
|
||
|
// Always create a slug for sef URL's
|
||
|
$item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id;
|
||
|
}
|
||
|
}
|
||
|
// return items
|
||
|
return $items;
|
||
|
}
|
||
|
}
|