loadLanguage(); } /* * Insertion avant contenu article */ public function onContentBeforeDisplay($context, &$article, &$params) { $app = Factory::getApplication(); if($app->isClient('administrator') || $this->params->get('lmap_content_before','') == ''){ return ''; } return $this->getContent($article, 'lmap_content_before'); } /* * Insertion après contenu article */ public function onContentAfterDisplay($context, &$article, &$params) { $app = Factory::getApplication(); if($app->isClient('administrator') || $this->params->get('lmap_content_after','') == ''){ return ''; } return $this->getContent($article, 'lmap_content_after'); } /* * Insertion avant contenu article */ private function getContent($article, $position) { $app = Factory::getApplication(); // == Selon categories // lmap_cat_inclus : 0-exclus, 1-inclus // lmap_cat_niv : 0-aucun, 1-un sous-niveau // lmap_catid : id(s) des catégories $lmap_catid = $this->params->get('lmap_catid', array()); if (in_array('all', $lmap_catid)) { if (!$this->params->get('lmap_cat_inclus',1)) {return;} } else { $ok = in_array($article->catid, $lmap_catid) || ($this->params->get('lmap_cat_niv',1) && in_array($article->parent_id, $lmap_catid)); if ($ok XOR $this->params->get('lmap_cat_inclus', 1)) {return;} } //=== Actif selon niveau d'access $user = Factory::getUser(); if (!$this->params->get('lmap_access_guest',1) && $user->guest) { return; } //=== selon homepage // méthode classique qui ne distingue pas le blog // $menu = $app->getMenu(); // $homepage = ($menu->getActive() == $menu->getDefault()); $root_link = str_replace('index.php','',JUri::root()); $current_link = preg_replace('/index.php/','',JUri::current()); $homepage = ($current_link == $root_link); switch ($this->params->get('lmap_homepage','always')) { case 'always': $ok = true; break; case 'only' : $ok = $homepage; break; case 'except': $ok = !$homepage; break; } if (!$ok) {return;} //=== selon type vue // tous, en vue article, en vue blog (categorie et vedette) $view_article = (Factory::getApplication()->input->getCmd('view', '') == 'article'); switch ($this->params->get('lmap_view', 'all')) { case 'all': $ok = true; break; case 'article': $ok = $view_article; break; case 'blog': $ok = !$view_article; break; } if (!$ok) {return;} //=== Actif selon device // dump($this->isMobile(),'IsMobile'); switch ($this->params->get('lmap_filterMobile','always')) { case 'always': $ok = true; break; case 'mobile': $ok = $this->isMobile(); break; case 'desktop': $ok = !$this->isMobile(); break; } if (!$ok) {return;} //=== Texte à insérer $contents = $this->params->get($position, ''); //-- Recherche code PHP $regexp = '/(.*?)<\?php\s+(.*?)\?>(.*)/s'; $found = preg_match($regexp, $contents, $matches); while ($found) { $phpcode = $matches[2]; global $errmsg; if ($this->check_php($phpcode)) { ob_start(); eval($phpcode); $output = ob_get_contents(); ob_end_clean(); } else { $output = "command not allowed: $errmsg"; } $contents = $matches[1] . $output . $matches[3]; $found = preg_match($regexp, $contents, $matches); } //-- Recherche loadposition (merci lefabdu51) $regexp = '#{loadposition (.*)}#i'; $found = preg_match($regexp, $contents, $matches); $output = ''; while ($found) { $modules = ModuleHelper::getModules($matches[1]); foreach ($modules as $module) { $output .= ModuleHelper::renderModule($module); } $contents = str_replace($matches[0], $output, $contents); $found = preg_match($regexp, $contents, $matches); } //-- Code à insérer PluginHelper::importPlugin('content'); $contents = HTMLHelper::_('content.prepare', $contents); return '