1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289:
<?php
class Inbound_API_Wrapper {
static $inbound_api_uri;
static $docs_uri = 'http://docs.inboundnow.com/feed?post_type=doc-page';
static $blog_uri = 'http://www.inboundnow.com/feed/';
static $data;
static $templates;
static $extensions;
static $remote_content;
static $blogs;
static $docs;
static $response;
public function __construct() {
self::get_api_url();
}
public static function get_api_url() {
self::$inbound_api_uri = 'https://www.inboundnow.com/pro-api/';
return self::$inbound_api_uri;
}
public static function get_api_key() {
$settings_values = Inbound_Options_API::get_option( 'inbound-pro' , 'settings' , array() );
return (isset($settings_values['api-key']['api-key'])) ? trim($settings_values['api-key']['api-key']) : '';
}
public static function get_downloads() {
self::$data = Inbound_Options_API::get_option( 'inbound-api' , 'downloads' , array() );
if ( isset(self::$data['expire']) && self::$data['expire'] > gmdate( 'Y-m-d G:i:s' ) && !isset($_GET['inbound_reset_downloads_data']) && is_array(self::$data) ) {
}
$response = wp_remote_post( self::$inbound_api_uri ,
array(
'timeout' => 30,
'body' => array ( 'get_downloads' => true , 'key' => 'hudson11' )
)
);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
exit;
}
self::$data = unserialize( $response['body'] );
self::$data['expire'] = gmdate('Y-m-d G:i:s' , strtotime( "+1 hour" ));
Inbound_Options_API::update_option( 'inbound-api' , 'downloads' , self::$data );
return self::$data;
}
public static function get_docs() {
self::$remote_content = Inbound_Options_API::get_option( 'inbound-api' , 'remote' , array() );
if ( isset(self::$remote_content['docs']['expire']) && self::$remote_content['docs']['expire'] > gmdate( 'Y-m-d G:i:s' ) ) {
return self::$remote_content['docs']['items'];
}
$response = wp_remote_get( self::$docs_uri );
if (is_wp_error($response) || !isset($response['body'])) {
return;
}
$xml = simplexml_load_string( $response['body'] , null , LIBXML_NOCDATA );
$json = json_encode($xml);
self::$docs = json_decode($json,TRUE);
self::$remote_content['docs']['expire'] = gmdate('Y-m-d G:i:s' , strtotime( "+3 hours" ));
self::$remote_content['docs']['items'] = self::$docs['channel']['item'];
Inbound_Options_API::update_option( 'inbound-api' , 'remote' , self::$remote_content );
return self::$docs['channel']['item'];
}
public static function get_blog_posts() {
self::$remote_content = Inbound_Options_API::get_option( 'inbound-api' , 'remote' , array() );
if ( isset(self::$remote_content['blog']['expire']) && self::$remote_content['blog']['expire'] > gmdate( 'Y-m-d G:i:s' ) ) {
return self::$remote_content['blog']['items'];
}
$response = wp_remote_get( self::$blog_uri );
if (is_wp_error($response)) {
$error = $response->get_error_message();
echo $error;
return;
}
$xml = simplexml_load_string( $response['body'] , null , LIBXML_NOCDATA );
$json = json_encode($xml);
self::$blogs = json_decode($json,TRUE);
self::$remote_content['blog']['expire'] = gmdate('Y-m-d G:i:s' , strtotime( "+3 hours" ));
self::$remote_content['blog']['items'] = self::$blogs['channel']['item'];
Inbound_Options_API::update_option( 'inbound-api' , 'remote' , self::$remote_content );
return self::$blogs['channel']['item'];
}
public static function get_pro_templates() {
self::get_downloads();
self::$templates = array();
foreach ( self::$data as $key => $download ) {
if ( isset($download->download_type) && $download->download_type == 'template' ) {
self::$templates[] = (array) $download;
}
}
return self::$templates;
}
public static function get_pro_extensions() {
self::get_downloads();
self::$extensions = array();
foreach ( self::$data as $key => $download ) {
if ( isset($download->download_type) && $download->download_type == 'extension' ) {
self::$extensions[] = (array) $download;
}
}
return self::$extensions;
}
public static function get_inboundnow_blog_posts() {
}
public static function get_pro_info_endpoint() {
return self::get_api_url().'pro/latest';
}
public static function get_download_zip( $download ) {
$license_key = self::get_api_key();
$domain = site_url();
$response = wp_remote_post( self::$inbound_api_uri.'downloads/zip' , array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(
'download' => $download,
'site' => $domain,
'api-key' => $license_key
)
));
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
}
$json = $response['body'];
$array = json_decode($json, true);
if (
(!isset($array['url']) || !$array['url'] )
&&
isset($array['files'])
) {
foreach ( $array['files'] as $key=> $file_meta ) {
if (!$array['url'] && $file_meta['name'] != 'inbound-premium-template-support.zip' ) {
$array['url'] = $file_meta['file'];
} else {
continue;
}
}
}
if(isset($array['error']) || !isset( $array['url'] )) {
if (isset($GLOBALS['is_activating'])) {
return '';
} else {
echo '<pre>'.$json.'</pre>';
print_r($array);exit;
}
}
return $array['url'];
}
}
new Inbound_API_Wrapper;