00001 <?php
00002
00003
00025 define('MARK_READ', 0);
00026
00030 define('MARK_NEW', 1);
00031
00035 define('MARK_UPDATED', 2);
00036
00044 function init_theme() {
00045 global $theme, $user, $custom_theme, $theme_key;
00046
00047
00048 if (isset($theme)) {
00049 return;
00050 }
00051
00052 drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
00053 $themes = list_themes();
00054
00055
00056
00057 $theme = !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland');
00058
00059
00060
00061 $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
00062
00063
00064 $theme_key = $theme;
00065
00066
00067 $base_theme = array();
00068 $ancestor = $theme;
00069 while ($ancestor && isset($themes[$ancestor]->base_theme)) {
00070 $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme];
00071 $ancestor = $themes[$ancestor]->base_theme;
00072 }
00073 _init_theme($themes[$theme], array_reverse($base_theme));
00074 }
00075
00101 function _init_theme($theme, $base_theme = array(), $registry_callback = '_theme_load_registry') {
00102 global $theme_info, $base_theme_info, $theme_engine, $theme_path;
00103 $theme_info = $theme;
00104 $base_theme_info = $base_theme;
00105
00106 $theme_path = dirname($theme->filename);
00107
00108
00109
00110
00111 $final_stylesheets = array();
00112
00113
00114 foreach ($base_theme as $base) {
00115 if (!empty($base->stylesheets)) {
00116 foreach ($base->stylesheets as $media => $stylesheets) {
00117 foreach ($stylesheets as $name => $stylesheet) {
00118 $final_stylesheets[$media][$name] = $stylesheet;
00119 }
00120 }
00121 }
00122 }
00123
00124
00125 if (!empty($theme->stylesheets)) {
00126 foreach ($theme->stylesheets as $media => $stylesheets) {
00127 foreach ($stylesheets as $name => $stylesheet) {
00128 $final_stylesheets[$media][$name] = $stylesheet;
00129 }
00130 }
00131 }
00132
00133
00134 foreach ($final_stylesheets as $media => $stylesheets) {
00135 foreach ($stylesheets as $stylesheet) {
00136 drupal_add_css($stylesheet, 'theme', $media);
00137 }
00138 }
00139
00140
00141 $final_scripts = array();
00142
00143
00144 foreach ($base_theme as $base) {
00145 if (!empty($base->scripts)) {
00146 foreach ($base->scripts as $name => $script) {
00147 $final_scripts[$name] = $script;
00148 }
00149 }
00150 }
00151
00152
00153 if (!empty($theme->scripts)) {
00154 foreach ($theme->scripts as $name => $script) {
00155 $final_scripts[$name] = $script;
00156 }
00157 }
00158
00159
00160 foreach ($final_scripts as $script) {
00161 drupal_add_js($script, 'theme');
00162 }
00163
00164 $theme_engine = NULL;
00165
00166
00167 if (isset($theme->engine)) {
00168
00169 include_once './' . $theme->owner;
00170
00171 $theme_engine = $theme->engine;
00172 if (function_exists($theme_engine . '_init')) {
00173 foreach ($base_theme as $base) {
00174 call_user_func($theme_engine . '_init', $base);
00175 }
00176 call_user_func($theme_engine . '_init', $theme);
00177 }
00178 }
00179 else {
00180
00181 foreach ($base_theme as $base) {
00182
00183 if (!empty($base->owner)) {
00184 include_once './' . $base->owner;
00185 }
00186 }
00187
00188 if (!empty($theme->owner)) {
00189 include_once './' . $theme->owner;
00190 }
00191 }
00192
00193 if (drupal_function_exists($registry_callback)) {
00194 $registry_callback($theme, $base_theme, $theme_engine);
00195 }
00196 }
00197
00204 function theme_get_registry($registry = NULL) {
00205 static $theme_registry = NULL;
00206 if (isset($registry)) {
00207 $theme_registry = $registry;
00208 }
00209
00210 return $theme_registry;
00211 }
00212
00216 function _theme_set_registry($registry) {
00217
00218 return theme_get_registry($registry);
00219 }
00220
00233 function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
00234
00235 $cache = cache_get("theme_registry:$theme->name", 'cache');
00236 if (isset($cache->data)) {
00237 $registry = $cache->data;
00238 }
00239 else {
00240
00241 $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
00242 _theme_save_registry($theme, $registry);
00243 }
00244 _theme_set_registry($registry);
00245 }
00246
00250 function _theme_save_registry($theme, $registry) {
00251 cache_set("theme_registry:$theme->name", $registry);
00252 }
00253
00259 function drupal_rebuild_theme_registry() {
00260 cache_clear_all('theme_registry', 'cache', TRUE);
00261 }
00262
00278 function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
00279 $function = $name . '_theme';
00280 if (function_exists($function)) {
00281 $result = $function($cache, $type, $theme, $path);
00282
00283 foreach ($result as $hook => $info) {
00284 $result[$hook]['type'] = $type;
00285 $result[$hook]['theme path'] = $path;
00286
00287
00288 if (!isset($info['template']) && !isset($info['function'])) {
00289 $result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name . '_') . $hook;
00290 }
00291
00292
00293
00294
00295
00296 if (isset($info['file']) && !isset($info['path'])) {
00297 $result[$hook]['file'] = $path . '/' . $info['file'];
00298 include_once($result[$hook]['file']);
00299 }
00300 elseif (isset($info['file']) && isset($info['path'])) {
00301 include_once($info['path'] . '/' . $info['file']);
00302 }
00303
00304 if (isset($info['template']) && !isset($info['path'])) {
00305 $result[$hook]['template'] = $path . '/' . $info['template'];
00306 }
00307
00308
00309
00310 if (!isset($info['arguments']) && isset($cache[$hook])) {
00311 $result[$hook]['arguments'] = $cache[$hook]['arguments'];
00312 }
00313
00314
00315 if (!isset($info['theme paths']) && isset($cache[$hook])) {
00316 $result[$hook]['theme paths'] = $cache[$hook]['theme paths'];
00317 }
00318
00319 $result[$hook]['theme paths'][] = isset($info['path']) ? $info['path'] : $path;
00320
00321
00322 if (!isset($info['preprocess functions']) || !is_array($info['preprocess functions'])) {
00323 $info['preprocess functions'] = array();
00324 $prefixes = array();
00325 if ($type == 'module') {
00326
00327 $prefixes[] = 'template';
00328
00329
00330 $prefixes += module_list();
00331 }
00332 elseif ($type == 'theme_engine') {
00333
00334 $prefixes[] = $name . '_engine';
00335
00336 $prefixes[] = $name;
00337 $prefixes[] = $theme;
00338 }
00339 else {
00340
00341 $prefixes[] = $name;
00342 }
00343
00344 foreach ($prefixes as $prefix) {
00345 if (function_exists($prefix . '_preprocess')) {
00346 $info['preprocess functions'][] = $prefix . '_preprocess';
00347 }
00348 if (function_exists($prefix . '_preprocess_' . $hook)) {
00349 $info['preprocess functions'][] = $prefix . '_preprocess_' . $hook;
00350 }
00351 }
00352 }
00353
00354
00355 if (!empty($info['override preprocess functions'])) {
00356
00357 unset($result[$hook]['override preprocess functions']);
00358 }
00359 elseif (isset($cache[$hook]['preprocess functions']) && is_array($cache[$hook]['preprocess functions'])) {
00360 $info['preprocess functions'] = array_merge($cache[$hook]['preprocess functions'], $info['preprocess functions']);
00361 }
00362 $result[$hook]['preprocess functions'] = $info['preprocess functions'];
00363 }
00364
00365
00366 $cache = array_merge($cache, $result);
00367 }
00368 }
00369
00381 function _theme_build_registry($theme, $base_theme, $theme_engine) {
00382 $cache = array();
00383
00384
00385 foreach (module_implements('theme') as $module) {
00386 _theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module));
00387 }
00388
00389
00390 foreach ($base_theme as $base) {
00391
00392 $base_path = dirname($base->filename);
00393 if ($theme_engine) {
00394 _theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);
00395 }
00396 _theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);
00397 }
00398
00399
00400 if ($theme_engine) {
00401 _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
00402 }
00403
00404
00405 _theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));
00406
00407
00408 drupal_alter('theme_registry', $cache);
00409 return $cache;
00410 }
00411
00423 function list_themes($refresh = FALSE) {
00424 static $list = array();
00425
00426 if ($refresh) {
00427 $list = array();
00428 }
00429
00430 if (empty($list)) {
00431 $list = array();
00432 $themes = array();
00433
00434
00435 if (db_is_active() && !defined('MAINTENANCE_MODE')) {
00436 $result = db_query("SELECT * FROM {system} WHERE type = '%s'", 'theme');
00437 while ($theme = db_fetch_object($result)) {
00438 if (file_exists($theme->filename)) {
00439 $theme->info = unserialize($theme->info);
00440 $themes[] = $theme;
00441 }
00442 }
00443 }
00444 else {
00445
00446 $themes = _system_theme_data();
00447 }
00448
00449 foreach ($themes as $theme) {
00450 foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
00451 foreach ($stylesheets as $stylesheet => $path) {
00452 if (file_exists($path)) {
00453 $theme->stylesheets[$media][$stylesheet] = $path;
00454 }
00455 }
00456 }
00457 foreach ($theme->info['scripts'] as $script => $path) {
00458 if (file_exists($path)) {
00459 $theme->scripts[$script] = $path;
00460 }
00461 }
00462 if (isset($theme->info['engine'])) {
00463 $theme->engine = $theme->info['engine'];
00464 }
00465 if (isset($theme->info['base theme'])) {
00466 $theme->base_theme = $theme->info['base theme'];
00467 }
00468
00469
00470 if (!isset($theme->status)) {
00471 $theme->status = 0;
00472 }
00473 $list[$theme->name] = $theme;
00474 }
00475 }
00476
00477 return $list;
00478 }
00479
00567 function theme() {
00568 $args = func_get_args();
00569 $hook = array_shift($args);
00570
00571 static $hooks = NULL;
00572 if (!isset($hooks)) {
00573 init_theme();
00574 $hooks = theme_get_registry();
00575 }
00576
00577 if (is_array($hook)) {
00578 foreach ($hook as $candidate) {
00579 if (isset($hooks[$candidate])) {
00580 break;
00581 }
00582 }
00583 $hook = $candidate;
00584 }
00585
00586 if (!isset($hooks[$hook])) {
00587 return;
00588 }
00589
00590 $info = $hooks[$hook];
00591 global $theme_path;
00592 $temp = $theme_path;
00593
00594 $theme_path = $info['theme path'];
00595
00596
00597 if (!empty($info['file'])) {
00598 $include_file = $info['file'];
00599 if (isset($info['path'])) {
00600 $include_file = $info['path'] . '/' . $include_file;
00601 }
00602 include_once($include_file);
00603 }
00604 if (isset($info['function'])) {
00605
00606 $output = call_user_func_array($info['function'], $args);
00607 }
00608 else {
00609
00610 $variables = array(
00611 'template_files' => array()
00612 );
00613 if (!empty($info['arguments'])) {
00614 $count = 0;
00615 foreach ($info['arguments'] as $name => $default) {
00616 $variables[$name] = isset($args[$count]) ? $args[$count] : $default;
00617 $count++;
00618 }
00619 }
00620
00621
00622 $render_function = 'theme_render_template';
00623 $extension = '.tpl.php';
00624
00625
00626 global $theme_engine;
00627 if (isset($theme_engine)) {
00628
00629
00630 if ($info['type'] != 'module') {
00631 if (function_exists($theme_engine . '_render_template')) {
00632 $render_function = $theme_engine . '_render_template';
00633 }
00634 $extension_function = $theme_engine . '_extension';
00635 if (function_exists($extension_function)) {
00636 $extension = $extension_function();
00637 }
00638 }
00639 }
00640
00641 if (isset($info['preprocess functions']) && is_array($info['preprocess functions'])) {
00642
00643
00644 $args = array(&$variables, $hook);
00645 foreach ($info['preprocess functions'] as $preprocess_function) {
00646 if (drupal_function_exists($preprocess_function)) {
00647 call_user_func_array($preprocess_function, $args);
00648 }
00649 }
00650 }
00651
00652
00653
00654
00655
00656 $suggestions = array();
00657
00658 if (isset($variables['template_files'])) {
00659 $suggestions = $variables['template_files'];
00660 }
00661 if (isset($variables['template_file'])) {
00662 $suggestions[] = $variables['template_file'];
00663 }
00664
00665 if ($suggestions) {
00666 $template_file = drupal_discover_template($info['theme paths'], $suggestions, $extension);
00667 }
00668
00669 if (empty($template_file)) {
00670 $template_file = $info['template'] . $extension;
00671 if (isset($info['path'])) {
00672 $template_file = $info['path'] . '/' . $template_file;
00673 }
00674 }
00675 $output = $render_function($template_file, $variables);
00676 }
00677
00678 $theme_path = $temp;
00679 return $output;
00680 }
00681
00687 function drupal_discover_template($paths, $suggestions, $extension = '.tpl.php') {
00688 global $theme_engine;
00689
00690
00691 $suggestions = array_reverse($suggestions);
00692 $paths = array_reverse($paths);
00693 foreach ($suggestions as $suggestion) {
00694 if (!empty($suggestion)) {
00695 foreach ($paths as $path) {
00696 if (file_exists($file = $path . '/' . $suggestion . $extension)) {
00697 return $file;
00698 }
00699 }
00700 }
00701 }
00702 }
00703
00707 function path_to_theme() {
00708 global $theme_path;
00709
00710 if (!isset($theme_path)) {
00711 init_theme();
00712 }
00713
00714 return $theme_path;
00715 }
00716
00729 function drupal_find_theme_functions($cache, $prefixes) {
00730 $templates = array();
00731 $functions = get_defined_functions();
00732
00733 foreach ($cache as $hook => $info) {
00734 foreach ($prefixes as $prefix) {
00735 if (!empty($info['pattern'])) {
00736 $matches = preg_grep('/^' . $prefix . '_' . $info['pattern'] . '/', $functions['user']);
00737 if ($matches) {
00738 foreach ($matches as $match) {
00739 $new_hook = str_replace($prefix . '_', '', $match);
00740 $templates[$new_hook] = array(
00741 'function' => $match,
00742 'arguments' => $info['arguments'],
00743 );
00744 }
00745 }
00746 }
00747 if (function_exists($prefix . '_' . $hook)) {
00748 $templates[$hook] = array(
00749 'function' => $prefix . '_' . $hook,
00750 );
00751 }
00752 }
00753 }
00754
00755 return $templates;
00756 }
00757
00769 function drupal_find_theme_templates($cache, $extension, $path) {
00770 $templates = array();
00771
00772
00773
00774
00775 $theme_paths = array();
00776 foreach (list_themes() as $theme_info) {
00777 if (!empty($theme_info->base_theme)) {
00778 $theme_paths[$theme_info->base_theme][$theme_info->name] = dirname($theme_info->filename);
00779 }
00780 }
00781 foreach ($theme_paths as $basetheme => $subthemes) {
00782 foreach ($subthemes as $subtheme => $subtheme_path) {
00783 if (isset($theme_paths[$subtheme])) {
00784 $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);
00785 }
00786 }
00787 }
00788 global $theme;
00789 $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : array();
00790
00791
00792 $regex = str_replace('.', '\.', $extension) . '$';
00793
00794
00795 $files = drupal_system_listing($regex, $path, 'name', 0);
00796 foreach ($files as $template => $file) {
00797
00798 if (strpos($file->filename, str_replace($subtheme_paths, '', $file->filename)) !== 0) {
00799 continue;
00800 }
00801
00802
00803
00804 if (($pos = strpos($template, '.')) !== FALSE) {
00805 $template = substr($template, 0, $pos);
00806 }
00807
00808
00809 $hook = strtr($template, '-', '_');
00810 if (isset($cache[$hook])) {
00811 $templates[$hook] = array(
00812 'template' => $template,
00813 'path' => dirname($file->filename),
00814 );
00815 }
00816 }
00817
00818 $patterns = array_keys($files);
00819
00820 foreach ($cache as $hook => $info) {
00821 if (!empty($info['pattern'])) {
00822
00823
00824 $pattern = strtr($info['pattern'], '_', '-');
00825
00826 $matches = preg_grep('/^' . $pattern . '/', $patterns);
00827 if ($matches) {
00828 foreach ($matches as $match) {
00829 $file = substr($match, 0, strpos($match, '.'));
00830
00831 $templates[strtr($file, '-', '_')] = array(
00832 'template' => $file,
00833 'path' => dirname($files[$match]->filename),
00834 'arguments' => $info['arguments'],
00835 );
00836 }
00837 }
00838 }
00839 }
00840 return $templates;
00841 }
00842
00860 function theme_get_settings($key = NULL) {
00861 $defaults = array(
00862 'mission' => '',
00863 'default_logo' => 1,
00864 'logo_path' => '',
00865 'default_favicon' => 1,
00866 'favicon_path' => '',
00867 'primary_links' => 1,
00868 'secondary_links' => 1,
00869 'toggle_logo' => 1,
00870 'toggle_favicon' => 1,
00871 'toggle_name' => 1,
00872 'toggle_search' => 1,
00873 'toggle_slogan' => 0,
00874 'toggle_mission' => 1,
00875 'toggle_node_user_picture' => 0,
00876 'toggle_comment_user_picture' => 0,
00877 'toggle_primary_links' => 1,
00878 'toggle_secondary_links' => 1,
00879 );
00880
00881 if (module_exists('node')) {
00882 foreach (node_get_types() as $type => $name) {
00883 $defaults['toggle_node_info_' . $type] = 1;
00884 }
00885 }
00886 $settings = array_merge($defaults, variable_get('theme_settings', array()));
00887
00888 if ($key) {
00889 $settings = array_merge($settings, variable_get(str_replace('/', '_', 'theme_' . $key . '_settings'), array()));
00890 }
00891
00892
00893 if (!module_exists('search') || !user_access('search content')) {
00894 $settings['toggle_search'] = 0;
00895 }
00896
00897 return $settings;
00898 }
00899
00916 function theme_get_setting($setting_name, $refresh = FALSE) {
00917 global $theme_key;
00918 static $settings;
00919
00920 if (empty($settings) || $refresh) {
00921 $settings = theme_get_settings($theme_key);
00922
00923 $themes = list_themes();
00924 $theme_object = $themes[$theme_key];
00925
00926 if ($settings['mission'] == '') {
00927 $settings['mission'] = variable_get('site_mission', '');
00928 }
00929
00930 if (!$settings['toggle_mission']) {
00931 $settings['mission'] = '';
00932 }
00933
00934 if ($settings['toggle_logo']) {
00935 if ($settings['default_logo']) {
00936 $settings['logo'] = base_path() . dirname($theme_object->filename) . '/logo.png';
00937 }
00938 elseif ($settings['logo_path']) {
00939 $settings['logo'] = base_path() . $settings['logo_path'];
00940 }
00941 }
00942
00943 if ($settings['toggle_favicon']) {
00944 if ($settings['default_favicon']) {
00945 if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) {
00946 $settings['favicon'] = base_path() . $favicon;
00947 }
00948 else {
00949 $settings['favicon'] = base_path() . 'misc/favicon.ico';
00950 }
00951 }
00952 elseif ($settings['favicon_path']) {
00953 $settings['favicon'] = base_path() . $settings['favicon_path'];
00954 }
00955 else {
00956 $settings['toggle_favicon'] = FALSE;
00957 }
00958 }
00959 }
00960
00961 return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
00962 }
00963
00975 function theme_render_template($file, $variables) {
00976 extract($variables, EXTR_SKIP);
00977 ob_start();
00978 include "./$file";
00979 $contents = ob_get_contents();
00980 ob_end_clean();
00981 return $contents;
00982 }
00983
01059 function theme_placeholder($text) {
01060 return '<em>' . check_plain($text) . '</em>';
01061 }
01062
01073 function theme_status_messages($display = NULL) {
01074 $output = '';
01075 foreach (drupal_get_messages($display) as $type => $messages) {
01076 $output .= "<div class=\"messages $type\">\n";
01077 if (count($messages) > 1) {
01078 $output .= " <ul>\n";
01079 foreach ($messages as $message) {
01080 $output .= ' <li>' . $message . "</li>\n";
01081 }
01082 $output .= " </ul>\n";
01083 }
01084 else {
01085 $output .= $messages[0];
01086 }
01087 $output .= "</div>\n";
01088 }
01089 return $output;
01090 }
01091
01102 function theme_links($links, $attributes = array('class' => 'links')) {
01103 $output = '';
01104
01105 if (count($links) > 0) {
01106 $output = '<ul' . drupal_attributes($attributes) . '>';
01107
01108 $num_links = count($links);
01109 $i = 1;
01110
01111 foreach ($links as $key => $link) {
01112 $class = $key;
01113
01114
01115 if ($i == 1) {
01116 $class .= ' first';
01117 }
01118 if ($i == $num_links) {
01119 $class .= ' last';
01120 }
01121 if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
01122 $class .= ' active';
01123 }
01124 $output .= '<li class="' . $class . '">';
01125
01126 if (isset($link['href'])) {
01127
01128 $output .= l($link['title'], $link['href'], $link);
01129 }
01130 else if (!empty($link['title'])) {
01131
01132 if (empty($link['html'])) {
01133 $link['title'] = check_plain($link['title']);
01134 }
01135 $span_attributes = '';
01136 if (isset($link['attributes'])) {
01137 $span_attributes = drupal_attributes($link['attributes']);
01138 }
01139 $output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
01140 }
01141
01142 $i++;
01143 $output .= "</li>\n";
01144 }
01145
01146 $output .= '</ul>';
01147 }
01148
01149 return $output;
01150 }
01151
01168 function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
01169 if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) {
01170 $attributes = drupal_attributes($attributes);
01171 $url = (url($path) == $path) ? $path : (base_path() . $path);
01172 return '<img src="' . check_url($url) . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . (isset($image_attributes) ? $image_attributes : '') . $attributes . ' />';
01173 }
01174 }
01175
01183 function theme_breadcrumb($breadcrumb) {
01184 if (!empty($breadcrumb)) {
01185 return '<div class="breadcrumb">' . implode(' » ', $breadcrumb) . '</div>';
01186 }
01187 }
01188
01194 function theme_help() {
01195 if ($help = menu_get_active_help()) {
01196 return '<div class="help">' . $help . '</div>';
01197 }
01198 }
01199
01206 function theme_submenu($links) {
01207 return '<div class="submenu">' . implode(' | ', $links) . '</div>';
01208 }
01209
01283 function theme_table($header, $rows, $attributes = array(), $caption = NULL, $colgroups = array()) {
01284
01285
01286 if (count($header)) {
01287 drupal_add_js('misc/tableheader.js');
01288
01289
01290 $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class'] . ' sticky-enabled');
01291 }
01292
01293 $output = '<table' . drupal_attributes($attributes) . ">\n";
01294
01295 if (isset($caption)) {
01296 $output .= '<caption>' . $caption . "</caption>\n";
01297 }
01298
01299
01300 if (count($colgroups)) {
01301 foreach ($colgroups as $number => $colgroup) {
01302 $attributes = array();
01303
01304
01305 if (isset($colgroup['data'])) {
01306 foreach ($colgroup as $key => $value) {
01307 if ($key == 'data') {
01308 $cols = $value;
01309 }
01310 else {
01311 $attributes[$key] = $value;
01312 }
01313 }
01314 }
01315 else {
01316 $cols = $colgroup;
01317 }
01318
01319
01320 if (is_array($cols) && count($cols)) {
01321 $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
01322 $i = 0;
01323 foreach ($cols as $col) {
01324 $output .= ' <col' . drupal_attributes($col) . ' />';
01325 }
01326 $output .= " </colgroup>\n";
01327 }
01328 else {
01329 $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
01330 }
01331 }
01332 }
01333
01334
01335 if (count($header)) {
01336 $ts = tablesort_init($header);
01337
01338
01339 $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
01340 foreach ($header as $cell) {
01341 $cell = tablesort_header($cell, $header, $ts);
01342 $output .= _theme_table_cell($cell, TRUE);
01343 }
01344
01345 $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
01346 }
01347 else {
01348 $ts = array();
01349 }
01350
01351
01352 if (count($rows)) {
01353 $output .= "<tbody>\n";
01354 $flip = array('even' => 'odd', 'odd' => 'even');
01355 $class = 'even';
01356 foreach ($rows as $number => $row) {
01357 $attributes = array();
01358
01359
01360 if (isset($row['data'])) {
01361 foreach ($row as $key => $value) {
01362 if ($key == 'data') {
01363 $cells = $value;
01364 }
01365 else {
01366 $attributes[$key] = $value;
01367 }
01368 }
01369 }
01370 else {
01371 $cells = $row;
01372 }
01373 if (count($cells)) {
01374
01375 $class = $flip[$class];
01376 if (isset($attributes['class'])) {
01377 $attributes['class'] .= ' ' . $class;
01378 }
01379 else {
01380 $attributes['class'] = $class;
01381 }
01382
01383
01384 $output .= ' <tr' . drupal_attributes($attributes) . '>';
01385 $i = 0;
01386 foreach ($cells as $cell) {
01387 $cell = tablesort_cell($cell, $header, $ts, $i++);
01388 $output .= _theme_table_cell($cell);
01389 }
01390 $output .= " </tr>\n";
01391 }
01392 }
01393 $output .= "</tbody>\n";
01394 }
01395
01396 $output .= "</table>\n";
01397 return $output;
01398 }
01399
01403 function theme_table_select_header_cell() {
01404 drupal_add_js('misc/tableselect.js');
01405
01406 return array('class' => 'select-all');
01407 }
01408
01417 function theme_tablesort_indicator($style) {
01418 if ($style == "asc") {
01419 return theme('image', 'misc/arrow-asc.png', t('sort icon'), t('sort ascending'));
01420 }
01421 else {
01422 return theme('image', 'misc/arrow-desc.png', t('sort icon'), t('sort descending'));
01423 }
01424 }
01425
01438 function theme_box($title, $content, $region = 'main') {
01439 $output = '<h2 class="title">' . $title . '</h2><div>' . $content . '</div>';
01440 return $output;
01441 }
01442
01453 function theme_mark($type = MARK_NEW) {
01454 global $user;
01455 if ($user->uid) {
01456 if ($type == MARK_NEW) {
01457 return ' <span class="marker">' . t('new') . '</span>';
01458 }
01459 else if ($type == MARK_UPDATED) {
01460 return ' <span class="marker">' . t('updated') . '</span>';
01461 }
01462 }
01463 }
01464
01483 function theme_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
01484 $output = '<div class="item-list">';
01485 if (isset($title)) {
01486 $output .= '<h3>' . $title . '</h3>';
01487 }
01488
01489 if (!empty($items)) {
01490 $output .= "<$type" . drupal_attributes($attributes) . '>';
01491 $num_items = count($items);
01492 foreach ($items as $i => $item) {
01493 $attributes = array();
01494 $children = array();
01495 if (is_array($item)) {
01496 foreach ($item as $key => $value) {
01497 if ($key == 'data') {
01498 $data = $value;
01499 }
01500 elseif ($key == 'children') {
01501 $children = $value;
01502 }
01503 else {
01504 $attributes[$key] = $value;
01505 }
01506 }
01507 }
01508 else {
01509 $data = $item;
01510 }
01511 if (count($children) > 0) {
01512 $data .= theme_item_list($children, NULL, $type, $attributes);
01513 }
01514 if ($i == 0) {
01515 $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] . ' first');
01516 }
01517 if ($i == $num_items - 1) {
01518 $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] . ' last');
01519 }
01520 $output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
01521 }
01522 $output .= "</$type>";
01523 }
01524 $output .= '</div>';
01525 return $output;
01526 }
01527
01531 function theme_more_help_link($url) {
01532 return '<div class="more-help-link">' . t('<a href="@link">More help</a>', array('@link' => check_url($url))) . '</div>';
01533 }
01534
01544 function theme_xml_icon($url) {
01545 if ($image = theme('image', 'misc/xml.png', t('XML feed'), t('XML feed'))) {
01546 return '<a href="' . check_url($url) . '" class="xml-icon">' . $image . '</a>';
01547 }
01548 }
01549
01558 function theme_feed_icon($url, $title) {
01559 if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), $title)) {
01560 return '<a href="' . check_url($url) . '" class="feed-icon">' . $image . '</a>';
01561 }
01562 }
01563
01572 function theme_more_link($url, $title) {
01573 return '<div class="more-link">' . t('<a href="@link" title="@title">more</a>', array('@link' => check_url($url), '@title' => $title)) . '</div>';
01574 }
01575
01585 function theme_closure($main = 0) {
01586 $footer = module_invoke_all('footer', $main);
01587 return implode("\n", $footer) . drupal_get_js('footer');
01588 }
01589
01598 function theme_blocks($region) {
01599 $output = '';
01600
01601 if ($list = block_list($region)) {
01602 foreach ($list as $key => $block) {
01603
01604 $output .= theme('block', $block);
01605 }
01606 }
01607
01608
01609 $output .= drupal_get_content($region);
01610
01611 return $output;
01612 }
01613
01623 function theme_username($object) {
01624
01625 if ($object->uid && $object->name) {
01626
01627 if (drupal_strlen($object->name) > 20) {
01628 $name = drupal_substr($object->name, 0, 15) . '...';
01629 }
01630 else {
01631 $name = $object->name;
01632 }
01633
01634 if (user_access('access user profiles')) {
01635 $output = l($name, 'user/' . $object->uid, array('attributes' => array('title' => t('View user profile.'))));
01636 }
01637 else {
01638 $output = check_plain($name);
01639 }
01640 }
01641 else if ($object->name) {
01642
01643
01644
01645
01646 if (!empty($object->homepage)) {
01647 $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
01648 }
01649 else {
01650 $output = check_plain($object->name);
01651 }
01652
01653 $output .= ' (' . t('not verified') . ')';
01654 }
01655 else {
01656 $output = variable_get('anonymous', t('Anonymous'));
01657 }
01658
01659 return $output;
01660 }
01661
01672 function theme_progress_bar($percent, $message) {
01673 $output = '<div id="progress" class="progress">';
01674 $output .= '<div class="bar"><div class="filled" style="width: ' . $percent . '%"></div></div>';
01675 $output .= '<div class="percentage">' . $percent . '%</div>';
01676 $output .= '<div class="message">' . $message . '</div>';
01677 $output .= '</div>';
01678
01679 return $output;
01680 }
01681
01690 function theme_indentation($size = 1) {
01691 $output = '';
01692 for ($n = 0; $n < $size; $n++) {
01693 $output .= '<div class="indentation"> </div>';
01694 }
01695 return $output;
01696 }
01697
01702 function _theme_table_cell($cell, $header = FALSE) {
01703 $attributes = '';
01704
01705 if (is_array($cell)) {
01706 $data = isset($cell['data']) ? $cell['data'] : '';
01707 $header |= isset($cell['header']);
01708 unset($cell['data']);
01709 unset($cell['header']);
01710 $attributes = drupal_attributes($cell);
01711 }
01712 else {
01713 $data = $cell;
01714 }
01715
01716 if ($header) {
01717 $output = "<th$attributes>$data</th>";
01718 }
01719 else {
01720 $output = "<td$attributes>$data</td>";
01721 }
01722
01723 return $output;
01724 }
01725
01732 function template_preprocess(&$variables, $hook) {
01733 global $user;
01734 static $count = array();
01735
01736
01737
01738 $count[$hook] = isset($count[$hook]) && is_int($count[$hook]) ? $count[$hook] : 1;
01739 $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even';
01740 $variables['id'] = $count[$hook]++;
01741
01742
01743 $variables['directory'] = path_to_theme();
01744
01745
01746 $variables['is_admin'] = FALSE;
01747 $variables['is_front'] = FALSE;
01748 $variables['logged_in'] = FALSE;
01749 if ($variables['db_is_active'] = db_is_active() && !defined('MAINTENANCE_MODE')) {
01750
01751 if (user_access('access administration pages')) {
01752 $variables['is_admin'] = TRUE;
01753 }
01754
01755 $variables['is_front'] = drupal_is_front_page();
01756
01757 $variables['logged_in'] = ($user->uid > 0);
01758
01759 $variables['user'] = $user;
01760 }
01761 }
01762
01782 function template_preprocess_page(&$variables) {
01783
01784 if (theme_get_setting('toggle_favicon')) {
01785 drupal_set_html_head('<link rel="shortcut icon" href="' . check_url(theme_get_setting('favicon')) . '" type="image/x-icon" />');
01786 }
01787
01788 global $theme;
01789
01790 $regions = system_region_list($theme);
01791
01792 foreach (array_keys($regions) as $region) {
01793
01794 if (!(!$variables['show_blocks'] && ($region == 'left' || $region == 'right'))) {
01795 $blocks = theme('blocks', $region);
01796 }
01797 else {
01798 $blocks = '';
01799 }
01800
01801 isset($variables[$region]) ? $variables[$region] .= $blocks : $variables[$region] = $blocks;
01802 }
01803
01804
01805 $variables['layout'] = 'none';
01806 if (!empty($variables['left'])) {
01807 $variables['layout'] = 'left';
01808 }
01809 if (!empty($variables['right'])) {
01810 $variables['layout'] = ($variables['layout'] == 'left') ? 'both' : 'right';
01811 }
01812
01813
01814 if (drupal_is_front_page()) {
01815 $mission = filter_xss_admin(theme_get_setting('mission'));
01816 }
01817
01818
01819 if (drupal_get_title()) {
01820 $head_title = array(strip_tags(drupal_get_title()), variable_get('site_name', 'Drupal'));
01821 }
01822 else {
01823 $head_title = array(variable_get('site_name', 'Drupal'));
01824 if (variable_get('site_slogan', '')) {
01825 $head_title[] = variable_get('site_slogan', '');
01826 }
01827 }
01828 $variables['head_title'] = implode(' | ', $head_title);
01829 $variables['base_path'] = base_path();
01830 $variables['front_page'] = url();
01831 $variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());
01832 $variables['feed_icons'] = drupal_get_feeds();
01833 $variables['footer_message'] = filter_xss_admin(variable_get('site_footer', FALSE));
01834 $variables['head'] = drupal_get_html_head();
01835 $variables['help'] = theme('help');
01836 $variables['language'] = $GLOBALS['language'];
01837 $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
01838 $variables['logo'] = theme_get_setting('logo');
01839 $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
01840 $variables['mission'] = isset($mission) ? $mission : '';
01841 $variables['primary_links'] = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
01842 $variables['secondary_links'] = theme_get_setting('toggle_secondary_links') ? menu_secondary_links() : array();
01843 $variables['search_box'] = (theme_get_setting('toggle_search') ? drupal_get_form('search_theme_form') : '');
01844 $variables['site_name'] = (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : '');
01845 $variables['site_slogan'] = (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : '');
01846 $variables['css'] = drupal_add_css();
01847 $variables['styles'] = drupal_get_css();
01848 $variables['scripts'] = drupal_get_js();
01849 $variables['tabs'] = theme('menu_local_tasks');
01850 $variables['title'] = drupal_get_title();
01851
01852 $variables['closure'] = theme('closure');
01853
01854 if ($node = menu_get_object()) {
01855 $variables['node'] = $node;
01856 }
01857
01858
01859
01860 $body_classes = array();
01861
01862 $body_classes[] = $variables['is_front'] ? 'front' : 'not-front';
01863
01864 $body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
01865
01866
01867
01868
01869 $body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-' . form_clean_id(drupal_strtolower(arg(0))));
01870
01871 if (isset($variables['node']) && $variables['node']->type) {
01872 $body_classes[] = 'node-type-' . form_clean_id($variables['node']->type);
01873 }
01874
01875 if ($variables['layout'] == 'both') {
01876 $body_classes[] = 'two-sidebars';
01877 }
01878 elseif ($variables['layout'] == 'none') {
01879 $body_classes[] = 'no-sidebars';
01880 }
01881 else {
01882 $body_classes[] = 'one-sidebar sidebar-' . $variables['layout'];
01883 }
01884
01885 $variables['body_classes'] = implode(' ', $body_classes);
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897 $i = 0;
01898 $suggestion = 'page';
01899 $suggestions = array();
01900 while ($arg = arg($i++)) {
01901 $suggestions[] = $suggestion . '-' . $arg;
01902 if (!is_numeric($arg)) {
01903 $suggestion .= '-' . $arg;
01904 }
01905 }
01906 if (drupal_is_front_page()) {
01907 $suggestions[] = 'page-front';
01908 }
01909
01910 if ($suggestions) {
01911 $variables['template_files'] = $suggestions;
01912 }
01913 }
01914
01929 function template_preprocess_node(&$variables) {
01930 $node = $variables['node'];
01931 if (module_exists('taxonomy')) {
01932 $variables['taxonomy'] = taxonomy_link('taxonomy terms', $node);
01933 }
01934 else {
01935 $variables['taxonomy'] = array();
01936 }
01937
01938 if ($variables['teaser'] && $node->teaser) {
01939 $variables['content'] = $node->teaser;
01940 }
01941 elseif (isset($node->body)) {
01942 $variables['content'] = $node->body;
01943 }
01944 else {
01945 $variables['content'] = '';
01946 }
01947
01948 $variables['date'] = format_date($node->created);
01949 $variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
01950 $variables['name'] = theme('username', $node);
01951 $variables['node_url'] = url('node/' . $node->nid);
01952 $variables['terms'] = theme('links', $variables['taxonomy'], array('class' => 'links inline'));
01953 $variables['title'] = check_plain($node->title);
01954
01955
01956 $variables = array_merge((array)$node, $variables);
01957
01958
01959 if (theme_get_setting('toggle_node_info_' . $node->type)) {
01960 $variables['submitted'] = theme('node_submitted', $node);
01961 $variables['picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '';
01962 }
01963 else {
01964 $variables['submitted'] = '';
01965 $variables['picture'] = '';
01966 }
01967
01968 $variables['template_files'][] = 'node-' . $node->type;
01969 }
01970
01988 function template_preprocess_block(&$variables) {
01989 static $block_counter = array();
01990
01991 if (!isset($block_counter[$variables['block']->region])) {
01992 $block_counter[$variables['block']->region] = 1;
01993 }
01994
01995 $variables['block_zebra'] = ($block_counter[$variables['block']->region] % 2) ? 'odd' : 'even';
01996 $variables['block_id'] = $block_counter[$variables['block']->region]++;
01997
01998 $variables['template_files'][] = 'block-' . $variables['block']->region;
01999 $variables['template_files'][] = 'block-' . $variables['block']->module;
02000 $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta;
02001 }
02002