From 31a654b61284e0f848645aeb436d0335bc765abf Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Tue, 25 Aug 2009 12:03:29 +0000 Subject: cleaned up tagging views to better integrate with image class --- lib/image.php | 21 ++++++++++++---- views/default/object/image.php | 45 ++++++++++++----------------------- views/default/tidypics/image_menu.php | 2 +- views/default/tidypics/tagging.php | 30 +++++++++++++---------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/lib/image.php b/lib/image.php index cb4182f01..7986335ed 100644 --- a/lib/image.php +++ b/lib/image.php @@ -19,8 +19,19 @@ parent::__construct($guid); } + public function isPhotoTagged() + { + $num_tags = count_annotations($this->getGUID(), 'object', 'image', 'phototag'); + if ($num_tags > 0) + return true; + else + return false; + } + public function getPhotoTags() { + global $CONFIG; + // get tags as annotations $photo_tags = get_annotations($this->getGUID(), 'object', 'image', 'phototag'); if (!$photo_tags) @@ -36,7 +47,7 @@ // create link to page with other photos tagged with same tag $phototag_text = $photo_tag->value; - $phototag_link = $vars['url'] . 'search/?tag=' . $phototag_text . '&subtype=image&object=object'; + $phototag_link = $CONFIG->wwwroot . 'search/?tag=' . $phototag_text . '&subtype=image&object=object'; if ($photo_tag->type === 'user') { $user = get_entity($photo_tag->value); @@ -45,7 +56,7 @@ else $phototag_text = "unknown user"; - $phototag_link = $vars['url'] . "pg/photos/tagged/" . $photo_tag->value; + $phototag_link = $CONFIG->wwwroot . "pg/photos/tagged/" . $photo_tag->value; } if (isset($photo_tag->x1)) { @@ -56,14 +67,14 @@ $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},'; // prepare variable arrays for tagging view - $photo_tag_links[$p->id] = array($phototag_text, $phototag_link); + $photo_tag_links[$p->id] = array('text' => $phototag_text, 'url' => $phototag_link); } $photo_tags_json = rtrim($photo_tags_json,','); $photo_tags_json .= ']'; - $rt = array('raw' => $photo_tags, 'json' => $photo_tags_json, 'links' => $photo_tag_links); - return $rt; + $ret_data = array('json' => $photo_tags_json, 'links' => $photo_tag_links); + return $ret_data; } } diff --git a/views/default/object/image.php b/views/default/object/image.php index dd225f02f..3b7917223 100644 --- a/views/default/object/image.php +++ b/views/default/object/image.php @@ -8,27 +8,15 @@ include_once dirname(dirname(dirname(dirname(__FILE__)))) . "/lib/exif.php"; $image = $vars['entity']; - $file_guid = $image->getGUID(); + $image_guid = $image->getGUID(); $tags = $image->tags; $title = $image->title; $desc = $image->description; $owner = $image->getOwnerEntity(); $friendlytime = friendly_time($image->time_created); - $mime = $image->mimetype; -///////////////////////////////////////////////////// -// get photo tags from database - $photo_tags_json = "\"\""; - - $tag_info = $image->getPhotoTags(); - if ($tag_info) { - $photo_tags = $tag_info['raw']; - $photo_tags_json = $tag_info['json']; - $photo_tag_links = $tag_info['links']; - } - /******************************************************************** * * search view of an image @@ -39,7 +27,7 @@ if (get_input('search_viewtype') == "gallery") { ?>
- thumbnail + thumbnail
getURL()}\">" . sprintf(elgg_echo("comments")) . " (" . $numcomments . ")"; $info .= "

