PluginProbe
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager / 10
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager v10
10.56 1.2.1 10 10.1 10.2 10.3 10.31 10.32 10.33 10.34 10.50 10.51 10.52 10.53 10.55 9.0 9.0.1 9.4 trunk 1.0.0 1.1 1.2
easy-code-manager / models / setup.php

setup.php in FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager 10, at models/setup.php

327 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 /**
10 *
11 */
12 class CJTSetupModel {
13
14 /**
15 *
16 */
17 const LICENSES_CACHE = 'cache.CJTSetupModel.licenses';
18
19 /**
20 * put your comment there...
21 *
22 * @var mixed
23 */
24 private $xmlDocCache = array();
25
26 /**
27 * put your comment there...
28 *
29 * @var mixed
30 */
31 protected $licenses;
32
33 /**
34 * put your comment there...
35 *
36 */
37 public function __construct() {
38 // Read all cached licenses!
39 $this->licenses = get_option(self::LICENSES_CACHE);
40 // Make sure its array!
41 if (!is_array($this->licenses)) {
42 $this->licenses = array();
43 }
44 }
45
46 /**
47 * put your comment there...
48 *
49 * @param mixed $component
50 * @param mixed $action
51 * @param mixed $state
52 * @param mixed $pluginBase
53 */
54 public function cacheState($component, $action, $state)
55 {
56
57 $cache =& $this->getLicenses();
58
59 // Cache Plugin data!
60 $state['action'] = $action;
61 $state['plugin'] = get_plugin_data(ABSPATH . PLUGINDIR . "/{$component['pluginBase']}", false);
62
63 // Cache object!
64 $cache[$component['name']] = $state;
65 update_option(self::LICENSES_CACHE, $cache);
66
67 $this->licenses = $cache;
68
69 return $action;
70 }
71
72 /**
73 * put your comment there...
74 *
75 * @param mixed $action
76 * @param mixed $component
77 * @param mixed $license
78 * @param mixed $attrs
79 */
80 public function dispatchLicenseAction($action, $component, $license, $attrs)
81 {
82
83 # Get Plugin File from component base name
84 $pluginFile = WP_PLUGIN_DIR . $component['pluginBase'];
85
86 # Get CJT Store object
87 $store = new CJTStore(
88 cssJSToolbox::getInstance()->getServiesClientAPI(),
89 $component['name'],
90 $license['key'],
91 $attrs,
92 $pluginFile
93 );
94
95 # Build method name from the given action
96 $methodName = "{$action}License";
97
98 try
99 {
100
101 # Call requested method
102 $result = $store->$methodName($license['name']);
103
104 # Build response object locally
105
106 # The structure is implemented as EDD license extension API call returns
107 # CJT orignally intergrated with EDD but now its use thier own store API
108 # So we will still return comptaible structure for UI elemenets to act the same
109
110 if ($result) // Success operation
111 {
112 $response['license'] = 'valid';
113 }
114 else // Operation faild
115 {
116 $response['license'] = 'invalid';
117 }
118
119 }
120 catch (CJTServicesAPICallException $exception)
121 {
122
123 // If request error compaitble the response object to be used!
124 $response = array
125 (
126 'license' => 'error',
127 'component' => $component['name']
128 );
129
130 }
131
132 return $response;
133 }
134
135 /**
136 * put your comment there...
137 *
138 */
139 public function getCJTComponentData()
140 {
141
142 $component = array();
143
144 // Set info!
145 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
146 $component['title'] = 'CSS & Javascript Toolbox';
147
148 return $component;
149 }
150
151 /**
152 * put your comment there...
153 *
154 * @param mixed $pluginBase
155 */
156 public function & getExtXML($pluginBase)
157 {
158
159 // Get cache of instantiate new
160 if (isset($this->xmlDocCache[$pluginBase]))
161 {
162 return $this->xmlDocCache[$pluginBase];
163 }
164
165 $pluginDirName = dirname($pluginBase);
166 $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
167 $pluginDirName . DIRECTORY_SEPARATOR .
168 $pluginDirName . '.xml';
169
170 # Use XML
171 $exDef = new SimpleXMLElement(file_get_contents($pluginXMLFile));
172
173 # Register XPath namespace
174 $license = $exDef->license;
175 $license->registerXPathNamespace('ext', 'https://css-javascript-toolbox.com/extensions/xmldeffile');
176
177 // Cache it!
178 $this->xmlDocCache[$pluginBase] = $exDef;
179
180 return $exDef;
181 }
182
183 /**
184 * put your comment there...
185 *
186 * @param mixed $component
187 */
188 public function getExtensionProductTypes($component)
189 {
190
191 $types = array();
192
193 # Extension plugin file
194 $exDef =& $this->getExtXML($component['pluginBase']);
195 $license = $exDef->license;
196
197 # Get types
198 $typesSrc = $license->xpath('name');
199
200 foreach ($typesSrc as $type)
201 {
202
203 # Add to list
204 $types[$name] = array
205 (
206 'name' => (string) $type->attributes()->identifier,
207 'text' => (string) $type->attributes()->text,
208 );
209 }
210
211 return $types;
212 }
213
214 /**
215 * put your comment there...
216 *
217 */
218 public function & getLicenses() {
219 return $this->licenses;
220 }
221
222 /**
223 * put your comment there...
224 *
225 * @param mixed $component
226 */
227 public function getProductTypeAttrs($component)
228 {
229
230 $attrs = '';
231
232 $xmlDoc = $this->getExtXML($component['pluginBase']);
233 $license = $xmlDoc->license;
234
235 foreach ($license->xpath('name') as $item)
236 {
237
238 $identifier = (string) $item->attributes()->identifier;
239
240 // Found name to match componenent name
241 if ($component['name'] == $identifier)
242 {
243
244 $attrs = (string) $item->attributes()->attrs;
245
246 break;
247 }
248
249 }
250
251 return $attrs;
252 }
253
254 /**
255 * Get list of all cached licenses that has
256 * a license key in $state state!
257 *
258 * @param mixed $state
259 */
260 public function getStatedLicenses($state = 'activate') {
261 // Initializing!
262 $statedList = array();
263 // Read all cached licenses!
264 $cacheList =& $this->getLicenses();
265 // Find license with the requested state!
266 foreach ($cacheList as $key => $license) {
267 if ($license['action'] == $state) {
268 $statedList[$key] = $license;
269 }
270 }
271 return $statedList;
272 }
273
274 /**
275 * put your comment there...
276 *
277 * @param mixed $licenseTypes
278 * @param mixed $compoment
279 * @param mixed $struct
280 */
281 public function getStateStruct($licenseTypes, $struct = null) {
282 // INit
283 $state = null;
284 // Read all licenses from db!
285 $licensesCache =& $this->getLicenses();
286 // Find license
287 foreach ($licenseTypes as $type) {
288 # Get product name to search
289 $productName = $type['name'];
290 if (isset($licensesCache[$productName])) {
291 # Get product state
292 $state = $licensesCache[$productName];
293 # Filter to section
294 if ($struct) {
295 $state = $state[$struct];
296 }
297 # ALways push product name
298 $state['productName'] = $productName;
299 # Exit for
300 break;
301 }
302 }
303 return $state;
304 }
305
306 /**
307 * put your comment there...
308 *
309 * @param mixed $state
310 */
311 public function removeCachedLicense($state) {
312 // Initializing!
313 $componentName = $state['component']['name'];
314 // Read all cached licenses!
315 $cachedStates =& $this->getLicenses();
316 // Set return value!
317 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
318 // Remove component license even if its not exists, nothing will happen!
319 unset($cachedStates[$componentName]);
320 // Update cache list!
321 update_option(self::LICENSES_CACHE, $cachedStates);
322 // Update local cache!
323 $this->licenses = $cachedStates;
324 return $result;
325 }
326
327 } // End class.