PluginProbe
CSS & JavaScript Toolbox / 9.3
CSS & JavaScript Toolbox v9.3
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 +110 -51 6.09.3 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,41 +6,40 @@
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 - */
22 17 const LICENSES_CACHE = 'cache.CJTSetupModel.licenses';
23 18
24 19 /**
25 20 * put your comment there...
26 - *
21 + *
27 22 * @var mixed
28 23 */
29 24 protected $licenses;
30 -
25 +
31 26 /**
32 27 * put your comment there...
33 - *
28 + *
34 29 */
35 30 public function __construct() {
36 31 // Read all cached licenses!
37 32 $this->licenses = get_option(self::LICENSES_CACHE);
33 + // Make sure its array!
34 + if (!is_array($this->licenses)) {
35 + $this->licenses = array();
36 + }
38 37 }
39 -
38 +
40 39 /**
41 40 * put your comment there...
42 - *
41 + *
43 42 * @param mixed $component
44 43 * @param mixed $action
45 44 * @param mixed $state
46 45 * @param mixed $pluginBase
@@ -57,60 +56,103 @@
57 56 update_option(self::LICENSES_CACHE, $cache);
58 57 // update local Cache!
59 58 $this->licenses = $cache;
60 59 // return action name
61 - return $action;
60 + return $action;
62 61 }
63 -
62 +
64 63 /**
65 64 * put your comment there...
66 - *
65 + *
67 66 * @param mixed $action
68 67 * @param mixed $component
69 68 * @param mixed $license
70 69 */
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) {
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!
84 92 $response = array('license' => 'error', 'component' => $component['name']);
85 93 }
86 94 return $response;
87 95 }
88 -
96 +
89 97 /**
90 98 * put your comment there...
91 - *
99 + *
92 100 */
93 101 public function getCJTComponentData() {
94 102 $component = array();
95 103 // Set info!
96 - $component['name'] = self::EDD_PRODUCT_NAME;
97 104 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
105 + $component['title'] = 'CSS & JavaScript Toolbox';
98 106 return $component;
99 107 }
100 -
108 +
101 109 /**
102 110 * put your comment there...
103 - *
111 + *
112 + * @param mixed $component
104 113 */
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', 'http://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 + */
105 147 public function & getLicenses() {
106 - return $this->licenses ? $this->licenses : array();
148 + return $this->licenses;
107 149 }
108 -
150 +
109 151 /**
110 - * Get list of all cached licenses that has
152 + * Get list of all cached licenses that has
111 153 * a license key in $state state!
112 - *
154 + *
113 155 * @param mixed $state
114 156 */
115 157 public function getStatedLicenses($state = 'activate') {
116 158 // Initializing!
@@ -124,27 +166,44 @@
124 166 }
125 167 }
126 168 return $statedList;
127 169 }
128 -
170 +
129 171 /**
130 172 * put your comment there...
131 - *
173 + *
174 + * @param mixed $licenseTypes
132 175 * @param mixed $compoment
133 - * @param mixed $field
176 + * @param mixed $struct
134 177 */
135 - public function getStateStruct($compoment, $struct = null) {
178 + public function getStateStruct($licenseTypes, $struct = null) {
179 + // INit
180 + $state = null;
136 181 // Read all licenses from db!
137 182 $licensesCache =& $this->getLicenses();
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);
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;
142 201 }
143 -
202 +
144 203 /**
145 204 * put your comment there...
146 - *
205 + *
147 206 * @param mixed $state
148 207 */
149 208 public function removeCachedLicense($state) {
150 209 // Initializing!
@@ -152,9 +211,9 @@
152 211 // Read all cached licenses!
153 212 $cachedStates =& $this->getLicenses();
154 213 // Set return value!
155 214 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
156 - // Remove component license even if its not exists, nothing will happen!
215 + // Remove component license even if its not exists, nothing will happen!
157 216 unset($cachedStates[$componentName]);
158 217 // Update cache list!
159 218 update_option(self::LICENSES_CACHE, $cachedStates);
160 219 // Update local cache!
@@ -160,6 +219,6 @@
160 219 // Update local cache!
161 220 $this->licenses = $cachedStates;
162 221 return $result;
163 222 }
164 -
223 +
165 224 } // End class.