private function handleUrls($text, $filter = '')
{
// Check for images and download them, replace urls
preg_match_all('/<img.*src="(.*)".*\\/>/Ui', $text, $matchesImages);
if (isset($matchesImages[1]) && !empty($matchesImages[1])) {
// Walk through image links
foreach ($matchesImages[1] as $key => $file) {
// Should we bother looking at this file?
if (!empty($filter) && !mb_stristr($file, $filter)) {
continue;
}
$noSize = preg_replace('/\\-\\d+x\\d+/i', '', $file);
if (isset($this->attachments[mb_strtolower($file)])) {
$text = str_replace($file, $this->attachments[mb_strtolower($file)], $text);
} elseif (isset($this->attachments[mb_strtolower($noSize)])) {
$text = str_replace($file, $this->attachments[mb_strtolower($noSize)], $text);
}
}
}
// Check for links to schrijf.be and try to replace them
preg_match_all('/<a.*href="(.*)".*\\/>/Ui', $text, $matchesLinks);
if (isset($matchesLinks[1]) && !empty($matchesLinks[1])) {
// Walk through links
foreach ($matchesLinks[1] as $key => $link) {
// Should we bother looking at this file?
if (!empty($filter) && !mb_stristr($link, $filter)) {
continue;
}
$noSize = preg_replace('/\\-\\d+x\\d+/i', '', $link);
if (isset($this->attachments[mb_strtolower($link)])) {
$text = str_replace($link, $this->attachments[mb_strtolower($link)], $text);
} elseif (isset($this->attachments[mb_strtolower($noSize)])) {
$text = str_replace($link, $this->attachments[mb_strtolower($noSize)], $text);
}
}
}
return $text;
}