| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTStore extends CJTServicesClientModule |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* put your comment there... |
| 14 |
* |
| 15 |
* @var mixed |
| 16 |
*/ |
| 17 |
private $attrs; |
| 18 |
|
| 19 |
/** |
| 20 |
* put your comment there... |
| 21 |
* |
| 22 |
* @var mixed |
| 23 |
*/ |
| 24 |
private $baseName; |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @var mixed |
| 30 |
*/ |
| 31 |
private $itemName; |
| 32 |
|
| 33 |
/** |
| 34 |
* put your comment there... |
| 35 |
* |
| 36 |
* @var mixed |
| 37 |
*/ |
| 38 |
private $license; |
| 39 |
|
| 40 |
/** |
| 41 |
* put your comment there... |
| 42 |
* |
| 43 |
* @var mixed |
| 44 |
*/ |
| 45 |
private $pluginFile; |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
* @var mixed |
| 51 |
*/ |
| 52 |
private $slug; |
| 53 |
|
| 54 |
/** |
| 55 |
* put your comment there... |
| 56 |
* |
| 57 |
* @param mixed $servicesClient |
| 58 |
* @param mixed $itemName |
| 59 |
* @param mixed $license |
| 60 |
* @param mixed $attrs |
| 61 |
* @param mixed $pluginFile |
| 62 |
* @return CJTStore |
| 63 |
*/ |
| 64 |
public function __construct($servicesClient, |
| 65 |
$itemName, |
| 66 |
$license, |
| 67 |
$attrs, |
| 68 |
$pluginFile) |
| 69 |
{ |
| 70 |
|
| 71 |
# Initialize module base class |
| 72 |
parent::__construct($servicesClient); |
| 73 |
|
| 74 |
# Initialize |
| 75 |
$this->pluginFile = $pluginFile; |
| 76 |
$this->baseName = plugin_basename($pluginFile); |
| 77 |
$this->slug = basename($this->baseName, '.php'); |
| 78 |
$this->license = $license; |
| 79 |
$this->attrs = $attrs; |
| 80 |
$this->itemName = $itemName; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* put your comment there... |
| 86 |
* |
| 87 |
* @param mixed $ownerName |
| 88 |
* @return mixed |
| 89 |
*/ |
| 90 |
public function activateLicense($ownerName) |
| 91 |
{ |
| 92 |
return (int) $this->makeCall(__FUNCTION__, compact('ownerName'))->getResponseData(); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
* @param mixed $ownerName |
| 99 |
* @return mixed |
| 100 |
*/ |
| 101 |
public function checkLicense($ownerName) |
| 102 |
{ |
| 103 |
return (int) $this->makeCall(__FUNCTION__, compact('ownerName'))->getResponseData(); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* put your comment there... |
| 108 |
* |
| 109 |
* @param mixed $ownerName |
| 110 |
* @return mixed |
| 111 |
*/ |
| 112 |
public function deactivateLicense($ownerName) |
| 113 |
{ |
| 114 |
return (int) $this->makeCall(__FUNCTION__, compact('ownerName'))->getResponseData(); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* put your comment there... |
| 119 |
* |
| 120 |
*/ |
| 121 |
public function getAttrs() |
| 122 |
{ |
| 123 |
return $this->attrs; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* put your comment there... |
| 128 |
* |
| 129 |
*/ |
| 130 |
public function getBaseName() |
| 131 |
{ |
| 132 |
return $this->baseName; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* put your comment there... |
| 137 |
* |
| 138 |
*/ |
| 139 |
public function getItemName() |
| 140 |
{ |
| 141 |
return $this->itemName; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* put your comment there... |
| 146 |
* |
| 147 |
*/ |
| 148 |
public function getPluginInformation() |
| 149 |
{ |
| 150 |
# Check if there is update available for current extension |
| 151 |
$info = $this->jsonDecode($this->makeCall(__FUNCTION__)->getResponseData()); |
| 152 |
|
| 153 |
# Return result |
| 154 |
return $info; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* put your comment there... |
| 159 |
* |
| 160 |
*/ |
| 161 |
public function getPluginUpdate() |
| 162 |
{ |
| 163 |
|
| 164 |
# Check if there is update available for current extension |
| 165 |
$pluginUpdate = $this->jsonDecode($this->makeCall(__FUNCTION__)->getResponseData()); |
| 166 |
|
| 167 |
# Return result |
| 168 |
return $pluginUpdate; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* put your comment there... |
| 173 |
* |
| 174 |
*/ |
| 175 |
public function getLicense() |
| 176 |
{ |
| 177 |
return $this->license; |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* put your comment there... |
| 182 |
* |
| 183 |
*/ |
| 184 |
public function getPluginFile() |
| 185 |
{ |
| 186 |
return $this->pluginFile; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* put your comment there... |
| 191 |
* |
| 192 |
*/ |
| 193 |
public function getSlug() |
| 194 |
{ |
| 195 |
return $this->slug; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* put your comment there... |
| 200 |
* |
| 201 |
*/ |
| 202 |
public function hasUpdate() |
| 203 |
{ |
| 204 |
|
| 205 |
# Get Last release version |
| 206 |
$pluginUpdate = $this->getPluginInformation(); |
| 207 |
$version = $pluginUpdate['currentVersion']; |
| 208 |
|
| 209 |
# Get Plugin current version |
| 210 |
$pluginData = get_plugin_data($this->getPluginFile()); |
| 211 |
|
| 212 |
# Return version details if there is new version/ otherwise return false |
| 213 |
$result = (version_compare($version, $pluginData['Version']) == 1) ? $pluginUpdate : false; |
| 214 |
|
| 215 |
return $result; |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* put your comment there... |
| 220 |
* |
| 221 |
* @param mixed $method |
| 222 |
* @param mixed $params |
| 223 |
* @param mixed $postData |
| 224 |
* @return CJTServicesClientModule |
| 225 |
*/ |
| 226 |
public function makeCall( $method, |
| 227 |
$params = null, |
| 228 |
$postData = null, |
| 229 |
$bodyEncoding = CJTServicesClient::BODY_ENCODING_JSON) |
| 230 |
{ |
| 231 |
|
| 232 |
# Always include the following parameters |
| 233 |
$params = array_merge(array |
| 234 |
( |
| 235 |
'itemIdentifier' => $this->getItemName(), |
| 236 |
'license' => $this->getLicense() , |
| 237 |
'itemAttrs' => $this->getAttrs(), |
| 238 |
|
| 239 |
), $params ? $params : array()); |
| 240 |
|
| 241 |
// Make API Call throuh Module base layer |
| 242 |
return parent::makeCall($method, $params, $postData, $bodyEncoding); |
| 243 |
} |
| 244 |
|
| 245 |
} |