/[drupal]/contributions/themes/d4rk/template.php
ViewVC logotype

Diff of /contributions/themes/d4rk/template.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri Jan 30 20:27:17 2009 UTC revision 1.2, Sun Feb 1 04:32:21 2009 UTC
# Line 0  Line 1 
1    <?php
2    //       This function creates the body classes that are relative to each page
3    //
4    //      @param $vars
5    //        A sequential array of variables to pass to the theme template.
6    //      @param $hook
7    //        The name of the theme function being called ("page" in this case.)
8    //
9    
10    function phptemplate_preprocess_page(&$vars, $hook) {
11      global $theme;
12    
13      // Don't display empty help from node_help().
14      if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
15        $vars['help'] = '';
16      }
17    
18      // Classes for body element. Allows advanced theming based on context
19      // (home page, node of certain type, etc.)
20      $body_classes = array($vars['body_classes']);
21      if (user_access('administer blocks')) {
22              $body_classes[] = 'admin';
23            }
24      if (!$vars['is_front']) {
25        // Add unique classes for each page and website section
26        $path = drupal_get_path_alias($_GET['q']);
27        list($section, ) = explode('/', $path, 2);
28        $body_classes[] = phptemplate_id_safe('page-'. $path);
29        $body_classes[] = phptemplate_id_safe('section-'. $section);
30    
31        if (arg(0) == 'node') {
32          if (arg(1) == 'add') {
33            if ($section == 'node') {
34              array_pop($body_classes); // Remove 'section-node'
35            }
36            $body_classes[] = 'section-node-add'; // Add 'section-node-add'
37          }
38          elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
39            if ($section == 'node') {
40              array_pop($body_classes); // Remove 'section-node'
41            }
42            $body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
43          }
44        }
45      }
46      // Check what the user's browser is and add it as a body class
47      $user_agent = $_SERVER['HTTP_USER_AGENT'];
48      if($user_agent) {
49        if (strpos($user_agent, 'MSIE')) {
50          $body_classes[] = 'browser-ie';
51        } else if (strpos($user_agent, 'MSIE 6.0')) {
52          $body_classes[] = 'browser-ie6';
53        } else if (strpos($user_agent, 'MSIE 7.0')) {
54          $body_classes[] = 'browser-ie7';
55        } else if (strpos($user_agent, 'MSIE 8.0')) {
56          $body_classes[] = 'browser-ie8';
57        } else if (strpos($user_agent, 'Firefox/2')) {
58          $body_classes[] = 'browser-firefox2';
59        } else if (strpos($user_agent, 'Firefox/3')) {
60          $body_classes[] = 'browser-firefox3';
61        }else if (strpos($user_agent, 'Safari')) {
62          $body_classes[] = 'browser-safari';
63        } else if (strpos($user_agent, 'Opera')) {
64          $body_classes[] = 'browser-opera';
65        }
66      }
67      $vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
68    }
69    
70    
71    
72    //
73    //      from ZEN // Override or insert PHPTemplate variables into the node templates.
74    //
75    //       This function creates the NODES classes, like 'node-unpublished' for nodes
76    //       that are not published, or 'node-mine' for node posted by the connected user...
77    //
78    //      @param $vars
79    //        A sequential array of variables to pass to the theme template.
80    //      @param $hook
81    //        The name of the theme function being called ("node" in this case.)
82    //
83    
84    function phptemplate_preprocess_node(&$vars, $hook) {
85      global $user;
86    
87      // Special classes for nodes
88      $node_classes = array();
89      if ($vars['sticky']) {
90        $node_classes[] = 'sticky';
91      }
92      if (!$vars['node']->status) {
93        $node_classes[] = 'node-unpublished';
94        $vars['unpublished'] = TRUE;
95      }
96      else {
97        $vars['unpublished'] = FALSE;
98      }
99      if ($vars['node']->uid && $vars['node']->uid == $user->uid) {
100        // Node is authored by current user
101        $node_classes[] = 'node-mine';
102      }
103      if ($vars['teaser']) {
104        // Node is displayed as teaser
105        $node_classes[] = 'node-teaser';
106      }
107      // Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
108      $node_classes[] = 'node-type-'. $vars['node']->type;
109      $vars['node_classes'] = implode(' ', $node_classes); // Concatenate with spaces
110    }
111    
112    
113    //
114    // from ZEN // Override or insert PHPTemplate variables into the block templates.
115    //
116    //      This function create the EDIT LINKS for blocks and menus blocks.
117    //      When overing a block (except in IE6), some links appear to edit
118    //      or configure the block. You can then edit the block, and once you are
119    //      done, brought back to the first page.
120    //
121    // @param $vars
122    //   A sequential array of variables to pass to the theme template.
123    // @param $hook
124    //   The name of the theme function being called ("block" in this case.)
125    //
126    
127    function phptemplate_preprocess_block(&$vars, $hook) {
128      $block = $vars['block'];
129    
130      if (user_access('administer blocks')) {
131        // Display 'edit block' for custom blocks
132        if ($block->module == 'block') {
133          $edit_links[] = l( t('edit block'), 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('edit the content of this block'), 'class' => 'block-edit'), drupal_get_destination(), NULL, FALSE, TRUE);
134        }
135        // Display 'configure' for other blocks
136        else {
137          $edit_links[] = l(t('configure'), 'admin/build/block/configure/'. $block->module .'/'. $block->delta, array('title' => t('configure this block'), 'class' => 'block-config'), drupal_get_destination(), NULL, FALSE, TRUE);
138        }
139    
140        // Display 'edit menu' for menu blocks
141        if (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
142          $edit_links[] = l(t('edit menu'), 'admin/build/menu', array('title' => t('edit the menu that defines this block'), 'class' => 'block-edit-menu'), drupal_get_destination(), NULL, FALSE, TRUE);
143        }
144        $vars['edit_links_array'] = $edit_links;
145        $vars['edit_links'] = '<div class="edit">'. implode(' ', $edit_links) .'</div>';
146      }
147    }
148    
149    
150    //
151    //  Create some custom classes for comments
152    //
153    
154    function comment_classes($comment) {
155      $node = node_load($comment->nid);
156      global $user;
157    
158      $output .= ($comment->new) ? ' comment-new' : '';
159      $output .=  ' '. $status .' ';
160      if ($node->name == $comment->name) {
161        $output .= 'node-author';
162      }
163      if ($user->name == $comment->name) {
164        $output .=  ' mine';
165      }
166      return $output;
167    }
168    
169    
170    //
171    //      Customize the PRIMARY and SECONDARY LINKS, to allow the admin tabs to work on all browsers
172    //      An implementation of theme_menu_item_link()
173    //
174    //      @param $link
175    //        array The menu item to render.
176    //      @return
177    //        string The rendered menu item.
178    //
179    
180    function phptemplate_menu_item_link($link) {
181      if (empty($link['options'])) {
182        $link['options'] = array();
183      }
184    
185      // If an item is a LOCAL TASK, render it as a tab
186      if ($link['type'] & MENU_IS_LOCAL_TASK) {
187        $link['title'] = '<span class="tab">'. check_plain($link['title']) .'</span>';
188        $link['options']['html'] = TRUE;
189      }
190    
191      if (empty($link['type'])) {
192        $true = TRUE;
193      }
194    
195      return l($link['title'], $link['href'], $link['options']);
196    }
197    
198    /**
199     * Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
200     */
201    function phptemplate_menu_local_tasks() {
202      $output = '';
203    
204      if ($primary = menu_primary_local_tasks()) {
205        $output .= "<ul class=\"tabs primary clear-block\">\n". $primary ."</ul>\n";
206      }
207      if ($secondary = menu_secondary_local_tasks()) {
208        $output .= "<ul class=\"tabs secondary clear-block\">\n". $secondary ."</ul>\n";
209      }
210    
211      return $output;
212    }
213    
214    //
215    //      Add custom classes to menu item
216    //
217    
218    function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
219      $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
220      if (!empty($extra_class)) {
221        $class .= ' '. $extra_class;
222      }
223      if ($in_active_trail) {
224        $class .= ' active-trail';
225      }
226    #New line added to get unique classes for each menu item
227      $css_class = phptemplate_id_safe(str_replace(' ', '_', strip_tags($link)));
228      return '<li class="'. $class . ' ' . $css_class . '">' . $link . $menu ."</li>\n";
229    }
230    
231    
232    //
233    //      Converts a string to a suitable html ID attribute.
234    //
235    //       http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
236    //       valid ID attribute in HTML. This function:
237    //
238    //      - Ensure an ID starts with an alpha character by optionally adding an 'n'.
239    //      - Replaces any character except A-Z, numbers, and underscores with dashes.
240    //      - Converts entire string to lowercase.
241    //
242    //      @param $string
243    //        The string
244    //      @return
245    //        The converted string
246    //
247    
248    
249    function phptemplate_id_safe($string) {
250      // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
251      $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
252      // If the first character is not a-z, add 'n' in front.
253      if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
254        $string = 'id'. $string;
255      }
256      return $string;
257    }
258    
259    //
260    // REMOVED TRUNCATE FUNCTION
261    // Instead, use : http://api.drupal.org/api/function/truncate_utf8/5
262    //
263    
264    //
265    //  Return a themed breadcrumb trail.
266    //      Alow you to customize the breadcrumb markup
267    //
268    
269    function phptemplate_breadcrumb($breadcrumb) {
270      if (!empty($breadcrumb)) {
271        return '<div class="breadcrumb">'. implode(' ยป ', $breadcrumb) .'</div>';
272      }
273    }
274    
275    /**
276    * Override of the Search Box
277    */
278    function d4rk_theme() {
279      return array(
280        // The form ID.
281        'search_theme_form' => array(
282          // Forms always take the form argument.
283          'arguments' => array('form' => NULL),
284        ),
285      );
286    }
287    
288    function d4rk_search_theme_form($form) {
289    
290        // this line deactivate the 'search this site' label - you can change/delete this
291        unset($form['search_theme_form']['#title']);
292    
293        // Change the size of the search box (you can change the value '25 to whatever you want) - you can change/delete this
294        $form['search_theme_form']['#size'] = 32;
295    
296        // Set a default value in the search box, you can change 'search' to whatever you want - you can change/delete this
297        $form['search_theme_form']['#value'] = 'Search';
298        // Additionnaly, hide the text when editing - you can change/delete this
299        // Remember to change the value 'search' here too if you change it in the previous line
300        $form['search_theme_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'Search';}", 'onfocus' => "if (this.value == 'Search') {this.value = '';}" );
301    
302        // Don't change this
303        $output .= drupal_render($form);
304        return $output;
305    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2