public static function get_quota($settings, $bypass_cache = false) { $cache_time = 43200; // 12 hours. if ($bypass_cache == false) { $transient = get_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username']); if ($transient !== false) { pb_backupbuddy::status('details', 'Stash quota information CACHED. Returning cached version.'); return $transient; } } else { pb_backupbuddy::status('details', 'Stash bypassing cached quota information. Getting new values.'); } $itxapi_username = $settings['itxapi_username']; $itxapi_password = $settings['itxapi_password']; require_once dirname(__FILE__) . '/lib/class.itx_helper.php'; require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php'; $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password); $quota_url = $stash->get_quota_url(); $request = new RequestCore($quota_url); $response = $request->send_request(true); // See if the request was successful. if (!$response->isOK()) { pb_backupbuddy::status('error', 'Stash request for quota failed.'); } // See if we got a json response. if (!($quota_data = json_decode($response->body, true))) { pb_backupbuddy::status('error', 'Stash did not get valid json response.'); } // Finally see if the API returned an error. if (isset($quota_data['error'])) { if ($quota_data['error']['code'] == '3002') { pb_backupbuddy::alert('Invalid iThemes.com Member account password. Unable to authenticate to Stash. Please verify your password & try again. Changing your iThemes password will require updating your Stash destination to continue using it. <a href="http://ithemes.com/member/member.php" target="_new">Forget your password?</a>'); } else { pb_backupbuddy::alert(implode(' - ', $quota_data['error'])); } return false; } set_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username'], $quota_data, $cache_time); return $quota_data; }
public static function get_quota($settings, $bypass_cache = false) { $cache_time = 43200; // 12 hours. if ($bypass_cache == false) { $transient = get_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username']); if ($transient !== false) { pb_backupbuddy::status('details', 'Stash quota information CACHED. Returning cached version.'); return $transient; } } else { pb_backupbuddy::status('details', 'Stash bypassing cached quota information. Getting new values.'); } $itxapi_username = $settings['itxapi_username']; $itxapi_password = $settings['itxapi_password']; pb_backupbuddy::status('details', 'Loading ITX helper file.'); require_once dirname(__FILE__) . '/lib/class.itx_helper.php'; pb_backupbuddy::status('details', 'Loading AWS SDK file.'); require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php'; $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password); $quota_url = $stash->get_quota_url(); pb_backupbuddy::status('details', 'RequestCore getting quota.'); $request = new RequestCore($quota_url); try { $response = $request->send_request(true); } catch (Exception $e) { $error = 'Error #32897329: Unable to get Stash quota information. Details:`' . $e->getMessage() . '`.'; pb_backupbuddy::status('error', $error); echo $error; return false; } // See if the request was successful. if (!$response->isOK()) { pb_backupbuddy::status('error', 'Stash request for quota failed.'); } // See if we got a json response. if (!($quota_data = json_decode($response->body, true))) { pb_backupbuddy::status('error', 'Stash did not get valid json response.'); } // Finally see if the API returned an error. if (isset($quota_data['error'])) { if ($quota_data['error']['code'] == '3002') { echo 'Invalid iThemes.com Member account password. Please re-authenticate to Stash from the Remote Destination Settings page.'; return false; } else { pb_backupbuddy::alert(implode(' - ', $quota_data['error'])); } return false; } set_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username'], $quota_data, $cache_time); return $quota_data; }