示例#1
0
 public function load($group)
 {
     $config = array();
     if ($files = JsonApiApplication::find_file($this->_directory, $group, NULL, TRUE)) {
         foreach ($files as $file) {
             $config = Arr::merge($config, JsonApiApplication::load($file));
         }
     }
     return $config;
 }
示例#2
0
 public static function load($lang)
 {
     if (isset(I18n::$_cache[$lang])) {
         return I18n::$_cache[$lang];
     }
     $table = array();
     $parts = explode("-", $lang);
     do {
         $path = implode(DIRECTORY_SEPARATOR, $parts);
         if ($files = JsonApiApplication::find_file("i18n", $path, NULL, TRUE)) {
             $t = array();
             foreach ($files as $file) {
                 $t = array_merge($t, JsonApiApplication::load($file));
             }
             $table += $t;
         }
         array_pop($parts);
     } while ($parts);
     return I18n::$_cache[$lang] = $table;
 }
示例#3
0
 public static function cache($save = FALSE, $append = FALSE)
 {
     if ($save === TRUE) {
         try {
             JsonApiApplication::cache('Route::cache()', Route::$_routes);
         } catch (Exception $e) {
             throw new JsonApiApplication_Exception('One or more routes could not be cached (:message)', array(':message' => $e->getMessage()), 0, $e);
         }
     } else {
         if ($routes = JsonApiApplication::cache('Route::cache()')) {
             if ($append) {
                 Route::$_routes += $routes;
             } else {
                 Route::$_routes = $routes;
             }
             return Route::$cache = TRUE;
         } else {
             return Route::$cache = FALSE;
         }
     }
 }
 public function render()
 {
     if (!$this->_header->offsetExists('content-type')) {
         $this->_header['content-type'] = JsonApiApplication::$content_type . '; charset=' . JsonApiApplication::$charset;
     }
     $this->headers('content-length', (string) $this->content_length());
     if (JsonApiApplication::$expose) {
         $this->headers('user-agent', JsonApiApplication::version());
     }
     if ($this->_cookies) {
         if (extension_loaded('http')) {
             $cookies = version_compare(phpversion('http'), '2.0.0', '>=') ? (string) new \http\Cookie($this->_cookies) : http_build_cookie($this->_cookies);
             $this->_header['set-cookie'] = $cookies;
         } else {
             $cookies = array();
             foreach ($this->_cookies as $key => $value) {
                 $string = $key . '=' . $value['value'] . '; expires=' . date('l, d M Y H:i:s T', $value['expiration']);
                 $cookies[] = $string;
             }
             $this->_header['set-cookie'] = $cookies;
         }
     }
     $output = $this->_protocol . ' ' . $this->_status . ' ' . Response::$messages[$this->_status] . "\r\n";
     $output .= (string) $this->_header;
     $output .= $this->_body;
     return $output;
 }
} else {
    require SYSPATH . "classes" . DIRECTORY_SEPARATOR . "JsonApiApplication" . EXT;
}
date_default_timezone_set("australia/brisbane");
setlocale(LC_ALL, "en_AU.utf-8");
spl_autoload_register(array("JsonApiApplication", "auto_load"));
ini_set("unserialize_callback_func", "spl_autoload_call");
mb_substitute_character("none");
if (isset($_SERVER["JSONAPIAPPLICATION_ENV"])) {
    JsonApiApplication::$environment = constant("JsonApiApplication::" . strtoupper($_SERVER["JSONAPIAPPLICATION_ENV"]));
}
I18n::lang("en-au");
JsonApiApplication::init(array("base_url" => "/JsonApiApplication/", "errors" => true, "index_file" => FALSE));
JsonApiApplication::$log->attach(new Log_File(APPPATH . "logs"));
JsonApiApplication::$config->attach(new JsonApiApplication_Config_File());
JsonApiApplication::modules(array("auth" => MODPATH . "auth", "orm" => MODPATH . "orm", "cache" => MODPATH . "cache", "database" => MODPATH . "database", "mailer" => MODPATH . "mailer"));
Cache::$default = "file";
Route::set("home", "home(/<catcher>)", array("catcher" => ".*"))->defaults(array("controller" => "welcome", "action" => "read"));
Route::set("welcome", "")->defaults(array("controller" => "welcome", "action" => "read"));
Route::set("navigation", "navigation/read/<id>")->defaults(array("controller" => "navigation", "action" => "read"));
Route::set("page", "page/read/<id>")->defaults(array("controller" => "page", "action" => "read"));
Route::set("testimonial", "testimonial/read/<limit>/<offset>")->defaults(array("controller" => "testimonial", "action" => "read"));
Route::set("posts", "posts/read/<limit>/<offset>")->defaults(array("controller" => "posts", "action" => "read"));
Route::set("post", "post/read/<id>")->defaults(array("controller" => "post", "action" => "read"));
Route::set("comments", "comments/read/<id>/<limit>/<offset>")->defaults(array("controller" => "comments", "action" => "read"));
Route::set("categories", "categories/read/<limit>/<offset>")->defaults(array("controller" => "categories", "action" => "read"));
Route::set("contactinfo", "contactinfo/read/<id>")->defaults(array("controller" => "contactinfo", "action" => "read"));
Route::set("contact", "contact/post")->defaults(array("controller" => "contact", "action" => "post"));
Route::set("captcha", "contact/read")->defaults(array("controller" => "contact", "action" => "read"));
Cookie::$salt = "LOASWnL7A1WKQMk1JALCP1H5BMelyIPQNVdXiGsbEEVhVtyApGsFC6LyINUsDHl1";
/*if (!Route::cache()) Route::cache(TRUE);*/
示例#6
0
<?php

