function to_array($options = array()) { $options['auth'] = isset($options['auth']) ? $options['auth'] : false; $options['in_album'] = isset($options['in_album']) ? $options['in_album'] : false; $exclude = array('storage_url', 'storage_url_midsize', 'deleted', 'featured_order', 'favorite_order', 'old_slug', 'has_exif', 'has_iptc', 'tags_old'); $bools = array('featured', 'favorite'); $dates = array('uploaded_on', 'modified_on', 'captured_on', 'featured_on', 'file_modified_on', 'published_on'); $strings = array('title', 'caption'); list($data, $fields) = $this->prepare_for_output($options, $exclude, $bools, $dates, $strings); $data = Shutter::filter('api.content.before', array($data, $this, $options)); if (!$data['featured']) { unset($data['featured_on']); } if (!$data['favorite']) { unset($data['favorited_on']); } $koken_url_info = $this->config->item('koken_url_info'); if ($this->file_type != 0 && !empty($this->lg_preview)) { $preview_file = array_shift(explode(':', $this->lg_preview)); } if ($options['auth'] || $data['file_type'] != 0 || (int) $data['max_download'] === 1) { $pathinfo = pathinfo($this->filename); $path = 'storage/originals/' . str_replace(DIRECTORY_SEPARATOR, '/', $this->path) . '/' . $pathinfo['basename']; $url = $koken_url_info->base . $path; if (preg_match('/^https?:/', $this->filename)) { $data['original'] = array(); } else { if (!empty($this->storage_url)) { $data['original'] = array('url' => $this->storage_url, 'width' => (int) $this->width, 'height' => (int) $this->height); if (!empty($this->storage_url_midsize)) { $data['original']['midsize'] = $this->storage_url_midsize; } } else { $data['original'] = array('url' => $url, 'relative_url' => '/' . $path, 'width' => (int) $this->width, 'height' => (int) $this->height); } } if (isset($preview_file)) { $path .= '_previews/' . $preview_file; $url = $koken_url_info->base . $path; list($pw, $ph) = getimagesize(FCPATH . $path); $data['original']['preview'] = array('url' => $url, 'relative_url' => '/' . $path, 'width' => $pw, 'height' => $ph); } } if (!$options['auth'] && $data['visibility'] == 0) { unset($data['internal_id']); } if (!preg_match('~https?://~', $this->filename)) { $info = pathinfo($this->filename); $mimes = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'flv' => 'video/x-flv', 'f4v' => 'video/f4v', 'swf' => 'application/x-shockwave-flash', 'mov' => 'video/mp4', 'mp4' => 'video/mp4', 'm4v' => 'video/x-m4v', '3gp' => 'video/3gpp', '3g2' => 'video/3gpp2', 'mp3' => 'audio/mpeg'); if (array_key_exists(strtolower($info['extension']), $mimes)) { $data['mime_type'] = $mimes[strtolower($info['extension'])]; } else { if (function_exists('mime_content_type')) { $data['mime_type'] = mime_content_type($this->path_to_original()); } else { $data['mime_type'] = ''; } } } else { $data['mime_type'] = ''; } $data['__koken__'] = 'content'; if (!isset($options['include_presets']) || $options['include_presets']) { include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php'; if ($this->file_type > 0 && empty($this->lg_preview)) { $prefix = $koken_url_info->base . 'admin/images/no-thumb,'; $data['cache_path'] = array('prefix' => $prefix, 'extension' => 'png'); $data['presets'] = array(); foreach (DarkroomUtils::$presets as $name => $opts) { $h = $opts['width'] * 2 / 3; $data['presets'][$name] = array('url' => $koken_url_info->base . "admin/images/no-thumb,{$name}.png", 'width' => $opts['width'], 'height' => round($h)); $data['presets'][$name]['cropped'] = array('url' => $koken_url_info->base . "admin/images/no-thumb,{$name}.crop.png", 'width' => $opts['width'], 'height' => $opts['width']); } } else { if ($this->file_type > 0 || !preg_match('~^https?://~', $this->filename)) { if (isset($info['extension'])) { $prefix = preg_replace("/\\.{$info['extension']}\$/", '', basename($this->filename)); } else { $prefix = basename($this->filename); } if (isset($preview_file)) { $info = pathinfo($preview_file); } $cache_base = $koken_url_info->base . (KOKEN_REWRITE ? 'storage/cache/images' : 'i.php?') . '/' . str_replace('\\', '/', $this->cache_path) . '/' . $prefix . ','; $data['cache_path'] = array('prefix' => $cache_base); $data['cache_path']['extension'] = $data['file_modified_on']['timestamp'] . '.' . $info['extension']; $data['presets'] = array(); foreach (DarkroomUtils::$presets as $name => $opts) { $dims = $this->compute_cache_size($opts['width'], $opts['height']); if ($dims) { list($w, $h) = $dims; $data['presets'][$name] = array('url' => $cache_base . "{$name}.{$data['file_modified_on']['timestamp']}.{$info['extension']}", 'hidpi_url' => $cache_base . "{$name}.2x.{$data['file_modified_on']['timestamp']}.{$info['extension']}", 'width' => (int) $w, 'height' => (int) $h); list($cx, $cy) = $this->compute_cache_size($opts['width'], $opts['height'], true); $data['presets'][$name]['cropped'] = array('url' => $cache_base . "{$name}.crop.{$data['file_modified_on']['timestamp']}.{$info['extension']}", 'hidpi_url' => $cache_base . "{$name}.crop.2x.{$data['file_modified_on']['timestamp']}.{$info['extension']}", 'width' => (int) $cx, 'height' => (int) $cy); } } } } } if ($data['file_type'] == 0) { unset($data['duration']); } if (array_key_exists('duration', $data)) { $r = $data['duration']; $data['duration'] = array(); $data['duration']['raw'] = $r; $m = floor($r / 60); $s = str_pad(floor($r % 60), 2, '0', STR_PAD_LEFT); if ($m > 60) { $h = floor($m / 60); $m = str_pad(floor($m % 60), 2, '0', STR_PAD_LEFT); $m = "{$h}:{$m}"; } $data['duration']['clean'] = "{$m}:{$s}"; } $data['iptc'] = $data['iptc_fields'] = $data['exif'] = $data['exif_fields'] = array(); if ($this->has_iptc) { list($data['iptc'], $data['iptc_fields']) = $this->iptc_to_human(); } $data['geolocation'] = false; if ($this->has_exif) { if (!isset($options['exif'])) { $options['exif'] = 'all'; } $exif = $this->_get_exif_data(); if (isset($exif['GPS']['GPSLatitude'])) { include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'gps.php'; $gps = new GPS($exif['GPS']); $data['geolocation'] = array('latitude' => rtrim(sprintf('%.12f', $gps->latitude()), '0'), 'longitude' => rtrim(sprintf('%.12f', $gps->longitude()), '0')); } list($data['exif'], $data['exif_fields']) = $this->exif_to_human($data['exif'], $options['exif']); } if (array_key_exists('file_type', $data)) { switch ($data['file_type']) { // TODO: Make this array and include mime type? Ehhh? case 0: $data['file_type'] = 'image'; break; case 1: $data['file_type'] = 'video'; break; case 2: $data['file_type'] = 'audio'; break; } } if (array_key_exists('visibility', $data)) { switch ($data['visibility']) { case 1: $raw = 'unlisted'; break; case 2: $raw = 'private'; break; default: $raw = 'public'; break; } $data['visibility'] = array('raw' => $raw, 'clean' => ucwords($raw)); $data['public'] = $raw === 'public'; } if (array_key_exists('max_download', $data)) { switch ($data['max_download']) { case 0: $data['max_download'] = 'none'; $clean = 'None'; break; case 1: $data['max_download'] = 'original'; $clean = 'Original'; break; case 2: $data['max_download'] = 'huge'; $clean = 'Huge (2048)'; break; case 3: $data['max_download'] = 'xlarge'; $clean = 'X-Large (1600)'; break; case 4: $data['max_download'] = 'large'; $clean = 'Large (1024)'; break; case 5: $data['max_download'] = 'medium_large'; $clean = 'Medium-Large (800)'; break; case 6: $data['max_download'] = 'medium'; $clean = 'Medium (480)'; break; } $data['max_download'] = array('raw' => $data['max_download'], 'clean' => $clean); } if (array_key_exists('license', $data) && !is_null($data['license'])) { if ($data['license'] == 'all') { $clean = '© All rights reserved'; } else { // Data is stored as commercial,modifications ... (y|n),(y,s,n) // Example: NonCommercial ShareAlike == n,s list($commercial, $mods) = explode(',', $data['license']); $license_url = 'http://creativecommons.org/licenses/by'; if ($commercial == 'y') { $clean = 'Commercial'; } else { $license_url .= '-nc'; $clean = 'NonCommercial'; } switch ($mods) { case 'y': // Nothing to do here, standard license break; case 's': $clean .= '-ShareAlike'; $license_url .= '-sa'; break; case 'n': $clean .= '-NoDerivs'; $license_url .= '-nd'; break; } $license_url .= '/3.0/deed.en_US'; } $data['license'] = array('raw' => $data['license'], 'clean' => $clean); if (isset($license_url)) { $data['license']['url'] = $license_url; } } $data['tags'] = $this->_get_tags_for_output($options); $data['categories'] = array('count' => is_null($this->category_count) ? $this->categories->count() : (int) $this->category_count, 'url' => $koken_url_info->base . 'api.php?/content/' . $data['id'] . '/categories'); $data['albums'] = array('count' => is_null($this->album_count) ? $this->albums->count() : (int) $this->album_count, 'url' => $koken_url_info->base . 'api.php?/content/' . $data['id'] . '/albums'); if (isset($options['order_by']) && in_array($options['order_by'], array('uploaded_on', 'modified_on', 'captured_on'))) { $data['date'] =& $data[$options['order_by']]; } else { $data['date'] =& $data['published_on']; } if ($data['visibility'] === 'private') { $data['url'] = false; } else { $cat = isset($options['category']) ? $options['category'] : (isset($options['context']) && strpos($options['context'], 'category-') === 0 ? str_replace('category-', '', $options['context']) : false); if ($cat) { if (is_numeric($cat)) { foreach ($this->categories->get_iterated() as $c) { if ($c->id == $cat) { $cat = $c->slug; break; } } } } $data['url'] = $this->url(array('date' => $data['published_on'], 'album' => $options['in_album'], 'tag' => isset($options['tags']) ? $options['tags'] : (isset($options['context']) && strpos($options['context'], 'tag-') === 0 ? str_replace('tag-', '', $options['context']) : false), 'category' => $cat, 'favorite' => isset($options['favorite']) || isset($options['context']) && $options['context'] === 'favorites' ? true : false, 'feature' => isset($options['featured']) || isset($options['context']) && $options['context'] === 'features' ? true : false)); if ($data['url']) { list($data['__koken_url'], $data['url']) = $data['url']; $data['canonical_url'] = $data['url']; } } if (!$options['auth'] && $data['visibility'] === 'unlisted') { unset($data['url']); } if (empty($data['source'])) { $data['source'] = false; } else { $data['source'] = array('title' => $data['source'], 'url' => $data['source_url']); } unset($data['source_url']); $final = Shutter::filter('api.content', array($data, $this, $options)); if (!isset($final['html']) || empty($final['html'])) { $final['html'] = false; } return $final; }