2015-11-30 21:30:54 +00:00
|
|
|
<?php
|
2021-08-16 17:11:22 +00:00
|
|
|
/*-------------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
|
|
|
____ ____ __ __ __
|
|
|
|
/\ _`\ /\ _`\ __ /\ \__ __/\ \ /\ \__
|
|
|
|
\ \,\L\_\ __ _ __ ___ ___ ___ ___ \ \ \/\ \/\_\ ____\ \ ,_\ _ __ /\_\ \ \____ __ __\ \ ,_\ ___ _ __
|
|
|
|
\/_\__ \ /'__`\/\`'__\/' __` __`\ / __`\ /' _ `\ \ \ \ \ \/\ \ /',__\\ \ \/ /\`'__\/\ \ \ '__`\/\ \/\ \\ \ \/ / __`\/\`'__\
|
|
|
|
/\ \L\ \/\ __/\ \ \/ /\ \/\ \/\ \/\ \L\ \/\ \/\ \ \ \ \_\ \ \ \/\__, `\\ \ \_\ \ \/ \ \ \ \ \L\ \ \ \_\ \\ \ \_/\ \L\ \ \ \/
|
|
|
|
\ `\____\ \____\\ \_\ \ \_\ \_\ \_\ \____/\ \_\ \_\ \ \____/\ \_\/\____/ \ \__\\ \_\ \ \_\ \_,__/\ \____/ \ \__\ \____/\ \_\
|
|
|
|
\/_____/\/____/ \/_/ \/_/\/_/\/_/\/___/ \/_/\/_/ \/___/ \/_/\/___/ \/__/ \/_/ \/_/\/___/ \/___/ \/__/\/___/ \/_/
|
|
|
|
|
|
|
|
/------------------------------------------------------------------------------------------------------------------------------------/
|
|
|
|
|
2024-02-10 09:13:31 +00:00
|
|
|
@version 3.0.x
|
2021-08-16 17:11:22 +00:00
|
|
|
@created 22nd October, 2015
|
|
|
|
@package Sermon Distributor
|
|
|
|
@subpackage sermon.php
|
|
|
|
@author Llewellyn van der Merwe <https://www.vdm.io/>
|
|
|
|
@copyright Copyright (C) 2015. All Rights Reserved
|
|
|
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
|
|
|
A sermon distributor that links to Dropbox.
|
|
|
|
|
|
|
|
/----------------------------------------------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
2024-02-10 09:13:31 +00:00
|
|
|
use Joomla\CMS\Factory;
|
|
|
|
use Joomla\CMS\Language\Text;
|
|
|
|
use Joomla\CMS\Component\ComponentHelper;
|
2022-05-27 05:37:27 +00:00
|
|
|
use Joomla\CMS\MVC\Model\ItemModel;
|
2024-02-10 09:13:31 +00:00
|
|
|
use Joomla\CMS\Plugin\PluginHelper;
|
|
|
|
use Joomla\CMS\Router\Route;
|
|
|
|
use Joomla\CMS\Uri\Uri;
|
2021-08-16 17:11:22 +00:00
|
|
|
use Joomla\Utilities\ArrayHelper;
|
2024-02-10 09:13:31 +00:00
|
|
|
use Joomla\CMS\Helper\TagsHelper;
|
|
|
|
use VDM\Joomla\Utilities\JsonHelper;
|
|
|
|
use VDM\Joomla\Utilities\StringHelper;
|
|
|
|
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
2021-08-16 17:11:22 +00:00
|
|
|
|
|
|
|
/**
|
2022-05-27 05:37:27 +00:00
|
|
|
* Sermondistributor Sermon Item Model
|
2021-08-16 17:11:22 +00:00
|
|
|
*/
|
2022-05-27 05:37:27 +00:00
|
|
|
class SermondistributorModelSermon extends ItemModel
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Model context string.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_context = 'com_sermondistributor.sermon';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$this->app = Factory::getApplication();
|
2021-08-16 17:11:22 +00:00
|
|
|
$this->input = $this->app->input;
|
|
|
|
// Get the itme main id
|
|
|
|
$id = $this->input->getInt('id', null);
|
|
|
|
$this->setState('sermon.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)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$this->user = Factory::getUser();
|
2017-02-17 20:21:37 +00:00
|
|
|
// check if this user has permission to access item
|
|
|
|
if (!$this->user->authorise('site.sermon.access', 'com_sermondistributor'))
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$app = Factory::getApplication();
|
|
|
|
$app->enqueueMessage(Text::_('COM_SERMONDISTRIBUTOR_NOT_AUTHORISED_TO_VIEW_SERMON'), 'error');
|
2017-02-17 20:21:37 +00:00
|
|
|
// redirect away to the default view if no access allowed.
|
2024-02-10 09:13:31 +00:00
|
|
|
$app->redirect(Route::_('index.php?option=com_sermondistributor&view=preachers'));
|
2017-02-17 20:21:37 +00:00
|
|
|
return false;
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
$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('sermon.id');
|
2024-02-10 09:13:31 +00:00
|
|
|
|
2021-08-16 17:11:22 +00:00
|
|
|
if ($this->_item === null)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$this->_item = [];
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->_item[$pk]))
|
|
|
|
{
|
|
|
|
try
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get a db connection.
|
2024-02-10 09:13:31 +00:00
|
|
|
$db = Factory::getDbo();
|
2015-11-30 21:30:54 +00:00
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create a new query object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get from #__sermondistributor_sermon as a
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->select($db->quoteName(
|
2024-02-11 17:24:51 +00:00
|
|
|
array('a.id','a.asset_id','a.name','a.alias','a.preacher','a.short_description','a.icon','a.scripture','a.series','a.catid','a.description','a.link_type','a.source','a.build','a.manual_files','a.local_files','a.url','a.auto_sermons','a.published','a.created_by','a.modified_by','a.created','a.modified','a.version','a.hits','a.ordering','a.metadesc','a.metakey','a.metadata'),
|
|
|
|
array('id','asset_id','name','alias','preacher','short_description','icon','scripture','series','catid','description','link_type','source','build','manual_files','local_files','url','auto_sermons','published','created_by','modified_by','created','modified','version','hits','ordering','metadesc','metakey','metadata')));
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->from($db->quoteName('#__sermondistributor_sermon', 'a'));
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get from #__sermondistributor_series as b
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->select($db->quoteName(
|
|
|
|
array('b.name','b.alias'),
|
|
|
|
array('series_name','series_alias')));
|
|
|
|
$query->join('LEFT', ($db->quoteName('#__sermondistributor_series', 'b')) . ' ON (' . $db->quoteName('a.series') . ' = ' . $db->quoteName('b.id') . ')');
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get from #__sermondistributor_preacher as c
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->select($db->quoteName(
|
|
|
|
array('c.name','c.alias'),
|
|
|
|
array('preacher_name','preacher_alias')));
|
|
|
|
$query->join('LEFT', ($db->quoteName('#__sermondistributor_preacher', 'c')) . ' ON (' . $db->quoteName('a.preacher') . ' = ' . $db->quoteName('c.id') . ')');
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get from #__categories as e
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->select($db->quoteName(
|
|
|
|
array('e.alias','e.title'),
|
|
|
|
array('category_alias','category')));
|
|
|
|
$query->join('LEFT', ($db->quoteName('#__categories', 'e')) . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('e.id') . ')');
|
|
|
|
$query->where('a.access IN (' . implode(',', $this->levels) . ')');
|
|
|
|
$query->where('a.id = ' . (int) $pk);
|
2017-08-18 11:20:01 +00:00
|
|
|
// Get where a.published is 1
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->where('a.published = 1');
|
|
|
|
$query->order('a.ordering ASC');
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Reset the query using our newly populated query object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$db->setQuery($query);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Load the results as a stdClass object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$data = $db->loadObject();
|
|
|
|
|
|
|
|
if (empty($data))
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$app = Factory::getApplication();
|
2016-07-16 12:19:44 +00:00
|
|
|
// If no data is found redirect to default page and show warning.
|
2024-02-10 09:13:31 +00:00
|
|
|
$app->enqueueMessage(Text::_('COM_SERMONDISTRIBUTOR_NOT_FOUND_OR_ACCESS_DENIED'), 'warning');
|
|
|
|
$app->redirect(Route::_('index.php?option=com_sermondistributor&view=preachers'));
|
2015-11-30 21:30:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-03 16:43:27 +00:00
|
|
|
// Load the JEvent Dispatcher
|
2024-02-10 09:13:31 +00:00
|
|
|
PluginHelper::importPlugin('content');
|
|
|
|
$this->_dispatcher = Factory::getApplication();
|
2018-09-06 08:34:13 +00:00
|
|
|
// Check if we can decode local_files
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($data->local_files) && JsonHelper::check($data->local_files))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Decode local_files
|
2015-11-30 21:30:54 +00:00
|
|
|
$data->local_files = json_decode($data->local_files, true);
|
|
|
|
}
|
2018-09-06 08:34:13 +00:00
|
|
|
// Check if we can decode manual_files
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($data->manual_files) && JsonHelper::check($data->manual_files))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Decode manual_files
|
2015-11-30 21:30:54 +00:00
|
|
|
$data->manual_files = json_decode($data->manual_files, true);
|
|
|
|
}
|
2018-09-06 08:34:13 +00:00
|
|
|
// Check if item has params, or pass whole item.
|
2024-02-10 09:13:31 +00:00
|
|
|
$params = (isset($data->params) && JsonHelper::check($data->params)) ? json_decode($data->params) : $data;
|
2018-03-03 16:43:27 +00:00
|
|
|
// Make sure the content prepare plugins fire on description
|
2024-02-10 09:13:31 +00:00
|
|
|
$_description = new \stdClass();
|
2018-03-03 16:43:27 +00:00
|
|
|
$_description->text =& $data->description; // value must be in text
|
|
|
|
// Since all values are now in text (Joomla Limitation), we also add the field name (description) to context
|
2022-03-03 03:49:35 +00:00
|
|
|
$this->_dispatcher->triggerEvent("onContentPrepare", array('com_sermondistributor.sermon.description', &$_description, &$params, 0));
|
2016-07-16 12:19:44 +00:00
|
|
|
// Checking if description has uikit components that must be loaded.
|
2015-11-30 21:30:54 +00:00
|
|
|
$this->uikitComp = SermondistributorHelper::getUikitComp($data->description,$this->uikitComp);
|
2016-07-16 12:19:44 +00:00
|
|
|
// set the global sermon value.
|
2015-11-30 21:30:54 +00:00
|
|
|
$this->a_sermon = $data->id;
|
2016-07-16 12:19:44 +00:00
|
|
|
// set idSermonStatisticD to the $data object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$data->idSermonStatisticD = $this->getIdSermonStatisticEbbd_D($data->id);
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// set data object to item.
|
2021-08-16 17:11:22 +00:00
|
|
|
$this->_item[$pk] = $data;
|
|
|
|
}
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
|
|
|
if ($e->getCode() == 404)
|
|
|
|
{
|
|
|
|
// Need to go thru the error handler to allow Redirect to work.
|
2024-02-10 09:13:31 +00:00
|
|
|
JError::raiseError(404, $e->getMessage());
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->setError($e);
|
|
|
|
$this->_item[$pk] = false;
|
|
|
|
}
|
|
|
|
}
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($this->_item[$pk]))
|
|
|
|
{
|
|
|
|
// set some default tottals
|
|
|
|
$this->_item[$pk]->statisticTotal = 0;
|
|
|
|
// set the auto links if found
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($this->_item[$pk]->auto_sermons) && StringHelper::check($this->_item[$pk]->auto_sermons))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
|
|
|
// Decode the auto files
|
|
|
|
$this->_item[$pk]->auto_sermons = json_decode($this->_item[$pk]->auto_sermons, true);
|
|
|
|
}
|
|
|
|
// set statistic per filename if found
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($this->_item[$pk]->idSermonStatisticD) && UtilitiesArrayHelper::check($this->_item[$pk]->idSermonStatisticD))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
|
|
|
foreach ($this->_item[$pk]->idSermonStatisticD as $statistic)
|
|
|
|
{
|
|
|
|
$this->_item[$pk]->statistic[$statistic->filename] = $statistic->counter;
|
|
|
|
}
|
|
|
|
// set the total downloads for this sermon
|
|
|
|
$this->_item[$pk]->statisticTotal = array_sum($this->_item[$pk]->statistic);
|
|
|
|
}
|
|
|
|
unset($this->_item[$pk]->idSermonStatisticD);
|
|
|
|
// build needed slugs
|
|
|
|
$this->_item[$pk]->preacher_slug = (isset($this->_item[$pk]->preacher_alias)) ? $this->_item[$pk]->preacher.':'.$this->_item[$pk]->preacher_alias : $this->_item[$pk]->preacher;
|
|
|
|
$this->_item[$pk]->series_slug = (isset($this->_item[$pk]->series_alias)) ? $this->_item[$pk]->series.':'.$this->_item[$pk]->series_alias : $this->_item[$pk]->series;
|
|
|
|
$this->_item[$pk]->category_slug = (isset($this->_item[$pk]->category_alias)) ? $this->_item[$pk]->catid.':'.$this->_item[$pk]->category_alias : $this->_item[$pk]->catid;
|
|
|
|
// now build the links
|
|
|
|
$this->_item[$pk]->preacher_link = JRoute::_(SermondistributorHelperRoute::getPreacherRoute($this->_item[$pk]->preacher_slug));
|
|
|
|
$this->_item[$pk]->series_link = JRoute::_(SermondistributorHelperRoute::getSeriesRoute($this->_item[$pk]->series_slug));
|
|
|
|
$this->_item[$pk]->category_link = JRoute::_(SermondistributorHelperRoute::getCategoryRoute($this->_item[$pk]->category_slug));
|
|
|
|
// build the download links
|
|
|
|
SermondistributorHelper::getDownloadLinks($this->_item[$pk]);
|
|
|
|
// fix the scripture links that they will show
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($this->_item[$pk]->scripture) && StringHelper::check($this->_item[$pk]->scripture))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
|
|
|
if (strpos(",",$this->_item[$pk]->scripture) !== false)
|
|
|
|
{
|
|
|
|
$scripture = (array) explode(",",$this->_item[$pk]->scripture);
|
|
|
|
}
|
|
|
|
elseif (strpos(";",$this->_item[$pk]->scripture) !== false)
|
|
|
|
{
|
|
|
|
$scripture = (array) explode(";",$this->_item[$pk]->scripture);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$scripture = (array) $this->_item[$pk]->scripture;
|
|
|
|
}
|
|
|
|
// now load the getBible taging
|
|
|
|
$scripture = '<p><span class="getBible">'.implode(' [in]</span></p><p><span class="getBible">',$scripture).' [in]</span></p>';
|
2024-02-10 09:13:31 +00:00
|
|
|
$this->_item[$pk]->scripture = Html::_('content.prepare', $scripture);
|
2015-11-30 21:30:54 +00:00
|
|
|
}
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_item[$pk];
|
2019-04-04 11:52:38 +00:00
|
|
|
}
|
2015-11-30 21:30:54 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* Method to get an array of Statistic Objects.
|
|
|
|
*
|
|
|
|
* @return mixed An array of Statistic Objects on success, false on failure.
|
|
|
|
*
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public function getIdSermonStatisticEbbd_D($id)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get a db connection.
|
2024-02-10 09:13:31 +00:00
|
|
|
$db = Factory::getDbo();
|
2015-11-30 21:30:54 +00:00
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create a new query object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Get from #__sermondistributor_statistic as d
|
2015-11-30 21:30:54 +00:00
|
|
|
$query->select($db->quoteName(
|
|
|
|
array('d.filename','d.counter'),
|
|
|
|
array('filename','counter')));
|
|
|
|
$query->from($db->quoteName('#__sermondistributor_statistic', 'd'));
|
|
|
|
$query->where('d.sermon = ' . $db->quote($id));
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// Reset the query using our newly populated query object.
|
2015-11-30 21:30:54 +00:00
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
|
2016-07-16 12:19:44 +00:00
|
|
|
// check if there was data returned
|
2015-11-30 21:30:54 +00:00
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
return $db->loadObjectList();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* Get the uikit needed components
|
|
|
|
*
|
|
|
|
* @return mixed An array of objects on success.
|
|
|
|
*
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public function getUikitComp()
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
if (isset($this->uikitComp) && UtilitiesArrayHelper::check($this->uikitComp))
|
2015-11-30 21:30:54 +00:00
|
|
|
{
|
|
|
|
return $this->uikitComp;
|
|
|
|
}
|
|
|
|
return false;
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
}
|