diff options
-rw-r--r-- | friendmostviewed.php | 13 | ||||
-rw-r--r-- | mostrecentimages.php | 4 | ||||
-rw-r--r-- | mostviewedimages.php | 22 | ||||
-rw-r--r-- | viewimage.php | 20 | ||||
-rw-r--r-- | views/default/object/image.php | 31 | ||||
-rw-r--r-- | yourmostviewed.php | 24 |
6 files changed, 75 insertions, 39 deletions
diff --git a/friendmostviewed.php b/friendmostviewed.php index a196f51af..4f832b228 100644 --- a/friendmostviewed.php +++ b/friendmostviewed.php @@ -40,6 +40,19 @@ WHERE ent.owner_guid = " . $user->guid . " ORDER BY (views+0) DESC LIMIT $max"; + + $sql = "SELECT ent.guid, count( * ) AS views + FROM `my_elggentities` ent + INNER JOIN " . $prefix . "entity_subtypes sub ON ent.subtype = sub.id + AND sub.subtype = 'image' + INNER JOIN " . $prefix . "annotations ann1 ON ann1.entity_guid = ent.guid + INNER JOIN " . $prefix . "metastrings ms ON ms.id = ann1.name_id + AND ms.string = 'tp_view' + WHERE ann1.owner_guid = " . $user->guid . " + GROUP BY ent.guid + ORDER BY views DESC + LIMIT $max"; + $result = get_data($sql); $entities = array(); diff --git a/mostrecentimages.php b/mostrecentimages.php index 53d8ef236..e42cea4ae 100644 --- a/mostrecentimages.php +++ b/mostrecentimages.php @@ -8,14 +8,18 @@ // Load Elgg engine include_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + include_once(dirname(__FILE__) . "/notice.php"); $max = 8; $images = list_entities("object", "image", 0, $max, false, false, true); $title = "Most recent images"; $area2 = elgg_view_title($title); + $notice = tp_notice(); + $area2 .= $notice->text; $area2 .= $images; $body = elgg_view_layout('two_column_left_sidebar', '', $area2); page_draw($title, $body); + if($notice->showMessage == true) system_message($notice->text); ?>
\ No newline at end of file diff --git a/mostviewedimages.php b/mostviewedimages.php index 8831dc33e..5bbbcf5e7 100644 --- a/mostviewedimages.php +++ b/mostviewedimages.php @@ -12,18 +12,26 @@ global $CONFIG; $prefix = $CONFIG->dbprefix; $max = 24; - //grab the top views (metadata 'tp_views') for $max number of entities - //ignores entity subtypes - $sql = "select md.entity_guid, md.owner_guid, md.enabled, ms.string as views from " . $prefix . "metadata md - inner join " . $prefix . "metastrings ms on md.value_id = ms.id - inner join " . $prefix . "metastrings ms2 on md.name_id = ms2.id and ms2.string = 'tp_views' - order by (views+0) desc LIMIT $max"; + + //this works but is wildly inefficient + //$annotations = get_annotations(0, "object", "image", "tp_view", "", "", 5000); + + $sql = "SELECT ent.guid, count( * ) AS views + FROM `my_elggentities` ent + INNER JOIN " . $prefix . "entity_subtypes sub ON ent.subtype = sub.id + AND sub.subtype = 'image' + INNER JOIN " . $prefix . "annotations ann1 ON ann1.entity_guid = ent.guid + INNER JOIN " . $prefix . "metastrings ms ON ms.id = ann1.name_id + AND ms.string = 'tp_view' + GROUP BY ent.guid + ORDER BY views DESC + LIMIT $max"; $result = get_data($sql); $entities = array(); foreach($result as $entity) { - $entities[] = get_entity($entity->entity_guid); + $entities[] = get_entity($entity->guid); } $title = "Most viewed images"; diff --git a/viewimage.php b/viewimage.php index 8534e3d30..3a0d42b5d 100644 --- a/viewimage.php +++ b/viewimage.php @@ -31,23 +31,6 @@ $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,
@@ -59,10 +42,9 @@ }
- $title = $photo->title . " - views: $views[value]";
+ $title = $photo->title;
$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);
diff --git a/views/default/object/image.php b/views/default/object/image.php index 09a121256..13a94fc7d 100644 --- a/views/default/object/image.php +++ b/views/default/object/image.php @@ -88,7 +88,26 @@ if ($photo_tags) { // //////////////////////////////////////////////////////// - + // Get view information + + $viewer = get_loggedin_user(); + + //who is viewing? + if($viewer->guid) { + $the_viewer = $viewer->guid; + } else { + $the_viewer = 0; + } + + create_annotation($file_guid, "tp_view", "1", "integer", $the_viewer, 2); + $views_a = get_annotations($file_guid, "object", "image", "tp_view"); + $views = count($views_a); + + $my_views = 0; + foreach($views_a as $view) { + if($view->owner_guid == $the_viewer && $the_viewer != 0) $my_views++; + } + // Build back and next links $back = ''; @@ -123,17 +142,19 @@ if ($photo_tags) { <div id="tidypics_wrapper"> <div id="tidypics_breadcrumbs"> - <?php echo elgg_view('tidypics/breadcrumbs', array('album' => $album,) ); ?> + <?php echo elgg_view('tidypics/breadcrumbs', array('album' => $album,) ); ?> <br /> + Views: <?=$views ?> <?= $my_views ? " ($my_views by me)" : ""; ?> </div> <div id="tidypics_desc"> <?php echo autop($desc); ?> </div> <div id="tidypics_image_nav"> - <?php echo $back . $next; ?> + <?php echo $back . " " . $next; ?> </div> <div id="tidypics_image_wrapper"> <?php echo '<img id="tidypics_image"' . ' src="' . $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $file_guid . '&size=large" alt="' . $title . '"/>'; ?> + <div class="clearfloat"></div> </div> <div id="tidypics_controls"> @@ -159,7 +180,11 @@ if ($photo_tags) { <?php if (!is_null($tags)) { ?> <div class="object_tag_string"><?php echo elgg_view('output/tags',array('value' => $tags));?></div> <?php } ?> +<div id="rate_container"> + <?php echo elgg_view('rate/rate', array('entity'=> $vars['entity'])); ?> +</div> <? + echo elgg_echo('image:by');?> <b><a href="<?php echo $vars['url']; ?>pg/profile/<?php echo $owner->username; ?>"><?php echo $owner->name; ?></a></b> <?php echo $friendlytime; ?> </div> diff --git a/yourmostviewed.php b/yourmostviewed.php index f9a1af88a..84cc2ca10 100644 --- a/yourmostviewed.php +++ b/yourmostviewed.php @@ -13,20 +13,24 @@ global $CONFIG; $prefix = $CONFIG->dbprefix; $max = 24; - //grab the top views (metadata 'tp_views') for $max number of entities - //ignores entity subtypes - $sql = "SELECT md.entity_guid, md.owner_guid, md.enabled, ms.string AS views from " . $prefix . "entities ent - INNER JOIN " . $prefix . "metadata md ON md.entity_guid = ent.guid - INNER JOIN " . $prefix . "metastrings ms ON md.value_id = ms.id - INNER JOIN " . $prefix . "metastrings ms2 ON md.name_id = ms2.id AND ms2.string = 'tp_views' - WHERE ent.owner_guid = " . $viewer->guid . " - ORDER BY (views+0) DESC LIMIT $max"; - + + $sql = "SELECT ent.guid, count( * ) AS views + FROM `my_elggentities` ent + INNER JOIN " . $prefix . "entity_subtypes sub ON ent.subtype = sub.id + AND sub.subtype = 'image' + INNER JOIN " . $prefix . "annotations ann1 ON ann1.entity_guid = ent.guid + INNER JOIN " . $prefix . "metastrings ms ON ms.id = ann1.name_id + AND ms.string = 'tp_view' + WHERE ann1.owner_guid = " . $viewer->guid . " + GROUP BY ent.guid + ORDER BY views DESC + LIMIT $max"; + $result = get_data($sql); $entities = array(); foreach($result as $entity) { - $entities[] = get_entity($entity->entity_guid); + $entities[] = get_entity($entity->guid); } $title = elgg_echo("tidypics:yourmostviewed"); |