/**
  * Macro which takes a given url location for craigslist search and scrapes useful content off the page
  * @param array $location
  * @return array
  */
 private static function getRecords(array $location)
 {
     $string = getFileCache($location['url']);
     if (!$string) {
         return array();
     }
     $xml = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);
     $search_items = array();
     foreach ($xml->item as $item) {
         $info = get_object_vars($item);
         $dc_nodes = $item->children('http://purl.org/dc/elements/1.1/');
         $dc = get_object_vars($dc_nodes);
         $data = $info + $dc;
         $search_items[] = array('location' => $location['partial'], 'info' => $data);
     }
     return $search_items;
 }
Example #2
0
function renderImagePreview($file_id)
{
    if ($image = getFileCache($file_id)) {
        header("Content-type: image/jpeg");
        echo $image;
        return;
    }
    //Cache Miss
    $file = getFile($file_id);
    $image = imagecreatefromstring($file['contents']);
    unset($file);
    $width = imagesx($image);
    $height = imagesy($image);
    if ($width > getConfigVar('PREVIEW_IMAGE_MAXPXS') or $height > getConfigVar('PREVIEW_IMAGE_MAXPXS')) {
        $ratio = getConfigVar('PREVIEW_IMAGE_MAXPXS') / max($width, $height);
        $newwidth = $width * $ratio;
        $newheight = $height * $ratio;
        $resampled = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresampled($resampled, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        imagedestroy($image);
        $image = $resampled;
        unset($resampled);
    }
    header('Content-type: image/jpeg');
    ob_start();
    imagejpeg($image);
    imagedestroy($image);
    commitAddFileCache($file_id, ob_get_flush());
}