{'version'} > $version){ //create new sub menu add_options_page('Amazon Store Install', 'Amazon Store Install', 'manage_options', 'ov-aws-update', 'OVAmazonStoreGPL::displayMenu'); } }catch(Exception $e){} // no worries try later } public static function displayMenu(){ // display install form or install data depending on state. if( isset($_REQUEST['ov_action']) && !empty($_REQUEST['ov_action']) ){ try{ $info = self::getCurrentVersion(); self::install($info->{'version'},$info->{'url'}); }catch(Exception $e){ echo '
'; echo '

Amazon Store Install

'; echo ''; echo '
'; echo 'Sorry... There was an error getting the current version info - '.$e->getMessage(); echo '
'; echo 'Please make sure your server allows traffic to update.onlinevelocity.com'; echo '
'; } }else{ if(self::doesMainPluginExist()){ self::displayUpdateMenu(); }else{ self::displayInstallMenu(); } } } private static function displayInstallMenu(){ echo '
'; echo '

Amazon Store Install

'; echo '
'; echo ''; echo '
'; echo ''; echo '
'; echo 'Congratulations you are almost there...
'; echo 'To complete the install you must press the install button.
By clicking install you agree to the Licensing terms specified below.

'; echo '
'; echo '

'; echo ''; echo '
'; echo '
'; } private static function displayUpdateMenu(){ echo '
'; echo '

Amazon Store Update

'; echo '
'; echo ''; echo '
'; echo ''; echo '
'; echo 'There is a new Update available. Wahoo!!!

'; echo '
'; echo ''; echo '
'; echo '
'; } private static function getCurrentVersion(){ $url = 'http://update.onlinevelocity.com/version.php'; $json = @file_get_contents($url); if(!($json === FALSE)){ $data = OVJSON::decode($json); }else{ throw new Exception("Could not connect to update.onlinevelocity.com"); } return $data; } private static function install($version,$package){ include_once WP_PLUGIN_DIR . OVELOCITY_GPL_ROOT . '/OVAmazonStoreUpgrader.php'; $pluginDir = WP_PLUGIN_DIR . OVELOCITY_GPL_ROOT . '/ov_amazon_store/'; $installer = new OVAmazonStoreUpgrader(); $result = $installer->install($package,$pluginDir); if ( !(! $result || is_wp_error($result)) && self::doesMainPluginExist()){ // update version first since plugin was actually installed // we may need additional checks for post install hook update_option('ov-amazon-store-version',$version); $main_path = OVELOCITY_ROOT_DIR . '/ov_amazon_store.php'; include_once($main_path); // check if function exists for 1.3.x support. if (function_exists('OVAmazonStore::postInstall()')){ OVAmazonStore::postInstall(); } } } } class OVJSON { public static function encode($obj) { return json_encode($obj); } public static function decode($json, $toAssoc = false) { $result = json_decode($json, $toAssoc); if (function_exists('json_last_error')){ switch(json_last_error()){ case JSON_ERROR_DEPTH: $error = ' - Maximum stack depth exceeded'; break; case JSON_ERROR_CTRL_CHAR: $error = ' - Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $error = ' - Syntax error, malformed JSON'; break; case JSON_ERROR_NONE: default: $error = ''; } }else{ if($result == NULL){ $error = 'Could not decode JSON'; } } if (!empty($error)) throw new Exception('JSON Error: '.$error); return $result; } } add_action('init', 'OVAmazonStoreGPL::inst_init'); ?>