As many of us, I'm using Drupal to set up a community of bloggers. One of the most common requests from users is to be able to choose among different themes for their spaces (profile, blog and blog posts).

There is a "blog theme" module that does this, but it has not been updated to 4.7.
I am posting the code below as a possible update to blog theme at http://drupal.org/project/issues/blogtheme

There is a problem, however with my code. When I enable it, I get the following error when displaying the main node page (which is the default frontpage too):

    * warning: Invalid argument supplied for foreach() in /home/ciudades/public_html/modules/node.module on line 359.
    * warning: implode(): Bad arguments. in /home/ciudades/public_html/modules/node.module on line 363.
    * user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /home/ciudades/public_html/includes/database.mysql.inc on line 120.

Here's the module code:

// $Id$ mycustomtheme.module,v 0.9 2006/7/24 14:38:00 Carlos Miranda Levy Exp $ 

/**
 * @mycustomtheme.module
 * This module uses the theme selected by users when displaying their posts and user pages.
 * It's supposed to update/substitute blog_theme.module which has not been updated to 4.7
 * It's just a few lines of code, less than 20, including brackets and stuff.
 * It's an important feature for those who want to allow members of their communities to choose 
 * from different themes for their pages, like most blogging communities do.
 * 
 * There is one problem to be fixed and it is that if the default front page is used (node),
 * an error is displayed. Just go to admin/settings and change default front page to "blog"
 * until a solution is found.
 */

/**
 * Implementation of hook_help().
 */
function mycustomtheme_help($section) {
  switch ($section) {
    case 'admin/help#mycustomtheme':
      return t('This module uses the theme selected by users when displaying their posts and user pages.');
    case 'admin/modules#description':
      return t('Uses the theme users pick in their profile when displaying their posts and user pages');
  }
}


/**
 * Implementation of hook_init().
 */
function mycustomtheme_init() {
}


/**
 * Implementation of hook_menu().
 */
function mycustomtheme_menu($may_cache) {
	// If it's
	// main blog page for user, then arg(0)="blog"; arg(1)=user id.
	// blog post, then arg(0)="node"; arg(1)=node id.
	// user page, then arg(0)="user"; arg(1)=user id.

	global $custom_theme;
	switch (arg(0)) {
		case "blog":
			$uid = arg(1);
			break;
		case "node":
			$currentnode = node_load(arg(1));
			$uid = $currentnode->uid;
			break;
		case "user":
			$uid = arg(1);
			break;
	}

	$user = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
	profile_load_profile(&$user);

	if (arg(0) == 'node' or arg(0) == 'blog' or arg(0)== 'user') {
		if (arg(1) and arg(1)!=="add" and arg(0)!=="forum")
		{
			$themes = list_themes();
			$custom_theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'bluemarine');
		}
	}
}


/**
 * Implementation of hook_block().
 */
function mycustomtheme_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0]['info'] = t('About Me');
    // OPTIONAL: Add additional block descriptions here, if required.
    return $blocks;
  }
  else if ($op == 'configure') {
    // OPTIONAL: Enter form elements to add to block configuration screen, if required.    
  }
  else if ($op == 'save') {
    // OPTIONAL: Add code to trigger when block configuration is saved, if required.
  }
  else if ($op == 'view') {
    switch ($delta) {
      case 0:
        $block['subject'] = t('About Me');
        $block['content'] = t('I have uploaded code for this at http://drupal.org/node/75277');
        break;
      // OPTIONAL: Enter additional cases for each additional block, if defined.
    }
    return $block;
  }
}

Comments

ystung’s picture

<?php
// $Id$ mycustomtheme.module,v 0.9 2006/7/24 14:38:00 Carlos Miranda Levy Exp $

/**
 * @mycustomtheme.module
 * This module uses the theme selected by users when displaying their posts and user pages.
 * It's supposed to update/substitute blog_theme.module which has not been updated to 4.7
 * It's just a few lines of code, less than 20, including brackets and stuff.
 * It's an important feature for those who want to allow members of their communities to choose
 * from different themes for their pages, like most blogging communities do.
 *
 * There is one problem to be fixed and it is that if the default front page is used (node),
 * an error is displayed. Just go to admin/settings and change default front page to "blog"
 * until a solution is found.
 */

/**
 * Implementation of hook_help().
 */
function mycustomtheme_help($section) {
  switch ($section) {
    case 'admin/help#mycustomtheme':
      return t('This module uses the theme selected by users when displaying their posts and user pages.');
    case 'admin/modules#description':
      return t('Uses the theme users pick in their profile when displaying their posts and user pages');
  }
}


/**
 * Implementation of hook_init().
 */
function mycustomtheme_init() {
}


/**
 * Implementation of hook_menu().
 */
function mycustomtheme_menu($may_cache) {
    // If it's
    // main blog page for user, then arg(0)="blog"; arg(1)=user id.
    // blog post, then arg(0)="node"; arg(1)=node id.
    // user page, then arg(0)="user"; arg(1)=user id.

    global $custom_theme;
    switch (arg(0)) {
        case "blog":
            $uid = arg(1);
            break;
/*        case "node":
            $currentnode = node_load(arg(1));
            $uid = $currentnode->uid;
            break;*/
        case "user":
            $uid = arg(1);
            break;
    }

    $user = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
    profile_load_profile(&$user);

    if (arg(0) == 'node' or arg(0) == 'blog' or arg(0)== 'user') {
        if (arg(1) and arg(1)!=="add" and arg(0)!=="forum")
        {
            $themes = list_themes();
            $custom_theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'bluemarine');
        }
    }
}

I change your code

/*        case "node":
            $currentnode = node_load(arg(1));
            $uid = $currentnode->uid;
            break;*/

clean function mycustomtheme_block
and the warning message disappear...
I am not sure why they are disappear.

nickie’s picture

Cool thing! Can it be ported for 5.0?

nickie’s picture

It's not good idea. The right code i think this:

 case "node":
            $currentnode = node_load(intval(arg(1)));
            $uid = $currentnode->uid;
            break;
Leeteq’s picture

Check the attachments in this thread:
http://drupal.org/node/59318

(I havent had time to test with 4.7.x yet.)

.
--
( Evaluating the long-term route for Drupal 7.x via BackdropCMS at https://www.CMX.zone )

kulfi’s picture

Did this get ported to 5.x?

kulfi’s picture

As per this thread: http://drupal.org/node/108075, blogtheme has been updated for D5.

Putting out a request for contributors to update the project page (http://drupal.org/node/19248). The most recent release is for 4.6, and its not clear what version HEAD is.

Thanks.