PluginProbe
CSS & JavaScript Toolbox / 6.1
CSS & JavaScript Toolbox v6.1
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 -106 trunk6.1 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,32 @@
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 Pro';
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);
@@ -34,12 +39,12 @@
34 39 if (!is_array($this->licenses)) {
35 40 $this->licenses = array();
36 41 }
37 42 }
38 -
43 +
39 44 /**
40 45 * put your comment there...
41 - *
46 + *
42 47 * @param mixed $component
43 48 * @param mixed $action
44 49 * @param mixed $state
45 50 * @param mixed $pluginBase
@@ -49,9 +54,9 @@
49 54 $cache =& $this->getLicenses();
50 55 // Add action to the state object!
51 56 $state['action'] = $action;
52 57 // Cache Plugin data!
53 - $state['plugin'] = get_plugin_data(WP_PLUGIN_DIR . "/{$component['pluginBase']}", false);
58 + $state['plugin'] = get_plugin_data(ABSPATH . PLUGINDIR . "/{$component['pluginBase']}", false);
54 59 // Cache object!
55 60 $cache[$component['name']] = $state;
56 61 update_option(self::LICENSES_CACHE, $cache);
57 62 // update local Cache!
@@ -56,103 +61,60 @@
56 61 update_option(self::LICENSES_CACHE, $cache);
57 62 // update local Cache!
58 63 $this->licenses = $cache;
59 64 // return action name
60 - return $action;
65 + return $action;
61 66 }
62 -
67 +
63 68 /**
64 69 * put your comment there...
65 - *
70 + *
66 71 * @param mixed $action
67 72 * @param mixed $component
68 73 * @param mixed $license
69 74 */
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!
75 + public function dispatchEddCall($action, $component, $license) {
76 + // Activating License key thorugh EDD APIs!
77 + $request['edd_action'] = "{$action}_license";
78 + $request['item_name'] = urlencode($component['name']);
79 + $request['license'] = $license['key'];
80 + /* CJT Extra Fields For EDD */
81 + $request['CJTEFFEDD_licenseName'] = $license['name'];
82 + // Request the server!
83 + $response = wp_remote_get(add_query_arg($request, cssJSToolbox::getCJTWebSiteURL()));
84 + // We need only the JSON object returned by EDD APIs.
85 + $response = @json_decode(wp_remote_retrieve_body($response), true);
86 + // If request error compaitble the response object to be used!
87 + if (!$response) {
92 88 $response = array('license' => 'error', 'component' => $component['name']);
93 89 }
94 90 return $response;
95 91 }
96 -
92 +
97 93 /**
98 94 * put your comment there...
99 - *
95 + *
100 96 */
101 97 public function getCJTComponentData() {
102 98 $component = array();
103 99 // Set info!
100 + $component['name'] = self::EDD_PRODUCT_NAME;
104 101 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
105 - $component['title'] = 'CSS & JavaScript Toolbox';
106 102 return $component;
107 103 }
108 -
104 +
109 105 /**
110 106 * put your comment there...
111 - *
112 - * @param mixed $component
107 + *
113 108 */
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 109 public function & getLicenses() {
148 110 return $this->licenses;
149 111 }
150 -
112 +
151 113 /**
152 - * Get list of all cached licenses that has
114 + * Get list of all cached licenses that has
153 115 * a license key in $state state!
154 - *
116 + *
155 117 * @param mixed $state
156 118 */
157 119 public function getStatedLicenses($state = 'activate') {
158 120 // Initializing!
@@ -166,44 +128,27 @@
166 128 }
167 129 }
168 130 return $statedList;
169 131 }
170 -
132 +
171 133 /**
172 134 * put your comment there...
173 - *
174 - * @param mixed $licenseTypes
135 + *
175 136 * @param mixed $compoment
176 - * @param mixed $struct
137 + * @param mixed $field
177 138 */
178 - public function getStateStruct($licenseTypes, $struct = null) {
179 - // INit
180 - $state = null;
139 + public function getStateStruct($compoment, $struct = null) {
181 140 // Read all licenses from db!
182 141 $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;
142 + // If not set return clean empty array!
143 + $componentName = $compoment['name'];
144 + $state = isset($licensesCache[$componentName]) ? $licensesCache[$componentName] : false;
145 + return ($struct ? ($state[$struct] ? $state[$struct] : false) : $state);
201 146 }
202 -
147 +
203 148 /**
204 149 * put your comment there...
205 - *
150 + *
206 151 * @param mixed $state
207 152 */
208 153 public function removeCachedLicense($state) {
209 154 // Initializing!
@@ -211,9 +156,9 @@
211 156 // Read all cached licenses!
212 157 $cachedStates =& $this->getLicenses();
213 158 // Set return value!
214 159 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
215 - // Remove component license even if its not exists, nothing will happen!
160 + // Remove component license even if its not exists, nothing will happen!
216 161 unset($cachedStates[$componentName]);
217 162 // Update cache list!
218 163 update_option(self::LICENSES_CACHE, $cachedStates);
219 164 // Update local cache!
@@ -219,6 +164,6 @@
219 164 // Update local cache!
220 165 $this->licenses = $cachedStates;
221 166 return $result;
222 167 }
223 -
168 +
224 169 } // End class.