Forum CMS Made Simple FR
[Résolu] smarty et balise {php} - Version imprimable

+- Forum CMS Made Simple FR (https://forum.cmsmadesimple.fr)
+-- Forum : Général (https://forum.cmsmadesimple.fr/forum-3.html)
+--- Forum : Modules, Tags (https://forum.cmsmadesimple.fr/forum-14.html)
+--- Sujet : [Résolu] smarty et balise {php} (/thread-3337.html)



[Résolu] smarty et balise {php} - Steve - 05/11/2014

Citation :#~~~~~ DEBUT BLOC A NE PAS SUPPRIMER ~~~~~
#~ Version du CMS: 1.11.11
#~ Url du site : local
#~ Hébergeur / Soft : lamp php 5.3.27
#~ Informations Système :
#~ ----------------------------------------------
#~ Cms Version: 1.11.11
#~ Installed Modules:
#~ CMSMailer: 5.2.2
#~ CMSPrinting: 1.0.5
#~ FileManager: 1.4.5
#~ MenuManager: 1.8.6
#~ MicroTiny: 1.2.7
#~ ModuleManager: 1.5.8
#~ News: 2.14.4
#~ Search: 1.7.11
#~ ThemeManager: 1.1.8
#~ OpenStatisticsCommunity: 0.2.0
#~ TemplateExternalizer: 1.3
#~ Archiver: 0.2.4
#~ TinyMCE: 2.9.11
#~ FrontEndUsers: 1.18.1
#~ CGExtensions: 1.31
#~ CGCalendar: 1.10.0.1
#~ CustomContent: 1.8.3
#~ FormBuilder: 0.7.3
#~ NewsSlides: 1.2
#~ JQueryTools: 1.1.1
#~ CGContentUtils: 1.3.3
#~ Showtime: 3.2
#~ Statistics: 1.1.3
#~ CGFeedMaker: 1.0.16
#~ CGJobMgr: 1.2.7
#~ NMS: 2.5.6
#~ Config Information:
#~ php_memory_limit:
#~ process_whole_template:
#~ max_upload_size: 100000000
#~ url_rewriting: none
#~ page_extension: .html
#~ query_var: page
#~ image_manipulation_prog: GD
#~ auto_alias_content: true
#~ locale:
#~ default_encoding: utf-8
#~ admin_encoding: utf-8
#~ set_names: true
#~ Php Information:
#~ phpversion: 5.3.27
#~ md5_function: On (True)
#~ gd_version: 2
#~ tempnam_function: On (True)
#~ magic_quotes_runtime: Off (False)
#~ E_STRICT: 2048
#~ E_DEPRECATED: 8192
#~ memory_limit: 1024M
#~ max_execution_time: 1200
#~ output_buffering: 4096
#~ safe_mode: Off (False)
#~ file_uploads: On (True)
#~ post_max_size: 100M
#~ upload_max_filesize: 100M
#~ session_save_path: /tmp (0777)
#~ session_use_cookies: On (True)
#~ xml_function: On (True)
#~ xmlreader_class: On (True)
#~ Server Information:
#~ Server Api: cgi-fcgi
#~ Server Db Type: MySQL (mysql)
#~ Server Db Version: 5.0.77
#~ Server Db Grants: Found a "GRANT ALL" statement that appears to be suitable
#~ Server Time Diff: No filesystem time difference found
#~ ----------------------------------------------
#~~~~~ FIN BLOC A NE PAS SUPPRIMER ~~~~~



Salut à tous,

Nous avons migré de la version 1.10.3 à la dernière version.
Nous avons des menus avec des balises {php} et voici l'erreur :


Error: at line 62 in file /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:

Syntax error in template "globalcontent:menu" on line 62 "
HOME
" unknown tag "echo"


#0 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php(575): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ec...', 62)
#1 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templateparser.php(2383): Smarty_Internal_TemplateCompilerBase->compileTag('echo', Array)
#2 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templateparser.php(3093): Smarty_Internal_Templateparser->yy_r37()
#3 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templateparser.php(3191): Smarty_Internal_Templateparser->yy_reduce(37)
#4 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_smartytemplatecompiler.php(111): Smarty_Internal_Templateparser->doParse(25, ';')
#5 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php(273): Smarty_Internal_SmartyTemplateCompiler->doCompile('??global $gCms;...')
#6 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_template.php(186): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#7 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templatebase.php(149): Smarty_Internal_Template->compileTemplateSource()
#8 /usr/local/apache/htdocs/nmtripy/lib/classes/class.Smarty_CMS.php(326): Smarty_Internal_TemplateBase->fetch('globalcontent:m...', 'p15', NULL, NULL, false, false, false)
#9 /usr/local/apache/htdocs/nmtripy/plugins/function.global_content.php(23): Smarty_CMS->fetch('globalcontent:m...')
#10 /usr/local/apache/htdocs/nmtripy/tmp/templates_c/e47747a9d075f96463f3d893a106f66f740181e5.tpl_body.23.php(27): smarty_function_global_content(Array, Object(Smarty_Internal_Template))
#11 /usr/local/apache/htdocs/nmtripy/lib/smarty/libs/sysplugins/smarty_internal_templatebase.php(182): content_545a2c635bbc69_10240138(Object(Smarty_Internal_Template))
#12 /usr/local/apache/htdocs/nmtripy/lib/classes/class.Smarty_CMS.php(326): Smarty_Internal_TemplateBase->fetch('tpl_body:23', 'p15', NULL, NULL, false, false, false)
#13 /usr/local/apache/htdocs/nmtripy/index.php(240): Smarty_CMS->fetch('tpl_body:23')
#14 {main}

le echo se fait entre les balises {php} {/php}

Avez-vous une idée ?

Merci à vous.

Edit : Je précise que normalement, cela devrait fonctionner vu que vous utilisez SmartyBC et il y a un registerPlugins('block', 'php', 'smarty_php_tag').
J'ai fait un var_dump dans cette function et elle n'est pas appelée. J'imagine qu'il y a un problème suite à votre override ?


[Résolu] smarty et balise {php} - jce76350 - 05/11/2014

la réponse est dans ta question : " unknown tag "echo"
tu as une balise echo inconnue
http://wiki.cmsmadesimple.fr/wiki/Udt_base
http://docs.cmsmadesimple.org/tags/user-defined-tags/writing-a-udt

et je déplace dans le bon forum Modules, Tags


[Résolu] smarty et balise {php} - Steve - 05/11/2014

Salut,

Merci pour la réponse rapide mais echo n'est pas une balise mais une fonction php :

Admin => Content => Global Content Blocks

Menu :

Code :
[== Indéfini ==]
{php}
global $gCms;

$manager =& $gCms->GetHierarchyManager();

$var = 'root_page_id';
if( isset($params['assign']) && $params['assign'] != '' )
{
  $var = $params['assign'];
}
$result = "NO RESULT";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Hierarchy();
    $currentNode =& $currentNode->getParentNode();
}

/*
echo $result;
*/



switch ($result) {

case "":
    $home = true;
    break;    
    
case 1:
    $home = true;
    break;    
case 2:
    $project = true;
    break;        
    
case 3:
    $partners = true;
    break;
    
case 4:
    $library = true;
    break;
        
case 5:
    $contact = true;
    break;
    
default:
  $home = true;
   break;
}
/*
echo $gCms->variables['page_name'];
*/
{/php}
<div id="header_bottom">
  <ul class="nav">
    <li ><a href="index.php?page=home" class="bouton_menu{php} if ($home == true){echo "_current"; }  {/php}"  onmouseover ="javascript:ak_hidelayer('sm_1');ak_hidelayer('sm_2');ak_hidelayer('sm_3')" >HOME</a></li>
    <li><a href="index.php?page=project" class="bouton_menu{php} if ($project == true){echo "_current"; }  {/php}"  onmouseover ="javascript:ak_showlayer('sm_3');ak_hidelayer('sm_1');ak_hidelayer('sm_2')">PROJECT</a>
      <ul class="submenu" id="sm_3" onmouseout="ak_hidelayer('sm_3')" >
<li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=committees">Management Committees</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=project">MIP-DILI Project</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-1">Work package 1</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-2">Work package 2</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-3">Work package 3</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-4">Work package 4</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-5">Work package 5</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-6">Work package 6</a></li>
        <li  onmouseover ="javascript:ak_showlayer('sm_3')"><a href="index.php?page=work-package-7">Work package 7</a></li>
    </li>
      </ul>
    <li ><a href="index.php?page=partners"class="bouton_menu{php} if ($partners == true){echo "_current"; }  {/php}" onmouseover="javascript:ak_showlayer('sm_1');ak_hidelayer('sm_2');ak_hidelayer('sm_3')" >PARTNERS</a>
      <ul class="submenu" id="sm_1"  onmouseout="ak_hidelayer('sm_1')">
        <li onmouseover ="javascript:ak_showlayer('sm_1')"><a href="index.php?page=partners&menu=efpia">EFPIA Members</a></li>
<li onmouseover ="javascript:ak_showlayer('sm_1')"><a href="index.php?page=partners&menu=academics">Academics</a></li>
<li onmouseover ="javascript:ak_showlayer('sm_1')"><a href="index.php?page=partners&menu=smes">SMEs</a></li>
  
        <!-- <li><a href="index.php?page=job-announcements">Job Announcements</a></li>-->
      </ul>
    </li>
    <li ><a href="index.php?page=library" class="bouton_menu{php} if ($library == true){echo "_current"; }  {/php}" onmouseover="javascript:showlayer('sm_2');ak_hidelayer('sm_1');ak_hidelayer('sm_3')" >LIBRARY</a>
      <ul class="submenu" id="sm_2"  onmouseout="ak_hidelayer('sm_2')">
        <li onmouseover ="javascript:ak_showlayer('sm_2')"><a href="index.php?page=library">News & Publications</a></li>
        <li onmouseover ="javascript:ak_showlayer('sm_2')"><a href="index.php?page=archives">Archives</a></li>
        <li onmouseover ="javascript:ak_showlayer('sm_2')"><a href="index.php?page=glossary">Glossary</a></li>
<li onmouseover ="javascript:ak_showlayer('sm_2')"><a href="index.php?page=links">Links</a></li>
      </ul>
    </li>
    <!--  <li  ><a href="index.php?page=news" class="bouton_menu{php} if ($news == true){echo "_current"; }  {/php}">NEWS</a></li>-->
    <!--    <li><a href="index.php?page=events" class="bouton_menu{php} if ($events == true){echo "_current"; }  {/php}">EVENTS</a></li>-->
    <li ><a href="index.php?page=contact" class="bouton_menu{php} if ($contact == true){echo "_current"; }  {/php}" onmouseover ="javascript:ak_hidelayer('sm_1');ak_hidelayer('sm_2');ak_hidelayer('sm_3')">CONTACT</a></li>
  </ul>
</div>

Les erreurs viennent de ceci :

{php} if ($home == true){echo "_current"; } {/php}

alors que normalement :

SmartyBC.class.php :

Code :
[== Indéfini ==]
    public function __construct(array $options=array())
    {
        parent::__construct($options);
        // register {php} tag
        $this->registerPlugin('block', 'php', 'smarty_php_tag');
    }


/**
* Smarty {php}{/php} block function
*
* @param array   $params   parameter list
* @param string  $content  contents of the block
* @param object  $template template object
* @param boolean &$repeat  repeat flag
* @return string content re-formatted
*/
function smarty_php_tag($params, $content, $template, &$repeat)
{
    eval($content);

    return '';
}

Le PHP devrait être eval, non parsé.


[Résolu] smarty et balise {php} - jce76350 - 05/11/2014

Citation :{php} if ($home == true){echo "_current"; } {/php}
ça se trouve à quel endroit ce code


[Résolu] smarty et balise {php} - Steve - 05/11/2014

Dans un block de contenu, ici : Admin => Content => Global Content Blocks
Cela fonctionnait sans souci, avant le passage vers la nouvelle version


[Résolu] smarty et balise {php} - jce76350 - 05/11/2014

Citation :Cela fonctionnait sans souci, avant le passage vers la nouvelle version
ha oui mais il y a eu des modifications Wink
lire les 2 liens donnés sur les balises plus haut


[Résolu] smarty et balise {php} - jissey - 05/11/2014

Bonjour,
utiliser une UDT.


[Résolu] smarty et balise {php} - jce76350 - 05/11/2014

{php}{/php} supprimé en 1.11 voir le changelog Removed the use_smarty_php_tags config variable
et lire http://www.cmsmadesimple.fr/forum/viewtopic.php?id=5350


[Résolu] smarty et balise {php} - bess - 05/11/2014

Pas mieux que mes collègues : il te faut passer par une balise utilisateur. En gros tu copie colle le contenu de l'ancien {php}{/php} et tu adapte le code

exemple :

avant : {php} if ($home == true){echo "_current"; } {/php}
après dans l'udt "toto" : if ($home == true){echo "_current"; }
et l'appel à l'udt dans ton gabarit : {toto}


+sécurisé
+propre pour la factorisation de code
++ simple car 100% php et non plus un mix entre php / smarty


[Résolu] smarty et balise {php} - Steve - 06/11/2014

Salut à vous,

Cela fonctionne, un très très grand merci pour votre aide et la rapidité !

Bonne journée,
Steve.