Project

General

Profile

Download (7.54 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
 * Checks if the taxon specified by the uuid is contained in the currently focused classification.
54
 *
55
 * @param $taxon_uuid
56
 * @return bool
57
 */
58
function taxon_in_current_classification($taxon_uuid) {
59
  $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
      if (get_current_classification_uuid() == $node->classificationUUID) {
64
        $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
 *
77
 * function fragment(){
78
 *    global $fragment;
79
 *    if(!$fragment){
80
 *       $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
81
 *    }
82
 *   return $fragment;
83
 * }
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
 * 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
 */
130
function cdm_annotations($annotations = null, $enclosingTag = span) {
131

    
132
  if (!is_array($annotations)) {
133
    return '';
134
  }
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
/* ============================ pager ============================= */
145

    
146
/**
147
 * @todo Please document this function.
148
 * @see http://drupal.org/node/1354
149
 */
150
function theme_cdm_pager($variables) {
151
  $pager = $variables['pager'];
152
  $path = $variables['path'];
153
  $parameters = $variables['parameters'];
154
  $out = '';
155

    
156
  if ($pager->pagesAvailable > 1) {
157

    
158
    $out .= '<div class="pager">';
159
    if ($pager->currentIndex > 0) {
160
      $out .= theme('cdm_pager_link', array(
161
        'text' => '« ' . t('First'),
162
        'linkIndex' => 0,
163
        'pager' => $pager,
164
        'path' => $path,
165
        'parameters' => $parameters,
166
        'attributes' => array('class' => array('pager-first')),
167
        ));
168
      $out .= theme('cdm_pager_link', array(
169
        'text' => '‹ ' . t('Previous'),
170
        'linkIndex' => $pager->currentIndex - 1,
171
        'pager' => $pager,
172
        'path' => $path,
173
        'parameters' => $parameters,
174
        'attributes' => array('class' => array('pager-previous')),
175
        ));
176
    }
177

    
178
    if ($pager->indices[0] > 0) {
179
      $out .= '<div class="pager-list-dots-left">...</div>';
180
    }
181

    
182
    foreach ($pager->indices as $index) {
183
      $label = $index + 1;
184
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
185
  'class' => array('pager-first'),
186
)));
187
    }
188
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
189
      $out .= '<div class="pager-list-dots-right">...</div>';
190
    }
191

    
192
    if ($pager->nextIndex) {
193
      $out .= theme(
194
        'cdm_pager_link',
195
        array(
196
          'text' => t('Next') . ' ›',
197
          'linkIndex' => $pager->nextIndex,
198
          'pager' => $pager,
199
          'path' => $path,
200
          'parameters' => $parameters,
201
          'attributes' => array(
202
            'class' => array('pager-next'),
203
          )
204
        )
205
      );
206
      $out .= theme(
207
        'cdm_pager_link',
208
        array(
209
          'text' => t('Last') . ' »',
210
          'linkIndex' => $pager->pagesAvailable - 1,
211
          'pager' => $pager,
212
          'path' => $path,
213
          'parameters' => $parameters,
214
          'attributes' => array(
215
            'class' => array('pager-last'),
216
          )
217
        )
218
      );
219
    }
220
    $out .= '</div>';
221

    
222
    return $out;
223
  }
224
}
225

    
226
/**
227
 * @todo Please document this function.
228
 * @see http://drupal.org/node/1354
229
 */
230
function theme_cdm_pager_link($variables) {
231
  $text = $variables['text'];
232
  $linkIndex = $variables['linkIndex'];
233
  $pager = $variables['pager'];
234
  $path = $variables['path'];
235
  $parameters = $variables['parameters'];
236
  $attributes = $variables['attributes'];
237

    
238
  // the parameters may still contain the q param,
239
  // but this is already in the path variable
240
  unset($parameters['q']);
241

    
242
  $parameters['pager']['pageNumber'] = $linkIndex;
243
  if ($linkIndex == $pager->currentIndex) {
244
    $out = '<strong>' . $text . '</strong>';
245
  }
246
  else {
247
    // $queryString = drupal_query_string_encode($parameters);
248
    $queryString = $parameters;
249
    $out = l($text, $path, array(
250
      'attributes' => $attributes,
251
      'query' => $queryString,
252
    ));
253
  }
254
  return $out;
255
}
256

    
257
/* ============================ special buttons ============================= */
258

    
259
/**
260
 * @todo Please document this function.
261
 * @see http://drupal.org/node/1354
262
 */
263
function theme_cdm_print_button() {
264

    
265
  drupal_add_js('jQuery(document).ready(function() {
266
         jQuery(\'#print_button\').click(function () {
267
         window.print();
268
     });
269
  });', array('type' => 'inline'));
270

    
271
  $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') . '" />';
272
  // .t('Print this page');
273
  // $output .= l('Print this page', '');
274
  $output .= '<span>Print this page</span>';
275
  $output .= '</div>';
276

    
277
  return $output;
278
}
279

    
(1-1/8)