Show Page Trace in Output

@return string
198285
public function showTrace()
    {
        if (!Container::get('config')->get('app_debug')) {
            return;
        }

        $trace = $this->getTrace();
        $tpl = '
<!-- Kotori Page Trace (If you want to hide this feature, please set APP_DEBUG to false.)-->
<div id="page_trace" style="position: fixed; bottom: 0; right: 0; font-size: 14px; width: 100%; z-index: 999999; color: #000; text-align: left; font-family: \'Hiragino Sans GB\',\'Microsoft YaHei\',\'WenQuanYi Micro Hei\';">
<div id="page_trace_tab" style="display: none; background: white; margin: 0; height: 250px;">
<div id="page_trace_tab_tit" style="height: 30px; padding: 6px 12px 0; border-bottom: 1px solid #ececec; border-top: 1px solid #ececec; font-size: 16px">';
        foreach ($trace as $key => $value) {
            $tpl .= '<span id="page_trace_tab_tit_' . strtolower($key) . '" style="color: #000; padding-right: 12px; height: 30px; line-height: 30px; display: inline-block; margin-right: 3px; cursor: pointer; font-weight: 700">' . $key . '</span>';
        }

        $tpl .= '</div>
<div id="page_trace_tab_cont" style="overflow: auto; height: 212px; padding: 0; line-height: 24px">';
        foreach ($trace as $key => $info) {
            $tpl .= '<div id="page_trace_tab_cont_' . strtolower($key) . '" style="display: none;">
    <ol style="padding: 0; margin: 0">';
            if (is_array($info)) {
                foreach ($info as $k => $val) {
                    $val = is_array($val) ? print_r($val, true) : (is_bool($val) ? json_encode($val) : $val);
                    $val = (in_array($key, ['Support'])) ? $val : htmlentities($val, ENT_COMPAT, 'utf-8');
                    $tpl .= '<li style="border-bottom: 1px solid #EEE; font-size: 14px; padding: 0 12px">' . (is_numeric($k) ? '' : $k . ' : ') . $val . '</li>';
                }
            }

            $tpl .= '</ol>
    </div>';
        }

        $tpl .= '</div>
</div>
<div id="page_trace_close" style="display: none; text-align: right; height: 15px; position: absolute; top: 10px; right: 12px; cursor: pointer;"><img style="vertical-align: top;" src="data:image/gif;base64,R0lGODlhDwAPAJEAAAAAAAMDA////wAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXB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Pzs3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+urayrqqmop6alpKOioaCfnp2cm5qZmJeWlZSTkpGQj46NjIuKiYiHhoWEg4KBgH9+fXx7enl4d3Z1dHNycXBvbm1sa2ppaGdmZWRjYmFgX15dXFtaWVhXVlVUU1JRUE9OTUxLSklIR0ZFRENCQUA/Pj08Ozo5ODc2NTQzMjEwLy4tLCsqKSgnJiUkIyIhIB8eHRwbGhkYFxYVFBMSERAPDg0MCwoJCAcGBQQDAgEAACH5BAAAAAAALAAAAAAPAA8AAAIdjI6JZqotoJPR1fnsgRR3C2jZl3Ai9aWZZooV+RQAOw==" /></div>
</div>
<div id="page_trace_open" style="height: 30px; float: right; text-align: right; overflow: hidden; position: fixed; bottom: 0; right: 0; color: #000; line-height: 30px; cursor: pointer;"><div style="background: #232323; color: #FFF; padding: 0 6px; float: right; line-height: 30px; font-size:14px">';
        $errorCount = count(Handle::$errors);

        if ($errorCount == 0) {
            $tpl .= Hook::listen(\Kotori\App::class) . 'μs';
        } else {
            $tpl .= $errorCount . ' errors';
        }

        $tpl .= '</div><img width="30" style="border-left:2px solid black;border-top:2px solid black;border-bottom:2px solid black;" title="ShowPageTrace" src="' . Helper::logo() . '"></div>';
        $tpl .= HtmlCompress::construct()->compress('<script type="text/javascript">
(function() {
\'use strict\';
var tab_tit = document.getElementById(\'page_trace_tab_tit\').getElementsByTagName(\'span\'),
    tab_cont = document.getElementById(\'page_trace_tab_cont\').getElementsByTagName(\'div\'),
    open = document.getElementById(\'page_trace_open\'),
    close = document.getElementById(\'page_trace_close\').children[0],
    trace = document.getElementById(\'page_trace_tab\'),
    storage = localStorage.getItem(\'kotori_show_page_trace\'),
    history = (storage !== null && storage.split(\'|\')) ||  [0,0],
    bindClick = function(dom, listener) {
        if (dom.addEventListener) {
            dom.addEventListener(\'click\', listener, false);
        } else {
            dom.attachEvent(\'onclick\', listener);
        }
    };
bindClick(open, function() {
    trace.style.display = \'block\';
    this.style.display = \'none\';
    close.parentNode.style.display = \'block\';
    history[0] = 1;
    localStorage.setItem(\'kotori_show_page_trace\', history.join(\'|\'));
});
bindClick(close, function() {
    trace.style.display = \'none\';
    this.parentNode.style.display = \'none\';
    open.style.display = \'block\';
    history[0] = 0;
    localStorage.setItem(\'kotori_show_page_trace\', history.join(\'|\'));
});
for (var i = 0; i < tab_tit.length; i++) {
    bindClick(tab_tit[i], (function(i) {
        return function() {
            for (var j = 0; j < tab_cont.length; j++) {
                tab_cont[j].style.display = \'none\';
                tab_tit[j].style.color = \'#999\';
            }
            tab_cont[i].style.display = \'block\';
            tab_tit[i].style.color = \'#000\';
            history[1] = i;
            localStorage.setItem(\'kotori_show_page_trace\', history.join(\'|\'));
        };
    })(i));
}
parseInt(history[0]) && open.click();
tab_tit[history[1]].click();
})();
</script>');
        return $tpl;
    }
162878
public function getOutput()
    {
        $this->readPipesForOutput(__FUNCTION__);

        if (false === $ret = stream_get_contents($this->stdout, -1, 0)) {
            return '';
        }

        return $ret;
    }
229005
public function get()
    {
        if ($this->page_count <= 1) {
            return '';
        }

        // Output HTML holder.
        $output = '';

        $output .= $this->get_opening_links();
        $output .= $this->get_links();
        $output .= $this->get_closing_links();

        // Apply before and after content if present in the args.
        if (! empty($output)) {
            $output = $this->args['before_output'] . $output . $this->args['after_output'];
        }

        /**
         * Filter snap_pagination output.
         *
         * @since  1.0.0
         *
         * @var string $output The output HTML for the pagination.
         * @return  string The filtered HTML.
         */
        $output = apply_filters('snap_pagination_output', $output);

        return $output;
    }
319651
final function Render()
    {
        $this->output = '';
        $this->ReadTranslations();
        if ($this->BeforeInit())
        {
            return $this->output;
        }
        if ($this->Init())
        {
            return $this->output;
        }
        if ($this->BeforeGather())
        {
            return $this->output;
        }
        $this->GatherOutput();
        $this->AfterGather();
        return $this->output;        
    }
25810
public function display()
    {
        $this->output = '';
        $output = $this->load($this->_layout);
        $this->output = $this->output.$output;

        return $this->output;
    }
821430
public static function backTrace() {

        $str = "<br />[backTrace]";
        foreach (debug_backtrace() as $row) {
            $str .= "<br />FILE: "
                    . $row['file'] . " FUNC: " . $row['function']
                    . " LINE: " . $row['line'] . " ARGS: "
                    . print_r($row['args'], true);
        }
        return $str;
    }
132390
private function getOutput()
    {
        $output = "# Todo list\n\n";

        // Make menu
        $columns = 12;

        $captions = implode('|', array_fill(0, $columns, ' '));
        $subcaptions = implode('|', array_fill(0, $columns, ':---:'));

        $output .= "|$captions|\n";
        $output .= "|$subcaptions|\n";

        $menu = [];
        foreach (array_keys($this->output) as $language) {
            $menu[] = "[$language](#$language)";
        }

        $rows = array_chunk($menu, $columns);
        array_map(function ($row) use (&$output) {
            $row = implode(' | ', $row);
            $output .= $row."\n";
        }, $rows);

        $output .= "\n\n";

        // Make items
        foreach ($this->output as $language => $values) {
            $output .= "#### {$language}:\n";
            $output .= implode(PHP_EOL, $values);
            $output .= "\n\n[ [to top](#todo-list) ]\n\n";
        }

        return $output;
    }
741008
public function getOutput() {
		// assign template and frame_template to page
		$this->_content['page']['template'] = $this->template;

		if (!is_dir($this->compile_path)) mkdir($this->compile_path, 0777, true); // create temp dir if it does not exist

		// init serpent
		$_engine = new \McSodbrenner\Serpent\Serpent($this->compile_path, 'utf-8', $this->force_compile);

		// handle mappings
		$mappings = [
			'dump'			=> '\\Morrow\\Debug::dump',
			'url'			=> '\\Morrow\\Factory::load("Url")->create',
			'securl'		=> '\\Morrow\\Factory::load("Security")->createCSRFUrl',
			'cycle'			=> '\\Morrow\\Views\\Serpent::cycle',
			'mailto'		=> '\\Morrow\\Views\\Serpent::mailto',
			'hidelink'		=> '\\Morrow\\Views\\Serpent::hidelink',
			'thumb'			=> '\\Morrow\\Views\\Serpent::thumb',
			'fileurl'		=> '\\Morrow\\Views\\Serpent::fileurl',
			'truncate'		=> '\\Morrow\\Views\\Serpent::truncate',
			'strip'			=> 'ob_start(["\\Morrow\\Views\\Serpent::strip"]) //',
			'endstrip'		=> 'ob_end_flush',
			'loremipsum'	=> '\\Morrow\\Views\\Serpent::loremipsum',
			'_'				=> '\\Morrow\\Factory::load("Language")->_',
			'module'		=> 'stream_get_contents(\\Morrow\\Factory::load("Core\\Feature")->run',
		];
		// add user mappings
		foreach ($this->mappings as $key => $value) {
			$mappings[$key] = $value;
		}

		$_engine->addMappings($mappings);

		// handle resources
		$_engine->addResource('file',
			new \McSodbrenner\Serpent\ResourceFile($this->template_path, $this->template_suffix, Factory::load('Language')->get())
		);

		foreach ($this->resources as $resource) {
			call_user_func_array([$_engine, 'addResource'], $resource);
		}

		// create stream handle for the output
		$handle = fopen('php://temp/maxmemory:'.(1*1024*1024), 'r+'); // 1MB


		// write source to stream
		$_engine->pass($this->_content);
		fwrite($handle, $_engine->render($this->template));

		return $handle;
	}
68689
public function showNew()
    {
        $pages_list = $this->core->api('Page/all', 'GET')->run();
        return $this->templates->render("Main::Pages/New", [
            "messages" => [
                'error' => '',
                'info' => '',
                'success' => '',
                'warning' => ''
            ],
            "request" => [],
            "pages" => $pages_list['response']
        ]);
    }
1078287
public function getStackTrace()
    {
        if (!isset($this->message[4]) || empty($this->message[4])) {
            return null;
        }

        $traces = array_map(function ($trace) {
            return "in {$trace['file']}:{$trace['line']}";
        }, $this->message[4]);
        return implode("\n", $traces);
    }
1075151
public function trace()
    {
        $s = 0;
        $n = min($this->m, $this->n);
        for ($i = 0; $i < $n; ++$i) {
            $s += $this->A[$i][$i];
        }
        return $s;
    }
1260093
public function output()
	{
		if(!isset($this->_template))
		{
			throw new Ergo\Exception("Not template file has been assigned");
		}

		$oldInclude = get_include_path();
		set_include_path(implode(PATH_SEPARATOR, $this->_include));

		$contents = $this->_renderTemplate($this->_template, $this->_vars);

		set_include_path($oldInclude);
		return $contents;
	}
1247666
public function showPages()
    {
        // Get dependencies
        $page = ($this->container->dataMapper)('PageMapper');

        // Fetch pages & templates
        $data['pages'] = $page->findPages(true);
        $data['templates'] = $this->getPageTemplates('page');

        return $this->render('pages.html', $data);
    }
625002
private static function additional_output()
    {
        $backtrace = \debug_backtrace()[3];

        $root = \realpath(__DIR__ . '/../../../../../../');

        return '<span class="sf-dump-lineinfo">' . \ltrim(\str_replace($root, '', $backtrace['file']), '/\\') . ':' . $backtrace['line'] . '</span>';
    }
568227
protected function get_progress_trace_instance() {
        if ($this->progress === null) {
            if (!$this->table->is_downloading()) {
                $this->progress = new \core\progress\display_if_slow(get_string('calculatingallstats', 'quiz_statistics'));
                $this->progress->set_display_names();
            } else {
                $this->progress = new \core\progress\none();
            }
        }
        return $this->progress;
    }
1144201
public function outputAr()
    {
        $aOut = [];

        foreach ($this->aEntries as $aEntry) {

            $sTemp = !empty($aEntry['tag']) ? '<' . $aEntry['tag'] . ' ' : '<meta ';
            unset($aEntry['tag']);
            foreach ($aEntry as $sKey => $sValue) {

                $sTemp .= $sKey . '="' . $sValue . '" ';
            }
            $sTemp  = trim($sTemp) . '>';
            $aOut[] = $sTemp;
        }

        return $aOut;
    }
407818
private function showTrace() {
         // 系统默认显示信息
        $files =  get_included_files();
        $info   =   array();
        foreach ($files as $key=>$file){
            $info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )';
        }
        $trace  =   array();
        $base   =   array(
            '请求信息'=>  date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__,
            '运行时间'=> $this->showTime(),
            '内存开销'=> MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持',
            '查询信息'=> N('db_query').' queries '.N('db_write').' writes ',
            '文件加载'=> count(get_included_files()),
            '缓存信息'=> N('cache_read').' gets '.N('cache_write').' writes ',
            '配置加载'=> count(c()),
            '会话信息'=> 'SESSION_ID='.session_id(),
            );
        // 读取应用定义的Trace文件
        $traceFile  =   CONF_PATH.'trace.php';
        if(is_file($traceFile)) {
            $base    =   array_merge($base,include $traceFile);
        }
        $debug  =   trace();
        $tabs   =   C('TRACE_PAGE_TABS',null,$this->tracePagTabs);
        foreach ($tabs as $name=>$title){
            switch(strtoupper($name)) {
                case 'BASE':// 基本信息
                    $trace[$title]  =   $base;
                    break;
                case 'FILE': // 文件信息
                    $trace[$title]  =   $info;
                    break;
                default:// 调试信息
                    if(strpos($name,'|')) {// 多组信息
                        $array  =   explode('|',$name);
                        $result =   array();
                        foreach($array as $name){
                            $result   +=   isset($debug[$name])?$debug[$name]:array();
                        }
                        $trace[$title]  =   $result;
                    }else{
                        $trace[$title]  =   isset($debug[$name])?$debug[$name]:'';
                    }
            }
        }
    foreach ($trace as $key=>$val){
            if(!is_array($val) && empty($val))
                $val=array();
            if(is_array($val)){
            $fire=array(
            array('','')
            );
            foreach($val as $k=>$v){
                $fire[]=array($k,$v);
            }
            fb(array($key,$fire),FirePHP::TABLE);
        }else{
            fb($val,$key);
        }
     }
    unset($files,$info,$log,$base);
    }