Skip to content

Commit

Permalink
Forcing taxonomies to honour state and access settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar committed Aug 2, 2018
1 parent ce20992 commit c287073
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 4 deletions.
10 changes: 10 additions & 0 deletions administrator/components/com_finder/helpers/indexer/result.php
Expand Up @@ -545,5 +545,15 @@ public function unserialize($serialized)
$this->type_id,
$this->url
) = unserialize($serialized);

foreach ($this->taxonomy as $nodes)
{
foreach ($nodes as $node)
{
$curTaxonomy = FinderIndexerTaxonomy::getTaxonomy($node->id);
$node->state = $curTaxonomy->state;
$node->access = $curTaxonomy->access;
}
}
}
}
89 changes: 86 additions & 3 deletions administrator/components/com_finder/helpers/indexer/taxonomy.php
Expand Up @@ -20,15 +20,23 @@
class FinderIndexerTaxonomy
{
/**
* An internal cache of taxonomy branch data.
* An internal cache of taxonomy data.
*
* @var array
* @since 2.5
* @since __DEPLOY_VERSION__
*/
public static $taxonomies = array();

/**
* An internal cache of branch data.
*
* @var array
* @since __DEPLOY_VERSION__
*/
public static $branches = array();

/**
* An internal cache of taxonomy node data.
* An internal cache of taxonomy node data for inserting it.
*
* @var array
* @since 2.5
Expand Down Expand Up @@ -368,4 +376,79 @@ public static function removeOrphanNodes()

return $db->getAffectedRows();
}

/**
* Get a taxonomy based on its id or all taxonomies
*
* @param integer $id Id of the taxonomy
*
* @return object|array A taxonomy object or an array of all taxonomies
*
* @since __DEPLOY_VERSION__
*/
public static function getTaxonomy($id = 0)
{
if (!count(self::$taxonomies))
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select(array('id','parent_id','lft','rgt','level',
'path','title','alias','state','access','language'))
->from($db->quoteName('#__finder_taxonomy'))
->order($db->quoteName('lft'));

$db->setQuery($query);
self::$taxonomies = $db->loadObjectList('id');
}

if ($id == 0)
{
return self::$taxonomies;
}

if (isset(self::$taxonomies[$id]))
{
return self::$taxonomies[$id];
}

return false;
}

/**
* Get a taxonomy branch object based on its title or all branches
*
* @param string $title Title of the branch
*
* @return object|array The object with the branch data or an array of all branches
*
* @since __DEPLOY_VERSION__
*/
public static function getBranch($title = '')
{
if (!count(self::$branches))
{
$taxonomies = self::getTaxonomy();

foreach ($taxonomies as $t)
{
if ($t->level == 1)
{
self::$branches[$t->title] = $t;
}
}
}

if ($title == '')
{
return self::$branches;
}

if (isset(self::$branches[$title]))
{
return self::$branches[$title];
}

return false;
}
}
18 changes: 17 additions & 1 deletion components/com_finder/tmpl/search/default_result.php
Expand Up @@ -11,6 +11,8 @@

use Joomla\String\StringHelper;

$user = JFactory::getUser();

// Get the mime type class.
$mime = !empty($this->result->mime) ? 'mime-' . $this->result->mime : null;

Expand Down Expand Up @@ -52,7 +54,21 @@
<?php if (count($taxonomies) && $this->params->get('show_taxonomy', 1)) : ?>
<dd class="result-taxonomy">
<?php foreach ($taxonomies as $type => $taxonomy) : ?>
<span class="badge badge-secondary"><?php echo $type . ': ' . implode(',', array_column($taxonomy, 'title')); ?></span>
<?php $branch = FinderIndexerTaxonomy::getBranch($type); ?>
<?php if ($branch->state == 1 && in_array($branch->access, $user->getAuthorisedViewLevels())) : ?>
<?php
$taxonomy_text = array();

foreach ($taxonomy as $node) :
if ($node->state == 1 && in_array($node->access, $user->getAuthorisedViewLevels())) :
$taxonomy_text[] = $node->title;
endif;
endforeach;

if (count($taxonomy_text)) : ?>
<span class="badge badge-secondary"><?php echo $type . ': ' . implode(',', $taxonomy_text); ?></span>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</dd>
<?php endif; ?>
Expand Down

0 comments on commit c287073

Please sign in to comment.