]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
cleaned up tagging views to better integrate with image class
authorCash Costello <cash.costello@gmail.com>
Tue, 25 Aug 2009 12:03:29 +0000 (12:03 +0000)
committerCash Costello <cash.costello@gmail.com>
Tue, 25 Aug 2009 12:03:29 +0000 (12:03 +0000)
lib/image.php
views/default/object/image.php
views/default/tidypics/image_menu.php
views/default/tidypics/tagging.php

index cb4182f0151746b253233947a87854226b64910c..7986335ed218810a16e51d8633465006c5368995 100644 (file)
                        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 . '&amp;subtype=image&amp;object=object';
+                               $phototag_link = $CONFIG->wwwroot . 'search/?tag=' . $phototag_text . '&amp;subtype=image&amp;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)) {
                                        $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;
                }
        }
        
index dd225f02f9ff3daf71ab2ad1335f7729a18c717c..3b79172236ff7dbf9bdc2a170ee62207278f6ff1 100644 (file)
@@ -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") {
                        ?>
                        <div class="tidypics_album_images">
-                               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $file_guid;?>&size=small" alt="thumbnail"/></a>
+                               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $image_guid;?>&size=small" alt="thumbnail"/></a>
                        </div>
                        <?php
                }
@@ -51,7 +39,7 @@
                        if ($numcomments)
                                $info .= ", <a href=\"{$image->getURL()}\">" . sprintf(elgg_echo("comments")) . " (" . $numcomments . ")</a>";
                        $info .= "</p>";
-                       $icon = "<a href=\"{$image->getURL()}\">" . '<img src="' . $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $file_guid . '&size=thumb" alt="' . $title . '" /></a>';
+                       $icon = "<a href=\"{$image->getURL()}\">" . '<img src="' . $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $image_guid . '&size=thumb" alt="' . $title . '" /></a>';
 
                        echo elgg_view_listing($icon, $info);
                }
