Skip to content

Commit

Permalink
[PriviblurBridge] Add Priviblur (Tumblr frontend) bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantop committed Aug 19, 2024
1 parent c0e37bc commit dd837cb
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions bridges/PriviblurBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

class PriviblurBridge extends BridgeAbstract
{
const NAME = 'Priviblur';
const MAINTAINER = 'phantop';
const URI = 'https://github.com/syeopite/priviblur';
const DESCRIPTION = 'Returns Tumblr posts from a Priviblur link';
const PARAMETERS = [
[
'url' => [
'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();
}
}

0 comments on commit dd837cb

Please sign in to comment.