'; // mode $m = (isset($_GET['m'])) ? $_GET['m'] : ''; if ($m==='php') { // source of the PHP script $app_html = f_color_file($e_script, false, true); $app_html = f_source_create_html($app_html); } elseif ($m==='source') { // source of the template $app_html = f_color_file($e_template, true, true); $app_html = f_source_create_html($app_html); } elseif ($m==='template') { // display the template with the sidebar $app_html = file_get_contents($e_template); } else { // display the result of the example with the sidebar $m = 'result'; $other_prms = '&e='.$e.'&m='.$m; // can be needed by examples which have a GET form or autorefering links. $GLOBALS['_TBS_AutoInstallPlugIns'][] = 'clsMyPluginRenderNothing'; // Set the plug-in to be auto-loaded when TBS is instanciated. include($e_script); $app_html = $TBS->Source; } if ($m!=='result') { $sidebar_html = f_sidebar_getmerged(); $p = strpos($app_html, $sidebar_landmark); if ($p===false) { // can happen with sub-templates // inserte the main title if missing if (strpos($app_html, ''; } else { $title = ''; } $app_html = str_replace('', ''.$title.$sidebar_landmark, $app_html); $app_html = str_replace('', '', $app_html); } $app_html = str_replace($sidebar_landmark, $sidebar_landmark.$sidebar_html, $app_html); } // Display the result. if ($app_echo) { echo $app_html; exit; } else { // Nothing to do. Another script is supposed to get the result in the variable $html. Used in the TinyButStrong web site for example. } // fonction for this application /* Merges the Side-bar template and return the contents */ function f_sidebar_getmerged() { global $e, $m, $s, $e_script, $e_template, $sidebar; include_once('tbs_class.php'); $TBS = new clsTinyButStrong; $TBS->Source = '[sidebar;file;getbody=body]'; $TBS->MergeField('sidebar', $sidebar); $TBS->Show(TBS_NOTHING); return $TBS->Source; } /* Create an HTML body for viewing the PHP or HTML colored source */ function f_source_create_html($contents) { $title = 'Source code of '.$contents['file']; return ' TinyButStrong - '.$title.'

'.$title.'

'.$contents['main'].'
'; } /* Color the contents of a file. Can be HTML or PHP. Returns an array with 'main', 'css' and 'file' */ function f_color_file($file, $ishtml, $lines) { $x = highlight_file($file, true); if ($ishtml) { f_color_tag($x, 't', 'table,tr,td,th'); f_color_tag($x, 's', 'script'); f_color_tag($x, 'c', 'style'); f_color_tag($x, 'n'); } if ($lines) { // display line number $n = 1 + substr_count($x, '
'); $n_txt = ''; for ($i=1;$i<=$n;$i++) { if ($i>1) $n_txt .= "\r\n"; $n_txt .= $i; } $x = '
  '.$n_txt.'
 
'.$x.'
'; } $style = ' code {font-family: "Courier New", Courier, monospace; font-size: 12px; white-space:nowrap} .z {font-family: "Courier New", Courier, monospace; font-size: 12px; margin:0; padding:0;} '."\r\n"; if ($lines) $style .= '.n {color: #009;} .t {color: #099;} .v {color: #00F;} .s {color: #900;} .c {color: #909;} '."\r\n"; return array('main'=>$x, 'css'=>$style, 'file'=>basename($file)); } /* Color a list of tags or all remaing tags with using a CSS class. * $txt must be a source code wich is a result of highlight_file(). */ function f_color_tag(&$txt, $class, $tag='') { $z2 = ''; $zo = '<'; $zc = '>'; $zc_len = strlen('>'); $all = ($tag===''); // color all remaing tags if ($all) $txt = str_replace($zc,$zc.'',$txt); if (is_string($tag)) $tag = explode(',', $tag); foreach ($tag as $t) { $p = 0; $z = $zo.$t; $z_len = strlen($z); do { $p = strpos($txt, $z, $p); if ($p!==false) { if ($all or (substr($txt,$p+$z_len,1)==='&')) { // the next char must be a ' ' or a '>'. In both case, it is converted by highlight_file() with a special char begining with '&'. if (($p>0) and (substr($txt,$p-2,2)!=='">')) { // the tag must not be previsouly colored $p2 = strpos($txt, $zc, $p+$z_len); if ($p2!==false) { $x = substr($txt, $p, $p2 + $zc_len - $p); $x = str_replace('="','="',$x); // color the value of attributes $x = str_replace('=\'','=\'',$x); // color the value of attributes $x = str_replace('"&','"&',$x); $x = $z2.$x.''; $txt = substr($txt,0,$p).$x.substr($txt,$p2 + $zc_len); $p = $p + strlen($x); } else { $p = false; } } else { $p = $p + $z_len; } } else { $p = $p + $z_len; } } } while ($p!==false); $z = $zo.'/'.$t.$zc; $txt = str_replace($z,$z2.$z.'',$txt); } } /* Auto-loaded Plug-in for inserting the side-bar in running examples. */ class clsMyPluginRenderNothing { function OnInstall() { return array('BeforeShow'); } function BeforeShow(&$Render) { $TBS = &$this->TBS; if ($TBS->_Mode==0) { // the engine is not in subtemplate-mode // insert the sidebar, it contains [onshow] fields global $sidebar, $sidebar_landmark; $sidebar_field = '[onshow;file='.$sidebar.';getbody=body]'; if (strpos($TBS->Source,'