From 90de7cb6f6089363795cd4d91f88c26c6f5bda88 Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Thu, 11 Oct 2018 20:21:49 -0500 Subject: [PATCH 1/3] Added post widget --- classes/LBRY_Network.php | 56 ++++++++++++++++++++++++++++++++++++++++ classes/lbrypress.php | 8 +++++- templates/meta_box.php | 23 +++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 templates/meta_box.php diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index e571557..6caf40a 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -7,10 +7,66 @@ 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')); + } + + /** + * 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() + { + } + + public function meta_box_html() + { + require_once(LBRY_ABSPATH . 'templates/meta_box.php'); } } 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..0971faa --- /dev/null +++ b/templates/meta_box.php @@ -0,0 +1,23 @@ + 'Unattributed', + 'permanent_url' => 'unattributed' +); +$channels = LBRY()->daemon->channel_list(); +array_unshift($channels, $unnatributed); +?> +

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

+ From 798ac5f30e18f1e5cc6594cc8b24078f8d3099ec Mon Sep 17 00:00:00 2001 From: Paul Kirby Date: Thu, 11 Oct 2018 22:59:01 -0500 Subject: [PATCH 2/3] Populate meta box with current selections --- classes/LBRY_Network.php | 31 +++++++++++++++++++++++++++---- templates/meta_box.php | 8 +++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/classes/LBRY_Network.php b/classes/LBRY_Network.php index 6caf40a..8a7bce8 100644 --- a/classes/LBRY_Network.php +++ b/classes/LBRY_Network.php @@ -40,7 +40,7 @@ class LBRY_Network 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')); + add_action('save_post', array($this, 'save_post_meta'), 10, 2); } /** @@ -54,18 +54,41 @@ class LBRY_Network array($this, 'meta_box_html'), // Callback function 'post', // Screen Options (or post type) 'side', // Context - 'high' // Priority + 'high' // Priority ); } /** * Handles saving the post meta that is relative to publishing to the LBRY Network */ - public function save_post_meta() + 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); + } + } } - public function meta_box_html() + public function meta_box_html($post) { require_once(LBRY_ABSPATH . 'templates/meta_box.php'); } diff --git a/templates/meta_box.php b/templates/meta_box.php index 0971faa..93e73fa 100644 --- a/templates/meta_box.php +++ b/templates/meta_box.php @@ -6,14 +6,20 @@ $unnatributed = (object) array( ); $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: