Skip to content

Commit

Permalink
1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio De Stefano committed Jan 12, 2015
1 parent 7ccd92b commit 6195e8b
Show file tree
Hide file tree
Showing 797 changed files with 17,242 additions and 16 deletions.
2 changes: 1 addition & 1 deletion aeria.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Caffeina Srl
* Author URI: http://caffeina.co
* Plugin URI: https://github.com/CaffeinaLab/aeria
* Version: 1.2.0
* Version: 1.3.0
*/

// Exit if accessed directly
Expand Down
Empty file modified classes/Aeria.php
100755 → 100644
Empty file.
74 changes: 74 additions & 0 deletions classes/AeriaAJAX.php
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));
}

}
164 changes: 164 additions & 0 deletions classes/AeriaCache.php
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 modified classes/AeriaMetabox.php
100755 → 100644
Empty file.
65 changes: 65 additions & 0 deletions classes/AeriaNetwork.php
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 modified classes/AeriaPost.php
100755 → 100644
Empty file.
30 changes: 16 additions & 14 deletions classes/AeriaSocial.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
// Exit if accessed directly.
if( false === defined('AERIA') ) exit;

wp_enqueue_script('aeria.social', AERIA_URL.'resources/js/aeria.social.js', ['jquery']);
wp_enqueue_style('aeria.social', AERIA_URL.'resources/css/aeria.social.css');

AeriaAJAX::register('aeriasocial.get', function(){
if (!isset($_REQUEST['uri'])) {
die(json_encode([ 'error' => 'Please provide a URI' ]));
}

die(json_encode(AeriaSocial::getCount($_REQUEST['uri'])));
});

class AeriaSocial {

public static $services = [];
Expand All @@ -21,18 +32,9 @@ public static function init($config = null) {
if (is_array($config)) static::$config = array_merge(static::$config, $config);
static::$services = array_keys(static::$config['services']);

add_action('wp_enqueue_scripts', function(){
wp_enqueue_script('aeria.social', AERIA_URL.'/scripts/aeria.social.js');
wp_enqueue_style('aeria.social', AERIA_URL.'/resources/css/aeria.social.css');
if (isset(static::$config['apiurl'])) {
echo '<script>window.AERIA_SOCIAL_API_URI = "' . static::$config['apiurl'] . '";</script>';
}
});

AeriaAJAX::register('aeriasocial.get', function(){
if (!isset($_REQUEST['uri'])) die(json_encode([ 'error' => 'Please provide a URI' ]));
die(json_encode(static::getCount($_REQUEST['uri'])));
});
if (isset(static::$config['apiurl'])) {
wp_localize_script('aeria.social', 'AERIA_SOCIAL', [ 'URL' => static::$config['apiurl'] ]);
}
}

public static function widget($uri, $info=[], $opt=[]) {
Expand All @@ -57,7 +59,7 @@ public static function widget($uri, $info=[], $opt=[]) {
if ( ! isset($opt['nocount'])) {
$r .= '<span class="aeriasocial-count"><i></i><u></u>';
$r .= '<span data-aeriasocial-count>';
if (!is_null($stats)) $r .= $parsed_stats['services'][$service];
if (!is_null($stats)) $r .= (string)$stats['services'][$service];
$r .= '</span>';
$r .= '</span>';
}
Expand Down Expand Up @@ -177,4 +179,4 @@ public static function getMostSharedContents() {
return $data;
}

}
}
Empty file modified classes/AeriaTaxonomy.php
100755 → 100644
Empty file.
Empty file modified classes/AeriaType.php
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "http://labs.caffeina.co/tech/aeria",
"download_url": "https://github.com/CaffeinaLab/aeria/archive/master.zip",

"version": "1.2.0",
"version": "1.3.0",
"requires": "3.5",
"tested": "4.0",
"last_updated": "2014-12-05 11:00:00",
Expand Down
Loading

0 comments on commit 6195e8b

Please sign in to comment.