if (count(get_included_files()) == 1) {
    exit("Direct access not permitted.");
}
?>

<style type="text/css">
<?php 
include JsonApiApplication::find_file("views", "profiler/style", "css");
?>
</style>

<?php 
$group_stats = Profiler::group_stats();
$group_cols = array('min', 'max', 'average', 'total');
$application_cols = array('min', 'max', 'average', 'current');
?>

<div class="JsonApiApplication">
	<?php 
foreach (Profiler::groups() as $group => $benchmarks) {
    ?>
	<table class="profiler">
		<tr class="group">
			<th class="name" rowspan="2"><?php 
    echo __(ucfirst($group));
    ?>
</th>
			<td class="time" colspan="4"><?php 
    echo number_format($group_stats[$group]['total']['time'], 6);
 /**
  * Returns the error messages. If no file is specified, the error message
  * will be the name of the rule that failed. When a file is specified, the
  * message will be loaded from "field/rule", or if no rule-specific message
  * exists, "field/default" will be used. If neither is set, the returned
  * message will be "file/field/rule".
  *
  * By default all messages are translated using the default language.
  * A string can be used as the second parameter to specified the language
  * that the message was written in.
  *
  *     // Get errors from messages/forms/login.php
  *     $errors = $Validation->errors('forms/login');
  *
  * @uses    JsonApiApplication::message
  * @param   string  $file       file to load error messages from
  * @param   mixed   $translate  translate the message
  * @return  array
  */
 public function errors($file = NULL, $translate = TRUE)
 {
     if ($file === NULL) {
         return $this->_errors;
     }
     $messages = array();
     foreach ($this->_errors as $field => $set) {
         list($error, $params) = $set;
         $label = $this->_labels[$field];
         if ($translate) {
             if (is_string($translate)) {
                 $label = __($label, NULL, $translate);
             } else {
                 $label = __($label);
             }
         }
         $values = array(':field' => $label, ':value' => Arr::get($this, $field));
         if (is_array($values[':value'])) {
             $values[':value'] = implode(', ', Arr::flatten($values[':value']));
         }
         if ($params) {
             foreach ($params as $key => $value) {
                 if (is_array($value)) {
                     $value = implode(', ', Arr::flatten($value));
                 } elseif (is_object($value)) {
                     continue;
                 }
                 if (isset($this->_labels[$value])) {
                     $value = $this->_labels[$value];
                     if ($translate) {
                         if (is_string($translate)) {
                             $value = __($value, NULL, $translate);
                         } else {
                             $value = __($value);
                         }
                     }
                 }
                 $values[':param' . ($key + 1)] = $value;
             }
         }
         if ($message = JsonApiApplication::message($file, "{$field}.{$error}") and is_string($message)) {
         } elseif ($message = JsonApiApplication::message($file, "{$field}.default") and is_string($message)) {
         } elseif ($message = JsonApiApplication::message($file, $error) and is_string($message)) {
             // Found a default message for this error
         } elseif ($message = JsonApiApplication::message('validation', $error) and is_string($message)) {
             // Found a default message for this error
         } else {
             // No message exists, display the path expected
             $message = "{$file}.{$field}.{$error}";
         }
         if ($translate) {
             if (is_string($translate)) {
                 $message = __($message, $values, $translate);
             } else {
                 $message = __($message, $values);
             }
         } else {
             $message = strtr($message, $values);
         }
         $messages[$field] = $message;
     }
     return $messages;
 }
示例#8
0
 /**
  * Sends headers to the php processor, or supplied `$callback` argument.
  * This method formats the headers correctly for output, re-instating their
  * capitalization for transmission.
  *
  * [!!] if you supply a custom header handler via `$callback`, it is
  *  recommended that `$response` is returned
  *
  * @param   HTTP_Response   $response   header to send
  * @param   boolean         $replace    replace existing value
  * @param   callback        $callback   optional callback to replace PHP header function
  * @return  mixed
  * @since   3.2.0
  */
 public function send_headers(HTTP_Response $response = NULL, $replace = FALSE, $callback = NULL)
 {
     $protocol = $response->protocol();
     $status = $response->status();
     // Create the response header
     $processed_headers = array($protocol . ' ' . $status . ' ' . Response::$messages[$status]);
     // Get the headers array
     $headers = $response->headers()->getArrayCopy();
     foreach ($headers as $header => $value) {
         if (is_array($value)) {
             $value = implode(', ', $value);
         }
         $processed_headers[] = Text::ucfirst($header) . ': ' . $value;
     }
     if (!isset($headers['content-type'])) {
         $processed_headers[] = 'Content-Type: ' . JsonApiApplication::$content_type . '; charset=' . JsonApiApplication::$charset;
     }
     if (JsonApiApplication::$expose and !isset($headers['x-powered-by'])) {
         $processed_headers[] = 'X-Powered-By: ' . JsonApiApplication::version();
     }
     // Get the cookies and apply
     if ($cookies = $response->cookie()) {
         $processed_headers['Set-Cookie'] = $cookies;
     }
     if (is_callable($callback)) {
         // Use the callback method to set header
         return call_user_func($callback, $response, $processed_headers, $replace);
     } else {
         $this->_send_headers_to_php($processed_headers, $replace);
         return $response;
     }
 }
 public function action_read()
 {
     $this->data = Model::factory($this->request->controller())->Read(JsonApiApplication::sanitize($this->request->param("limit")), JsonApiApplication::sanitize($this->request->param("offset")));
 }
示例#10
0
        $this->_message->attach(Swift_Attachment::newInstance($data, $file, $mime));
        return $this;
    }
    public function send(array &$failed = NULL)
    {
        return Email::mailer()->send($this->_message, $failed);
    }
    public function batch(array $to, array &$failed = NULL)
    {
        $message = clone $this->_message;
        $mailer = Email::mailer();
        $total = 0;
        foreach ($to as $email => $name) {
            if (ctype_digit((string) $email)) {
                $email = $name;
                $name = NULL;
            }
            $message->setTo($email, $name);
            $total += $mailer->send($message, $failed);
        }
        return $total;
    }
}
if (!class_exists("Swift")) {
    require JsonApiApplication::find_file("vendor" . DIRECTORY_SEPARATOR . "swiftmailer", "lib" . DIRECTORY_SEPARATOR . "swift_required");
}
function swiftmailer_configurator()
{
    Swift_Preferences::getInstance()->setCharset(JsonApiApplication::$charset);
}
Swift::init("swiftmailer_configurator");
示例#11
0
 public function set_filename($file)
 {
     if (($path = JsonApiApplication::find_file("views", $file)) === FALSE) {
         throw new View_Exception("The requested view :file could not be found", array(":file" => $file));
     }
     $this->_file = $path;
     return $this;
 }
