return $html;\r
}\r
\r
+ 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)\r
+ {\r
+ global $CONFIG;\r
+ \r
+ $sum = sanitise_string($sum);\r
+ $entity_type = sanitise_string($entity_type);\r
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);\r
+ $name = get_metastring_id($name);\r
+ $limit = (int) $limit;\r
+ $offset = (int) $offset;\r
+ $owner_guid = (int) $owner_guid;\r
+ if (!empty($mdname) && !empty($mdvalue)) {\r
+ $meta_n = get_metastring_id($mdname);\r
+ $meta_v = get_metastring_id($mdvalue);\r
+ }\r
+ \r
+ if (empty($name)) return 0;\r
+ \r
+ $where = array();\r
+ \r
+ if ($entity_type!="")\r
+ $where[] = "e.type='$entity_type'";\r
+ if ($owner_guid > 0)\r
+ $where[] = "e.owner_guid = $owner_guid";\r
+ if ($entity_subtype)\r
+ $where[] = "e.subtype=$entity_subtype";\r
+ if ($name!="")\r
+ $where[] = "a.name_id='$name'";\r
+ \r
+ if (!empty($mdname) && !empty($mdvalue)) {\r
+ if ($mdname!="")\r
+ $where[] = "m.name_id='$meta_n'";\r
+ if ($mdvalue!="")\r
+ $where[] = "m.value_id='$meta_v'";\r
+ }\r
+ \r
+ if ($sum != "count")\r
+ $where[] = "a.value_type='integer'"; // Limit on integer types\r
+\r
+ if (!$count) {\r
+ $query = "SELECT distinct e.*, $sum(ms.string) as sum ";\r
+ } else {\r
+ $query = "SELECT count(distinct e.guid) as num, $sum(ms.string) as sum ";\r
+ }\r
+ $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 ";\r
+ \r
+ if (!empty($mdname) && !empty($mdvalue)) {\r
+ $query .= " JOIN {$CONFIG->dbprefix}metadata m on m.entity_guid = e.guid "; \r
+ }\r
+ \r
+ $query .= " WHERE ";\r
+ foreach ($where as $w)\r
+ $query .= " $w and ";\r
+ $query .= get_access_sql_suffix("a"); // now add access\r
+ $query .= ' and ' . get_access_sql_suffix("e"); // now add access\r
+ if (!$count) $query .= ' group by e.guid';\r
+ \r
+ if (!$count) {\r
+ $query .= ' order by sum ' . $orderdir;\r
+ $query .= ' limit ' . $offset . ' , ' . $limit;\r
+ return get_data($query, "entity_row_to_elggstar");\r
+ } else {\r
+ if ($row = get_data_row($query)) {\r
+ return $row->num;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
/**\r
* Is page owner a group - convenience function\r
* \r
+++ /dev/null
-<?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
<?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
*
*/
$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
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);
+++ /dev/null
-<?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
}\r
\r
/**\r
- * Sets up submenus for tidypics. Triggered on pagesetup.\r
+ * Sets up sidebar menus for tidypics. Triggered on pagesetup.\r
*/\r
function tidypics_submenus() {\r
\r
$view_count = get_plugin_setting('view_count', 'tidypics');\r
\r
// owner gets "your albumn", "your friends albums", "your most viewed", "your most recent"\r
- if (get_loggedin_userid() == $page_owner->guid && get_loggedin_userid()) {\r
+ if (get_loggedin_userid() && get_loggedin_userid() == $page_owner->guid) {\r
+ \r
add_submenu_item( elgg_echo('album:create'), \r
- $CONFIG->wwwroot . "pg/photos/new/". $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/new/{$page_owner->username}/", \r
'tidypics-a' );\r
\r
add_submenu_item( elgg_echo("album:yours"), \r
- $CONFIG->wwwroot . "pg/photos/owned/" . $_SESSION['user']->username, \r
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/", \r
'tidypics-a' );\r
\r
add_submenu_item( elgg_echo('album:yours:friends'), \r
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/", \r
'tidypics-a');\r
\r
if ($view_count != 'disabled') {\r
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),\r
- $CONFIG->wwwroot . 'pg/photos/yourmostviewed',\r
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/",\r
'tidypics-a');\r
}\r
\r
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),\r
- $CONFIG->wwwroot . 'pg/photos/mostrecent/' . $_SESSION['user']->username,\r
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/",\r
'tidypics-a');\r
} else if (isloggedin()) {\r
- // 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"\r
+ \r
+ $user = get_loggedin_user();\r
+ \r
+ // logged in not owner gets "page owners albums", "page owner's friends albums", "page owner's most viewed", "page owner's most recent"\r
+ // and then "your albums", "your most viewed", "your most recent"\r
add_submenu_item( elgg_echo("album:yours"), \r
- $CONFIG->wwwroot . "pg/photos/owned/" . $_SESSION['user']->username, \r
+ $CONFIG->wwwroot . "pg/photos/owned/{$user->username}/", \r
'tidypics-b' );\r
\r
if ($view_count != 'disabled') {\r
add_submenu_item( elgg_echo('tidypics:yourmostviewed'),\r
- $CONFIG->wwwroot . 'pg/photos/yourmostviewed',\r
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$user->username}/",\r
'tidypics-b');\r
}\r
\r
add_submenu_item( elgg_echo('tidypics:yourmostrecent'),\r
- $CONFIG->wwwroot . 'pg/photos/mostrecent/' . $_SESSION['user']->username,\r
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$user->username}/",\r
'tidypics-b');\r
\r
if($page_owner->name) { // check to make sure the owner set their display name\r
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/", \r
'tidypics-a' );\r
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/", \r
'tidypics-a');\r
\r
if ($view_count != 'disabled') {\r
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostviewed'),$page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/friendmostviewed/". $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/mostviewed/{$page_owner->username}/", \r
'tidypics-a');\r
}\r
\r
add_submenu_item( sprintf(elgg_echo('tidypics:friendmostrecent'),$page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/mostrecent/". $page_owner->username, \r
+ $CONFIG->wwwroot . "pg/photos/mostrecent/{$page_owner->username}/", \r
'tidypics-a');\r
}\r
} else if ($page_owner->guid) {\r
// non logged in user gets "page owners albums", "page owner's friends albums" \r
add_submenu_item( sprintf(elgg_echo("album:user"), $page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/owned/" . $page_owner->username, \r
- 'tidypics' );\r
+ $CONFIG->wwwroot . "pg/photos/owned/{$page_owner->username}/", \r
+ 'tidypics-a' );\r
add_submenu_item( sprintf(elgg_echo('album:friends'),$page_owner->name), \r
- $CONFIG->wwwroot . "pg/photos/friends/". $page_owner->username, \r
- 'tidypics');\r
+ $CONFIG->wwwroot . "pg/photos/friends/{$page_owner->username}/", \r
+ 'tidypics-a');\r
}\r
\r
+ // everyone gets world albums, most recent, most viewed, most recently viewed, recently commented \r
add_submenu_item( elgg_echo('album:all'), \r
$CONFIG->wwwroot . "pg/photos/world/", \r
'tidypics-z');\r
add_submenu_item( elgg_echo('tidypics:mostrecent'),\r
- $CONFIG->wwwroot . 'pg/photos/mostrecent',\r
+ $CONFIG->wwwroot . 'pg/photos/mostrecent/',\r
'tidypics-z');\r
\r
if ($view_count != 'disabled') {\r
add_submenu_item( elgg_echo('tidypics:mostviewed'),\r
- $CONFIG->wwwroot . 'pg/photos/mostviewed',\r
+ $CONFIG->wwwroot . 'pg/photos/mostviewed/',\r
'tidypics-z');\r
add_submenu_item( elgg_echo('tidypics:recentlyviewed'),\r
- $CONFIG->wwwroot . 'pg/photos/recentlyviewed',\r
+ $CONFIG->wwwroot . 'pg/photos/recentlyviewed/',\r
'tidypics-z');\r
}\r
add_submenu_item( elgg_echo('tidypics:recentlycommented'),\r
- $CONFIG->wwwroot . 'pg/photos/recentlycommented',\r
+ $CONFIG->wwwroot . 'pg/photos/recentlycommented/',\r
'tidypics-z');\r
add_submenu_item( 'Flickr Integration',\r
$CONFIG->wwwroot . 'mod/tidypics/pages/flickr/setup.php',\r
\r
}\r
\r
+ /**\r
+ * Sets up tidypics admin menu. Triggered on pagesetup.\r
+ */\r
+ function tidypics_adminmenu()\r
+ {\r
+ global $CONFIG;\r
+ if (get_context() == 'admin' && isadminloggedin()) {\r
+ add_submenu_item(elgg_echo('tidypics:administration'), $CONFIG->url . "mod/tidypics/pages/admin.php");\r
+ }\r
+ }\r
+\r
/**\r
* Sets up submenus for tidypics most viewed pages\r
*/\r
add_submenu_item(elgg_echo('tidypics:mostcommented'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimages.php");\r
add_submenu_item(elgg_echo('tidypics:mostcommentedthismonth'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagesthismonth.php");\r
add_submenu_item(elgg_echo('tidypics:mostcommentedtoday'), $CONFIG->url . "mod/tidypics/pages/lists/mostcommentedimagestoday.php");\r
- add_submenu_item(elgg_echo('tidypics:recentlycommented'), $CONFIG->wwwroot . 'pg/photos/recentlycommented');\r
- }\r
- /**\r
- * Sets up tidypics admin menu. Triggered on pagesetup.\r
- */\r
- function tidypics_adminmenu()\r
- {\r
- global $CONFIG;\r
- if (get_context() == 'admin' && isadminloggedin()) {\r
- add_submenu_item(elgg_echo('tidypics:administration'), $CONFIG->url . "mod/tidypics/pages/admin.php");\r
- }\r
+ add_submenu_item(elgg_echo('tidypics:recentlycommented'), $CONFIG->wwwroot . 'pg/photos/recentlycommented/');\r
}\r
\r
/**\r
include($CONFIG->pluginspath . "tidypics/pages/tagged.php");\r
break;\r
\r
- case "rate": //rate image\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
- include($CONFIG->pluginspath . "tidypics/actions/rate.php");\r
- break;\r
-\r
-\r
- case "mostviewed":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
+ case "mostviewed": // images with the most views\r
+ if (isset($page[1])) set_input('username',$page[1]);\r
include($CONFIG->pluginspath . "tidypics/pages/lists/mostviewedimages.php");\r
break;\r
\r
- case "mostrecent":\r
+ case "mostrecent": // images uploaded most recently\r
if (isset($page[1])) set_input('username',$page[1]);\r
include($CONFIG->pluginspath . "tidypics/pages/lists/mostrecentimages.php");\r
break;\r
- \r
- case "yourmostviewed":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
- include($CONFIG->pluginspath . "tidypics/pages/lists/yourmostviewed.php");\r
- break;\r
- \r
- case "friendmostviewed":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
- include($CONFIG->pluginspath . "tidypics/pages/lists/friendmostviewed.php");\r
- break;\r
- \r
- case "recentlyviewed":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
+ \r
+ case "recentlyviewed": // images most recently viewed\r
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlyviewed.php");\r
break;\r
\r
- case "recentlycommented":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
+ case "recentlycommented": // images with the most recent comments\r
include($CONFIG->pluginspath . "tidypics/pages/lists/recentlycommented.php");\r
break;\r
\r
- case "highestrated":\r
- if (isset($page[1])) set_input('guid',$page[1]);\r
+ case "highestrated": // images with the highest average rating\r
include($CONFIG->pluginspath . "tidypics/pages/lists/highestrated.php");\r
break;\r
\r
* Tidypics Album RSS View\r
*/\r
\r
- // for now catch the albums view and ignore it\r
- if (get_context() == "search" && get_input('search_viewtype') == "gallery") {\r
- } else {\r
+// for now catch the albums view and ignore it\r
+if (get_context() == "search" && get_input('search_viewtype') == "gallery") {\r
\r
- $album = $vars['entity'];\r
+} else {\r
\r
- $base_url = $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=';\r
+ $album = $vars['entity'];\r
\r
// use fullsize image\r
$base_url_fullsize = $vars['url'] . 'pg/photos/download/';\r
<url><?php echo $album_cover_url; ?></url>\r
<title><![CDATA[<?php echo $title; ?>]]></title>\r
<link><?php echo $album->getURL() . '?view=rss'; ?></link>\r
-\r
</image>\r
<?php\r
}\r
\r
\r
foreach ($images as $image) {\r
- $descr = '<p>' . get_entity($image->owner_guid)->name;\r
- $descr .= ' ' . elgg_echo('tidypics:posted') . '</p>';\r
- $descr .= "<p><img src=\"{$base_url}{$image->guid}&size=small\" /></p>";\r
- $descr .= "<p>{$image->description}</p>";\r
-\r
-?>\r
- <item>\r
- <title><?php echo $image->title; ?></title>\r
- <link><?php echo $base_url . $image->guid . '&size=large'; ?></link>\r
- <description><?php echo htmlentities($descr, ENT_QUOTES); ?></description>\r
- <pubDate><?php echo date("r", $image->time_created); ?></pubDate>\r
- <guid isPermaLink="true"><?php echo $image->getURL(); ?></guid>\r
- <media:content url="<?php echo $base_url_fullsize . $image->guid . '/inline/'; ?>" medium="image" type="<?php echo $image->getMimeType(); ?>" />\r
- <media:title><?php echo $image->title; ?></media:title>\r
- <media:description><?php echo htmlentities($image->description); ?></media:description>\r
- <media:thumbnail url="<?php echo $base_url . $image->guid . '&size=thumb'; ?>"></media:thumbnail>\r
- </item>\r
-\r
-<?php\r
+ echo elgg_view_entity($image);\r
}\r
\r
- }\r
+}\r
?>
\ No newline at end of file