* Bombay is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * Bombay is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * To read the license please visit http://www.gnu.org/copyleft/gpl.html
 *
 *
 *-------10--------20--------30--------40--------50--------60---------72
 */
requires('helpers');
define('STATUS_CONTINUE', 100);
define('STATUS_SWITCHING_PROTOCOLS', 101);
define('STATUS_OK', 200);
define('STATUS_CREATED', 201);
define('STATUS_ACCEPTED', 202);
define('STATUS_NON_AUTHORITATIVE_INFORMATION', 203);
define('STATUS_NO_CONTENT', 204);
define('STATUS_RESET_CONTENT', 205);
define('STATUS_PARTIAL_CONTENT', 206);
define('STATUS_MULTIPLE_CHOICES', 300);
define('STATUS_MOVED_PERMANENTLY', 301);
define('STATUS_FOUND', 302);
define('STATUS_SEE_OTHER', 303);
define('STATUS_NOT_MODIFIED', 304);
define('STATUS_USE_PROXY', 305);
Exemple #2
0
 * Bombay is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * Bombay is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * To read the license please visit http://www.gnu.org/copyleft/gpl.html
 *
 *
 *-------10--------20--------30--------40--------50--------60---------72
 */
requires('helpers', 'webserver');
define('URI_SCHEME', uri_scheme(server_var('HTTPS')));
define('URI_HOST', uri_host(server_var('HTTP_HOST')));
define('URI_PORT', uri_port(server_var('HTTP_HOST')));
define('URI_PATH', uri_path(server_var('PHP_SELF')));
define('URI_ABSOLUTE_BASE', uri_absolute_base(URI_SCHEME, URI_HOST, URI_PORT, URI_PATH));
define('URI_RELATIVE_BASE', uri_relative_base(URI_PATH));
define('URI_SECURE_ABSOLUTE_BASE', uri_absolute_base('https', URI_HOST, URI_PORT, URI_PATH));
function uri_scheme($https)
{
    $ssl = !is_null($https) and is_equal('on', $https);
    $scheme = $ssl ? 'https' : 'http';
    return $scheme;
}
function uri_host($http_host)
{
Exemple #3
0
<?php

requires('helpers', 'template');
function handler_func_resolver($handler_func)
{
    if (!str_contains('/', $handler_func)) {
        return array('', $handler_func);
    }
    $pieces = explode('/', $handler_func);
    $func = array_pop($pieces);
    $handler = implode('/', $pieces);
    return array($handler, $func);
}
function handler_dir($handler)
{
    $handler_basedir = php_self_dir() . 'handlers' . DIRECTORY_SEPARATOR;
    return $handler_basedir . str_slashes_to_directory_separator($handler) . DIRECTORY_SEPARATOR;
}
function handler_templates_dir($handler)
{
    $basedir = empty($handler) ? php_self_dir() : handler_dir($handler);
    return $basedir . 'templates' . DIRECTORY_SEPARATOR;
}
function handler_file($handler)
{
    if (str_contains('/', $handler)) {
        $pieces = explode('/', $handler);
        $handler_basename = array_pop($pieces);
    } else {
        $handler_basename = $handler;
    }
 * Bombay is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * Bombay is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * To read the license please visit http://www.gnu.org/copyleft/gpl.html
 *
 *
 *-------10--------20--------30--------40--------50--------60---------72
 */
requires('uri');
function apache_specific_is_rewrite_engine_on()
{
    return _apache_specific_is_rewrite_engine_on(server_var('REWRITE_ENGINE'));
}
function _apache_specific_is_rewrite_engine_on($rewrite_engine)
{
    return is_equal('on', strtolower($rewrite_engine));
}
function apache_specific_request_path()
{
    if (!apache_specific_is_rewrite_engine_on()) {
        return default_request_path();
    }
    return _apache_specific_request_path(server_var('REQUEST_URI'), uri_path(server_var('PHP_SELF')));
}
Exemple #5
0
<?php

require_once dirname(__FILE__) . '/../pnd.php';
requires('helper');
function str_slashes_to_directory_separator($path)
{
    return preg_replace('/[\\/\\\\]/', DIRECTORY_SEPARATOR, $path);
}
function str_contains($needle, $haystack)
{
    return strpos($haystack, $needle) !== false;
}
function str_underscorize($str)
{
    $str = preg_replace('/^[^a-zA-Z0-9]+/', '', trim($str));
    return preg_replace('/[^a-zA-Z0-9]/', '_', trim($str));
}
function str_hyphenate($str)
{
    $str = preg_replace('/^[^a-zA-Z0-9]+/', '', trim($str));
    return preg_replace('/[^a-zA-Z0-9]/', '-', trim($str));
}
function str_humanize($str)
{
    return strtr(trim($str), array('-' => ' ', '_' => ' '));
}
function str_xss_sanitize($str, $charset = 'UTF-8')
{
    return htmlspecialchars($str, ENT_QUOTES, $charset);
}
function str_random_alphanum($length = 10)
Exemple #6
0
<?php

require_once dirname(__FILE__) . '/../pnd.php';
requires('str');
function varialize($var_name, $var)
{
    $var_str = var_export($var, true);
    return "<?php\n\n\${$var_name} = {$var_str};\n\n?>";
}
function unvarialize_file($file, $var_name, $default = NULL)
{
    include $file;
    return isset(${$var_name}) ? ${$var_name} : $default;
}
function is_equal($var1, $var2)
{
    return $var1 === $var2;
}
function array_val($arr, $key_str, $default = NULL)
{
    $keys = explode('.', $key_str);
    $val = $arr;
    foreach ($keys as $key) {
        if (!isset($val[$key])) {
            return $default;
        }
        $val = $val[$key];
    }
    return $val;
}
function server_var($key, $sanitize = true)
Exemple #7
0
<?php

require_once dirname(__FILE__) . '/../bombay.php';
//TODO: 'error'
requires('helpers', 'request', 'response', 'route', 'template', 'form', 'emailmodule', 'db', 'handler');
function yield_to_glue()
{
    map_request_to_handler(request_(), routes());
}
function map_request_to_handler($req, $routes)
{
    if ($route = route_match($routes, $req)) {
        $req['path'] = $route['path_matches'];
        exit_with_mojo_flush_response($req, next_func($req, $route['funcs']));
    }
    exit_with_404_plain('Not Found');
}
function next_func($req, $pipeline)
{
    if (!empty($pipeline)) {
        $next_func = array_shift($pipeline);
        list($handler, $func) = func_resolver($next_func);
        if (!is_callable($func)) {
            handler_autoloader($handler);
        }
        if (is_callable($func)) {
            $response = call_user_func($func, $req, $pipeline);
            if (!isset($response['template']) and is_string($next_func)) {
                $response['template'] = $next_func;
            }
            return $response;
Exemple #8
0
<?php

requires('path', 'helpers', 'request');
function routes($route = NULL, $reset = false)
{
    static $routes = array();
    if ($reset) {
        return $routes = array();
    }
    if (is_null($route)) {
        return $routes;
    }
    $routes[] = $route;
    return $routes;
}
function handle_head()
{
    handle_('HEAD', func_get_args());
}
function handle_get()
{
    handle_('GET', func_get_args());
}
function handle_post()
{
    handle_('POST', func_get_args());
}
function handle_($method, $args)
{
    array_unshift($args, $method);
    $route = parse_route_params($args);
    CacheCountry::setCacheBehavior(SessionAdmin::getCacheBehavior());
    $cache = CacheCountry::getCountries();

    $service = new DatacenterService($repository, $cache);//$countryMap);
    $statistic = new Statistic();
    $grouper = new DataGrouper();
    $controller = new DatacenterController($service, $statistic, $jsonResponse, $grouper, $factory);     
    return $controller;
}
?>
<?php 
$json = new JsonResponse();
if ($_POST['value'] != null && is_numeric($_POST['value'])) {
    $id_data = $_REQUEST['id_data'];
    $_POST['fromAdmin'] = true;
    $controller = requires($json);
    $value = (double) $_POST['value'];
    $data = new Data(null, null, null, null, null, null, null);
    $data->setId($id_data);
    $data->setValue($value);
    if ($controller->editValue($data)) {
        $message = "Valor alterado com sucesso";
        print_r($json->response(true, $message)->serialize());
    } else {
        $message = "Valor não foi alterado";
        print_r($json->response(false, $message)->serialize());
    }
} else {
    print_r($json->response(false, "O valor deve ser um número válido!")->serialize());
}
Exemple #10
0
<?php

require_once dirname(__FILE__) . '/../pnd.php';
requires('path', 'helper', 'request', 'response');
function handler_($method, $paths, $conds, $func)
{
    return compact('method', 'paths', 'conds', 'func', 'path_matches');
}
function handle_all($path)
{
    handle_request('*', $path, array(), array_slice(func_get_args(), 1));
}
function handle_head($path)
{
    handle_request('HEAD', $path, array(), array_slice(func_get_args(), 1));
}
function handle_get($path)
{
    handle_request('GET', $path, array(), array_slice(func_get_args(), 1));
}
function handle_query($path)
{
    handle_request('GET', $path, array('query' => true), array_slice(func_get_args(), 1));
}
function handle_post($path)
{
    handle_request('POST', $path, array(), array_slice(func_get_args(), 1));
}
function handle_post_action($path, $action)
{
    handle_request('POST', $path, array('action' => $action), array_slice(func_get_args(), 2));