Project

General

Profile

Download (8.07 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * Common Theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15
16
define('FOOTNOTE_ANNOTATIONS', 'annotations');
17
18
/**
19
 * Get the true path to the root of the Drupal site.
20
 *
21
 * Better than using DOCUMENT_ROOT and base_path().
22
 */
23
function absolute_path_to_drupal() {
24
  static $absolute_path_to_drupal = NULL;
25
26
  if ($absolute_path_to_drupal === NULL) {
27
    // Get the absolute path to this file:
28
    $dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
29
    $parts = explode('/', $dir);
30
    // Iterate up the directory hierarchy until we find the website root:
31
    $done = FALSE;
32
    do {
33
      // Check a couple of obvious things:
34
      $done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
35
      if (!$done) {
36
        // If there's no more path to examine, we didn't find the site root:
37
        if (empty($parts)) {
38
          $absolute_path_to_drupal = FALSE;
39
          break;
40
        }
41
        // Go up one level and look again:
42
        array_pop($parts);
43
        $dir = implode('/', $parts);
44
      }
45
    } while (!$done);
46
47
    $absolute_path_to_drupal = $dir;
48
  }
49
  return $absolute_path_to_drupal;
50
}
51
52
/**
53 6e2a9ba9 Andreas Kohlbecker
 * Checks if the taxon specified by the uuid is contained in the currently focused classification.
54
 *
55
 * @param $taxon_uuid
56
 * @return bool
57 6657531f Andreas Kohlbecker
 */
58 7663cd0b Andreas Kohlbecker
function taxon_in_current_classification($taxon_uuid) {
59 6657531f Andreas Kohlbecker
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
60
  $taxon_in_current_tree = FALSE;
61
  if (is_array($taxon_nodes)) {
62
    foreach ($taxon_nodes as $node) {
63 64cfdac1 Andreas Kohlbecker
      if (get_current_classification_uuid() == $node->classificationUUID) {
64 6657531f Andreas Kohlbecker
        $taxon_in_current_tree = TRUE;
65
        break;
66
      }
67
    }
68
  }
69
  return $taxon_in_current_tree;
70
}
71
72
/**
73
 * TODO if getting fragment from request is possible remove
74
 * $_REQUEST['highlite'] HACK
75
 * NOT WORKING since fragments are not available to the server
76 7a2a14b3 Andreas Kohlbecker
 *
77 6657531f Andreas Kohlbecker
 * function fragment(){
78 7a2a14b3 Andreas Kohlbecker
 *    global $fragment;
79
 *    if(!$fragment){
80
 *       $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
81
 *    }
82
 *   return $fragment;
83 6657531f Andreas Kohlbecker
 * }
84
 */
85
function uuid_anchor($uuid, $innerHTML) {
86
  $highlite = FALSE;
87
  $params = drupal_get_query_parameters();
88
  if (isset($params['highlite']) && $params['highlite'] == $uuid) {
89
    $highlite = TRUE;
90
  }
91
92
  return '<a name="' . $uuid . '" ></a><span class="' . ($highlite ? 'highlite' : '') . '">' . $innerHTML . '</span>';
93
}
94
95
/**
96
 * @todo Enter description here...
97
 * @deprecated looks like this is not used anymore
98
 */
99
/*
100
function tagNameParts($name, $numOfNameTokens) {
101
  $out = '<span class="name">';
102
103
  $token = strtok($name, " \n\t");
104
  $i = 0;
105
  $noSpace = TRUE;
106
  while ($token != FALSE) {
107
    if ($i == $numOfNameTokens) {
108
      $out .= '</span> <span class="authors">';
109
      $noSpace = TRUE;
110
    }
111
    $out .= ($noSpace ? '' : ' ') . $token;
112
    $noSpace = FALSE;
113
    $token = strtok(" \n\t");
114
    $i++;
115
  }
116
  return $out . '</span>';
117
}
118
*/
119
120
/* ============================ annotations ============================= */
121
122
/**
123 e9cc637a Andreas Kohlbecker
 * Created markup for the annotations
124
 * @param null $annotations
125
 * @param $enclosingTag
126
 *  Tag name of the DOM element to enclose the annotations.
127
 *
128
 * @return string
129 6657531f Andreas Kohlbecker
 */
130 e9cc637a Andreas Kohlbecker
function cdm_annotations($annotations = null, $enclosingTag = span) {
131
132 6657531f Andreas Kohlbecker
  if (!is_array($annotations)) {
133 e9cc637a Andreas Kohlbecker
    return '';
134 6657531f Andreas Kohlbecker
  }
135
  $out = '<' . $enclosingTag . ' class="annotations">';
136
  $i = 0;
137
  foreach ($annotations as $annotation) {
138
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
139
  }
140
  $out .= '</' . $enclosingTag . '>';
141
  return $out;
142
}
143
144
145
146 4ae6064e Andreas Kohlbecker
/**
147
 * Theme function for CDM marker instances
148
 *
149
 * @see compose_cdm_marker();
150
 * @param array $variables
151
 *   - markerType_representation_l10n: the localized representation of the marker.markerType field
152
 */
153
function theme_cdm_marker($variables) {
154
  $class_attribute = null;
155
  //TODO class attribute hacked?, use generic drupal way?
156
  if(isset($variables['attributes']['class'])){
157
    $class_attribute = $variables['attributes']['class'];
158
  }
159
  return '<span class="' . $class_attribute . '">' . $variables['label'] . '</span>';
160
}
161
162 6657531f Andreas Kohlbecker
/* ============================ pager ============================= */
163 c278f2a0 Andreas Kohlbecker
164 6657531f Andreas Kohlbecker
/**
165
 * @todo Please document this function.
166
 * @see http://drupal.org/node/1354
167
 */
168
function theme_cdm_pager($variables) {
169
  $pager = $variables['pager'];
170
  $path = $variables['path'];
171
  $parameters = $variables['parameters'];
172
  $out = '';
173
174
  if ($pager->pagesAvailable > 1) {
175
176
    $out .= '<div class="pager">';
177
    if ($pager->currentIndex > 0) {
178
      $out .= theme('cdm_pager_link', array(
179 c278f2a0 Andreas Kohlbecker
        'text' => '« ' . t('First'),
180 6657531f Andreas Kohlbecker
        'linkIndex' => 0,
181
        'pager' => $pager,
182
        'path' => $path,
183
        'parameters' => $parameters,
184
        'attributes' => array('class' => array('pager-first')),
185
        ));
186
      $out .= theme('cdm_pager_link', array(
187 c278f2a0 Andreas Kohlbecker
        'text' => '‹ ' . t('Previous'),
188 6657531f Andreas Kohlbecker
        'linkIndex' => $pager->currentIndex - 1,
189
        'pager' => $pager,
190
        'path' => $path,
191
        'parameters' => $parameters,
192
        'attributes' => array('class' => array('pager-previous')),
193
        ));
194
    }
195
196
    if ($pager->indices[0] > 0) {
197
      $out .= '<div class="pager-list-dots-left">...</div>';
198
    }
199
200
    foreach ($pager->indices as $index) {
201
      $label = $index + 1;
202
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
203
  'class' => array('pager-first'),
204
)));
205
    }
