Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature, Multilanguage: Add the possibility of displaying associations in article info and in articles list #11935

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions administrator/components/com_content/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@
hr="true"
/>

<field
name="show_associations"
type="radio"
class="btn-group btn-group-yesno"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC"
default="0"
>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

<field
name="flags"
type="radio"
class="btn-group btn-group-yesno"
label="JGLOBAL_SHOW_FLAG_LABEL"
description="JGLOBAL_SHOW_FLAG_DESC"
default="1"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="spacer3"
type="spacer"
hr="true"
/>

<field
name="show_author"
type="radio"
Expand Down
11 changes: 11 additions & 0 deletions administrator/components/com_content/models/forms/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="show_associations"
type="list"
class="chzn-color"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC">
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

<field
name="show_author"
Expand Down
4 changes: 4 additions & 0 deletions administrator/language/en-GB/en-GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ JGLOBAL_SELECTION_ALL="Select All"
JGLOBAL_SELECTION_INVERT="Toggle Selection"
JGLOBAL_SELECTION_INVERT_ALL="Toggle All Selections"
JGLOBAL_SELECTION_NONE="Clear Selection"
JGLOBAL_SHOW_ASSOCIATIONS_DESC="Multilingual only. If set to Show, the associated articles flags or URL Language Code will be displayed."
JGLOBAL_SHOW_ASSOCIATIONS_LABEL="Show Associations"
JGLOBAL_SHOW_AUTHOR_DESC="If set to Show, the Name of the article's Author will be displayed."
JGLOBAL_SHOW_AUTHOR_LABEL="Show Author"
JGLOBAL_SHOW_CATEGORY_DESC="If set to Show, the title of the article&rsquo;s category will show."
Expand All @@ -506,6 +508,8 @@ JGLOBAL_SHOW_FEATURED_ARTICLES_DESC="Select to show, hide or only display featur
JGLOBAL_SHOW_FEATURED_ARTICLES_LABEL="Featured Articles"
JGLOBAL_SHOW_FEED_LINK_DESC="Show or hide an RSS Feed Link. (A Feed Link will show up as a feed icon in the address bar of most modern browsers)."
JGLOBAL_SHOW_FEED_LINK_LABEL="Show Feed Link"
JGLOBAL_SHOW_FLAG_DESC="If set to 'Yes', will display language choice as image flags. Otherwise will use the content language URL Language Code."
JGLOBAL_SHOW_FLAG_LABEL="Use Image Flags"
JGLOBAL_SHOW_FULL_DESCRIPTION="Show full description ..."
JGLOBAL_SHOW_HEADINGS_DESC="Show or hide the headings in list layouts."
JGLOBAL_SHOW_HEADINGS_LABEL="Table Headings"
Expand Down
64 changes: 63 additions & 1 deletion components/com_content/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getAssociations($id = 0, $view = null)
$view = is_null($view) ? $jinput->get('view') : $view;
$id = empty($id) ? $jinput->getInt('id') : $id;

if ($view == 'article')
if ($view == 'article' || $view == 'category' || $view == 'featured')
{
if ($id)
{
Expand All @@ -60,4 +60,66 @@ public static function getAssociations($id = 0, $view = null)

return array();
}

/**
* Method to display in frontend the associations for a given article
*
* @param integer $id Id of the article
*
* @return string The url of each associated article
*
* @since __DEPLOY_VERSION__
*/
public static function displayAssociations($id)
{
$url_assoc = '';
$associations = self::getAssociations($id);

if (!empty($associations))
{
jimport('joomla.application.component.helper');
$params = JComponentHelper::getParams('com_content');
$levels = JFactory::getUser()->getAuthorisedViewLevels();
$languages = JLanguageHelper::getLanguages();

foreach ($associations as $key => $value)
{
foreach ($languages as $language)
{
// Do not display language without frontend UI
if (!array_key_exists($language->lang_code, JLanguageMultilang::getSiteLangs()))
{
$key == null;
}
// Do not display language without specific home menu
elseif (!array_key_exists($key, JLanguageMultilang::getSiteHomePages()))
{
$key == null;
}
// Do not display language without authorized access level
elseif (isset($language->access) && $language->access && !in_array($language->access, $levels))
{
$key == null;
}
elseif (isset($key) && ($key == $language->lang_code))
{
$class = 'label label-association label-' . $language->sef;
$url = '&nbsp;<a class="' . $class . '" href="' . JRoute::_($value) . '">' . strtoupper($language->sef) . '</a>&nbsp;';

if ($params->get('flags', 1))
{
$flag = JHtml::_('image', 'mod_languages/' . $language->image . '.gif',
$language->title_native, array('title' => $language->title_native), true
);
$url = '&nbsp;<a href="' . JRoute::_($value) . '">' . $flag . '</a>&nbsp;';
}

$url_assoc .= $url;
}
}
}
}

return $url_assoc;
}
}
8 changes: 6 additions & 2 deletions components/com_content/views/article/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
$canEdit = $params->get('access-edit');
$user = JFactory::getUser();
$info = $params->get('info_block_position', 0);

