/**
     * Returns a html backtrace, suitable for displaying in a browser
     *
     * TODO: link to online API documentation
     *
     * @see http://php.net/manual/en/function.debug-backtrace.php
     * @version 1.1
     * @date 20120724 (v1.1) (greg) $ignore is actually a marker for a frame to highlight
     * @author greg <*****@*****.**>
     *
     * @param integer $ignore number of a stack frame to highlight
     * @param array $backtrace (optional) a backtrace array, like debug_backtrace() gives
     * @return string
     */
    public static function asHTML($ignore = -1, $backtrace = null)
    {
        if (empty($backtrace)) {
            $backtrace = debug_backtrace();
        }
        $ignore = intval($ignore);
        $internals = get_defined_functions();
        $internals = $internals['internal'];
        $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
        // Need this for absolute URL configuration to be sef safe.
        $aurl = $protocol . $_SERVER['SERVER_NAME'] . str_replace('/index.php', '', $_SERVER['PHP_SELF']);
        $trace = '';
        $i = 0;
        foreach ($backtrace as $v) {
            //if ($ignore-- > 0) continue;
            $i++;
            $class_collapsbody = "accordionbody" . $i;
            $ignore--;
            $class = 0 == $ignore ? 'active' : '';
            $trace .= '<tr class="' . $class . '">';
            if (empty($v['file'])) {
                $v['file'] = '';
            }
            if (empty($v['line'])) {
                $v['line'] = '';
            }
            $filepath = preg_replace('!^' . $_SERVER['DOCUMENT_ROOT'] . '/!', '<span class="bt-line-number">...</span>', $v['file']);
            $trace .= '<td>' . $filepath . '</td><td>' . $v['line'] . '</td><td>';
            if (isset($v['class'])) {
                $fct = $v['class'] . '::' . $v['function'];
                $call = $fct . '(';
                if (isset($v['args'])) {
                    $errRow[] = $v['args'];
                    $separator = '';
                    foreach ($v['args'] as $arg) {
                        $call .= $separator . PHPDS_errorHandler::getArgument($arg);
                        $separator = ', ';
                    }
                }
                $call .= ')';
                $call = PHPDS_backtrace::highlightString(preg_replace("/,/", ", ", $call));
                if (substr($v['class'], 0, 5) == 'PHPDS') {
                    // $call = '<a href="http://doc.phpdevshell.org/PHPDevShell/'.$v['class'].'.html#'.$v['function'].'" target="_blank"><img src="' . $aurl . '/themes/default/images/icons-16/book-question.png" /></a>&nbsp;'.$call;
                }
                $trace .= $call;
            } elseif (isset($v['function'])) {
                $fct = $v['function'];
                $call = $fct . '(';
                $errRow[] = $v['function'];
                if (!empty($v['args'])) {
                    $errRow[] = $v['args'];
                    $separator = '';
                    foreach ($v['args'] as $arg) {
                        $call .= $separator . PHPDS_errorHandler::getArgument($arg);
                        $separator = ', ';
                    }
                }
                $call .= ')';
                $call = PHPDS_backtrace::highlightString(preg_replace("/,/", ", ", $call));
                /*if (!empty($internals[$fct]))*/
                $call = '<a href="http://www.php.net/manual-lookup.php?lang=en&pattern=' . urlencode($fct) . '" target="_blank"><img src="' . $aurl . '/themes/default/images/icons-16/book-question.png" /></a>&nbsp;' . $call;
                $trace .= $call;
            }
            $backtrace__ = PHPDS_backtrace::fetchCodeFragment($v['file'], $v['line']);
            $trace .= '</td><td><button type="button" class="btn" data-toggle="collapse" data-target="#' . $class_collapsbody . '"><i class="icon-eye-open"></i></button></td></tr>';
            $trace .= '<tr class="' . $class . '">';
            $trace .= <<<HTML
                    <td colspan="4">
                        <div id="{$class_collapsbody}" class="accordion-body collapse">
                            <pre>{$backtrace__}</pre>
                        </div>
                    </td>
                </tr>
HTML;
        }
        return $trace;
    }
 /**
  * Returns a html backtrace, suitable for displaying in a browser
  *
  * TODO: link to online API documentation
  *
  * @see http://php.net/manual/en/function.debug-backtrace.php
  * @version 1.0
  * @author greg <*****@*****.**>
  *
  * @param integer $ignore number of lines to ignore at the beginning of the backtrace
  * @param array $backtrace (optional) a backtrace array, like debug_backtrace() gives
  * @return string
  */
 public function asHTML($ignore = 0, $backtrace = null)
 {
     if (empty($backtrace)) {
         $backtrace = debug_backtrace();
     }
     $ignore = intval($ignore);
     $internals = get_defined_functions();
     $internals = $internals['internal'];
     $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
     // Need this for absolute URL configuration to be sef safe.
     $aurl = $protocol . $_SERVER['SERVER_NAME'] . str_replace('/index.php', '', $_SERVER['PHP_SELF']);
     $trace = '';
     foreach ($backtrace as $v) {
         if ($ignore-- > 0) {
             continue;
         }
         $class = 0 == $ignore ? 'ui-state-active ui-corner-all' : '';
         $trace .= '<tr class="' . $class . '">';
         if (empty($v['file'])) {
             $v['file'] = '';
         }
         if (empty($v['line'])) {
             $v['line'] = '';
         }
         $filepath = preg_replace('!^' . $_SERVER['DOCUMENT_ROOT'] . '/!', '<span class="bt-line-number">...</span>', $v['file']);
         $trace .= '<td>' . $filepath . '</td><td>' . $v['line'] . '</td><td>';
         if (isset($v['class'])) {
             $fct = $v['class'] . '::' . $v['function'];
             $call = $fct . '(';
             if (isset($v['args'])) {
                 $errRow[] = $v['args'];
                 $separator = '';
                 foreach ($v['args'] as $arg) {
                     $call .= $separator . PHPDS_errorHandler::getArgument($arg);
                     $separator = ', ';
                 }
             }
             $call .= ')';
             $call = PHPDS_backtrace::highlightString($call);
             if (substr($v['class'], 0, 5) == 'PHPDS') {
                 // $call = '<a href="http://doc.phpdevshell.org/PHPDevShell/'.$v['class'].'.html#'.$v['function'].'" target="_blank"><img src="' . $aurl . '/themes/cloud/images/icons-16/book-question.png" /></a>&nbsp;'.$call;
             }
             $trace .= $call;
         } elseif (isset($v['function'])) {
             $fct = $v['function'];
             $call = $fct . '(';
             $errRow[] = $v['function'];
             if (!empty($v['args'])) {
                 $errRow[] = $v['args'];
                 $separator = '';
                 foreach ($v['args'] as $arg) {
                     $call .= $separator . PHPDS_errorHandler::getArgument($arg);
                     $separator = ', ';
                 }
             }
             $call .= ')';
             $call = PHPDS_backtrace::highlightString($call);
             /*if (!empty($internals[$fct]))*/
             $call = '<a href="http://www.php.net/manual-lookup.php?lang=en&pattern=' . urlencode($fct) . '" target="_blank"><img src="' . $aurl . '/themes/cloud/images/icons-16/book-question.png" /></a>&nbsp;' . $call;
             $trace .= $call;
         }
         $trace .= '</td></tr>';
         $trace .= '<tr class="' . $class . '">';
         $trace .= '<td colspan="10">' . PHPDS_backtrace::fetchCodeFragment($v['file'], $v['line']) . '</td></tr>';
     }
     return $trace;
 }