Project

General

Profile

Download (14.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * Copyright (C) 2007 EDIT
6
 * European Distributed Institute of Taxonomy
7
 * http://www.e-taxonomy.eu
8
 *
9
 * The contents of this file are subject to the Mozilla Public License Version 1.1
10
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
 */
12

    
13
define(FOOTNOTE_ANNOTATIONS, 'annotations');
14

    
15

    
16
/**
17
* Get the true path to the root of the Drupal site.
18
* Better than using DOCUMENT_ROOT and base_path().
19
*/
20
function absolute_path_to_drupal() {
21
    static $absolute_path_to_drupal = NULL;
22

    
23
    if ($absolute_path_to_drupal === NULL) {
24
        // Get the absolute path to this file:
25
        $dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
26
        $parts = explode('/', $dir);
27
        // Iterate up the directory hierarchy until we find the website root:
28
        $done = FALSE;
29
        do{
30
            // Check a couple of obvious things:
31
            $done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
32
            if (!$done) {
33
                // If there's no more path to examine, we didn't find the site root:
34
                if (empty($parts)) {
35
                    $absolute_path_to_drupal = FALSE;
36
                    break;
37
                }
38
            // Go up one level and look again:
39
            array_pop($parts);
40
            $dir = implode('/', $parts);
41
            }
42
        }while (!$done);
43

    
44
        $absolute_path_to_drupal = $dir;
45
    }
46
    return $absolute_path_to_drupal;
47
}
48

    
49
function taxon_in_current_tree ($taxon_uuid) {
50
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
51
  $taxon_in_current_tree = false;
52
  if(is_array($taxon_nodes)){
53
    foreach($taxon_nodes as $node){
54
      if(get_taxonomictree_uuid_selected() == $node->classification->uuid){
55
        $taxon_in_current_tree = true;
56
        break;
57
      }
58
    }
59
  }
60
  return $taxon_in_current_tree;
61
}
62

    
63
/**
64
 * TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
65
 * NOT WORKING since fragments are not available to the server
66
 function fragment(){
67
 global $fragment;
68
 if(!$fragment){
69
 $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
70
 }
71
 return $fragment;
72
 }
73
 */
74

    
75
function uuid_anchor($uuid, $innerHTML){
76
  $highlite = $_REQUEST['highlite'] == $uuid;
77
  return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
78
}
79

    
80
/**
81
 * Enter description here...
82
 *
83
 * @param unknown_type $name
84
 * @param unknown_type $numOfNameTokens
85
 * @return unknown
86
 * @deprecated looks like this is not used anymore
87
 */
88
function tagNameParts($name, $numOfNameTokens){
89

    
90
  $out = '<span class="name">';
91

    
92
  $token = strtok($name, " \n\t");
93
  $i = 0;
94
  $noSpace = true;
95
  while($token != false){
96
    if($i == $numOfNameTokens){
97
      $out .= '</span> <span class="authors">';
98
      $noSpace = true;
99
    }
100
    $out .= ($noSpace?'':' ').$token;
101
    $noSpace = false;
102
    $token = strtok(" \n\t");
103
    $i++;
104
  }
105
  return $out.'</span>';
106
}
107

    
108
/**
109
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas
110
 * each item will provided with a class attribute which set to the key of the TaggedText item.
111
 *
112
 * @param array $taggedtxt
113
 * @param String $tag
114
 * @param String $glue the string by which the chained text tokens are concatenated together.
115
 *       Default is a blank character
116
 * @return String of HTML
117
 */
118
function theme_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
119
  $out = '';
120
  $i = 0;
121
  foreach($taggedtxt as $tt){
122
    if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
123
      $out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
124
    }
125
  }
126
  return $out;
127
}
128

    
129
/* ============================ annotations ============================= */
130

    
131
/**
132
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to display
133
 * as well as create or update annotations.
134
 * The following cdm classes are annotatable:
135
 *
136
 *  DescriptionElementBase
137
 *	EventBase
138
 *	HomotypicalGroup
139
 *	IdentifiableEntity
140
 *	  DescriptionBase
141
 *	  IdentifiableMediaEntity
142
 *	  Media
143
 *	  Sequence
144
 *	  TaxonBase
145
 *	  TaxonNameBase
146
 *	  TaxonomicTree
147
 *	  TermBase
148
 *	LanguageStringBase
149
 *	ReferencedEntityBase
150
 *	  NomenclaturalStatus
151
 *	  OriginalSourceBase
152
 *	  RelationshipBase
153
 *	  TypeDesignationBase
154
 *	TaxonNode
155
 *  WorkingSet
156
 *
157
 * @param $cdmBase_list an array of CdmBase instances or a single instance
158
 * @param $footnote_list_key
159
 */
