<?php
// $Id: template.php,v 1.6 2009/05/25 0829 Exp $
/**
* Get theme setting values.
*/
if (is_null(theme_get_setting('diykit_skin'))) {
global $theme_key;
$themes = list_themes();
$defaults = $themes[$theme_key]->info['settings'];
$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);
}
/**
* Override or insert PHPTemplate variables into the page.tpl.php.
*/
function phptemplate_preprocess_page(&$vars) {
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'] .'/ie-fix.css';
$vars['iefix'] = '';
if (file_exists($iefix)) {
$vars['iefix'] .= '<!--[if IE]><link type="text/css" rel="stylesheet" media="all" href="'. base_path() . $iefix .'" /><![endif]-->'. "\n";
}
if ($skin != 'none') {
$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]><link type="text/css" rel="stylesheet" media="all" href="'. base_path() . $skin_iefix .'" /><![endif]-->'. "\n";
}
}
drupal_add_css($vars['directory'] .'/common.css', 'theme', 'all');
$vars['css'] = drupal_add_css();
$vars['styles'] = drupal_get_css();
// $body_classes
$body_classes = array($vars['body_classes']);
$body_classes[] = theme_get_setting($theme .'_layout');
$body_classes[] = theme_get_setting($theme .'_column');
$vars['body_classes'] = implode(' ', $body_classes);
}
/**
* Override or insert PHPTemplate variables into the node.tpl.php.
*/
function phptemplate_preprocess_node(&$vars) {
// $node_classes
$node_classes[] = 'node';
if ($vars['teaser']) {
$node_classes[] = 'teaser';
$node_classes[] = $vars['zebra'];
}
if ($vars['page']) {
$node_classes[] = 'page';
}
if ($vars['sticky']) {
$node_classes[] = 'sticky';
}
if (!$vars['status']) {
$node_classes[] = 'node-unpublished';
}
$vars['node_classes'] = implode(' ', $node_classes);
// $node_body_top, $node_body_bottom
if ($vars['page']) {
$vars['node_body_top'] = theme('blocks', 'node_body_top');
$vars['node_body_bottom'] = theme('blocks', 'node_body_bottom');
}
}
/**
* Override or insert PHPTemplate variables into the comment-wrapper.tpl.php.
*/
function phptemplate_preprocess_comment_wrapper(&$vars) {
// $comments_title
if ($vars['content'] && $vars['node']->type != 'forum') {
$vars['comments_title'] = t('Comments');
}
}
/**
* Override or insert PHPTemplate variables into the comment.tpl.php.
*/
function phptemplate_preprocess_comment(&$vars) {
global $user;
// $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 == $vars['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);
}
/**
* Override or insert PHPTemplate variables into the block.tpl.php.
*/
function phptemplate_preprocess_block(&$vars) {
// $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);
}
/**
* Override theme functions.
*/
function phptemplate_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$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()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
$link['html'] = TRUE;
$output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link);
}
else if (!empty($link['title'])) {
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
global $theme;
if (theme_get_setting($theme .'_breadcrumb') == 1 && $title = drupal_get_title()) {
$breadcrumb[] = '<span class="current">'. $title .'</span>';
}
return '<div class="breadcrumb">'. implode('<span class="breadcrumb-separate"> » </span>', $breadcrumb) .'</div>';
}
}
function phptemplate_feed_icon($url, $title) {
global $theme;
$skin = theme_get_setting($theme .'_skin');
$path = 'misc/feed.png';
if (is_file($file = path_to_theme() .'/skin/'. $skin .'/images/feed.png')) {
$path = $file;
}
else if (is_file($file = path_to_theme() .'/images/feed.png')) {
$path = $file;
}
if ($image = theme('image', $path, t('Syndicate content'), t('Syndicate content'), $title)) {
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>';
}
}
}
function phptemplate_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$pager_middle = ceil($quantity / 2);
$pager_current = $pager_page_array[$element] + 1;
$pager_first = $pager_current - $pager_middle + 1;
$pager_last = $pager_current + $quantity - $pager_middle;
$pager_max = $pager_total[$element];
$i = $pager_first;
if ($pager_last > $pager_max) {
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
$li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('<span>«</span>First')), $limit, $element, $parameters);
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('<span>‹</span>Prev')), $limit, $element, 1, $parameters);
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('Next<span>›</span>')), $limit, $element, 1, $parameters);
$li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('Last<span>»</span>')), $limit, $element, $parameters);
if ($pager_total[$element] > 1) {
if ($li_first) {
$items[] = array(
'class' => 'pager-first',
'data' => $li_first,
);
}
if ($li_previous) {
$items[] = array(
'class' => 'pager-previous',
'data' => $li_previous,
);
}
if ($i != $pager_max) {
if ($i > 1) {
$items[] = array(
'class' => 'pager-ellipsis ellipsis-previous',
'data' => '<span class="pager-ellipsis">…</span>',
);
}
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
$items[] = array(
'class' => 'pager-item item-previous',
'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
);
}
if ($i == $pager_current) {
$items[] = array(
'class' => 'pager-current',
'data' => '<strong class="pager-current">'. $i .'</strong>',
);
}
if ($i > $pager_current) {
$items[] = array(
'class' => 'pager-item item-next',
'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
);
}
}
if ($i < $pager_max) {
$items[] = array(
'class' => 'pager-ellipsis ellipsis-next',
'data' => '<span class="pager-ellipsis">…</span>',
);
}
}
if ($li_next) {
$items[] = array(
'class' => 'pager-next',
'data' => $li_next,
);
}
if ($li_last) {
$items[] = array(
'class' => 'pager-last',
'data' => $li_last,
);
}
return theme('item_list', $items, NULL, 'ul', array('id' => 'pager'));
}
}
function phptemplate_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page;
}
$query = array();
if (count($parameters)) {
$query[] = drupal_query_string_encode($parameters, array());
}
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
if (!isset($attributes['title'])) {
static $titles = NULL;
if (!isset($titles)) {
$titles = array(
t('<span>«</span>First') => t('Go to first page'),
t('<span>‹</span>Prev') => t('Go to previous page'),
t('Next<span>›</span>') => t('Go to next page'),
t('Last<span>»</span>') => t('Go to last page'),
);
}
if (isset($titles[$text])) {
$attributes['title'] = $titles[$text];
}
else if (is_numeric($text)) {
$attributes['title'] = t('Go to page @number', array('@number' => $text));
}
}
return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => count($query) ? implode('&', $query) : NULL, 'html' => TRUE));
}
// $Id: template.php,v 1.6 2009/05/25 0829 Exp $
/**
* Get theme setting values.
*/
if (is_null(theme_get_setting('diykit_skin'))) {
global $theme_key;
$themes = list_themes();
$defaults = $themes[$theme_key]->info['settings'];
$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);
}
/**
* Override or insert PHPTemplate variables into the page.tpl.php.
*/
function phptemplate_preprocess_page(&$vars) {
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'] .'/ie-fix.css';
$vars['iefix'] = '';
if (file_exists($iefix)) {
$vars['iefix'] .= '<!--[if IE]><link type="text/css" rel="stylesheet" media="all" href="'. base_path() . $iefix .'" /><![endif]-->'. "\n";
}
if ($skin != 'none') {
$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]><link type="text/css" rel="stylesheet" media="all" href="'. base_path() . $skin_iefix .'" /><![endif]-->'. "\n";
}
}
drupal_add_css($vars['directory'] .'/common.css', 'theme', 'all');
$vars['css'] = drupal_add_css();
$vars['styles'] = drupal_get_css();
// $body_classes
$body_classes = array($vars['body_classes']);
$body_classes[] = theme_get_setting($theme .'_layout');
$body_classes[] = theme_get_setting($theme .'_column');
$vars['body_classes'] = implode(' ', $body_classes);
}
/**
* Override or insert PHPTemplate variables into the node.tpl.php.
*/
function phptemplate_preprocess_node(&$vars) {
// $node_classes
$node_classes[] = 'node';
if ($vars['teaser']) {
$node_classes[] = 'teaser';
$node_classes[] = $vars['zebra'];
}
if ($vars['page']) {
$node_classes[] = 'page';
}
if ($vars['sticky']) {
$node_classes[] = 'sticky';
}
if (!$vars['status']) {
$node_classes[] = 'node-unpublished';
}
$vars['node_classes'] = implode(' ', $node_classes);
// $node_body_top, $node_body_bottom
if ($vars['page']) {
$vars['node_body_top'] = theme('blocks', 'node_body_top');
$vars['node_body_bottom'] = theme('blocks', 'node_body_bottom');
}
}
/**
* Override or insert PHPTemplate variables into the comment-wrapper.tpl.php.
*/
function phptemplate_preprocess_comment_wrapper(&$vars) {
// $comments_title
if ($vars['content'] && $vars['node']->type != 'forum') {
$vars['comments_title'] = t('Comments');
}
}
/**
* Override or insert PHPTemplate variables into the comment.tpl.php.
*/
function phptemplate_preprocess_comment(&$vars) {
global $user;
// $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 == $vars['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);
}
/**
* Override or insert PHPTemplate variables into the block.tpl.php.
*/
function phptemplate_preprocess_block(&$vars) {
// $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);
}
/**
* Override theme functions.
*/
function phptemplate_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$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()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
$link['html'] = TRUE;
$output .= l('<span>'. $link['title'] .'</span>', $link['href'], $link);
}
else if (!empty($link['title'])) {
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
global $theme;
if (theme_get_setting($theme .'_breadcrumb') == 1 && $title = drupal_get_title()) {
$breadcrumb[] = '<span class="current">'. $title .'</span>';
}
return '<div class="breadcrumb">'. implode('<span class="breadcrumb-separate"> » </span>', $breadcrumb) .'</div>';
}
}
function phptemplate_feed_icon($url, $title) {
global $theme;
$skin = theme_get_setting($theme .'_skin');
$path = 'misc/feed.png';
if (is_file($file = path_to_theme() .'/skin/'. $skin .'/images/feed.png')) {
$path = $file;
}
else if (is_file($file = path_to_theme() .'/images/feed.png')) {
$path = $file;
}
if ($image = theme('image', $path, t('Syndicate content'), t('Syndicate content'), $title)) {
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>';
}
}
}
function phptemplate_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$pager_middle = ceil($quantity / 2);
$pager_current = $pager_page_array[$element] + 1;
$pager_first = $pager_current - $pager_middle + 1;
$pager_last = $pager_current + $quantity - $pager_middle;
$pager_max = $pager_total[$element];
$i = $pager_first;
if ($pager_last > $pager_max) {
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
$li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('<span>«</span>First')), $limit, $element, $parameters);
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('<span>‹</span>Prev')), $limit, $element, 1, $parameters);
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('Next<span>›</span>')), $limit, $element, 1, $parameters);
$li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('Last<span>»</span>')), $limit, $element, $parameters);
if ($pager_total[$element] > 1) {
if ($li_first) {
$items[] = array(
'class' => 'pager-first',
'data' => $li_first,
);
}
if ($li_previous) {
$items[] = array(
'class' => 'pager-previous',
'data' => $li_previous,
);
}
if ($i != $pager_max) {
if ($i > 1) {
$items[] = array(
'class' => 'pager-ellipsis ellipsis-previous',
'data' => '<span class="pager-ellipsis">…</span>',
);
}
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
$items[] = array(
'class' => 'pager-item item-previous',
'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
);
}
if ($i == $pager_current) {
$items[] = array(
'class' => 'pager-current',
'data' => '<strong class="pager-current">'. $i .'</strong>',
);
}
if ($i > $pager_current) {
$items[] = array(
'class' => 'pager-item item-next',
'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
);
}
}
if ($i < $pager_max) {
$items[] = array(
'class' => 'pager-ellipsis ellipsis-next',
'data' => '<span class="pager-ellipsis">…</span>',
);
}
}
if ($li_next) {
$items[] = array(
'class' => 'pager-next',
'data' => $li_next,
);
}
if ($li_last) {
$items[] = array(
'class' => 'pager-last',
'data' => $li_last,
);
}
return theme('item_list', $items, NULL, 'ul', array('id' => 'pager'));
}
}
function phptemplate_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page;
}
$query = array();
if (count($parameters)) {
$query[] = drupal_query_string_encode($parameters, array());
}
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
if (!isset($attributes['title'])) {
static $titles = NULL;
if (!isset($titles)) {
$titles = array(
t('<span>«</span>First') => t('Go to first page'),
t('<span>‹</span>Prev') => t('Go to previous page'),
t('Next<span>›</span>') => t('Go to next page'),
t('Last<span>»</span>') => t('Go to last page'),
);
}
if (isset($titles[$text])) {
$attributes['title'] = $titles[$text];
}
else if (is_numeric($text)) {
$attributes['title'] = t('Go to page @number', array('@number' => $text));
}
}
return l($text, $_GET['q'], array('attributes' => $attributes, 'query' => count($query) ? implode('&', $query) : NULL, 'html' => TRUE));
}

