Пример #1
0
$cobra['path.app'] = $__home . '/apps';
$cobra['path.cache'] = $__home . '/cache';
$cobra['path.log'] = $__home . '/log';
$cobra['path.error'] = $__home . '/error';
$cobra['path.htdocs'] = $__home . '/../htdocs';
// system files
$cobra['path.bootstrap'] = __FILE__;
$cobra['path.kernel'] = $__home . '/k.php';
$cobra['path.config'] = $__home . '/co.ses.php';
// load kernel
if (!is_readable($cobra['path.kernel'])) {
    die('boot::kernel');
}
// else
require_once $cobra['path.kernel'];
// load config
if (!is_readable($cobra['path.config'])) {
    die('boot::config');
}
// else
require_once $cobra['path.config'];
// custom defines
// __k_define( 'COBRA_SITE_LOCK', $cobra['path.htdocs'] . '/nologin' );
__k_define('COBRA_OB', false);
__k_define('COBRA_RECURSIVE_CACHE', true);
// init cobra
__k_init('UTF-8', '__k_exception_handler');
// cache cobra
__k_cache_store(COBRA_MAIN_ID, new coCobra($cobra, $config));
// clean up
unset($__home, $cobra, $config);
Пример #2
0
<?php

__k_define('COBRA_REQUEST_SIZE', 128);
__k_define('COBRA_REQUEST_POST', true);
__k_define('COBRA_REQUEST_JSON_OBCLEAN', COBRA_KERNEL_JSON_OBCLEAN);
// begin static class coReq
class coReq
{
    public function __construct()
    {
    }
    public static function request($id = NULL, $default = NULL, $post = COBRA_REQUEST_POST, $clear = true, $safe = true, $size = COBRA_REQUEST_SIZE)
    {
        if ($post) {
            $v = (!isset($_POST[$id]) or $_POST[$id] == '') ? $default : $_POST[$id];
            if ($clear) {
                unset($_POST[$id]);
            }
        } else {
            $v = (!isset($_REQUEST[$id]) or $_REQUEST[$id] == '') ? $default : $_REQUEST[$id];
            if ($clear) {
                unset($_REQUEST[$id]);
            }
        }
        if ($safe && !empty($v)) {
            $v = coStr::subalnum($v, $size);
        }
        return $v;
    }
    public static function get($id = NULL, $default = NULL, $clear = true, $safe = true, $size = COBRA_REQUEST_SIZE)
    {
Пример #3
0
Файл: k.php Проект: hornos/cobra
function __k_init($encoding = 'UTF-8', $error_handler = NULL)
{
    __k_define('COBRA_MAIN_ID', 'cobra');
    __k_define('COBRA_KERNEL_STRING_SIZE', 64);
    __k_define('COBRA_KERNEL_STRING_REGEXP', '[^[:alpha:]_.-]');
    __k_define('COBRA_KERNEL_JSON_OBCLEAN', false);
    __k_define('COBRA_MAIN_CACHE_ID', 'cobra');
    __k_define('COBRA_RECURSIVE_CACHE', false);
    __k_define('COBRA_CLASS_EXTENSION', 'php');
    __k_define('COBRA_APP_BOOTSTRAP', 'bs.php');
    __k_define('COBRA_CACHE_EXTENSION', 'cache');
    __k_define('COBRA_ERROR_EXTENSION', 'html');
    __k_define('COBRA_DEBUG', 9);
    __k_define('COBRA_CLI', PHP_SAPI == 'cli' ? true : false);
    __k_define('COBRA_OB', true);
    __k_define('COBRA_EOL', COBRA_CLI ? PHP_EOL : '<br>' . PHP_EOL);
    __k_define('COBRA_MB', extension_loaded('mbstring'));
    // Time
    __k_define('COBRA_DEFAULT_TIMEZONE', 'CET');
    date_default_timezone_set(COBRA_DEFAULT_TIMEZONE);
    __k_ob_start();
    __k_encoding($encoding);
    // exception handling
    if (!empty($error_handler)) {
        set_exception_handler($error_handler);
    }
    return true;
}
Пример #4
0
<?php

__k_define('COBRA_STRING_SIZE', COBRA_KERNEL_STRING_SIZE);
__k_define('COBRA_STRING_REGEX_ALPHA', '[^[:alpha:]_:./ -]');
__k_define('COBRA_STRING_REGEX_NAME', '[^[:alpha:] -]');
__k_define('COBRA_STRING_REGEX_ALNUM', '[^[:alnum:]_:./ -]');
__k_define('COBRA_STRING_REGEX_EMAIL', '[^[:alnum:]@_./ -]');
__k_define('COBRA_STRING_REGEX_PREURL', '^.*:\\/\\/');
__k_define('COBRA_STRING_REGEX_NUM', '[^[:digit:].-]');
__k_define('COBRA_STRING_REGEX_TEL', '[^[:digit:].+-]');
// begin static class coStr
class coStr
{
    public function __construct()
    {
    }
    public static function lower($str = '')
    {
        return COBRA_MB ? mb_strtolower($str) : strtolower($str);
    }
    public static function trunc($str = '', $size = COBRA_STRING_SIZE)
    {
        if ($size == 0) {
            return $str;
        }
        return COBRA_MB ? mb_substr(trim($str), 0, $size) : substr(trim($str), 0, $size);
    }
    public static function sqlf($str = '')
    {
        return '\'' . addslashes($str) . '\'';
    }
Пример #5
0
<?php

// Global cobra defines
__k_define('COBRA_DB_FUNCTION_PREFIX', 'f_');
__k_define('COBRA_DB_TABLE_PREFIX', 't_');
__k_define('COBRA_DB_TABLEFUNCTION_PREFIX', COBRA_DB_FUNCTION_PREFIX . COBRA_DB_TABLE_PREFIX);
__k_define('COBRA_DB_SELECT_LIMIT', 500);
__k_define('COBRA_DB_PROCEDURE_NAME_SIZE', 256);
__k_define('COBRA_DB_SQL_TIME', true);
__k_define('COBRA_DB_TIMESTAMP_FORMAT', 'Y-m-d H:i:s');
// PHP microtime bug?
__k_define('COBRA_DB_MICROTIME_FORMAT', 'Y-m-d H:i:s.u');
// Exception class
class coDBEx extends coEx
{
    public function __construct($message = __CLASS__)
    {
        parent::__construct($message);
    }
}
// begin class coDB
class coDB implements ArrayAccess
{
    private $__config;
    /**< config array */
    private $__dbconn;
    /**< database connection object */
    // Constructor
    public function __construct($config = NULL)
    {
        if (empty($config)) {