Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id: ext_links.module,v 1.3.4.5.2.10.2.5 2008/09/26 11:58:24 niif Exp $
3

    
4
/**
5
 * @file
6
 * Provides external links for sources to taxa information
7
 */
8

    
9
/**
10
 * Display help and module information
11
 * @param path which path of the site we're displaying help
12
 * @param arg array that holds the current path as would be returned from arg() function
13
 * @return help text for the path
14
 */
15
function ext_links_help($section) {
16
  $output = '';
17
  switch ($section) { 
18
    case 'admin/help#ext_links':
19
      //TODO
20
      $output = '<p>'. t("Link to external sources like ## for taxa.") .'</p>';
21
      break;
22
  }
23
  return $output;
24
} // function ext_links_help
25

    
26
/**
27
 * Generate the HTML text for the ext_link login block
28
 * @param op the operation from the URL
29
 * @param delta offset
30
 * @returns block HTML 
31
 */
32
function ext_links_admin() {
33
	global $ext_links_default;
34
	$ext_links[0] = array(
35
		'form' => 'gbif',
36
		'form_title' => 'GBIF',
37
		'check_title' => 'GBIF',
38
		'link_title' => 'GBIF link',
39
		'link_description' => 'The link to GBIF without the taxon name.',
40
		'concat_default_value' => ' ',
41
		'text_title' => 'GBIF text',
42
		'text_description' => 'The text of the link that is displayed..',
43
	);
44
	$ext_links[1] = array(
45
		'form' => 'biocase',
46
		'form_title' => 'BioCASE',
47
		'check_title' => 'Display BioCASE link?',
48
		'link_title' => 'BioCASE link',
49
		'link_description' => 'The link to BioCASE without the taxon name.',
50
		'concat_default_value' => ' ',
51
		'text_title' => 'BioCASE text',
52
		'text_description' => 'The text of the link that is displayed..',
53
	);
54
	$ext_links[2] = array(
55
		'form' => 'nybg',
56
		'form_title' => 'The New York Botanical Garden',
57
		'check_title' => 'Display NYBG link?',
58
		'link_title' => 'NYBG link',
59
		'link_description' => 'The link to NCBI without the taxon name.',
60
		'concat_default_value' => ' ',
61
		'text_title' => 'NYBG text',
62
		'text_description' => 'The text of the link that is displayed..',
63
	);
64
	$ext_links[3] = array(
65
		'form' => 'tropicos',
66
		'form_title' => 'Tropicos',
67
		'check_title' => 'Display Tropicos link?',
68
		'link_title' => 'Tropicos link',
69
		'link_description' => 'The link to Tropicos without the taxon name.',
70
		'concat_default_value' => '+',
71
		'text_title' => 'Tropicos text',
72
		'text_description' => 'The text of the link that is displayed..',
73
	);
74
	$ext_links[4] = array(
75
		'form' => 'ncbi',
76
		'form_title' => 'NCBI',
77
		'check_title' => 'Display NCBI link?',
78
		'link_title' => 'NCBI link',
79
		'link_description' => 'The link to NCBI without the taxon name.',
80
		'concat_default_value' => '+AND+',
81
		'text_title' => 'NCBI text',
82
		'text_description' => 'The text of the link that is displayed..',
83
	);
84
	$ext_links[5] = array(
85
		'form' => 'google',
86
		'form_title' => 'Google Images',
87
		'check_title' => 'Display Google Images link?',
88
		'link_title' => 'Google Images link',
89
		'link_description' => 'The link to Google Images without the taxon name.',
90
		'concat_default_value' => '+',
91
		'text_title' => 'Google Images text',
92
		'text_description' => 'The text of the link that is displayed..',
93
	);
94
	$ext_links[6] = array(
95
		'form' => 'flickr',
96
		'form_title' => 'flickr',
97
		'check_title' => 'Display flickr link?',
98
		'link_title' => 'flickr link',
99
		'link_description' => 'The link to flickr without the taxon name.',
100
		'concat_default_value' => '+',
101
		'text_title' => 'flickr text',
102
		'text_description' => 'The text of the link that is displayed..',
103
	);
104
	$ext_links[7] = array(
105
		'form' => 'scholar',
106
		'form_title' => 'Google scholar',
107
		'check_title' => 'Display Google scholar link?',
108
		'link_title' => 'Google scholar link',
109
		'link_description' => 'The link to Google scholar without the taxon name.',
110
		'concat_default_value' => '+',
111
		'text_title' => 'Google scholar text',
112
		'text_description' => 'The text of the link that is displayed..',
113
	);
114
	$ext_links[8] = array(
115
		'form' => 'bhl',
116
		'form_title' => 'Biodiversity Heritage Library (BHL)',
117
		'check_title' => 'Display BHL link?',
118
		'link_title' => 'BHL link',
119
		'link_description' => 'The link to BHL without the taxon name.',
120
		'concat_default_value' => ' ',
121
		'text_title' => 'BHL text',
122
		'text_description' => 'The text of the link that is displayed..',
123
	);
124

    
125
	for($i=0; $i<sizeof($ext_links); $i++){
126
	  $form[$ext_links[$i][form]] = array(
127
	    '#type' => 'fieldset',
128
	    '#title' => t($ext_links[$i][form_title]),
129
	    '#collapsible' => TRUE,
130
	    '#collapsed' => TRUE,
131
	  );
132
	  $form[$ext_links[$i][form]]['ext_links_'.$ext_links[$i][form].'_check'] = array(
133
	    '#type' => 'checkbox',
134
	    '#title' => t($ext_links[$i][check_title]),
135
	    '#default_value' => variable_get('ext_links_'.$ext_links[$i][form].'_check', 1),
136
	  );
137
	  $form[$ext_links[$i][form]]['ext_links_'.$ext_links[$i][form].'_link'] = array(
138
	    '#type' => 'textfield',
139
	    '#title' => t($ext_links[$i][link_title]),
140
	    '#default_value' => variable_get('ext_links_'.$ext_links[$i][form].'_link', $ext_links_default[$ext_links[$i][form]][link_default_value]),
141
	    '#size' => 70,
142
	    '#maxlength' => 255,
143
	    '#description' => t($ext_links[$i][link_description])
144
	  );
145
	  $form[$ext_links[$i][form]]['ext_links_'.$ext_links[$i][form].'_concat'] = array(
146
	    '#type' => 'textfield',
147
	    '#title' => t('Concatenate string'),
148
	    '#default_value' => variable_get('ext_links_'.$ext_links[$i][form].'_concat', $ext_links[$i][concat_default_value]),
149
	    '#size' => 70,
150
	    '#maxlength' => 255,
151
	    '#description' => t('Concatenate string between genus and species')
152
	  );
153
	$form[$ext_links[$i][form]]['ext_links_'.$ext_links[$i][form].'_text'] = array(
154
	    '#type' => 'textfield',
155
	    '#title' => t($ext_links[$i][text_title]),
156
	    '#default_value' => variable_get('ext_links_'.$ext_links[$i][form].'_text', $ext_links_default[$ext_links[$i][form]][text_default_value]),
157
	    '#size' => 70,
158
	    '#maxlength' => 255,
159
	    '#description' => t($ext_links[$i][text_description])
160
	  );
161
	}
162
  return system_settings_form($form);
163
} // function ext_links_admin()
164

    
165
function ext_links_perm() {
166

    
167
	return array('access extlinks content', 'administer extlinks');
168

    
169
} // function onthisdate_perm
170

    
171
/**
172
* Implementation of hook_menu().
173
*/
174
function ext_links_menu() {
175

    
176
	// default values for the external links defined as global variables
177
 	global $ext_links_default;
178
	$ext_links_default["gbif"] = array(
179
		'link_default_value' => 'http://data.gbif.org/species/',
180
		'text_default_value' => 'Search GBIF...',
181
 	); 
182
	$ext_links_default["biocase"] = array(
183
 		'link_default_value' => 'http://search.biocase.org/edit/search/units/simpleSearch/query1?unitName=',
184
		'text_default_value' => 'Search BioCASE...',
185
 	); 
186
 	$ext_links_default["nybg"] = array(
187
 		'link_default_value' => 'http://rbg-web2.rbge.org.uk/cgi-bin/nph-readbtree.pl/dataset=NYBG/filename=names3/firstval=1/multiaddr=/multiform=multisite3.php?ETI=',
188
		'text_default_value' => 'Search NYBG...',
189
 	); 
190
	$ext_links_default["tropicos"] = array(
191
		'link_default_value' => 'http://www.tropicos.org/NameSearch.aspx?name=',
192
		'text_default_value' => 'Search Tropicos...',
193
	); 
194
 	$ext_links_default["ncbi"] = array(
195
		'link_default_value' => 'http://www.ncbi.nlm.nih.gov/gquery/gquery.fcgi?term=',
196
		'text_default_value' => 'Search NCBI...',
197
 		); 
198
 	$ext_links_default["google"] = array(
199
		'link_default_value' => 'http://images.google.com/images?q=',
200
		'text_default_value' => 'Search Google Images...',
201
 	); 
202
 	$ext_links_default["flickr"] = array(
203
		'link_default_value' => 'http://www.flickr.com/search/?w=all&q=',
204
		'text_default_value' => 'Search flickr...',
205
 	); 
206
 	$ext_links_default["scholar"] = array(
207
		'link_default_value' => 'http://scholar.google.de/scholar?hl=de&btnG=Suche&lr=&as_ylo=&as_vis=0&q=',
208
		'text_default_value' => 'Search Google scholar...',
209
 	); 
210
 	$ext_links_default["bhl"] = array(
211
		'link_default_value' => 'http://www.biodiversitylibrary.org/Search.aspx?searchCat=&searchTerm=',
212
		'text_default_value' => 'Search BHL...',
213
 	); 
214
 	
215
	$items = array();
216

    
217
  $items[] = array(
218
    'path' => 'admin/settings/extlinks',
219
    'title' => t('External links'),
220
    'description' => t('Description of your External links'),
221
    'callback' => 'drupal_get_form',
222
    'callback arguments' => 'ext_links_admin',
223
    'access' => user_access('access administration pages'),
224
    'type' => MENU_NORMAL_ITEM,
225
   );
226

    
227
  return $items;
228
} // function ext_links_menu()
229

    
230
/**
231
 * returns the genus and the first epithet from the object taxon
232
 * @param $taxon
233
 * @return unknown_type
234
 */