// Check if associations are implemented. If they are, define the parameter.
$assocParam = JLanguageAssociations::isEnabled() ? $params->get('show_associations') : '';
JHtml::_('behavior.caption');

?>
<div class="item-page<?php echo $this->pageclass_sfx; ?>" itemscope itemtype="https://schema.org/Article">
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? JFactory::getConfig()->get('language') : $this->item->language; ?>" />
Expand All @@ -35,7 +39,7 @@

<?php // Todo Not that elegant would be nice to group the params ?>
<?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') ); ?>
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') || $assocParam); ?>

<?php if (!$useDefList && $this->print) : ?>
<div id="pop-print" class="btn hidden-print">
Expand Down Expand Up @@ -134,7 +138,7 @@
<?php // Optional teaser intro text for guests ?>
<?php elseif ($params->get('show_noauth') == true && $user->get('guest')) : ?>
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
<?php echo JHtml::_('content.prepare', $this->item->introtext); ?>
<?php echo JHtml::_('content.prepare', $this->item->introtext); ?>
<?php // Optional link to let them register to see the whole article. ?>
<?php if ($params->get('show_readmore') && $this->item->fulltext != null) : ?>
<?php $menu = JFactory::getApplication()->getMenu(); ?>
Expand Down
11 changes: 11 additions & 0 deletions components/com_content/views/article/tmpl/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@
<option value="0">JNO</option>
</field>

<field
name="show_associations"
type="radio"
class="btn-group"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC">
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

<field
name="show_author"
type="radio"
Expand Down
16 changes: 14 additions & 2 deletions components/com_content/views/category/tmpl/blog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@
<option value="1">JYES</option>
</field>

<field
name="show_associations"
type="list"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC"
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="use_article">COM_CONTENT_FIELD_VALUE_USE_ARTICLE_SETTINGS</option>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>

<field
name="show_author"
type="list"
Expand All @@ -438,8 +450,8 @@
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="use_article">COM_CONTENT_FIELD_VALUE_USE_ARTICLE_SETTINGS</option>
<option value="0">JNo</option>
<option value="1">JYes</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
Expand Down
6 changes: 5 additions & 1 deletion components/com_content/views/category/tmpl/blog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
$canEdit = $this->item->params->get('access-edit');
$info = $params->get('info_block_position', 0);

// Check if associations are implemented. If they are, define the parameter.
$assocParam = JLanguageAssociations::isEnabled() ? $params->get('show_associations') : '';

?>
<?php if ($this->item->state == 0 || strtotime($this->item->publish_up) > strtotime(JFactory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(JFactory::getDate())) && $this->item->publish_down != JFactory::getDbo()->getNullDate())) : ?>
Expand All @@ -32,7 +36,7 @@

<?php // Todo Not that elegant would be nice to group the params ?>
<?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') ); ?>
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') || $assocParam); ?>

<?php if ($useDefList && ($info == 0 || $info == 2)) : ?>
<?php echo JLayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above')); ?>
Expand Down
11 changes: 11 additions & 0 deletions components/com_content/views/category/tmpl/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,17 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="show_associations"
type="list"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC"
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

