Example #1
0
function process_request()
{
    global $parsedown, $modules, $static_pages, $hidden_pages, $external_pages;
    // Set up Parsedown
    $parsedown = null;
    if (file_exists('lib/parsedown.php')) {
        include 'lib/parsedown.php';
        $parsedown = Parsedown::instance();
    }
    // Build the static page array
    if (file_exists('static/metadata.json')) {
        $site_metadata = parse_json_file('static/metadata.json');
        $modules->run('site_metadata', $site_metadata);
        // Pack non-iterable site info into a series of constants
        foreach ($site_metadata['info'] as $k => $v) {
            if (!is_int($k)) {
                define('SITE_' . strtoupper($k), $v);
            }
        }
        // These are global array variables instead of lists of constants for two reasons
        // 1) $external_pages, by necessity, contains characters that cannot be used in a constant
        // 2) It greatly simplifies iterating them, which should be the focus as that is the most common use case.
        foreach ($site_metadata['pages']['internal'] as $page) {
            if (isset($page['hidden']) && $page['hidden'] == true) {
                $hidden_pages[$page['page']] = $page['title'];
            } else {
                $static_pages[$page['page']] = $page['title'];
            }
        }
        foreach ($site_metadata['pages']['external'] as $page) {
            $external_pages[$page['page']] = $page['title'];
        }
        $pages = array_merge($static_pages, $hidden_pages);
        $files = implode('|', array_keys($pages));
    }
    // Run any daily tasks...
    run_tasks();
    $pieces = array('story' => '(?P<story>[-a-z0-9_]+)', 'page' => '(?P<page>[-a-z0-9_]*)', 'static' => '(?P<file>(' . $files . '))');
    $URI = $_SERVER['REQUEST_URI'];
    $result = array();
    $debug = 'No Match';
    $mode = 'comics';
    $url_root = parse_url(SITE_LINK)['path'];
    switch ($URI) {
        case SITE_LINK:
            $mode = 'comics';
            $debug = 'Landing/Splash Page';
            break;
        case preg_match('#^' . $url_root . $pieces['static'] . '$#', $URI, $result) === 1 ? true : false:
            $mode = 'static';
            $debug = 'Static Content';
            break;
        case preg_match('#^' . $url_root . 'archive/' . $pieces['page'] . '$#', $URI, $result) === 1 ? true : false:
            $mode = 'comics';
            $debug = 'Default Comic Archive';
            break;
        case preg_match('#^' . $url_root . 'archive/' . $pieces['story'] . '/' . $pieces['page'] . '$#', $URI, $result) === 1 ? true : false:
            $mode = 'comics';
            $debug = 'Specific Comic Archive';
            break;
        default:
            $mode = 'error';
            $debug = 'Default';
            $result = array('err' => '404');
            $param = array('mode' => &$mode, 'debug' => &$debug, 'URI' => &$URI, 'result' => &$result);
            $modules->run("mode_select", $param);
            break;
    }
    $values = array('mode' => &$mode, 'debug' => &$debug, 'result' => &$result);
    $modules->run('pre_process', $values);
    if (file_exists('lib/' . $mode . '.php')) {
        include 'lib/' . $mode . '.php';
        if (function_exists('pre_process')) {
            $result = pre_process($result);
        }
    }
    $modules->run('process_request', $result);
    foreach ($result as $k => $v) {
        if (!is_int($k)) {
            define('COMIC_' . strtoupper($k), $v);
        }
    }
    if (!defined('COMIC_DEBUG')) {
        define('COMIC_DEBUG', $debug);
    }
    if (!defined('COMIC_MODE')) {
        define('COMIC_MODE', $mode);
    }
}
Example #2
0
function __kc_ub_log($type, $arr)
{
    pre_process($arr);
    global $__log__;
    $format = $arr[0];
    array_shift($arr);
    $pid = kc_posix_getpid();
    $bt = debug_backtrace();
    if (isset($bt[1]) && isset($bt[1]['file'])) {
        $c = $bt[1];
    } else {
        if (isset($bt[2]) && isset($bt[2]['file'])) {
            //Ϊ�˼��ݻص�����ʹ��log
            $c = $bt[2];
        } else {
            if (isset($bt[0]) && isset($bt[0]['file'])) {
                $c = $bt[0];
            } else {
                $c = array('file' => 'faint', 'line' => 'faint');
            }
        }
    }
    $line_no = '[' . $c['file'] . ':' . $c['line'] . '] ';
    if (!empty($__log__[$pid])) {
        $log = $__log__[$pid];
        $log->write_log($type, $format, $line_no, $arr);
    } else {
        $s = __mc_log__::$LOG_NAME[$type] . ' ' . vsprintf($format, $arr) . "\n";
        echo $s;
    }
}