Project

General

Profile

Download (14.4 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
 */
158
function theme_cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = null){
159
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
160
    return '';
161
  }
162
  $footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key);
163
  foreach($footNoteKeys as $a){
164
    //$out .=  theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)? ',' : ''));
165
    $out .=  theme('cdm_footnote_key', $a, (isset($out)? ',' : ''));
166
  }
167
  return $out;
168
}
169

    
170

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

    
178
function theme_cdm_annotation_content($AnnotationTO){
179

    
180
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
181
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
182

    
183
  $out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
184

    
185
  $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
186
  $annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
187

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

    
199
  return $out;
200
}
201

    
202
function theme_cdm_list_of_annotations($annotationElements){
203

    
204
  $out = '<ul class="annotation_list">';
205

    
206
  foreach ($annotationElements as $key => $row){
207
    $created[$key] = $row;
208
  }
209
  array_multisort($created, SORT_ASC, $annotationElements);
210

    
211
  foreach ($annotationElements as $annotation){
212
    $out .= '<li>' . $annotation->text . '</li>';
213
  }
214

    
215
  $out .= '</ul>';
216

    
217
  return $out;
218

    
219
}
220

    
221
/* ============================ footnotes ============================= */
222

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

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

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

    
246

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

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

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

    
281
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
282
  if(!cdm_exist_footnote($footnote_list, $footnote)){
283
    $footnote_list[] = $footnote;
284
  }
285
}
286

    
287
/* ============================ pager ============================= */
288

    
289

    
290
function theme_cdm_pager(&$pager, $path, $parameters){
291
  $out = '';
292

    
293
  if ($pager->pagesAvailable > 1) {
294

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

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

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

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

    
319
    return $out;
320
  }
321
}
322

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

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

    
336
/* ============================ special buttons ============================= */
337

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

    
346
  }
347
  return $out;
348
}
349

    
350
function theme_cdm_back_to_image_gallery_button(){
351

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

    
354
  return $out;
355
}
356

    
357
function theme_cdm_print_button(){
358

    
359
  drupal_add_js ('$(document).ready(function() {
360
         $(\'#print_button\').click(function () {
361
         window.print();
362
     });
363
  });', 'inline');
364

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

    
372
  return $output;
373
}
374

    
375

    
376

    
377

    
378
/* ============================ java script functions ============================= */
379

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

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

    
415
function _add_js_footnotes(){
416
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
417
}
418

    
419

    
420
function _add_js_cluetip(){
421

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

    
440
function _add_js_ahah(){
441
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
442
}
(1-1/8)