2011/2/11 Denis Linvinus <linvi...@gmail.com>

> I found little bug,
>
> imposible to use '0' as condition parameter
>
> following template don't work
>
> ##IFticket.numberoftasks=0## --- ##ENDIFticket.numberoftasks##
> ##ELSEticket.numberoftasks## ##lang.ticket.numberoftasks## :
>  ##ticket.numberoftasks## ##ENDELSEticket.numberoftasks##
>
> problem with
>
>
> if (empty($out[2][$key]) ){ // No = : check if ot empty or not null
>
> zero also interpretete as empty, so we need to check length too, or
> something similar
>
> if (empty($out[2][$key]) && !strlen($out[2][$key]) ){ // No = : check if ot
> empty or not null
>
>
>
i have check content_text and it also need to be decoded,

otherwise i get

--b1_823641f82b34a65ee8f9b0a60fb836ae
Content-Type: text/plain; charset = "utf-8"
Content-Transfer-Encoding: 8bit



 [11-02-2011 14:19]&#160; &#1053;&#1086;&#1074;&#1099;&#1081; Личный
&#160;&#1086;&#1090;&#1074;&#1077;&#1090; &#1087;&#1086;
&#1079;&#1072;&#1103;&#1074;&#1082;&#1077; Автор
Денис :

zsdafsdf

 so this is my current working patch

--- ./notificationtemplate.class.php    2011-01-18 17:04:00.000000000 +0300
+++ ./notificationtemplate.class.php.new    2011-02-11 15:50:25.000000000
+0300
@@ -211,6 +211,7 @@
          if ($template_datas = $this->getByLanguage($language)) {
             //Template processing
             // Decode html chars to have clean text
+        $template_datas['content_text'] =
html_entity_decode_deep($template_datas['content_text']);
             $data = html_entity_decode_deep($data);
             $template_datas['subject'] =
html_entity_decode_deep($template_datas['subject']);
             $this->signature = html_entity_decode_deep($this->signature);
@@ -324,14 +325,14 @@

    static function processIf($string, $data) {

-      if (preg_match_all("/##IF([a-z\.]*)[=]?([\w ]*)##/i",$string,$out)) {
+      if (preg_match_all("/##IF([a-z\.]*)[=]?(.*?)##/i",$string,$out)) {
          foreach ($out[1] as $key => $tag_infos) {
             $if_field = $tag_infos;
             //Get the field tag value (if one)
-            $regex_if = "/##IF".$if_field."[=]?[\w
]*##(.*)##ENDIF".$if_field."##/Uis";
+            $regex_if =
"/##IF".$if_field."[=]?.*##(.*)##ENDIF".$if_field."##/Uis";
             //Get the else tag value (if one)
-            $regex_else = "/##ELSE".$if_field."[=]?[\w
]*##(.*)##ENDELSE".$if_field."##/Uis";
-            if (empty($out[2][$key])){ // No = : check if ot empty or not
null
+            $regex_else =
"/##ELSE".$if_field."[=]?.*##(.*)##ENDELSE".$if_field."##/Uis";
+            if (empty($out[2][$key]) && !strlen($out[2][$key]) ){ // No = :
check if ot empty or not null
                if (isset($data['##'.$if_field.'##'])
                   && $data['##'.$if_field.'##'] != ''
                   && $data['##'.$if_field.'##'] != '&nbsp;'
@@ -342,7 +343,7 @@
                }
             } else { // check exact match
                if (isset($data['##'.$if_field.'##'])
-                  && $data['##'.$if_field.'##'] == $out[2][$key]) {
+                && html_entity_decode_deep($data['##'.$if_field.'##']) ==
html_entity_decode_deep($out[2][$key])) {
                   $condition_ok=true;
                } else {
                   $condition_ok=false;



>
>
> 2011/2/10 Nicolas Michaux <nicolas-glpi-...@michaux.homelinux.org>
>
>> On Thursday 10 February 2011 10:11:05 Denis Linvinus wrote:
>>
>> > Hello!
>> Hi,
>>
>> > > > As we have problem only with template condition, better decode
>> > > > only condition.
>> > >
>> > > Ok, what about this patch for you?
>> >
>> > This patch also works for me.
>> Great news!
>>
>> > But i don't understand why
>> >
>> > if (preg_match_all("/##IF([a-z\.]*)[=]?(.*)##/Ui",$string,$out)) {
>> >
>> > not the same as
>> >
>> > if (preg_match_all("/##IF([a-z\.]*)[=]?(.*?)##/i",$string,$out)) {
>> Maybe we should double the question mark if the whole expression is
>> considered ungreedy :
>> if (preg_match_all("/##IF([a-z\.]*)[=]??(.*)##/Ui",$string,$out)) {
>>
>> "The question mark  ?  changes the behavior of the quantifiers *, +, ?
>> from "greedy" to "ungreedy" in a "greedy" regular expression. But the same
>> question mark  ?  changes the behavior of the quantifiers *, +, ? from
>> "ungreedy"
>> to "greedy" in an "ungreedy" regular expression!"
>>
>> I didn't test it.
>>
>> Nicolas
>>
>> _______________________________________________
>> Glpi-dev mailing list
>> Glpi-dev@gna.org
>> https://mail.gna.org/listinfo/glpi-dev
>>
>
>
_______________________________________________
Glpi-dev mailing list
Glpi-dev@gna.org
https://mail.gna.org/listinfo/glpi-dev

Reply via email to