protected function get_urls_from_content($content, $cache, &$to_cache)
{
$url_pairs = array();
if (!preg_match_all('/(http|https)?:?\\/\\/[^"\'\\s<>\\\\]*/', $content, $matches) || !isset($matches[0])) {
// No URLs found, return
return $url_pairs;
}
$matches = array_unique($matches[0]);
$urls = array();
foreach ($matches as $url) {
if (!$this->url_needs_replacing($url)) {
// URL already correct, skip
continue;
}
$parts = parse_url($url);
if (!isset($parts['path'])) {
// URL doesn't have a path, continue
continue;
}
$info = pathinfo($parts['path']);
if (!isset($info['extension'])) {
// URL doesn't have a file extension, continue
continue;
}
$attachment_id = null;
$bare_url = $this->as3cf->maybe_remove_query_string($url);
if (isset($cache[$bare_url])) {
$attachment_id = $cache[$bare_url];
if ($this->is_failure($attachment_id)) {
// Attachment ID failure, continue
continue;
}
}
if (is_null($attachment_id) || is_array($attachment_id)) {
// Attachment ID not cached, need to search by URL.
$urls[] = $url;
} else {
$this->push_to_url_pairs($url_pairs, $attachment_id, $url, $to_cache);
}
}
if (!empty($urls)) {
$attachments = $this->get_attachment_ids_from_urls($urls);
foreach ($attachments as $url => $attachment_id) {
if (!$attachment_id) {
// Can't determine attachment ID, continue
$this->url_cache_failure($url, $to_cache);
continue;
}
$this->push_to_url_pairs($url_pairs, $attachment_id, $url, $to_cache);
}
}
return $url_pairs;
}