-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Flavio De Stefano
committed
Jan 12, 2015
1 parent
7ccd92b
commit 6195e8b
Showing
797 changed files
with
17,242 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
// Exit if accessed directly. | ||
if( false === defined('AERIA') ) exit; | ||
|
||
wp_enqueue_script('aeria.ajax', AERIA_URL.'resources/js/aeria.ajax.js'); | ||
wp_localize_script('aeria.ajax', 'AERIA_AJAX', [ 'URL' => AERIA_HOME_URL.'index.php' ]); | ||
|
||
// Install Ajax Handler | ||
add_filter('query_vars',function($vars) { | ||
$vars[] = 'ajax'; | ||
return $vars; | ||
}); | ||
|
||
add_action('template_redirect', function() { | ||
if ($action = get_query_var('ajax')) { | ||
ini_set('zlib.output_compression','On'); | ||
|
||
if (!defined('DOING_AJAX')) { | ||
define('DOING_AJAX', true); | ||
} | ||
|
||
send_nosniff_header(); | ||
|
||
$action = $action; | ||
$args = $_REQUEST; | ||
$user_logged = is_user_logged_in(); | ||
|
||
$privateHook = 'AERIA_AJAX_HANDLER_private_'.$action; | ||
$publicHook = 'AERIA_AJAX_HANDLER_public_'.$action; | ||
|
||
unset($args['ajax']); | ||
ob_end_clean(); | ||
|
||
if ($user_logged && AeriaAJAX::existsPrivate($action)) { | ||
do_action($privateHook,$args); | ||
} elseif (AeriaAJAX::exists($action)) { | ||
do_action($publicHook,$args); | ||
} | ||
|
||
exit; | ||
} | ||
}); | ||
|
||
class AeriaAJAX { | ||
|
||
public static $registry = array(); | ||
|
||
public static function exists($function_name){ | ||
return isset(static::$registry['AERIA_AJAX_HANDLER_public_'.$function_name]); | ||
} | ||
|
||
public static function existsPrivate($function_name){ | ||
return isset(static::$registry['AERIA_AJAX_HANDLER_private_'.$function_name]); | ||
} | ||
|
||
public static function register($function_name,$callback){ | ||
$key='AERIA_AJAX_HANDLER_public_'.$function_name; | ||
static::$registry[$key] = $callback; | ||
add_action($key,$callback); | ||
} | ||
|
||
public static function registerPrivate($function_name,$callback){ | ||
$key='AERIA_AJAX_HANDLER_private_'.$function_name; | ||
static::$registry[$key] = $callback; | ||
add_action($key,$callback); | ||
} | ||
|
||
public static function sendJSON($payload){ | ||
ob_end_clean(); | ||
header('Content-Type: application/json'); | ||
die(json_encode($payload,JSON_NUMERIC_CHECK)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php | ||
// Exit if accessed directly. | ||
if( false === defined('AERIA') ) exit; | ||
|
||
|
||
class AeriaCache { | ||
static $cache_hashes = []; | ||
public static $driver = 'AeriaCacheBypass'; | ||
|
||
public static function hash($key){ | ||
return (is_object($key)||is_array($key))?sha1(serialize($key)):$key; | ||
} | ||
|
||
public static function set($data,$key,$group=false,$expire=0){ | ||
$d = static::$driver; | ||
$hash = static::hash($key); | ||
$data = serialize($data); | ||
if(!isset(static::$cache_hashes[$group])) static::$cache_hashes[$group] = []; | ||
static::$cache_hashes[$group][$hash] = time(); | ||
return $d::set($data,$hash,$group,$expire); | ||
} | ||
|
||
public static function get($key,$group=false,$default=null){ | ||
$d = static::$driver; | ||
$hash = static::hash($key); | ||
$r = $d::get($hash,$group,$default); | ||
return is_serialized($r)?unserialize($r):$r; | ||
} | ||
|
||
public static function delete($key,$group=false){ | ||
$d = static::$driver; | ||
$hash = static::hash($key); | ||
return $d::delete($hash,$group); | ||
} | ||
|
||
public static function deleteGroup($group){ | ||
$d = static::$driver; | ||
$d::deleteGroup($group); | ||
} | ||
|
||
public static function clear(){ | ||
$d = static::$driver; | ||
$d::clear(); | ||
} | ||
|
||
public static function setDriver($new_driver){ | ||
$c = 'AeriaCache' . $new_driver; | ||
if (class_exists($c)) { | ||
static::$driver = $c; | ||
} | ||
} | ||
|
||
} | ||
|
||
class AeriaCacheWordPress { | ||
public static function get($key,$group='',$default=null) { | ||
if(null===($v=get_transient($key)) && $default){ | ||
$v = is_callable($default)?call_user_func($default):$default; | ||
static::set($v,$key,$group); | ||
} | ||
return $v; | ||
} | ||
public static function set($data,$key,$group='',$expire=0) { | ||
return set_transient($key,$data,$expire); | ||
} | ||
public static function delete($key,$group='') { | ||
return delete_transient($key); | ||
} | ||
public static function clear() { | ||
} | ||
public static function deleteGroup($group) { | ||
} | ||
} | ||
|
||
function & redis(){ | ||
if(!defined('PREDIS_LOADED')){ | ||
require dirname(__DIR__).'/vendor/Predis/Autoloader.php'; | ||
Predis\Autoloader::register(); | ||
define('PREDIS_LOADED',1); | ||
} | ||
try { | ||
return new Predis\Client('tcp://127.0.0.1:6379'); | ||
} catch(Exception $e){ | ||
die('AeriaCacheRedis Error: '.$e->getMessage()); | ||
} | ||
} | ||
|
||
class AeriaCacheRedis { | ||
|
||
public static function & redis() { | ||
return redis(); | ||
} | ||
|
||
public static function get($key,$group=false,$default=null) { | ||
$r = redis(); | ||
|
||
try { | ||
$v = $group ? $r->hget($group,$key) : $r->get($key); | ||
} catch(Exception $e) { | ||
$v = null; | ||
} | ||
|
||
if (null === $v && $default){ | ||
$v = is_callable($default) ? call_user_func($default) : $default; | ||
static::set($v, $key, $group); | ||
} | ||
|
||
return $v; | ||
|
||
} | ||
|
||
public static function set($data,$key,$group=false,$expire=0) { | ||
$r = redis(); | ||
try { | ||
if ($group) { | ||
return $r->hset($group, $key, $data); | ||
} else { | ||
if (!$expire) return $r->set($key, $data); | ||
else return $r->setex($key, $expire, $data); | ||
} | ||
} catch(Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static function delete($key,$group=false) { | ||
$r = redis(); | ||
try { | ||
return $group ? $r->hdel($group,$key) : $r->del($key); | ||
} catch(Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static function deleteGroup($group) { | ||
$r = redis(); | ||
try { | ||
return $r->delete($group); | ||
} catch(Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
public static function clear() { | ||
$r = redis(); | ||
return $r->flushall(); | ||
} | ||
|
||
} | ||
|
||
|
||
class AeriaCacheBypass { | ||
|
||
public static function get($key,$group='') { return false; } | ||
|
||
public static function set($data,$key,$group='',$expire=0) {} | ||
|
||
public static function delete($key,$group='') {} | ||
|
||
public static function deleteGroup($group) {} | ||
|
||
public static function clear() {} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
// Exit if accessed directly. | ||
if( false === defined('AERIA') ) exit; | ||
|
||
class AeriaNetwork { | ||
|
||
public static $errors = []; | ||
|
||
public static function send($uri, $data=[], $method='GET', $headers=[], $additional=[]) | ||
{ | ||
if (is_array($data)) $data = http_build_query($data); | ||
$method = strtoupper($method); | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_TIMEOUT, 2); | ||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
|
||
if ($method=='POST') { | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
if (!empty($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | ||
} else { | ||
if (!empty($data)) $uri .= '?' . $data; | ||
} | ||
|
||
if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
curl_setopt($ch, CURLOPT_URL, $uri); | ||
|
||
if (!empty($additional)) foreach ((array)$additional as $k => $v) curl_setopt($curl, $k, $v); | ||
|
||
try { | ||
$content = curl_exec($ch); | ||
if (curl_errno($ch)) throw new Exception(curl_error($ch)); | ||
if (empty($content)) throw new Exception("Empty response"); | ||
} catch (Exception $e) { | ||
curl_close($ch); | ||
AeriaDebug::exception($e); | ||
static::$errors[] = $e->getMessage(); | ||
return null; | ||
} | ||
|
||
curl_close($ch); | ||
return $content; | ||
} | ||
|
||
public static function json() | ||
{ | ||
$response = forward_static_call_array(['static','send'], func_get_args()); | ||
$json = json_decode($response); | ||
if (json_last_error() || empty($json)) return null; | ||
return $json; | ||
} | ||
|
||
public static function jsonp() | ||
{ | ||
$response = forward_static_call_array(['static','send'], func_get_args()); | ||
$response = str_replace('cb({', '{', $response); | ||
$response = str_replace('})','}', $response); | ||
$json = json_decode($response); | ||
if (json_last_error() || empty($json)) return null; | ||
return $json; | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.