235
function getSpeciesName($taxon){
236
	$speciesName = array();
237
	$i = 0;
238
	while(isset($taxon->name->taggedName[$i]) && !$speciesName[species]){
239
		if($taxon->name->taggedName[$i]->type == "name"){
240
			if(!isset($speciesName[genus]))
241
				$speciesName[genus] = $taxon->name->taggedName[$i]->text;
242
			else
243
				$speciesName[species] = $taxon->name->taggedName[$i]->text;
244
		}
245
		$i++;
246
	}
247
	return $speciesName;
248
}
249
/**
250
 * Generate the HTML text for the ext_link login block
251
 * @param op the operation from the URL
252
 * @param delta offset
253
 * @returns block HTML 
254
 */
255
function ext_links_block($op='list', $delta=0) {
256
  // listing of blocks, such as on the admin/block page
257
	global $ext_links_default;
258
	
259
   if ($op == "list"){
260
    	$block[0]["info"] = t("External Taxon Links");
261
		return $block;
262
   } else if ($op == 'view') {
263
      switch($delta){
264
        case 0:
265
        		if (arg(0)=="cdm_dataportal" && arg(1)=="taxon" && arg(2)!== 0){
266
        			$uuid = arg(2);
267
        		    $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
268
        		    //var_dump($taxon);
269
        		    //$taxon->titleCache;
270
        		    //var_export()
271
        		    if($taxon){
272
          		    	drupal_add_js(drupal_get_path('module', 'ext_links') . '/ext_links.js');
273
        		    	$speciesName = getSpeciesName($taxon);
274
          		    	$genus = $taxon->name->taggedName[0]->text;
275
          		    	$species = $taxon->name->taggedName[1]->text;
276
          		    	$block_content = '';
277
          		    	if(variable_get('ext_links_gbif_check', true)) {
278
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_gbif_link', $ext_links_default[gbif][link_default_value]).$speciesName[genus].variable_get('ext_links_gbif_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_gbif_text', $ext_links_default[gbif][text_default_value]).'</a><br />';
279
          		    	}
280
          		    	if(variable_get('ext_links_biocase_check', 1)) {
281
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_biocase_link', $ext_links_default[biocase][link_default_value]).$speciesName[genus].variable_get('ext_links_biocase_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_biocase_text', $ext_links_default[biocase][text_default_value]).'</a><br />';
282
          		    	}
283
          		    	if(variable_get('ext_links_nybg_check', 1)) {
284
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_nybg_link', $ext_links_default[nybg][link_default_value]).$speciesName[genus].variable_get('ext_links_nybg_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_nybg_text', $ext_links_default[nybg][text_default_value]).'</a><br />';
285
          		    	}
286
          		    	if(variable_get('ext_links_tropicos_check', 1)) {
287
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_tropicos_link', $ext_links_default[tropicos][link_default_value]).$speciesName[genus].variable_get('ext_links_tropicos_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_tropicos_text', $ext_links_default[tropicos][text_default_value]).'</a><br />';
288
          		    	}
289
          		    	if(variable_get('ext_links_ncbi_check', 1)) {
290
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_ncbi_link', $ext_links_default[ncbi][link_default_value]).$speciesName[genus].variable_get('ext_links_ncbi_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_ncbi_text', $ext_links_default[ncbi][text_default_value]).'</a><br />';
291
          		    	}
292
          		    	if(variable_get('ext_links_google_check', 1)) {
293
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_google_link', $ext_links_default[google][link_default_value]).$speciesName[genus].variable_get('ext_links_google_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_google_text', $ext_links_default[google][text_default_value]).'</a><br />';
294
          		    	}
295
          		    	if(variable_get('ext_links_flickr_check', 1)) {
296
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_flickr_link', $ext_links_default[flickr][link_default_value]).$speciesName[genus].variable_get('ext_links_flickr_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_flickr_text', $ext_links_default[flickr][text_default_value]).'</a><br />';
297
          		    	}
298
          		    	if(variable_get('ext_links_scholar_check', 1)) {
299
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_scholar_link', $ext_links_default[scholar][link_default_value]).$speciesName[genus].variable_get('ext_links_scholar_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_scholar_text', $ext_links_default[scholar][text_default_value]).'</a><br />';
300
          		    	}
301
          		    	if(variable_get('ext_links_bhl_check', 1)) {
302
          		    		$block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_bhl_link', $ext_links_default[bhl][link_default_value]).$speciesName[genus].variable_get('ext_links_bhl_concat', ' ').$speciesName[species].'\')">'.variable_get('ext_links_bhl_text', $ext_links_default[bhl][text_default_value]).'</a><br />';
303
          		    	}
304
          			    $block['subject'] = 'External links';
305
          			    $block['content'] = $block_content;
306
	       				
307
          			    return $block;
308
  		          } // if taxon
309
  	  	} // if path
310
      } // switch 
311
    } // op ?
312
} // function ext_link_block()
313

    
314

    
315

    
316

    
317
// include the admin form if it really want to use
318
//if (arg(0) === 'admin' AND arg(1) === 'user' AND arg(2) === 'ext_link') {
319
//  include_once('ext_link_admin.inc');
320
//}
(3-3/3)