Hello
I stumbled across your work improving the base forums and now I am starting the process of going over the module. I like the easy of use, documentation and modular approach that you are taking soI am trying to see if I can replace my existing UIEforum setup, but I've hit a little snag so far.
I had no problem installing the module, getting the css files into my theme folder but I seem to have the call added improperly to my template.php file; while all seems to work as it should, the actual posts themselves aren't being themed, they are just coming up as content pages. There is no post theming, no user pict or stats sidebar, and the page is coming in with the full "create content" publishing options instead of the standard forum "post reply." I've gone over the instructions a couple of times, but I must be missing something obvious.
I'm no programmer but I can usually track down simple theming issues, but this one has me stumped. Clearly my template.php mod is wrong. I am working from a modded template that was made by a designer I hired. Trying to work through what he was doing is a bit of a nightmare.
Here is the template.php for my site, I tried adding the code in several places, but higher in the sequence breaks the page and lower has no effect.
Any help or insight is greatly appreciated.
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
// Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
case 'page':
// get the currently logged in user
global $user;
// An anonymous user has a user id of zero.
if ($user->uid > 0) {
// The user is logged in.
$vars['logged_in'] = TRUE;
}
else {
// The user has logged out.
$vars['logged_in'] = FALSE;
}
if (module_exists('advanced_forum')) {
$vars = advanced_forum_addvars($hook, $vars);
}
if (module_exists('advanced_forum')) {
$vars = advanced_forum_addvars($hook, $vars);
}
$body_classes = array();
// classes for body element
// allows advanced theming based on context (home page, node of certain type, etc.)
$body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
$body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
if ($vars['node']->type) {
$body_classes[] = 'ntype-'. zen_id_safe($vars['node']->type);
}
switch (TRUE) {
case $vars['sidebar_left'] && $vars['sidebar_right'] :
$body_classes[] = 'both-sidebars';
break;
case $vars['sidebar_left'] :
$body_classes[] = 'sidebar-left';
break;
case $vars['sidebar_right'] :
$body_classes[] = 'sidebar-right';
break;
}
// implode with spaces
$vars['body_classes'] = implode(' ', $body_classes);
break;
case 'node':
// get the currently logged in user
global $user;
// set a new $is_admin variable
// this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
$vars['is_admin'] = in_array('admin', $user->roles);
$node_classes = array('node');
if ($vars['sticky']) {
$node_classes[] = 'sticky';
}
if (!$vars['node']->status) {
$node_classes[] = 'node-unpublished';
}
$node_classes[] = 'ntype-'. zen_id_safe($vars['node']->type);
// implode with spaces
$vars['node_classes'] = implode(' ', $node_classes);
$vars['storylink_url'] = check_url($vars['node']->vote_storylink_url);
if (arg(1) != 'add' && arg(2) != 'edit') {
$style = variable_get('vote_up_down_widget_style_node', 0) == 1 ? '_alt' : '';
$vars['vote_up_down_widget'] = theme("vote_up_down_widget$style", $vars['node']->nid, 'node');
$vars['vote_up_down_points'] = theme("vote_up_down_points$style", $vars['node']->nid, 'node');
}
$vars['vote_storylink_via'] = theme('vote_storylink_via', $vars['node']->vote_storylink_url);
if (arg(1) == 'top') {
static $count;
$count = is_array($count) ? $count : array();
$count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1;
$vars['seqid'] = $count[$hook]++;
}
break;
case 'comment':
// we load the node object that the current comment is attached to
$node = node_load($vars['comment']->nid);
// if the author of this comment is equal to the author of the node, we set a variable
// then in our theme we can theme this comment differently to stand out
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
break;
}
return $vars;
}
Comments
Comment #1
serpisor2 commentedI have the same problem like you (topics appearing like normal content pages) but i am not entirely sure it is related to template.php. I am not sure because I have advprofile installed which works flawlessly and i used the same method to add the call for advforum in my template.php. This is my _phptemplate_variables function:
If you find a solution please post it here. I am using the fireflystream theme which i modified to look as i want but the only change i've done to template.php is related to advprofile. Is it possible this is related to page.tpl.php? That file i changed a lot.
Comment #2
serpisor2 commentedMy problem was solved by adding return $vars inside the if statement. This is my function now:
What you should try is add the "return $vars;" inside the if (module_exists('advanced_forum')), it did work for me but your template.php is a lot more complex then mine. Good luck!
Thank you Michelle for these awesome modules!
Comment #3
serpisor2 commentedHere i am posting again. I'd like to say sorry for the above post but i was so excited i fixed the issue that i forgot to test my own site if it displays correctly first. Anyways by adding what i said you will probably fix your forum into displaying correctly but break everything else. At my site the forum was displaying correctly but everything else (advprofile, nodes etc.) weren't displaying correctly. This is my function now:
This works for my theme, what you need to do is find the place where the $vars get overwritten by the code that follows (i am not sure if this is what really happens, i am just guessing). What i'd try if i were you is this function:
Good luck!
Comment #4
Max_Headroom commentedhokuspokus:
Serpisor2's reply will work, but it is better to have the code first in the template.php so that the forum's css can be loaded first before other css or changes.
I would suggest:
Serpisor2:
I think you might run into some problems with all your "return $vars". In your modified code, if "hook == page" is true, then your Adv Forum snippet won't run, as there is a "return $vars" before your snippet. This is also your problem why your original code does not work. Because "hook == page" (probably) returns false, return $vars does not execute.
Cut "return $vars" from where it is at the end of your function and replace "return array() with it. I don't see where "return array()" is used, I think it is just a failsafe.
Some education: $vars does not get overwritten. It is an array, so elements get added to it.
PHP is fun ;-)
Comment #5
serpisor2 commentedI was thinking that if the vars are added at the beginning of the function, but disappear at the end they must be replaced/deleted somewhere but what was really happening was an empty array was returned ... :). Anyways i have no idea what hook == page is ... it was there with the theme i downloaded so i'm not sure what it does (i'm the kind of guy that doesn't fix or care about what's not broken :P). You did get me wandering so what i did is delete the whole if($hook == 'page') and my theme is working as before ... That if() was supposed to add some vars for the color module (which i don't use) and for secondary tabs which i have no idea what they are supposed to be, only thing i know is that primary tabs are what the theme author called the Edit, Revisions and other tabs that appear next to node titles. Anyways i don't care much about that if(hook == page), what got me wandering is that advanced_profile_addvars($hook, $vars) doesn't add any vars really. I mean, with my old setup vars were never returned (since hook == page was always false), but the profiles were displaying correctly and everything was ok... Now i deleted the whole _phptemplate_variables function (just to test) and profiles still are ok... If you know about advanced_profiles and you could tell me what vars it really adds, i'll be happy to know. This is just a question from someone curious about the subject but who doesn't really need to know this, so feel free not to answer (i'm sure others need your help more than i do), also sorry for hi-jacking this issue/topic/post/whatever :)
PHP is magic ;-)
Comment #6
hokuspokus commentedBlammo!
Thanks folks and Zandroc, your advice worked and now my full forum is theming.
I'm going through what everyone said here right now and pick up as much as I can.
Trying to work through my template was tough because I wasn't sure what each function was doing. Building a site from scratch is much easier than mapping out what others have done with their code, but I am immensely grateful for the support that the drupal community provides.
Now it's time to see how painful the conversion will be from UIEForums....
Comment #7
Max_Headroom commentedSerpisor2
"Page" refers here to your main theme template. See page.tpl.php in your theme. If you ok to be without theming for secondary menu (Secondary to primary menu. See admin/build/menu/settings), then you can delete it I suppose.
If you delete the whole _phptemplate_variables function, you will see that your forum posts are not themed. I haven't looked at advanced profiles yet. But I am sure you will find advanced_profile_addvars function in advanced_profile.module. You will see there how it works with $vars.
We are going OT here. I'm closing it, problem fixed.
Comment #8
capellicThings get a bit more complicated when using Zen.
Zen invites you to create custom "sub themes" (themes/zen/my_theme) and so it is using template.php in the zen directory *and* in the my_theme directory. So if I try to paste _phptemplate_variables into the zen/my_theme/template.php file, I get a duplicate function error -- and this is because it is already defined in zen/template.php.
I guess I could overwrite _phptemplate_variables in zen/template.php, which I did as a test and it I do get the intended result (post node was themed!), but I am worried that there might be some unintended consequences due to there being some big differences between the _phptemplate_variables function posted here and the one that Zen is using.
What I think would be ideal is if I could somehow override just the portion of _phptemplate_variables that I need -- and I'll look a bit more closely at the issue soon -- but was wondering if there was some advice on how to proceed without being unnecessarily invasive.
UPDATE
I added the following to the zen/template.php file and everything works fine. I would prefer to add it to zen/my_theme/template.php, but this will be good enough.
Comment #9
kriskd commentedI'd like to get that function in my zen subtheme properly (if possible). Can someone help?
Comment from the zen template.php:
So, which one do I use? Page or Node?
Scrolling down a bit, here is what preprocess_page has:
Michelle, or anyone, can you suggest how/where to add the required code into this?
Comment #10
michelleAdd the call to both the node and comment preprocesses.
Michelle
Comment #11
kriskd commentedI ended up working through this example as I was doubtful it could be done in the sub-theme alone. Maybe since those posts, it was discovered it could be done in the sub-theme? Will give it a try tomorrow. :-)
Comment #12
kriskd commentedI don't think placing the function call in the node and comment preprocesses are working. Here is what I did:
(Note that I just commented out "Delete this line..." instead of actually deleting that text so the function calls are active.)
I will submit an issue in Zen theme report and see if they can help.
Comment #13
michelleI submitted an issue as well: http://drupal.org/node/246109
Michelle
Comment #14
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.