]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added archive view for blogs.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 24 Mar 2010 19:49:40 +0000 (19:49 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 24 Mar 2010 19:49:40 +0000 (19:49 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5497 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/blog/blog_lib.php
mod/blog/views/default/blog/sidebar_menu.php

index 7f83d0dc3a6c6e85eed21114159c2ba2ee9e00b3..8c09260a3a48e873da6cb118b03e587372e6af31 100644 (file)
@@ -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
  */
index bd348c7e678bb2c1e87572b948eb35a3494507b5..a3fe1c181c3550bfc308a1d6db734929551df2eb 100644 (file)
@@ -35,24 +35,32 @@ echo elgg_view("blogs/sidebar", array("object_type" => 'blog'));
 $comments = get_annotations(0, "object", "blog", "generic_comment", "", 0, 4, 0, "desc");
 echo elgg_view('annotation/latest_comments', array('comments' => $comments));
 
-if ($dates = get_entity_dates('object', 'blog', page_owner())) {
-       echo elgg_view_title(elgg_echo('blog:archives'));
-
-       echo '<ul>';
-       foreach($dates as $date) {
-               $timestamplow = mktime(0,0,0,substr($date,4,2),1,substr($date,0,4));
-               $timestamphigh = mktime(0,0,0,((int) substr($date,4,2)) + 1,1,substr($date,0,4));
-
-               if (!isset($page_owner)) $page_owner = page_owner_entity();
-               $link = $CONFIG->wwwroot . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh;
-               //add_submenu_item(sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4)), $link, 'filter');
-               $month = sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4));
-               echo "<li><a href=\"$link\" title=\"$month\">$month</a><li>";
-       }
 
-       echo '</ul>';
-}
+// only show archives for users or groups.
+// This is a limitation of the URL schema.
+if ($page_owner) {
+       $dates = blog_get_blog_months($user);
+
+       if ($dates) {
+               echo elgg_view_title(elgg_echo('blog:archives'));
+
+               echo '<ul>';
+               foreach($dates as $date) {
+                       $date = $date->yearmonth;
 
+                       $timestamplow = mktime(0,0,0,substr($date,4,2),1,substr($date,0,4));
+                       $timestamphigh = mktime(0,0,0,((int) substr($date,4,2)) + 1,1,substr($date,0,4));
+
+                       if (!isset($page_owner)) $page_owner = page_owner_entity();
+                       $link = $CONFIG->wwwroot . 'pg/blog/' . $page_owner->username . '/archive/' . $timestamplow . '/' . $timestamphigh;
+                       //add_submenu_item(sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4)), $link, 'filter');
+                       $month = sprintf(elgg_echo('date:month:' . substr($date,4,2)), substr($date, 0, 4));
+                       echo "<li><a href=\"$link\" title=\"$month\">$month</a><li>";
+               }
+
+               echo '</ul>';
+       }
+}
 
 // temporarily force tag-cloud display
 $tags = display_tagcloud(0, 100, 'tags');