I've been a drupal site user/admin for over a year and have found all kinds of great things to use it for. Just upgraded my site to 4.5.2 and I have to say it doesn't leave me wanting for much. There are a few things I wish it could do so I figured it was about time to roll up my sleves and dive in...

The first thing I am attempting to do is to make the archive.module block and page blogcentric - that is to say context sensitive to the currently displayed blog. I've managed to hack archive.module using some keen xtreme programming methodology (read: 5 nights trial and error) and have actually got it to work - however it's pretty ugly. I'd like to a) clean up the code using more drupalese syntax b) perhaps port to a seperate module as that seems the way to do things properly 'round here

1) Ok so the first thing I did was put !^blog\/([0-9]*)! into the block path for archive (neat trick that) so the calendar only shows up on the blog pages.

2) Next, in the archive_calendar function I added a preg_match to hack out the user id of the current blog from $_GET['q'] like this:

// get the users uid from the url
preg_match("/^blog\/([0-9]*)/",$_GET['q'],$blog_uid);

I didn't like this much but I couldn't figure out how to get at the $uid variable or the $node->$uid attribute from the archive module. Is there a better way to do this than what I have above?

3) from there it is a simple matter of changing the SQL to include a peek at the n.uid so as to pull out only nodes for the current blog's user

$result = db_query('SELECT DISTINCT(n.nid), n.created FROM {node} n '. node_access_join_sql() .'
WHERE n.uid = %d AND n.status = 1 AND n.created > %d AND n.created < %d AND '. node_access_where_sql() .'
ORDER BY n.created', $blog_uid[1], $start_of_month, $end_of_month);

4) last thing for the _block part was to add the current blog's uid to the hyperlink to the archives page for each of the matches in the calendar

if (in_array($nday, $days_with_posts)) {
$daytext = l($nday, "archive/$year/$month/$nday/&bloguser=$blog_uid[1]");
$dayclass = 'day-link';
}

I didn't much like this either - I would have prefered just putting it at the end after a / like 2004/27/01/$uid but I couldn't for the life of me figure out how the date was being parsed into $year /$month /$day and how I could access another variable that way? I'm assuming it has something to do with one of the parse_url() functions but i couldn't find where the callback was for doing it for the date? Could somewhere point me in the right direction to make this better?

5) caveat #1 - I commented out all the lines that cache the calendar block - obviously or it would never change one blog to another - since the calendar is only being displayed for blog pages i figured the hit would be minimal - unless someone has another way of selectively cache the block for each uid?

I think that's enough to start with for now - I did get the archive page to work by adding a field to the form with a drop down of all users, and just default selecting the current user using the $_GET['bloguser'] variable i created in step 4.

If anyone has any pointers or suggestions I would certainly appreciate it...

Comments

Prometheus6’s picture

I have a week module that creates weekly archive pages and a block with the links to each page. On the q=blog page it includes every blog's entries and on q=blog/# it includes links specific to the blog. You may find some ideas in there.

Basically, though, I using the arg() function instead of a regex. You can get your year, month and day values from the URL the same way. My URLs look like

week/blog/yyyy/mm/dd

or

week/blog/#/yyyy/mm/dd

where # is the uid of the user who owns the blog.

tatonca’s picture

Thanks for the tip! I wondered about the arg() function but wasn't sure how it was implemented - does it automatically divide out the variables by the "/" character and stick them into arg(0),arg(1),... ...arg(n) ?

While were taking about variables, is there an easy way to figure out what reserved variables there are and how they can be accessed? Are all variables internal until exported ? Are there any global variables for common information - say logged in user or node attributes? I tried using $node->$uid but it didn't seem to be available - is there a function that will return the $node hash?

grantbow@civicspacelabs.org’s picture

tatonca, your timing is very good. I have been working on blogroll for a few weeks and was about to working with Prometheus6 on a blog_archive module. I haven't gotten very far on blog_archive yet, haven't checked it in, but today I was going to start diving in to allow monthly archives (as well as weekly) which is another typical blog feature. I created a drupal-personal-blogs mail list to support informal work on both and get all the project emails. It would be great to work with you so we don't duplicate efforts.

Prometheus6’s picture

You got issues with my week archives???

:-)

tatonca’s picture

Sounds great. Actually I'm working on a bunch of things in the personal blog vein, and it would be great to work with folks, share some ideas and get some learnings... thanks for letting me know....

Prometheus6’s picture

That's how it works, but only with the q parameter. If you add another one you have to go after that on directly, like $_GET('whatever').

There is a global $user object/variable that's pretty straightforward. Custom profile data is serialized in one field (named 'data'). Take a look at the table to see what fields are available. $node->uid is the user id of the node's author. But I don't know of a hash value for nodes that's automatically saved anywhere.