                                                                                                                                                                                
                                                                                                                                                                                
index.html                                                                                          0000705                 00000000037 15242036640 0006541 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <!DOCTYPE html><title></title>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 tmpl/default.php                                                                                    0000705                 00000002035 15242036640 0007655 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_tags_similar
 *
 * @copyright   (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

?>
<div class="tagssimilar<?php echo $moduleclass_sfx; ?>">
<?php if ($list) : ?>
	<ul>
	<?php foreach ($list as $i => $item) : ?>
		<li>
			<?php if (($item->type_alias === 'com_users.category') || ($item->type_alias === 'com_banners.category')) : ?>
				<?php if (!empty($item->core_title)) : ?>
					<?php echo htmlspecialchars($item->core_title, ENT_COMPAT, 'UTF-8'); ?>
				<?php endif; ?>
			<?php else : ?>
				<a href="<?php echo JRoute::_($item->link); ?>">
					<?php if (!empty($item->core_title)) : ?>
						<?php echo htmlspecialchars($item->core_title, ENT_COMPAT, 'UTF-8'); ?>
					<?php endif; ?>
				</a>
			<?php endif; ?>
		</li>
	<?php endforeach; ?>
	</ul>
<?php else : ?>
	<span><?php echo JText::_('MOD_TAGS_SIMILAR_NO_MATCHING_TAGS'); ?></span>
<?php endif; ?>
</div>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   tmpl/index.html                                                                                     0000705                 00000000037 15242036640 0007515 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <!DOCTYPE html><title></title>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 mod_tags_similar.xml                                                                                0000705                 00000005663 15242036640 0010615 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1" client="site" method="upgrade">
	<name>mod_tags_similar</name>
	<author>Joomla! Project</author>
	<creationDate>January 2013</creationDate>
	<copyright>(C) 2013 Open Source Matters, Inc.</copyright>
	<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
	<authorEmail>admin@joomla.org</authorEmail>
	<authorUrl>www.joomla.org</authorUrl>
	<version>3.1.0</version>
	<description>MOD_TAGS_SIMILAR_XML_DESCRIPTION</description>
	<files>
		<filename module="mod_tags_similar">mod_tags_similar.php</filename>
		<folder>tmpl</folder>
		<filename>helper.php</filename>
	</files>
	<languages>
		<language tag="en-GB">en-GB.mod_tags_similar.ini</language>
		<language tag="en-GB">en-GB.mod_tags_similar.sys.ini</language>
	</languages>
	<help key="JHELP_EXTENSIONS_MODULE_MANAGER_TAGS_SIMILAR" />
	<config>
		<fields name="params">
			<fieldset name="basic">
				<field
					name="maximum"
					type="integer"
					label="MOD_TAGS_SIMILAR_MAX_LABEL"
					description="MOD_TAGS_SIMILAR_MAX_DESC"
					default="5"
					filter="integer"
					first="1"
					last="20"
					step="1"
				/>

				<field
					name="matchtype"
					type="list"
					label="MOD_TAGS_SIMILAR_FIELD_MATCHTYPE_LABEL"
					description="MOD_TAGS_SIMILAR_FIELD_MATCHTYPE_DESC"
					default="any"
					>
					<option value="all">MOD_TAGS_SIMILAR_FIELD_ALL</option>
					<option value="any">MOD_TAGS_SIMILAR_FIELD_ONE</option>
					<option value="half">MOD_TAGS_SIMILAR_FIELD_HALF</option>
				</field>

				<field
					name="ordering"
					type="list"
					label="MOD_TAGS_SIMILAR_FIELD_ORDERING_LABEL"
					description="MOD_TAGS_SIMILAR_FIELD_ORDERING_DESC"
					default="count"
					>
					<option value="count">MOD_TAGS_SIMILAR_FIELD_ORDERING_COUNT</option>
					<option value="random">MOD_TAGS_SIMILAR_FIELD_ORDERING_RANDOM</option>
					<option value="countrandom">MOD_TAGS_SIMILAR_FIELD_ORDERING_COUNT_AND_RANDOM</option>
				</field>
			</fieldset>
			<fieldset name="advanced">
				<field
					name="layout"
					type="modulelayout"
					label="JFIELD_ALT_LAYOUT_LABEL"
					description="JFIELD_ALT_MODULE_LAYOUT_DESC"
					validate="moduleLayout"
				/>

				<field
					name="moduleclass_sfx"
					type="textarea"
					label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
					description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC"
					rows="3"
				/>

				<field
					name="owncache"
					type="list"
					label="COM_MODULES_FIELD_CACHING_LABEL"
					description="COM_MODULES_FIELD_CACHING_DESC"
					default="1"
					filter="integer"
					>
					<option value="1">JGLOBAL_USE_GLOBAL</option>
					<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
				</field>

				<field
					name="cache_time"
					type="number"
					label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
					description="COM_MODULES_FIELD_CACHE_TIME_DESC"
					default="900"
					filter="integer"
				/>
			</fieldset>
		</fields>
	</config>
</extension>
                                                                             helper.php                                                                                          0000705                 00000011753 15242036640 0006543 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_tags_similar
 *
 * @copyright   (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');

/**
 * Helper for mod_tags_similar
 *
 * @since  3.1
 */
abstract class ModTagssimilarHelper
{
	/**
	 * Get a list of tags
	 *
	 * @param   Registry  &$params  Module parameters
	 *
	 * @return  array
	 */
	public static function getList(&$params)
	{
		$app        = JFactory::getApplication();
		$option     = $app->input->get('option');
		$view       = $app->input->get('view');

		// For now assume com_tags and com_users do not have tags.
		// This module does not apply to list views in general at this point.
		if ($option === 'com_tags' || $view === 'category' || $option === 'com_users')
		{
			return array();
		}

		$db         = JFactory::getDbo();
		$user       = JFactory::getUser();
		$groups     = implode(',', $user->getAuthorisedViewLevels());
		$matchtype  = $params->get('matchtype', 'all');
		$maximum    = $params->get('maximum', 5);
		$ordering   = $params->get('ordering', 'count');
		$tagsHelper = new JHelperTags;
		$prefix     = $option . '.' . $view;
		$id         = $app->input->getInt('id');
		$now        = JFactory::getDate()->toSql();
		$nullDate   = $db->getNullDate();

		$tagsToMatch = $tagsHelper->getTagIds($id, $prefix);

		if (!$tagsToMatch || $tagsToMatch === null)
		{
			return array();
		}

		$tagCount = substr_count($tagsToMatch, ',') + 1;

		$query = $db->getQuery(true)
			->select(
				array(
					$db->quoteName('m.core_content_id'),
					$db->quoteName('m.content_item_id'),
					$db->quoteName('m.type_alias'),
					'COUNT( ' . $db->quoteName('tag_id') . ') AS ' . $db->quoteName('count'),
					$db->quoteName('ct.router'),
					$db->quoteName('cc.core_title'),
					$db->quoteName('cc.core_alias'),
					$db->quoteName('cc.core_catid'),
					$db->quoteName('cc.core_language'),
					$db->quoteName('cc.core_params'),
				)
			);

		$query->from($db->quoteName('#__contentitem_tag_map', 'm'));

		$query->join('INNER', $db->quoteName('#__tags', 't') . ' ON m.tag_id = t.id')
			->join('INNER', $db->quoteName('#__ucm_content', 'cc') . ' ON m.core_content_id = cc.core_content_id')
			->join('INNER', $db->quoteName('#__content_types', 'ct') . ' ON m.type_alias = ct.type_alias');

		$query->where($db->quoteName('m.tag_id') . ' IN (' . $tagsToMatch . ')');
		$query->where('t.access IN (' . $groups . ')');
		$query->where('(cc.core_access IN (' . $groups . ') OR cc.core_access = 0)');

		// Don't show current item
		$query->where('(' . $db->quoteName('m.content_item_id') . ' <> ' . $id
			. ' OR ' . $db->quoteName('m.type_alias') . ' <> ' . $db->quote($prefix) . ')'
		);

		// Only return published tags
		$query->where($db->quoteName('cc.core_state') . ' = 1 ')
			->where('(' . $db->quoteName('cc.core_publish_up') . '=' . $db->quote($nullDate) . ' OR '
				. $db->quoteName('cc.core_publish_up') . '<=' . $db->quote($now) . ')'
			)
			->where('(' . $db->quoteName('cc.core_publish_down') . '=' . $db->quote($nullDate) . ' OR '
				. $db->quoteName('cc.core_publish_down') . '>=' . $db->quote($now) . ')'
			);

		// Optionally filter on language
		$language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');

		if ($language !== 'all')
		{
			if ($language === 'current_language')
			{
				$language = JHelperContent::getCurrentLanguage();
			}

			$query->where($db->quoteName('cc.core_language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
		}

		$query->group(
			$db->quoteName(
				array('m.core_content_id', 'm.content_item_id', 'm.type_alias', 'ct.router', 'cc.core_title',
				'cc.core_alias', 'cc.core_catid', 'cc.core_language', 'cc.core_params')
			)
		);

		if ($matchtype === 'all' && $tagCount > 0)
		{
			$query->having('COUNT( ' . $db->quoteName('tag_id') . ')  = ' . $tagCount);
		}
		elseif ($matchtype === 'half' && $tagCount > 0)
		{
			$tagCountHalf = ceil($tagCount / 2);
			$query->having('COUNT( ' . $db->quoteName('tag_id') . ')  >= ' . $tagCountHalf);
		}

		if ($ordering === 'count' || $ordering === 'countrandom')
		{
			$query->order($db->quoteName('count') . ' DESC');
		}

		if ($ordering === 'random' || $ordering === 'countrandom')
		{
			$query->order($query->Rand());
		}

		$db->setQuery($query, 0, $maximum);

		try
		{
			$results = $db->loadObjectList();
		}
		catch (RuntimeException $e)
		{
			$results = array();
			JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
		}

		foreach ($results as $result)
		{
			$result->link = TagsHelperRoute::getItemRoute(
				$result->content_item_id,
				$result->core_alias,
				$result->core_catid,
				$result->core_language,
				$result->type_alias,
				$result->router
			);

			$result->core_params = new Registry($result->core_params);
		}

		return $results;
	}
}
                     mod_tags_similar.php                                                                                0000705                 00000001634 15242036640 0010576 0                                                                                                    ustar 00                                                                                                                                                                                                                                                       <?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_tags_similar
 *
 * @copyright   (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Include the tags_similar functions only once
JLoader::register('ModTagssimilarHelper', __DIR__ . '/helper.php');

$cacheparams = new stdClass;
$cacheparams->cachemode = 'safeuri';
$cacheparams->class = 'ModTagssimilarHelper';
$cacheparams->method = 'getList';
$cacheparams->methodparams = $params;
$cacheparams->modeparams = array('id' => 'array', 'Itemid' => 'int');

$list = JModuleHelper::moduleCache($module, $params, $cacheparams);

if (!count($list))
{
	return;
}

$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8');

require JModuleHelper::getLayoutPath('mod_tags_similar', $params->get('layout', 'default'));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    