Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / themes / garland_diptera / template.php @ ed0183ea

History | View | Annotate | Download (7.8 KB)

1
<?php
2
// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $
3

    
4
/**
5
 * Sets the body-tag class attribute.
6
 *
7
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
8
 */
9
function phptemplate_body_class($sidebar_left, $sidebar_right) {
10
  if ($sidebar_left != '' && $sidebar_right != '') {
11
    $class = 'sidebars';
12
  }
13
  else {
14
    if ($sidebar_left != '') {
15
      $class = 'sidebar-left';
16
    }
17
    if ($sidebar_right != '') {
18
      $class = 'sidebar-right';
19
    }
20
  }
21

    
22
  if (isset($class)) {
23
    print ' class="'. $class .'"';
24
  }
25
}
26

    
27
/**
28
 * Return a themed breadcrumb trail.
29
 *
30
 * @param $breadcrumb
31
 *   An array containing the breadcrumb links.
32
 * @return a string containing the breadcrumb output.
33
 */
34
function phptemplate_breadcrumb($breadcrumb) {
35
  if (!empty($breadcrumb)) {
36
    return '<div class="breadcrumb">'. implode('', $breadcrumb) .'</div>';
37
  }
38
}
39

    
40
/**
41
 * Allow themable wrapping of all comments.
42
 */
43
function phptemplate_comment_wrapper($content, $type = null) {
44
  static $node_type;
45
  if (isset($type)) $node_type = $type;
46

    
47
  if (!$content || $node_type == 'forum') {
48
    return '<div id="comments">'. $content . '</div>';
49
  }
50
  else {
51
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
52
  }
53
}
54

    
55
/**
56
 * Override or insert PHPTemplate variables into the templates.
57
 */
58
function _phptemplate_variables($hook, $vars) {
59
  if ($hook == 'page') {
60

    
61
    if ($secondary = menu_secondary_local_tasks()) {
62
      $output = '<span class="clear"></span>';
63
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
64
      $vars['tabs2'] = $output;
65
    }
66

    
67
    // Hook into color.module
68
    if (module_exists('color')) {
69
      _color_page_alter($vars);
70
    }
71
    return $vars;
72
  }
73
  return array();
74
}
75

    
76
/**
77
 * Returns the rendered local tasks. The default implementation renders
78
 * them as tabs.
79
 *
80
 * @ingroup themeable
81
 */
82
function phptemplate_menu_local_tasks() {
83
  $output = '';
84

    
85
  if ($primary = menu_primary_local_tasks()) {
86
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
87
  }
88

    
89
  return $output;
90
}
91

    
92
/**
93
 * This function sort an array of description elements where all the elements
94
 * are of type UUID_CITATION. The sorting is done based at first on the title
95
 * cache of the author and second of the date of the publication.
96
 * @param $x An element of the array
97
 * @param $y An element of the array
98
 * @return array The sortered description elements array
99
 */
100
function compare_citations($x, $y)
101
{
102

    
103
  if( !$x->sources[0]->citation->uuid){// && !$y->sources[0]->citation->uuid){
104
    $res = -1;
105
    //var_dump($y->sources[0]->citation->uuid);
106
  }elseif(!$y->sources[0]->citation->uuid){
107
    $res = 1;
108
    //var_dump($x->sources[0]->citation->uuid);
109
  }
110
  else{
111

    
112

    
113
  $author_team_x = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $x->sources[0]->citation->uuid);
114
  $author_team_y = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $y->sources[0]->citation->uuid);
115

    
116
   //same author, and different year
117
  if($author_team_x->titleCache == $author_team_y->titleCache){
118
    $x_year = substr(
119
            $x->sources[0]->citation->datePublished->start,
120
            0,
121
            strpos($x->sources[0]->citation->datePublished->start,'-'));
122
    $y_year = substr(
123
              $y->sources[0]->citation->datePublished->start,
124
              0,
125
              strpos($y->sources[0]->citation->datePublished->start,'-'));
126
    if ($x_year < $y_year){//the year of the first publication is smaller
127
      $res = -1;
128
    }
129
    else if($x_year == $y_year){ //if same year check the page
130
      $x_page = $x->sources[0]->citationMicroReference;
131
      $y_page = $y->sources[0]->citationMicroReference;
132
      if($x_page < $y_page){
133
        $res = -1;
134
      }
135
      else{
136
        $res = 1;
137
      }
138
    }else
139
    $res = 1;
140
  }
141
  //different author and the first one is alphabetically smaller
142
  //else if($x->sources[0]->citation->authorship->teamMembers[0]->lastname <
