+
+function slurp_page($url)
+{
+ $ch = curl_init ($url);
+
+ curl_setopt ($ch, CURLOPT_HEADER, 0);
+ curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
+ curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
+ curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
+
+ ob_start();
+ $success = curl_exec ($ch);
+ $page = ob_get_contents();
+ ob_end_clean();
+
+ curl_close ($ch);
+
+ return $success ? $page : "FAILED";
+}
+
+/*
+ * Function: get_image_urls_sp
+ *
+ * Purpose: Return the image URLs from a single page
+ */
+function get_image_urls_sp($page, $url)
+{
+ preg_match_all('|<img\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
+
+ foreach (array_unique($matches[1]) as $image_link)
+ {
+ $result[] = link_to_absolute($url, $image_link);
+ }
+
+ return count($result) ? $result : 0;
+}
+
+/*
+ * Function: get_image_urls
+ *
+ * Purpose: If the page is a frameset, rerurn the image URLs from all
+ * its frame SRCes, else from the page itself.
+ */
+function get_image_urls($page, $url)
+{
+
+ preg_match_all('|<frame\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
+
+ if (count($matches[1]))
+ {
+ foreach(array_unique($matches[1]) as $frame_link)
+ {
+ $framebuf = slurp_page(link_to_absolute($url, $frame_link));
+ $result = array_merge($result, get_image_urls_sp($framebuf, link_to_absolute($url, $frame_link)));
+ }
+ }
+ else
+ {
+ $result = get_image_urls_sp($page, $url);
+ }
+
+ return array_values(array_unique($result));
+}
+
+
+/*
+ * Function: error_abort
+ * Purpose: Return an error page with $title and $message
+ */
+function error_abort($title, $message)