aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2012-07-14 14:42:37 -0400
committerCash Costello <cash.costello@gmail.com>2012-07-14 14:42:37 -0400
commit0eec78495e5f63a80c2b04fcb87bda1ccb2b6648 (patch)
tree42b2bb3b35e8d6ba2924f0aabe42f218beea6bca
parent65548983c054a48fe0adb94c327847a7101db390 (diff)
downloadelgg-0eec78495e5f63a80c2b04fcb87bda1ccb2b6648.tar.gz
elgg-0eec78495e5f63a80c2b04fcb87bda1ccb2b6648.tar.bz2
added exif back
-rw-r--r--classes/TidypicsImage.php3
-rw-r--r--lib/exif.php39
-rw-r--r--pages/photos/image/view.php2
-rw-r--r--start.php1
-rw-r--r--views/default/photos/sidebar.php12
-rw-r--r--views/default/photos/sidebar/exif.php20
-rw-r--r--views/default/tidypics/exif.php14
7 files changed, 56 insertions, 35 deletions
diff --git a/classes/TidypicsImage.php b/classes/TidypicsImage.php
index 26a3483a9..9081bc1fe 100644
--- a/classes/TidypicsImage.php
+++ b/classes/TidypicsImage.php
@@ -38,6 +38,7 @@ class TidypicsImage extends ElggFile {
$this->simpletype = "image";
$this->saveImageFile($data);
$this->saveThumbnails();
+ $this->extractExifData();
}
return true;
@@ -326,7 +327,7 @@ class TidypicsImage extends ElggFile {
* @warning image file must be saved first
*/
public function extractExifData() {
- include_once dirname(dirname(__FILE__)) . "/lib/exif.php";
+ elgg_load_library('tidypics:exif');
td_get_exif($this);
}
diff --git a/lib/exif.php b/lib/exif.php
index 43a640336..8ca0dde0c 100644
--- a/lib/exif.php
+++ b/lib/exif.php
@@ -8,47 +8,48 @@
/**
* Pull EXIF data from image file
*
- * @param TidypicsImage $file
+ * @param TidypicsImage $image
*/
-function td_get_exif($file) {
+function td_get_exif($image) {
// catch for those who don't have exif module loaded
if (!is_callable('exif_read_data')) {
return;
}
- $mime = $file->mimetype;
+ $mime = $image->mimetype;
if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') {
return;
}
- $filename = $file->getFilenameOnFilestore();
- $exif = exif_read_data($filename);
- create_metadata($file->getGUID(), "tp_exif", serialize($exif), "text", $file->getOwnerGUID(), ACCESS_PUBLIC);
+ $filename = $image->getFilenameOnFilestore();
+ $exif = exif_read_data($filename, 'IFD0,EXIF', true);
+ if (is_array($exif)) {
+ $data = array_merge($exif['IFD0'], $exif['EXIF']);
+ foreach ($data as $key => $value) {
+ if (is_string($value)) {
+ // there are sometimes unicode characters that cause problems with serialize
+ $data[$key] = preg_replace( '/[^[:print:]]/', '', $value);
+ }
+ }
+ $image->tp_exif = serialize($data);
+ }
}
/**
* Grab array of EXIF data for display
*
- * @param int $file_guid GUID of TidypicsImage
+ * @param TidypicsImage $image
* @return array|false
*/
-function tp_exif_formatted($file_guid) {
-
- $metadata_exif = get_metadata_byname($file_guid, "tp_exif");
- if (!$metadata_exif) {
- // //try to load it from the file if its not in the database
- $file = new ElggFile($file_guid);
- td_get_exif($file);
- unset($file);
- $metadata_exif = get_metadata_byname($file_guid, "tp_exif");
- }
+function tp_exif_formatted($image) {
- if (!$metadata_exif) {
+ $exif = $image->tp_exif;
+ if (!$exif) {
return false;
}
- $exif = unserialize($metadata_exif["value"]);
+ $exif = unserialize($exif);
$model = $exif['Model'];
if (!$model) {
diff --git a/pages/photos/image/view.php b/pages/photos/image/view.php
index 1d359b6c7..fc4a01320 100644
--- a/pages/photos/image/view.php
+++ b/pages/photos/image/view.php
@@ -57,7 +57,7 @@ $body = elgg_view_layout('content', array(
'filter' => false,
'content' => $content,
'title' => $photo->getTitle(),
- 'sidebar' => elgg_view('tidypics/sidebar', array(
+ 'sidebar' => elgg_view('photos/sidebar', array(
'page' => 'view',
'image' => $photo,
)),
diff --git a/start.php b/start.php
index 9295dc7eb..1e851b8f3 100644
--- a/start.php
+++ b/start.php
@@ -17,6 +17,7 @@ function tidypics_init() {
elgg_register_library('tidypics:core', "$base_dir/tidypics.php");
elgg_register_library('tidypics:upload', "$base_dir/upload.php");
elgg_register_library('tidypics:resize', "$base_dir/resize.php");
+ elgg_register_library('tidypics:exif', "$base_dir/exif.php");
elgg_load_library('tidypics:core');
// Set up site menu
diff --git a/views/default/photos/sidebar.php b/views/default/photos/sidebar.php
new file mode 100644
index 000000000..4c0feb72c
--- /dev/null
+++ b/views/default/photos/sidebar.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Sidebar view
+ */
+
+$page = elgg_extract('page', $vars);
+$image = elgg_extract('image', $vars);
+if ($image && $page == 'view') {
+ if (elgg_get_plugin_setting('exif', 'tidypics')) {
+ echo elgg_view('photos/sidebar/exif', $vars);
+ }
+}
diff --git a/views/default/photos/sidebar/exif.php b/views/default/photos/sidebar/exif.php
new file mode 100644
index 000000000..1d4444b53
--- /dev/null
+++ b/views/default/photos/sidebar/exif.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * EXIF sidebar module
+ */
+
+$image = $vars['image'];
+
+elgg_load_library('tidypics:exif');
+
+$exif = tp_exif_formatted($image);
+if ($exif) {
+ $title = "EXIF";
+ $body = '<table class="elgg-table elgg-table-alt">';
+ foreach ($exif as $key => $value) {
+ $body .= "<tr><td>$key</td><td>$value</td></tr>";
+ }
+ $body .= '</table>';
+
+ echo elgg_view_module('aside', $title, $body);
+}
diff --git a/views/default/tidypics/exif.php b/views/default/tidypics/exif.php
deleted file mode 100644
index f21e2eff7..000000000
--- a/views/default/tidypics/exif.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-$guid = $vars['guid'];
-
-$exif = tp_exif_formatted($guid);
-if ($exif) {
- echo '<div id="tidypics_exif">';
- foreach ($exif as $name => $value) {
- echo $name . ': ' . $value . '<br />';
- }
- echo '</div>';
-}
-
-?> \ No newline at end of file