<field name="show_author" type="list"
description="JGLOBAL_SHOW_AUTHOR_DESC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JLoader::register('ContentHelperAssociation', JPATH_SITE . '/components/com_content/helpers/association.php');

// Create some shortcuts.
$params = &$this->item->params;
Expand Down Expand Up @@ -135,6 +136,9 @@
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language)); ?>">
<?php echo $this->escape($article->title); ?>
</a>
<?php if (JLanguageAssociations::isEnabled() && $this->params->get('show_associations')) : ?>
<?php echo ContentHelperAssociation::displayAssociations($id = $article->id); ?>
<?php endif; ?>
<?php else: ?>
<?php
echo $this->escape($article->title) . ' : ';
Expand All @@ -147,6 +151,9 @@
<a href="<?php echo $link; ?>" class="register">
<?php echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE'); ?>
</a>
<?php if (JLanguageAssociations::isEnabled() && $this->params->get('show_associations')) : ?>
<?php echo ContentHelperAssociation::displayAssociations($id = $article->id); ?>
<?php endif; ?>
<?php endif; ?>
<?php if ($article->state == 0) : ?>
<span class="list-published label label-warning">
Expand Down
11 changes: 11 additions & 0 deletions components/com_content/views/featured/tmpl/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@
<option value="1">JYES</option>
</field>

<field
name="show_associations"
type="list"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
description="JGLOBAL_SHOW_ASSOCIATIONS_DESC"
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>

<field name="show_author" type="list"
description="JGLOBAL_SHOW_AUTHOR_DESC"
label="JGLOBAL_SHOW_AUTHOR_LABEL"
Expand Down
5 changes: 4 additions & 1 deletion components/com_content/views/featured/tmpl/default_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
$canEdit = $this->item->params->get('access-edit');
$info = $this->item->params->get('info_block_position', 0);

// Check if associations are implemented. If they are, define the parameter.
$assocParam = JLanguageAssociations::isEnabled() ? $params->get('show_associations') : '';

?>

<?php if ($this->item->state == 0 || strtotime($this->item->publish_up) > strtotime(JFactory::getDate())
Expand Down Expand Up @@ -50,7 +53,7 @@

<?php // Todo Not that elegant would be nice to group the params ?>
<?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') ); ?>
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') || $assocParam); ?>

<?php if ($useDefList && ($info == 0 || $info == 2)) : ?>
<?php echo JLayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above')); ?>
Expand Down
1 change: 1 addition & 0 deletions language/en-GB/en-GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ JALL="All"
JALL_LANGUAGE="All"
JAPPLY="Save"
JARCHIVED="Archived"
JASSOCIATIONS="Also available:"
JAUTHOR="Author"
JCANCEL="Cancel"
JCATEGORY="Category"
Expand Down
19 changes: 19 additions & 0 deletions layouts/joomla/content/info_block/associations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('JPATH_BASE') or die;
JLoader::register('ContentHelperAssociation', JPATH_SITE . '/components/com_content/helpers/association.php');
$id = $displayData['item']->id;
?>
<?php if (ContentHelperAssociation::displayAssociations($id) != null) : ?>
<dd class="association">
<?php echo JText::_('JASSOCIATIONS'); ?>
<?php echo ContentHelperAssociation::displayAssociations($id); ?>
</dd>
<?php endif; ?>
5 changes: 5 additions & 0 deletions layouts/joomla/content/info_block/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@
<?php echo JLayoutHelper::render('joomla.content.info_block.category', $displayData); ?>
<?php endif; ?>

<?php if ($displayData['params']->get('show_associations')) : ?>
<?php echo JLayoutHelper::render('joomla.content.info_block.associations', $displayData); ?>
<?php endif; ?>

<?php if ($displayData['params']->get('show_publish_date')) : ?>
<?php echo JLayoutHelper::render('joomla.content.info_block.publish_date', $displayData); ?>
<?php endif; ?>

<?php endif; ?>

<?php if ($displayData['position'] == 'above' && ($blockPosition == 0)
Expand Down