1
|
<?php
|
2
|
// $Id: taxon_experts.module 2466 2008-05-27 15:51:07Z a.kohlbecker $
|
3
|
|
4
|
// include the module specific template extention for this module
|
5
|
require_once('template.taxon_experts.php');
|
6
|
|
7
|
/**
|
8
|
* @file
|
9
|
* A online information service on taxonomic experts, their expertise
|
10
|
* and ongoing and planned taxonomic research projects.
|
11
|
* This module is brought to you by the European Distributed Institute of Taxonomy - EDIT
|
12
|
*
|
13
|
* @author Berlin, BGBM, Andreas Kohlbecker 2007 - http://www.bgbm.org/BioDivInf/default.htm
|
14
|
*
|
15
|
* Copyright (C) 2007 EDIT
|
16
|
* European Distributed Institute of Taxonomy
|
17
|
* http://www.e-taxonomy.eu
|
18
|
*
|
19
|
*/
|
20
|
|
21
|
/**
|
22
|
* Implementation of hook_user().
|
23
|
* used to update all nodes from one user, thus updating there autonodetitles
|
24
|
* this function will invoke, when a user edits his user profile page
|
25
|
*/
|
26
|
function taxon_experts_user($op, &$edit, &$account, $category = NULL) {
|
27
|
|
28
|
switch ($op) {
|
29
|
case 'update':
|
30
|
|
31
|
// only invoke update, if user updated his account manually
|
32
|
if($category != 'expertsdb_person') return;
|
33
|
|
34
|
// load all nodes from this user
|
35
|
if($uid = $account->uid){
|
36
|
|
37
|
// find content types to update
|
38
|
// search through them for matching user ids and load those nodes
|
39
|
$types = content_types();
|
40
|
$types_to_update = array(
|
41
|
'expertsdb_instmembership',
|
42
|
'expertsdb_interest',
|
43
|
);
|
44
|
|
45
|
// Find nodes of the given types by this user and update the autonodetitle
|
46
|
$search_tables = array();
|
47
|
foreach ($types as $type_name => $type) {
|
48
|
// Only add tables where the expertsdb_field is present
|
49
|
if (in_array($type_name, $types_to_update)) {
|
50
|
$search_tables['content_type_'.$type_name] = $type_name;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
foreach($search_tables as $table => $type){
|
55
|
$ids = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n LEFT JOIN {" . $table . "} f ON n.vid = f.vid WHERE n.uid=" . $account->uid . " AND n.type='" . $type . "' AND n.status = 1"));
|
56
|
while ($data = db_fetch_object($ids)) {
|
57
|
// load the node
|
58
|
$node = node_load($data->nid);
|
59
|
|
60
|
// invoke autonodetitle
|
61
|
auto_nodetitle_set_title($node);
|
62
|
|
63
|
// just resave the node
|
64
|
node_save($node);
|
65
|
}
|
66
|
}
|
67
|
}
|
68
|
}
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Implementation of hook_nodeapi().
|
73
|
*
|
74
|
* this fixes issue with autonodetitle not being able to fetch node titles of referenced nodes
|
75
|
*/
|
76
|
function taxon_experts_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
|
77
|
$types_to_update = array(
|
78
|
'expertsdb_instmembership',
|
79
|
);
|
80
|
|
81
|
if ($op == 'alter' && variable_get('ant_'. $node->type, 0) && in_array($node->type,$types_to_update)) {
|
82
|
|
83
|
switch($node->type){
|
84
|
case 'expertsdb_instmembership':
|
85
|
|
86
|
// invoke autonodetitle
|
87
|
auto_nodetitle_set_title($node);
|
88
|
|
89
|
break;
|
90
|
}
|
91
|
|
92
|
}
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @param $display_options: e.g.: array(
|
97
|
* 12 => array('term_path'=> true, 'notes'=>'$node->field_taxon_notes'),
|
98
|
* 10 => array('term_path'=> true, 'notes'=>'$node->field_geo_notes',))
|
99
|
*/
|
100
|
function theme_expertdb_interest_categories($taxonomies, $display_options = array(), $table = true, $profile_node = FALSE){
|
101
|
|
102
|
static $vocab_labels = array(
|
103
|
'Taxonomy' => 'Field of Expertise',
|
104
|
'Georegion' => 'Geographic Region',
|
105
|
'Environment' => 'Environment',
|
106
|
'Activity' => 'Taxonomic Activity',
|
107
|
'Methods' => 'Methodology',
|
108
|
);
|
109
|
|
110
|
$terms = array();
|
111
|
foreach($taxonomies as $tid => $term){
|
112
|
$terms[$term->vid][] = $term;
|
113
|
}
|
114
|
if($table){
|
115
|
$rows = array();
|
116
|
foreach($terms as $vid => $term_items){
|
117
|
$temp_cell = FALSE;
|
118
|
$vocab = taxonomy_get_vocabulary($vid);
|
119
|
|
120
|
$header_cell = array('data'=>t($vocab_labels[$vocab->name]).':', 'header'=>true, 'class'=>'category');
|
121
|
$terms_cell = array('data'=>'', 'class'=>'term');
|
122
|
|
123
|
$show_term_path = isset($display_options[$vid]['term_path']);
|
124
|
|
125
|
foreach($term_items as $t){
|
126
|
// calculate path from root term to $t if desired
|
127
|
if($show_term_path){
|
128
|
$p_terms = taxonomy_get_parents_all($t->tid);
|
129
|
} else {
|
130
|
$p_terms = array($t);
|
131
|
}
|
132
|
$term_path = '';
|
133
|
while($item = array_pop($p_terms)){
|
134
|
$term_path .= $item->name.(count($p_terms) ? ' » ':'');
|
135
|
}
|
136
|
// create table cell
|
137
|
$temp_cell['data'][] = '<span class="term" title="'.$t->description.'">'.$term_path.'</span>';
|
138
|
}
|
139
|
$terms_cell['data'] = count($temp_cell['data']) > 1 ? implode('<br /> ',$temp_cell['data']) : implode('',$temp_cell['data']);
|
140
|
|
141
|
// append notes
|
142
|
if($display_options[$vid]['notes']){
|
143
|
$terms_cell['data'] .= '<span class="notes">'.$display_options[$vid]['notes'].'</span>';
|
144
|
}
|
145
|
|
146
|
$rows[] = array($header_cell, $terms_cell);
|
147
|
}
|
148
|
return theme('table', null, $rows, array('class'=>'interest_data'));
|
149
|
|
150
|
} else {
|
151
|
$output = '';
|
152
|
foreach($terms as $vid => $term_items){
|
153
|
$vocab = taxonomy_get_vocabulary($vid);
|
154
|
$output .= '<div class="field taxonomy">';
|
155
|
$output .= '<div class="field-label field-label-category">'.t($vocab_labels[$vocab->name]).'</div>';
|
156
|
$output .= '<div class="field-items field-items-terms">';
|
157
|
foreach($term_items as $t){
|
158
|
$output .= '<span class="field-item field-item-term" title="'.$t->description.'">'.$t->name.'</span>';
|
159
|
}
|
160
|
$output .= '</div></div>';
|
161
|
}
|
162
|
return $output;
|
163
|
}
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* Display the nodes of a view as a table and add an edit & delete links to each row.
|
168
|
* An additional add link will be added as last row to the table.
|
169
|
* see theme_views_view_list for a definition of $type
|
170
|
*/
|
171
|
function theme_views_view_optable($view, $nodes, $type, $add_op_link = null, $operations = array()) {
|
172
|
|
173
|
$rows[] = array();
|
174
|
$fields = _views_get_fields();
|
175
|
|
176
|
foreach ($nodes as $node) {
|
177
|
$row = array();
|
178
|
foreach ($view->field as $field) {
|
179
|
$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
|
180
|
$cell['class'] = "view-field view-field-$field[queryname]";
|
181
|
$row[] = $cell;
|
182
|
}
|
183
|
if( count($operations) || $add_op_link ){
|
184
|
// add links for the edit & delete operations
|
185
|
$cell['data'] = '';
|
186
|
if(in_array('view', $operations)){
|
187
|
$cell['data'] .= l(t('View'), "node/$node->nid").' ';
|
188
|
}
|
189
|
if(in_array('edit', $operations)){
|
190
|
$cell['data'] .= l(t('Edit'), "node/$node->nid/edit", null, drupal_get_destination()).' ';
|
191
|
}
|
192
|
if(in_array('delete', $operations)){
|
193
|
$cell['data'] .= l(t('Delete'), "node/$node->nid/delete", null, drupal_get_destination());
|
194
|
}
|
195
|
$cell['class'] = "view-field view-field-operations";
|
196
|
$row[] = $cell;
|
197
|
}
|
198
|
$rows[] = $row;
|
199
|
}
|
200
|
|
201
|
|
202
|
if($add_op_link){
|
203
|
// fill empty fields
|
204
|
$row = array();
|
205
|
foreach ($view->field as $field) {
|
206
|
$cell['data'] = '';
|
207
|
$cell['class'] = "view-field view-field-empty";
|
208
|
$row[] = $cell;
|
209
|
}
|
210
|
// append add link as last cell
|
211
|
$cell['data'] = $add_op_link;
|
212
|
$cell['class'] = "view-field view-field-operations";
|
213
|
$row[] = $cell;
|
214
|
|
215
|
$rows[] = $row;
|
216
|
}
|
217
|
|
218
|
$header = $view->table_header;
|
219
|
if(count($operations)){
|
220
|
$header[] = array('data'=>t('Actions'));
|
221
|
}
|
222
|
|
223
|
return theme('table', $header, $rows);
|
224
|
}
|
225
|
|
226
|
|
227
|
/*
|
228
|
* lifespan theming is done by expertsdb_timespan.module field formatters
|
229
|
*/
|
230
|
/*function theme_date_lifespan($field, $dates, $node = NULL) {
|
231
|
|
232
|
$date1 = $dates['value']['formatted'];
|
233
|
$date2 = $dates['value2']['formatted'];
|
234
|
if (empty($date1) && empty($date2)) {
|
235
|
return '';
|
236
|
}
|
237
|
elseif ($date1 == $date2 || empty($date2)) {
|
238
|
return '<div class="date_lifespan">*<span class="date-display-single">'. $date1 .'</span></div>';
|
239
|
}
|
240
|
else {
|
241
|
return '<div class="date_lifespan">*<span class="date-display-single">'. $date1 .'</span>'
|
242
|
.'<span class="date-display-separator"> - </span>'
|
243
|
.'†<span class="date-display-end">'. $date2 .'</span></div>';
|
244
|
}
|
245
|
}*/
|
246
|
|
247
|
|
248
|
/**
|
249
|
* Enter description here...
|
250
|
*
|
251
|
* @param unknown_type $rows
|
252
|
* @param unknown_type $cell array e.g:
|
253
|
* $cell = array(
|
254
|
* 'empty' => array(
|
255
|
* 'data' => '',
|
256
|
* 'class' => 'view-field view-field-operations'),
|
257
|
* 'addcell' => array(
|
258
|
* 'data' => $add_op_link,
|
259
|
* 'class' => 'view-field view-field-operations'));
|
260
|
*
|
261
|
* @param integer $position in which column to put the cell in,
|
262
|
* defaults to the last cell,
|
263
|
* if $position > last column the cell will be put into the last column
|
264
|
*
|
265
|
* Usage example:
|
266
|
* if($add_op_link){
|
267
|
$lastrow_cells = array(
|
268
|
'empty' => array(
|
269
|
'data' => '',
|
270
|
'class' => 'view-field view-field-empty'),
|
271
|
'addcell' => array(
|
272
|
'data' => $add_op_link,
|
273
|
'class' => 'view-field view-field-operations')
|
274
|
);
|
275
|
_add_as_last_row($rows, $lastrow_cells);
|
276
|
}
|
277
|
*/
|
278
|
function _add_as_last_row(&$rows, $cells, $position = false){
|
279
|
|
280
|
$row = array();
|
281
|
foreach ($rows[0] as $idx => $field) {
|
282
|
$row[] = $cell['empty'];
|
283
|
}
|
284
|
|
285
|
if($position){
|
286
|
// put cell in position
|
287
|
$row[$position] = $cells['addcell'];
|
288
|
} else {
|
289
|
// append add link as last cell
|
290
|
$row[count($row)-1] = $cells['addcell'];
|
291
|
}
|
292
|
$rows[] = $row;
|
293
|
}
|
294
|
|
295
|
|
296
|
/*function _autotitle_expertsdb_address(&$node){
|
297
|
$contact_nid = $node->field_parent_contact[0]['nid'];
|
298
|
$contact_node = node_load($contact_nid);
|
299
|
print 'Address for '.$contact_node->title;
|
300
|
}*/
|
301
|
|
302
|
/**
|
303
|
* Alternative link rendering to point to the user account of the node author
|
304
|
* instead of pointing to the node itself
|
305
|
*
|
306
|
* used for view search_person
|
307
|
*/
|
308
|
function taxon_experts_handler_user_link($fieldinfo, $fielddata, $value, $data){
|
309
|
if ($fielddata['options'] == 'nolink') {
|
310
|
return check_plain($value);
|
311
|
}
|
312
|
$node = node_load($data->nid);
|
313
|
return l($value, "user/$node->uid");
|
314
|
}
|
315
|
|
316
|
function taxon_experts_handler_user_interest_link($fieldinfo, $fielddata, $value, $data){
|
317
|
if ($fielddata['label'] != 'Interest') {
|
318
|
return check_plain($value);
|
319
|
}
|
320
|
$node = node_load($data->nid);
|
321
|
$image = theme('image', drupal_get_path('module', 'taxon_experts') . '/images/go_to_interest.png', t('Go to this interest'));
|
322
|
return l($image, "node/$data->nid",array('title' => t('Go to this interest: '.$node->title)),NULL,NULL,NULL,TRUE);
|
323
|
}
|
324
|
|
325
|
function taxon_experts_handler_expert_link($fieldinfo, $fielddata, $value, $data){
|
326
|
if ($fielddata['options'] == 'nolink') {
|
327
|
return check_plain($value);
|
328
|
}
|
329
|
$node = node_load($data->nid);
|
330
|
$name = _taxon_expert_get_expert_name($value);
|
331
|
return l($name, "user/$node->uid");
|
332
|
}
|
333
|
|
334
|
|
335
|
function _taxon_experts_get_profile_nid($type){
|
336
|
if(arg(0) == 'user'){
|
337
|
$profile_node = node_load(array('type'=>$type, 'uid'=>arg(1)));
|
338
|
return $profile_node->nid;
|
339
|
} else {
|
340
|
return arg(1);
|
341
|
}
|
342
|
}
|
343
|
|
344
|
function _taxon_expert_get_expert_name($nid = false){
|
345
|
if(!$nid) return;
|
346
|
$node = node_load($nid);
|
347
|
return $node->title;
|
348
|
}
|
349
|
/*
|
350
|
* find out, if the current user is the owner of the current node
|
351
|
*/
|
352
|
function _taxon_experts_user_is_owner(){
|
353
|
global $user;
|
354
|
if(arg(0) == 'user' && arg(1) == $user->uid){
|
355
|
return TRUE;
|
356
|
}
|
357
|
if(arg(0) == 'node' && is_numeric(arg(1))){
|
358
|
$node = node_load(arg(1));
|
359
|
if($node->uid == $user->uid){
|
360
|
return TRUE;
|
361
|
}
|
362
|
}
|
363
|
}
|
364
|
|
365
|
function _taxon_experts_menu_custom($nid = false, $uid = false){
|
366
|
global $user;
|
367
|
if(!$uid || !$nid || $user->uid == $uid || !user_access('edit expertsdb_person content')) return;
|
368
|
$output = "<ul class=\"tabs primary\">\n";
|
369
|
$output .= '<li>'. l(t('Edit'),'/node/' . $nid . '/edit') ."</li>\n";
|
370
|
$output .= "</ul>\n";
|
371
|
$output .= '<div class="clear-block"> </div>';;
|
372
|
return $output;
|
373
|
}
|