You are here

crumbs.module in Crumbs, the Breadcrumbs suite 6

Same filename and directory in other branches
  1. 6.2 crumbs.module
  2. 7.2 crumbs.module
  3. 7 crumbs.module

File

crumbs.module
View source
<?php

module_load_include('inc', 'crumbs', 'crumbs.TrailFinder');
module_load_include('inc', 'crumbs', 'crumbs.ItemWrapper');
module_load_include('inc', 'crumbs', 'crumbs.PluginEngine');
module_load_include('inc', 'crumbs', 'crumbs.decorateItem');
module_load_include('inc', 'crumbs', 'crumbs.findParent');
module_load_include('inc', 'crumbs', 'crumbs.decorateTrail');
module_load_include('inc', 'crumbs', 'plugins/crumbs.menu');
module_load_include('inc', 'crumbs', 'plugins/crumbs.forum');
module_load_include('inc', 'crumbs', 'plugins/crumbs.views_ui');
module_load_include('inc', 'crumbs', 'plugins/crumbs.taxonomy');
module_load_include('inc', 'crumbs', 'plugins/crumbs.path');
module_load_include('inc', 'crumbs', 'plugins/crumbs.pathauto');
module_load_include('inc', 'crumbs', 'plugins/crumbs.nodereference');
module_load_include('inc', 'crumbs', 'plugins/crumbs.crumbs');
function crumbs_perm() {
  return array(
    'administer crumbs',
  );
}
function crumbs_menu() {
  $items = array();
  $items['crumbs/node-type-dummy-path/%'] = array(
    'title' => 'Crumbs dummy path',
    'title callback' => 'check_plain',
    'page callback' => '_crumbs_donothing',
    'access callback' => '_crumbs_noaccess',
  );
  $items['admin/build/crumbs'] = array(
    'title' => 'Crumbs',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'crumbs_admin_form',
    ),
    'access arguments' => array(
      'administer crumbs',
    ),
    'file' => 'crumbs.admin.inc',
  );
  return $items;
}
function _crumbs_donothing() {
  return '';
}
function _crumbs_noaccess() {
  return TRUE;
}
function crumbs_preprocess_page(&$vars) {
  $trail = crumbs_get_trail();
  $vars['crumbs_trail'] = $trail;

  // Some modules call drupal_set_breadcrumb() with their own ideas of a
  // breadcrumb, and thus overwrite the breadcrumb set in crumbs_init(),
  // Thus, we need template_preprocess_page() to restore the crumbs crumb
  // for page rendering.
  $breadcrumb = crumbs_get_breadcrumb();
  $vars['breadcrumb'] = theme('breadcrumb', $breadcrumb);
  $finder = _crumbs_get_finder();
  $finder
    ->invokePreprocessPage($vars, $trail);
}
function crumbs_get_trail() {
  static $_trail;
  if (!isset($_trail)) {
    $_trail = crumbs_build_trail($_GET['q']);
  }
  return $_trail;
}
function crumbs_build_trail($path) {
  $finder = _crumbs_get_finder();
  $trail = $finder
    ->buildTrail($path);
  $trail_wrapped = array();
  foreach ($trail as $path => $extra) {
    $trail_wrapped[$path] = new crumbs_ItemWrapper_theme($extra);
  }
  return $trail_wrapped;
}
function crumbs_get_breadcrumb() {
  static $_breadcrumb;
  if (!isset($_breadcrumb)) {
    $trail = crumbs_get_trail();
    $_breadcrumb = crumbs_build_breadcrumb($trail);
  }
  return $_breadcrumb;
}
function crumbs_build_breadcrumb($trail) {
  $breadcrumb = array();
  foreach ($trail as $path => $item) {
    $breadcrumb[] = $item
      ->link();
  }
  return $breadcrumb;
}
function _crumbs_get_settings() {
  $settings = variable_get('crumbs', array());
  return is_array($settings) ? $settings : array();
}

/**
 * Collect plugin objects
 */
function _crumbs_get_objects() {
  $sort_order = _crumbs_get_settings();
  $objects = array();
  $objects_enabled = array();
  $modules_enabled = array();
  foreach ($sort_order as $order_key => $enabled) {
    if ($enabled) {
      list($object_key, $sub_key) = explode(':', $order_key, 2);
      list($module, $instance_key) = explode('.', $object_key, 2);
      $objects_enabled[$object_key] = TRUE;
      $modules_enabled[$module] = TRUE;
    }
  }
  foreach (module_list(FALSE, TRUE) as $module) {
    $class = $module . '_class_CrumbsParentFinder';
    if (class_exists($class)) {
      if (method_exists($class, 'construct')) {

        // use the factory method.
        $result = call_user_func(array(
          $class,
          'construct',
        ));
        if (is_object($result)) {
          $objects[$module] = $result;
        }
        else {
          if (is_array($result)) {
            foreach ($result as $key => $object) {
              $objects["{$module}.{$key}"] = $object;
            }
          }
        }
      }
      else {
        $objects[$module] = new $class();
      }
    }
  }
  foreach ($objects as $key => $object) {
    if (!is_object($object)) {
      unset($objects[$key]);
    }
  }
  return $objects;
}

/**
 * Collect plugin objects, but sorted/keyed in a special way
 */
function _crumbs_get_objects_by_method() {
  $sort_order = _crumbs_get_settings();
  $objects = _crumbs_get_objects();
  foreach ($sort_order as $key => $enabled) {
    if (!$enabled) {
      unset($objects[$key]);
    }
  }
  $objects_by_method = array(
    '.' => array(),
    'find' => array(),
  );
  foreach ($objects as $k => $object) {
    if (!is_object($object)) {
      continue;
    }
    $objects_by_method['.'][$k] = $object;
    foreach (get_class_methods($object) as $method) {
      $objects_by_method[$method][$k] = $object;
    }
  }
  return $objects_by_method;
}