PluginProbe
CSS & JavaScript Toolbox / 6.0
CSS & JavaScript Toolbox v6.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 +51 -110 116.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,40 +6,41 @@
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 + const EDD_PRODUCT_NAME = 'CJT V6';
18 +
19 + /**
20 + *
21 + */
17 22 const LICENSES_CACHE = 'cache.CJTSetupModel.licenses';
18 23
19 24 /**
20 25 * put your comment there...
21 - *
26 + *
22 27 * @var mixed
23 28 */
24 29 protected $licenses;
25 -
30 +
26 31 /**
27 32 * put your comment there...
28 - *
33 + *
29 34 */
30 35 public function __construct() {
31 36 // Read all cached licenses!
32 37 $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 }
38 -
39 +
39 40 /**
40 41 * put your comment there...
41 - *
42 + *
42 43 * @param mixed $component
43 44 * @param mixed $action
44 45 * @param mixed $state
45 46 * @param mixed $pluginBase
@@ -56,103 +57,60 @@
56 57 update_option(self::LICENSES_CACHE, $cache);
57 58 // update local Cache!
58 59 $this->licenses = $cache;
59 60 // return action name
60 - return $action;
61 + return $action;
61 62 }
62 -
63 +
63 64 /**
64 65 * put your comment there...
65 - *
66 + *
66 67 * @param mixed $action
67 68 * @param mixed $component
68 69 * @param mixed $license
69 70 */
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!
71 + public function dispatchEddCall($action, $component, $license) {
72 + // Activating License key thorugh EDD APIs!
73 + $request['edd_action'] = "{$action}_license";
74 + $request['item_name'] = urlencode($component['name']);
75 + $request['license'] = $license['key'];
76 + /* CJT Extra Fields For EDD */
77 + $request['CJTEFFEDD_licenseName'] = $license['name'];
78 + // Request the server!
79 + $response = wp_remote_get(add_query_arg($request, cssJSToolbox::getCJTWebSiteURL()));
80 + // We need only the JSON object returned by EDD APIs.
81 + $response = @json_decode(wp_remote_retrieve_body($response), true);
82 + // If request error compaitble the response object to be used!
83 + if (!$response) {
92 84 $response = array('license' => 'error', 'component' => $component['name']);
93 85 }
94 86 return $response;
95 87 }
96 -
88 +
97 89 /**
98 90 * put your comment there...
99 - *
91 + *
100 92 */
101 93 public function getCJTComponentData() {
102 94 $component = array();
103 95 // Set info!
96 + $component['name'] = self::EDD_PRODUCT_NAME;
104 97 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
105 - $component['title'] = 'CSS & JavaScript Toolbox';
106 98 return $component;
107 99 }
108 -
100 +
109 101 /**
110 102 * put your comment there...
111 - *
112 - * @param mixed $component
103 + *
113 104 */
114 - public function getExtensionProductTypes($component) {
115 - # Initialize
116 - $types = array();
117 - # Extension plugin file
118 - $pluginDirName = dirname($component['pluginBase']);
119 - $pluginXMLFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
120 - $pluginDirName . DIRECTORY_SEPARATOR .
121 - $pluginDirName . '.xml';
122 - # Use XML
123 - $exDef = new SimpleXMLElement(file_get_contents($pluginXMLFile));
124 - # Register XPath namespace
125 - $license = $exDef->license;
126 - $license->registerXPathNamespace('ext', 'https://css-javascript-toolbox.com/extensions/xmldeffile');
127 - # Get types
128 - $typesSrc = $exDef->license->xpath('name');
129 - foreach ($typesSrc as $type) {
130 - # Product name
131 - $name = (string) $type;
132 - # Old Definiton document doesnt support text attributes.
133 - # If not there use name node value as TEXT
134 - if (!$text = ((string) $type->attributes()->text)) {
135 - $text = $name;
136 - }
137 - # Add to list
138 - $types[$name] = array('name' => $name, 'text' => $text);
139 - }
140 - return $types;
141 - }
142 -
143 - /**
144 - * put your comment there...
145 - *
146 - */
147 105 public function & getLicenses() {
148 - return $this->licenses;
106 + return $this->licenses ? $this->licenses : array();
149 107 }
150 -
108 +
151 109 /**
152 - * Get list of all cached licenses that has
110 + * Get list of all cached licenses that has
153 111 * a license key in $state state!
154 - *
112 + *
155 113 * @param mixed $state
156 114 */
157 115 public function getStatedLicenses($state = 'activate') {
158 116 // Initializing!
@@ -166,44 +124,27 @@
166 124 }
167 125 }
168 126 return $statedList;
169 127 }
170 -
128 +
171 129 /**
172 130 * put your comment there...
173 - *
174 - * @param mixed $licenseTypes
131 + *
175 132 * @param mixed $compoment
176 - * @param mixed $struct
133 + * @param mixed $field
177 134 */
178 - public function getStateStruct($licenseTypes, $struct = null) {
179 - // INit
180 - $state = null;
135 + public function getStateStruct($compoment, $struct = null) {
181 136 // Read all licenses from db!
182 137 $licensesCache =& $this->getLicenses();
183 - // Find license
184 - foreach ($licenseTypes as $type) {
185 - # Get product name to search
186 - $productName = $type['name'];
187 - if (isset($licensesCache[$productName])) {
188 - # Get product state
189 - $state = $licensesCache[$productName];
190 - # Filter to section
191 - if ($struct) {
192 - $state = $state[$struct];
193 - }
194 - # ALways push product name
195 - $state['productName'] = $productName;
196 - # Exit for
197 - break;
198 - }
199 - }
200 - return $state;
138 + // If not set return clean empty array!
139 + $componentName = $compoment['name'];
140 + $state = isset($licensesCache[$componentName]) ? $licensesCache[$componentName] : false;
141 + return ($struct ? ($state[$struct] ? $state[$struct] : false) : $state);
201 142 }
202 -
143 +
203 144 /**
204 145 * put your comment there...
205 - *
146 + *
206 147 * @param mixed $state
207 148 */
208 149 public function removeCachedLicense($state) {
209 150 // Initializing!
@@ -211,9 +152,9 @@
211 152 // Read all cached licenses!
212 153 $cachedStates =& $this->getLicenses();
213 154 // Set return value!
214 155 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
215 - // Remove component license even if its not exists, nothing will happen!
156 + // Remove component license even if its not exists, nothing will happen!
216 157 unset($cachedStates[$componentName]);
217 158 // Update cache list!
218 159 update_option(self::LICENSES_CACHE, $cachedStates);
219 160 // Update local cache!
@@ -219,6 +160,6 @@
219 160 // Update local cache!
220 161 $this->licenses = $cachedStates;
221 162 return $result;
222 163 }
223 -
164 +
224 165 } // End class.