diff --git a/classes/LBRY_Admin.php b/classes/LBRY_Admin.php new file mode 100644 index 0000000..4de7f3b --- /dev/null +++ b/classes/LBRY_Admin.php @@ -0,0 +1,54 @@ +request('wallet_unused_address')); + return $result->result; + } + + /** + * Returns the balance of a current LBRY wallet + * @param string $address Wallet Address + * @return float Wallet Balance + */ + public function wallet_balance($address) + { + return $this->request('wallet_balance', array( + 'address' => $address, + 'include_unconfirmed' => false + )); + } + + private function request($method, $params = array()) + { + // JSONify our request data + $data = array( + 'method' => $method, + 'params' => $params + ); + $data = json_encode($data); + + // Send it via curl + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->address); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + curl_setopt($ch, CURLOPT_AUTOREFERER, false); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + $result = curl_exec($ch); + curl_close($ch); + return $result; + } + + /** + * Temporary placeholder function for daemon. Not currently in use. + * @return [type] [description] + */ + private function download_daemon() + { + $output_filename = "lbrydaemon"; + + $host = "http://build.lbry.io/daemon/build-6788_commit-5099e19_branch-lbryum-refactor/mac/lbrynet"; + $fp = fopen(LBRY_URI . '/' . $output_filename, 'w+'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $host); + curl_setopt($ch, CURLOPT_VERBOSE, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_setopt($ch, CURLOPT_AUTOREFERER, false); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + $result = curl_exec($ch); + curl_close($ch); + fclose($fp); + + $filepath = LBRY_URI . '/' . $output_filename; + + + `chmod +x {$filepath}`; + error_log(`{$filepath} status`); + `{$filepath} start &`; + } +} diff --git a/classes/LBRY_Daemon_Logger.php b/classes/LBRY_Daemon_Logger.php new file mode 100644 index 0000000..96a6a2b --- /dev/null +++ b/classes/LBRY_Daemon_Logger.php @@ -0,0 +1,21 @@ +require_dependencies(); - $this->LBRY_Admin = new LBRY_Admin(); + /** + * 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->LBRY_Admin->settings_init(); + /** + * Run during plugin activation + * @return [type] [description] + */ + public function activate() + { + $LBRY_Daemon = LBRY_Daemon::get_instance(); - $this->download_daemon(); + // Add options to the options table we need + if (! get_option(LBRY_WALLET)) { + $wallet_address = $LBRY_Daemon->wallet_unused_address(); + add_option(LBRY_WALLET, $wallet_address); } - private function require_dependencies() - { - require_once(LBRY_URI . '/classes/admin/lbry_admin.php'); - } - private function download_daemon() - { - $output_filename = "lbrydaemon"; + error_log('Activated'); + } - $host = "http://build.lbry.io/daemon/build-6788_commit-5099e19_branch-lbryum-refactor/mac/lbrynet"; - $fp = fopen(LBRY_URI . '/' . $output_filename, 'w+'); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $host); - curl_setopt($ch, CURLOPT_VERBOSE, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_AUTOREFERER, false); - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - curl_setopt($ch, CURLOPT_HEADER, 0); - - $result = curl_exec($ch); - curl_close($ch); - fclose($fp); - - $filepath = LBRY_URI . '/' . $output_filename; - - - `chmod +x {$filepath}`; - error_log(`{$filepath} status`); - `{$filepath} start &`; - } + /** + * Clean up on deactivation + * @return [type] [description] + */ + public function deactivate() + { + error_log('Deactivated'); } } diff --git a/classes/speech/lbry_speech.php b/classes/speech/lbry_speech.php deleted file mode 100644 index 3fd1dfb..0000000 --- a/classes/speech/lbry_speech.php +++ /dev/null @@ -1,14 +0,0 @@ -init(); + }); - if (class_exists('LBRYPress')) { - $lbryPress = LBRYPress::get_instance(); - // register_activation_hook(__FILE__, array( $lbryPress, 'activate' )); - // register_deactivation_hook(__FILE__, array( $lbryPress, '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'); } + +/** + * Admin Set up + */