示例#12
0
 public function execute($db = NULL, $as_object = NULL, $object_params = NULL)
 {
     if (!is_object($db)) {
         $db = Database::instance($db);
     }
     if ($as_object === NULL) {
         $as_object = $this->_as_object;
     }
     if ($object_params === NULL) {
         $object_params = $this->_object_params;
     }
     $sql = $this->compile($db);
     if ($this->_lifetime !== NULL and $this->_type === Database::SELECT) {
         $cache_key = 'Database::query("' . $db . '", "' . $sql . '")';
         if (($result = JsonApiApplication::cache($cache_key, NULL, $this->_lifetime)) !== NULL and !$this->_force_execute) {
             return new Database_Result_Cached($result, $sql, $as_object, $object_params);
         }
     }
     $result = $db->query($this->_type, $sql, $as_object, $object_params);
     if (isset($cache_key) and $this->_lifetime > 0) {
         JsonApiApplication::cache($cache_key, $result->as_array(), $this->_lifetime);
     }
     return $result;
 }
示例#13
0
 public static function from_unicode($arr)
 {
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require JsonApiApplication::find_file("utf8", __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = TRUE;
     }
     return _from_unicode($arr);
 }
示例#14
0
 /**
  * Creates a new Mailer object.
  *
  * @param   string  configuration
  * @return  void
  */
 public function __construct($config = "default")
 {
     if (!class_exists('Swift', FALSE)) {
         // Load SwiftMailer Autoloader
         require_once JsonApiApplication::find_file('vendor', 'swift/swift_required');
     }
     // Load configuration
     $this->before();
 }
示例#15
0
 public static function gen_mt_rand()
 {
     if (!isset(UTF8::$called[__FUNCTION__])) {
         require JsonApiApplication::find_file("utf8", __FUNCTION__);
         // Function has been called
         UTF8::$called[__FUNCTION__] = TRUE;
     }
     return _gen_mt_rand();
 }
} else {
    require SYSPATH . "classes" . DIRECTORY_SEPARATOR . "JsonApiApplication" . EXT;
}
date_default_timezone_set("australia/brisbane");
setlocale(LC_ALL, "en_AU.utf-8");
spl_autoload_register(array("JsonApiApplication", "auto_load"));
ini_set("unserialize_callback_func", "spl_autoload_call");
mb_substitute_character("none");
if (isset($_SERVER["JSONAPIAPPLICATION_ENV"])) {
    JsonApiApplication::$environment = constant("JsonApiApplication::" . strtoupper($_SERVER["JSONAPIAPPLICATION_ENV"]));
}
I18n::lang("en-au");
JsonApiApplication::init(array("base_url" => "/JsonApiApplication/", "errors" => true));
JsonApiApplication::$log->attach(new Log_File(APPPATH . "logs"));
JsonApiApplication::$config->attach(new JsonApiApplication_Config_File());
JsonApiApplication::modules(array("cache" => MODPATH . "cache", "database" => MODPATH . "database", "email" => MODPATH . "email"));
Cache::$default = "file";
Route::set("welcome", "")->defaults(array("controller" => "welcome", "action" => "read"));
Route::set("navigation", "navigation/read/<id>")->defaults(array("controller" => "navigation", "action" => "read"));
Route::set("page", "page/read/<id>")->defaults(array("controller" => "page", "action" => "read"));
Route::set("posts", "posts/read")->defaults(array("controller" => "posts", "action" => "read"));
Route::set("post", "post/read/<id>")->defaults(array("controller" => "post", "action" => "read"));
Route::set("comments", "comments/read/<id>/<row>/<offset>")->defaults(array("controller" => "comments", "action" => "read"));
Route::set("categories", "categories/read")->defaults(array("controller" => "categories", "action" => "read"));
Route::set("contactinfo", "contactinfo/read/<id>")->defaults(array("controller" => "contactinfo", "action" => "read"));
Route::set("contact", "contact/post")->defaults(array("controller" => "contact", "action" => "post"));
Route::set("captcha", "contact/read")->defaults(array("controller" => "contact", "action" => "read"));
Cookie::$salt = "LOASWnL7A1WKQMk1JALCP1H5BMelyIPQNVdXiGsbEEVhVtyApGsFC6LyINUsDHl1";
/*if (!Route::cache()) Route::cache(TRUE);

    try {
示例#17
0
 public static function shutdown_handler()
 {
     if (!JsonApiApplication::$_init) {
         return;
     }
     try {
         if (JsonApiApplication::$caching === TRUE and JsonApiApplication::$_files_changed === TRUE) {
             // Write the file path cache
             JsonApiApplication::cache("JsonApiApplication::find_file()", JsonApiApplication::$_files);
         }
     } catch (Exception $e) {
         // Pass the exception to the handler
         JsonApiApplication_Exception::handler($e);
     }
     if (JsonApiApplication::$errors and $error = error_get_last() and in_array($error["type"], JsonApiApplication::$shutdown_errors)) {
         // Clean the output buffer
         ob_get_level() and ob_clean();
         // Fake an exception for nice debugging
         JsonApiApplication_Exception::handler(new ErrorException($error["message"], $error["type"], 0, $error["file"], $error["line"]));
         // Shutdown now to avoid a "death loop"
         exit(1);
     }
 }
示例#18
0
 public function action_read()
 {
     $this->data = Model::factory($this->request->controller())->Read(JsonApiApplication::sanitize($this->request->param("id")));
     //echo $this->request->param('id');
 }
示例#19
0
 /**
  * Renders the HTTP_Interaction to a string, producing
  *
  *  - Protocol
  *  - Headers
  *  - Body
  *
  *  If there are variables set to the `JsonApiApplication_Request::$_post`
  *  they will override any values set to body.
  *
  * @return  string
  */
 public function render()
 {
     if (!($post = $this->post())) {
         $body = $this->body();
     } else {
         $this->headers('content-type', 'application/x-www-form-urlencoded; charset=' . JsonApiApplication::$charset);
         $body = http_build_query($post, NULL, '&');
     }
     // Set the content length
     $this->headers('content-length', (string) $this->content_length());
     // If JsonApiApplication expose, set the user-agent
     if (JsonApiApplication::$expose) {
         $this->headers('user-agent', JsonApiApplication::version());
     }
     // Prepare cookies
     if ($this->_cookies) {
         $cookie_string = array();
         // Parse each
         foreach ($this->_cookies as $key => $value) {
             $cookie_string[] = $key . '=' . $value;
         }
         // Create the cookie string
         $this->_header['cookie'] = implode('; ', $cookie_string);
     }
     $output = $this->method() . ' ' . $this->uri() . ' ' . $this->protocol() . "\r\n";
     $output .= (string) $this->_header;
     $output .= $body;
     return $output;
 }
