| @@ -13,13 +13,8 @@ | ||
| 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... |
| @@ -34,8 +29,12 @@ | ||
| 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... |
| @@ -67,21 +66,30 @@ | ||
| 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 | } |
| @@ -92,10 +100,10 @@ | ||
| 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 | /** |
| @@ -100,11 +108,45 @@ | ||
| 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 | 152 | * Get list of all cached licenses that has |
| @@ -128,18 +170,35 @@ | ||
| 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... |