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
css-javascript-toolbox / models / setup.php

setup.php in CSS & JavaScript Toolbox 8.0, at models/setup.php

215 lines 5.2 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 protected $licenses;
25
26 /**
27 * put your comment there...
28 *
29 */
30 public function __construct() {
31 // Read all cached licenses!
32 $this->licenses = get_option(self::LICENSES_CACHE);
33 // Make sure its array!
34 if (!is_array($this->licenses)) {
35 $this->licenses = array();
36 }
37 }
38
39 /**
40 * put your comment there...
41 *
42 * @param mixed $component
43 * @param mixed $action
44 * @param mixed $state
45 * @param mixed $pluginBase
46 */
47 public function cacheState($component, $action, $state) {
48 // Read cache from db!
49 $cache =& $this->getLicenses();
50 // Add action to the state object!
51 $state['action'] = $action;
52 // Cache Plugin data!
53 $state['plugin'] = get_plugin_data(ABSPATH . PLUGINDIR . "/{$component['pluginBase']}", false);
54 // Cache object!
55 $cache[$component['name']] = $state;
56 update_option(self::LICENSES_CACHE, $cache);
57 // update local Cache!
58 $this->licenses = $cache;
59 // return action name
60 return $action;
61 }
62
63 /**
64 * put your comment there...
65 *
66 * @param mixed $action
67 * @param mixed $component
68 * @param mixed $license
69 */
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) {
83 $response = array('license' => 'error', 'component' => $component['name']);
84 }
85 return $response;
86 }
87
88 /**
89 * put your comment there...
90 *
91 */
92 public function getCJTComponentData() {
93 $component = array();
94 // Set info!
95 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
96 $component['title'] = 'CSS & Javascript Toolbox';
97 return $component;
98 }
99
100 /**
101 * put your comment there...
102 *
103 * @param mixed $component
104 */
105 public function getExtensionProductTypes($component) {
106 # Initialize
107 $types = array();
108 # Extension plugin file
109 $pluginDirName = dirname($component['pluginBase']);
110 $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
111 $pluginDirName . DIRECTORY_SEPARATOR .
112 $pluginDirName . '.xml';
113 # Use XML
114 $exDef = new SimpleXMLElement(file_get_contents($pluginXMLFile));
115 # Register XPath namespace
116 $license = $exDef->license;
117 $license->registerXPathNamespace('ext', 'http://css-javascript-toolbox.com/extensions/xmldeffile');
118 # Get types
119 $typesSrc = $exDef->license->xpath('name');
120 foreach ($typesSrc as $type) {
121 # Product name
122 $name = (string) $type;
123 # Old Definiton document doesnt support text attributes.
124 # If not there use name node value as TEXT
125 if (!$text = ((string) $type->attributes()->text)) {
126 $text = $name;
127 }
128 # Add to list
129 $types[$name] = array('name' => $name, 'text' => $text);
130 }
131 return $types;
132 }
133
134 /**
135 * put your comment there...
136 *
137 */
138 public function & getLicenses() {
139 return $this->licenses;
140 }
141
142 /**
143 * Get list of all cached licenses that has
144 * a license key in $state state!
145 *
146 * @param mixed $state
147 */
148 public function getStatedLicenses($state = 'activate') {
149 // Initializing!
150 $statedList = array();
151 // Read all cached licenses!
152 $cacheList =& $this->getLicenses();
153 // Find license with the requested state!
154 foreach ($cacheList as $key => $license) {
155 if ($license['action'] == $state) {
156 $statedList[$key] = $license;
157 }
158 }
159 return $statedList;
160 }
161
162 /**
163 * put your comment there...
164 *
165 * @param mixed $licenseTypes
166 * @param mixed $compoment
167 * @param mixed $struct
168 */
169 public function getStateStruct($licenseTypes, $struct = null) {
170 // INit
171 $state = null;
172 // Read all licenses from db!
173 $licensesCache =& $this->getLicenses();
174 // Find license
175 foreach ($licenseTypes as $type) {
176 # Get product name to search
177 $productName = $type['name'];
178 if (isset($licensesCache[$productName])) {
179 # Get product state
180 $state = $licensesCache[$productName];
181 # Filter to section
182 if ($struct) {
183 $state = $state[$struct];
184 }
185 # ALways push product name
186 $state['productName'] = $productName;
187 # Exit for
188 break;
189 }
190 }
191 return $state;
192 }
193
194 /**
195 * put your comment there...
196 *
197 * @param mixed $state
198 */
199 public function removeCachedLicense($state) {
200 // Initializing!
201 $componentName = $state['component']['name'];
202 // Read all cached licenses!
203 $cachedStates =& $this->getLicenses();
204 // Set return value!
205 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
206 // Remove component license even if its not exists, nothing will happen!
207 unset($cachedStates[$componentName]);
208 // Update cache list!
209 update_option(self::LICENSES_CACHE, $cachedStates);
210 // Update local cache!
211 $this->licenses = $cachedStates;
212 return $result;
213 }
214
215 } // End class.