示例#20
0
 /**
  * Gets the total application run time and memory usage. Caches the result
  * so that it can be compared between requests.
  *
  *     list($time, $memory) = Profiler::application();
  *
  * @return  array  execution time, memory
  * @uses    JsonApiApplication::cache
  */
 public static function application()
 {
     // Load the stats from cache, which is valid for 1 day
     $stats = JsonApiApplication::cache('profiler_application_stats', NULL, 3600 * 24);
     if (!is_array($stats) or $stats['count'] > Profiler::$rollover) {
         // Initialize the stats array
         $stats = array('min' => array('time' => NULL, 'memory' => NULL), 'max' => array('time' => NULL, 'memory' => NULL), 'total' => array('time' => NULL, 'memory' => NULL), 'count' => 0);
     }
     // Get the application run time
     $time = microtime(TRUE) - APPLICATION_START_TIME;
     // Get the total memory usage
     $memory = memory_get_usage() - APPLICATION_START_MEMORY;
     // Calculate max time
     if ($stats['max']['time'] === NULL or $time > $stats['max']['time']) {
         $stats['max']['time'] = $time;
     }
     // Calculate min time
     if ($stats['min']['time'] === NULL or $time < $stats['min']['time']) {
         $stats['min']['time'] = $time;
     }
     // Add to total time
     $stats['total']['time'] += $time;
     // Calculate max memory
     if ($stats['max']['memory'] === NULL or $memory > $stats['max']['memory']) {
         $stats['max']['memory'] = $memory;
     }
     // Calculate min memory
     if ($stats['min']['memory'] === NULL or $memory < $stats['min']['memory']) {
         $stats['min']['memory'] = $memory;
     }
     // Add to total memory
     $stats['total']['memory'] += $memory;
     // Another mark has been added to the stats
     $stats['count']++;
     // Determine the averages
     $stats['average'] = array('time' => $stats['total']['time'] / $stats['count'], 'memory' => $stats['total']['memory'] / $stats['count']);
     // Cache the new stats
     JsonApiApplication::cache('profiler_application_stats', $stats);
     // Set the current application execution time and memory
     // Do NOT cache these, they are specific to the current request only
     $stats['current']['time'] = $time;
     $stats['current']['memory'] = $memory;
     // Return the total application run time and memory usage
     return $stats;
 }