"; - $icon = "getURL()}\">" . '' . $title . ''; + $icon = "getURL()}\">" . '' . $title . ''; echo elgg_view_listing($icon, $info); } @@ -62,7 +50,7 @@ ****************************************************************/ } else if (get_context() == "front") { ?> - <?php echo $title; ?> + <?php echo $title; ?>
- thumbnail + thumbnail
guid != $view->owner_guid) - create_annotation($file_guid, "tp_view", "1", "integer", $the_viewer, ACCESS_PUBLIC); - $views_a = get_annotations($file_guid, "object", "image", "tp_view", "", 0, 9999); + create_annotation($image_guid, "tp_view", "1", "integer", $the_viewer, ACCESS_PUBLIC); + $views_a = get_annotations($image_guid, "object", "image", "tp_view", "", 0, 9999); $views = count($views_a); $my_views = 0; @@ -125,7 +113,7 @@ $album = get_entity($image->container_guid); - $current = array_search($file_guid, $_SESSION['image_sort']); + $current = array_search($image_guid, $_SESSION['image_sort']); if (!$current) { // means we are no longer using the correct album array @@ -138,7 +126,7 @@ } if ($_SESSION['image_sort']) - $current = array_search($file_guid, $_SESSION['image_sort']); + $current = array_search($image_guid, $_SESSION['image_sort']); } if ($current != 0) @@ -177,9 +165,9 @@
\"{$title}\""; + echo "\"{$title}\""; } else { - echo "\"{$title}\""; + echo "\"{$title}\""; } ?>
@@ -188,19 +176,16 @@ // image menu (start tagging, download, etc.) echo '
    '; - echo elgg_view('tidypics/image_menu', array('file_guid' => $file_guid, + echo elgg_view('tidypics/image_menu', array('image_guid' => $image_guid, 'viewer' => $viewer, 'owner' => $owner, - 'anytags' => $photo_tags != '', + 'anytags' => $image->isPhotoTagged(), 'album' => $album, ) ); echo '
'; // tagging code if (get_plugin_setting('tagging', 'tidypics') != "disabled") { - echo elgg_view('tidypics/tagging', array( 'photo_tags' => $photo_tags, - 'links' => $photo_tag_links, - 'photo_tags_json' => $photo_tags_json, - 'file_guid' => $file_guid, + echo elgg_view('tidypics/tagging', array( 'image' => $image, 'viewer' => $viewer, 'owner' => $owner, ) ); } @@ -208,7 +193,7 @@ if (get_plugin_setting('exif', 'tidypics') == "enabled") { ?> - $file_guid)); ?> + $image_guid)); ?>
diff --git a/views/default/tidypics/image_menu.php b/views/default/tidypics/image_menu.php index d6568360c..afbb34f21 100644 --- a/views/default/tidypics/image_menu.php +++ b/views/default/tidypics/image_menu.php @@ -10,7 +10,7 @@ * **************************************************************************/ - $image_guid = $vars['file_guid']; + $image_guid = $vars['image_guid']; $viewer = $vars['viewer']; $owner = $vars['owner']; $anytags = $vars['anytags']; diff --git a/views/default/tidypics/tagging.php b/views/default/tidypics/tagging.php index f911fe217..7062d942a 100644 --- a/views/default/tidypics/tagging.php +++ b/views/default/tidypics/tagging.php @@ -1,20 +1,26 @@ getPhotoTags(); + + // defining json text as "" makes sure the tagging javascript code doesn't throw errors if no tags + $photo_tags_json = "\"\""; + if ($tag_info) { + $photo_tags_json = $tag_info['json']; + } - if ($photo_tags) { + if ($tag_info) { ?>

@@ -41,7 +47,7 @@ ksort($friend_array); $content = "
"; - $content .= ""; + $content .= ""; $content .= ""; $content .= ""; $content .= ""; @@ -66,11 +72,11 @@

"; - foreach ($links as $id => $text) { + if ($tag_info) { + $content = ""; + foreach ($tag_info['links'] as $id => $link) { $name = "tags[{$id}]"; - $content .= elgg_view("input/checkboxes", array('options' => array($text[0] => $text[0]), 'internalname' => $name, 'value' => '' )); + $content .= elgg_view("input/checkboxes", array('options' => array($link['text'] => $link['text']), 'internalname' => $name, 'value' => '' )); } $content .= ""; -- cgit v1.2.3