Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for phpPlatonLib/templateSystems/ObjTemplate/Attic/ObjTemplate.class.php between version 1.3 and 1.4

version 1.3, 2001/11/02 19:19:59 version 1.4, 2001/11/04 19:55:20
Line 11 
Line 11 
   
 class ObjTemplate  class ObjTemplate
 {  {
   
         var $cstr = array(          var $cstr = array(
                         'begin' => '<!--',                          'begin' => '<!--',
                         'end' => '-->',                          'end' => '-->',
Line 94  class ObjTemplate
Line 95  class ObjTemplate
   
                 for ($i = 0; $i < count($ar); $i++) {                  for ($i = 0; $i < count($ar); $i++) {
                         if (is_array($ar[$i])) {                          if (is_array($ar[$i])) {
                                 //if (isset($ar[$i]['key'])) {  
                                 if (! strcmp($key, $ar[$i]['key'])) {                                  if (! strcmp($key, $ar[$i]['key'])) {
                                         return true;                                          return true;
                                 }                                  }
                                 elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) {                                  elseif (! strcmp($this->cmd['if'], $ar[$i]['key'])) {
                                         //echo "COMPARE: " . $this->cmd['if'] . " vs. ". $ar[$i]['key'] . "<br>";  
                                         //echo "var_dump(): " . var_dump($ar[$i]['key']) . "<br>";  
                                         if (is_array($ar[$i]['true'])) {                                          if (is_array($ar[$i]['true'])) {
                                                 if (true == $this->_is_key($key, $ar[$i]['true']))                                                  if (true == $this->_is_key($key, $ar[$i]['true']))
                                                         return true;                                                          return true;
                                         }                                          }
   
                                         if (is_array($ar[$i]['false'])) {                                          if (is_array($ar[$i]['false'])) {
                                                 if (true == $this->_is_key($key, $ar[$i]['false']))                                                  if (true == $this->_is_key($key, $ar[$i]['false']))
                                                         return true;                                                          return true;
                                         }                                          }
                                 }                                  }
                                 //}  
                                 else {                                  else {
                                         if (true == $this->_is_key($key, $ar[$i]))                                          if (true == $this->_is_key($key, $ar[$i]))
                                                 return true;                                                  return true;
Line 133  class ObjTemplate
Line 132  class ObjTemplate
                         }                          }
                 }                  }
                 else {                  else {
                         $val_ar = $this->_string_transform($value, 1);                          $this->_set(strtolower($key), $this->_string_transform($value), $this->array);
                         $this->_set(strtolower($key), count($val_ar) > 1 ? $val_ar : $value, $this->array);  
                 }                  }
   
                 return;                  return;
Line 248  class ObjTemplate
Line 246  class ObjTemplate
         {          {
                 $html = $this->html();                  $html = $this->html();
   
                 $regexp =  $this->tag['start'] . $prefix . $this->tag['delim'] . ':([^%\b]+)' .                  $regexp =  $this->tag['begin'] . $prefix . $this->tag['delim'] . '([^%\b]+)' .
                         ( isset($this->tag['end']) ? $this->tag['end'] : '\b' ) . '';                          ( isset($this->tag['end']) ? $this->tag['end'] : '\b' ) . '';
   
                 preg_match_all("/$regexp/is", $html, $matches);                  preg_match_all("/$regexp/is", $html, $matches);
   
                 return array(preg_split("/$regexp/is", $this->html), $matches[1]);                  return array(preg_split("/$regexp/is", $html), $matches[1]);
         }          }
   
         function get_array()          function get_array()
Line 273  class ObjTemplate
Line 271  class ObjTemplate
         {          {
                 $ar_out_idx = 0;                  $ar_out_idx = 0;
   
                 $regexp = $this->tag['begin'] . '(\w+(' . $this->tag['delim'] . '[\w\.]+)*)' .                  /*
                    * Spliting string into two arrays by tags. First array ($m_tags) will
                    * contain only tags without starting prefix and ending sufix.
                    * The second array ($m_texts) will contain text between tags.
                    * Elemets goes in this order: $m_texts[0], $m_tags[0], $m_texts[1], ...
                    *
                    * Optimalization for this array spliting is strongly required.
                    */
   
                   $regexp = $this->tag['begin'] . '(\w[\w\d_]*(' . $this->tag['delim'] . '[^\b%]+)*)' .
                         ( isset($this->tag['end']) ? $this->tag['end'] : '\b' );                          ( isset($this->tag['end']) ? $this->tag['end'] : '\b' );
   
                 preg_match_all("/$regexp/is", $string, $m_tags);                  preg_match_all("/$regexp/is", $string, $m_tags);
Line 281  class ObjTemplate
Line 288  class ObjTemplate
   
                 $m_texts = preg_split("/$regexp/im", $string);                  $m_texts = preg_split("/$regexp/im", $string);
   
                   /*
                    * Debug informations printing.
                    */
   
                 if ($debug) {                  if ($debug) {
                         print "_string_transform() DEBUG: m_tags: ";                          print "_string_transform() DEBUG: m_tags: ";
                         var_dump($m_tags);                          var_dump($m_tags);
Line 291  class ObjTemplate
Line 302  class ObjTemplate
                         print "<br>";                          print "<br>";
                 }                  }
   
                   /*
                    * Main loop.
                    */
   
                 for ($i = 0; $i < count($m_texts); $i++) {                  for ($i = 0; $i < count($m_texts); $i++) {
   
                           /* Text processing. */
                         if (strlen($m_texts[$i]) > 0) {                          if (strlen($m_texts[$i]) > 0) {
                                 if ($ar_out_idx > 0 && ! is_array($ar_out[$ar_out_idx - 1])) {                                  if ($ar_out_idx > 0 && ! is_array($ar_out[$ar_out_idx - 1])) {
                                         $ar_out[$ar_out_idx - 1] .= $m_texts[$i];                                          $ar_out[$ar_out_idx - 1] .= $m_texts[$i];
Line 302  class ObjTemplate
Line 319  class ObjTemplate
                                 }                                  }
                         }                          }
   
                           /* Tag processing. */
                         if (strlen($m_tags[$i]) > 0) {                          if (strlen($m_tags[$i]) > 0) {
                                 $cmd_parts = explode($this->tag['delim'], $m_tags[$i], 2);                                  $cmd_parts = explode($this->tag['delim'], $m_tags[$i], 2);
   
                                 // toto bol povodny if() - zrejme uz nude na nic, takze                                  /* FILE tag. */
                                 // to mozes pokojne vymazat :)  
                                 //  
                                 //if (! strcasecmp($this->cmd['file'] . $this->tag['delim'],  
                                 //                      substr($m_tags[$i], 0, 1 + strlen($this->cmd['file'])))) {  
                                 if (! strcasecmp($this->cmd['file'], $cmd_parts[0])                                  if (! strcasecmp($this->cmd['file'], $cmd_parts[0])
                                                 && strlen($cmd_parts[1]) > 0) {                                                  && strlen($cmd_parts[1]) > 0) {
                                         $filename_with_path = dirname($this->filename) . '/' . $cmd_parts[1];                                          $filename_with_path = dirname($this->filename) . '/' . $cmd_parts[1];
Line 321  class ObjTemplate
Line 335  class ObjTemplate
                                                 $ar_out[$ar_out_idx] =                                                  $ar_out[$ar_out_idx] =
                                                         $this->_generate_error("file not found: $filename_with_path");                                                          $this->_generate_error("file not found: $filename_with_path");
   
                                         $ar_out_idx++;                                          //$ar_out_idx++;
                                 }                                  }
   
                                   /* IF tag. */
                                 elseif (! strcasecmp($this->cmd['if'], $cmd_parts[0])) {                                  elseif (! strcasecmp($this->cmd['if'], $cmd_parts[0])) {
                                         $ar_out[$ar_out_idx] = array(                                          $ar_out[$ar_out_idx] = array(
                                                         'key' => $this->cmd['if'],                                                          'key' => $this->cmd['if'],
Line 335  class ObjTemplate
Line 351  class ObjTemplate
                                                 $cmd_parts2 = explode($this->tag['delim'], $m_tags[$j], 2);                                                  $cmd_parts2 = explode($this->tag['delim'], $m_tags[$j], 2);
                                                 $tmp_str .= $m_texts[$j];                                                  $tmp_str .= $m_texts[$j];
   
                                                   /* IF subtag. */
                                                 if (! strcasecmp($this->cmd['if'], $cmd_parts2[0])) {                                                  if (! strcasecmp($this->cmd['if'], $cmd_parts2[0])) {
                                                         $level++;                                                          $level++;
                                                 }                                                  }
   
                                                   /* ELSE subtag. */
                                                 elseif (! $level && ! strcasecmp($this->cmd['else'], $cmd_parts2[0])) {                                                  elseif (! $level && ! strcasecmp($this->cmd['else'], $cmd_parts2[0])) {
   
                                                         if (! isset($ar_out[$ar_out_idx]['true'])) {                                                          if (! isset($ar_out[$ar_out_idx]['true'])) {
Line 348  class ObjTemplate
Line 367  class ObjTemplate
                                                                 continue;                                                                  continue;
                                                         }                                                          }
                                                 }                                                  }
   
                                                   /* ENDIF subtag. */
                                                 elseif (! strcasecmp($this->cmd['endif'], $cmd_parts2[0])) {                                                  elseif (! strcasecmp($this->cmd['endif'], $cmd_parts2[0])) {
                                                         if ($level)                                                          if ($level)
                                                                 $level--;                                                                  $level--;
Line 365  class ObjTemplate
Line 386  class ObjTemplate
   
                                         $i = $j;                                          $i = $j;
                                 }                                  }
   
                                   /* Others tags. */
                                 else {                                  else {
                                         $ar_out[$ar_out_idx] = array('key' => strtolower($m_tags[$i]));                                          $ar_out[$ar_out_idx] = array('key' => strtolower($m_tags[$i]));
                                 }                                  }
   
                                 $ar_out_idx++;                                  $ar_out_idx++;
                         }                          }
                         }  
   
                         return $ar_out;  
                 }                  }
   /* TODO: remove this
                   if ($ar_out_idx <= 1)
                           print "!!!! ar_out_idx = $ar_out_idx<br>";
   */
   
                 function _generate_error($message = "unknown error")                  return $ar_out_idx > 1 ? $ar_out : $ar_out[0];
                 {          }
                         return $this->cstr['begin']  
                                 . ' ' . $this->cstr['classname'] . ':'  
                                 . ' ' . $message  
                                 . ' ' . $this->cstr['end'];  
                 }  
   
           function _generate_error($message = "unknown error")
           {
                   return $this->cstr['begin']
                           . ' ' . $this->cstr['classname'] . ':'
                           . ' ' . $message
                           . ' ' . $this->cstr['end'];
         }          }
   
         ?>  }
   
   ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top