95 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| /**
 | |
|  * @copyright	Copyright (C) 2012 Cédric KEIFLIN alias ced1870
 | |
|  * http://www.joomlack.fr
 | |
|  * @license		GNU/GPL
 | |
|  * Version 1.0
 | |
|  * */
 | |
| // No direct access
 | |
| defined('_JEXEC') or die;
 | |
| 
 | |
| use Joomla\CMS\Plugin\CMSPlugin;
 | |
| use Joomla\CMS\Factory;
 | |
| use Joomla\CMS\Plugin\PluginHelper;
 | |
| use Joomla\Registry\Registry;
 | |
| 
 | |
| class plgSystemMultilanguagesck extends CMSPlugin {
 | |
| 
 | |
| 	public function onAfterRender() {
 | |
| 		$app = Factory::getApplication();
 | |
| 		$document = Factory::getDocument();
 | |
| 		$doctype = $document->getType();
 | |
| 		$input = $app->input;
 | |
| 
 | |
| 		// si pas en frontend, on sort
 | |
| 		if ($app->isClient('administrator')) {
 | |
| 			return false;
 | |
| 		}
 | |
| 
 | |
| 		// si pas HTML, on sort
 | |
| 		if ($doctype !== 'html') {
 | |
| 			return;
 | |
| 		}
 | |
| 
 | |
| 		if ($input->get('layout') == 'edit') {
 | |
| 			return;
 | |
| 		}
 | |
| 
 | |
| 		// renvoie les données dans la page
 | |
| 		// récupère les données de la page
 | |
| 		if (version_compare(JVERSION, '4') >= 0) {
 | |
| 			$body = Factory::getApplication()->getBody(); 
 | |
| 		} else {
 | |
| 			$body = JResponse::getBody();
 | |
| 		}
 | |
| 
 | |
| 		// debug mode
 | |
| 		// get attribute from system plugin params
 | |
| 		$plugin = PluginHelper::getPlugin('system', 'multilanguagesck');
 | |
| 		$pluginParams = new Registry($plugin->params);
 | |
| 		if ($pluginParams->get('debugmode') == '1') {
 | |
| 			// get the language
 | |
| 			$lang = Factory::getLanguage();
 | |
| 			$langtag = $lang->getTag(); // returns fr-FR or en-GB
 | |
| 			$debugmessage = '<p style="font-size:14px;color:red;">The actual language tag is : ' . $langtag . '</p>';
 | |
| 			$body = str_replace("<body", $debugmessage . "<body", $body);
 | |
| 		}
 | |
| 
 | |
| 		$regex = "#{langck(.*?){/langck}#s"; // masque de recherche
 | |
| 		$body = preg_replace_callback($regex, array($this, 'checklanguageck'), $body);
 | |
| 
 | |
| 		if (version_compare(JVERSION, '4') >= 0) {
 | |
| 			Factory::getApplication()->setBody($body); 
 | |
| 		} else {
 | |
| 			JResponse::setBody($body);
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	function checklanguageck($matches) {
 | |
| 
 | |
| 		// découpe l'expression pour récupérer les textes
 | |
| 		$patterns = "#{langck(.*)}(.*){/langck}#Uis";
 | |
| 		$result = preg_match($patterns, $matches[0], $results);
 | |
| 
 | |
| 		// vérifie si des paramètres personnalisés existent
 | |
| 		$params = explode('=', $results[1]);
 | |
| 
 | |
| 		// si pas de langue définie on sort
 | |
| 		if (!isset($params[1]))
 | |
| 			return $matches[0];
 | |
| 
 | |
| 		$lang = Factory::getLanguage();
 | |
| 		$langtag = $lang->getTag(); // returns fr-FR or en-GB
 | |
| 		// vérifie si ça colle avec la langue active
 | |
| 		if (($params[1] == $langtag) AND isset($results[2])) {
 | |
| 			$return = $results[2];
 | |
| 		} else {
 | |
| 			$return = '';
 | |
| 		}
 | |
| 
 | |
| 		return $return;
 | |
| 	}
 | |
| 
 | |
| }
 |