Skip to content

Commit

Permalink
[VkBridge] Save internal links in posts and get hashtags before makin…
Browse files Browse the repository at this point in the history
…g item (RSS-Bridge#1363)
  • Loading branch information
em92 authored and teromene committed Nov 18, 2019
1 parent adfc84b commit 55556a4
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions bridges/VkBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,41 @@ public function collectData()
$a->outertext = '';
}

// fix links and get post hashtags
$hashtags = array();
foreach($post->find('a') as $a) {
$href = $a->getAttribute('href');
$innertext = $a->innertext;

$hashtag_prefix = '/feed?section=search&q=%23';
$hashtag = null;

if ($href && substr($href, 0, strlen($hashtag_prefix)) === $hashtag_prefix) {
$hashtag = urldecode(substr($href, strlen($hashtag_prefix)));
} else if (substr($innertext, 0, 1) == '#') {
$hashtag = $innertext;
}

if ($hashtag) {
$a->outertext = $innertext;
$hashtags[] = $hashtag;
continue;
}

$parsed_url = parse_url($href);

if (array_key_exists('path', $parsed_url) === false) continue;

if (strpos($parsed_url['path'], '/away.php') === 0) {
parse_str($parsed_url['query'], $parsed_query);
$a->setAttribute('href', iconv(
'windows-1251',
'utf-8//ignore',
$parsed_query['to']
));
}
}

if (is_object($post->find('div.copy_quote', 0))) {
if ($this->getInput('hide_reposts') === true) {
continue;
Expand All @@ -252,21 +287,9 @@ public function collectData()
}

$item = array();
$item['content'] = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<br><img>');
$item['content'] = strip_tags(backgroundToImg($post->find('div.wall_text', 0)->innertext), '<a><br><img>');
$item['content'] .= $content_suffix;
$item['categories'] = array();

// get post hashtags
foreach($post->find('a') as $a) {
$href = $a->getAttribute('href');
$prefix = '/feed?section=search&q=%23';
$innertext = $a->innertext;
if ($href && substr($href, 0, strlen($prefix)) === $prefix) {
$item['categories'][] = urldecode(substr($href, strlen($prefix)));
} else if (substr($innertext, 0, 1) == '#') {
$item['categories'][] = $innertext;
}
}
$item['categories'] = $hashtags;

// get post link
$post_link = $post->find('a.post_link', 0)->getAttribute('href');
Expand Down

0 comments on commit 55556a4

Please sign in to comment.