晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/stando/www/wp-content/plugins/gravityforms_v2139/includes/ |
Upload File : |
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
if ( ! defined( 'GRAVITY_API_URL' ) ) {
define( 'GRAVITY_API_URL', 'https://o4zq2dvjn6.execute-api.us-east-1.amazonaws.com/prod/' );
}
if ( ! class_exists( 'Gravity_Api' ) ) {
/**
* Client-side API wrapper for interacting with the Gravity APIs.
*
* @package Gravity Forms
* @subpackage Gravity_Api
* @since 1.9
* @access public
*/
class Gravity_Api {
private static $instance = null;
public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Retrieves site key and site secret key from remote API and stores them as WP options. Returns false if license key is invalid; otherwise, returns true.
*
* @since 1.9.?
* @access public
*
* @param string $license_key
*
* @return bool Success
*/
public function register_current_site( $license_key, $is_md5 = false ) {
$body = GFCommon::get_remote_post_params();
$body['site_name'] = get_bloginfo( 'name' );
$body['site_url'] = get_bloginfo( 'url' );
if ( $is_md5 ) {
$body['license_key_md5'] = $license_key;
$license_key_md5 = $license_key;
} else {
$body['license_key'] = $license_key;
$license_key_md5 = md5( $license_key );
}
GFCommon::log_debug( __METHOD__ . '() - registering site' );
$result = $this->request( 'sites', $body, 'POST', array( 'headers' => $this->get_license_auth_header( $license_key_md5 ) ) );
$result = $this->prepare_response_body( $result );
if ( is_wp_error( $result ) ) {
GFCommon::log_debug( __METHOD__ . '() - error registering site. ' . print_r( $result, true ) );
return $result;
}
//Updating site key and secret
update_option( 'gf_site_key', $result->key );
update_option( 'gf_site_secret', $result->secret );
GFCommon::log_debug( __METHOD__ . '() - site registration successful. Site Key: ' . $result->key );
return true;
}
public function update_current_site( $new_license_key_md5 ) {
$site_key = $this->get_site_key();
if ( empty( $site_key ) ) {
return false;
}
$body = GFCommon::get_remote_post_params();
$body['site_name'] = get_bloginfo( 'name' );
$body['site_url'] = get_bloginfo( 'url' );
$body['license_key_md5'] = $new_license_key_md5;
$body['site_key'] = $site_key;
$site_secret = $this->get_site_secret();
if ( $site_secret ) {
$site_secret_md5 = md5( $site_secret );
$body['site_secret'] = $site_secret;
$body['site_secret_md5'] = $site_secret_md5;
}
GFCommon::log_debug( __METHOD__ . '() - refreshing license info' );
$result = $this->request( 'sites/' . $site_key, $body, 'PUT', array( 'headers' => $this->get_site_auth_header( $site_key, $site_secret ) ) );
$result = $this->prepare_response_body( $result );
if ( is_wp_error( $result ) ) {
GFCommon::log_debug( __METHOD__ . '() - error updating site registration. ' . print_r( $result, true ) );
return $result;
}
return true;
}
public function deregister_current_site(){
$site_key = $this->get_site_key();
$site_secret = $this->get_site_secret();
if ( empty( $site_key ) ) {
return false;
}
GFCommon::log_debug( __METHOD__ . '() - deregistering' );
$body = array(
'license_key_md5' => '',
);
$result = $this->request( 'sites/' . $site_key, $body, 'PUT', array( 'headers' => $this->get_site_auth_header( $site_key, $site_secret ) ) );
$result = $this->prepare_response_body( $result );
if ( is_wp_error( $result ) ) {
GFCommon::log_debug( __METHOD__ . '() - error updating site registration. ' . print_r( $result, true ) );
return $result;
}
return true;
}
/***
* Retrieves API Keys for third party services. Requires a valid license
*
* @param $third_party_name string - Name or the third party service. "Dropbox" is currently the only supported service.
* @return WP_Error|object - If successful, returns the api key.
*/
public function get_api_key( $third_party_name ) {
$site_keys = $this->ensure_site_registered();
if ( empty( $site_keys ) ) {
return false;
}
switch ( $third_party_name ) {
case 'Dropbox' :
GFCommon::log_debug( __METHOD__ . '() - retrieving dropbox api key' );
$auth = base64_encode( $site_keys['site_key'] . ':' . $site_keys['site_secret'] );
$headers = array( 'Authorization' => 'GravityAPI ' . $auth );
$response = $this->request( 'credentials/dropbox', array(), 'GET', array( 'headers' => $headers ) );
return $this->prepare_response_body( $response );
default :
return new WP_Error( 'unsupported_service_name', 'The provided third party service name: ' . $third_party_name . ' is not supported. ' );
}
}
// # HELPERS
private function get_site_auth_header( $site_key, $site_secret ){
$auth = base64_encode( "{$site_key}:{$site_secret}" );
return array( 'Authorization' => 'GravityAPI ' . $auth );
}
private function get_license_auth_header( $license_key_md5 ){
$auth = base64_encode( "license:{$license_key_md5}" );
return array( 'Authorization' => 'GravityAPI ' . $auth );
}
public function prepare_response_body( $raw_response ) {
if ( is_wp_error( $raw_response ) ) {
return $raw_response;
}
else if ( $raw_response['response']['code'] != 200 ) {
return new WP_Error( 'server_error', 'Error from server: ' . $raw_response['response']['message'] );
}
$response_body = json_decode( $raw_response['body'] );
if ( $response_body === null ){
return new WP_Error( 'invalid_response', 'Invalid response from server: ' . $raw_response['body'] );
}
return $response_body;
}
public function purge_site_credentials() {
delete_option( 'gf_site_key' );
delete_option( 'gf_site_secret' );
}
public function request( $resource, $body, $method = 'POST', $options = array() ) {
$body['timestamp'] = time();
// set default options
$options = wp_parse_args( $options, array(
'method' => $method,
'timeout' => 10,
'body' => in_array( $method, array( 'GET', 'DELETE' ) ) ? null : json_encode( $body ),
'headers' => array(),
'sslverify' => false,
) );
// set default header options
$options['headers'] = wp_parse_args( $options['headers'], array(
'Content-Type' => 'application/json; charset=' . get_option( 'blog_charset' ),
'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),
'Referer' => get_bloginfo( 'url' ),
) );
// WP docs say method should be uppercase
$options['method'] = strtoupper( $options['method'] );
$request_url = $this->get_gravity_api_url() . $resource;
$raw_response = wp_remote_request( $request_url, $options );
return $raw_response;
}
public function get_site_key() {
if ( defined( 'GRAVITY_API_SITE_KEY' ) ) {
return GRAVITY_API_SITE_KEY;
}
$site_key = get_option( 'gf_site_key' );
if ( empty( $site_key ) ) {
return false;
}
return $site_key;
}
public function get_site_secret() {
if ( defined( 'GRAVITY_API_SITE_SECRET' ) ) {
return GRAVITY_API_SITE_SECRET;
}
$site_secret = get_option( 'gf_site_secret' );
if ( empty( $site_secret ) ) {
return false;
}
return $site_secret;
}
public function get_gravity_api_url() {
return trailingslashit( GRAVITY_API_URL );
}
public function ensure_site_registered() {
if ( ! $this->is_site_registered() ) {
$license_key_md5 = GFCommon::get_key();
if ( empty( $license_key_md5 ) ) {
return false;
}
$result = $this->register_current_site( $license_key_md5, true );
if ( ! $result || is_wp_error( $result ) ) {
return false;
}
}
return array(
'site_key' => $this->get_site_key(),
'site_secret' => $this->get_site_secret(),
);
}
public function is_site_registered() {
return $this->get_site_key() && $this->get_site_secret();
}
}
function gapi() {
return Gravity_Api::get_instance();
}
gapi();
}