includes/template.php
changeset 892 668e6a9adf99
parent 865 7f8262b2004a
child 906 c949e82b8f49
equal deleted inserted replaced
891:d75c81630571 892:668e6a9adf99
  1664       }
  1664       }
  1665       $text = str_replace_once($matches[0][$i], $string, $text);
  1665       $text = str_replace_once($matches[0][$i], $string, $text);
  1666     }
  1666     }
  1667     
  1667     
  1668     // URLs
  1668     // URLs
  1669     preg_match_all('/\{url:([A-z0-9]+):([^\s\}]+?)(?:;([^\s\}]+?))?(?:\|(escape))?\}/i', $text, $matches);
  1669     preg_match_all('/\{url:([A-z0-9]+):([^\}]+?)(?:;([^\s\}]+?))?(?:\|(escape))?\}/i', $text, $matches);
  1670     foreach ( $matches[1] as $i => $string_id )
  1670     foreach ( $matches[1] as $i => $string_id )
  1671     {
  1671     {
  1672       $namespace =& $matches[1][$i];
  1672       $namespace =& $matches[1][$i];
  1673       $page_id =& $matches[2][$i];
  1673       $page_id =& $matches[2][$i];
  1674       $params =& $matches[3][$i];
  1674       $params =& $matches[3][$i];
  2299     $parser = null;
  2299     $parser = null;
  2300     
  2300     
  2301     switch($row['block_type'])
  2301     switch($row['block_type'])
  2302     {
  2302     {
  2303       case BLOCK_WIKIFORMAT:
  2303       case BLOCK_WIKIFORMAT:
  2304         $parser = $this->makeParserText($vars['sidebar_section']);
  2304         $parser = $this->makeParserText($vars['sidebar_section_raw']);
  2305         $c = RenderMan::render($row['block_content']);
  2305         $c = RenderMan::render($row['block_content']);
  2306         break;
  2306         break;
  2307         
  2307         
  2308       case BLOCK_TEMPLATEFORMAT:
  2308       case BLOCK_TEMPLATEFORMAT:
  2309         $parser = $this->makeParserText($vars['sidebar_section']);
  2309         $parser = $this->makeParserText($vars['sidebar_section']);
  2506     $ob .= implode(",\n    " , $messages)."\n";
  2506     $ob .= implode(",\n    " , $messages)."\n";
  2507     $ob .= '</div>'."\n";
  2507     $ob .= '</div>'."\n";
  2508     return $ob;
  2508     return $ob;
  2509   }
  2509   }
  2510   
  2510   
       
  2511   /**
       
  2512    * Parse a system message.
       
  2513    * @param string message
       
  2514    * @return string
       
  2515    */
       
  2516   
       
  2517   function parse_system_message($text)
       
  2518   {
       
  2519     ob_start();
       
  2520     eval( '?>' . $text );
       
  2521     $result = ob_get_contents();
       
  2522     ob_end_clean();
       
  2523     return $this->parse($result);
       
  2524   }
       
  2525   
  2511 } // class template
  2526 } // class template
  2512 
  2527 
  2513 /**
  2528 /**
  2514  * The core of the template compilation engine. Independent from the Enano API for failsafe operation.
  2529  * The core of the template compilation engine. Independent from the Enano API for failsafe operation.
  2515  * @param string text to process
  2530  * @param string text to process
  2536   // Escape slashes and single quotes in template code
  2551   // Escape slashes and single quotes in template code
  2537   $text = str_replace('\\', '\\\\', $text);
  2552   $text = str_replace('\\', '\\\\', $text);
  2538   $text = str_replace('\'', '\\\'', $text);
  2553   $text = str_replace('\'', '\\\'', $text);
  2539   
  2554   
  2540   // Initialize the PHP compiled code
  2555   // Initialize the PHP compiled code
  2541   $text = 'ob_start(); echo \''.$text.'\'; $tpl_code = ob_get_contents(); ob_end_clean(); return $tpl_code;';
  2556   $text = 'ob_start(); global $paths, $template; echo \''.$text.'\'; $tpl_code = ob_get_contents(); ob_end_clean(); return $tpl_code;';
  2542   
  2557   
  2543   ##
  2558   ##
  2544   ## Main rules
  2559   ## Main rules
  2545   ##
  2560   ##
  2546   
  2561   
  2641   //
  2656   //
  2642   // Data substitution/variables
  2657   // Data substitution/variables
  2643   //
  2658   //
  2644   
  2659   
  2645   // System messages
  2660   // System messages
  2646   $text = preg_replace('/<!-- SYSMSG ([A-z0-9\._-]+?) -->/is', '\' . $template->tplWikiFormat($paths->sysMsg(\'\\1\')) . \'', $text);
  2661   $text = preg_replace('/<!-- SYSMSG ([A-z0-9\._-]+?) -->/is', '\' . $this->parse_system_message($paths->sysMsg(\'\\1\')) . \'', $text);
  2647   
  2662   
  2648   // Hooks
  2663   // Hooks
  2649   $text = preg_replace('/<!-- HOOK ([A-z0-9_]+) -->/', '\' . $this->get_theme_hook(\'\\1\') . \'', $text);
  2664   $text = preg_replace('/<!-- HOOK ([A-z0-9_]+) -->/', '\' . $this->get_theme_hook(\'\\1\') . \'', $text);
  2650   
  2665   
  2651   // only do this if the plugins API is loaded
  2666   // only do this if the plugins API is loaded