aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tidypics.php69
-rw-r--r--pages/lists/friendmostviewed.php59
-rw-r--r--pages/lists/mostviewedimages.php39
-rw-r--r--pages/lists/yourmostviewed.php49
-rw-r--r--start.php108
-rw-r--r--views/rss/object/album.php32
6 files changed, 155 insertions, 201 deletions
diff --git a/lib/tidypics.php b/lib/tidypics.php
index a5b713ee4..e24e4d77e 100644
--- a/lib/tidypics.php
+++ b/lib/tidypics.php
@@ -191,6 +191,75 @@
return $html;
}
+ function tp_get_entities_from_annotations_calculate_x($sum = "sum", $entity_type = "", $entity_subtype = "", $name = "", $mdname = '', $mdvalue = '', $owner_guid = 0, $limit = 10, $offset = 0, $orderdir = 'desc', $count = false)
+ {
+ global $CONFIG;
+
+ $sum = sanitise_string($sum);
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $name = get_metastring_id($name);
+ $limit = (int) $limit;
+ $offset = (int) $offset;
+ $owner_guid = (int) $owner_guid;
+ if (!empty($mdname) && !empty($mdvalue)) {
+ $meta_n = get_metastring_id($mdname);
+ $meta_v = get_metastring_id($mdvalue);
+ }
+
+ if (empty($name)) return 0;
+
+ $where = array();
+
+ if ($entity_type!="")
+ $where[] = "e.type='$entity_type'";
+ if ($owner_guid > 0)
+ $where[] = "e.owner_guid = $owner_guid";
+ if ($entity_subtype)
+ $where[] = "e.subtype=$entity_subtype";
+ if ($name!="")
+ $where[] = "a.name_id='$name'";
+
+ if (!empty($mdname) && !empty($mdvalue)) {
+ if ($mdname!="")
+ $where[] = "m.name_id='$meta_n'";
+ if ($mdvalue!="")
+ $where[] = "m.value_id='$meta_v'";
+ }
+
+ if ($sum != "count")
+ $where[] = "a.value_type='integer'"; // Limit on integer types
+
+ if (!$count) {
+ $query = "SELECT distinct e.*, $sum(ms.string) as sum ";
+ } else {
+ $query = "SELECT count(distinct e.guid) as num, $sum(ms.string) as sum ";
+ }
+ $query .= " from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}annotations a on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings ms on a.value_id=ms.id ";
+
+ if (!empty($mdname) && !empty($mdvalue)) {
+ $query .= " JOIN {$CONFIG->dbprefix}metadata m on m.entity_guid = e.guid ";
+ }
+
+ $query .= " WHERE ";
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix("a"); // now add access
+ $query .= ' and ' . get_access_sql_suffix("e"); // now add access
+ if (!$count) $query .= ' group by e.guid';
+
+ if (!$count) {
+ $query .= ' order by sum ' . $orderdir;
+ $query .= ' limit ' . $offset . ' , ' . $limit;
+ return get_data($query, "entity_row_to_elggstar");
+ } else {
+ if ($row = get_data_row($query)) {
+ return $row->num;
+ }
+ }
+ return false;
+ }
+
/**
* Is page owner a group - convenience function
*
diff --git a/pages/lists/friendmostviewed.php b/pages/lists/friendmostviewed.php
deleted file mode 100644
index 07fcd39b5..000000000
--- a/pages/lists/friendmostviewed.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
- /**
- * Tidypics Friends Albums Listing
- *
- */
-
- include_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . "/engine/start.php";
-
- //if no friends were requested, see world pictures instead, or redirect to user's friends
-/* if (is_null(get_input('username')) || get_input('username')=='') {
- if (!isloggedin()) {
- forward('pg/photos/world');
- } else {
- forward('pg/photos/friends/' . $_SESSION['user']->username);
- }
- }*/
-
- if (is_null(page_owner_entity()->name) || page_owner_entity()->name == '') {
- $friendname = get_input('username');
- } else {
- $friendname = page_owner_entity()->name;
- };
-
- //there has to be a better way to do this
- if(!$friendname) {
- $page = get_input("page");
- list($pagename, $friendname) = split("/", $page);
- }
- $user = get_user_by_username($friendname);
- global $CONFIG;
- $prefix = $CONFIG->dbprefix;
- $max = 24;
-
- $sql = "SELECT ent.guid, count( * ) AS views
- FROM " . $prefix . "entities 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 ent.owner_guid = " . $user->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->guid);
- }
-
- $title = sprintf(elgg_echo("tidypics:friendmostviewed"), $friendname);
- $area2 = elgg_view_title($title);
- $area2 .= elgg_view_entity_list($entities, $max, 0, $max, false);
- $body = elgg_view_layout('two_column_left_sidebar', '', $area2);
- page_draw($title, $body);
-
-?> \ No newline at end of file
diff --git a/pages/lists/mostviewedimages.php b/pages/lists/mostviewedimages.php
index b8cc67b51..16b9d7295 100644
--- a/pages/lists/mostviewedimages.php
+++ b/pages/lists/mostviewedimages.php
@@ -1,8 +1,7 @@
<?php
/**
- * Tidypics full view of an image
- * Given a GUID, this page will try and display any entity
+ * Most viewed images - either for a user or all site
*
*/
@@ -13,9 +12,24 @@
$prefix = $CONFIG->dbprefix;
$max = 24;
+ $owner_guid = page_owner();
+
+ //$start = microtime(true);
+ $photos = tp_get_entities_from_annotations_calculate_x(
+ 'count',
+ 'object',
+ 'image',
+ 'tp_view',
+ '',
+ '',
+ $owner_guid,
+ $max);
+ //error_log("elgg query is " . (float)(microtime(true) - $start));
+
//this works but is wildly inefficient
//$annotations = get_annotations(0, "object", "image", "tp_view", "", "", 5000);
-
+/*
+ $start = microtime(true);
$sql = "SELECT ent.guid, count( * ) AS views
FROM " . $prefix . "entities ent
INNER JOIN " . $prefix . "entity_subtypes sub ON ent.subtype = sub.id
@@ -33,15 +47,26 @@
foreach($result as $entity) {
$entities[] = get_entity($entity->guid);
}
- $title = elgg_echo("tidypics:mostviewed");
+*/
+ //error_log("custom query is " . (float)(microtime(true) - $start));
+
+ if ($owner_guid) {
+ if ($owner_guid == get_loggedin_userid()) {
+ $title = elgg_echo("tidypics:yourmostviewed");
+ } else {
+ $title = sprintf(elgg_echo("tidypics:friendmostviewed"), page_owner_entity()->name);
+ }
+ } else {
+ $title = elgg_echo("tidypics:mostviewed");
+ }
$area2 = elgg_view_title($title);
// grab the html to display the images
- $images = tp_view_entity_list($entities, $max, 0, $max, false);
+ $content = tp_view_entity_list($photos, $max, 0, $max, false);
// this view takes care of the title on the main column and the content wrapper
- $area2 = elgg_view('tidypics/content_wrapper', array('title' => $title, 'content' => $images,));
- if( empty( $area2 )) $area2 = $images;
+ $area2 = elgg_view('tidypics/content_wrapper', array('title' => $title, 'content' => $content,));
+ if( empty( $area2 )) $area2 = $content;
$body = elgg_view_layout('two_column_left_sidebar', '', $area2);
page_draw($title, $body);
diff --git a/pages/lists/yourmostviewed.php b/pages/lists/yourmostviewed.php
deleted file mode 100644
index 9155c4454..000000000
--- a/pages/lists/yourmostviewed.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?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(dirname(dirname(__FILE__))))) . "/engine/start.php";
-
- $viewer = get_loggedin_user();
-
- global $CONFIG;
- $prefix = $CONFIG->dbprefix;
- $max = 24;
-
- $sql = "SELECT ent.guid, count( * ) AS views
- FROM " . $prefix . "entities 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 ent.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->guid);
- }
-
- $title = elgg_echo("tidypics:yourmostviewed");
- $area2 = elgg_view_title($title);
-
- // grab the html to display the images
- $images = tp_view_entity_list($entities, $max, 0, $max, false);
-
- // this view takes care of the title on the main column and the content wrapper
- $area2 = elgg_view('tidypics/content_wrapper', array('title' => $title, 'content' => $images,));
- if( empty( $area2 )) $area2 = $images;
-
- $body = elgg_view_layout('two_column_left_sidebar', '', $area2);
- page_draw($title, $body);
-?> \ No newline at end of file
diff --git a/start.php b/start.php
index 6a1b95723..f56669c1f 100644
--- a/start.php
+++ b/start.php
@@ -76,7 +76,7 @@
}
/**
- * Sets up submenus for tidypics. Triggered on pagesetup.
+ * Sets up sidebar menus for tidypics. Triggered on pagesetup.
*/
function tidypics_submenus() {
@@ -98,89 +98,95 @@
$view_count = get_plugin_setting('view_count', 'tidypics');
// owner gets "your albumn", "your friends albums", "your most viewed", "your most recent"
- if (get_loggedin_userid() == $page_owner->guid && get_loggedin_userid()) {
+ if (get_loggedin_userid() && get_loggedin_userid() == $page_owner->guid) {
+
add_submenu_item( elgg_echo('album:create'),
- $CONFIG->wwwroot . "pg/photos/new/". $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/new/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( elgg_echo("album:yours"),
- $CONFIG->wwwroot . "pg/photos/owned/" . $_SESSION['user']->username,
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( elgg_echo('album:yours:friends'),
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
'tidypics-a');
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),
- $CONFIG->wwwroot . 'pg/photos/yourmostviewed',
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/",
'tidypics-a');
}
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),
- $CONFIG->wwwroot . 'pg/photos/mostrecent/' . $_SESSION['user']->username,
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/",
'tidypics-a');
} else if (isloggedin()) {
- // logged in not owner gets "your albums", "page owners albums", "page owner's friends albums", "page owner's most viewed", "page owner's most recent"
+
+ $user = get_loggedin_user();
+
+ // logged in not owner gets "page owners albums", "page owner's friends albums", "page owner's most viewed", "page owner's most recent"
+ // and then "your albums", "your most viewed", "your most recent"
add_submenu_item( elgg_echo("album:yours"),
- $CONFIG->wwwroot . "pg/photos/owned/" . $_SESSION['user']->username,
+ $CONFIG->wwwroot . "pg/photos/owned/{$user->username}/",
'tidypics-b' );
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),
- $CONFIG->wwwroot . 'pg/photos/yourmostviewed',
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$user->username}/",
'tidypics-b');
}
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),
- $CONFIG->wwwroot . 'pg/photos/mostrecent/' . $_SESSION['user']->username,
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$user->username}/",
'tidypics-b');
if($page_owner->name) { // check to make sure the owner set their display name
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name),
- $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
'tidypics-a' );
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name),
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
'tidypics-a');
if ($view_count != 'disabled') {
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostviewed'),$page_owner->name),
- $CONFIG->wwwroot . "pg/photos/friendmostviewed/". $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/",
'tidypics-a');
}
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostrecent'),$page_owner->name),
- $CONFIG->wwwroot . "pg/photos/mostrecent/". $page_owner->username,
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/",
'tidypics-a');
}
} else if ($page_owner->guid) {
// non logged in user gets "page owners albums", "page owner's friends albums"
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name),
- $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username,
- 'tidypics' );
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/",
+ 'tidypics-a' );
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name),
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username,
- 'tidypics');
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/",
+ 'tidypics-a');
}
+ // everyone gets world albums, most recent, most viewed, most recently viewed, recently commented
add_submenu_item( elgg_echo('album:all'),
$CONFIG->wwwroot . "pg/photos/world/",
'tidypics-z');
add_submenu_item( elgg_echo('tidypics:mostrecent'),
- $CONFIG->wwwroot . 'pg/photos/mostrecent',
+ $CONFIG->wwwroot . 'pg/photos/mostrecent/',
'tidypics-z');
if ($view_count != 'disabled') {
add_submenu_item( elgg_echo('tidypics:mostviewed'),
- $CONFIG->wwwroot . 'pg/photos/mostviewed',
+ $CONFIG->wwwroot . 'pg/photos/mostviewed/',
'tidypics-z');
add_submenu_item( elgg_echo('tidypics:recentlyviewed'),
- $CONFIG->wwwroot . 'pg/photos/recentlyviewed',
+ $CONFIG->wwwroot . 'pg/photos/recentlyviewed/',
'tidypics-z');
}
add_submenu_item( elgg_echo('tidypics:recentlycommented'),
- $CONFIG->wwwroot . 'pg/photos/recentlycommented',
+ $CONFIG->wwwroot . 'pg/photos/recentlycommented/',
'tidypics-z');
add_submenu_item( 'Flickr Integration',
$CONFIG->wwwroot . 'mod/tidypics/pages/flickr/setup.php',
@@ -191,6 +197,17 @@
}
/**
+ * Sets up tidypics admin menu. Triggered on pagesetup.
+ */
+ function tidypics_adminmenu()
+ {
+ global $CONFIG;
+ if (get_context() == 'admin' && isadminloggedin()) {
+ add_submenu_item(elgg_echo('tidypics:administration'), $CONFIG->url . "mod/tidypics/pages/admin.php");
+ }
+ }
+
+ /**
* Sets up submenus for tidypics most viewed pages
*/
function tidypics_mostviewed_submenus() {
@@ -205,17 +222,7 @@
add_submenu_item(elgg_echo('tidypics:mostcommented'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimages.php");
add_submenu_item(elgg_echo('tidypics:mostcommentedthismonth'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagesthismonth.php");
add_submenu_item(elgg_echo('tidypics:mostcommentedtoday'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagestoday.php");
- add_submenu_item(elgg_echo('tidypics:recentlycommented'), $CONFIG->wwwroot . 'pg/photos/recentlycommented');
- }
- /**
- * Sets up tidypics admin menu. Triggered on pagesetup.
- */
- function tidypics_adminmenu()
- {
- global $CONFIG;
- if (get_context() == 'admin' && isadminloggedin()) {
- add_submenu_item(elgg_echo('tidypics:administration'), $CONFIG->url . "mod/tidypics/pages/admin.php");
- }
+ add_submenu_item(elgg_echo('tidypics:recentlycommented'), $CONFIG->wwwroot . 'pg/photos/recentlycommented/');
}
/**
@@ -281,44 +288,25 @@
include($CONFIG->pluginspath . "tidypics/pages/tagged.php");
break;
- case "rate": //rate image
- if (isset($page[1])) set_input('guid',$page[1]);
- include($CONFIG->pluginspath . "tidypics/actions/rate.php");
- break;
-
-
- case "mostviewed":
- if (isset($page[1])) set_input('guid',$page[1]);
+ case "mostviewed": // images with the most views
+ if (isset($page[1])) set_input('username',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/lists/mostviewedimages.php");
break;
- case "mostrecent":
+ case "mostrecent": // images uploaded most recently
if (isset($page[1])) set_input('username',$page[1]);
include($CONFIG->pluginspath . "tidypics/pages/lists/mostrecentimages.php");
break;
-
- case "yourmostviewed":
- if (isset($page[1])) set_input('guid',$page[1]);
- include($CONFIG->pluginspath . "tidypics/pages/lists/yourmostviewed.php");
- break;
-
- case "friendmostviewed":
- if (isset($page[1])) set_input('guid',$page[1]);
- include($CONFIG->pluginspath . "tidypics/pages/lists/friendmostviewed.php");
- break;
-
- case "recentlyviewed":
- if (isset($page[1])) set_input('guid',$page[1]);
+
+ case "recentlyviewed": // images most recently viewed
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlyviewed.php");
break;
- case "recentlycommented":
- if (isset($page[1])) set_input('guid',$page[1]);
+ case "recentlycommented": // images with the most recent comments
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlycommented.php");
break;
- case "highestrated":
- if (isset($page[1])) set_input('guid',$page[1]);
+ case "highestrated": // images with the highest average rating
include($CONFIG->pluginspath . "tidypics/pages/lists/highestrated.php");
break;
diff --git a/views/rss/object/album.php b/views/rss/object/album.php
index c59f0e2d3..990322baf 100644
--- a/views/rss/object/album.php
+++ b/views/rss/object/album.php
@@ -3,13 +3,12 @@
* Tidypics Album RSS View
*/
- // for now catch the albums view and ignore it
- if (get_context() == "search" && get_input('search_viewtype') == "gallery") {
- } else {
+// for now catch the albums view and ignore it
+if (get_context() == "search" && get_input('search_viewtype') == "gallery") {
- $album = $vars['entity'];
+} else {
- $base_url = $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=';
+ $album = $vars['entity'];
// use fullsize image
$base_url_fullsize = $vars['url'] . 'pg/photos/download/';
@@ -30,7 +29,6 @@
<url><?php echo $album_cover_url; ?></url>
<title><![CDATA[<?php echo $title; ?>]]></title>
<link><?php echo $album->getURL() . '?view=rss'; ?></link>
-
</image>
<?php
}
@@ -40,26 +38,8 @@
foreach ($images as $image) {
- $descr = '<p>' . get_entity($image->owner_guid)->name;
- $descr .= ' ' . elgg_echo('tidypics:posted') . '</p>';
- $descr .= "<p><img src=\"{$base_url}{$image->guid}&size=small\" /></p>";
- $descr .= "<p>{$image->description}</p>";
-
-?>
- <item>
- <title><?php echo $image->title; ?></title>
- <link><?php echo $base_url . $image->guid . '&amp;size=large'; ?></link>
- <description><?php echo htmlentities($descr, ENT_QUOTES); ?></description>
- <pubDate><?php echo date("r", $image->time_created); ?></pubDate>
- <guid isPermaLink="true"><?php echo $image->getURL(); ?></guid>
- <media:content url="<?php echo $base_url_fullsize . $image->guid . '/inline/'; ?>" medium="image" type="<?php echo $image->getMimeType(); ?>" />
- <media:title><?php echo $image->title; ?></media:title>
- <media:description><?php echo htmlentities($image->description); ?></media:description>
- <media:thumbnail url="<?php echo $base_url . $image->guid . '&amp;size=thumb'; ?>"></media:thumbnail>
- </item>
-
-<?php
+ echo elgg_view_entity($image);
}
- }
+}
?> \ No newline at end of file