206
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
207
      $out .= '<div class="pager-list-dots-right">...</div>';
208
    }
209
210
    if ($pager->nextIndex) {
211 c278f2a0 Andreas Kohlbecker
      $out .= theme(
212
        'cdm_pager_link',
213
        array(
214
          'text' => t('Next') . ' ›',
215
          'linkIndex' => $pager->nextIndex,
216
          'pager' => $pager,
217
          'path' => $path,
218
          'parameters' => $parameters,
219
          'attributes' => array(
220
            'class' => array('pager-next'),
221
          )
222
        )
223
      );
224
      $out .= theme(
225
        'cdm_pager_link',
226
        array(
227
          'text' => t('Last') . ' »',
228
          'linkIndex' => $pager->pagesAvailable - 1,
229
          'pager' => $pager,
230
          'path' => $path,
231
          'parameters' => $parameters,
232
          'attributes' => array(
233
            'class' => array('pager-last'),
234
          )
235
        )
236
      );
237 6657531f Andreas Kohlbecker
    }
238
    $out .= '</div>';
239
240
    return $out;
241
  }
242
}
243
244
/**
245
 * @todo Please document this function.
246
 * @see http://drupal.org/node/1354
247
 */
248
function theme_cdm_pager_link($variables) {
249
  $text = $variables['text'];
250
  $linkIndex = $variables['linkIndex'];
251
  $pager = $variables['pager'];
252
  $path = $variables['path'];
253
  $parameters = $variables['parameters'];
254
  $attributes = $variables['attributes'];
255 34dd7be9 Andreas Kohlbecker
256 17cfc574 Andreas Kohlbecker
  // the parameters may still contain the q param,
257
  // but this is already in the path variable
258
  unset($parameters['q']);
259
260 34dd7be9 Andreas Kohlbecker
  $parameters['pager']['pageNumber'] = $linkIndex;
261 6657531f Andreas Kohlbecker
  if ($linkIndex == $pager->currentIndex) {
262
    $out = '<strong>' . $text . '</strong>';
263
  }
264
  else {
265
    // $queryString = drupal_query_string_encode($parameters);
266
    $queryString = $parameters;
267
    $out = l($text, $path, array(
268
      'attributes' => $attributes,
269
      'query' => $queryString,
270
    ));
271
  }
272
  return $out;
273
}
274
275
/* ============================ special buttons ============================= */
276
277
/**
278
 * @todo Please document this function.
279
 * @see http://drupal.org/node/1354
280
 */
281
function theme_cdm_print_button() {
282
283
  drupal_add_js('jQuery(document).ready(function() {
284
         jQuery(\'#print_button\').click(function () {
285
         window.print();
286
     });
287
  });', array('type' => 'inline'));
288
289 c8234bdf Andreas Kohlbecker
  $output = '<div id="print_button"><img src="' . base_path()  .  drupal_get_path('module', 'cdm_dataportal') . '/images/print_icon.gif"' . ' alt="' . t('Print this page') . '" title="' . t('Print this page') . '" />';
290 6657531f Andreas Kohlbecker
  // .t('Print this page');
291
  // $output .= l('Print this page', '');
292
  $output .= '<span>Print this page</span>';
293
  $output .= '</div>';
294
295
  return $output;
296
}