filename) . '/template.php'; if (file_exists($file)) { include_once($file); } } function phptemplate_templates($directory = 'themes') { return system_listing('^page\.tpl\.php$', $directory, 'filename'); } /** * Execute a template engine call. * * Each call to the template engine has two parts. Namely preparing * the variables, and then doing something with them. * * The first step is done by all template engines / themes, the second * step is dependent on the engine used. * * @param $hook * The name of the theme function being executed * @param $vars * A sequential array of variables passed to the theme function. * @param $file * A suggested template file to use. * @return * The HTML generated by the template system. */ function _phptemplate_callback($hook, $vars = array(), $file = null) { global $theme_engine; // Allow specified variables to be overridden $variables_function = '_' . $theme_engine . '_variables'; if (function_exists($variables_function)) { $vars = array_merge($vars, call_user_func($variables_function, $hook, $vars)); } if ($vars['template_file']) { $file = $vars['template_file']; } $hook_function = '_' . $theme_engine . '_' . $hook; $default_function = '_' . $theme_engine . '_default'; if (function_exists($hook_function)) { return call_user_func($hook_function, $vars, $file); } elseif (function_exists($default_function)) { return call_user_func($default_function, $hook, $vars, $file); } } /** * Counts how many times certain hooks have been called * * Sidebar left / right are special cases. */ function _phptemplate_default_variables($hook, $vars) { static $count = array(); $count[$hook] = is_int($count[$hook]) ? $count[$hook] : 1; $vars['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even'; $vars['seqid'] = $count[$hook]++; global $sidebar_indicator; if ($hook == 'block') { $count['block_counter'][$sidebar_indicator] = is_int($count['block_counter'][$sidebar_indicator]) ? $count['block_counter'][$sidebar_indicator] : 1; $vars['block_zebra'] = ($count['block_counter'][$sidebar_indicator] % 2) ? 'odd' : 'even'; $vars['block_seqid'] = $count['block_counter'][$sidebar_indicator]++; } // Tell all templates where they are located. $vars['directory'] = path_to_theme(); if (drupal_get_path_alias($_GET['q']) == variable_get('site_frontpage', 'node')) { $vars['is_front'] = true; } return $vars; } function phptemplate_features() { return array( 'logo', 'toggle_name', 'toggle_search', 'toggle_slogan', 'toggle_mission', 'toggle_primary_links', 'toggle_secondary_links', 'toggle_node_user_picture', 'toggle_comment_user_picture'); } /** * PHPTemplate specific theme settings * * Due to differences in the handling of primary and secondary links, these settings need to be seperately specified for phptemplate based themes. * * @returns * HTML code for the phptemplate engine specific form segment on theme configuration pages. */ function phptemplate_settings() { $header = array(t('link text'), t('url'), t('description')); $form = t('

Due to incompatibilies in the handling of primary, and secondary links in PHPTemplate, these links need to specified seperately using the form below. Even though this is on the theme-specific configuration page, these settings will take affect in all themes using PHPTemplate.

'); foreach (array('Primary', 'Secondary') as $utype) { $rows = array(); //Use $utype field , and strtolower() it to get the type field.. to avoid issues with ucfirst() and unicode. $type = strtolower($utype); //Increment the link count, if the user has requested more links. if (variable_get('phptemplate_' . $type . '_links_more', false)) { variable_del('phptemplate_' . $type . '_links_more'); variable_set('phptemplate_' . $type . '_link_count', variable_get('phptemplate_' . $type . '_link_count', 5) + 5); } //Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format. $value = variable_get('phptemplate_' . $type . '_links', array()); //Get the amount of links to show, possibly expanding if there are more links defined than the count specifies. $count = variable_get('phptemplate_' . $type . '_link_count', 5); $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']); if (variable_get('phptemplate_' . $type . '_link_count', 5) != $count) { variable_set('phptemplate_' . $type . '_link_count', $count); } for ($i = 0; $i < $count; $i++) { $row = array(); foreach (array('text', 'link', 'description') as $field) { $row[] = form_textfield('', 'phptemplate_' . $type . '_links][' . $field . '][' . $i, $value[$field][$i], 15, 90); } $rows[] = $row; } $form .= form_item(t("$utype links"), theme("table", $header, $rows), t('You can specify your _TYPE_ links here, one link per line.
The link text field is the text you want to link.
The url field is the location the link points to.
The description field is an optional description of where the link points.', array('_TYPE_' => $type))); $form .= form_checkbox(t('I need more _TYPE_ links.', array('_TYPE_' => $type)), 'phptemplate_' . $type . '_links_more', 1, FALSE, t('Checking this box will give you 5 additional _TYPE_ links.', array('_TYPE_' => $type))); } return $form; } /** * Prepare the values passed to the theme_page function to be passed * into a pluggable template engine. */ function phptemplate_page($content) { global $node_cache; /* Set title and breadcrumb to declared values */ if (file_exists(path_to_theme() . '/favicon.ico')) { drupal_set_html_head("\n"); } if ($_GET['q'] == variable_get('site_frontpage', 'node')) { $mission = theme_get_setting('mission'); $frontpage = true; } $links['primary'] = array(); $links['secondary'] = array(); foreach (array('primary', 'secondary') as $type) { //Get the data to populate the textfields, if the variable is not an array .. try to parse the old-style link format. $value = variable_get('phptemplate_' . $type . '_links', array()); //Get the amount of links to show, possibly expanding if there are more links defined than the count specifies. $count = variable_get('phptemplate_' . $type . '_link_count', 5); $count = ($count > sizeof($value['link'])) ? $count : sizeof($value['link']); if (theme_get_setting('toggle_' . $type . '_links')) { for ($i =0; $i < $count; $i++) { unset($attributes); if (!empty($value['text'][$i])) { if (!empty($value['description'][$i])) { $attributes['title'] = $value['description'][$i]; } $text = $value['text'][$i]; $link = $value['link'][$i]; if (substr($link, 0, 4) == 'http') { $links[$type][$link] = ''. $text .''; } else { $links[$type][$link] = l($text, $link, $attributes); } } } } } /** * Populate sidebars. */ $layout = "none"; global $sidebar_indicator; /** * Sidebar_indicator tells the block counting code to count sidebars seperately. */ $sidebar_indicator = 'left'; $sidebar_left = theme("blocks", "left"); if ($sidebar_left != "") { $layout = "left"; } $sidebar_indicator = 'right'; $sidebar_right = theme("blocks", "right"); if ($sidebar_right != "") { $layout = ($layout == "left") ? "both" : "right"; } $sidebar_indicator = null; $vars = array( 'head_title' => (drupal_get_title() ? strip_tags(drupal_get_title()) .' | '. variable_get('site_name', 'drupal') : variable_get('site_name', 'drupal') .' | '. variable_get('site_slogan', '')), 'language' => $GLOBALS['locale'], 'site' => variable_get('site_name', 'drupal'), 'head' => drupal_get_html_head(), 'onload_attributes' => theme('onload_attribute'), 'logo' => theme_get_setting('logo'), 'site_name' => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''), 'site_slogan' => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''), 'search_box' => theme_get_setting('toggle_search'), 'search_url' => url('search'), 'search_button_text' => t('search'), 'search_description' => t('Enter the terms you wish to search for.'), 'title' => drupal_get_title(), 'primary_links' => $links['primary'], 'secondary_links' => $links['secondary'], 'breadcrumb' => theme('breadcrumb', drupal_get_breadcrumb()), 'tabs' => theme('menu_local_tasks'), 'messages' => theme('status_messages'), 'layout' => $layout, 'help' => menu_get_active_help(), 'styles' => theme_get_styles(), 'mission' => $mission, 'sidebar_left' => $sidebar_left, 'content' => '' . $content . '', 'sidebar_right' => $sidebar_right, 'footer_message' => variable_get('site_footer', FALSE), 'closure' => theme('closure') ); /** * Pass the node object to the page template on node views. */ if (sizeof($node_cache) == 1) { $vars['node'] = $node_cache[0]; } return _phptemplate_callback('page', $vars); } /** * Prepare the values passed to the theme_node function to be passed * into a pluggable template engine. */ function phptemplate_node($node, $main = 0, $page = 0) { global $node_cache; $node_cache[] = $node; if (module_exist('taxonomy')) { $taxonomy = taxonomy_link('taxonomy terms', $node); } else { $taxonomy = array(); } $vars = array( 'title' => check_plain($node->title), 'node_url' => url('node/' . $node->nid), 'terms' => theme('links',$taxonomy), 'name' => format_name($node), 'date' => format_date($node->created), 'sticky' => $node->sticky, 'picture' => theme_get_setting('toggle_node_user_picture') ? theme('user_picture', $node) : '', 'content' => ($main && $node->teaser) ? $node->teaser : $node->body, 'links' => $node->links ? theme('links', $node->links) : '', 'mission' => $mission, 'page' => $page, 'taxonomy' => $taxonomy, /* Lastly , pass the actual node to allow more customization */ 'node' => $node, 'main' => $main, 'page' => $page ); // Display info only on certain node types. if (theme_get_setting('toggle_node_info_' . $node->type)) { $vars['submitted'] = t('Submitted by %a on %b.', array('%a' => format_name($node), '%b' => format_date($node->created))); } return _phptemplate_callback('node', $vars, 'node-' . $node->type); } /** * Prepare the values passed to the theme_comment function to be passed * into a pluggable template engine. */ function phptemplate_comment($comment, $links = 0) { return _phptemplate_callback('comment', array( 'new' => $comment->new ? t('new') : '', 'comment' => $comment, 'submitted' => t('Submitted by %a on %b.', array('%a' => format_name($comment), '%b' => format_date($comment->timestamp))), 'title' => l($comment->subject, $_GET['q'], NULL, NULL, "comment-$comment->cid"), 'picture' => theme_get_setting('toggle_comment_user_picture') ? theme('user_picture', $comment) : '', 'links' => $links, 'content' => $comment->comment, 'author' => format_name($comment), 'date' => format_date($comment->timestamp) )); } /** * Prepare the values passed to the theme_block function to be passed * into a pluggable template engine. */ function phptemplate_block($block) { return _phptemplate_callback('block', array('block' => $block)); } /** * Prepare the values passed to the theme_box function to be passed * into a pluggable template engine. */ function phptemplate_box($title, $content, $region = 'main') { return _phptemplate_callback('box', array( 'title' => $title, 'content' => $content, 'region' => $region )); } /** * Default callback for PHPTemplate. */ function _phptemplate_default($hook, $vars, $file = null, $extension = '.tpl.php') { global $theme_engine; if ($file && file_exists(path_to_theme() . "/$file$extension")) { $file = path_to_theme() . "/$file$extension"; } else { if (file_exists(path_to_theme() . "/$hook$extension")) { $file = path_to_theme() . "/$hook$extension"; } else { if (in_array($hook, array('node', 'block', 'box', 'comment'))) { $file = "themes/engines/$theme_engine/$hook$extension"; } else { $vars['hook'] = $hook; watchdog('error', $theme_engine . ' was instructed to override the ' . $hook . ' theme function, but no valid template file was found.'); $file = "themes/engines/$theme_engine/default$extension"; } } } if ($file) { return call_user_func('_' . $theme_engine . '_render', $file, $vars); } } function _phptemplate_render($file, $vars) { $phptemplate = new Template(dirname($file)); $phptemplate->set_vars($vars); return $phptemplate->fetch(basename($file)); } ?>