Permalink
Browse files

Adds support for hreflang meta tag for multilingual websites, in Admi…

…n_ContentPage module and language library.
  • Loading branch information...
JB Lebrun
JB Lebrun committed Oct 26, 2018
1 parent 0c20e20 commit feeadaaf8361a34fd47958ad4146498bac44afb9
@@ -4,11 +4,11 @@
* @details Engine / Tool Library
* @file engine/lib/tool/language.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.1
* @version 1.0.2
* @date Creation: Jun 2005
* @date Modification: Apr 2018
* @date Modification: Oct 2018
* @copyright 2015 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
global $languages;
@@ -32,54 +32,61 @@ define("LANG_ICON_DEFAULT", "default");
* @var array $languages
*/
$languages = array(
'en' => array(
'en' => array(
'title' => 'English',
'extend' => 'en-gb',
'locale' => array(
'' => array('en_GB'),
),
),
),
),
'fr' => array(
'title' => 'Fran&ccedil;ais',
'extend' => 'fr-fr',
'locale' => array(
'' => array('fr_FR', 'french', 'france', 'fr_FR@euro'),
'utf8' => array('fr_FR.utf8', 'fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR', 'french', 'france', 'fr_FR@euro'),
'iso88591' => array('fr_FR.iso88591', 'fr_FR.iso885915@euro', 'fr_FR.8859-1', 'fr_FR.88591', 'fr_FR.ISO8859-1', 'fr_FR', 'french', 'france', 'fr_FR@euro'),
),
),
),
),
'de' => array(
'title' => 'Deutsch',
'title' => 'Deutsch',
'extend' => 'de-de',
'locale' => array(
'' => array('de_DE'),
'utf8' => array('de_DE.utf8', 'de_DE.UTF8', 'de_DE.UTF-8'),
),
),
),
),
'it' => array(
'title' => 'Italiano',
'extend' => 'it-it',
'locale' => array(
'' => array('it_IT'),
),
),
),
),
'es' => array(
'title' => 'Espa&ntilde;ol',
'title' => 'Espa&ntilde;ol',
'extend' => 'es-es',
'locale' => array(
'' => array('es_ES'),
'utf8' => array('es_ES.utf8', 'es_ES.UTF8', 'es_ES.UTF-8'),
),
),
),
),
'pt' => array(
'title' => 'Portugu&ecirc;s',
'title' => 'Portugu&ecirc;s',
'extend' => 'pt-pt',
'locale' => array(
'' => array('pt_PT'),
'utf8' => array('pt_PT.utf8', 'pt_PT.UTF8', 'pt_PT.UTF-8'),
),
),
),
),
'br' => array(
'title' => 'Brasileiro',
'extend' => 'pt-br',
'locale' => array(
'' => array('pt_BR'),
'utf8' => array('pt_BR.utf8', 'pt_BT.UTF8', 'pt_BR.UTF-8')
),
),
),
),
);
/**
@@ -125,9 +132,9 @@ function language_getTitle($lg) {
*/
function language_getIcon($short, $full=true) {
global $camyks;
$flag = $camyks->get_dataFileURL('img/flag/'.$short.LANG_ICON_EXTENSION);
if ($full)
return '<img src="'.$flag.'" alt="'.$short.'" style="border:0" />';
return $flag;
@@ -187,13 +194,13 @@ function language_numberFormat($number, $floats=2) {
*/
function language_getDictionnaryList($folder='') {
global $camyks;
/* initialise result */
$result = array();
/* load files in folder */
$files = folder_listFiles($folder);
/* check files */
foreach ($files as $file) {
if (substr($file, 0, 12) == 'translation_' and substr($file , strlen($file) - strlen($camyks->file_extension), strlen($camyks->file_extension)) == $camyks->file_extension) {
@@ -202,4 +209,4 @@ function language_getDictionnaryList($folder='') {
}
return $result;
}
?>
?>
@@ -5,9 +5,9 @@
* @details Plugin, Module Engine
* @file plugin/module/Admin_ContentPage/Admin_ContentPage.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Jun 2005
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2005 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -1505,6 +1505,7 @@ final class Admin_ContentPage extends Module {
/* load data */
$this->W3CValidatorStatus = $this->config->get_w3cValidatorList();
$this->OGMetaStatus = $this->config->get_ogMetaStatusList();
$this->HrefLangStatus = $this->config->get_hrefLangStatusList();
$this->Error404FallBacks = $this->config->get_404FallbackList();
/* update form */
@@ -4,9 +4,9 @@
* @details Plugin / Module layout
* @file plugin/module/Admin_ContentPage/html/configuration/edit.html.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Dec 2014
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2014 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -258,19 +258,28 @@ $minus_ = $camyks->theme->get_pictURL('minus', 12, 'ovr');

<tr>
<td class="eTableHeader" colspan="2">
<?=$this->get_translation('formtitle_ogmeta'); ?>
<?=$this->get_translation('formtitle_sitetags'); ?>
</td>
</tr>

<tr>
<td class="eTableLine0 eContent2">
<?=$camyks->get_translation('formitem_status');?>
<?=$this->get_translation('formitem_ogmeta');?>
</td>
<td class="eTableLine0 eContent1">
<?=$this->editform->display_selectInput(array('name'=>'site_ogmeta', 'values'=>$this->OGMetaStatus));?>
</td>
</tr>

<tr>
<td class="eTableLine1 eContent2">
<?=$this->get_translation('formitem_hreflang');?>
</td>
<td class="eTableLine1 eContent1">
<?=$this->editform->display_selectInput(array('name'=>'site_hreflang', 'values'=>$this->HrefLangStatus));?>
</td>
</tr>

<tr>
<td class="eTableLine0" colspan="2">
&nbsp;
@@ -4,9 +4,9 @@
* @details Plugin / Module layout
* @file plugin/module/Admin_ContentPage/html/configuration/view.html.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Dec 2014
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2014 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -129,19 +129,28 @@ global $camyks;

<tr>
<td class="eTableHeader" colspan="2">
<?=$this->get_translation('formtitle_ogmeta'); ?>
<?=$this->get_translation('formtitle_sitetags'); ?>
</td>
</tr>

<tr>
<td class="eTableLine0 eContent2">
<?=$camyks->get_translation('formitem_status');?>
<?=$this->get_translation('formitem_ogmeta');?>
</td>
<td class="eTableLine0 eContent1">
<?=$this->config->get_ogMetaStatusTitle(); ?>
</td>
</tr>

<tr>
<td class="eTableLine1 eContent2">
<?=$this->get_translation('formitem_hreflang');?>
</td>
<td class="eTableLine1 eContent1">
<?=$this->config->get_hrefLangStatusTitle(); ?>
</td>
</tr>

<tr>
<td class="eTableLine0" colspan="2">
&nbsp;
@@ -170,10 +179,10 @@ global $camyks;

<?php if (substr($this->config->vars['page_404FallBack'], -7, 7) == 'display'): ?>
<tr>
<td class="eTableLine0 eContent2">
<td class="eTableLine1 eContent2">
<?=$this->get_translation('formitem_send404header');?>
</td>
<td class="eTableLine0 eContent1">
<td class="eTableLine1 eContent1">
<?=$camyks->get_translation($this->config->vars['page_404SendHeader']?'yes':'no');?>
</td>
</tr>
@@ -4,9 +4,9 @@
* @details Plugin / Module Library
* @file plugin/module/Admin_ContentPage/lib/Admin_ContentPageConfig.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Jun 2014
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2014 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -44,6 +44,7 @@ final class Admin_ContentPageConfig extends PluginConfig {
/* site parameters values */
$this->add_newItem('site_ogmeta', 'boolean', 0);
$this->add_newItem('site_hreflang', 'boolean', 1);
/* generic initialisation */
parent::init_config();
@@ -132,8 +133,8 @@ final class Admin_ContentPageConfig extends PluginConfig {
*/
public function get_w3cValidatorList() {
return array(
0 => $this->get_translation('config_w3cvalidator_disabled'),
1 => $this->get_translation('config_w3cvalidator_enabled'),
0 => $this->get_translation('config_w3cvalidator_disabled'),
1 => $this->get_translation('config_w3cvalidator_enabled'),
);
}
@@ -154,8 +155,8 @@ final class Admin_ContentPageConfig extends PluginConfig {
*/
public function get_ogMetaStatusList() {
return array(
0 => $this->get_translation('config_ogmeta_disabled'),
1 => $this->get_translation('config_ogmeta_enabled'),
0 => $this->get_translation('config_ogmeta_disabled'),
1 => $this->get_translation('config_ogmeta_enabled'),
);
}
@@ -170,6 +171,28 @@ final class Admin_ContentPageConfig extends PluginConfig {
return '';
}
/**
* Return hreflang status list.
* @return array
*/
public function get_hrefLangStatusList() {
return array(
0 => $this->get_translation('config_hreflang_disabled'),
1 => $this->get_translation('config_hreflang_enabled'),
);
}
/**
* Return hreflang status title.
* @return array
*/
public function get_hrefLangStatusTitle() {
$l = $this->get_hrefLangStatusList();
if (isset($l[$this->vars['site_hreflang']]))
return $l[$this->vars['site_hreflang']];
return '';
}
/**
* Return error 404 fallback values.
* @return array
@@ -4,9 +4,9 @@
* @details Plugin / Module Library
* @file plugin/module/Admin_ContentPage/lib/ContentPage.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Jun 2005
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2005 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -1165,7 +1165,7 @@ final class ContentPage {
* @return void
*/
public function init_site() {
global $camyks;
global $camyks, $languages;
/* parse params */
if (strpos($this->params_, '-')==0 or strpos($this->params_, '/')==0) {
@@ -1189,6 +1189,12 @@ final class ContentPage {
$camyks->HTMLPage->add_meta('og:image', '', 'property');
}
if ($this->get_configValue('site_hreflang') == 1 and count($camyks->get_confValue('site_languages'))) {
foreach ($camyks->get_confValue('site_languages') as $l)
if ($l != $camyks->current_language)
$camyks->HTMLPage->add_link('alternate', $camyks->get_confValue('url').'/'.$this->get_siteLink($this->params, $l), array('hreflang'=>$languages[$l]['extend']));
}
/* init template */
if ($this->template == '') {
$this->template = $camyks->site_conf['site_default_template'];
@@ -1294,6 +1300,7 @@ final class ContentPage {
/* add name */
$link = $this->name;
/* add params */
if (count($params) > 0) {
if ($camyks->get_confValue('friendlyurls') == 'modern')
@@ -4,9 +4,9 @@
* @details Plugin / Module Dictionnary
* @file plugin/module/Admin_ContentPage/locale/translation_en.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Sep 2009
* @date Modification: Sep 2018
* @date Modification: Oct 2018
* @copyright 2009 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@@ -68,9 +68,13 @@ $this->trads['mod_admin_contentpage_config_w3cvalidator_disabled'] = 'Disabled';
$this->trads['mod_admin_contentpage_config_w3cvalidator_enabled'] = 'Enabled';
/* configuration - site */
$this->trads['mod_admin_contentpage_formtitle_ogmeta'] = 'Open Graph metas';
$this->trads['mod_admin_contentpage_formtitle_sitetags'] = 'Header tags';
$this->trads['mod_admin_contentpage_formitem_ogmeta'] = 'Open Graph metas: ';
$this->trads['mod_admin_contentpage_config_ogmeta_disabled'] = 'Disabled';
$this->trads['mod_admin_contentpage_config_ogmeta_enabled'] = 'Enabled';
$this->trads['mod_admin_contentpage_formitem_hreflang'] = 'Hreflang metas: ';
$this->trads['mod_admin_contentpage_config_hreflang_disabled'] = 'Disabled';
$this->trads['mod_admin_contentpage_config_hreflang_enabled'] = 'Enabled';
/* finder page */
$this->trads['mod_admin_contentpage_is_homepage'] = 'Homepage';
Oops, something went wrong.

0 comments on commit feeadaa

Please sign in to comment.