Esempio n. 1
0
function init()
{
    $headers = Core\Headers::getInstance();
    $dom = DOM\HTML::getInstance();
    if (in_array('text/html', explode(',', $headers->accept))) {
        build_head($dom->head);
        build_body($dom->body);
        return $dom;
    } elseif ($headers->accept === 'application/json' and !empty($_REQUEST)) {
        require_once './components/handlers/request.php';
        return \Components\Handlers\Request\handle($_REQUEST);
    } else {
        http_response_code(API\Abstracts\HTTPStatusCodes::BAD_REQUEST);
    }
}
Esempio n. 2
0
<?php

// Check PHP version >= 5.5
if (version_compare(PHP_VERSION, getenv('MIN_PHP_VERSION'), '<')) {
    http_response_code(500);
    exit(sprintf('PHP version %s or greater is needed', getenv('MIN_PHP_VERSION')));
}
// Setup Autoloader
set_include_path(realpath(getenv('AUTOLOAD_DIR')) . PATH_SEPARATOR . get_include_path());
spl_autoload_extensions(getenv('AUTOLOAD_EXTS'));
spl_autoload_register(getenv('AUTOLOAD_FUNC'));
// Set Console logger and other classes
$console = \shgysk8zer0\Core\Console::getInstance()->asErrorHandler()->asExceptionHandler();
$timer = new \shgysk8zer0\Core\Timer();
$headers = \shgysk8zer0\Core\Headers::getInstance();
$url = new \shgysk8zer0\Core\URL();
// Verify that HTML is in the Accept header
if (in_array('text/html', explode(',', $headers->accept))) {
    $dom = new \shgysk8zer0\DOM\HTML();
    $dom->head->append('title', 'HTTP-OS');
    $dom->head->append('link', null, ['rel' => 'prefetch', 'href' => 'combined.svg', 'type' => 'image/svg+xml']);
    // Load all JavaScript async
    \shgysk8zer0\Core\ArrayObject::of('scripts/custom.es6', 'scripts/std-js/polyfills/element/close.js', 'scripts/std-js/polyfills/element/remove.js', 'scripts/std-js/polyfills/element/show.js', 'scripts/std-js/polyfills/element/showModal.js', 'scripts/std-js/appcache_listener.es6', 'scripts/std-js/deprefixer.es6', 'scripts/std-js/prototypes.es6', 'scripts/std-js/zq.es6', 'scripts/std-js/support_test.es6', 'scripts/std-js/functions.es6', 'scripts/std-js/json_response.es6')->reduce(function (\DOMElement $head, $script) {
        $head->append('script', null, ['type' => 'application/javascript', 'src' => $script, 'asyne' => '', 'defer' => '']);
        return $head;
    }, $dom->head);
    // Import stylesheet
    $dom->head->append('link', null, ['rel' => 'stylesheet', 'href' => 'stylesheets/styles/import.css', 'media' => 'all']);
    $dom->body->append('header')->append('h1', 'HTTP-OS');
    $dom->body->append('a', 'Home', ['href' => $url]);
    $details = $dom->body->append('main')->append('details');
Esempio n. 3
0
    http_response_code(500);
    exit('PHP version ' . getenv('MIN_PHP_VERSION') . ' or greater is required');
}
define('BASE', __DIR__);
if (PHP_SAPI === 'cli') {
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'std-php-functions' . DIRECTORY_SEPARATOR . 'autoloader.php';
}
init();
if (!defined('THEME')) {
    define('THEME', 'default-theme');
}
define_UA();
set_exception_handler(new \shgysk8zer0\Core\ExceptionLog());
$redirect = false;
$URL = \shgysk8zer0\Core\URL::load();
$headers = \shgysk8zer0\Core\Headers::load();
if ($URL->host === 'localhost' and BROWSER === 'Chrome') {
    $URL->host = '127.0.0.1';
    $redirect = true;
} elseif (substr($URL->host, 0, 4) === 'www.') {
    $URL->host = substr($URL->host, 4);
    $redirect = true;
} elseif (array_key_exists('tags', $_REQUEST)) {
    $URL->path .= 'tags/' . urlencode($_REQUEST['tags']);
    $redirect = true;
}
if ($redirect) {
    unset($URL->user, $URL->pass, $URL->query, $URL->fragment);
    http_response_code(301);
    $headers->Location = "{$URL}";
    exit;