chameleon.theme 5.7 KB
Newer Older
1 2 3
<?php
// $Id$

Dries's avatar
 
Dries committed
4 5
/**
 * @file
6
 * A slim, CSS-driven theme which does not depend on a template engine like phptemplate
Dries's avatar
 
Dries committed
7 8
 */

9 10 11
/**
 * Implementation of hook_theme. Auto-discover theme functions.
 */
12
function chameleon_theme($existing, $type, $theme, $path) {
13
  return drupal_find_theme_functions($existing, array($theme));
14 15
}

16
function chameleon_page($content, $show_blocks = TRUE, $show_messages = TRUE) {
17
  $language = isset($GLOBALS['language']) ? $GLOBALS['language']->language : NULL;
18

19 20 21 22
  if (theme_get_setting('toggle_favicon')) {
    drupal_set_html_head('<link rel="shortcut icon" href="'. check_url(theme_get_setting('favicon')) .'" type="image/x-icon" />');
  }

23 24
  $title = drupal_get_title();

25 26 27 28
  // Get blocks before so that they can alter the header (JavaScript, Stylesheets etc.)
  $blocks_left = theme_blocks('left');
  $blocks_right = theme_blocks('right');

29
  $output  = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
30
  $output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"$language\" xml:lang=\"$language\">\n";
31
  $output .= "<head>\n";
32
  $output .= " <title>". ($title ? strip_tags($title) ." | ". variable_get("site_name", "Drupal") : variable_get("site_name", "Drupal") ." | ". variable_get("site_slogan", "")) ."</title>\n";
33
  $output .= drupal_get_html_head();
34
  $output .= drupal_get_css();
35
  $output .= drupal_get_js();
36
  $output .= "</head>";
37
  $output .= "<body>\n";
38 39
  $output .= " <div id=\"header\">";

40
  if ($logo = theme_get_setting('logo')) {
41
    $output .= "  <a href=\"". url() ."\" title=\"". t('Home') ."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>";
42
  }
43
  if (theme_get_setting('toggle_name')) {
44
    $output .= "  <h1 class=\"site-name title\">". l(variable_get('site_name', 'drupal'), "") ."</h1>";
45
  }
46
  if (theme_get_setting('toggle_slogan')) {
47 48 49 50 51
    $output .= "  <div class=\"site-slogan\">". variable_get('site_slogan', '') ."</div>";
  }

  $output .= "</div>\n";

52 53
  $primary_links = theme('links', menu_primary_links(), array('class' => 'links', 'id' => 'navlist'));
  $secondary_links = theme('links', menu_secondary_links(), array('class' => 'links', 'id' => 'subnavlist'));
54
  if (isset($primary_links) || isset($secondary_links)) {
55
    $output .= ' <div class="navlinks">';
56
    if (isset($primary_links)) {
57
      $output .= $primary_links;
58
    }
59
    if (isset($secondary_links)) {
60
      $output .= $secondary_links;
61 62 63 64
    }
    $output .= " </div>\n";
  }

65
  $output .= " <table id=\"content\">\n";
66 67
  $output .= "  <tr>\n";

68 69
  if ($show_blocks && !empty($blocks_left)) {
    $output .= "   <td id=\"sidebar-left\">$blocks_left</td>\n";
70 71 72 73
  }

  $output .= "   <td id=\"main\">\n";

74
  if ($title) {
75 76 77 78 79 80 81 82
    $output .= theme("breadcrumb", drupal_get_breadcrumb());
    $output .= "<h2>$title</h2>";
  }

  if ($tabs = theme('menu_local_tasks')) {
    $output .= $tabs;
  }

83
  $output .= theme('help');
84

85 86 87
  if ($show_messages) {
    $output .= theme('status_messages');
  }
88 89 90

  $output .= "\n<!-- begin content -->\n";
  $output .= $content;
91
  $output .= drupal_get_feeds();
92 93 94 95 96 97
  $output .= "\n<!-- end content -->\n";

  if ($footer = variable_get('site_footer', '')) {
    $output .= " <div id=\"footer\">$footer</div>\n";
  }

98
  $output .= "   </td>\n";
99

100 101
  if ($show_blocks && !empty($blocks_right)) {
    $output .= "   <td id=\"sidebar-right\">$blocks_right</td>\n";
102 103 104 105 106 107 108 109 110 111 112 113
  }

  $output .= "  </tr>\n";
  $output .= " </table>\n";

  $output .=  theme_closure();
  $output .= " </body>\n";
  $output .= "</html>\n";

  return $output;
}

114
function chameleon_node($node, $teaser = 0, $page = 0) {
115

116
  $output  = "<div class=\"node". ((!$node->status) ? ' node-unpublished' : '') . (($node->sticky) ? ' sticky' : '') ."\">\n";
117 118

  if (!$page) {
119
    $output .= " <h2 class=\"title\">". ($teaser ? l($node->title, "node/$node->nid") : check_plain($node->title)) ."</h2>\n";
120 121 122 123
  }

  $output .= " <div class=\"content\">\n";

124
  if ($teaser && $node->teaser) {
125 126
    $output .= $node->teaser;
  }
127
  elseif (isset($node->body)) {
128 129 130 131 132
    $output .= $node->body;
  }

  $output .= " </div>\n";

133 134 135
  $submitted['node_submitted'] = theme_get_setting("toggle_node_info_$node->type") ? array(
    'title' => t("By !author at @date", array('!author' => theme('username', $node), '@date' => format_date($node->created, 'small'))),
    'html' => TRUE) : array();
136

137
  $terms = array();
138
  if (module_exists('taxonomy')) {
139 140 141
    $terms = taxonomy_link("taxonomy terms", $node);
  }

142
  $links = array_merge($submitted, $terms);
143
  if (isset($node->links)) {
144 145 146
    $links = array_merge($links, $node->links);
  }
  if (count($links)) {
147
    $output .= '<div class="links">'. theme('links', $links, array('class' => 'links inline')) ."</div>\n";
148 149 150 151 152 153 154
  }

  $output .= "</div>\n";

  return $output;
}

155
function chameleon_comment($comment, $node, $links = array()) {
156 157 158
  $submitted['comment_submitted'] = array(
    'title' => t('By !author at @date', array('!author' => theme('username', $comment), '@date' => format_date($comment->timestamp, 'small'))),
    'html' => TRUE);
159

160
  $output  = "<div class=\"comment". ($comment->status == COMMENT_NOT_PUBLISHED ? ' comment-unpublished' : '') ."\">\n";
161
  $output .= " <h3 class=\"title\">". l($comment->subject, $_GET['q'], array('fragment' => "comment-$comment->cid")) ."</h3>\n";
162
  $output .= " <div class=\"content\">". $comment->comment;
163
  if (!empty($signature)) {
164 165
    $output .= "  <div class=\"clear-block\">";
    $output .= "<div></div>\n";
166 167 168 169
    $output .= $signature ."\n";
    $output .= "  </div>\n";
  }
  $output .= " </div>\n";
170 171 172 173 174
  $output .= " <div class=\"links\">". theme('links', array_merge($submitted, $links)) ."</div>\n";
  $output .= "</div>\n";

  return $output;
}
175 176 177 178 179 180 181

function chameleon_help() {
  if ($help = menu_get_active_help()) {
    return '<div class="help">'. $help .'</div><hr />';
  }
}