[GooglePlusPostBridge] General cleanup

This commit is contained in:
logmanoriginal 2018-07-31 18:55:35 +02:00
parent fb79a67370
commit 5f3c55b808
1 changed files with 35 additions and 38 deletions

View File

@ -1,8 +1,8 @@
<?php <?php
class GooglePlusPostBridge extends BridgeAbstract{ class GooglePlusPostBridge extends BridgeAbstract{
protected $_title; private $title;
protected $_url; private $url;
const MAINTAINER = 'Grummfy, logmanoriginal'; const MAINTAINER = 'Grummfy, logmanoriginal';
const NAME = 'Google Plus Post Bridge'; const NAME = 'Google Plus Post Bridge';
@ -18,6 +18,7 @@ class GooglePlusPostBridge extends BridgeAbstract{
)); ));
public function collectData(){ public function collectData(){
$username = $this->getInput('username'); $username = $this->getInput('username');
// Usernames start with a + if it's not an ID // Usernames start with a + if it's not an ID
@ -25,23 +26,19 @@ class GooglePlusPostBridge extends BridgeAbstract{
$username = '+' . $username; $username = '+' . $username;
} }
// get content parsed $html = getSimpleHTMLDOM(static::URI . '/' . urlencode($username) . '/posts')
$html = getSimpleHTMLDOMCached(static::URI . '/' . urlencode($username) . '/posts')
or returnServerError('No results for this query.'); or returnServerError('No results for this query.');
$html = defaultLinkTo($html, static::URI); $html = defaultLinkTo($html, static::URI);
// get title, url, ... there is a lot of intresting stuff in meta $this->title = $html->find('meta[property=og:title]', 0)->getAttribute('content');
$this->_title = $html->find('meta[property=og:title]', 0)->getAttribute('content'); $this->url = $html->find('meta[property=og:url]', 0)->getAttribute('content');
$this->_url = $html->find('meta[property=og:url]', 0)->getAttribute('content');
// I don't even know where to start with this discusting html...
foreach($html->find('div[jsname=WsjYwc]') as $post) { foreach($html->find('div[jsname=WsjYwc]') as $post) {
$item = array(); $item = array();
$item['author'] = $item['fullname'] = $post->find('div div div div a', 0)->innertext; $item['author'] = $post->find('div div div div a', 0)->innertext;
$item['id'] = $post->find('div div div', 0)->getAttribute('id');
$item['avatar'] = $post->find('div img', 0)->src;
$item['uri'] = $post->find('div div div a', 1)->href; $item['uri'] = $post->find('div div div a', 1)->href;
$timestamp = $post->find('a.qXj2He span', 0); $timestamp = $post->find('a.qXj2He span', 0);
@ -53,29 +50,28 @@ class GooglePlusPostBridge extends BridgeAbstract{
$timestamp->getAttribute('aria-label'))); $timestamp->getAttribute('aria-label')));
} }
$item['content'] = ''; $message = $post->find('div[jsname=EjRJtf]', 0);
// avatar display $item['content'] = '<div style="float: left; padding: 10px;"><a href="'
$item['content'] .= '<div style="float:left; margin: 0 0.5em 0.5em 0;"><a href="' . $this->url
. static::URI . '"><img align="top" alt="'
. '/'
. urlencode($this->getInput('username'));
$item['content'] .= '"><img align="top" alt="'
. $item['author'] . $item['author']
. '" src="' . '" src="'
. $item['avatar'] . $post->find('div img', 0)->src
. '" /></a></div>'; . '" /></a></div><div>'
. trim(strip_tags($message, '<a><p><div><img>'))
. '</div>';
$content = $post->find('div[jsname=EjRJtf]', 0); // Make title at least 50 characters long, but don't add '...' if it is shorter!
// extract plaintext if(strlen($message->plaintext) > 50) {
$item['content_simple'] = $content->plaintext; $end = strpos($message->plaintext, ' ', 50);
$item['title'] = substr($item['content_simple'], 0, 72) . '...'; }
$content = $content->innertext; if(strlen(substr($message->plaintext, 0, $end)) === strlen($message->plaintext)) {
$item['title'] = $message->plaintext;
$item['content'] .= '<div style="margin-top: -1.5em">' . $content . '</div>'; } else {
$item['content'] = trim(strip_tags($item['content'], '<a><p><div><img>')); $item['title'] = substr($message->plaintext, 0, $end) . '...';
}
$media = $post->find('[jsname="MTOxpb"]', 0); $media = $post->find('[jsname="MTOxpb"]', 0);
@ -84,23 +80,29 @@ class GooglePlusPostBridge extends BridgeAbstract{
$item['enclosures'] = array(); $item['enclosures'] = array();
foreach($media->find('img') as $img) { foreach($media->find('img') as $img) {
$item['enclosures'][] = $this->fixImage($img)->src; $item['enclosures'][] = $this->fixImage($img)->src;
} }
} }
// Add custom parameters (only useful for JSON or Plaintext)
$item['fullname'] = $item['author'];
$item['avatar'] = $post->find('div img', 0)->src;
$item['id'] = $post->find('div div div', 0)->getAttribute('id');
$item['content_simple'] = $message->plaintext;
$this->items[] = $item; $this->items[] = $item;
} }
} }
public function getName(){ public function getName(){
return $this->_title ?: 'Google Plus Post Bridge'; return $this->title ?: 'Google Plus Post Bridge';
} }
public function getURI(){ public function getURI(){
return $this->_url ?: parent::getURI(); return $this->url ?: parent::getURI();
} }
private function fixImage($img) { private function fixImage($img) {
@ -152,12 +154,7 @@ class GooglePlusPostBridge extends BridgeAbstract{
} }
echo $img->src . '<br>';
$img->src = $this->build_url($urlparts); $img->src = $this->build_url($urlparts);
echo $img->src . '<br><br>';
return $img; return $img;
} }