/** * Get all available update packages * * @access public * @return array */ public static function getAvailablePackages() { global $lC_Api; $result = array('entries' => array()); $api_version = defined('API_VERSION') && API_VERSION != NULL ? API_VERSION : '1_0'; $request_type = getRequestType(); $versions = transport::getResponse(array('url' => $request_type . '://api.loadedcommerce.com/' . $api_version . '/updates/available/?ref=' . $_SERVER['SCRIPT_FILENAME'], 'method' => 'get', 'timeout' => 10)); $versions_array = utility::xml2arr($versions); $counter = 0; foreach ($versions_array['data'] as $l => $v) { if (version_compare(utility::getVersion(), $v['version'], '<')) { $result['entries'][] = array('key' => $counter, 'version' => $v['version'], 'date' => lC_DateTime::getShort(lC_DateTime::fromUnixTimestamp(lC_DateTime::getTimestamp($v['dateCreated'], 'Ymd'))), 'announcement' => $v['newsLink'], 'update_package' => isset($v['pharLink']) ? $v['pharLink'] . '?ref=' . urlencode($_SERVER['SCRIPT_FILENAME']) : null); $counter++; } } @usort($result['entries'], function ($a, $b) { return version_compare($a['version'], $b['version'], '>'); }); $result['total'] = count($result['entries']); return $result; }
public static function apiCheck() { $api_version = defined('API_VERSION') && API_VERSION != NULL ? API_VERSION : '1_0'; $request_type = getRequestType(); $apiCheck = transport::getResponse(array('url' => $request_type . '://api.loadedcommerce.com/' . $api_version . '/updates/available/?ver=' . utility::getVersion() . '&ref=' . $_SERVER['SCRIPT_FILENAME'], 'method' => 'get', 'timeout' => 10)); $versions = utility::xml2arr($apiCheck); $error = false; if (count($versions) == 0) { // there was an error with the api $error = true; $errorMsg = preg_match("'<title[^>]*?>.*?</title>'si", $versions, $regs); $errorMsg = is_array($regs) ? strip_tags(end($regs)) : NULL; if ($errorMsg == '') { $errorMsg = 'Resource Unavailable at ' . $request_type . '://api.loadedcommerce.com/' . $api_version . '/updates/available/?ver=' . utility::getVersion() . '&ref=' . $_SERVER['SCRIPT_FILENAME']; } $error = true; // log the error self::log('Error: ' . $errorMsg); } if ($versions == null || $error) { // set the error flag return -1; } return 1; }
public static function getAvailbleAddons() { $installed = self::getInstalledAddons(); $request = array('storeName' => STORE_NAME, 'storeWWW' => HTTP_SERVER . DIR_WS_HTTP_CATALOG, 'storeSSL' => HTTPS_SERVER . DIR_WS_HTTPS_CATALOG); $checksum = hash('sha256', json_encode($request)); $request['checksum'] = $checksum; $request['instID'] = INSTALLATION_ID; $request_type = getRequestType(); $api_version = defined('API_VERSION') && API_VERSION != NULL ? API_VERSION : '1_0'; $resultXML = transport::getResponse(array('url' => $request_type . '://api.loadedcommerce.com/' . $api_version . '/store/addons/?ref=' . $_SERVER['SCRIPT_FILENAME'], 'method' => 'post', 'parameters' => $request, 'timeout' => 10)); $available = utility::xml2arr($resultXML); $addons = array(); $codeArr = array(); foreach ($installed as $key => $val) { $codeArr[$val['code']] = true; $addons[] = array('name' => $val['name'], 'code' => $val['code'], 'type' => $val['type'], 'title' => $val['title'], 'description' => $val['description'], 'rating' => $val['rating'], 'author' => $val['author'], 'authorWWW' => $val['authorWWW'], 'thumbnail' => $val['thumbnail'], 'version' => $val['version'], 'compatibility' => $val['compatibility'], 'installed' => $val['installed'], 'mobile' => $val['mobile'], 'enabled' => $val['enabled'], 'from_store' => false, 'featured' => false, 'featured_in_group' => false); } foreach ($available['data'] as $key => $val) { if (array_key_exists($val['code'], $codeArr)) { continue; } $addons[] = array('name' => $val['code'] . '/controller.php', 'code' => $val['code'], 'type' => $val['type'], 'title' => self::_decodeText($val['title']), 'description' => self::_decodeText($val['description']), 'rating' => $val['rating'], 'author' => $val['author'], 'authorWWW' => $val['authorWWW'], 'thumbnail' => $val['thumbnail'], 'version' => $val['version'], 'compatibility' => $val['compatibility'], 'installed' => $val['installed'], 'mobile' => $val['mobile'], 'enabled' => $val['enabled'], 'from_store' => true, 'featured' => $val['featured'], 'featured_in_group' => $val['featured_in_group']); } return $addons; }