160
function theme_cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key = null){
161
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
162
    return '';
163
  }
164
  $out = '';
165
  $footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key);
166
  foreach($footNoteKeys as $a){
167
    //$out .=  theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)? ',' : ''));
168
    $out .=  theme('cdm_footnote_key', $a, ($out ? ',' : ''));
169
  }
170
  return $out;
171
}
172

    
173

    
174
function theme_cdm_annotation_footnotes($footnoteListKey, $enclosingTag = 'span'){
175
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
176
    return '';
177
  }
178
  return theme('cdm_footnotes', $footnoteListKey . '-annotations', $enclosingTag);
179
}
180

    
181
function theme_cdm_annotation_content($AnnotationTO){
182

    
183
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
184
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
185

    
186
  $out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
187

    
188
  $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
189
  $annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
190

    
191
  // TODO users have to be authenticated to the dataportal to be able to write annotations
192
  $out .= '
193
        <div class="annotation_create">
194
          <form action="'.$annotationProxyUrl.'" method="POST">
195
            <textarea name="annotation"></textarea>
196
            <input type="hidden" name="commentator" value="">
197
            <input type="submit" value="'.t('Save annotation').'" />
198
          </form>
199
       </div>
200
  ';
201

    
202
  return $out;
203
}
204

    
205
function theme_cdm_list_of_annotations($annotationElements){
206

    
207
  $out = '<ul class="annotation_list">';
208

    
209
  foreach ($annotationElements as $key => $row){
210
    $created[$key] = $row;
211
  }
212
  array_multisort($created, SORT_ASC, $annotationElements);
213

    
214
  foreach ($annotationElements as $annotation){
215
    $out .= '<li>' . $annotation->text . '</li>';
216
  }
217

    
218
  $out .= '</ul>';
219

    
220
  return $out;
221

    
222
}
223

    
224
/* ============================ footnotes ============================= */
225

    
226
function theme_cdm_footnote_key($footnoteKey, $separator = '', $highlightable=true, $separator_off = false){
227
  if (!$footnoteKey->footnoteListKey){
228
    return '';
229
  }
230
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
231
    return '';
232
  }
233

    
234
  if ($separator_off){
235
    $separator = '';
236
  }
237
  $out = '<span class="footnote-key footnote-key-'.$footnoteKey->keyStr.' member-of-footnotes-'.$footnoteKey->footnoteListKey.'">'.$separator
238
  .'<a href="#footnote-'.$footnoteKey->keyStr.'">'.$footnoteKey->keyStr.'</a>'
239
  .'</span>';
240
  return $out;
241
}
242

    
243
function theme_cdm_footnote($footnoteKey, $footnoteText){
244
  _add_js_footnotes();
245
  $out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span>&nbsp;'.$footnoteText.'</span>';
246
  return $out;
247
}
248

    
249

    
250
function theme_cdm_footnotes($footnoteListKey, $enclosingTag = 'span'){
251
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
252
    return '';
253
  }
254
  $out = '<'.$enclosingTag.' class="footnotes footnotes-'.$footnoteListKey.' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</'.$enclosingTag.'>';
255
  FootnoteManager::removeFootnoteList($footnoteListKey);
256
  return $out;
257
}
258

    
259
function theme_cdm_annotations($annotations, $enclosingTag = 'span'){
260
  if(!is_array($annotations)){
261
    return;
262
  }
263
  $out = '<'.$enclosingTag.' class="annotations">';
264
  $i = 0;
265
  foreach($annotations as $annotation){
266
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
267
  }
268
  $out .= '</'.$enclosingTag.'>';
269
  return $out;
270
}
271

    
272
function cdm_exist_footnote($footnote_list, $footnote){
273
  $result = false;
274
  if (is_array($footnote_list)){
275
    foreach ($footnote_list as $element){
276
      if ($element == $footnote){
277
        $result = true;
278
      }
279
    }
280
  }
281
  return $result;
282
}
283

    
284
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
285
  if(!cdm_exist_footnote($footnote_list, $footnote)){
286
    $footnote_list[] = $footnote;
287
  }
