From 3b0b462b5790f15fcb612de66544838bdbce658b Mon Sep 17 00:00:00 2001 From: brettp Date: Wed, 24 Mar 2010 19:49:40 +0000 Subject: Added archive view for blogs. git-svn-id: http://code.elgg.org/elgg/trunk@5497 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/blog/blog_lib.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'mod/blog/blog_lib.php') diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php index 7f83d0dc3..8c09260a3 100644 --- a/mod/blog/blog_lib.php +++ b/mod/blog/blog_lib.php @@ -173,6 +173,37 @@ function blog_make_excerpt($text) { return substr(strip_tags($text), 0, 300); } +/** + * Returns a list of years and months for all blogs optionally for a user. + * Very similar to get_entity_dates() except uses a metadata field. + * + * @param mixed $user_guid + */ +function blog_get_blog_months($user_guid = NULL, $container_guid = NULL) { + global $CONFIG; + + $subtype = get_subtype_id('blog'); + + $q = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(mdv.string)) AS yearmonth + FROM {$CONFIG->dbprefix}entities e, {$CONFIG->dbprefix}metadata, {$CONFIG->dbprefix}metastrings mdn, {$CONFIG->dbprefix}metastrings mdv + WHERE e.guid = {$CONFIG->dbprefix}metadata.entity_guid + AND {$CONFIG->dbprefix}metadata.name_id = mdn.id + AND {$CONFIG->dbprefix}metadata.value_id = mdv.id + AND mdn.string = 'publish_date'"; + + if ($user_guid) { + $user_guid = (int)$user_guid; + $q .= " AND e.owner_guid = $user_guid"; + } + + if ($container_guid) { + $container_guid = (int)$container_guid; + $q .= " AND e.container_guid = $container_guid"; + } + + return get_data($q); +} + /** * Extended class to override the time_created */ -- cgit v1.2.3