/[drupal]/contributions/modules/trailscout/trailscout.module
ViewVC logotype

Contents of /contributions/modules/trailscout/trailscout.module

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


Revision 1.6 - (show annotations) (download) (as text)
Wed Jan 7 19:00:14 2009 UTC (10 months, 2 weeks ago) by tjfulopp
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +13 -13 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /* $Id: trailscout.module,v 1.5 2008/06/18 17:52:46 killes Exp $ */
3
4 /**
5 * Implementation of hook_perm()
6 *
7 * Valid permissions for this module
8 *
9 * @return array An array of valid permissions for this module
10 */
11 function trailscout_perm() {
12 return array('administer trailscout');
13 }
14
15 /**
16 * Implementation of hook_exit()
17 *
18 */
19 function trailscout_exit() {
20 trailscout_set_trail();
21 }
22
23 function trailscout_admin() {
24 $form['trailscout_maxcrumbs'] = array(
25 '#type' => 'textfield',
26 '#title' => t('Max breadcrumbs'),
27 '#default_value' => variable_get('trailscout_maxcrumbs', '5'),
28 '#required' => TRUE,
29 '#size' => 2,
30 '#maxlength' => 2,
31 '#description' => t("Max number of bread crumbs to show."),
32 );
33 $form['trailscout_maxcrumblength'] = array(
34 '#type' => 'textfield',
35 '#title' => t('Max crumb length'),
36 '#default_value' => variable_get('trailscout_maxcrumblength', '21'),
37 '#required' => TRUE,
38 '#size' => 2,
39 '#maxlength' => 2,
40 '#description' => t("Max length of each link description (closest word ending respected). Does not apply to the last (current) item."),
41 );
42 $form['trailscout_exclude'] = array(
43 '#type' => 'textarea',
44 '#title' => t('Excluded page titles'),
45 '#default_value' => variable_get('trailscout_exclude', "Page not found\nEmpty cache\nAccess Denied / User Login"),
46 '#required' => FALSE,
47 '#rows' => 10,
48 '#description' => t("List of page titles (one per line) that should not appear in the bread crumb trail. E.g. 'Page not found', 'Empty cache', etc."),
49 );
50 return system_settings_form($form);
51 }
52
53 function trailscout_menu($may_cache) {
54 $items = array();
55 if ($may_cache) {
56 $items[] = array(
57 'path' => 'admin/settings/trailscout',
58 'title' => t('TrailScout'),
59 'description' => t('TrailScout module settings'),
60 'callback' => 'drupal_get_form',
61 'callback arguments' => 'trailscout_admin',
62 'access' => user_access('administer trailscout'),
63 'type' => MENU_NORMAL_ITEM,
64 );
65 }
66 else {
67 trailscout_set_breadcrumb();
68 }
69 return $items;
70 }
71
72 /**
73 * Adds current page to the trail, if it is not excluded by title.
74 */
75 function trailscout_set_trail() {
76 $title = drupal_get_title();
77
78 if ($title && !trailscout_excluded($title)) {
79 $len = variable_get('trailscout_maxcrumblength', '21');
80 if (isset($_SESSION['trail'])) {
81 if (count($_SESSION['trail']) > variable_get('trailscout_maxcrumbs', 5)) {
82 array_shift($_SESSION['trail']);
83 }
84 $last_crumb = array_pop($_SESSION['trail']);
85 }
86 $link = truncate_utf8($title, $len, TRUE, TRUE);
87 $url = l($link, $_GET['q'], array('title' => $title));
88 if (isset($last_crumb) && $last_crumb != $url) {
89 // add last_crumb back
90 $_SESSION['trail'][] = $last_crumb;
91 }
92 // add new crumb
93 $_SESSION['trail'][] = $url;
94 }
95 }
96
97 /**
98 * Checks if the passed title is on the list of excluded page titles.
99 */
100 function trailscout_excluded($title) {
101 $excluded = variable_get('trailscout_exclude', "Page not found\nEmpty cache\nAccess Denied / User Login");
102 $excluded = explode("\n", str_replace("\r", '', $excluded));
103 foreach ($excluded as $ex) {
104 if ($title == $ex) {
105 return TRUE;
106 }
107 }
108 return FALSE;
109 }
110
111 /**
112 * Set the breadcrumb to the current trail if set.
113 */
114 function trailscout_set_breadcrumb() {
115 if (!isset($_SESSION['trail'])) {
116 return;
117 }
118 drupal_set_breadcrumb($_SESSION['trail']);
119 }
120

  ViewVC Help
Powered by ViewVC 1.1.2