コード例 #1
0
ファイル: AeriaSocial.php プロジェクト: caffeinalab/aeria
 public static function init($config = [])
 {
     static::$config = array_merge(static::$config, $config);
     // Added possibility to use outside of Wordpress
     if (defined('ABSPATH')) {
         // Install CSS + JS
         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');
         if (isset(static::$config['apiurl'])) {
             wp_localize_script('aeria.social', 'AERIA_SOCIAL', ['URL' => static::$config['apiurl']]);
         }
         // Install AJAX handler
         AeriaAJAX::register('aeriasocial.get', function () {
             if (!isset($_REQUEST['uri'])) {
                 echo json_encode(['error' => 'Please provide a URI']);
                 exit(1);
             }
             echo json_encode(AeriaSocial::getCount($_REQUEST['uri']));
             exit;
         });
     }
 }
コード例 #2
0
ファイル: AeriaAJAX.php プロジェクト: caffeinalab/aeria
    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]);