2018-09-01 01:50:29 +02:00
|
|
|
<?php
|
2018-10-05 23:50:42 +02:00
|
|
|
use League\HTMLToMarkdown\HtmlConverter;
|
|
|
|
|
2018-09-01 01:50:29 +02:00
|
|
|
/**
|
|
|
|
* Parses wordpress posts to be ready for the LBRY Network
|
2018-10-05 23:50:42 +02:00
|
|
|
* Uses the Html-to-Markdown package
|
|
|
|
* https://github.com/thephpleague/html-to-markdown
|
2018-09-01 01:50:29 +02:00
|
|
|
*
|
|
|
|
* @package LBRYPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LBRY_Network_Parser
|
|
|
|
{
|
2018-10-05 23:50:42 +02:00
|
|
|
public $converter = null;
|
|
|
|
|
2018-09-11 22:10:15 +02:00
|
|
|
public function __construct()
|
2018-09-01 01:50:29 +02:00
|
|
|
{
|
2018-10-06 00:53:04 +02:00
|
|
|
// COMBAK: Composer is not safe in a wordpress environment. May have to write our own package.
|
2018-10-05 23:50:42 +02:00
|
|
|
require_once LBRY_ABSPATH . 'vendor/autoload.php';
|
2018-10-06 00:53:04 +02:00
|
|
|
$this->converter = new HtmlConverter(array(
|
2020-04-01 18:47:29 +02:00
|
|
|
'strip_tags' => true
|
2018-10-06 00:53:04 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-10-12 09:42:40 +02:00
|
|
|
/**
|
|
|
|
* Converts a post into markdown.
|
|
|
|
* @param WP_Post $post The post to be converted
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function convert_to_markdown($post)
|
2018-10-06 00:53:04 +02:00
|
|
|
{
|
2018-10-12 09:42:40 +02:00
|
|
|
// $title = '<h1>' . $post->post_title . '</h1>';
|
|
|
|
//
|
|
|
|
// $featured_image = get_the_post_thumbnail($post);
|
|
|
|
//
|
|
|
|
// $content = $title;
|
|
|
|
// if ($featured_image) {
|
|
|
|
// $content .= $featured_image . '<br />';
|
|
|
|
// }
|
|
|
|
$content = apply_filters('the_content', $post->post_content);
|
2018-10-06 00:53:04 +02:00
|
|
|
$converted = $this->converter->convert($content);
|
|
|
|
|
|
|
|
return $converted;
|
2018-09-01 01:50:29 +02:00
|
|
|
}
|
|
|
|
}
|