diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index e571557..346059b 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -7,10 +7,92 @@ class LBRY_Network { + + /** + * The Publishing Object + * @var LBRY_Network_Publisher + */ + public $publisher = null; + + /** + * The Parsing Object + * @var LBRY_Network_Parser + */ + public $parser = null; + /** * [__construct description] */ public function __construct() { + $this->publisher = new LBRY_Network_Publisher(); + $this->parser = new LBRY_Network_Parser(); + + $this->post_meta_setup(); + } + + /** + * Sets up everything for the post meta boxes + */ + private function post_meta_setup() + { + // Add the meta boxes + add_action('add_meta_boxes', array($this, 'add_meta_boxes')); + + // Save the post meta on 'save_post' hook + add_action('save_post', array($this, 'save_post_meta'), 10, 2); + } + + /** + * Adds the meta boxes to the post editing backend + */ + public function add_meta_boxes() + { + add_meta_box( + 'lbry-network-publishing', // Unique ID + 'LBRY Network', // Title + array($this, 'meta_box_html'), // Callback function + 'post', // Screen Options (or post type) + 'side', // Context + 'high' // Priority + ); + } + + /** + * Handles saving the post meta that is relative to publishing to the LBRY Network + */ + public function save_post_meta($post_id, $post) + { + // Verify the nonce before proceeding. + if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) { + return $post_id; + } + + // Check if the current user has permission to edit the post. + $post_type = get_post_type_object($post->post_type); + if (!current_user_can($post_type->cap->edit_post, $post_id)) { + return $post_id; + } + + $meta_key = 'lbry_channels'; + $new_channels = (isset($_POST[$meta_key]) ? $_POST[$meta_key] : null); + $cur_channels = get_post_meta($post_id, $meta_key); + + // COMBAK: Make this a bit more efficent if they have lots of channels + // Start with clean meta, then add new channels if there are any + delete_post_meta($post_id, $meta_key); + if ($new_channels) { + foreach ($new_channels as $channel) { + add_post_meta($post_id, $meta_key, $channel); + } + } + + // Publish the post on the LBRY Network + $this->publisher->publish($post, $new_channels); + } + + public function meta_box_html($post) + { + require_once(LBRY_ABSPATH . 'templates/meta_box.php'); } } diff --git a/classes/LBRY_Network_Publisher.php b/classes/LBRY_Network_Publisher.php index 76b9370..0cd6235 100644 --- a/classes/LBRY_Network_Publisher.php +++ b/classes/LBRY_Network_Publisher.php @@ -13,4 +13,16 @@ class LBRY_Network_Publisher public function __construct() { } + + /** + * Publish the post to the LBRY Network + * @param int $post_id The ID of the post we are publishing + * @param array $channels An array of channels we are publishing to + */ + public function publish($post, $channels) + { + $name = $post->post_name; + + return; + } } diff --git a/classes/lbrypress.php b/classes/lbrypress.php index b087fae..9043ef1 100644 --- a/classes/lbrypress.php +++ b/classes/lbrypress.php @@ -38,6 +38,11 @@ class LBRYPress */ public $notice = null; + /** + * The Library Network Object + */ + public $network = null; + /** * Main LBRYPress Instance. * @@ -123,7 +128,6 @@ class LBRYPress { $this->daemon = new LBRY_Daemon(); $this->speech = new LBRY_Speech(); - $this->notice = new LBRY_Admin_Notice(); } /** @@ -137,6 +141,8 @@ class LBRYPress // Admin request if (is_admin()) { $this->admin = new LBRY_Admin(); + $this->notice = new LBRY_Admin_Notice(); + $this->network = new LBRY_Network(); } else { $this->speech->maybe_rewrite_urls(); } diff --git a/templates/meta_box.php b/templates/meta_box.php new file mode 100644 index 0000000..93e73fa --- /dev/null +++ b/templates/meta_box.php @@ -0,0 +1,29 @@ + 'Unattributed', + 'permanent_url' => 'unattributed' +); +$channels = LBRY()->daemon->channel_list(); +array_unshift($channels, $unnatributed); +$cur_channels = get_post_meta($post->ID, 'lbry_channels'); +?> + +

Choose which channels you would like to publish this post to:

+ diff --git a/templates/options_page.php b/templates/options_page.php index 5a2932f..320f2ea 100644 --- a/templates/options_page.php +++ b/templates/options_page.php @@ -2,14 +2,12 @@ $LBRY = LBRY(); $wallet_balance = $LBRY->daemon->wallet_balance(); $channel_list = $LBRY->daemon->channel_list(); +// TODO: Make this page look cleaner ?>
-

-

Your wallet amount:

-
daemon->channel_list(); submit_button('Save Settings'); ?>
-

Your Publishable Channels