aboutsummaryrefslogtreecommitdiff
path: root/viewimage.php
blob: 8534e3d30133b26b31f336c91f69d20848595292 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

	/**
	 * Tidypics full view of an image
	 * Given a GUID, this page will try and display any entity
	 * 
	 */

	// Load Elgg engine
	include_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

		// get the album entity
	$photo_guid = (int) get_input('guid');
	$photo = get_entity($photo_guid);

	// panic if we can't get it
	if (!$photo) forward();

	// set page owner based on owner of photo album
	set_page_owner($photo->owner_guid);
	$album = get_entity($photo->container_guid);
	if ($album) {
		$owner_guid = $album->container_guid;
		if ($owner_guid)
			set_page_owner($owner_guid);
	}

	$page_owner = page_owner_entity();
	if ($page_owner instanceof ElggGroup) {
		add_submenu_item(	sprintf(elgg_echo('album:group'),$page_owner->name), 
							$CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username);
	}

	$views = get_metadata_byname($photo_guid, "tp_views");
	if(!$views || intval($views["value"] == 0)) $views["value"] = 0;
	$views["value"] = $views["value"] + 1; //TODO: only add views for non-owner
	create_metadata($photo_guid, "tp_views", $views["value"], "integer", 0, 2);
	
	$viewer = get_loggedin_user();

	/*
	$metadatas = get_metadata_for_entity($photo_guid);
	$rating = 0;
	foreach($metadatas as $metadata) {
		if($metadata["owner_guid"] == $viewer["guid"]) {
			if($metadata["name"] == "rating") $rating = $metadata["value"];
		}
	}
	*/

	if (can_write_to_container(0, $album->container_guid)) {
		add_submenu_item(	elgg_echo('image:edit'),
							$CONFIG->wwwroot . 'pg/photos/edit/' . $photo_guid,
							'photos');
		add_submenu_item(	elgg_echo('image:delete'),
							$CONFIG->wwwroot . 'pg/photos/delete/' . $photo_guid,
							'photos',
							true);
	}

	
	$title = $photo->title . " - views: $views[value]";
	$area2 = elgg_view_title($title);
	$area2 .= elgg_view_entity($photo, true);
//	$area2 .= "<a href='$CONFIG->wwwroot" . "pg/photos/rate/$photo_guid'>Rate *</a>";

	$body = elgg_view_layout('two_column_left_sidebar', '', $area2);

	page_draw($title, $body);
?>