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

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

165 lines 3.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 EDD_PRODUCT_NAME = 'CJT V6';
18
19 /**
20 *
21 */
22 const LICENSES_CACHE = 'cache.CJTSetupModel.licenses';
23
24 /**
25 * put your comment there...
26 *
27 * @var mixed
28 */
29 protected $licenses;
30
31 /**
32 * put your comment there...
33 *
34 */
35 public function __construct() {
36 // Read all cached licenses!
37 $this->licenses = get_option(self::LICENSES_CACHE);
38 }
39
40 /**
41 * put your comment there...
42 *
43 * @param mixed $component
44 * @param mixed $action
45 * @param mixed $state
46 * @param mixed $pluginBase
47 */
48 public function cacheState($component, $action, $state) {
49 // Read cache from db!
50 $cache =& $this->getLicenses();
51 // Add action to the state object!
52 $state['action'] = $action;
53 // Cache Plugin data!
54 $state['plugin'] = get_plugin_data(ABSPATH . PLUGINDIR . "/{$component['pluginBase']}", false);
55 // Cache object!
56 $cache[$component['name']] = $state;
57 update_option(self::LICENSES_CACHE, $cache);
58 // update local Cache!
59 $this->licenses = $cache;
60 // return action name
61 return $action;
62 }
63
64 /**
65 * put your comment there...
66 *
67 * @param mixed $action
68 * @param mixed $component
69 * @param mixed $license
70 */
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) {
84 $response = array('license' => 'error', 'component' => $component['name']);
85 }
86 return $response;
87 }
88
89 /**
90 * put your comment there...
91 *
92 */
93 public function getCJTComponentData() {
94 $component = array();
95 // Set info!
96 $component['name'] = self::EDD_PRODUCT_NAME;
97 $component['pluginBase'] = CJTOOLBOX_PLUGIN_BASE;
98 return $component;
99 }
100
101 /**
102 * put your comment there...
103 *
104 */
105 public function & getLicenses() {
106 return $this->licenses ? $this->licenses : array();
107 }
108
109 /**
110 * Get list of all cached licenses that has
111 * a license key in $state state!
112 *
113 * @param mixed $state
114 */
115 public function getStatedLicenses($state = 'activate') {
116 // Initializing!
117 $statedList = array();
118 // Read all cached licenses!
119 $cacheList =& $this->getLicenses();
120 // Find license with the requested state!
121 foreach ($cacheList as $key => $license) {
122 if ($license['action'] == $state) {
123 $statedList[$key] = $license;
124 }
125 }
126 return $statedList;
127 }
128
129 /**
130 * put your comment there...
131 *
132 * @param mixed $compoment
133 * @param mixed $field
134 */
135 public function getStateStruct($compoment, $struct = null) {
136 // Read all licenses from db!
137 $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);
142 }
143
144 /**
145 * put your comment there...
146 *
147 * @param mixed $state
148 */
149 public function removeCachedLicense($state) {
150 // Initializing!
151 $componentName = $state['component']['name'];
152 // Read all cached licenses!
153 $cachedStates =& $this->getLicenses();
154 // Set return value!
155 $result = isset($cachedStates[$componentName]) ? 'valid' : 'invalid';
156 // Remove component license even if its not exists, nothing will happen!
157 unset($cachedStates[$componentName]);
158 // Update cache list!
159 update_option(self::LICENSES_CACHE, $cachedStates);
160 // Update local cache!
161 $this->licenses = $cachedStates;
162 return $result;
163 }
164
165 } // End class.