288
}
289

    
290
/* ============================ pager ============================= */
291

    
292

    
293
function theme_cdm_pager(&$pager, $path, $parameters){
294
  $out = '';
295

    
296
  if ($pager->pagesAvailable > 1) {
297

    
298
    $out .= '<div class="pager">';
299
    if($pager->currentIndex > 0){
300
      $out .= theme('cdm_pager_link', t('« first'), 0,  $pager, $path, $parameters, array('class' => 'pager-first'));
301
      $out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
302
    }
303

    
304
    if($pager->indices[0] > 0){
305
      $out .= '<div class="pager-list-dots-left">...</div>';
306
    }
307

    
308
    foreach($pager->indices as $index){
309
      $label = $index + 1;
310
      $out .= theme('cdm_pager_link', $label, $index,  $pager, $path, $parameters, array('class' => 'pager-first'));
311
    }
312
    if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
313
      $out .= '<div class="pager-list-dots-right">...</div>';
314
    }
315

    
316
    if($pager->nextIndex){
317
      $out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
318
      $out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
319
    }
320
    $out .= '</div>';
321

    
322
    return $out;
323
  }
324
}
325

    
326
function theme_cdm_pager_link($text, $linkIndex, &$pager, $path, $parameters = array(), $attributes) {
327

    
328
  $out = '';
329
  $parameters['search']['pageNumber'] = $linkIndex;
330
  if ($linkIndex == $pager->currentIndex) {
331
    $out = '<strong>'.$text.'</strong>';
332
  } else {
333
    $queryString = drupal_query_string_encode($parameters);
334
    $out = l($text, $path, $attributes, $queryString);
335
  }
336
  return $out;
337
}
338

    
339
/* ============================ special buttons ============================= */
340

    
341
function theme_cdm_back_to_search_result_button(){
342
  $out = '';
343
  $show_button = variable_get('cdm_dataportal_show_back_to_search_results', 1);
344
  if($_SESSION['cdm']['search'] && $show_button){
345
    /*['cdm']['last_search']*/
346
    //$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
347
    $out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
348

    
349
  }
350
  return $out;
351
}
352

    
353
function theme_cdm_back_to_image_gallery_button(){
354

    
355
  $out = '<div id="backToGalleryButton">'.l(t('Back to Images'), $_SESSION['cdm']['last_gallery'] ).'</div>';
356

    
357
  return $out;
358
}
359

    
360
function theme_cdm_print_button(){
361

    
362
  drupal_add_js ('$(document).ready(function() {
363
         $(\'#print_button\').click(function () {
364
         window.print();
365
     });
366
  });', 'inline');
367

    
368
  $output = '<div id="print_button"><img src="'
369
  .drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
370
  . ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
371
  //$output .= l(' Print this page', '');
372
  $output .= '<span>Print this page</span>';
373
  $output .= '</div>';
374

    
375
  return $output;
376
}
377

    
378

    
379

    
380

    
381
/* ============================ java script functions ============================= */
382

    
383
function _add_js_thickbox(){
384
  // ---- jQuery thickbox:
385
  /*
386
   * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
387
   * -> event is not triggered because of problems with compat-1.0.js'
388
   * see INSTALL.txt
389
   *
390
   */
391
  //drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
392
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
393
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
394
}
395

    
396
function _add_js_lightbox($galleryID){
397
  /*
398
   * Important Notice:
399
   * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
400
   * for captions instead of the "title" attribute
401
   */
402
  $lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
403
  drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
404
  drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
405
  drupal_add_js ('$(document).ready(function() {
406
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
407
        fixedNavigation:  true,
408
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\',
409
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',
410
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',
411
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',
412
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\',
413
        adjustToWindow: true
414
      });
415
    });
416
    ', 'inline');
417
}
418

    
419
function _add_js_footnotes(){
420
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
421
}
422

    
423

    
424
function _add_js_cluetip(){
425

    
426
  //TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
427
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
428
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
429
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
430
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
431
  drupal_add_js ("$(document).ready(function(){
432
      $('.cluetip').css({color: '#0062C2'}).cluetip({
433
        splitTitle: '|',
434
        showTitle: true,
435
        activation: 'hover',
436
        sicky: true,
437
        arrows: true,
438
        dropShadow: false,
439
        cluetipClass: 'rounded'
440
      });
441
    });", 'inline');
442
}
443

    
444
function _add_js_ahah(){
445
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
446
}
(1-1/8)