Пример #1
0
    /**
     * Show Page Trace in Output
     *
     * @return string
     */
    public function showTrace()
    {
        if (Config::getSoul()->APP_DEBUG == false) {
            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, array('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/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZW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3My8rJyMfGxcTDwsHAv769vLu6ubi3trW0s7KxsK+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') . 'μ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>
<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;
    }
Пример #2
0
 /**
  * Map URL to controller and action
  *
  * @return void
  */
 public function dispatch()
 {
     if (Config::getSoul()->URL_MODE == 'QUERY_STRING') {
         $this->_uri = explode('?', $this->_uri, 2);
         $_SERVER['QUERY_STRING'] = isset($this->_uri[1]) ? $this->_uri[1] : '';
         $this->_uri = $this->_uri[0];
         parse_str($_SERVER['QUERY_STRING'], $_GET);
     }
     define('URI', $this->_uri);
     switch ($this->_uri) {
         case 'favicon.ico':
             Response::getSoul()->setHeader('Content-Type', 'image/x-icon');
             Response::getSoul()->setCacheHeader();
             echo base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', Helper::logo()));
             exit;
         case 'kotori-php-system-route/highlight-github.css':
             Response::getSoul()->setHeader('Content-Type', 'text/css; charset=utf-8');
             Response::getSoul()->setCacheHeader();
             echo file_get_contents(Helper::getComposerVendorPath() . '/components/highlightjs/styles/github.css');
             exit;
         case 'kotori-php-system-route/highlight.js':
             Response::getSoul()->setHeader('Content-Type', 'text/javascript; charset=utf-8');
             Response::getSoul()->setCacheHeader();
             echo file_get_contents(Helper::getComposerVendorPath() . '/components/highlightjs/highlight.pack.min.js');
             exit;
     }
     $parsedRoute = $this->parseRoutes($this->_uri);
     if ($parsedRoute) {
         $this->_uri = $parsedRoute;
     } else {
         throw new \Exception('Request URI ' . $this->_uri . ' is not Matched by any route.');
     }
     $this->_uris = $this->_uri != '' ? explode('/', trim($this->_uri, '/')) : array();
     //Clean uris
     foreach ($this->_uris as $key => $value) {
         if ($value == '') {
             unset($this->_uris[$key]);
         }
     }
     $this->_uris = array_merge($this->_uris);
     $this->_controller = $this->getController();
     $this->_action = $this->getAction();
     //Define some variables
     define('CONTROLLER_NAME', $this->_controller);
     define('ACTION_NAME', $this->_action);
     define('PUBLIC_DIR', Request::getSoul()->getBaseUrl() . 'public');
     //If is already initialized
     $prefix = Config::getSoul()->NAMESPACE_PREFIX;
     $controllerClassName = $prefix . 'controllers\\' . $this->_controller;
     if (isset($this->_controllers[$this->_controller])) {
         $class = $this->_controllers[$this->_controller];
     } else {
         $class = new $controllerClassName();
         $this->_controllers[$this->_controller] = $class;
     }
     if (!class_exists($controllerClassName)) {
         throw new \Exception('Request Controller ' . $this->_controller . ' is not Found.');
     }
     if (!method_exists($class, $this->_action)) {
         throw new \Exception('Request Action ' . $this->_action . ' is not Found.');
     }
     //Parse params from uri
     $this->_params = $this->getParams();
     //Do some final cleaning of the params
     $_GET = array_merge($this->_params, $_GET);
     $_REQUEST = array_merge($_POST, $_GET, $_COOKIE);
     Response::getSoul()->setHeader('X-Powered-By', 'Kotori');
     Response::getSoul()->setHeader('Cache-control', 'private');
     //Call the requested method
     call_user_func_array(array($class, $this->_action), $this->_params);
 }