@@ -62,7 +50,7 @@
  ****************************************************************/
        } else if (get_context() == "front") {
 ?>
-               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $file_guid;?>&amp;size=thumb" class="tidypics_album_cover" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" /></a>
+               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $image_guid;?>&amp;size=thumb" class="tidypics_album_cover" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" /></a>
 <?php
        } else {
 
@@ -74,7 +62,7 @@
                if (!$vars['full']) {
 ?>
        <div class="tidypics_album_images">
-               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $file_guid;?>&size=small" alt="thumbnail"/></a>
+               <a href="<?php echo $image->getURL();?>"><img src="<?php echo $vars['url'];?>mod/tidypics/thumbnail.php?file_guid=<?php echo $image_guid;?>&size=small" alt="thumbnail"/></a>
        </div>
 <?php
                } else {
                                
                                // only non-owner views count
                                if ($owner->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;
 
                        $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
 
                                }
 
                                if ($_SESSION['image_sort'])
-                                       $current = array_search($file_guid, $_SESSION['image_sort']);
+                                       $current = array_search($image_guid, $_SESSION['image_sort']);
                        }
 
                        if ($current != 0)
                <div id="tidypics_image_wrapper">
                        <?php
                                if (get_plugin_setting('download_link', 'tidypics') != "disabled") {  
-                                       echo "<a href=\"{$vars['url']}action/tidypics/download?file_guid={$file_guid}&amp;view=inline\" title=\"{$title}\"><img id=\"tidypics_image\"  src=\"{$vars['url']}mod/tidypics/thumbnail.php?file_guid={$file_guid}&amp;size=large\" alt=\"{$title}\" /></a>";
+                                       echo "<a href=\"{$vars['url']}action/tidypics/download?file_guid={$image_guid}&amp;view=inline\" title=\"{$title}\"><img id=\"tidypics_image\"  src=\"{$vars['url']}mod/tidypics/thumbnail.php?file_guid={$image_guid}&amp;size=large\" alt=\"{$title}\" /></a>";
                                } else {
-                                       echo "<img id=\"tidypics_image\"  src=\"{$vars['url']}mod/tidypics/thumbnail.php?file_guid={$file_guid}&amp;size=large\" alt=\"{$title}\" />";
+                                       echo "<img id=\"tidypics_image\"  src=\"{$vars['url']}mod/tidypics/thumbnail.php?file_guid={$image_guid}&amp;size=large\" alt=\"{$title}\" />";
                                }
                        ?>
                        <div class="clearfloat"></div>
                        // image menu (start tagging, download, etc.)
                        
                        echo '<div id="tidypics_controls"><ul>';
-                       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 '</ul></div>'; 
                        
                        // 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, ) );
                        }
                        
                        if (get_plugin_setting('exif', 'tidypics') == "enabled") {
 ?>
-                               <?php echo elgg_view('tidypics/exif', array('guid'=> $file_guid)); ?>
+                               <?php echo elgg_view('tidypics/exif', array('guid'=> $image_guid)); ?>
 <?php          } ?>
                <div class="tidypics_info">
 <?php if (!is_null($tags)) { ?>
index d6568360c9367fd9e62fb67750855031c0dc391b..afbb34f21266e921c8191e69bd112b5c1f6912d6 100644 (file)
@@ -10,7 +10,7 @@
         *\r
         **************************************************************************/\r
 \r
-       $image_guid = $vars['file_guid'];\r
+       $image_guid = $vars['image_guid'];\r
        $viewer = $vars['viewer'];\r
        $owner = $vars['owner'];\r
        $anytags = $vars['anytags'];\r
index f911fe217ee7611c3ecebd137cc700c97e2cefe3..7062d942a7febe781f2af30c71751e0757a63f99 100644 (file)
@@ -1,20 +1,26 @@
 <?php\r
-       $photo_tags = $vars['photo_tags'];\r
-       $links = $vars['links'];\r
-       $photo_tags_json = $vars['photo_tags_json'];\r
-       $file_guid = $vars['file_guid'];\r
+\r
+       $image = $vars['image'];\r
        $viewer = $vars['viewer'];\r
        $owner = $vars['owner'];\r
 \r
+       // get photo tags\r
+       $tag_info = $image->getPhotoTags();\r
+\r
+       // defining json text as "" makes sure the tagging javascript code doesn't throw errors if no tags\r
+       $photo_tags_json = "\"\"";\r
+       if ($tag_info) {\r
+               $photo_tags_json = $tag_info['json'];\r
+       }\r
        \r
-       if ($photo_tags) { \r
+       if ($tag_info) { \r
 ?>\r
 <div id="tidypics_phototags_list">\r
        <h3><?php echo elgg_echo('tidypics:inthisphoto') ?></h3>\r
        <ul>\r
 <?php\r
-               foreach ($links as $id=>$link) {\r
-                       echo "<li><a class='tidypics_phototag_links' id='taglink{$id}' href='{$link[1]}'>{$link[0]}</a></li>";\r
+               foreach ($tag_info['links'] as $id=>$link) {\r
+                       echo "<li><a class='tidypics_phototag_links' id='taglink{$id}' href='{$link['url']}'>{$link['text']}</a></li>";\r
                }\r
 ?>\r
        </ul>\r
@@ -41,7 +47,7 @@
                ksort($friend_array);\r
 \r
                $content = "<div id='tidypics_tagmenu_left'>";\r
-               $content .= "<input type='hidden' name='image_guid' value='{$file_guid}' />";\r
+               $content .= "<input type='hidden' name='image_guid' value='{$image->guid}' />";\r
                $content .= "<input type='hidden' name='coordinates' id='coordinates' value='' />";\r
                $content .= "<input type='hidden' name='user_id' id='user_id' value='' />";\r
                $content .= "<input type='hidden' name='word' id='word' value='' />";\r
 <div id="tidypics_delete_tag_menu" class="tidypics_popup">\r
 <div id='tidypics_popup_header'><h3><?php echo elgg_echo('tidypics:deltag_title'); ?></h3></div>\r
 <?php\r
-       if ($photo_tags) {\r
-               $content = "<input type='hidden' name='image_guid' value='{$file_guid}' />";\r
-               foreach ($links as $id => $text) {\r
+       if ($tag_info) {\r
+               $content = "<input type='hidden' name='image_guid' value='{$image->guid}' />";\r
+               foreach ($tag_info['links'] as $id => $link) {\r
                        $name = "tags[{$id}]";\r
-                       $content .= elgg_view("input/checkboxes", array('options' => array($text[0] => $text[0]), 'internalname' => $name, 'value' => '' ));\r
+                       $content .= elgg_view("input/checkboxes", array('options' => array($link['text'] => $link['text']), 'internalname' => $name, 'value' => '' ));\r
                }\r
 \r
                $content .= "<input type='submit' value='" . elgg_echo('tidypics:actiondelete') . "' class='submit_button' />";\r