From dd837cbf686dd9a3212f8947f72e6e855a32243c Mon Sep 17 00:00:00 2001 From: Phantop Date: Mon, 19 Aug 2024 01:47:54 -0400 Subject: [PATCH] [PriviblurBridge] Add Priviblur (Tumblr frontend) bridge --- bridges/PriviblurBridge.php | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 bridges/PriviblurBridge.php diff --git a/bridges/PriviblurBridge.php b/bridges/PriviblurBridge.php new file mode 100644 index 00000000000..e7d39083422 --- /dev/null +++ b/bridges/PriviblurBridge.php @@ -0,0 +1,67 @@ + [ + 'name' => 'URL', + 'exampleValue' => 'https://priviblur.fly.dev', + 'required' => true, + ] + ] + ]; + + private $title; + + public function collectData() + { + $url = $this->getURI(); + $html = getSimpleHTMLDOM($url); + $html = defaultLinkTo($html, $url); + $this->title = $html->find('head title', 0)->innertext; + + $elements = $html->find('.post'); + foreach ($elements as $element) { + $item = []; + $item['author'] = $element->find('.primary-post-author .blog-name', 0)->innertext; + $item['comments'] = $element->find('.interaction-buttons > a', 1)->href; + $item['content'] = $element->find('.post-body', 0); + $item['timestamp'] = $element->find('.primary-post-author time', 0)->innertext; + $item['title'] = $item['author'] . ': ' . $item['timestamp']; + $item['uid'] = $item['comments']; // tumblr url is canonical + $item['uri'] = $element->find('.interaction-buttons > a', 0)->href; + + $tags = html_entity_decode($element->find('.post-tags', 0)->plaintext); + $tags = explode('#', $tags); + $tags = array_map('trim', $tags); + array_shift($tags); + $item['categories'] = $tags; + + $heading = $element->find('h1', 0); + if ($heading) { + $item['title'] = $heading->innertext; + } + + $this->items[] = $item; + } + } + + public function getName() + { + $name = parent::getName(); + if (isset($this->title)) { + $name = $this->title; + } + return $name; + } + + public function getURI() + { + return $this->getInput('url') ? $this->getInput('url') : parent::getURI(); + } +}