From 20ab73de5248b3418bbbad27850e3d3e093c473c Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 2 Jan 2012 12:45:16 -0500 Subject: added photo tagging - but not displaying or deleting tags yet --- actions/addtag.php | 105 ------------------------------- actions/photos/image/tag.php | 99 +++++++++++++++++++++++++++++ languages/en.php | 4 +- pages/photos/image/view.php | 5 ++ start.php | 23 +++++-- views/default/forms/photos/image/tag.php | 33 ++++++++++ views/default/js/photos/tagging.php | 73 +++++++++++++++++++++ views/default/object/image/full.php | 4 +- views/default/photos/css.php | 56 ++++++++++++++++- views/default/photos/tagging/help.php | 19 ++++++ views/default/photos/tagging/select.php | 16 +++++ 11 files changed, 321 insertions(+), 116 deletions(-) delete mode 100644 actions/addtag.php create mode 100644 actions/photos/image/tag.php create mode 100644 views/default/forms/photos/image/tag.php create mode 100644 views/default/js/photos/tagging.php create mode 100644 views/default/photos/tagging/help.php create mode 100644 views/default/photos/tagging/select.php diff --git a/actions/addtag.php b/actions/addtag.php deleted file mode 100644 index 97418f495..000000000 --- a/actions/addtag.php +++ /dev/null @@ -1,105 +0,0 @@ -tags)) { - if ($image->tags != $word) { - $new_word_tag = true; - $tagarray = $image->tags . ',' . $word; - $tagarray = string_to_tag_array($tagarray); - } - } else { - if (!in_array($word, $image->tags)) { - $new_word_tag = true; - $tagarray = $image->tags; - $tagarray[] = $word; - } - } -} - -// add new tag now so it is available in search -if ($new_word_tag) { - $image->clearMetadata('tags'); - $image->tags = $tagarray; -} - -// create string for javascript tag object -$tag->coords = $coordinates_str; -$tag->type = $relationships_type; -$tag->value = $value; - -$access_id = $image->getAccessID(); -$owner_id = get_loggedin_userid(); -$tagger = get_loggedin_user(); - -//Save annotation -$annotation_id = $image->annotate('phototag', serialize($tag), $access_id, $owner_id); -if ($annotation_id) { - // if tag is a user id, add relationship for searching (find all images with user x) - if ($relationships_type === 'user') { - if (!check_entity_relationship($user_id, 'phototag', $image_guid)) { - add_entity_relationship($user_id, 'phototag', $image_guid); - - // also add this to the river - subject is image, object is the tagged user - add_to_river('river/object/image/tag', 'tag', $tagger->guid, $user_id, $access_id, 0, $annotation_id); - - // notify user of tagging as long as not self - if ($owner_id != $user_id) { - notify_user( - $user_id, - $owner_id, - elgg_echo('tidypics:tag:subject'), - sprintf( - elgg_echo('tidypics:tag:body'), - $image->title, - $tagger->name, - $image->getURL() - ) - ); - } - } - } - - system_message(elgg_echo("tidypics:phototagging:success")); -} - - -forward($_SERVER['HTTP_REFERER']); diff --git a/actions/photos/image/tag.php b/actions/photos/image/tag.php new file mode 100644 index 000000000..0c7ce06ae --- /dev/null +++ b/actions/photos/image/tag.php @@ -0,0 +1,99 @@ +tags)) { + if ($image->tags != $word) { + $new_word_tag = true; + $tagarray = $image->tags . ',' . $word; + $tagarray = string_to_tag_array($tagarray); + } + } else { + if (!in_array($word, $image->tags)) { + $new_word_tag = true; + $tagarray = $image->tags; + $tagarray[] = $word; + } + } +} + +// add new tag now so it is available in search +if ($new_word_tag) { + $image->clearMetadata('tags'); + $image->tags = $tagarray; +} +*/ + +$tag = new stdClass(); +$tag->coords = $coordinates_str; +$tag->type = 'user'; +$tag->value = get_user_by_username($username)->getGUID(); +$access_id = $image->getAccessID(); + +$annotation_id = $image->annotate('phototag', serialize($tag), $access_id); +if ($annotation_id) { + // if tag is a user id, add relationship for searching (find all images with user x) + if ($tag->type === 'user') { + if (!check_entity_relationship($tag->value, 'phototag', $image_guid)) { + add_entity_relationship($tag->value, 'phototag', $image_guid); +/* + // also add this to the river - subject is image, object is the tagged user + add_to_river('river/object/image/tag', 'tag', $tagger->guid, $user_id, $access_id, 0, $annotation_id); + + // notify user of tagging as long as not self + if ($owner_id != $user_id) { + notify_user( + $user_id, + $owner_id, + elgg_echo('tidypics:tag:subject'), + sprintf( + elgg_echo('tidypics:tag:body'), + $image->title, + $tagger->name, + $image->getURL() + ) + ); + } + * + */ + } + } + + system_message(elgg_echo("tidypics:phototagging:success")); +} + +forward(REFERER); diff --git a/languages/en.php b/languages/en.php index ec65d0622..2276e4b12 100644 --- a/languages/en.php +++ b/languages/en.php @@ -45,7 +45,7 @@ $english = array( 'tidypics:friendmostviewed' => "%s's most viewed images", 'tidypics:friendmostrecent' => "%s's most recent images", 'tidypics:highestrated' => "Highest rated images", - 'tidypics:views' => "Views: %s", + 'tidypics:views' => "%s views", 'tidypics:viewsbyowner' => "by %s users (not including you)", 'tidypics:viewsbyothers' => "(%s by you)", 'tidypics:administration' => 'Tidypics Administration', @@ -129,7 +129,7 @@ $english = array( 'image:index' => "%u of %u", // tagging - 'tidypics:taginstruct' => 'Select area that you want to tag', + 'tidypics:taginstruct' => 'Select the area that you want to tag or %s', 'tidypics:deltag_title' => 'Select tags to delete', 'tidypics:finish_tagging' => 'Stop tagging', 'tidypics:tagthisphoto' => 'Tag this photo', diff --git a/pages/photos/image/view.php b/pages/photos/image/view.php index f9157a900..6db9ff529 100644 --- a/pages/photos/image/view.php +++ b/pages/photos/image/view.php @@ -17,6 +17,11 @@ if (!$photo) { $photo->addView(); +if (elgg_get_plugin_setting('tagging', 'tidypics')) { + elgg_load_js('tidypics:tagging'); + elgg_load_js('jquery.imgareaselect'); +} + // set page owner based on owner of photo album $album = $photo->getContainerEntity(); if ($album) { diff --git a/start.php b/start.php index 5638037cc..a81c1d854 100644 --- a/start.php +++ b/start.php @@ -34,6 +34,9 @@ function tidypics_init() { $js = elgg_get_simplecache_url('js', 'photos/tidypics'); elgg_register_simplecache_view('js/photos/tidypics'); elgg_register_js('tidypics', $js, 'footer'); + $js = elgg_get_simplecache_url('js', 'photos/tagging'); + elgg_register_simplecache_view('js/photos/tagging'); + elgg_register_js('tidypics:tagging', $js, 'footer'); elgg_register_js('tidypics:slideshow', 'mod/tidypics/vendors/PicLensLite/piclens_optimized.js', 'footer'); // Add photos link to owner block/hover menus @@ -93,7 +96,7 @@ function tidypics_init() { //register_action("tidypics/ajax_upload", true, "$base_dir/ajax_upload.php"); //register_action("tidypics/ajax_upload_complete", true, "$base_dir/ajax_upload_complete.php"); //register_action("tidypics/sortalbum", false, "$base_dir/sortalbum.php"); - //register_action("tidypics/addtag", false, "$base_dir/addtag.php"); + elgg_register_action("photos/image/tag", "$base_dir/image/tag.php"); //register_action("tidypics/deletetag", false, "$base_dir/deletetag.php"); elgg_register_action("photos/admin/settings", "$base_dir/admin/settings.php", 'admin'); @@ -284,15 +287,27 @@ function tidypics_entity_menu_setup($hook, $type, $return, $params) { if (elgg_instanceof($entity, 'object', 'image')) { if (elgg_get_plugin_setting('view_count', 'tidypics')) { $view_info = $entity->getViewInfo(); - $status_text = (int)$view_info['total'] . ' views'; + $text = elgg_echo('tidypics:views', array((int)$view_info['total'])); $options = array( - 'name' => 'published_status', - 'text' => "$status_text", + 'name' => 'views', + 'text' => "$text", 'href' => false, 'priority' => 90, ); $return[] = ElggMenuItem::factory($options); } + + if (elgg_get_plugin_setting('tagging', 'tidypics')) { + $options = array( + 'name' => 'tagging', + 'text' => elgg_echo('tidypics:actiontag'), + 'href' => '#', + 'title' => elgg_echo('tidypics:tagthisphoto'), + 'rel' => 'photo-tagging', + 'priority' => 80, + ); + $return[] = ElggMenuItem::factory($options); + } } if (elgg_instanceof($entity, 'object', 'album')) { diff --git a/views/default/forms/photos/image/tag.php b/views/default/forms/photos/image/tag.php new file mode 100644 index 000000000..31869be9e --- /dev/null +++ b/views/default/forms/photos/image/tag.php @@ -0,0 +1,33 @@ +'; + +echo elgg_view('input/autocomplete', array( + 'name' => 'username', + 'match_on' => 'friends', +)); + +echo elgg_view('input/hidden', array( + 'name' => 'guid', + 'value' => $vars['entity']->getGUID(), +)); + +echo elgg_view('input/hidden', array( + 'name' => 'coordinates', +)); + +echo ''; + +echo '
'; +echo elgg_view('input/submit', array( + 'value' => elgg_echo('tidypics:actiontag'), +)); +echo '
'; diff --git a/views/default/js/photos/tagging.php b/views/default/js/photos/tagging.php new file mode 100644 index 000000000..f831200e7 --- /dev/null +++ b/views/default/js/photos/tagging.php @@ -0,0 +1,73 @@ + + +elgg.provide('elgg.tidypics.tagging'); + +elgg.tidypics.tagging.init = function() { + $('[rel=photo-tagging]').click(elgg.tidypics.tagging.start); + + $('#tidypics-tagging-quit').click(elgg.tidypics.tagging.stop); +} + +/** + * Start a tagging session + */ +elgg.tidypics.tagging.start = function(event) { + + $('.tidypics-photo').imgAreaSelect({ + disable : false, + hide : false, + classPrefix : 'tidypics-tagging', + onSelectEnd : elgg.tidypics.tagging.startSelect, + onSelectStart: function() { + $('#tidypics-tagging-select').hide(); + } + }); + + $('.tidypics-photo').css({"cursor" : "crosshair"}); + + $('#tidypics-tagging-help').toggle(); + + event.preventDefault(); +} + +/** + * Stop tagging + * + * A tagging session could be completed or the user could have quit. + */ +elgg.tidypics.tagging.stop = function(event) { + $('#tidypics-tagging-help').toggle(); + $('#tidypics-tagging-select').hide(); + + $('.tidypics-photo').imgAreaSelect({hide: true, disable: true}); + $('.tidypics-photo').css({"cursor" : "pointer"}); + + event.preventDefault(); +} + +/** + * Start the selection stage of tagging + */ +elgg.tidypics.tagging.startSelect = function(img, selection) { + + var coords = '"x1":"' + selection.x1 + '",'; + coords += '"y1":"' + selection.y1 + '",'; + coords += '"width":"' + selection.width + '",'; + coords += '"height":"' + selection.height + '"'; + $("input[name=coordinates]").val(coords); + + $('#tidypics-tagging-select').show().css({ + 'top' : selection.y2 + 10, + 'left' : selection.x2 + }); +} + +elgg.register_hook_handler('init', 'system', elgg.tidypics.tagging.init); diff --git a/views/default/object/image/full.php b/views/default/object/image/full.php index e3a2c7003..33ba49739 100644 --- a/views/default/object/image/full.php +++ b/views/default/object/image/full.php @@ -51,8 +51,8 @@ echo $summary; echo '
'; echo elgg_view('object/image/navigation', $vars); -//echo elgg_view('tidypics/tagging/help'); -//echo elgg_view('tidypics/tagging/select', array('photo' => $photo)); +echo elgg_view('photos/tagging/help', $vars); +echo elgg_view('photos/tagging/select', $vars); echo $img; echo '
'; diff --git a/views/default/photos/css.php b/views/default/photos/css.php index 18f225131..31e3d9b53 100644 --- a/views/default/photos/css.php +++ b/views/default/photos/css.php @@ -1,9 +1,15 @@ +/* *************************************** + TIDYPICS +*************************************** */ .elgg-module-tidypics-album, .elgg-module-tidypics-image { width: 161px; @@ -23,6 +29,10 @@ display: block; } +.tidypics-wrapper-photo { + position: relative; +} + .tidypics-heading { color: #0054A7; } @@ -66,6 +76,46 @@ vertical-align: top; } +/* *************************************** + Tagging +*************************************** */ +.tidypics-tagging-border1 { + border: solid 2px white; +} + +.tidypics-tagging-border1, .tidypics-tagging-border2, +.tidypics-tagging-border3, .tidypics-tagging-border4 { + filter: alpha(opacity=50); + opacity: 0.5; +} + +.tidypics-tagging-handle { + background-color: #fff; + border: solid 1px #000; + filter: alpha(opacity=50); + opacity: 0.5; +} + +.tidypics-tagging-outer { + background-color: #000; + filter: alpha(opacity=50); + opacity: 0.5; +} + +.tidypics-tagging-help { + position: absolute; + left: 50%; + top: -25px; + width: 250px; + margin-left: -125px; + text-align: center; +} + +.tidypics-tagging-select { + position: absolute; + max-width: 300px; +} + diff --git a/views/default/photos/tagging/help.php b/views/default/photos/tagging/help.php new file mode 100644 index 000000000..a7f437e51 --- /dev/null +++ b/views/default/photos/tagging/help.php @@ -0,0 +1,19 @@ + elgg_echo('quit'), + 'href' => '#', + 'id' => 'tidypics-tagging-quit', +)); + +$instructions = elgg_echo('tidypics:taginstruct', array($button)); +?> + diff --git a/views/default/photos/tagging/select.php b/views/default/photos/tagging/select.php new file mode 100644 index 000000000..8894af63a --- /dev/null +++ b/views/default/photos/tagging/select.php @@ -0,0 +1,16 @@ + 'tidypics-tagging-select pam hidden', + 'id' => 'tidypics-tagging-select', +)); -- cgit v1.2.3