includes/template.php
changeset 534 6be4b47aa247
parent 533 698a8f04957c
child 538 a43f9d646dc7
equal deleted inserted replaced
533:698a8f04957c 534:6be4b47aa247
  1931   }
  1931   }
  1932   
  1932   
  1933   $keywords = implode('|', $keywords);
  1933   $keywords = implode('|', $keywords);
  1934   
  1934   
  1935   // Matches
  1935   // Matches
  1936   //          1     2                 3                 4   56                       7     8
  1936   //          1     2                 3                 4   56                       7     8        9
  1937   $regexp = '/(<!-- ('. $keywords .') ([A-z0-9_-]+) -->)(.*)((<!-- BEGINELSE \\3 -->)(.*))?(<!-- END \\3 -->)/isU';
  1937   $regexp = '/(<!-- ('. $keywords .') ([A-z0-9_-]+) -->)(.*)((<!-- BEGINELSE \\3 -->)(.*))?(<!-- END(IF)? \\3 -->)/isU';
  1938   
  1938   
  1939   /*
  1939   /*
  1940   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  1940   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  1941   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  1941   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  1942   
       
  1943   The while-loop is to bypass what is apparently a PCRE bug. It's hackish but it works. Properly written plugins should only need
       
  1944   to compile templates (using this method) once for each time the template file is changed.
       
  1945   */
  1942   */
  1946   
  1943   
  1947   profiler_log("[template] compiler matchout start");
  1944   profiler_log("[template] compiler matchout start");
  1948   preg_match_all($regexp, $text, $matches);
  1945   preg_match_all($regexp, $text, $matches);
  1949   profiler_log("[template] compiler core loop start");
  1946   profiler_log("[template] compiler core loop start");
  2015   // Data substitution/variables
  2012   // Data substitution/variables
  2016   //
  2013   //
  2017   
  2014   
  2018   // System messages
  2015   // System messages
  2019   $text = preg_replace('/<!-- SYSMSG ([A-z0-9\._-]+?) -->/is', '\' . $template->tplWikiFormat($paths->sysMsg(\'\\1\')) . \'', $text);
  2016   $text = preg_replace('/<!-- SYSMSG ([A-z0-9\._-]+?) -->/is', '\' . $template->tplWikiFormat($paths->sysMsg(\'\\1\')) . \'', $text);
       
  2017   
       
  2018   // only do this if the plugins API is loaded
       
  2019   if ( is_object(@$plugins) )
       
  2020   {
       
  2021     $code = $plugins->setHook('template_compile_subst');
       
  2022     foreach ( $code as $cmd )
       
  2023     {
       
  2024       eval($cmd);
       
  2025     }
       
  2026   }
  2020   
  2027   
  2021   // Template variables
  2028   // Template variables
  2022   $text = preg_replace('/\{([A-z0-9_-]+?)\}/is', '\' . $this->tpl_strings[\'\\1\'] . \'', $text);
  2029   $text = preg_replace('/\{([A-z0-9_-]+?)\}/is', '\' . $this->tpl_strings[\'\\1\'] . \'', $text);
  2023   
  2030   
  2024   // Reinsert PHP
  2031   // Reinsert PHP