[VkBridge] Save internal links in posts and get hashtags before making item (#1363)

This commit is contained in:
Eugene Molotov 2019-11-18 14:51:35 +05:00 committed by Lyra
parent 5b63121e92
commit 02dd778124

View file

@ -239,6 +239,41 @@ class VkBridge extends BridgeAbstract
$a->outertext = ''; $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 (is_object($post->find('div.copy_quote', 0))) {
if ($this->getInput('hide_reposts') === true) { if ($this->getInput('hide_reposts') === true) {
continue; continue;
@ -252,21 +287,9 @@ class VkBridge extends BridgeAbstract
} }
$item = array(); $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['content'] .= $content_suffix;
$item['categories'] = array(); $item['categories'] = $hashtags;
// 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;
}
}
// get post link // get post link
$post_link = $post->find('a.post_link', 0)->getAttribute('href'); $post_link = $post->find('a.post_link', 0)->getAttribute('href');