aboutsummaryrefslogtreecommitdiff
path: root/lib/image.php
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2010-05-01 12:24:16 +0000
committerCash Costello <cash.costello@gmail.com>2010-05-01 12:24:16 +0000
commitec7f055fd50b809ea50b7917b9c2e0cee5cd50d6 (patch)
tree40082090349123bfdda1b0b8ba444b9bfe5b91f8 /lib/image.php
parentfaeb704ed004777c57389f829519feeb2e235f11 (diff)
downloadelgg-ec7f055fd50b809ea50b7917b9c2e0cee5cd50d6.tar.gz
elgg-ec7f055fd50b809ea50b7917b9c2e0cee5cd50d6.tar.bz2
cleaned up library files
Diffstat (limited to 'lib/image.php')
-rw-r--r--lib/image.php331
1 files changed, 155 insertions, 176 deletions
diff --git a/lib/image.php b/lib/image.php
index 183d03c1c..4100f3f7b 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -1,200 +1,179 @@
<?php
+/**
+ * Tidypics Image class
+ *
+ * @package TidypicsImage
+ */
+
+
+class TidypicsImage extends ElggFile {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = "image";
+ }
+
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+ }
+
/**
- * Tidypics Image class
- *
+ * Has the photo been tagged with "in this photo" tags
+ *
+ * @return true/false
*/
+ public function isPhotoTagged() {
+ $num_tags = count_annotations($this->getGUID(), 'object', 'image', 'phototag');
+ if ($num_tags > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ /**
+ * Get an array of photo tag information
+ *
+ * @return array of json representations of the tags and the tag link text
+ */
+ public function getPhotoTags() {
+ global $CONFIG;
- class TidypicsImage extends ElggFile
- {
- protected function initialise_attributes()
- {
- parent::initialise_attributes();
-
- $this->attributes['subtype'] = "image";
- }
-
- public function __construct($guid = null)
- {
- parent::__construct($guid);
+ // get tags as annotations
+ $photo_tags = get_annotations($this->getGUID(), 'object', 'image', 'phototag');
+ if (!$photo_tags) {
+ // no tags or user doesn't have permission to tags, so return
+ return false;
}
-
- /**
- * Has the photo been tagged with "in this photo" tags
- *
- * @return true/false
- */
- public function isPhotoTagged()
- {
- $num_tags = count_annotations($this->getGUID(), 'object', 'image', 'phototag');
- if ($num_tags > 0) {
- return true;
+
+ $photo_tags_json = "[";
+ foreach ($photo_tags as $p) {
+ $photo_tag = unserialize($p->value);
+
+ // create link to page with other photos tagged with same tag
+ $phototag_text = $photo_tag->value;
+ $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);
+ if ($user) {
+ $phototag_text = $user->name;
+ } else {
+ $phototag_text = "unknown user";
+ }
+
+ $phototag_link = $CONFIG->wwwroot . "pg/photos/tagged/" . $photo_tag->value;
+ }
+
+ if (isset($photo_tag->x1)) {
+ // hack to handle format of Pedro Prez's tags - ugh
+ $photo_tag->coords = "\"x1\":\"{$photo_tag->x1}\",\"y1\":\"{$photo_tag->y1}\",\"width\":\"{$photo_tag->width}\",\"height\":\"{$photo_tag->height}\"";
+ $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},';
} else {
- return false;
+ $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},';
}
+
+ // prepare variable arrays for tagging view
+ $photo_tag_links[$p->id] = array('text' => $phototag_text, 'url' => $phototag_link);
}
-
- /**
- * Get an array of photo tag information
- *
- * @return array of json representations of the tags and the tag link text
- */
- public function getPhotoTags()
- {
- global $CONFIG;
-
- // get tags as annotations
- $photo_tags = get_annotations($this->getGUID(), 'object', 'image', 'phototag');
- if (!$photo_tags)
- {
- // no tags or user doesn't have permission to tags, so return
- return false;
- }
-
- $photo_tags_json = "[";
- foreach ($photo_tags as $p)
- {
- $photo_tag = unserialize($p->value);
-
- // create link to page with other photos tagged with same tag
- $phototag_text = $photo_tag->value;
- $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);
- if ($user) {
- $phototag_text = $user->name;
- } else {
- $phototag_text = "unknown user";
- }
-
- $phototag_link = $CONFIG->wwwroot . "pg/photos/tagged/" . $photo_tag->value;
- }
-
- if (isset($photo_tag->x1)) {
- // hack to handle format of Pedro Prez's tags - ugh
- $photo_tag->coords = "\"x1\":\"{$photo_tag->x1}\",\"y1\":\"{$photo_tag->y1}\",\"width\":\"{$photo_tag->width}\",\"height\":\"{$photo_tag->height}\"";
- $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},';
- } else {
- $photo_tags_json .= '{' . $photo_tag->coords . ',"text":"' . $phototag_text . '","id":"' . $p->id . '"},';
+
+ $photo_tags_json = rtrim($photo_tags_json,',');
+ $photo_tags_json .= ']';
+
+ $ret_data = array('json' => $photo_tags_json, 'links' => $photo_tag_links);
+ return $ret_data;
+ }
+
+ /**
+ * Get the view information for this image
+ *
+ * @param $viewer_guid the guid of the viewer (0 if not logged in)
+ * @return array with number of views, number of unique viewers, and number of views for this viewer
+ */
+ public function getViews($viewer_guid) {
+ $views = get_annotations($this->getGUID(), "object", "image", "tp_view", "", 0, 99999);
+ if ($views) {
+ $total_views = count($views);
+
+ if ($this->owner_guid == $viewer_guid) {
+ // get unique number of viewers
+ foreach ($views as $view) {
+ $diff_viewers[$view->owner_guid] = 1;
}
-
- // prepare variable arrays for tagging view
- $photo_tag_links[$p->id] = array('text' => $phototag_text, 'url' => $phototag_link);
+ $unique_viewers = count($diff_viewers);
}
-
- $photo_tags_json = rtrim($photo_tags_json,',');
- $photo_tags_json .= ']';
-
- $ret_data = array('json' => $photo_tags_json, 'links' => $photo_tag_links);
- return $ret_data;
- }
-
- /**
- * Get the view information for this image
- *
- * @param $viewer_guid the guid of the viewer (0 if not logged in)
- * @return array with number of views, number of unique viewers, and number of views for this viewer
- */
- public function getViews($viewer_guid)
- {
- $views = get_annotations($this->getGUID(), "object", "image", "tp_view", "", 0, 99999);
- if ($views)
- {
- $total_views = count($views);
-
- if ($this->owner_guid == $viewer_guid)
- {
- // get unique number of viewers
- foreach ($views as $view)
- {
- $diff_viewers[$view->owner_guid] = 1;
- }
- $unique_viewers = count($diff_viewers);
- }
- else if ($viewer_guid)
- {
- // get the number of times this user has viewed the photo
- $my_views = 0;
- foreach ($views as $view)
- {
- if ($view->owner_guid == $viewer_guid) {
- $my_views++;
- }
+ else if ($viewer_guid) {
+ // get the number of times this user has viewed the photo
+ $my_views = 0;
+ foreach ($views as $view) {
+ if ($view->owner_guid == $viewer_guid) {
+ $my_views++;
}
}
-
- $view_info = array("total" => $total_views, "unique" => $unique_viewers, "mine" => $my_views);
}
- else
- {
- $view_info = array("total" => 0, "unique" => 0, "mine" => 0);
- }
-
- return $view_info;
+
+ $view_info = array("total" => $total_views, "unique" => $unique_viewers, "mine" => $my_views);
}
-
- /**
- * Add a tidypics view annotation to this image
- *
- * @param $viewer_guid
- * @return none
- */
- public function addView($viewer_guid)
- {
- if ($viewer_guid != $this->owner_guid && tp_is_person()) {
- create_annotation($this->getGUID(), "tp_view", "1", "integer", $viewer_guid, ACCESS_PUBLIC);
- }
+ else {
+ $view_info = array("total" => 0, "unique" => 0, "mine" => 0);
}
+
+ return $view_info;
}
-
+
/**
- * get a list of people that can be tagged in an image
- *
- * @param $viewer entity
- * @return array of guid->name for tagging
+ * Add a tidypics view annotation to this image
+ *
+ * @param $viewer_guid
+ * @return none
*/
- function tp_get_tag_list($viewer)
- {
- $friends = get_user_friends($viewer->getGUID(), '', 999, 0);
- $friend_list = array();
- if ($friends) {
- foreach($friends as $friend) {
- //error_log("friend $friend->name");
- $friend_list[$friend->guid] = $friend->name;
- }
+ public function addView($viewer_guid) {
+ if ($viewer_guid != $this->owner_guid && tp_is_person()) {
+ create_annotation($this->getGUID(), "tp_view", "1", "integer", $viewer_guid, ACCESS_PUBLIC);
}
-
- // is this a group
- $is_group = tp_is_group_page();
- if ($is_group)
- {
- $group_guid = page_owner();
- $viewer_guid = $viewer->guid;
- $members = get_group_members($group_guid, 999);
- if (is_array($members))
- {
- foreach ($members as $member)
- {
- if ($viewer_guid != $member->guid)
- {
- $group_list[$member->guid] = $member->name;
- //error_log("group $member->name");
- }
+ }
+}
+
+/**
+ * get a list of people that can be tagged in an image
+ *
+ * @param $viewer entity
+ * @return array of guid->name for tagging
+ */
+function tp_get_tag_list($viewer) {
+ $friends = get_user_friends($viewer->getGUID(), '', 999, 0);
+ $friend_list = array();
+ if ($friends) {
+ foreach($friends as $friend) {
+ //error_log("friend $friend->name");
+ $friend_list[$friend->guid] = $friend->name;
+ }
+ }
+
+ // is this a group
+ $is_group = tp_is_group_page();
+ if ($is_group) {
+ $group_guid = page_owner();
+ $viewer_guid = $viewer->guid;
+ $members = get_group_members($group_guid, 999);
+ if (is_array($members)) {
+ foreach ($members as $member) {
+ if ($viewer_guid != $member->guid) {
+ $group_list[$member->guid] = $member->name;
+ //error_log("group $member->name");
}
-
- // combine group and friends list
- $intersect = array_intersect_key($friend_list, $group_list);
- $unique_friends = array_diff_key($friend_list, $group_list);
- $unique_members = array_diff_key($group_list, $friend_list);
- //$friend_list = array_merge($friend_list, $group_list);
- //$friend_list = array_unique($friend_list);
- $friend_list = $intersect + $unique_friends + $unique_members;
}
+
+ // combine group and friends list
+ $intersect = array_intersect_key($friend_list, $group_list);
+ $unique_friends = array_diff_key($friend_list, $group_list);
+ $unique_members = array_diff_key($group_list, $friend_list);
+ //$friend_list = array_merge($friend_list, $group_list);
+ //$friend_list = array_unique($friend_list);
+ $friend_list = $intersect + $unique_friends + $unique_members;
}
-
- asort($friend_list);
-
- return $friend_list;
}
-?> \ No newline at end of file
+
+ asort($friend_list);
+
+ return $friend_list;
+}