Example #1
0
function get_content($album, $level = 0)
{
    global $albumDB, $album_id, $content_id;
    $infos = array();
    foreach ($album->photos as $item) {
        if ($item->isAlbum()) {
            if ($item->hidden != 1) {
                $child = $albumDB->getAlbumByName($item->isAlbumName);
                $title = clean_text($child->fields['title']);
                $description = trim(clean_text($child->fields['description']));
                $name = clean_text($child->fields['name']);
                $matches = array();
                preg_match("/^(\\d{8})[\\/| ](.*)\$/", $title, $matches);
                if (sizeof($matches) > 0) {
                    $title = $name = $matches[2];
                    if ($description == "") {
                        $date = mktime(0, 0, 0, substr($matches[1], 4, 2), substr($matches[1], 6, 2), substr($matches[1], 0, 4));
                        setlocale(LC_TIME, "fr_CH");
                        $description = strftime("%d %B %Y", $date);
                    }
                }
                $info = array("type" => "album", "id" => $album_id, "name" => $name, "source" => convert_text($child->fields['name']), "title" => $title, "description" => $description, "level" => $level);
                $album_id++;
                $info['items'] = get_content($child, $level + 1);
                $info['upload_date'] = get_creation($info['items']);
                $infos[] = $info;
            }
        } else {
            if ($level >= 1) {
                $image_file = $item->getPhotoPath($album->getAlbumDir(), false);
                $exif = null;
                @($exif = exif_read_data($image_file, 0, true));
                unset($exif['EXIF']['MakerNote']);
                $exif_string = $exif_make = $exif_model = $exif_iso = $exif_camera_lens = $exif_camera_serial = null;
                if (!empty($exif)) {
                    if (isset($exif['IFD0']['Make'])) {
                        $exif_make = trim($exif['IFD0']['Make']);
                    }
                    if (isset($exif['IFD0']['Model'])) {
                        $exif_model = trim($exif['IFD0']['Model']);
                    }
                    if (isset($exif['EXIF']['ISOSpeedRatings'])) {
                        $exif_iso = trim($exif['EXIF']['ISOSpeedRatings']);
                    }
                    // Best Lens info is in this tag
                    if (isset($exif['EXIF']['UndefinedTag:0xA434'])) {
                        $exif_camera_lens = trim($exif['EXIF']['UndefinedTag:0xA434']);
                    }
                    $exif_string = utf8_encode(serialize($exif));
                } else {
                    $exif = null;
                }
                if (isset($item->exifData['Camera make'])) {
                    $exif_make = $item->exifData['Camera make'];
                }
                if (isset($item->exifData['Camera model'])) {
                    $exif_model = $item->exifData['Camera model'];
                }
                if (isset($item->exifData['ISO equiv.'])) {
                    $exif_iso = $item->exifData['ISO equiv.'];
                }
                $info = array("type" => "photo", "id" => $content_id, "caption" => clean_text($item->caption), "image_file" => $image_file, "capture_date" => $item->itemCaptureDate, "upload_date" => $item->uploadDate, "width" => $item->image->width, "height" => $item->image->height, "aspect_ratio" => round($item->image->width / $item->image->height, 3), "exif_string" => $exif_string, "exif_make" => $exif_make, "exif_model" => $exif_model, "exif_iso" => $exif_iso, "exif_camera_serial" => $exif_camera_serial, "exif_camera_lens" => $exif_camera_lens, "highlight" => $item->highlight == 1 ? true : false, "visibility" => $item->hidden == 1 ? 2 : 0);
                $content_id++;
                $infos[] = $info;
            }
        }
    }
    usort($infos, "order_content");
    return $infos;
}
Example #2
0
function get_content($parent = 0, $order_by = null, $captured = null)
{
    global $g3db, $album_id, $content_id;
    $query = "select * from items where parent_id=" . $parent;
    if ($order_by) {
        $query .= " order by " . $order_by;
    }
    $res = $g3db->query($query);
    while ($row = $res->fetch_assoc()) {
        if ($row['type'] == "album") {
            $title = clean_text($row['title']);
            $description = trim(clean_text($row['description']));
            $name = clean_text($row['name']);
            $item = array("type" => "album", "id" => $album_id, "name" => $name, "source" => convert_text($row['name']), "title" => $title, "description" => $description, "level" => $row['level'], "upload_date" => $row['created'], "slug" => $row['slug'], "cover" => $row['album_cover_item_id']);
            $album_id++;
            $child_order = $row['sort_column'] . " " . $row['sort_order'];
            $captured = $row['captured'];
            if ($captured == "") {
                $captured = $row['created'];
            }
            $item['items'] = get_content($row['id'], $child_order, $captured);
            if (is_array($item['items'])) {
                $item['upload_date'] = get_creation($item['items']);
            }
            $items[] = $item;
        } else {
            $image_file = urldecode(VARPATH . "albums/" . $row['relative_path_cache']);
            $exif = null;
            @($exif = exif_read_data($image_file, 0, true));
            unset($exif['EXIF']['MakerNote']);
            $exif_string = $exif_make = $exif_model = $exif_iso = $exif_camera_lens = $exif_camera_serial = null;
            if (!array_key_exists('GPS', $exif)) {
                $query = "select latitude, longitude from exif_coordinates where item_id=" . $row['id'];
                $gps_res = $g3db->query($query);
                $gps_row = $gps_res->fetch_assoc();
                $lon = $gps_row['longitude'];
                $lat = $gps_row['latitude'];
                $latref = $lat > 0 ? "N" : "S";
                $latinfo[0] = floor(abs($lat)) . "/1";
                $latinfo[1] = floor((abs($lat) - floor(abs($lat))) * 60 * 1000000) . "/1000000";
                $latinfo[2] = "0/1";
                $lonref = $lon > 0 ? "E" : "W";
                $loninfo[0] = floor(abs($lon)) . "/1";
                $loninfo[1] = floor((abs($lon) - floor(abs($lon))) * 60 * 1000000) . "/1000000";
                $loninfo[2] = "0/1";
                $exif['GPS'] = array("GPSVersion" => "", "GPSLatitudeRef" => $latref, "GPSLatitude" => $latinfo, "GPSLongitudeRef" => $lonref, "GPSLongitude" => $loninfo, "GPSMapDatum" => "WGS-84");
                $sectionsFound = array();
                if (array_key_exists('FILE', $exif)) {
                    if (array_key_exists('SectionsFound', $exif['FILE'])) {
                        $sectionsFound = split(",", $exif['FILE']['SectionsFound']);
                        $sectionsFound = array_map('trim', $sectionsFound);
                    }
                }
                $sectionsFound[] = "GPS";
                $exif['FILE']['SectionsFound'] = implode(", ", $sectionsFound);
            }
            if (!empty($exif)) {
                if (isset($exif['IFD0']['Make'])) {
                    $exif_make = trim($exif['IFD0']['Make']);
                }
                if (isset($exif['IFD0']['Model'])) {
                    $exif_model = trim($exif['IFD0']['Model']);
                }
                if (isset($exif['EXIF']['ISOSpeedRatings'])) {
                    $exif_iso = trim($exif['EXIF']['ISOSpeedRatings']);
                }
                // Best Lens info is in this tag
                if (isset($exif['EXIF']['UndefinedTag:0xA434'])) {
                    $exif_camera_lens = trim($exif['EXIF']['UndefinedTag:0xA434']);
                }
                $exif_string = utf8_encode(serialize($exif));
            } else {
                $exif = null;
            }
            if (!isset($old_capture_date) || $old_capture_date == "") {
                $old_capture_date = $captured;
            }
            $capture_date = $row['captured'];
            if ($capture_date == "") {
                $capture_date = $old_capture_date;
            }
            $old_capture_date = $capture_date;
            $item = array("type" => "photo", "id" => $content_id, "source_id" => $row['id'], "caption" => clean_text($row['description']), "image_file" => $image_file, "capture_date" => $capture_date, "upload_date" => $row['created'], "width" => $row['width'], "height" => $row['height'], "aspect_ratio" => round($row['width'] / $row['height'], 3), "exif_string" => $exif_string, "exif_make" => $exif_make, "exif_model" => $exif_model, "exif_iso" => $exif_iso, "exif_camera_serial" => $exif_camera_serial, "exif_camera_lens" => $exif_camera_lens, "level" => $row['level'], "slug" => $row['slug'], "name" => clean_text($row['title']), "visibility" => 0);
            $content_id++;
            $items[] = $item;
        }
    }
    return $items;
}