Began working on dependency injection style
infrastructure. initial work on settings page template
This commit is contained in:
parent
9f81309dee
commit
59c3118c79
5 changed files with 74 additions and 31 deletions
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
<?php
|
||||
$LBRY_Daemon = LBRY_Daemon::get_instance();
|
||||
$LBRY_Speech = LBRY_Speech::get_instance();
|
||||
$wallet_balance = $LBRY_Daemon->wallet_balance();
|
||||
$speech_address = $LBRY_Speech->get_address() || '';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?= esc_html(get_admin_page_title()); ?></h1>
|
||||
|
||||
<h2>Your wallet address:</h2>
|
||||
<code><?= get_option(LBRY_WALLET); ?></code>
|
||||
|
||||
<h2>Your wallet amount:</h2>
|
||||
<code><?= number_format($wallet_balance, 6, '.', ','); ?></code>
|
||||
<form action="options.php" method="post">
|
||||
<label for="speech_address">
|
||||
<h2>Your Spee.ch server address to act as a cdn for assets:</h2>
|
||||
<p class="form-help">Learn more about spee.ch <a href="https://github.com/lbryio/spee.ch" target="_blank">here</a>.</p>
|
||||
</label>
|
||||
<input type="text" name="speech_address" placeholder="https://your-speech-address.com" value="<?= $speech_address ?>">
|
||||
<?php
|
||||
submit_button('Save Settings');
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue