Using description from Yoast or Excerpt for LBRY Description

This commit is contained in:
Paul Kirby 2018-11-01 12:13:55 -05:00
parent 77cd4c2c96
commit 42c4c36bb2
3 changed files with 25 additions and 8 deletions

View file

@ -148,7 +148,7 @@ class LBRY_Daemon
); );
return $result->result; return $result->result;
} catch (LBRYDaemonException $e) { } catch (LBRYDaemonException $e) {
$this->logger->log('wallet_unused_address error', $e->getMessage() . ' | Code: ' . $e->getCode()); $this->logger->log('publish error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.'); LBRY()->notice->set_notice('error', 'Issue publishing / updating post to LBRY Network.');
return; return;
} }

View file

@ -40,7 +40,7 @@ class LBRY_Network
add_action('add_meta_boxes', array($this, 'add_meta_boxes')); add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
// Save the post meta on 'save_post' hook // Save the post meta on 'save_post' hook
add_action('save_post', array($this, 'save_post_meta'), 10, 2); add_action('wp_insert_post', array($this, 'save_post_meta'), 11, 2);
} }
/** /**
@ -48,7 +48,7 @@ class LBRY_Network
*/ */
public function add_meta_boxes() public function add_meta_boxes()
{ {
// TODO: Support post types based on user selection // IDEA: Support post types based on user selection
add_meta_box( add_meta_box(
'lbry-network-publishing', // Unique ID 'lbry-network-publishing', // Unique ID
'LBRY Network', // Title 'LBRY Network', // Title
@ -67,6 +67,10 @@ class LBRY_Network
*/ */
public function save_post_meta($post_id, $post) public function save_post_meta($post_id, $post)
{ {
if ($post->post_type != 'post') {
return;
}
// Verify the nonce before proceeding. // Verify the nonce before proceeding.
if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) { if (!isset($_POST['_lbrynonce']) || !wp_verify_nonce($_POST['_lbrynonce'], 'lbry_publish_channels')) {
return $post_id; return $post_id;

View file

@ -19,6 +19,7 @@ class LBRY_Network_Publisher
* @param int $post_id The ID of the post we are publishing * @param int $post_id The ID of the post we are publishing
* @param string $channel The Claim ID of the channel we are posting to * @param string $channel The Claim ID of the channel we are posting to
*/ */
// NOTE: This is currently sitting at about 150ms, mostly the post parsing
public function publish($post, $channel) public function publish($post, $channel)
{ {
// Leave if nothing to publish to // Leave if nothing to publish to
@ -32,21 +33,33 @@ class LBRY_Network_Publisher
$converted = LBRY()->network->parser->convert_to_markdown($post); $converted = LBRY()->network->parser->convert_to_markdown($post);
$write_status = $file && fwrite($file, $converted); $write_status = $file && fwrite($file, $converted);
fclose($file); fclose($file);
$endtime = microtime(true);
try { try {
// If everything went well with the conversion, carry on // If everything went well with the conversion, carry on
if ($write_status) { if ($write_status) {
$featured_id = get_post_thumbnail_id($post);
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
$name = $post->post_name; $name = $post->post_name;
$bid = floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]); $bid = floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]);
$title = $post->post_title; $title = $post->post_title;
$language = substr(get_locale(), 0, 2); $language = substr(get_locale(), 0, 2);
$license = get_option(LBRY_SETTINGS)[LBRY_LICENSE]; $license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
// TODO: See if we can grab from yoast or a default?
$description = $post->post_title; // Setup featured image
$featured_id = get_post_thumbnail_id($post);
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
$thumbnail = $featured_image[0] ? $featured_image[0] : false; $thumbnail = $featured_image[0] ? $featured_image[0] : false;
// Build description using Yoast if installed and its used, excerpt/title otherwise
$description = false;
if (class_exists('WPSEO_META')) {
$description = WPSEO_META::get_value('opengraph-description', $post->ID);
}
if (!$description) {
$excerpt = get_the_excerpt($post);
$description = $excerpt ? $excerpt : $title;
}
$description .= ' | Originally published at ' . get_permalink($post);
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel, $thumbnail); LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel, $thumbnail);
} }
} catch (Exception $e) { } catch (Exception $e) {