Example #1
0
 private function renderHtml()
 {
     $res = '<style>code, pre {white-space:nowrap} a {text-decoration:none} pre {color:gray;display:inline} big {color:red}</style><code>';
     foreach ($this->list as $item) {
         $stack = [];
         foreach (array_slice($item[3], 1) as $t) {
             $t += ['class' => '', 'type' => '', 'function' => ''];
             $stack[] = "{$t['class']}{$t['type']}{$t['function']}()" . (isset($t['file'], $t['line']) ? ' in ' . basename($t['file']) . ":{$t['line']}" : '');
         }
         $res .= Helpers::editorLink($item[0], $item[1]) . ' ' . '<span title="' . htmlspecialchars(implode("\n", $stack), ENT_IGNORE | ENT_QUOTES, 'UTF-8') . '">' . str_replace(self::BOM, '<big>BOM</big>', Dumper::toHtml($item[2])) . "</span><br>\n";
     }
     return $res . '</code>';
 }
Example #2
0
 /**
  * Returns syntax highlighted source code.
  * @param  string
  * @param  int
  * @param  int
  * @return string
  */
 public static function highlightPhp($source, $line, $lines = 15, array $vars = NULL)
 {
     if (function_exists('ini_set')) {
         ini_set('highlight.comment', '#998; font-style: italic');
         ini_set('highlight.default', '#000');
         ini_set('highlight.html', '#06B');
         ini_set('highlight.keyword', '#D24; font-weight: bold');
         ini_set('highlight.string', '#080');
     }
     $source = str_replace(["\r\n", "\r"], "\n", $source);
     $source = explode("\n", highlight_string($source, TRUE));
     $out = $source[0];
     // <code><span color=highlight.html>
     $source = str_replace('<br />', "\n", $source[1]);
     $out .= static::highlightLine($source, $line, $lines);
     if ($vars) {
         $out = preg_replace_callback('#">\\$(\\w+)(&nbsp;)?</span>#', function ($m) use($vars) {
             return array_key_exists($m[1], $vars) ? '" title="' . str_replace('"', '&quot;', trim(strip_tags(Dumper::toHtml($vars[$m[1]], [Dumper::DEPTH => 1])))) . $m[0] : $m[0];
         }, $out);
     }
     $out = str_replace('&nbsp;', ' ', $out);
     return "<pre class='php'><div>{$out}</div></pre>";
 }