diff --git a/classes/LBRY_Daemon.php b/classes/LBRY_Daemon.php index 30b0e83..16a74e9 100644 --- a/classes/LBRY_Daemon.php +++ b/classes/LBRY_Daemon.php @@ -26,8 +26,8 @@ class LBRY_Daemon */ public function wallet_unused_address() { - $result = json_decode($this->request('wallet_unused_address')); - return $result->result; + $result = $this->request('wallet_unused_address'); + return json_decode($result->result); } /** @@ -35,12 +35,21 @@ class LBRY_Daemon * @param string $address Wallet Address * @return float Wallet Balance */ - public function wallet_balance($address) + public function wallet_balance($address = '') { - return $this->request('wallet_balance', array( + $address = $address ?? get_option(LBRY_WALLET); + $result = $this->request('wallet_balance', array( 'address' => $address, 'include_unconfirmed' => false )); + + error_log(print_r($result, true)); + + return json_decode($result)->result; + } + + public function channel_list() + { } private function request($method, $params = array()) diff --git a/classes/LBRY_Speech.php b/classes/LBRY_Speech.php index 9f63fcf..3b5713b 100644 --- a/classes/LBRY_Speech.php +++ b/classes/LBRY_Speech.php @@ -7,7 +7,7 @@ * @package LBRYPress */ -class LBRY_Speech_Parser +class LBRY_Speech { private static $instance = null; @@ -20,4 +20,14 @@ class LBRY_Speech_Parser return self::$instance; } + + public function get_address() + { + return get_option(LBRY_SPEECH); + } + + public function set_address($address) + { + update_option(LBRY_SPEECH, $address); + } } diff --git a/classes/lbrypress.php b/classes/lbrypress.php index 94974aa..15e1ece 100644 --- a/classes/lbrypress.php +++ b/classes/lbrypress.php @@ -7,34 +7,39 @@ class LBRYPress { - private static $instance = null; + // TODO: Remove Singleton pattern, replace with dependency injection for all classes + // private static $instance = null; + // + // public static function get_instance() + // { + // // Create the object + // if (self::$instance === null) { + // self::$instance = new self; + // } + // + // return self::$instance; + // } + protected $daemon; + protected $admin; - public static function get_instance() + public function __construct(LBRY_Daemon $daemon = null, LBRY_Admin $admin = null) { - // Create the object - if (self::$instance === null) { - self::$instance = new self; - } - - return self::$instance; + $this->daemon = $daemon ?? new LBRY_Daemon(); + $this->admin = $admin ?? new LBRY_Admin(); + error_log('new LBRYPress constructed'); } /** * Set up all hooks and actions necessary for the plugin to run - * @return [type] [description] */ public function init() { // Initialize the admin interface - $LBRY_Admin = LBRY_Admin::get_instance(); - $LBRY_Admin->settings_init(); - - $LBRY_Daemon = LBRY_Daemon::get_instance(); + $this->admin->settings_init(); } /** * Run during plugin activation - * @return [type] [description] */ public function activate() { @@ -42,17 +47,15 @@ class LBRYPress // Add options to the options table we need if (! get_option(LBRY_WALLET)) { - $wallet_address = $LBRY_Daemon->wallet_unused_address(); + $wallet_address = $this->daemon->wallet_unused_address(); add_option(LBRY_WALLET, $wallet_address); } - error_log('Activated'); } /** * Clean up on deactivation - * @return [type] [description] */ public function deactivate() { diff --git a/lbrypress.php b/lbrypress.php index cff5929..8b6f1d3 100644 --- a/lbrypress.php +++ b/lbrypress.php @@ -32,7 +32,10 @@ define('LBRY_REQUIRED_PHP_VERSION', '5.3'); // TODO: Figure out what versions we define('LBRY_REQUIRED_WP_VERSION', '3.1'); // Library Options Names -define('LBRY_WALLET', 'lbry_wallet'); +define('LBRY_WALLET', 'lbry_wallet'); // the wallet address +define('LBRY_SPEECH', 'lbry_speech'); // the spee.ch address +define('LBRY_LICENSE', 'lbry_license'); // the license to publish with to the LBRY network +define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish /** * Checks if the system requirements are met @@ -86,16 +89,17 @@ spl_autoload_register('lbry_autoload_register'); */ if (lbry_requirements_met()) { add_action('init', function () { - LBRYPress::get_instance()->init(); + $LBRYPress = new LBRYPress(); + $LBRYPress->init(); }); - register_activation_hook(__FILE__, function () { - LBRYPress::get_instance()->activate(); - }); - - register_deactivation_hook(__FILE__, function () { - LBRYPress::get_instance()->deactivate(); - }); +// register_activation_hook(__FILE__, function () { + // LBRYPress::get_instance()->activate(); + // }); + // + // register_deactivation_hook(__FILE__, function () { + // LBRYPress::get_instance()->deactivate(); + // }); } else { add_action('admin_notices', 'lbry_requirements_error'); } diff --git a/templates/options_page.php b/templates/options_page.php index 4f49180..4a9754a 100644 --- a/templates/options_page.php +++ b/templates/options_page.php @@ -1,6 +1,23 @@ +wallet_balance(); +$speech_address = $LBRY_Speech->get_address() || ''; +?>

+ +

Your wallet address:

+ + +

Your wallet amount:

+
+ +