Sindbad~EG File Manager
<?php
/**
* @package RSDirectory!
* @copyright (c) 2013 - 2021 RSJoomla!
* @link https://www.rsjoomla.com
* @license GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// No direct access.
defined('_JEXEC') or die('Restricted access');
/**
* Entries model.
*/
class RSDirectoryModelEntries extends JModelList
{
protected $load_alpha = true;
/**
* Constructor.
*
* @access public
*
* @param array An optional associative array of configuration settings.
*/
public function __construct( $config = array() )
{
if ( empty($config['filter_fields'] ) )
{
$config['filter_fields'] = array_merge(array('c.path', 'c.lft'), array_keys($this->getSortFields()));
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* @access protected
*
* @param string $ordering
* @param string $direction
*/
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication();
$params = $app->getParams();
$list_limit = $params->get('list_limit', $app->get('list_limit', 20));
// List state information
$limit = $app->input->get('limit', $list_limit, 'uint');
if ($params->get('pagination_behavior', 0))
{
$limitstart = $app->input->get('limitstart', 0, 'uint');
} else {
$value = $app->getUserStateFromRequest('com_rsdirectory.entries' . '.limitstart', 'limitstart', 0, 'int');
$limitstart = ($limit != 0 ? (floor($value / $limit) * $limit) : 0);
}
$this->setState('params', $params);
list($order_field, $order_direction) = $this->splitOrdering($params->get('order_by', 'e.published_time-desc'));
// List state information.
parent::populateState($order_field, $order_direction);
$this->setState('list.limit', $limit);
$this->setState('list.start', $limitstart);
}
/**
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
*
* @access protected
*
* @return object A JDatabaseQuery object to retrieve the data set.
*/
protected function getListQuery()
{
// Get mainframe.
$app = JFactory::getApplication();
// Get the JInput object.
$jinput = $app->input;
// Get DBO.
$db = JFactory::getDbo();
// Get the menu item params.
$params = $this->state->params;
// Get the JUser object.
$user = JFactory::getUser();
$joined_entries_custom = false;
// set the fields and direction based on the users selection
list($order_field, $order_direction) = $this->splitOrdering();
$select = array(
$db->qn('e') . '.*',
$db->qn('c.title', 'category_title'),
$db->qn('c.path', 'category_path'),
' IF('.$db->qn("e.modified_time").' = '.$db->q('0000-00-00 00:00:00').', '.$db->qn("e.published_time").', '.$db->qn("e.modified_time").') as `modified_last`'
);
if ($order_field == 'author')
{
$author = RSDirectoryConfig::getInstance()->get('entry_author', 'name');
$select[] = $db->qn("a.$author", 'author');
}
$query = $db->getQuery(true)
->select($select)
->from( $db->qn('#__rsdirectory_entries', 'e') )
->leftJoin( $db->qn('#__categories', 'c') . ' ON ' . $db->qn('e.category_id') . ' = ' . $db->qn('c.id') );
if ($order_field == 'author')
{
$query->leftJoin( $db->qn('#__users', 'a') . ' ON ' . $db->qn('e.user_id') . ' = ' . $db->qn('a.id') );
}
// the condition that te user exists and is enabled
$query->where( $db->qn('e.user_id') . ' NOT IN (SELECT '.$db->qn('u.id').' FROM ' . $db->qn('#__users', 'u') .' WHERE '.$db->qn('u.block').' != '.$db->q(0).')');
// Check if the component is displayed
$is_component = true;
if (!$this->load_alpha) {
if ($jinput->get('option', '') != 'com_rsdirectory' || $jinput->get('view', '') != 'entries') {
$is_component = false;
}
}
// Process permissions.
$can_view_all_unpublished_entries = RSDirectoryHelper::checkUserPermission('can_view_all_unpublished_entries');
$can_view_own_unpublished_entries = RSDirectoryHelper::checkUserPermission('can_view_own_unpublished_entries');
if ($is_component && ($can_view_all_unpublished_entries || $can_view_own_unpublished_entries))
{
$statuses = $jinput->get( 'status', array(0, 1), 'status' );
$status_conditions = array();
if ( in_array(0, $statuses) )
{
$unpublished_condition[] = '(' . $db->qn('e.published') . ' = ' . $db->q(0) . ' OR ' . $db->qn('e.published_time') . ' > ' . $db->q( JFactory::getDate()->toSql() ) . ')';
if (!$can_view_all_unpublished_entries)
{
$unpublished_condition[] = '(' . $db->qn('e.user_id') . ' = ' . $db->q($user->id) . ')';
}
$status_conditions[] = implode(' AND ', $unpublished_condition);
}
if ( in_array(1, $statuses) )
{
$status_conditions[] = '((' . $db->qn('e.published') . ' = ' . $db->q(1) . ' AND ' . $db->qn('e.published_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) . ') AND (' . $db->qn('e.expiry_time') . ' = ' . $db->q('0000-00-00 00:00:00') . ' OR ' . $db->qn('e.expiry_time') . ' >= ' . $db->q( JFactory::getDate()->toSql() ) . '))';
}
if ($status_conditions)
{
$query->where( '(' . implode(' OR ', $status_conditions) . ')' );
}
}
else
{
$query->where( $db->qn('e.published') . ' = ' . $db->q(1) )
->where( $db->qn('e.published_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) )
->where( '(' . $db->qn('e.expiry_time') . ' = ' . $db->q('0000-00-00 00:00:00') . ' OR ' . $db->qn('e.expiry_time') . ' >= ' . $db->q( JFactory::getDate()->toSql() ) . ')' );
}
if ($is_component && $ratings = $jinput->get('ratings', array(), 'array'))
{
$ratings_where = array();
foreach ($ratings as $rating)
{
$rating = (int) $rating;
$ratings_where[] = '(' . $db->qn('e.avg_rating') . ' BETWEEN ' . $rating . ' AND ' . $rating . '.99)';
}
if ($ratings_where)
{
$query->where(implode(' OR ', $ratings_where));
}
}
// Initialize the featured categories array.
$featured_categories = array();
if ($is_component) {
// Get categories filter.
$categories = $jinput->get('categories', array(), 'array');
// Get a single category.
$category = $jinput->getInt('category');
if ($category) {
$categories[] = $category;
}
if (!empty($categories)) {
$featured_categories = RSDirectoryHelper::arrayInt($categories);
}
}
// Get the featured categories from the module settings if there were no categories filters.
if (!$featured_categories)
{
$featured_categories = RSDirectoryHelper::arrayInt( $params->get('featured_categories') );
}
if (!empty($featured_categories) && !in_array(0, $featured_categories)) {
// Let's see if the featured categories we've selected are accessible
if ($categories_filtered_ids = array_intersect($featured_categories, $this->getCategories())) {
$categories_ids = array();
foreach ($categories_filtered_ids as $id) {
$categories_ids[] = $id;
$categories_ids = array_merge($categories_ids, $this->getCategories($id));
}
}
} else {
$categories_ids = $this->getCategories();
}
if (empty($categories_ids)) {
$categories_ids = array(0);
}
if ($categories_ids) {
$query->where( $db->qn('e.category_id') . ' IN (' . implode( ',', array_unique($categories_ids) ) . ')' );
}
// Process the users filter.
if ($is_component) {
$users = $jinput->get('users', array(), 'array');
// Get single user.
$user = $jinput->getInt('user');
if ($user) {
$users[] = $user;
}
$users = RSDirectoryHelper::arrayInt($users);
if ($users) {
$query->where($db->qn('e.user_id') . ' IN (' . implode(',', array_unique($users)) . ')');
}
}
// Get the alpha filter
if ($this->load_alpha) {
$alpha = $jinput->get('alpha', '', 'raw');
if (strlen($alpha))
{
if ($alpha == '0-9') {
$query->where($db->qn('e.title') . ' REGEXP '.$db->q('^[0-9]'));
} else if ($alpha == JText::_('COM_RSDIRECTORY_SEF_SPECIAL')) {
$query->where($db->qn('e.title') . ' NOT REGEXP '.$db->q('^[A-Za-z0-9]'));
} else {
$query->where($db->qn('e.title') . ' LIKE ' . $db->q($db->escape($alpha, true) . '%'));
}
}
}
// Get the search query.
if ($is_component) {
list($q) = $jinput->get('q', array(''), 'array');
if (trim($q) !== '') {
// Initialize the forms ids array.
$forms_ids = array();
// Get all the categories that belong to RSDirectory!
$categories = RSDirectoryHelper::getCategories();
// Is "All categories" selected?
$all_categories = in_array(0, $featured_categories);
foreach ($categories as $category) {
if (empty($featured_categories) || in_array($category->id, $featured_categories) || $all_categories) {
$form_id = RSDirectoryHelper::getCategoryInheritedFormId($category->id, $categories);
if ($form_id) {
$forms_ids[] = $form_id;
}
}
}
$forms_ids = array_unique($forms_ids);
// Get form fields.
$form_fields = RSDirectoryHelper::getFormFields($forms_ids);
// Initialize the conditions array.
$where = array();
if ($form_fields) {
$use_word_combinations = RSDirectoryConfig::getInstance()->get('word_combinations_search', 0);
// ignore other chars in between the searched expressions
if ($use_word_combinations)
{
$explode_q = explode(' ', $q);
$q = array();
foreach($explode_q as $ex_q)
{
if (trim($ex_q) != '')
{
$val = trim($ex_q);
$q[] = $db->escape($val, true);
}
}
}
else
{
$q = $db->q('%' . $db->escape($q, true) . '%');
}
foreach ($form_fields as $form_field) {
if ($form_field->properties->get('searchable_simple') && $form_field->column_name) {
$table = $form_field->create_column ? 'ec' : 'e';
if ($table === 'ec' && !$joined_entries_custom)
{
$query->leftJoin( $db->qn('#__rsdirectory_entries_custom', 'ec') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('ec.entry_id') );
$joined_entries_custom = true;
}
if ($form_field->field_type == 'map') {
$column_name = "{$form_field->column_name}_address";
} else {
$column_name = $form_field->column_name;
}
if (!is_array($q)) {
$where[] = $db->qn("$table.$column_name") . " LIKE $q";
} else {
// create conditions even if the words are not in the same order
$inner_condition = array();
foreach ($q as $q_val) {
$inner_condition[] = $db->qn("$table.$column_name") . " LIKE ".$db->q('%' .$q_val . '%');
}
$where[] = '(' . implode(' AND ', $inner_condition). ')';
}
}
}
}
if ($where) {
$query->where('(' . implode(' OR ', $where) . ')');
}
}
}
// Process filters.
if ($is_component) {
if ($f = $jinput->get('f', array(), 'array')) {
if ($jinput->getInt('filter')) {
$fields = RSDirectoryHelper::getFilterFields($featured_categories);
// join the entries custom table if fields exists
if ($fields && !$joined_entries_custom)
{
$query->leftJoin( $db->qn('#__rsdirectory_entries_custom', 'ec') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('ec.entry_id') );
$joined_entries_custom = true;
}
RSDirectoryHelper::buildEntriesFilteringQuery($fields, $f, $query);
} // Process "Categories from Field Values".
else {
$fields = RSDirectoryHelper::getFormFields(null, true, true);
if ($fields) {
foreach ($f as $form_field_name => $values) {
if (is_string($values) && $values === '')
continue;
$field = RSDirectoryHelper::findElements(array('form_field_name' => $form_field_name), $fields);
if (!$field)
continue;
$table = $field->create_column ? 'ec' : 'e';
if ($table === 'ec' && !$joined_entries_custom)
{
$query->leftJoin( $db->qn('#__rsdirectory_entries_custom', 'ec') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('ec.entry_id') );
$joined_entries_custom = true;
}
$column_name = $db->qn("$table.$field->column_name");
// Initialize the condition array.
$cond = array();
if (!is_array($values)) {
$values = (array)$values;
}
foreach ($values as $value) {
if (is_string($value) && $value === '')
continue;
$cond[] = $column_name . ' LIKE ' . $db->q('%' . $db->escape($value, true) . '%');
}
if ($cond) {
$query->where('(' . implode(' OR ', $cond) . ')');
}
}
}
}
}
}
// Initialize the order array.
$order = array(
$db->qn('promoted') . ' DESC'
);
switch ( $params->get('orderby_pri') )
{
case 'alpha':
$order[] = $db->qn('c.path');
break;
case 'ralpha':
$order[] = $db->qn('c.path') . ' DESC ';
break;
case 'order':
$order[] = $db->qn('c.lft');
break;
}
if ($order_field == 'e.avg_rating') {
$order[] = $db->qn( $order_field ) . ' '.$db->escape( $order_direction ).', '.$db->qn('e.ratings_count') .' ' . $db->escape( $order_direction );
}
else if ($order_field == 'random'){
$order[] = 'RAND(' . RSDirectoryHelper::getRandomSeed() . ')';
}
else {
$order[] = $db->qn( $order_field ) . ' ' . $db->escape( $order_direction );
}
// end setting the order
$query->order($order);
// Need to remove duplicates?
if ($joined_entries_custom)
{
$query->group( $db->qn('e.id') );
}
return $query;
}
protected function cleanLetter($var)
{
return strlen($var);
}
protected function mb_strlen($str)
{
if (function_exists('mb_strlen'))
{
return mb_strlen($str);
}
else
{
return strlen(utf8_decode($str));
}
}
protected function mb_strtolower($str)
{
if (function_exists('mb_strtolower'))
{
return mb_strtolower($str);
}
else
{
return strtolower($str);
}
}
public function getLetters($params = null)
{
$app = JFactory::getApplication();
if (!$params instanceof JRegistry)
{
$params = $app->getParams();
}
else
{
$this->populateState();
}
$calculate_alphabetical = $params->get('calculate_alphabetical', 0);
$group_lengths = array(1);
// Get the additions if any
if (strlen($additions = $params->get('alphabet_additions', '')))
{
$additions = explode(',', $additions);
// Perform some cleanup
$additions = array_map('trim', $additions);
// Remove duplicates
$additions = array_unique($additions);
// Remove empty values, but let's keep 0 as a value if needed
$additions = array_filter($additions, 'strlen');
// Set all to lowercase
$additions = array_map(array($this, 'mb_strtolower'),$additions);
// Get the group length
$lengths = array_map(array($this, 'mb_strlen'), $additions);
$group_lengths = array_merge($group_lengths, $lengths);
$group_lengths = array_unique($group_lengths); // remove duplicates
}
$alpha_range = array();
$itemId = $params->get('custom_itemid', '');
// Use the best match item id listing only if the use_alphabetical option is disable on the menu item
$is_component = false;
if (JFactory::getApplication()->input->get('option', '') == 'com_rsdirectory' && JFactory::getApplication()->input->get('view', '') == 'entries') {
$is_component = true;
}
// if ItemId is empty and Advanced Sef option is enabled try to find one
if (RSDirectoryConfig::getInstance()->get('advanced_sef') && empty($itemId) && !$is_component) {
$itemId = RSDirectoryRoute::getListEntriesBestMatch();
}
// if an ItemId has been found
if (!empty($itemId)) {
$itemId = '&Itemid='.$itemId;
}
if ($params->get('use_latin_alphabet', 1))
{
$alpha_range = range('a', 'z');
}
if (!empty($additions))
{
$alpha_range = array_merge($alpha_range, $additions);
}
if ($params->get('use_numbers', 1))
{
$alpha_range[] = '0-9';
}
if ($params->get('use_special', 1))
{
$alpha_range[] = '#';
}
// Remove unwanted duplicates
$alpha_range = array_unique($alpha_range);
// If there is no range we need to stop the function here
if (empty($alpha_range))
{
return $alpha_range;
}
$url = $this->getLettersUrl();
$alpha_range = array_flip($alpha_range);
// neutralize the range
if ($calculate_alphabetical)
{
foreach ($alpha_range as $i => $range)
{
$alpha_range[$i] = false;
}
// get the entries that start with a specific letter
$this->load_alpha = false; // this will ignore the alpha filter on the main query
$db = JFactory::getDbo();
$query = $this->getListQuery(); // retrieve the current main query without the alpha filter (if present)
// Clear unneeded clauses
$query->clear('select');
$query->clear('group');
$query->clear('order');
// add our own select and group
foreach ($group_lengths as $length)
{
$query->select("SUBSTRING(" . $db->qn('e.title') . ", 1, " . $length . ") AS group_" . $length);
$query->group('BINARY(' . $db->qn('group_' . $length) . ')');
}
if ($letters = $db->setQuery($query)->loadObjectList())
{
foreach ($letters as $letter) {
foreach ($group_lengths as $length) {
$value = $this->mb_strtolower($letter->{'group_' . $length});
if (isset($alpha_range[$value])) {
$alpha_range[$value] = JRoute::_($url . '&alpha=' . urlencode($value).$itemId, false);
} elseif (is_numeric($value) && isset($alpha_range['0-9'])) {
$alpha_range['0-9'] = JRoute::_($url . '&alpha=0-9'.$itemId, false);
} elseif (isset($alpha_range['#']) && $length == 1 && !preg_match('/^[A-Za-z0-9]/', $value)) {
$alpha_range['#'] = JRoute::_($url . '&alpha=' . urlencode(JText::_('COM_RSDIRECTORY_SEF_SPECIAL')).$itemId, false);
}
}
}
}
}
else
{
foreach ($alpha_range as $value => $range)
{
if (is_numeric($value))
{
$alpha_range['0-9'] = JRoute::_($url . '&alpha=0-9'.$itemId, false);
}
elseif (!preg_match('/^[A-Za-z0-9]/', $value))
{
if ($value == '#')
{
$alpha_range['#'] = JRoute::_($url . '&alpha=' . urlencode(JText::_('COM_RSDIRECTORY_SEF_SPECIAL')).$itemId, false);
}
else
{
$alpha_range[$value] = JRoute::_($url . '&alpha=' . urlencode($value).$itemId, false);
}
}
else
{
$alpha_range[$value] = JRoute::_($url . '&alpha=' . urlencode($value) . $itemId, false);
}
}
}
return $alpha_range;
}
public function getLettersUrl(){
$app = JFactory::getApplication();
// process the query variables
$uri = JUri::getInstance();
$query_vars = $uri->getQuery(true);
$processed_vars = array(
'option' => 'com_rsdirectory',
'view' => 'entries',
);
$jinput = $app->input;
$is_component = true;
if ($jinput->get('option', '') != 'com_rsdirectory' || $jinput->get('view', '') != 'entries') {
$is_component = false;
}
if (!$is_component) {
$query_vars = $processed_vars;
} else {
foreach ($query_vars as $key => $values) {
if (in_array($key, array('user', 'users', 'status', 'categories', 'f', 'category', 'filter', 'q', 'ratings'))) {
$processed_vars[$key] = $values;
}
}
if (JFactory::getConfig()->get('sef')) {
// add the filter value if present
if ($filter = $jinput->getInt('filter', 0) && !isset($processed_vars['filter'])){
$processed_vars['filter'] = '1';
}
// Check for users
$users = $jinput->get('users', array(), 'array');
// Get single user.
$user = $jinput->getInt('user');
if ($user) {
$users[] = $user;
}
if (count($users) == 1 && !$filter) {
$user = JFactory::getUser($users[0]);
if (!isset($processed_vars['user'])) {
$processed_vars['user'] = RSDirectoryRoute::sef($user->id, $user->name);
}
}
// process categories
$categories = $jinput->get('categories', array(), 'array');
// Get a single category.
$category = $jinput->getInt('category');
if ($category) {
$categories[] = $category;
}
if (count($categories) == 1 && !$filter) {
$categories = RSDirectoryHelper::arrayInt($categories);
// it should only be one
$category = $categories[0];
$catData = RSDirectoryHelper::getCategories($category);
if (!isset($processed_vars['category'])) {
$processed_vars['category'] = RSDirectoryRoute::sef( $category, $catData[0]->alias);
}
}
}
$query_vars = $processed_vars;
}
$query_vars = urldecode(http_build_query($query_vars, '', '&'));
return 'index.php?'.$query_vars;
}
/**
* Method to get a list of entries.
*
* @access public
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Get items.
$items = parent::getItems();
// Exit the function if there are no results.
if (!$items)
return;
return RSDirectoryHelper::getEntriesData($items);
}
protected function getSortFields() {
return array(
'random-asc' => JText::_('COM_RSDIRECTORY_RANDOM'),
'e.price-asc' => JText::_('COM_RSDIRECTORY_PRICE_ASC'),
'e.price-desc' => JText::_('COM_RSDIRECTORY_PRICE_DESC'),
'e.published_time-asc' => JText::_('COM_RSDIRECTORY_PUBLISHED_TIME_ASC'),
'e.published_time-desc' => JText::_('COM_RSDIRECTORY_PUBLISHED_TIME_DESC'),
'modified_last-asc' => JText::_('COM_RSDIRECTORY_MODIFIED_LAST_ASC'),
'modified_last-desc' => JText::_('COM_RSDIRECTORY_MODIFIED_LAST_DESC'),
'e.expiry_time-asc' => JText::_('COM_RSDIRECTORY_EXPIRY_TIME_ASC'),
'e.expiry_time-desc' => JText::_('COM_RSDIRECTORY_EXPIRY_TIME_DESC'),
'e.title-asc' => JText::_('COM_RSDIRECTORY_TITLE_ASC'),
'e.title-desc' => JText::_('COM_RSDIRECTORY_TITLE_DESC'),
'e.big_subtitle-asc' => JText::_('COM_RSDIRECTORY_BIG_SUBTITLE_ASC'),
'e.big_subtitle-desc' => JText::_('COM_RSDIRECTORY_BIG_SUBTITLE_DESC'),
'e.small_subtitle-asc' => JText::_('COM_RSDIRECTORY_SMALL_SUBTITLE_ASC'),
'e.small_subtitle-desc' => JText::_('COM_RSDIRECTORY_SMALL_SUBTITLE_DESC'),
'author-asc' => JText::_('COM_RSDIRECTORY_AUTHOR_ASC'),
'author-desc' => JText::_('COM_RSDIRECTORY_AUTHOR_DESC'),
'e.hits-asc' => JText::_('COM_RSDIRECTORY_HITS_ASC'),
'e.hits-desc' => JText::_('COM_RSDIRECTORY_HITS_DESC'),
'e.ratings_count-asc' => JText::_('COM_RSDIRECTORY_RATINGS_COUNT_ASC'),
'e.ratings_count-desc' => JText::_('COM_RSDIRECTORY_RATINGS_COUNT_DESC'),
'e.avg_rating-asc' => JText::_('COM_RSDIRECTORY_AVG_RATING_ASC'),
'e.avg_rating-desc' => JText::_('COM_RSDIRECTORY_AVG_RATING_DESC')
);
}
protected function splitOrdering($value = null) {
if ($value === null) {
$value = $this->getState('list.ordering');
}
// format is 'column-direction'
$parts = explode('-', $value, 2);
// grab the column
$column = $parts[0];
// grab the direction
if (isset($parts[1])) {
$direction = $parts[1];
} else {
$direction = $this->getState('list.direction');
}
return array($column, $direction);
}
/**
* Method to get a select for the sorting options.
*
* @access public
*
* @return string
*/
public function getSortField()
{
$params = JFactory::getApplication()->getParams();
$fields = $this->getSortFields();
$options = array();
$options[] = JHtml::_('select.option', '', JText::_('COM_RSDIRECTORY_SORT_BY'));
foreach ($fields as $value => $text) {
$value = (string) $value;
$param = 'order_by_'.str_replace(array('e.', '-asc', '-desc'), '', $value);
if ($params->get($param, 1)) {
$options[] = JHtml::_('select.option', $value, $text);
}
}
return JHtml::_( 'select.genericlist', $options, 'filter_order', ' class="input-medium '.RsdirectoryAdapterGrid::formSelect().' '.RsdirectoryAdapterGrid::float('right').'" onchange="adminForm.submit();"', 'value', 'text', $this->getState('list.ordering') );
}
protected function getCategories($id = 'root') {
$options = array(
'extension' => 'com_rsdirectory',
'table' => '#__rsdirectory_entries',
'field' => 'category_id',
'statefield' => 'published',
'countItems' => false
);
// Create a new JCategories object.
$categories = new JCategories($options);
if ($root = $categories->get($id)) {
if ($children = $root->getChildren()) {
return $this->getIds($children);
}
}
return array();
}
protected function getIds($categories) {
$ids = array();
foreach ($categories as $category) {
$ids[] = $category->id;
if ($category->hasChildren()) {
$ids = array_merge($ids, $this->getIds($category->getChildren()));
}
}
return $ids;
}
// for breadcrumbs gets the tree to the specific category
public function getCategoriesTree(){
// Get mainframe.
$app = JFactory::getApplication();
// the selected category
$requestedCategory = $app->input->getInt('category');
// initialize the tree
$theTree = array();
// check if category is set
if (!$requestedCategory) {
return $theTree;
}
$category = JTable::getInstance('Category', 'JTable');
if ($category->load($requestedCategory)) {
$path = $category->getPath();
foreach ($path as $parentCategory) {
if ($parentCategory->id == 1) {
continue;
}
$theTree[] = (object) array(
'id' => $parentCategory->id,
'parent_id' => $parentCategory->parent_id,
'title' => $parentCategory->title,
'link' => RSDirectoryRoute::getCategoryEntriesURL($parentCategory->id, $parentCategory->title)
);
}
}
return $theTree;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists