[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/themes/rootcandy/ -> template.php (source)

   1  <?php
   2  // $Id: template.php,v 1.36.2.41 2010/01/01 14:18:22 sign Exp $
   3  
   4  /**
   5   * @file
   6   * The theme template.php file
   7   */
   8  
   9  function _rootcandy_admin_links() {
  10    global $user;
  11    if ($user->uid) {
  12      $links[] = '<a href="'. url('user') .'" class="user-name">'. $user->name .'</a>';
  13      $links[] = '<a href="'. url('logout') .'">'. t('Logout') .'</a>';
  14      $links = implode(' | ', $links);
  15  
  16      return $links;
  17    }
  18  }
  19  
  20  function rootcandy_body_class($left = NULL, $right = NULL) {
  21    $class = '';
  22    if ($left != '' AND $right) {
  23      $class = 'sidebars';
  24    }
  25    else if ($left != '' AND $right == '') {
  26      $class = 'sidebar-left';
  27    }
  28    else if ($left == '' AND $right != '') {
  29      $class = 'sidebar-right';
  30    }
  31  
  32    // Add classes describing the menu trail of the page.
  33    $class .= rootcandy_get_page_classes();
  34  
  35    if (isset($class)) {
  36      print ' class="'. $class .'"';
  37    }
  38  }
  39  
  40  function _rootcandy_admin_navigation() {
  41    $path = base_path() . path_to_theme();
  42    $base = path_to_theme();
  43  
  44    // get users role
  45    global $user;
  46  
  47    if ($user->uid != 1) {
  48      // get sorted roles
  49      $role_menu = _rootcandy_init_role_menu();
  50      if ($role_menu) {
  51        $rootcandy_navigation = theme_get_setting('rootcandy_navigation_source_'. $role_menu);
  52      }
  53    }
  54    else {
  55      $rootcandy_navigation = theme_get_setting('rootcandy_navigation_source_admin');
  56      if (!isset($rootcandy_navigation)) {
  57        $rootcandy_navigation = '_rootcandy_default_navigation';
  58      }
  59    }
  60  
  61    $menu_tree = array();
  62    if (!$rootcandy_navigation) {
  63      if (!$user->uid) {
  64        $menu_tree[] = array('href' => 'user/login', 'title' => t('User login'));
  65      }
  66    }
  67    elseif ($rootcandy_navigation == '_rootcandy_default_navigation') {
  68      // build default menu
  69      $menu_tree[] = array('href' => 'admin', 'title' => t('Dashboard'));
  70      $menu_tree[] = array('href' => 'admin/content', 'title' => t('Content'));
  71      if (variable_get('node_admin_theme', '0')) {
  72        $menu_tree[] = array('href' => 'node/add', 'title' => t('Create content'));
  73      }
  74      $menu_tree[] = array('href' => 'admin/build', 'title' => t('Building'));
  75      $menu_tree[] = array('href' => 'admin/settings', 'title' => t('Configuration'));
  76      $menu_tree[] = array('href' => 'admin/user', 'title' => t('Users'));
  77      $menu_tree[] = array('href' => 'admin/reports', 'title' => t('Reports'));
  78      if (module_exists('help')) {
  79        $menu_tree[] = array('href' => 'admin/help', 'title' => t('Help'));
  80      }
  81    }
  82    else {
  83      $menu_tree = menu_navigation_links($rootcandy_navigation);
  84    }
  85  
  86    if ($menu_tree) {
  87      $size = theme_get_setting('rootcandy_navigation_icons_size');
  88      $icons_disabled = theme_get_setting('rootcandy_navigation_icons');
  89      $list_class = 'i'. $size;
  90  
  91      $custom_icons = rootcandy_custom_icons();
  92      if (!isset($custom_icons)) {
  93        $custom_icons = '';
  94      }
  95  
  96      $match = _rootcandy_besturlmatch($_GET['q'], $menu_tree);
  97      $items = array();
  98      foreach ($menu_tree as $key => $item) {
  99        $id = '';
 100        $icon = '';
 101        $class= '';
 102        // icons
 103        if (!$icons_disabled) {
 104          $size = theme_get_setting('rootcandy_navigation_icons_size');
 105          if (!isset($size)) $size = 24;
 106          $arg = explode("/", $item['href']);
 107          $icon = _rootcandy_icon($arg, $size, 'admin', $custom_icons);
 108          if ($icon) $icon = $icon .'<br />';
 109        }
 110        if ($key == $match) {
 111          $id = 'current';
 112          if (!$icons_disabled && $size) {
 113            $id = 'current-'. $size;
 114          }
 115        }
 116  
 117        // add a class to li
 118        $class = "";
 119        if (is_array($arg)) {
 120          $class = implode($arg, '-');
 121        }
 122  
 123        $item['data'] = l($icon . $item['title'], $item['href'], array('html' => TRUE));
 124        if (!empty($id)) $item['id'] = $id;
 125        if (!empty($class)) $item['class'] = $class;
 126        if (!empty($item['attributes'])) {
 127          unset($item['attributes']);
 128        }
 129        $items[] = $item;
 130  
 131      }
 132      return theme('admin_navigation', $items, $list_class);
 133    }
 134  }
 135  
 136  function rootcandy_admin_navigation($items, $class) {
 137    return theme('item_list', $items, NULL, 'ul', array('class' => $class));
 138  }
 139  
 140  function _rootcandy_besturlmatch($needle, $menuitems) {
 141    $needle = drupal_get_path_alias($needle);
 142    $lastmatch = NULL;
 143    $lastmatchlen = 0;
 144    $urlparts = explode('/', $needle);
 145    $partcount = count($urlparts);
 146  
 147    foreach ($menuitems as $key => $menuitem) {
 148      $href = $menuitem['href'];
 149      $menuurlparts = explode('/', $href);
 150      $matches = _rootcandy_countmatches($urlparts, $menuurlparts);
 151      if (($matches > $lastmatchlen) || (($matches == $lastmatchlen) && (($lastmatch && drupal_strlen($menuitems[$lastmatch]['href'])) > drupal_strlen($href)) )) {
 152        $lastmatchlen = $matches;
 153        $lastmatch = $key;
 154      }
 155    }
 156    return $lastmatch;
 157  }
 158  
 159  /**
 160   * Override or insert PHPTemplate variables into the templates.
 161   */
 162  function rootcandy_preprocess_page(&$vars) {
 163    // get secondary links
 164    $vars['tabs2'] = menu_secondary_local_tasks();
 165  
 166    // color.module integration
 167    if (module_exists('color')) {
 168      _color_page_alter($vars);
 169    }
 170  
 171    // notify users that they can change settings in theme settings
 172    $admin_theme = variable_get('admin_theme', 'garland');
 173    if (arg(0) == 'admin' AND arg(1) == 'settings' AND arg(2) == 'admin' AND ($admin_theme == 'rootcandy' OR $admin_theme == 'rootcandy_fixed' OR $admin_theme == 'rootcandy_dark')) {
 174      $message = t('Thank you for using RootCandy.<br />Did you know, that Root Candy has advanced settings (Theme-specific settings fieldset)? You can change these settings at <a href="@configure-page">theme configuration page</a>.', array('@configure-page' => url('admin/build/themes/settings/'. $admin_theme)));
 175      $vars['messages'] .= '<div class="messages rootcandy">'. $message .'</div>';
 176    }
 177  
 178    if (arg(0) == 'admin' || ((arg(0) == 'node' AND is_numeric(arg(1)) AND arg(2) == 'edit') || (arg(0) == 'node' AND arg(1) == 'add'))) {
 179      $vars['go_home'] = '<a href="'. url() .'">'. t('Go Back to Homepage') .'</a>';
 180    }
 181  
 182    // get theme settings
 183    $vars['hide_header'] = theme_get_setting('rootcandy_header_display');
 184    $vars['hide_panel'] = theme_get_setting('rootcandy_hide_panel');
 185  
 186    // append legal notice
 187    $vars['closure'] .= '<div id="legal-notice">Theme created by <a href="http://sotak.co.uk" rel="external">Marek Sotak</a></div>';
 188  
 189    $vars['hide_content'] = '';
 190  
 191  
 192    // check whether help is disabled
 193    if (theme_get_setting('rootcandy_help_display')) {
 194      unset($vars['help']);
 195    }
 196  
 197    // dashboard
 198    if (arg(0) == 'admin' AND !arg(1)) {
 199      if (!theme_get_setting('rootcandy_dashboard_display')) {
 200        $vars['dashboard'] = 1;
 201  
 202        // display help and messages in regions
 203        switch (theme_get_setting('rootcandy_dashboard_help')) {
 204          case 'left':
 205            $vars['dashboard_left'] = $vars['help'] . $vars['dashboard_left'];
 206            unset($vars['help']);
 207            break;
 208          case 'right':
 209            $vars['dashboard_right'] = $vars['help'] . $vars['dashboard_right'];
 210            unset($vars['help']);
 211            break;
 212        }
 213  
 214        switch (theme_get_setting('rootcandy_dashboard_messages')) {
 215          case 'left':
 216            $vars['dashboard_left'] = $vars['messages'] . $vars['dashboard_left'];
 217            unset($vars['messages']);
 218            break;
 219          case 'right':
 220            $vars['dashboard_right'] = $vars['messages'] . $vars['dashboard_right'];
 221            unset($vars['messages']);
 222            break;
 223        }
 224      }
 225      if (theme_get_setting('rootcandy_dashboard_content_display')) {
 226        $vars['hide_content'] = theme_get_setting('rootcandy_dashboard_content_display');
 227      }
 228    }
 229  
 230    $vars['panel_navigation'] = '<a id="open" class="open" href="#"><span class="panel-open">'. t('Open Panel') .'</span></a>';
 231    $vars['panel_navigation'] .= '<a id="close" style="display: none;" class="close" href="#"><span class="panel-close">'. t('Close Panel') .'</span></a>';
 232  }
 233  
 234  function rootcandy_admin_block_content($content) {
 235    if (!$content) {
 236      return '';
 237    }
 238  
 239    if (system_admin_compact_mode()) {
 240      drupal_add_js(drupal_get_path('theme', 'rootcandy') .'/compact-icon.js');
 241      drupal_add_css(drupal_get_path('theme', 'rootcandy') .'/compact-icon.css');
 242      $counter = 1;
 243      $output = '<ul class="admin-menu-compact">';
 244      foreach ($content as $item) {
 245        $additional_class = $counter % 4 == 0 ? ' last' : ''; //Append class last to every 4th item signifying a new row
 246        $item['localized_options']['html'] = TRUE;
 247  
 248        if ($image = _rootcandy_menu_icon($item['href'])) {
 249          $link = l($image .'<br />'. $item['title'], $item['href'], $item['localized_options']);
 250        }
 251        else {
 252          $link = l(theme('image', drupal_get_path('theme', 'rootcandy') .'/icons/i32/misc/unknown.png') .'<br />'. $item['title'], $item['href'], $item['localized_options']);
 253        }
 254  
 255        $output .= '<li class="leaf'. $additional_class .'">'. $link .'</li>';
 256        $counter++;
 257      }
 258      $output .= '</ul>';
 259    }
 260    else {
 261      $output = '<dl class="admin-list">';
 262      foreach ($content as $item) {
 263        $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
 264        $output .= '<dd>'. $item['description'] .'</dd>';
 265      }
 266      $output .= '</dl>';
 267    }
 268  
 269    return $output;
 270  }
 271  
 272  function _rootcandy_menu_icon($href) {
 273    $filename = drupal_get_path('theme', 'rootcandy') .'/icons/i32/admin/'. str_replace('/', '-', drupal_strtolower($href)) .'.png';
 274    return theme('image', $filename);
 275  }
 276  
 277  /**
 278   * Returns the rendered local tasks. The default implementation renders
 279   * them as tabs. Overridden to split the secondary tasks.
 280   *
 281   * @ingroup themeable
 282   */
 283  function rootcandy_menu_local_tasks() {
 284    return menu_primary_local_tasks();
 285  }
 286  
 287  function _rootcandy_icon($name, $size = '16', $subdir = '', $icons = '') {
 288    $url = implode("/", $name);
 289    $name = implode("-", $name);
 290    $path = path_to_theme();
 291    if ($subdir) {
 292      $subdir = $subdir .'/';
 293    }
 294  
 295    if (isset($icons[$url])) {
 296      $icon = $icons[$url];
 297    }
 298    else {
 299      $icon = $path .'/icons/i'. $size .'/'. $subdir . $name .'.png';
 300    }
 301  
 302    $output = theme('image', $icon);
 303  
 304    if (!$output) {
 305      $icon = $path .'/icons/i'. $size .'/misc/unknown.png';
 306      $output = theme('image', $icon);
 307    }
 308  
 309    return $output;
 310  }
 311  
 312  function rootcandy_custom_icons() {
 313    $custom_icons = theme_get_setting('rootcandy_navigation_custom_icons');
 314    if (isset($custom_icons)) {
 315      $list = explode("\n", $custom_icons);
 316      $list = array_map('trim', $list);
 317      $list = array_filter($list, 'strlen');
 318      foreach ($list as $opt) {
 319        // Sanitize the user input with a permissive filter.
 320        $opt = rootcandy_filter_xss($opt);
 321        if (strpos($opt, '|') !== FALSE) {
 322          list($key, $value) = explode('|', $opt);
 323          $icons[$key] = $value ? $value : $key;
 324        }
 325        else {
 326          $icons[$opt] = $opt;
 327        }
 328      }
 329    }
 330    if (isset($icons)) {
 331      return $icons;
 332    }
 333  }
 334  
 335  function rootcandy_filter_xss($string) {
 336    return filter_xss($string);
 337  }
 338  
 339  /**
 340   * Read the theme settings' default values from the .info and save them into the database.
 341   *
 342   * @param $theme
 343   *   The actual name of theme that is being checked.
 344   */
 345  function rootcandy_settings_init($theme) {
 346    $themes = list_themes();
 347  
 348    // Get the default values from the .info file.
 349    $defaults = (is_array($themes[$theme]->info['settings'])) ? $themes[$theme]->info['settings'] : array();
 350  
 351    // Get the theme settings saved in the database.
 352    $settings = theme_get_settings($theme);
 353    // Don't save the toggle_node_info_ variables.
 354    if (module_exists('node')) {
 355      foreach (node_get_types() as $type => $name) {
 356        unset($settings['toggle_node_info_'. $type]);
 357      }
 358    }
 359  
 360    // Save default theme settings.
 361    variable_set(
 362      str_replace('/', '_', 'theme_'. $theme .'_settings'),
 363      array_merge($defaults, $settings)
 364    );
 365    // Force refresh of Drupal internals.
 366    theme_get_setting('', TRUE);
 367  }
 368  
 369  /*
 370   * In addition to initializing the theme settings during HOOK_theme(), init them
 371   * when viewing/resetting the admin/build/themes/settings/THEME forms.
 372   */
 373  if (arg(0) == 'admin' && arg(2) == 'themes' && arg(4)) {
 374    global $theme_key;
 375    rootcandy_settings_init($theme_key);
 376  }
 377  
 378  function rootcandy_get_page_classes($path = NULL) {
 379    if (!isset($path)) $path = $_GET['q'];
 380    if ($path) {
 381      $path = ' '. rootcandy_id_safe($path);
 382    }
 383    return $path;
 384  }
 385  
 386  /**
 387   * Converts a string to a suitable html ID attribute. Borrowed from Zen theme
 388   *
 389   * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
 390   * valid ID attribute in HTML. This function:
 391   *
 392   * - Ensure an ID starts with an alpha character by optionally adding an 'id'.
 393   * - Replaces any character except alphanumeric characters with dashes.
 394   * - Converts entire string to lowercase.
 395   *
 396   * @param $string
 397   *   The string
 398   * @return
 399   *   The converted string
 400   */
 401  function rootcandy_id_safe($string) {
 402    // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
 403    return check_plain(strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string)));
 404  }
 405  
 406  function rootcandy_breadcrumb($breadcrumb) {
 407    if (!empty($breadcrumb)) {
 408      /*
 409       * Modern browsers (Firefox 1.5 and above, Internet Explorer 5.0 and above,
 410       * Safari not checked) would automatically change the double-arrows (») to
 411       * the other direction once it detects a right-to-left page. So no need to
 412       * reverse the array, and no need to use reversed-direction arrows.
 413       */
 414      return '<div class="breadcrumb">'. str_replace(t('Administer'), t('Dashboard'), implode(' » ', $breadcrumb)) .'</div>';
 415    }
 416  }
 417  
 418  function _rootcandy_links($links, $attributes = array('class' => 'links')) {
 419    $output = '';
 420  
 421    if (count($links) > 0) {
 422      $output = '<ul'. drupal_attributes($attributes) .'>';
 423  
 424      $num_links = count($links);
 425      $i = 1;
 426  
 427      foreach ($links as $key => $link) {
 428        $class = $key;
 429  
 430        // Add first, last and active classes to the list of links to help out themers.
 431        if ($i == 1) {
 432          $class .= ' first';
 433        }
 434        if ($i == $num_links) {
 435          $class .= ' last';
 436        }
 437  
 438        $check_path = $_GET['q'];
 439        $check_path = explode("/", $check_path);
 440        $q_path = $check_path[0] .'/'. $check_path[1] .'/'. $check_path[2];
 441        if (isset($link['href']) && ($link['href'] == $q_path || ($link['href'] == '<front>' && drupal_is_front_page()))) {
 442          $class .= ' active';
 443        }
 444        $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
 445  
 446        if (isset($link['href'])) {
 447          // Pass in $link as $options, they share the same keys.
 448          $output .= l($link['title'], $link['href'], $link);
 449        }
 450        else if (!empty($link['title'])) {
 451          // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
 452          if (empty($link['html'])) {
 453            $link['title'] = check_plain($link['title']);
 454          }
 455          $span_attributes = '';
 456          if (isset($link['attributes'])) {
 457            $span_attributes = drupal_attributes($link['attributes']);
 458          }
 459          $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
 460        }
 461  
 462        $i++;
 463        $output .= "</li>\n";
 464      }
 465  
 466      $output .= '</ul>';
 467    }
 468  
 469    return $output;
 470  }
 471  
 472  function rootcandy_menu_item_link($link) {
 473    if ($link['href'] == 'admin') {
 474      $link['title'] = t('Dashboard');
 475    }
 476  
 477    return theme_menu_item_link($link);
 478  }
 479  
 480  function _rootcandy_countmatches($arrayone, $arraytwo) {
 481    $matches = 0;
 482    foreach ($arraytwo as $i => $part) {
 483      if (!isset($arrayone[$i])) break;
 484      if ($arrayone[$i] == $part) $matches = $i+1;
 485    }
 486    return $matches;
 487  }
 488  
 489  function rootcandy_system_settings_form($form) {
 490    $themes = list_themes();
 491    $enabled_theme = arg(4);
 492    if ($form['#id'] == 'system-theme-settings' AND ($enabled_theme == 'rootcandy' || $themes[$enabled_theme]->base_theme == 'rootcandy')) {
 493  
 494      foreach ($form['theme_specific']['rows'] as $rid => $row) {
 495        //we are only interested in numeric keys
 496        if (intval($rid)) {
 497          $this_row = $row['data']['#value'];
 498          //Add the weight field to the row
 499          $weight = $form['theme_specific']['rows'][$rid]['role-weight-'. $rid]['#value'];
 500          $this_row[] = drupal_render($form['theme_specific']['navigation']['nav-by-role']['rootcandy_navigation_source_'. $rid]);
 501          $this_row[] = drupal_render($form['theme_specific']['rows'][$rid]['role-weight-'. $rid]);
 502          //Add the row to the array of rows
 503          $table_rows[$weight] = array('data' => $this_row, 'class' => 'draggable');
 504        }
 505      }
 506      ksort($table_rows);
 507  
 508      $header = array(
 509        "Role", "Navigation menu", "Order"
 510      );
 511  
 512      $form['theme_specific']['navigation']['role-weights']['content']['#value'] = theme('table', $header, $table_rows, array('id' => 'rootcandy-settings-table'));
 513      $output = drupal_render($form);
 514  
 515      drupal_add_tabledrag('rootcandy-settings-table', 'order', 'sibling', 'weight');
 516    }
 517    else {
 518      $output = drupal_render($form);
 519    }
 520    return $output;
 521  }
 522  
 523  function rootcandy_theme() {
 524    return array(
 525      'system_settings_form' => array(
 526        'arguments' => array('form' => NULL),
 527      ),
 528      'admin_navigation' => array(
 529        'arguments' => array('items' => NULL, 'class' => NULL),
 530      ),
 531    );
 532  }
 533  
 534  function _rootcandy_init_role_menu() {
 535    global $theme_key;
 536    global $user;
 537    $i = 100;
 538    $settings = theme_get_settings($theme_key);
 539    $menu = array();
 540  
 541    $roles = user_roles(FALSE);
 542  
 543    foreach ($user->roles as $rid => $role) {
 544      if (!$weight = $settings['role-weight-'. $rid]) {
 545        $settings['role-weight-'. $rid] = $i++;
 546      }
 547      $menu[$settings['role-weight-'. $rid]] = $rid;
 548    }
 549    ksort($menu);
 550    return $menu[key($menu)];
 551  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7