From 8899f62867f1d9043fcb66b7961951e8156890d6 Mon Sep 17 00:00:00 2001 From: Jean-Marie Simonet Date: Mon, 5 Sep 2016 11:56:27 +0200 Subject: [PATCH 1/4] New Feature: Multilanguage, Add the possibility of displaying associations in article info and in articles list --- .../components/com_content/config.xml | 31 +++++++++ .../com_content/models/forms/article.xml | 11 ++++ administrator/language/en-GB/en-GB.ini | 4 ++ .../com_content/helpers/association.php | 64 ++++++++++++++++++- .../views/article/tmpl/default.php | 8 ++- .../views/article/tmpl/default.xml | 11 ++++ .../com_content/views/category/tmpl/blog.xml | 16 ++++- .../views/category/tmpl/blog_item.php | 6 +- .../views/category/tmpl/default.xml | 11 ++++ .../views/category/tmpl/default_articles.php | 7 ++ .../views/featured/tmpl/default.xml | 11 ++++ .../views/featured/tmpl/default_item.php | 5 +- language/en-GB/en-GB.ini | 1 + .../content/info_block/associations.php | 19 ++++++ layouts/joomla/content/info_block/block.php | 5 ++ 15 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 layouts/joomla/content/info_block/associations.php diff --git a/administrator/components/com_content/config.xml b/administrator/components/com_content/config.xml index 41d2f1203edbf..3f1668772194a 100644 --- a/administrator/components/com_content/config.xml +++ b/administrator/components/com_content/config.xml @@ -122,6 +122,37 @@ hr="true" /> + + + + + + + + + + + + JNO + + + + + + get('view') : $view; $id = empty($id) ? $jinput->getInt('id') : $id; - if ($view == 'article') + if ($view == 'article' || $view == 'category' || $view == 'featured') { if ($id) { @@ -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 = 0) + { + jimport('joomla.application.component.helper'); + $params = JComponentHelper::getParams('com_content'); + + $levels = JFactory::getUser()->getAuthorisedViewLevels(); + $languages = JLanguageHelper::getLanguages(); + + if (self::getAssociations($id) != null) + { + $associations = self::getAssociations($id); + + 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)) + { + if ($params->get('flags', 1)) + { + $flag = JHtml::_('image', 'mod_languages/' . $language->image . '.gif', + $language->title_native, array('title' => $language->title_native), true + ); + $url = ' ' . JRoute::_('' . $flag . '') . ' '; + } + else + { + $class = 'label label-association label-' . $language->sef; + $url = ' ' . JRoute::_('' . strtoupper($language->sef) . '') . ' '; + } + + echo $url; + } + } + } + } + } } diff --git a/components/com_content/views/article/tmpl/default.php b/components/com_content/views/article/tmpl/default.php index a6e6de972ad4c..2ccc940142192 100644 --- a/components/com_content/views/article/tmpl/default.php +++ b/components/com_content/views/article/tmpl/default.php @@ -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'); + ?>
@@ -35,7 +39,7 @@ 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); ?> print) : ?>
@@ -134,7 +138,7 @@ get('show_noauth') == true && $user->get('guest')) : ?> item); ?> - item->introtext); ?> + item->introtext); ?> get('show_readmore') && $this->item->fulltext != null) : ?> getMenu(); ?> diff --git a/components/com_content/views/article/tmpl/default.xml b/components/com_content/views/article/tmpl/default.xml index 4f4e9763c6428..d873a5d5c645d 100644 --- a/components/com_content/views/article/tmpl/default.xml +++ b/components/com_content/views/article/tmpl/default.xml @@ -131,6 +131,17 @@ + + + + + + JYES + + + + + + + - - + + 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') : ''; + ?> 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())) : ?> @@ -32,7 +36,7 @@ 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); ?> $this->item, 'params' => $params, 'position' => 'above')); ?> diff --git a/components/com_content/views/category/tmpl/default.xml b/components/com_content/views/category/tmpl/default.xml index 6fe9f78f62caa..25875d3b64b8d 100644 --- a/components/com_content/views/category/tmpl/default.xml +++ b/components/com_content/views/category/tmpl/default.xml @@ -346,6 +346,17 @@ + + + + + + item->params; @@ -135,6 +136,9 @@ escape($article->title); ?> + params->get('show_associations')) : ?> + id); ?> + escape($article->title) . ' : '; @@ -147,6 +151,9 @@ + params->get('show_associations')) : ?> + id); ?> + state == 0) : ?> diff --git a/components/com_content/views/featured/tmpl/default.xml b/components/com_content/views/featured/tmpl/default.xml index b62b0c6fc2273..46bfa001c8d49 100644 --- a/components/com_content/views/featured/tmpl/default.xml +++ b/components/com_content/views/featured/tmpl/default.xml @@ -221,6 +221,17 @@ + + + + + + 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') : ''; + ?> item->state == 0 || strtotime($this->item->publish_up) > strtotime(JFactory::getDate()) @@ -50,7 +53,7 @@ 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); ?> $this->item, 'params' => $params, 'position' => 'above')); ?> diff --git a/language/en-GB/en-GB.ini b/language/en-GB/en-GB.ini index 79f7aaedd4bce..6a939244d3c62 100644 --- a/language/en-GB/en-GB.ini +++ b/language/en-GB/en-GB.ini @@ -52,6 +52,7 @@ JALL="All" JALL_LANGUAGE="All" JAPPLY="Save" JARCHIVED="Archived" +JASSOCIATIONS="Associations:" JAUTHOR="Author" JCANCEL="Cancel" JCATEGORY="Category" diff --git a/layouts/joomla/content/info_block/associations.php b/layouts/joomla/content/info_block/associations.php new file mode 100644 index 0000000000000..3739f2d3acbaf --- /dev/null +++ b/layouts/joomla/content/info_block/associations.php @@ -0,0 +1,19 @@ +id; +?> + +
+ + +
+ diff --git a/layouts/joomla/content/info_block/block.php b/layouts/joomla/content/info_block/block.php index a82946972cf0e..67467188b7335 100644 --- a/layouts/joomla/content/info_block/block.php +++ b/layouts/joomla/content/info_block/block.php @@ -36,9 +36,14 @@ + get('show_associations')) : ?> + + + get('show_publish_date')) : ?> + Date: Mon, 5 Sep 2016 11:58:56 +0200 Subject: [PATCH 2/4] separate display flags --- administrator/components/com_content/config.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/administrator/components/com_content/config.xml b/administrator/components/com_content/config.xml index 3f1668772194a..a28a70046d995 100644 --- a/administrator/components/com_content/config.xml +++ b/administrator/components/com_content/config.xml @@ -141,7 +141,6 @@ label="JGLOBAL_SHOW_FLAG_LABEL" description="JGLOBAL_SHOW_FLAG_DESC" default="1" - showon="show_associations:1" > From 9d20270afbdf792c278fa9ff46e5524360297b50 Mon Sep 17 00:00:00 2001 From: Jean-Marie Simonet Date: Tue, 6 Sep 2016 10:18:25 +0200 Subject: [PATCH 3/4] Change string to "Also available:" --- language/en-GB/en-GB.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language/en-GB/en-GB.ini b/language/en-GB/en-GB.ini index 6a939244d3c62..05c3a632b2218 100644 --- a/language/en-GB/en-GB.ini +++ b/language/en-GB/en-GB.ini @@ -52,7 +52,7 @@ JALL="All" JALL_LANGUAGE="All" JAPPLY="Save" JARCHIVED="Archived" -JASSOCIATIONS="Associations:" +JASSOCIATIONS="Also available:" JAUTHOR="Author" JCANCEL="Cancel" JCATEGORY="Category" From 7cb21c47b25aba82f06022680fa83cb8db221f18 Mon Sep 17 00:00:00 2001 From: Jean-Marie Simonet Date: Wed, 7 Sep 2016 10:02:57 +0200 Subject: [PATCH 4/4] improving helper and info-block --- .../com_content/helpers/association.php | 30 +++++++++---------- .../content/info_block/associations.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index 1acddd67e3f13..60b154e75e5f8 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -70,17 +70,17 @@ public static function getAssociations($id = 0, $view = null) * * @since __DEPLOY_VERSION__ */ - public static function displayAssociations($id = 0) + public static function displayAssociations($id) { - jimport('joomla.application.component.helper'); - $params = JComponentHelper::getParams('com_content'); + $url_assoc = ''; + $associations = self::getAssociations($id); - $levels = JFactory::getUser()->getAuthorisedViewLevels(); - $languages = JLanguageHelper::getLanguages(); - - if (self::getAssociations($id) != null) + if (!empty($associations)) { - $associations = self::getAssociations($id); + jimport('joomla.application.component.helper'); + $params = JComponentHelper::getParams('com_content'); + $levels = JFactory::getUser()->getAuthorisedViewLevels(); + $languages = JLanguageHelper::getLanguages(); foreach ($associations as $key => $value) { @@ -103,23 +103,23 @@ public static function displayAssociations($id = 0) } elseif (isset($key) && ($key == $language->lang_code)) { + $class = 'label label-association label-' . $language->sef; + $url = ' ' . strtoupper($language->sef) . ' '; + if ($params->get('flags', 1)) { $flag = JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, array('title' => $language->title_native), true ); - $url = ' ' . JRoute::_('' . $flag . '') . ' '; - } - else - { - $class = 'label label-association label-' . $language->sef; - $url = ' ' . JRoute::_('' . strtoupper($language->sef) . '') . ' '; + $url = ' ' . $flag . ' '; } - echo $url; + $url_assoc .= $url; } } } } + + return $url_assoc; } } diff --git a/layouts/joomla/content/info_block/associations.php b/layouts/joomla/content/info_block/associations.php index 3739f2d3acbaf..b79229448cdfe 100644 --- a/layouts/joomla/content/info_block/associations.php +++ b/layouts/joomla/content/info_block/associations.php @@ -11,7 +11,7 @@ JLoader::register('ContentHelperAssociation', JPATH_SITE . '/components/com_content/helpers/association.php'); $id = $displayData['item']->id; ?> - +