143
  //$y->sources[0]->citation->authorship->teamMembers[0]->lastname){
144
  else if ($author_team_x->titleCache < $author_team_y->titleCache)        {
145
    $res = -1;
146
  }
147
  //different author and the second one is alphabetically smaller
148
  else{
149
    $res = 1;
150
  }
151

    
152
  }
153
  //var_dump($res);
154
  //var_dump(' ============ ');
155
  return $res;
156
}
157

    
158

    
159
function garland_diptera_cdm_descriptionElements($descriptionElements){
160

    
161
  $outArray = array();
162
  $glue = '';
163
  $sortOutArray = false;
164
  $enclosingHtml = 'ul';
165

    
166
  $citations = array();
167

    
168
  // only for diptera
169
  if(isset($descriptionElements[0]) && $descriptionElements[0]->feature->uuid == UUID_CITATION ) {
170
    foreach($descriptionElements as $element){
171
      $tokens = split(":", $element->multilanguageText_L10n->text);
172
      if(count($tokens) == 2){
173
        // token[0]: taxon name; token[1]: note;
174
        $element->multilanguageText_L10n->text = $tokens[1] . ' [<span class="name">' . $tokens[0] . '</span>]';
175
      }
176
      if(isset($element->citation->datePublished->start)){
177
        $elementMap[partialToYear($element->citation->datePublished->start)] = $element;
178
      } else {
179
        $elementMap[] = $element;
180
      }
181
    }
182
    $success = ksort($elementMap);
183
    $descriptionElements = $elementMap;
184
  }
185
  // ---
186
  usort($descriptionElements, 'compare_citations');
187
  foreach($descriptionElements as $element){
188
    if($element->class == 'TextData'){
189
      $asListElement = true;
190
      $outArray[] = theme('cdm_descriptionElementTextData', $element, $asListElement);
191
    }else if($element->class == 'Distribution'){
192
      if( !array_search($element->area->representation_L10n, $outArray)){
193
        $outArray[] = $element->area->representation_L10n;
194
        $glue = ', ';
195
        $sortOutArray = true;
196
        $enclosingHtml = 'p';
197
      }
198
    }else{
199
      $outArray[] = '<li>No method for rendering unknown description class: '.$element->classType.'</li>';
200
    }
201
  }
202

    
203
  $feature = NULL;
204
  // FIXME the below line was plain wrong before refactoring from theme to compose function
205
  // it was like theme('compose_feature_block_wrap_elements', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
206
  // which could never have worked
207
  return compose_feature_block_wrap_elements($outArray, $feature, $glue, $sortOutArray);
208
}
209

    
210
/**
211
 * Allows theaming of the taxon page tabs
212
 *
213
 * @param $tabname
214
 * @return unknown_type
215
 * FIXME the theme hoock cdm_taxonpage_tab no linger exists use the settings instead
216
 */
217
function garland_diptera_cdm_taxonpage_tab($tabname){
218
  switch($tabname){
219
    case 'Synonymy' : return t('Nomenclature'); break;
220
    default : return t($tabname);
221
  }
222
}
223

    
224
function garland_diptera_cdm_feature_name($feature_name){
225
  switch($feature_name){
226
    case "Citation": return t("Citations");
227
    case 'Has orthographic variant': return t("Misspellings");
228
    default: return t(ucfirst($feature_name));
229
  }
230
}
231

    
232
function garland_diptera_cdm_OriginalSource($descriptionElementSource, $doLink = TRUE){
233

    
234
    //ev. delegate to theme_cdm_ReferencedEntityBase
235
    $out = '';
236
    if($descriptionElementSource->citation){
237
      $datePublished = $descriptionElementSource->citation->datePublished;
238
      if (strlen($datePublished->start) >0){
239
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
240
      }
241

    
242
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $descriptionElementSource->citation->uuid);
243
        $author_team_titlecache = $author_team->titleCache;
244
        if (strlen($year)>0){
245
          $reference = $author_team_titlecache.' '. $year;
246
        }else {
247
          $reference = $author_team_titlecache ;
248
        }
249

    
250
      if($doLink){
251
        $out = l('<span class="reference">'.$reference.'</span>'
252
          , path_to_reference($descriptionElementSource->citation->uuid)
253
          , array("class"=>"reference")
254
          , NULL, NULL, FALSE ,TRUE);
255
      } else {
256
       $out = $reference;
257
      }
258
      if($descriptionElementSource->citationMicroReference){
259
        $out .= ': '. $descriptionElementSource->citationMicroReference;
260
      }
261
    }
262
    return $out;
263
}
Add picture from clipboard (Maximum size: 40 MB)