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 route.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\Language\Multilanguage;
|
|
|
|
use Joomla\CMS\Component\ComponentHelper;
|
|
|
|
use Joomla\CMS\Categories\CategoryNode;
|
|
|
|
use Joomla\CMS\Categories\Categories;
|
|
|
|
use VDM\Joomla\Utilities\ArrayHelper;
|
|
|
|
|
2021-08-16 17:11:22 +00:00
|
|
|
/**
|
|
|
|
* Sermondistributor Route Helper
|
|
|
|
**/
|
|
|
|
abstract class SermondistributorHelperRoute
|
|
|
|
{
|
2015-11-30 21:30:54 +00:00
|
|
|
protected static $lookup;
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Sermon
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getSermonRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'sermon' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=sermon&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'sermon' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=sermon';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.sermons');
|
2015-11-30 21:30:54 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles, 'sermon'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Preachers
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getPreachersRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'preachers' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=preachers&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'preachers' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=preachers';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.preachers');
|
2015-11-30 21:30:54 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Preacher
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getPreacherRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'preacher' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=preacher&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'preacher' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=preacher';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.preacher');
|
2015-11-30 21:30:54 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles, 'preacher'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Categories
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getCategoriesRoute($id = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'categories' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=categories&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'categories' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=categories';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Category
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getCategoryRoute($id = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'category' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=category&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'category' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=category';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles, 'category'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Serieslist
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getSerieslistRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'serieslist' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=serieslist&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'serieslist' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=serieslist';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.serieslist');
|
2015-11-30 21:30:54 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Series
|
|
|
|
*/
|
2015-11-30 21:30:54 +00:00
|
|
|
public static function getSeriesRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2015-11-30 21:30:54 +00:00
|
|
|
$needles = array(
|
|
|
|
'series' => array((int) $id)
|
|
|
|
);
|
2016-07-16 12:19:44 +00:00
|
|
|
// Create the link
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=series&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-16 12:19:44 +00:00
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'series' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2015-11-30 21:30:54 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=series';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.series');
|
2015-11-30 21:30:54 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles, 'series'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
2018-03-03 16:43:27 +00:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-20 04:39:01 +00:00
|
|
|
* @param int The route of the Api
|
|
|
|
*/
|
2018-03-03 16:43:27 +00:00
|
|
|
public static function getApiRoute($id = 0, $catid = 0)
|
|
|
|
{
|
|
|
|
if ($id > 0)
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
|
|
|
$needles = array(
|
|
|
|
'api' => array((int) $id)
|
|
|
|
);
|
|
|
|
// Create the link
|
|
|
|
$link = 'index.php?option=com_sermondistributor&view=api&id='. $id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initialize the needel array.
|
2019-04-04 11:52:38 +00:00
|
|
|
$needles = array(
|
|
|
|
'api' => array()
|
|
|
|
);
|
|
|
|
// Create the link but don't add the id.
|
2018-03-03 16:43:27 +00:00
|
|
|
$link = 'index.php?option=com_sermondistributor&view=api';
|
|
|
|
}
|
|
|
|
if ($catid > 1)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$categories = Categories::getInstance('sermondistributor.api');
|
2018-03-03 16:43:27 +00:00
|
|
|
$category = $categories->get($catid);
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$needles['category'] = array_reverse($category->getPath());
|
|
|
|
$needles['categories'] = $needles['category'];
|
|
|
|
$link .= '&catid='.$catid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item = self::_findItem($needles))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
|
2015-11-30 21:30:54 +00:00
|
|
|
return $link;
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the URL route for sermondistributor category from a category ID and language
|
|
|
|
*
|
2024-02-10 09:13:31 +00:00
|
|
|
* @param mixed $catid The id of the items's category either an integer id or a instance of CategoryNode
|
2021-08-16 17:11:22 +00:00
|
|
|
* @param mixed $language The id of the language being used.
|
|
|
|
*
|
|
|
|
* @return string The link to the contact
|
|
|
|
*
|
|
|
|
* @since 1.5
|
|
|
|
*/
|
|
|
|
public static function getCategoryRoute_keep_for_later($catid, $language = 0)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
if ($catid instanceof CategoryNode)
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$id = $catid->id;
|
|
|
|
$category = $catid;
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
else
|
2024-02-10 09:13:31 +00:00
|
|
|
{
|
|
|
|
throw new Exception('First parameter must be CategoryNode');
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
2024-02-10 09:13:31 +00:00
|
|
|
|
2015-11-30 21:30:54 +00:00
|
|
|
$views = array(
|
2021-08-16 17:11:22 +00:00
|
|
|
"com_sermondistributor.sermon" => "sermon");
|
|
|
|
$view = $views[$category->extension];
|
2024-02-10 09:13:31 +00:00
|
|
|
|
|
|
|
if ($id < 1 || !($category instanceof CategoryNode))
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
|
|
|
$link = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Create the link
|
|
|
|
$link = 'index.php?option=com_sermondistributor&view='.$view.'&category='.$category->slug;
|
2024-02-10 09:13:31 +00:00
|
|
|
|
2021-08-16 17:11:22 +00:00
|
|
|
$needles = array(
|
|
|
|
$view => array($id),
|
|
|
|
'category' => array($id)
|
|
|
|
);
|
2024-02-10 09:13:31 +00:00
|
|
|
|
|
|
|
if ($language && $language != "*" && Multilanguage::isEnabled())
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$db = Factory::getDbo();
|
|
|
|
$query = $db->getQuery(true)
|
2021-08-16 17:11:22 +00:00
|
|
|
->select('a.sef AS sef')
|
|
|
|
->select('a.lang_code AS lang_code')
|
|
|
|
->from('#__languages AS a');
|
2024-02-10 09:13:31 +00:00
|
|
|
|
2021-08-16 17:11:22 +00:00
|
|
|
$db->setQuery($query);
|
|
|
|
$langs = $db->loadObjectList();
|
|
|
|
foreach ($langs as $lang)
|
|
|
|
{
|
|
|
|
if ($language == $lang->lang_code)
|
|
|
|
{
|
|
|
|
$link .= '&lang='.$lang->sef;
|
|
|
|
$needles['language'] = $language;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-10 09:13:31 +00:00
|
|
|
|
2021-08-16 17:11:22 +00:00
|
|
|
if ($item = self::_findItem($needles,'category'))
|
|
|
|
{
|
|
|
|
|
2024-02-10 09:13:31 +00:00
|
|
|
$link .= '&Itemid='.$item;
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($category)
|
|
|
|
{
|
|
|
|
$catids = array_reverse($category->getPath());
|
|
|
|
$needles = array(
|
|
|
|
'category' => $catids
|
|
|
|
);
|
|
|
|
if ($item = self::_findItem($needles,'category'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
elseif ($item = self::_findItem(null, 'category'))
|
|
|
|
{
|
|
|
|
$link .= '&Itemid='.$item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static function _findItem($needles = null,$type = null)
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
$app = Factory::getApplication();
|
2021-08-16 17:11:22 +00:00
|
|
|
$menus = $app->getMenu('site');
|
|
|
|
$language = isset($needles['language']) ? $needles['language'] : '*';
|
|
|
|
|
|
|
|
// Prepare the reverse lookup array.
|
|
|
|
if (!isset(self::$lookup[$language]))
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
self::$lookup[$language] = [];
|
2021-08-16 17:11:22 +00:00
|
|
|
|
2024-02-10 09:13:31 +00:00
|
|
|
$component = ComponentHelper::getComponent('com_sermondistributor');
|
2021-08-16 17:11:22 +00:00
|
|
|
|
|
|
|
$attributes = array('component_id');
|
|
|
|
$values = array($component->id);
|
|
|
|
|
|
|
|
if ($language != '*')
|
|
|
|
{
|
|
|
|
$attributes[] = 'language';
|
|
|
|
$values[] = array($needles['language'], '*');
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = $menus->getItems($attributes, $values);
|
|
|
|
|
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
|
|
|
if (isset($item->query) && isset($item->query['view']))
|
|
|
|
{
|
|
|
|
$view = $item->query['view'];
|
|
|
|
|
|
|
|
if (!isset(self::$lookup[$language][$view]))
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
self::$lookup[$language][$view] = [];
|
2021-08-16 17:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($item->query['id']))
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Here it will become a bit tricky
|
|
|
|
* language != * can override existing entries
|
|
|
|
* language == * cannot override existing entries
|
|
|
|
*/
|
|
|
|
if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
|
|
|
|
{
|
|
|
|
self::$lookup[$language][$view][$item->query['id']] = $item->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self::$lookup[$language][$view][0] = $item->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($needles)
|
|
|
|
{
|
|
|
|
foreach ($needles as $view => $ids)
|
|
|
|
{
|
|
|
|
if (isset(self::$lookup[$language][$view]))
|
|
|
|
{
|
2024-02-10 09:13:31 +00:00
|
|
|
if (ArrayHelper::check($ids))
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
|
|
|
foreach ($ids as $id)
|
|
|
|
{
|
|
|
|
if (isset(self::$lookup[$language][$view][(int) $id]))
|
|
|
|
{
|
|
|
|
return self::$lookup[$language][$view][(int) $id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (isset(self::$lookup[$language][$view][0]))
|
|
|
|
{
|
|
|
|
return self::$lookup[$language][$view][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type)
|
|
|
|
{
|
|
|
|
// Check if the global menu item has been set.
|
2024-02-10 09:13:31 +00:00
|
|
|
$params = ComponentHelper::getParams('com_sermondistributor');
|
2021-08-16 17:11:22 +00:00
|
|
|
if ($item = $params->get($type.'_menu', 0))
|
|
|
|
{
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the active menuitem matches the requested language
|
|
|
|
$active = $menus->getActive();
|
|
|
|
|
|
|
|
if ($active
|
|
|
|
&& $active->component == 'com_sermondistributor'
|
2024-02-10 09:13:31 +00:00
|
|
|
&& ($language == '*' || in_array($active->language, array('*', $language)) || !Multilanguage::isEnabled()))
|
2021-08-16 17:11:22 +00:00
|
|
|
{
|
|
|
|
return $active->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not found, return language specific home link
|
|
|
|
$default = $menus->getDefault($language);
|
|
|
|
|
|
|
|
return !empty($default->id) ? $default->id : null;
|
|
|
|
}
|
|
|
|
}
|