コード例 #1
0
 public function Get($pa_additional_query_params = null, $pa_options = null)
 {
     global $g_ui_locale_id;
     $vn_max = $this->request->getParameter('maxRows', pInteger) ? $this->request->getParameter('maxRows', pInteger) : 20;
     $ps_query = $this->request->getParameter('term', pString);
     $ps_gn_elements = urldecode($this->request->getParameter('gnElements', pString));
     $ps_gn_delimiter = urldecode($this->request->getParameter('gnDelimiter', pString));
     $pa_elements = explode(',', $ps_gn_elements);
     $vo_conf = Configuration::load();
     $vs_user = trim($vo_conf->get("geonames_user"));
     $va_items = array();
     if (unicode_strlen($ps_query) >= 3) {
         $vs_base = $vo_conf->get('geonames_api_base_url') . '/search';
         $t_locale = new ca_locales($g_ui_locale_id);
         $vs_lang = $t_locale->get("language");
         $va_params = array("q" => $ps_query, "lang" => $vs_lang, 'style' => 'full', 'username' => $vs_user, 'maxRows' => $vn_max);
         $vs_query_string = '';
         foreach ($va_params as $vs_key => $vs_value) {
             $vs_query_string .= "{$vs_key}=" . urlencode($vs_value) . "&";
         }
         try {
             $vs_xml = caQueryExternalWebservice("{$vs_base}?{$vs_query_string}");
             $vo_xml = new SimpleXMLElement($vs_xml);
             $va_attr = $vo_xml->status ? $vo_xml->status->attributes() : null;
             if ($va_attr && isset($va_attr['value']) && (int) $va_attr['value'] > 0) {
                 $va_items[0] = array('displayname' => _t('Connection to GeoNames with username "%1" was rejected with the message "%2". Check your configuration and make sure your GeoNames.org account is enabled for web services.', $vs_user, $va_attr['message']), 'lat' => '', 'lng' => '');
                 $va_items[0]['label'] = $va_items[0]['displayname'];
             } else {
                 foreach ($vo_xml->children() as $vo_child) {
                     if ($vo_child->getName() == "geoname") {
                         $va_elements = array();
                         foreach ($pa_elements as $ps_element) {
                             $vs_val = $vo_child->{trim($ps_element)};
                             if (strlen(trim($vs_val)) > 0) {
                                 $va_elements[] = trim($vs_val);
                             }
                         }
                         $va_items[(string) $vo_child->geonameId] = array('displayname' => $vo_child->name, 'label' => join($ps_gn_delimiter, $va_elements) . ($vo_child->lat ? " [" . $vo_child->lat . "," : '') . ($vo_child->lng ? $vo_child->lng . "]" : ''), 'lat' => $vo_child->lat ? $vo_child->lat : null, 'lng' => $vo_child->lng ? $vo_child->lng : null, 'id' => (string) $vo_child->geonameId);
                     }
                 }
             }
         } catch (Exception $e) {
             $va_items[0] = array('displayname' => _t('Could not connect to GeoNames'), 'lat' => '', 'lng' => '', 'id' => 0);
             $va_items[0]['label'] = $va_items[0]['displayname'];
         }
     }
     $this->view->setVar('geonames_list', $va_items);
     return $this->render('ajax_geonames_list_html.php');
 }
コード例 #2
0
 public function testBasicQuery()
 {
     $vs_voc_query = '&q=' . rawurlencode('cs:http://id.loc.gov/authorities/subjects');
     $vs_url = 'http://id.loc.gov/search/?q=' . urlencode('"bowl"') . $vs_voc_query . '&format=atom&count=150';
     $vs_data = caQueryExternalWebservice($vs_url);
     $this->assertInternalType('string', $vs_data);
     $this->assertGreaterThan(0, strlen($vs_data));
     $o_xml = @simplexml_load_string($vs_data);
     $this->assertInternalType('object', $o_xml);
     $this->assertTrue($o_xml instanceof SimpleXMLElement);
     $o_entries = $o_xml->{'entry'};
     $this->assertTrue($o_entries instanceof SimpleXMLElement);
     $this->assertGreaterThan(65, sizeof($o_entries));
     // there were 67 on 11/4/2015
 }
