mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-23 15:06:53 +00:00
[VkBridge] Unpin post if pinned
This commit is contained in:
parent
e29cd8fd1a
commit
f4a351c380
@ -46,9 +46,16 @@ class VkBridge extends BridgeAbstract
|
|||||||
$html = str_get_html($text_html);
|
$html = str_get_html($text_html);
|
||||||
$pageName = $html->find('.page_name', 0)->plaintext;
|
$pageName = $html->find('.page_name', 0)->plaintext;
|
||||||
$this->pageName = htmlspecialchars_decode($pageName);
|
$this->pageName = htmlspecialchars_decode($pageName);
|
||||||
|
$pinned_post_item = null;
|
||||||
|
$last_post_id = 0;
|
||||||
|
|
||||||
foreach ($html->find('.post') as $post) {
|
foreach ($html->find('.post') as $post) {
|
||||||
|
|
||||||
|
$is_pinned_post = false;
|
||||||
|
if (strpos($post->getAttribute('class'), 'post_fixed') !== false) {
|
||||||
|
$is_pinned_post = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_object($post->find('a.wall_post_more', 0))) {
|
if (is_object($post->find('a.wall_post_more', 0))) {
|
||||||
//delete link "show full" in content
|
//delete link "show full" in content
|
||||||
$post->find('a.wall_post_more', 0)->outertext = '';
|
$post->find('a.wall_post_more', 0)->outertext = '';
|
||||||
@ -72,6 +79,8 @@ class VkBridge extends BridgeAbstract
|
|||||||
|
|
||||||
// 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');
|
||||||
|
preg_match("/wall-?\d+_(\d+)/", $post_link, $preg_match_result);
|
||||||
|
$item['post_id'] = intval($preg_match_result[1]);
|
||||||
if (substr(self::URI, -1) == '/') {
|
if (substr(self::URI, -1) == '/') {
|
||||||
$post_link = self::URI . ltrim($post_link, "/");
|
$post_link = self::URI . ltrim($post_link, "/");
|
||||||
} else {
|
} else {
|
||||||
@ -81,9 +90,26 @@ class VkBridge extends BridgeAbstract
|
|||||||
$item['timestamp'] = $this->getTime($post);
|
$item['timestamp'] = $this->getTime($post);
|
||||||
$item['title'] = $this->getTitle($item['content']);
|
$item['title'] = $this->getTitle($item['content']);
|
||||||
$item['author'] = $pageName;
|
$item['author'] = $pageName;
|
||||||
|
if ($is_pinned_post) {
|
||||||
|
// do not append it now
|
||||||
|
$pinned_post_item = $item;
|
||||||
|
} else {
|
||||||
|
$last_post_id = $item['post_id'];
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_null($pinned_post_item)) {
|
||||||
|
return;
|
||||||
|
} else if (count($this->items) == 0) {
|
||||||
|
$this->items[] = $pinned_post_item;
|
||||||
|
} else if ($last_post_id < $pinned_post_item['post_id']) {
|
||||||
|
$this->items[] = $pinned_post_item;
|
||||||
|
usort($this->items, function ($item1, $item2) {
|
||||||
|
return $item1['post_id'] - $item2['post_id'];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTitle($content)
|
private function getTitle($content)
|
||||||
|
Loading…
Reference in New Issue
Block a user