1
0
Fork 0
forked from blallo/rss-bridge

[FacebookBridge] Handle summary posts

Previously summary posts were ignored which resulted in the last
two posts not showing up in the feed (the latest two are shown in
the summary post).

Now summary posts are treated like regular posts, returning them
as part of the regular feed.

References #502, #505
This commit is contained in:
logmanoriginal 2017-04-10 13:04:38 +02:00
parent 2500d0df93
commit e221358ead

View file

@ -168,89 +168,96 @@ EOD;
$this->authorName = $author; $this->authorName = $author;
foreach($element->children() as $post){ foreach($element->children() as $cell){
// Ignore summary posts // Manage summary posts
if(strpos($post->class, '_3xaf') !== false) continue; if(strpos($cell->class, '_3xaf') !== false){
$posts = $cell->children();
} else {
$posts = array($cell);
}
$item = array(); foreach($posts as $post){
if(count($post->find('abbr')) > 0){ $item = array();
//Retrieve post contents if(count($post->find('abbr')) > 0){
$content = preg_replace(
'/(?i)><div class=\"clearfix([^>]+)>(.+?)div\ class=\"userContent\"/i',
'',
$post);
$content = preg_replace( //Retrieve post contents
'/(?i)><div class=\"_59tj([^>]+)>(.+?)<\/div><\/div><a/i', $content = preg_replace(
'', '/(?i)><div class=\"clearfix([^>]+)>(.+?)div\ class=\"userContent\"/i',
$content); '',
$post);
$content = preg_replace( $content = preg_replace(
'/(?i)><div class=\"_3dp([^>]+)>(.+?)div\ class=\"[^u]+userContent\"/i', '/(?i)><div class=\"_59tj([^>]+)>(.+?)<\/div><\/div><a/i',
'', '',
$content); $content);
$content = preg_replace( $content = preg_replace(
'/(?i)><div class=\"_4l5([^>]+)>(.+?)<\/div>/i', '/(?i)><div class=\"_3dp([^>]+)>(.+?)div\ class=\"[^u]+userContent\"/i',
'', '',
$content); $content);
//Remove html nodes, keep only img, links, basic formatting $content = preg_replace(
$content = strip_tags($content, '<a><img><i><u><br><p>'); '/(?i)><div class=\"_4l5([^>]+)>(.+?)<\/div>/i',
'',
$content);
//Adapt link hrefs: convert relative links into absolute links and bypass external link redirection //Remove html nodes, keep only img, links, basic formatting
$content = preg_replace_callback('/ href=\"([^"]+)\"/i', $unescape_fb_link, $content); $content = strip_tags($content, '<a><img><i><u><br><p>');
//Clean useless html tag properties and fix link closing tags //Adapt link hrefs: convert relative links into absolute links and bypass external link redirection
foreach (array( $content = preg_replace_callback('/ href=\"([^"]+)\"/i', $unescape_fb_link, $content);
'onmouseover',
'onclick',
'target',
'ajaxify',
'tabindex',
'class',
'style',
'data-[^=]*',
'aria-[^=]*',
'role',
'rel',
'id') as $property_name)
$content = preg_replace('/ ' . $property_name . '=\"[^"]*\"/i', '', $content);
$content = preg_replace('/<\/a [^>]+>/i', '</a>', $content);
//Convert textual representation of emoticons eg //Clean useless html tag properties and fix link closing tags
//"<i><u>smile emoticon</u></i>" back to ASCII emoticons eg ":)" foreach (array(
$content = preg_replace_callback( 'onmouseover',
'/<i><u>([^ <>]+) ([^<>]+)<\/u><\/i>/i', 'onclick',
$unescape_fb_emote, 'target',
$content 'ajaxify',
); 'tabindex',
'class',
'style',
'data-[^=]*',
'aria-[^=]*',
'role',
'rel',
'id') as $property_name)
$content = preg_replace('/ ' . $property_name . '=\"[^"]*\"/i', '', $content);
$content = preg_replace('/<\/a [^>]+>/i', '</a>', $content);
//Retrieve date of the post //Convert textual representation of emoticons eg
$date = $post->find("abbr")[0]; //"<i><u>smile emoticon</u></i>" back to ASCII emoticons eg ":)"
if(isset($date) && $date->hasAttribute('data-utime')){ $content = preg_replace_callback(
$date = $date->getAttribute('data-utime'); '/<i><u>([^ <>]+) ([^<>]+)<\/u><\/i>/i',
} else { $unescape_fb_emote,
$date = 0; $content
);
//Retrieve date of the post
$date = $post->find("abbr")[0];
if(isset($date) && $date->hasAttribute('data-utime')){
$date = $date->getAttribute('data-utime');
} else {
$date = 0;
}
//Build title from username and content
$title = $author;
if(strlen($title) > 24)
$title = substr($title, 0, strpos(wordwrap($title, 24), "\n")) . '...';
$title = $title . ' | ' . strip_tags($content);
if(strlen($title) > 64)
$title = substr($title, 0, strpos(wordwrap($title, 64), "\n")) . '...';
//Build and add final item
$item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href');
$item['content'] = $content;
$item['title'] = $title;
$item['author'] = $author;
$item['timestamp'] = $date;
$this->items[] = $item;
} }
//Build title from username and content
$title = $author;
if(strlen($title) > 24)
$title = substr($title, 0, strpos(wordwrap($title, 24), "\n")) . '...';
$title = $title . ' | ' . strip_tags($content);
if(strlen($title) > 64)
$title = substr($title, 0, strpos(wordwrap($title, 64), "\n")) . '...';
//Build and add final item
$item['uri'] = self::URI . $post->find('abbr')[0]->parent()->getAttribute('href');
$item['content'] = $content;
$item['title'] = $title;
$item['author'] = $author;
$item['timestamp'] = $date;
$this->items[] = $item;
} }
} }
} }