PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / libs / json_api / json_api.php

json_api.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/libs/json_api/json_api.php

85 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AliNext_Lite;;
4
5 if (!defined('A2WL_JSON_API_VERSION')) {
6 define('A2WL_JSON_API_VERSION', "1.0.0");
7 }
8
9 if (!defined('A2WL_JSON_API_DIR')) {
10 define('A2WL_JSON_API_DIR', dirname(__FILE__));
11 }
12
13 @include_once A2WL_JSON_API_DIR . "/singletons/api.php";
14 @include_once A2WL_JSON_API_DIR . "/singletons/query.php";
15 @include_once A2WL_JSON_API_DIR . "/singletons/response.php";
16
17 if (!class_exists('Json_Api_Configurator')) {
18 class Json_Api_Configurator {
19
20 private string $root_menu_slug;
21
22 private function __construct() { }
23
24 public static function init($root_menu_slug) {
25 $configurator = new Json_Api_Configurator();
26 $configurator->root_menu_slug = $root_menu_slug;
27
28 add_action('init', array($configurator, 'json_api_init'));
29
30 add_action('a2wl_install', array($configurator, 'activation'));
31 add_action('a2wl_uninstall', array($configurator, 'deactivation'));
32 }
33
34 public function activation() {
35 // Add the rewrite rule on activation
36 global $wp_rewrite;
37 add_filter('rewrite_rules_array', array(new Json_Api_Configurator(),'json_api_rewrites'));
38 $wp_rewrite->flush_rules();
39 }
40
41 public function deactivation() {
42 // Remove the rewrite rule on deactivation
43 global $wp_rewrite;
44 $wp_rewrite->flush_rules();
45 }
46
47 function json_api_init() {
48
49 global $a2wl_json_api;
50 if (phpversion() < 5) {
51 add_action('admin_notices', array($this, 'json_api_php_version_warning'));
52 return;
53 }
54 if (!class_exists('AliNext_Lite\JSON_API')) {
55 add_action('admin_notices', array($this, 'json_api_class_warning'));
56 return;
57 }
58
59 add_filter('rewrite_rules_array', array($this, 'json_api_rewrites'));
60
61 $a2wl_json_api = new JSON_API(empty($this->root_menu_slug)?'':$this->root_menu_slug);
62 }
63
64 function json_api_rewrites($wp_rules) {
65 $base = get_setting('json_api_base');
66 if (empty($base)) {
67 return $wp_rules;
68 }
69 $json_api_rules = array(
70 "$base\$" => 'index.php?a2w-json=info',
71 "$base/(.+)\$" => 'index.php?a2w-json=$matches[1]'
72 );
73 return array_merge($json_api_rules, $wp_rules);
74 }
75
76 function json_api_php_version_warning() {
77 echo "<div id=\"json-api-warning\" class=\"updated fade\"><p>Sorry, JSON API requires PHP version 5.0 or greater.</p></div>";
78 }
79
80 function json_api_class_warning() {
81 echo "<div id=\"json-api-warning\" class=\"updated fade\"><p>Oops, JSON_API class not found. If you've defined a A2WL_JSON_API_DIR constant, double check that the path is correct.</p></div>";
82 }
83
84 }
85 }