New module 'Custom breadcrumbs'
This commit is contained in:
parent
89b4aad0f8
commit
3813ae0e06
26 changed files with 6004 additions and 0 deletions
|
@ -0,0 +1,16 @@
|
|||
; $Id: custom_breadcrumbs_paths.info,v 1.1.2.1 2009/04/06 12:43:32 mgn Exp $
|
||||
name = Custom Breadcrumbs for Paths
|
||||
package = Custom Breadcrumbs
|
||||
dependencies[] = custom_breadcrumbs
|
||||
description = Provides Custom Breadcrumbs for specific paths.
|
||||
core = 6.x
|
||||
|
||||
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-01-08
|
||||
version = "6.x-2.0-rc1"
|
||||
core = "6.x"
|
||||
project = "custom_breadcrumbs"
|
||||
datestamp = "1294462254"
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_paths.install,v 1.1.2.7 2010/05/03 22:49:15 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install file for the custom_breadcrumbs module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_install() {
|
||||
drupal_install_schema('custom_breadcrumbs_paths');
|
||||
|
||||
// Search for Paths breadcrumbs in existing {custom_breadcrumb} and copy to new table.
|
||||
drupal_set_message(t('Looking for Specify Path breadcrumbs to copy from {custom_breadcrumb}...'));
|
||||
$result = db_query("SELECT * FROM {custom_breadcrumb} WHERE node_type = '%s'", 'Specify Path');
|
||||
$found = 0;
|
||||
while ($breadcrumb = db_fetch_object($result)) {
|
||||
$start = strpos($breadcrumb->paths, "\n");
|
||||
$specific_path = drupal_substr($breadcrumb->paths, 0, $start);
|
||||
$title = drupal_substr($breadcrumb->titles, strpos($breadcrumb->titles, "\n") + 1);
|
||||
$newpath = drupal_substr($breadcrumb->paths, strpos($breadcrumb->paths, "\n") + 1);
|
||||
db_query("INSERT INTO {custom_breadcrumbs_paths} (titles, paths, visibility_php, specific_path, set_active_menu, language) VALUES ('%s', '%s', '%s', '%s', %d, '%s' )", $title, $newpath, $breadcrumb->visibility_php, $specific_path, $breadcrumb->set_active_menu, $breadcrumb->language);
|
||||
drupal_set_message('Copied path '. $specific_path .' to {custom_breadcrumbs_paths}.' );
|
||||
++$found;
|
||||
}
|
||||
if ($found > 0) {
|
||||
drupal_set_message(format_plural($found, 'Copied 1 breadcrumb.', 'Copied @count breadcrumbs.'));
|
||||
drupal_set_message(t('You can now delete the old Specify Path breadcrumb from <a href="@link">admin/build/custom_breadcrumbs</a>. They will be listed with title Specify Path and page type node.', array('@link' => url('admin/build/custom_breadcrumbs'))));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No Specify Path breadcrumbs were found in {custom_breadcrumbs}'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_schema() {
|
||||
$schema['custom_breadcrumbs_paths'] = array(
|
||||
'description' => 'Stores custom breadcrumb trails for specific paths.',
|
||||
'fields' => array(
|
||||
'bid' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier for the {custom_breadcrumbs_views}.',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => FALSE,
|
||||
'description' => 'An optional name for the custom breadcrumb.',
|
||||
),
|
||||
'titles' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'A return-delimited list of titles for the breadcrumb links.',
|
||||
),
|
||||
'paths' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'description' => 'A return-delimited list of url paths for the breadcrumb links.',
|
||||
),
|
||||
'visibility_php' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'medium',
|
||||
'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_views} visibility.',
|
||||
),
|
||||
'specific_path' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Path to the view for this custom breadcrumb.',
|
||||
),
|
||||
'language' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'language' => array('language'),
|
||||
'path_language' => array('specific_path', 'language'),
|
||||
),
|
||||
'primary key' => array('bid'),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds indices to custom_breadcrumb table to improve performance.
|
||||
*/
|
||||
function custom_breadcrumbs_paths_update_6000() {
|
||||
$ret = array();
|
||||
db_add_index($ret, 'custom_breadcrumbs_paths', 'language', array('language'));
|
||||
db_add_index($ret, 'custom_breadcrumbs_paths', 'path_language', array('specific_path', 'language'));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds name field for improved organization of breadcrumbs
|
||||
* Remove set_active_menu field because it is no longer used.
|
||||
*/
|
||||
function custom_breadcrumbs_paths_update_6200() {
|
||||
$ret = array();
|
||||
db_add_field($ret, 'custom_breadcrumbs_paths', 'name', array('type' => 'varchar', 'length' => 128, 'NOT NULL' => FALSE, 'description' => 'An optional name for the custom breadcrumb.'));
|
||||
db_drop_field($ret, 'custom_breadcrumbs_paths', 'set_active_menu');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_uninstall() {
|
||||
drupal_uninstall_schema('custom_breadcrumbs_paths');
|
||||
|
||||
// Remove persistent variables.
|
||||
variable_del('custom_breadcrumbs_paths_allow_wildcards');
|
||||
}
|
|
@ -0,0 +1,303 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_paths.module,v 1.1.2.26 2010/12/30 18:36:25 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Assign custom breadcrumbs based on the Drupal path.
|
||||
*/
|
||||
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs.admin');
|
||||
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs_common');
|
||||
|
||||
/**
|
||||
* Implements hook_cb_breadcrumb_info().
|
||||
*
|
||||
* @return an array with elements:
|
||||
* 'table' indicating the db_table to load the breadcrumb from,
|
||||
* 'field' a unique field of the database table used to identify the breadcrumb,
|
||||
* 'type' a string used for indicating the breadcrumb type on the admin list,
|
||||
* 'name_constructor' a function which generates the breadcrumb name from the breadcrumb.
|
||||
*/
|
||||
function custom_breadcrumbs_paths_cb_breadcrumb_info() {
|
||||
$breadcrumb_type_info = array();
|
||||
$breadcrumb_type_info['paths'] = array(
|
||||
'table' => 'custom_breadcrumbs_paths',
|
||||
'field' => 'specific_path',
|
||||
'type' => 'path',
|
||||
'name_constructor' => '_custom_breadcrumbs_paths_breadcrumb_name',
|
||||
);
|
||||
return $breadcrumb_type_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a default name to display in the admin screen.
|
||||
*
|
||||
* @param $breadcrumb
|
||||
* The breadcrumb object.
|
||||
*
|
||||
* @return
|
||||
* A text string that will be used as the breadcrumb name.
|
||||
*/
|
||||
function _custom_breadcrumbs_paths_breadcrumb_name($breadcrumb) {
|
||||
if (isset($breadcrumb->specific_path)) {
|
||||
return $breadcrumb->specific_path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_menu() {
|
||||
$items = array();
|
||||
$items['admin/build/custom_breadcrumbs/path/add'] = array(
|
||||
'title' => 'Path',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_paths_form', 'path'),
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 5,
|
||||
);
|
||||
$items['admin/build/custom_breadcrumbs/path/edit'] = array(
|
||||
'title' => 'Edit custom breadcrumb for path',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_paths_form', 'path'),
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_page().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_preprocess_page(&$variables) {
|
||||
if (!custom_breadcrumbs_exclude_path()) {
|
||||
$objs = (isset($variables) && is_array($variables)) ? $variables : array();
|
||||
// Check for a match to provide custom breadcrumbs on module callback pages.
|
||||
if (_custom_breadcrumbs_paths_set_breadcrumb($objs)) {
|
||||
$variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_nodeapi().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_nodeapi($node, $op, $teaser, $page) {
|
||||
if ($op == 'alter' && empty($teaser) && !empty($page)) {
|
||||
// Check for breadcrumb at this path and set if a match is found.
|
||||
// Nodes have higher priority than views and theme templates.
|
||||
_custom_breadcrumbs_paths_set_breadcrumb(array('node' => $node), 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_render().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_views_pre_render(&$view) {
|
||||
// Don't really do anything with the view. This is just a pretense to insert a breadcrumb.
|
||||
$curpath = drupal_get_normal_path($_GET['q']);
|
||||
// Check to see if the view path matches the current path.
|
||||
$viewpage = FALSE;
|
||||
foreach ($view->display as $display) {
|
||||
// We're only interested in main page views.
|
||||
if (!_custom_breadcrumbs_allowed_display($display)) continue;
|
||||
$viewpath = _custom_breadcrumbs_construct_view_path($display);
|
||||
$viewpage = $viewpage || _custom_breadcrumbs_match_path($curpath, $viewpath);
|
||||
}
|
||||
if ($viewpage) {
|
||||
// Check for breadcrumb at this path and set if a match is found.
|
||||
// Views have a higher priority than theme templates, but lower than nodes.
|
||||
_custom_breadcrumbs_paths_set_breadcrumb(array('view' => $view), 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a custom breadcrumb at the current path and sets it if one is found.
|
||||
*
|
||||
* @param $objs
|
||||
* An array of objects to be used in token replacement. Array keys indicate type of object.
|
||||
* @param $priority
|
||||
* An integer indicating whether this attempt should override previous attempts.
|
||||
* The lowest priority is 1. Higher values are given priority over lower values.
|
||||
*/
|
||||
function _custom_breadcrumbs_paths_set_breadcrumb($objs = array(), $priority = 1) {
|
||||
static $success;
|
||||
// Allow a higher priority request to take precedence.
|
||||
if (!isset($success) || ($priority > $success)) {
|
||||
$matchpath = variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE);
|
||||
$breadcrumbs = _custom_breadcrumbs_paths_get_breadcrumbs($matchpath);
|
||||
if (!empty($breadcrumbs)) {
|
||||
foreach ($breadcrumbs as $id => $breadcrumb) {
|
||||
if ((!$matchpath) || _custom_breadcrumbs_paths_page_match($breadcrumb)) {
|
||||
if (custom_breadcrumbs_is_visible($breadcrumb, $objs)) {
|
||||
if ($matchpath) {
|
||||
// Assume a longer path match is a better fit than a prior shorter match.
|
||||
if (($pos = strrpos($breadcrumb->specific_path, '*')) !== FALSE) {
|
||||
if (!isset($max) || (isset($max) && ($pos > $max))) {
|
||||
$max = $pos;
|
||||
$max_id = $id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No wildcards in this breadcrumb, so its a direct match.
|
||||
$max_id = $id;
|
||||
// Don't check any others once a visible breadcrumb is found.
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Wildcards are not allowed, so this must be a direct match.
|
||||
$max_id = $id;
|
||||
// Don't check any others once a visible breadcrumb is found.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($max_id)) {
|
||||
custom_breadcrumbs_set_breadcrumb($breadcrumbs[$max_id], $objs);
|
||||
$success = $priority;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom_breadcrumbs_paths breadcrumbs.
|
||||
*
|
||||
* @param $matchpath
|
||||
* If TRUE, then load all paths breadcrumbs to allow wildcard matching,
|
||||
* otherwise only the current path is queried.
|
||||
* @param $path
|
||||
* The drupal path to match against.
|
||||
*
|
||||
* @return $breadcrumbs
|
||||
* An array of breadcrumb objects meeting the query criteria.
|
||||
*/
|
||||
function _custom_breadcrumbs_paths_get_breadcrumbs($matchpath = FALSE, $path = NULL) {
|
||||
// Don't bother checking if we don't have a path to match against.
|
||||
if (isset($_REQUEST['q']) || !is_null($path)) {
|
||||
global $language;
|
||||
$languages = array('language' => $language->language, 'all' => '');
|
||||
// Load all path breadcrumbs for wildcard matching.
|
||||
$param = array();
|
||||
if (!$matchpath) {
|
||||
// Check for path prefix and strip it out if its found.
|
||||
$prefix = $language->language .'/';
|
||||
$path = is_null($path) ? str_replace($prefix, '', $_REQUEST['q']) : $path;
|
||||
$param = array('specific_path' => $path);
|
||||
}
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', NULL, $param, $languages);
|
||||
return $breadcrumbs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current path matches the breadcrumb specific path.
|
||||
*
|
||||
* @param $breadcrumb
|
||||
* The breadcrumb object.
|
||||
*
|
||||
* @return $page_match
|
||||
* TRUE if the current path matches the breadcrumb specific path, FALSE otherwise.
|
||||
*/
|
||||
function _custom_breadcrumbs_paths_page_match($breadcrumb) {
|
||||
$page_match = FALSE;
|
||||
if (isset($_REQUEST['q'])) {
|
||||
if (isset($breadcrumb->language) && $breadcrumb->language != '') {
|
||||
// Check for a match on the prefixed path.
|
||||
$path = $breadcrumb->language . '/' . $breadcrumb->specific_path;
|
||||
$page_match = _custom_breadcrumbs_match_path($_REQUEST['q'], $path);
|
||||
}
|
||||
else {
|
||||
// Append the current language if the breadcrumb language is 'All'.
|
||||
global $language;
|
||||
$path = $language->language . '/' . $breadcrumb->specific_path;
|
||||
$page_match = _custom_breadcrumbs_match_path($_REQUEST['q'], $path);
|
||||
}
|
||||
if (!$page_match) {
|
||||
// Check for a direct match.
|
||||
$page_match = _custom_breadcrumbs_match_path($_REQUEST['q'], $breadcrumb->specific_path);
|
||||
}
|
||||
}
|
||||
return $page_match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_cb_node_form_table().
|
||||
*
|
||||
* @param $node
|
||||
* The node object being edited.
|
||||
*
|
||||
* @return $breadcrumbs
|
||||
* An array of breadcrumb objects with the same path as the node
|
||||
* used in the custom_breadcrumbs fieldset on the node edit page.
|
||||
*/
|
||||
function custom_breadcrumbs_paths_cb_node_form_table($node) {
|
||||
$matchpath = variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE);
|
||||
$param = ($matchpath) ? array() : array('specific_path' => $node->path);
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', NULL, $param);
|
||||
foreach ($breadcrumbs as $key => $breadcrumb) {
|
||||
if (!_custom_breadcrumbs_match_path($node->path, $breadcrumb->specific_path)) {
|
||||
unset($breadcrumbs[$key]);
|
||||
}
|
||||
}
|
||||
return $breadcrumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Provide an edit form for a custom breadcrumb paths breadcrumb.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see custom_breadcrumbs_form_validate()
|
||||
* @see custom_breadcrumbs_form_submit()
|
||||
*/
|
||||
function custom_breadcrumbs_paths_form(&$form_state, $type) {
|
||||
$form = array();
|
||||
$bid = arg(5);
|
||||
$breadcrumb = NULL;
|
||||
if (isset($bid)) {
|
||||
drupal_set_title(t('Edit Custom Breadcrumb for Path'));
|
||||
$breadcrumb = array_pop(custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_paths', NULL, array('bid' => $bid)));
|
||||
}
|
||||
else {
|
||||
drupal_set_title(t('Add Custom Breadcrumb for Path'));
|
||||
}
|
||||
$description = t('The Drupal path that this custom breadcrumb trail will apply to.');
|
||||
if (variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE)) {
|
||||
$description .= ' ' . t("The '*' character can be used as a wildcard to set a custom breadcrumb for all matching paths. For example, foo/bar* could be used to match every page with a path beginning with foo/bar. Do not include language prefixes in the path. This will be handled automatically according to the selected language.");
|
||||
}
|
||||
$form['specific_path'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Specific Path'),
|
||||
'#required' => TRUE,
|
||||
'#description' => $description,
|
||||
'#default_value' => isset($breadcrumb->specific_path) ? $breadcrumb->specific_path : NULL,
|
||||
'#weight' => -10,
|
||||
);
|
||||
|
||||
$form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
|
||||
// Store the function to call to save this breadcrumb.
|
||||
$form['#module'] = 'custom_breadcrumbs_paths';
|
||||
$form['#infokey'] = 'paths';
|
||||
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
|
||||
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function custom_breadcrumbs_paths_form_alter(&$form, $form_state, $form_id) {
|
||||
if ($form_id == 'custom_breadcrumbs_admin_settings') {
|
||||
$form['adv_settings']['custom_breadcrumbs_paths_allow_wildcards'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use wildcard pattern matching in paths'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_paths_allow_wildcards', FALSE),
|
||||
'#description' => t("If checked, the '*' character can be used as a wildcard to set a custom breadcrumb for all matching paths. For example, foo/bar/* could be used to match every page with a path beginning with foo/bar."),
|
||||
'#weight' => -20,
|
||||
);
|
||||
}
|
||||
}
|
Reference in a new issue