-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbaker.module
156 lines (136 loc) · 3.75 KB
/
baker.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
// $Id: baker.module,v 0.9 Fri Nov 13 10:53:29 CET 2009, fran Exp $
/**
* hook_menu.
* Define adminstration pages
*
* @return $items: array with pages
**/
function baker_menu()
{
$items = array();
$items['admin/build/baker'] = array(
'title' => 'Baker administration',
'type' => MENU_CALLBACK,
'page callback' => 'baker_administration_page',
'access callback' => 'user_access',
'access arguments' => array('administer baker'),
'file' => 'baker.admin.inc');
$items['admin/build/baker/add'] = array(
'title' => 'Baker add new title',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('baker_admin_form'),
'access callback' => 'user_access',
'access arguments' => array('administer baker'),
'file' => 'baker.admin.inc');
$items['admin/build/baker/edit/%'] = array(
'title' => 'Baker adit title',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('baker_admin_form'),
'access callback' => 'user_access',
'access arguments' => array('administer baker'),
'file' => 'baker.admin.inc');
$items['admin/build/baker/delete/%'] = array(
'title' => 'Baker adit title',
'type' => MENU_CALLBACK,
'page callback' => '_baker_delete_item',
'access callback' => 'user_access',
'access arguments' => array('administer baker'),
'file' => 'baker.admin.inc');
return $items;
}
/**
* Define access permisions
*
* @return void
**/
function baker_perm(){
return array('administer baker', 'administer baker parameters for breadcrumbs');
}
/**
* hook_nodeapi.
* this function set the drupal breadcrumbs. Its call other functions
* to generate the crumbs that will be displayed.
*
* @return void
* @var $variables: all page's variables
**/
function baker_preprocess_page(&$variables){
$breadcrumb = _baker_create_breadcrumb($variables);
if($breadcrumb){
$variables['breadcrumb'] = $breadcrumb;
}
}
/**
* Gets URL and explode the path to generate the breadcrumb
*
* @return $breadcrumb
**/
function _baker_create_breadcrumb($variables)
{
$url = _baker_get_url();
$crumbs = _baker_generate_crumbs($url);
$breadcrumb = '<div class="breadcrumb">'. implode(' » ', $crumbs) .'</div>';
return $breadcrumb;
}
/**
* Gets the actual url
*
* @return $url : string with the actual url
**/
function _baker_get_url()
{
global $base_path;
if(isset($_GET['q'])){
$url =url($_GET['q']);
//remove base_path;
if($base_path != '/'){
$url = str_replace($base_path, '', $url);
}
return $url;
}
}
/**
* Generate the links with its titles.
*
* @return $crumbs : array with the links thats will generate the finally breadcrumbs
**/
function _baker_generate_crumbs($url)
{
// Load actual base url
global $base_url;
$crumbs[] = l(t('Home'), "<front>");
$url_items = explode('/',$url);
$last_item = count($url_items) -1;
$last_url='';
$path_length = count($key);
foreach($url_items as $key => $item ){
if($item != ''){
// The first item don't the slash because $base_url got it. Its avoid this cases www.pepito.com//blog
if($key != 0){
$last_url .= '/';
}
// check the last item. It must not be a link.
if($key == $last_item){
$crumb = urldecode($item);
}else{
$crumb = l(urldecode($item), $base_url . $last_url . $item);
}
$crumbs[] = $crumb;
$last_url .= $item;
}
}
return $crumbs;
}
/**
* This function generate the title of the crumb for the url.
* The title could be customized througth the baker administration by the user.
*
* @return $title
**/
function _baker_generate_title($last_url, $item)
{
//TODO:
}