",$text); $short = array_slice($tmp,0,1); return implode("
",$short); } public function longBody(string $text): string { $tmp = explode("
",$text); $long = array_slice($tmp,1); return implode("
",$long); } public function prepareData(array &$data): void { foreach($data as $index => $row) { if($row['author_type'] === 0) { $keyword = "club"; } else { $keyword = "id"; } if($row['post_type'] === "copy") { $data[$index]['author_link'] = sprintf("%s/%s%d", self::VK_LINK, $keyword, $row['author']); $data[$index]['article_link'] = sprintf("%s/%s%d?w=wall%d_%d", self::VK_LINK, $keyword, $row['author'], $row['author'], $row['copy_post_id'] ); } else { $data[$index]['author_link'] = sprintf("%s/%s%d", self::VK_LINK, $keyword, $row['author']); $data[$index]['article_link'] = sprintf("%s/%s%d?w=wall%d_%d", self::VK_LINK, $keyword, $row['author'], $row['author'], $row['id'] ); } $data[$index]['body1'] = $this->convertMediaLinks($this->shortBody($row['article'])); $data[$index]['body2'] = $this->convertMediaLinks($this->longBody($row['article'])); } } private function cleanBreaks(string $text): string { return str_replace("

", "
", $text); } public function convertMediaLinks(string $link): string { $pattern = '/(http|https):\/\/(\S+)/i'; $replacement = '$0'; $res = preg_replace($pattern,$replacement,$link); $pattern = '/\[([^\[\]\|]+)\|([^\[\]\|]+)\]/i'; $replacement = sprintf('$2', self::VK_LINK); $res = preg_replace($pattern,$replacement,$res); #https://vk.com/feed?q=%23ledstarband§ion=search $pattern = '/\#(\S+)/i'; $replacement = '$0'; $res = preg_replace($pattern, $replacement, $res); return $res; } }