コード例 #3
0
 public function Get($pa_additional_query_params = null, $pa_options = null)
 {
     if (!($ps_query = $this->request->getParameter('q', pString))) {
         $ps_query = $this->request->getParameter('term', pString);
     }
     $ps_type = $this->request->getParameter('type', pString);
     $va_vocs = array();
     $vs_voc_query = '';
     if ($vn_element_id = $this->request->getParameter('element_id', pInteger)) {
         $t_element = new ca_metadata_elements($vn_element_id);
         if ($vs_voc = $t_element->getSetting('vocabulary')) {
             $vs_voc_query .= '&q=' . rawurlencode($vs_voc);
         }
     }
     $vo_conf = Configuration::load();
     $va_items = array();
     if (unicode_strlen($ps_query) >= 3) {
         try {
             $vs_data = caQueryExternalWebservice('http://id.loc.gov/search/?q=' . urlencode('"' . $ps_query . '"') . $vs_voc_query . '&format=atom&count=150');
             if ($vs_data) {
                 $o_xml = @simplexml_load_string($vs_data);
                 if ($o_xml) {
                     $o_entries = $o_xml->{'entry'};
                     if ($o_entries && sizeof($o_entries)) {
                         foreach ($o_entries as $o_entry) {
                             $o_links = $o_entry->{'link'};
                             $va_attr = $o_links[0]->attributes();
                             $vs_url = (string) $va_attr->{'href'};
                             $va_items[] = array('label' => (string) $o_entry->{'title'}, 'idno' => (string) $o_entry->{'id'}, 'url' => $vs_url);
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $va_items['error'] = array('displayname' => _t('ERROR') . ':' . $e->getMessage(), 'idno' => '');
         }
     }
     $this->view->setVar('lcsh_list', $va_items);
     return $this->render('ajax_lcsh_list_html.php');
 }
コード例 #4
0
 public function getExtraInfo($pa_settings, $ps_url)
 {
     $vs_lang = caGetOption('lang', $pa_settings, 'en');
     // readable version of get parameters
     $va_get_params = array('action' => 'query', 'titles' => self::getPageTitleFromURI($ps_url), 'prop' => 'pageimages|info|extracts', 'inprop' => 'url', 'piprop' => 'name|thumbnail', 'pithumbsize' => '200px', 'format' => 'json');
     $vs_content = caQueryExternalWebservice('https://' . $vs_lang . '.wikipedia.org/w/api.php?' . caConcatGetParams($va_get_params));
     $va_content = @json_decode($vs_content, true);
     if (!is_array($va_content) || !isset($va_content['query']['pages'])) {
         return array();
     }
     // the top two levels are 'query' and 'pages'
     $va_results = $va_content['query']['pages'];
     if (sizeof($va_results) > 1) {
         Debug::msg('[Wikipedia] Found multiple results for page title ' . self::getPageTitleFromURI($ps_url));
     }
     if (sizeof($va_results) == 0) {
         Debug::msg('[Wikipedia] Couldnt find any results for page title ' . self::getPageTitleFromURI($ps_url));
         return null;
     }
     $va_result = array_shift($va_results);
     // try to extract the first paragraph (usually an abstract/summary of the article)
     $vs_abstract = preg_replace("/\\s+<p><\\/p>\\s+<h2>.+\$/ms", "", $va_result['extract']);
     return array('image_thumbnail' => $va_result['thumbnail']['source'], 'image_thumbnail_width' => $va_result['thumbnail']['width'], 'image_thumbnail_height' => $va_result['thumbnail']['height'], 'image_viewer_url' => $va_result['fullurl'] . '#/media/File:' . $va_result['pageimage'], 'title' => $va_result['title'], 'pageid' => $va_result['page_id'], 'fullurl' => $va_result['fullurl'], 'canonicalurl' => $va_result['canonicalurl'], 'extract' => $va_result['extract'], 'abstract' => $vs_abstract);
 }
コード例 #5
0
ファイル: uBio.php プロジェクト: idiscussforum/providence
 /** 
  * Fetch details about a specific item from a uBio-based data service
  *
  * @param array $pa_settings Plugin settings values
  * @param string $ps_url The URL originally returned by the data service uniquely identifying the item
  * @return array An array of data from the data server defining the item.
  */
 public function getExtendedInformation($pa_settings, $ps_url)
 {
     if (!($vs_ubio_keycode = caGetOption('keyCode', $pa_settings, null))) {
         $o_config = Configuration::load();
         $vs_ubio_keycode = $o_config->get('ubio_keycode');
     }
     $vs_result = caQueryExternalWebservice("{$ps_url}&keyCode={$vs_ubio_keycode}");
     if (!$vs_result) {
         return array();
     }
     $va_info_fields = array();
     $o_xml = simplexml_load_string($vs_result);
     if ($vs_id = (string) $o_xml->{'namebankID'}) {
         $va_info_fields['namebankID'] = $vs_id;
         $va_info_fields['Detail page'] = "http://www.ubio.org/browser/details.php?namebankID=" . $vs_id;
     }
     if ($o_xml->{'fullNameString'}) {
         $va_info_fields['Full name'] = base64_decode($o_xml->{'fullNameString'});
     }
     if ($o_xml->{'packageName'}) {
         $va_info_fields['Package name'] = $o_xml->{'packageName'};
     }
     if (strlen($vs_extinct = trim((string) $o_xml->{'extinctFlag'}))) {
         $vs_extinct = $vs_extinct == '0' ? _t("No") : _t("Yes");
         $va_info_fields['extinct?'] = $vs_extinct;
     }
     if ($o_xml->{'rankName'}) {
         $va_info_fields['Rank name'] = $o_xml->{'rankName'};
     }
     if ($o_xml->{'languageName'}) {
         $va_info_fields['Language name'] = $o_xml->{'languageName'};
     }
     $va_homotypic_synonyms = array();
     if ($o_xml->{'homotypicSynonyms'}) {
         foreach ($o_xml->{'homotypicSynonyms'}->{'value'} as $vo_value) {
             if ($vo_value->{'fullNameString'}) {
                 $va_homotypic_synonyms[] = base64_decode((string) $vo_value->{'fullNameString'});
             }
         }
     }
     if (sizeof($va_homotypic_synonyms)) {
         $va_info_fields['Homotypic synonyms'] = join('; ', $va_homotypic_synonyms);
     }
     $vs_display = '';
     foreach ($va_info_fields as $vs_fld => $vs_val) {
         $vs_display .= "<b>{$vs_fld}</b>: " . htmlentities($vs_val) . "<br />\n";
     }
     return array('display' => $vs_display);
 }
コード例 #6
0
 public function Get($pa_additional_query_params = null, $pa_options = null)
 {
     $ps_query = trim($this->request->getParameter('term', pString));
     $vo_conf = Configuration::load();
     $va_items = array();
     if (unicode_strlen($ps_query) >= 3) {
         try {
             /* // ITIS
             			$i = 0;
             			$vo_doc = new DOMDocument();
             			//$t = new Timer();
             			$vs_result = @file_get_contents("http://www.itis.gov/ITISWebService/services/ITISService/searchForAnyMatch?srchKey={$ps_query}",0,$vo_ctx);
             			//file_put_contents("/tmp/times", "ITIS: {$t->getTime(2)}\n", FILE_APPEND);
             			if(strlen($vs_result)>0){
             				$vo_doc->loadXML($vs_result);
             				$vo_resultlist = $vo_doc->getElementsByTagName("anyMatchList");
             				foreach($vo_resultlist as $vo_result){
             					$vs_cn = $vs_sn = $vs_id = "";
             					foreach($vo_result->childNodes as $vo_field){
             						switch($vo_field->nodeName){
             							case "ax23:commonNameList":
             								foreach($vo_field->childNodes as $vo_cns){
             									if($vo_cns->nodeName == "ax23:commonNames"){
             										foreach($vo_cns->childNodes as $vo_cn){
             											if($vo_cn->nodeName == "ax23:commonName"){
             												$vs_cn = $vo_cn->textContent;
             											}
             										}
             									}
             								}
             								break;
             							case "ax23:tsn":
             								$vs_id = $vo_field->textContent;
             								break;
             							case "ax23:sciName":
             								$vs_sn = $vo_field->textContent;
             								break;
             							default:
             								break;
             						}
             					}
             					if(strlen($vs_id)>0){
             						$va_items["itis".$vs_id] = array(
             							"idno" => "ITIS:{$vs_id}",
             							"common_name" => $vs_cn,
             							"sci_name" => $vs_sn
             						);
             						if(++$i == 50){ // let's limit to 50 results, right?
             							break;
             						}
             					}
             				}
             			} else {
             				$va_items['error_itis'] = array(
             					'msg' => _t('ERROR: ITIS web service query failed.'),
             				);
             			}*/
             // uBio
             $vo_conf = new Configuration();
             $vs_ubio_keycode = trim($vo_conf->get("ubio_keycode"));
             if (strlen($vs_ubio_keycode) > 0) {
                 $vs_url = "http://www.ubio.org/webservices/service.php?function=namebank_search&searchName={$ps_query}&sci=1&vern=1&keyCode={$vs_ubio_keycode}";
                 $vs_result = caQueryExternalWebservice($vs_url);
                 $vo_doc = new DOMDocument();
                 if (strlen($vs_result) > 0) {
                     $vo_doc->loadXML($vs_result);
                     $vo_resultlist = $vo_doc->getElementsByTagName("value");
                     $i = 0;
                     if ($vo_resultlist->length > 0) {
                         foreach ($vo_resultlist as $vo_result) {
                             $vs_name = $vs_id = $vs_package = $vs_cn = "";
                             if ($vo_result->parentNode->nodeName == "scientificNames") {
                                 foreach ($vo_result->childNodes as $vo_field) {
                                     switch ($vo_field->nodeName) {
                                         case "nameString":
                                             $vs_name = base64_decode($vo_field->textContent);
                                             break;
                                         case "namebankID":
                                             $vs_id = $vo_field->textContent;
                                             break;
                                         case "packageName":
                                             $vs_package = $vo_field->textContent;
                                             break;
                                         default:
                                             break;
                                     }
                                 }
                             } elseif ($vo_result->parentNode->nodeName == "vernacularNames") {
                                 foreach ($vo_result->childNodes as $vo_field) {
                                     switch ($vo_field->nodeName) {
                                         case "fullNameStringLink":
                                             $vs_name = base64_decode($vo_field->textContent);
                                             break;
                                         case "namebankIDLink":
                                             $vs_id = $vo_field->textContent;
                                             break;
                                         case "packageName":
                                             $vs_package = $vo_field->textContent;
                                             break;
                                         case "nameString":
                                             $vs_cn = base64_decode($vo_field->textContent);
                                             break;
                                         default:
                                             break;
                                     }
                                 }
                             }
                             if (strlen($vs_name) > 0 && strlen($vs_id) > 0) {
                                 $va_items["ubio{$vs_id}"] = array("id" => "uBio:{$vs_id}", "idno" => "uBio:{$vs_id}", "sci_name" => $vs_name . (strlen($vs_package) > 0 ? " ({$vs_package}) " : ""), "common_name" => $vs_cn);
                                 $va_items["ubio{$vs_id}"]['label'] = $va_items["ubio{$vs_id}"]['sci_name'] . ($vs_cn ? " ({$vs_cn})" : "") . " [uBio:{$vs_id}]";
                                 if (++$i == 100) {
                                     // let's limit to 100 results, right?
                                     break;
                                 }
                             }
                         }
                     } else {
                         if ($vo_errors = $vo_doc->getElementsByTagName('error')) {
                             $vs_err = '';
                             foreach ($vo_errors as $vo_result) {
                                 if ($vo_result->textContent) {
                                     $vs_err .= $vo_result->textContent;
                                 }
                             }
                             $va_items['error_ubio'] = array('label' => $vs_err, 'id' => null);
                         } else {
                             $va_items['error_ubio'] = array('label' => _t('No results found for %1.', $ps_query), 'id' => null);
                         }
                     }
                 } else {
                     $va_items['error_ubio'] = array('label' => _t('ERROR: uBio web service query failed.'), 'id' => null);
                 }
             } else {
                 $va_items['error_ubio'] = array('label' => _t('ERROR: No uBio keycode in app.conf.'), 'id' => null);
             }
         } catch (Exception $e) {
             $va_items['error'] = array('label' => _t('ERROR') . ':' . $e->getMessage(), 'id' => null);
         }
     }
     $this->view->setVar('taxonomy_list', $va_items);
     return $this->render('ajax_taxonomy_list_html.php');
 }