Submitted by Kevin Hankens on Fri, 05/07/2010 - 09:30
<?php
/**
* Implements theme_preprocess_page().
*/
function inspired_preprocess_page(&$vars) {
$vars['theme_path'] = drupal_get_path('theme', 'inspired');
// Ensure that we are editing with the admin theme
$arg0 = arg(0);
$arg1 = arg(1);
$arg2 = arg(2);
if ($arg0 == 'node' && is_numeric($arg1) && $arg2 != 'edit') {
$vars['template_files'][] = 'page-custom';
}
// Render main menu
//$vars['v']['main_menu'] = generate_main_menu();
}
/**
* Implements theme_preprocess_node().
*/
function inspired_preprocess_node(&$vars) {
$vars['theme_path'] = drupal_get_path('theme', 'inspired');
// Attach node data to article groups from articles
if ($vars['type'] == 'article_group') {
// Primary article
$primary = node_load($vars['field_agroup_particle'][0]['nid']);
$vars['v']['primary'] = $primary->v;
// Featured and More articles
$vars['v']['featured'] = load_related_articles($vars['field_agroup_farticles']);
$vars['v']['more'] = load_related_articles($vars['field_agroup_marticles']);
}
// See if any templates are bound to this content type
if ($vars['type'] != 'template') {
$result = db_query(
"SELECT n.nid
FROM {node} n
INNER JOIN {content_type_template} c
ON c.vid = n.vid
WHERE n.type = 'template'
AND c.field_content_type_value = '%s'",
$vars['type']
);
// Load the template data from its node
$nid = db_result($result);
if (is_numeric($nid)) {
$template = node_load($nid);
if (is_object($template)) {
$file = $template->field_template_file_name[0]['value'];
attach_template($vars, $file);
}
// Merge the $v arrays
if (is_array($template->v)) {
$vars['v'] = is_array($vars['v']) ? array_merge($vars['v'], $template->v) : $template->v;
}
}
kpr($vars);
}
// Check if the node has specified a template file
if (isset($vars['field_template_file_name'][0]['value'])) {
attach_template($vars, $vars['field_template_file_name'][0]['value']);
}
}
/**
* Helper function to attach a specified template to a node
* @param array $vars
* The variables preprocessed for a node template
* @param str $file
* The file name of the template without a .tpl.php extension
*/
function attach_template(&$vars, $file) {
$vars['template_files'][] = $file;
}
function load_related_articles($articles) {
$v = array();
if (!empty($articles)) {
foreach ($articles as $article) {
$node = node_load($article['nid']);
$v[] = $node->v;
}
}
return $v;
}
?>
Post new comment