PluginProbe
CSS & JavaScript Toolbox / 8.0
CSS & JavaScript Toolbox v8.0
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | models/setup.php +46 -55 108.0 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 -*
3 +*
4 4 */
5 5
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
@@ -6,27 +6,27 @@
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
8 8
9 9 /**
10 -*
10 +*
11 11 */
12 12 class CJTSetupModel {
13 -
13 +
14 14 /**
15 - *
15 + *
16 16 */
17 17 const LICENSES_CACHE = 'cache.CJTSetupModel.licenses';
18 18
19 19 /**
20 20 * put your comment there...
21 - *
21 + *
22 22 * @var mixed
23 23 */
24 24 protected $licenses;
25 -
25 +
26 26 /**
27 27 * put your comment there...
28 - *
28 + *
29 29 */
30 30 public function __construct() {
31 31 // Read all cached licenses!
32 32 $this->licenses = get_option(self::LICENSES_CACHE);
@@ -34,12 +34,12 @@
34 34 if (!is_array($this->licenses)) {
35 35 $this->licenses = array();
36 36 }
37 37 }
38 -
38 +
39 39 /**
40 40 * put your comment there...
41 - *
41 + *
42 42 * @param mixed $component
43 43 * @param mixed $action
44 44 * @param mixed $state
45 45 * @param mixed $pluginBase
@@ -56,75 +56,66 @@
56 56 update_option(self::LICENSES_CACHE, $cache);
57 57 // update local Cache!
58 58 $this->licenses = $cache;
59 59 // return action name
60 - return $action;
60 + return $action;
61 61 }
62 -
62 +
63 63 /**
64 64 * put your comment there...
65 - *
65 + *
66 66 * @param mixed $action
67 67 * @param mixed $component
68 68 * @param mixed $license
69 69 */
70 - public function dispatchLicenseAction($action, $component, $license) {
71 - # Get Plugin File from component base name
72 - $pluginFile = WP_PLUGIN_DIR . $component[ 'pluginBase' ];
73 - # Get CJT Store object
74 - $store = new CJTStore( $component [ 'name' ], $license[ 'key' ], $pluginFile );
75 - # Build method name from the given action
76 - $methodName = "{$action}License";
77 - try {
78 - # Call requested method
79 - $result = $store->$methodName( $license[ 'name' ] );
80 - # Build response object locally
81 - # The structure is taken from EDD license extension as it was used here
82 - # when the plugin is orignally developed
83 - if ( $result ) { // Success operation
84 - $response['license'] = 'valid';
85 - }
86 - else { // Operation faild
87 - $response['license'] = 'invalid';
88 - }
89 - }
90 - catch ( CJTServicesAPICallException $exception ) {
91 - // If request error compaitble the response object to be used!
70 + public function dispatchEddCall($action, $component, $license) {
71 + // Activating License key thorugh EDD APIs!
72 + $request['edd_action'] = "{$action}_license";
73 + $request['item_name'] = urlencode($component['name']);
74 + $request['license'] = $license['key'];
75 + /* CJT Extra Fields For EDD */
76 + //$request['CJTEFFEDD_licenseName'] = $license['name'];
77 + // Request the server!
78 + $response = wp_remote_get(add_query_arg($request, cssJSToolbox::getCJTWebSiteURL()));
79 + // We need only the JSON object returned by EDD APIs.
80 + $response = @json_decode(wp_remote_retrieve_body($response), true);
81 + // If request error compaitble the response object to be used!
82 + if (!$response) {
92 83 $response = array('license' => 'error', 'component' => $component['name']);
93 84 }
94 85 return $response;
95 86 }
96 -
87 +
97 88 /**
98 89 * put your comment there...
99 - *
90 + *
100 91 */
101 92 public function getCJTComponentData() {
102 93 $component = array();
103 94 // Set info!
104 95 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
105 - $component['title'] = 'CSS & JavaScript Toolbox';
96 + $component['title'] = 'CSS & Javascript Toolbox';
106 97 return $component;
107 98 }
108 -
99 +
109 100 /**
110 101 * put your comment there...
111 - *
102 + *
112 103 * @param mixed $component
113 104 */
114 105 public function getExtensionProductTypes($component) {
115 - # Initialize
106 + # Initialize
116 107 $types = array();
117 108 # Extension plugin file
118 109 $pluginDirName = dirname($component['pluginBase']);
119 - $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
120 - $pluginDirName . DIRECTORY_SEPARATOR .
110 + $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
111 + $pluginDirName . DIRECTORY_SEPARATOR .
121 112 $pluginDirName . '.xml';
122 113 # Use XML
123 114 $exDef = new SimpleXMLElement(file_get_contents($pluginXMLFile));
124 115 # Register XPath namespace
125 116 $license = $exDef->license;
126 - $license->registerXPathNamespace('ext', 'https://css-javascript-toolbox.com/extensions/xmldeffile');
117 + $license->registerXPathNamespace('ext', 'http://css-javascript-toolbox.com/extensions/xmldeffile');
127 118 # Get types
128 119 $typesSrc = $exDef->license->xpath('name');
129 120 foreach ($typesSrc as $type) {
130 121 # Product name
@@ -141,18 +132,18 @@
141 132 }
142 133
143 134 /**
144 135 * put your comment there...
145 - *
136 + *
146 137 */
147 138 public function & getLicenses() {
148 139 return $this->licenses;
149 140 }
150 -
141 +
151 142 /**
152 - * Get list of all cached licenses that has
143 + * Get list of all cached licenses that has
153 144 * a license key in $state state!
154 - *
145 + *
155 146 * @param mixed $state
156 147 */
157 148 public function getStatedLicenses($state = 'activate') {
158 149 // Initializing!
@@ -166,22 +157,22 @@
166 157 }
167 158 }
168 159 return $statedList;
169 160 }
170 -
161 +
171 162 /**
172 163 * put your comment there...
173 - *
164 + *
174 165 * @param mixed $licenseTypes
175 166 * @param mixed $compoment
176 167 * @param mixed $struct
177 168 */
178 169 public function getStateStruct($licenseTypes, $struct = null) {
179 - // INit
170 + // INit
180 171 $state = null;
181 172 // Read all licenses from db!
182 173 $licensesCache =& $this->getLicenses();
183 - // Find license
174 + // Find license
184 175 foreach ($licenseTypes as $type) {
185 176 # Get product name to search
186 177 $productName = $type['name'];
187 178 if (isset($licensesCache[$productName])) {
@@ -198,12 +189,12 @@
198 189 }
199 190 }
200 191 return $state;
201 192 }
202 -
193 +
203 194 /**
204 195 * put your comment there...
205 - *
196 + *
206 197 * @param mixed $state
207 198 */
208 199 public function removeCachedLicense($state) {
209 200 // Initializing!
@@ -211,9 +202,9 @@
211 202 // Read all cached licenses!
212 203 $cachedStates =& $this->getLicenses();
213 204 // Set return value!
214 205 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
215 - // Remove component license even if its not exists, nothing will happen!
206 + // Remove component license even if its not exists, nothing will happen!
216 207 unset($cachedStates[$componentName]);
217 208 // Update cache list!
218 209 update_option(self::LICENSES_CACHE, $cachedStates);
219 210 // Update local cache!
@@ -219,6 +210,6 @@
219 210 // Update local cache!
220 211 $this->licenses = $cachedStates;
221 212 return $result;
222 213 }
223 -
214 +
224 215 } // End class.