<?php
// $Id: template.php,v 1.3 2008/09/26 0829 Exp $
/**
* Get theme setting values.
*/
if (is_null(theme_get_setting('diykit_skin'))) {
global $theme_key;
$defaults = array(
'diykit_skin' => 'default',
'diykit_layout' => 'fixed',
'diykit_column' => 'portal',
);
$settings = theme_get_settings($theme_key);
if (module_exists('node')) {
foreach (node_get_types() as $type => $name) {
unset($settings['toggle_node_info_' . $type]);
}
}
variable_set(
str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
array_merge($defaults, $settings)
);
theme_get_setting('', TRUE);
}
/**
* Block regions.
*/
function diykit_regions() {
return array(
'header' => t('header'),
'footer' => t('footer'),
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content_top' => t('content top'),
'content_bottom' => t('content bottom'),
'content_body_top' => t('content body top'),
'content_body_bottom' => t('content body bottom'),
);
}
/**
* Override and insert phptemplate variables.
*/
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case 'page':
global $user;
global $theme;
// $xml
$user_agent = getenv('HTTP_USER_AGENT');
if (!(strpos($user_agent, 'Windows') !== FALSE && strpos($user_agent, 'MSIE 6') !== FALSE)) {
$vars['xml'] = '<?xml version="1.0" encoding="utf-8"?>'. "\n";
}
// $css, $styles, $iefix
$skin = theme_get_setting($theme . '_skin');
$iefix = $vars['directory'] . '/css/ie-fix.css';
$vars['iefix'] = '';
if (file_exists($iefix)) {
$vars['iefix'] .= '<!--[if IE]><style type="text/css" media="all">@import "' . base_path() . $iefix . '";</style><![endif]-->' . "\n";
}
if ($skin == 'default') {
$css = $vars['directory'] . '/css/skin.css';
if (file_exists($css)) {
drupal_add_css($css, 'theme', 'all');
}
}
else if ($skin) {
$css = $vars['directory'] . '/skin/' . $skin . '/skin.css';
$skin_iefix = $vars['directory'] . '/skin/' . $skin . '/ie-fix.css';
if (file_exists($css)) {
drupal_add_css($css, 'theme', 'all');
}
if (file_exists($skin_iefix)) {
$vars['iefix'] .= '<!--[if IE]><style type="text/css" media="all">@import "' . base_path() . $skin_iefix . '";</style><![endif]-->' . "\n";
}
}
$vars['css'] = drupal_add_css();
$vars['styles'] = drupal_get_css();
// $body_classes
$layout = theme_get_setting($theme . '_layout');
$column = theme_get_setting($theme . '_column');
$body_classes[] = !empty($vars['is_front']) ? 'front' : 'not-front';
$body_classes[] = ($user->uid > 0) ? ' logged-in' : ' not-logged-in';
$body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. form_clean_id(drupal_strtolower(arg(0))));
if (isset($vars['node']) && $vars['node']->type) {
$body_classes[] = 'node-type-'. form_clean_id($vars['node']->type);
}
if ($vars['layout'] == 'both') {
$body_classes[] = 'two-sidebars';
}
elseif ($vars['layout'] == 'none') {
$body_classes[] = 'no-sidebars';
}
else {
$body_classes[] = 'one-sidebar sidebar-'. $vars['layout'];
}
if ($layout) { $body_classes[] = $layout; }
if ($column) { $body_classes[] = $column; }
$vars['body_classes'] = implode(' ', $body_classes);
// $site_footer, $footer
$vars['site_footer'] = filter_xss_admin(variable_get('site_footer', FALSE));
$vars['footer'] = theme('blocks', 'footer');
break;
case 'node':
// $node_classes
$node_classes[] = 'node';
if ($vars['page'] == 0) {
$node_classes[] = 'teaser';
$node_classes[] = $vars['zebra'];
}
if ($vars['page'] == 1) {
$node_classes[] = 'page';
}
if ($vars['sticky']) {
$node_classes[] = 'sticky';
}
if (!$vars['node']->status) {
$node_classes[] = 'node-unpublished';
}
if ($vars['node']->type) {
$node_classes[] = 'type-' . $vars['node']->type;
}
$vars['node_classes'] = implode(' ', $node_classes);
// $content_body_top, $content_body_bottom
if ($vars['page'] == 1) {
$vars['content_body_top'] = theme('blocks', 'content_body_top');
$vars['content_body_bottom'] = theme('blocks', 'content_body_bottom');
}
break;
case 'comment':
global $user;
$node = node_load($vars['comment']->nid);
// $comment_classes
$comment_classes[] = 'comment';
if ($vars['comment']->new) {
$comment_classes[] = 'comment-new';
}
if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
$comment_classes[] = 'comment-unpublished';
}
if ($vars['comment']->uid == $node->uid) {
$comment_classes[] = 'comment-by-author';
}
if ($user->uid && $vars['comment']->uid == $user->uid) {
$comment_classes[] = 'comment-mine';
}
if ($vars['comment']->uid) {
$comment_classes[] = 'comment-uid-' . $vars['comment']->uid;
}
$comment_classes[] = $vars['zebra'];
$vars['comment_classes'] = implode(' ', $comment_classes);
break;
case 'block':
// $block_classes
$block_classes[] = 'block';
$block_classes[] = 'block-' . $vars['block']->module;
$block_classes[] = $vars['zebra'];
$block_classes[] = $vars['block']->region . '-' . $vars['block_zebra'];
$block_classes[] = $vars['block']->region . '-' . $vars['block_id'];
$vars['block_classes'] = implode(' ', $block_classes);
break;
}
return $vars;
}
/**
* Override theme functions.
*/
function phptemplate_comment_wrapper($content, $type = null) {
static $node_type;
if (isset($type)) {
$node_type = $type;
}
if ($content) {
if ($node_type == 'forum') {
$output[] = '<div id="comments">'. $content .'</div>';
}
else {
$output[] = '<div id="comments">';
$output[] = '<h2 class="title comments">'. t('Comments') .'</h2>';
$output[] = $content .'</div>';
}
return implode("\n", $output);
}
return '';
}
function phptemplate_links($links, $attributes = array('class' => 'links')) {
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
if (isset($link['attributes']) && isset($link['attributes']['class'])) {
$link['attributes']['class'] .= ' '. $key;
}
else {
$link['attributes']['class'] = $key;
}
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
$html = isset($link['html']) && $link['html'];
$link['query'] = isset($link['query']) ? $link['query'] : NULL;
$link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
if (isset($link['href'])) {
$output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html = TRUE);
}
else if (!empty($link['title'])) {
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
function phptemplate_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
$output = '<div class="item-list">';
if (isset($title)) {
$output .= '<h3>'. $title .'</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
foreach ($items as $i => $item) {
$attributes = array();
$children = array();
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (count($children) > 0) {
$data .= theme_item_list($children, NULL, $type, $attributes);
}
if ($i == 0) {
$attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
}
if ($i == $num_items - 1) {
$attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
}
$output .= '<li' . drupal_attributes($attributes) . '>'. $data .'</li>'. "\n";
}
$output .= "</$type>";
}
$output .= '</div>';
return $output;
}
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">' . implode('<span class="breadcrumb-separate"> » </span>', $breadcrumb) . '</div>';
}
}
function phptemplate_feed_icon($url) {
global $theme;
$skin = theme_get_setting($theme . '_skin');
if ($skin && $skin != 'default') {
$path = path_to_theme() . '/skin/' . $skin . '/images/feed.png';
if (!is_file($path)) {
$path = path_to_theme() . '/images/feed.png';
}
}
else {
$path = path_to_theme() . '/images/feed.png';
}
if (!is_file($path)) {
$path = 'misc/feed.png';
}
if ($image = theme('image', $path, t('Syndicate content'), t('Syndicate content'))) {
return '<a href="' . check_url($url) . '" class="feed-icon">' . $image . '</a>';
}
}
function phptemplate_mark($type = MARK_NEW) {
global $user;
if ($user->uid) {
if ($type == MARK_NEW) {
return ' <span class="marker marker-new">' . t('new') . '</span>';
}
else if ($type == MARK_UPDATED) {
return ' <span class="marker marker-update">' . t('updated') . '</span>';
}
}
}
// $Id: template.php,v 1.3 2008/09/26 0829 Exp $
/**
* Get theme setting values.
*/
if (is_null(theme_get_setting('diykit_skin'))) {
global $theme_key;
$defaults = array(
'diykit_skin' => 'default',
'diykit_layout' => 'fixed',
'diykit_column' => 'portal',
);
$settings = theme_get_settings($theme_key);
if (module_exists('node')) {
foreach (node_get_types() as $type => $name) {
unset($settings['toggle_node_info_' . $type]);
}
}
variable_set(
str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
array_merge($defaults, $settings)
);
theme_get_setting('', TRUE);
}
/**
* Block regions.
*/
function diykit_regions() {
return array(
'header' => t('header'),
'footer' => t('footer'),
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content_top' => t('content top'),
'content_bottom' => t('content bottom'),
'content_body_top' => t('content body top'),
'content_body_bottom' => t('content body bottom'),
);
}
/**
* Override and insert phptemplate variables.
*/
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case 'page':
global $user;
global $theme;
// $xml
$user_agent = getenv('HTTP_USER_AGENT');
if (!(strpos($user_agent, 'Windows') !== FALSE && strpos($user_agent, 'MSIE 6') !== FALSE)) {
$vars['xml'] = '<?xml version="1.0" encoding="utf-8"?>'. "\n";
}
// $css, $styles, $iefix
$skin = theme_get_setting($theme . '_skin');
$iefix = $vars['directory'] . '/css/ie-fix.css';
$vars['iefix'] = '';
if (file_exists($iefix)) {
$vars['iefix'] .= '<!--[if IE]><style type="text/css" media="all">@import "' . base_path() . $iefix . '";</style><![endif]-->' . "\n";
}
if ($skin == 'default') {
$css = $vars['directory'] . '/css/skin.css';
if (file_exists($css)) {
drupal_add_css($css, 'theme', 'all');
}
}
else if ($skin) {
$css = $vars['directory'] . '/skin/' . $skin . '/skin.css';
$skin_iefix = $vars['directory'] . '/skin/' . $skin . '/ie-fix.css';
if (file_exists($css)) {
drupal_add_css($css, 'theme', 'all');
}
if (file_exists($skin_iefix)) {
$vars['iefix'] .= '<!--[if IE]><style type="text/css" media="all">@import "' . base_path() . $skin_iefix . '";</style><![endif]-->' . "\n";
}
}
$vars['css'] = drupal_add_css();
$vars['styles'] = drupal_get_css();
// $body_classes
$layout = theme_get_setting($theme . '_layout');
$column = theme_get_setting($theme . '_column');
$body_classes[] = !empty($vars['is_front']) ? 'front' : 'not-front';
$body_classes[] = ($user->uid > 0) ? ' logged-in' : ' not-logged-in';
$body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. form_clean_id(drupal_strtolower(arg(0))));
if (isset($vars['node']) && $vars['node']->type) {
$body_classes[] = 'node-type-'. form_clean_id($vars['node']->type);
}
if ($vars['layout'] == 'both') {
$body_classes[] = 'two-sidebars';
}
elseif ($vars['layout'] == 'none') {
$body_classes[] = 'no-sidebars';
}
else {
$body_classes[] = 'one-sidebar sidebar-'. $vars['layout'];
}
if ($layout) { $body_classes[] = $layout; }
if ($column) { $body_classes[] = $column; }
$vars['body_classes'] = implode(' ', $body_classes);
// $site_footer, $footer
$vars['site_footer'] = filter_xss_admin(variable_get('site_footer', FALSE));
$vars['footer'] = theme('blocks', 'footer');
break;
case 'node':
// $node_classes
$node_classes[] = 'node';
if ($vars['page'] == 0) {
$node_classes[] = 'teaser';
$node_classes[] = $vars['zebra'];
}
if ($vars['page'] == 1) {
$node_classes[] = 'page';
}
if ($vars['sticky']) {
$node_classes[] = 'sticky';
}
if (!$vars['node']->status) {
$node_classes[] = 'node-unpublished';
}
if ($vars['node']->type) {
$node_classes[] = 'type-' . $vars['node']->type;
}
$vars['node_classes'] = implode(' ', $node_classes);
// $content_body_top, $content_body_bottom
if ($vars['page'] == 1) {
$vars['content_body_top'] = theme('blocks', 'content_body_top');
$vars['content_body_bottom'] = theme('blocks', 'content_body_bottom');
}
break;
case 'comment':
global $user;
$node = node_load($vars['comment']->nid);
// $comment_classes
$comment_classes[] = 'comment';
if ($vars['comment']->new) {
$comment_classes[] = 'comment-new';
}
if ($vars['comment']->status == COMMENT_NOT_PUBLISHED) {
$comment_classes[] = 'comment-unpublished';
}
if ($vars['comment']->uid == $node->uid) {
$comment_classes[] = 'comment-by-author';
}
if ($user->uid && $vars['comment']->uid == $user->uid) {
$comment_classes[] = 'comment-mine';
}
if ($vars['comment']->uid) {
$comment_classes[] = 'comment-uid-' . $vars['comment']->uid;
}
$comment_classes[] = $vars['zebra'];
$vars['comment_classes'] = implode(' ', $comment_classes);
break;
case 'block':
// $block_classes
$block_classes[] = 'block';
$block_classes[] = 'block-' . $vars['block']->module;
$block_classes[] = $vars['zebra'];
$block_classes[] = $vars['block']->region . '-' . $vars['block_zebra'];
$block_classes[] = $vars['block']->region . '-' . $vars['block_id'];
$vars['block_classes'] = implode(' ', $block_classes);
break;
}
return $vars;
}
/**
* Override theme functions.
*/
function phptemplate_comment_wrapper($content, $type = null) {
static $node_type;
if (isset($type)) {
$node_type = $type;
}
if ($content) {
if ($node_type == 'forum') {
$output[] = '<div id="comments">'. $content .'</div>';
}
else {
$output[] = '<div id="comments">';
$output[] = '<h2 class="title comments">'. t('Comments') .'</h2>';
$output[] = $content .'</div>';
}
return implode("\n", $output);
}
return '';
}
function phptemplate_links($links, $attributes = array('class' => 'links')) {
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
if (isset($link['attributes']) && isset($link['attributes']['class'])) {
$link['attributes']['class'] .= ' '. $key;
}
else {
$link['attributes']['class'] = $key;
}
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
$html = isset($link['html']) && $link['html'];
$link['query'] = isset($link['query']) ? $link['query'] : NULL;
$link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
if (isset($link['href'])) {
$output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html = TRUE);
}
else if (!empty($link['title'])) {
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
function phptemplate_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
$output = '<div class="item-list">';
if (isset($title)) {
$output .= '<h3>'. $title .'</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
foreach ($items as $i => $item) {
$attributes = array();
$children = array();
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (count($children) > 0) {
$data .= theme_item_list($children, NULL, $type, $attributes);
}
if ($i == 0) {
$attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
}
if ($i == $num_items - 1) {
$attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
}
$output .= '<li' . drupal_attributes($attributes) . '>'. $data .'</li>'. "\n";
}
$output .= "</$type>";
}
$output .= '</div>';
return $output;
}
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">' . implode('<span class="breadcrumb-separate"> » </span>', $breadcrumb) . '</div>';
}
}
function phptemplate_feed_icon($url) {
global $theme;
$skin = theme_get_setting($theme . '_skin');
if ($skin && $skin != 'default') {
$path = path_to_theme() . '/skin/' . $skin . '/images/feed.png';
if (!is_file($path)) {
$path = path_to_theme() . '/images/feed.png';
}
}
else {
$path = path_to_theme() . '/images/feed.png';
}
if (!is_file($path)) {
$path = 'misc/feed.png';
}
if ($image = theme('image', $path, t('Syndicate content'), t('Syndicate content'))) {
return '<a href="' . check_url($url) . '" class="feed-icon">' . $image . '</a>';
}
}
function phptemplate_mark($type = MARK_NEW) {
global $user;
if ($user->uid) {
if ($type == MARK_NEW) {
return ' <span class="marker marker-new">' . t('new') . '</span>';
}
else if ($type == MARK_UPDATED) {
return ' <span class="marker marker-update">' . t('updated') . '</span>';
}
}
}

