示例#1
0
 public function generate_record($id, $result)
 {
     // Well... really generate some record.
     $record = new MsRecord($this);
     $record->set_data('msdb_generator_id', $id);
     // just for debugging
     $record->set_data('pdb_id', $result->abstract_records[$id]);
     // generate the neccessary data on the fly
     $name = $this->soap_client->call('getPrimaryCitationTitle', array('in0' => $result->abstract_records[$id]));
     $record->set_data('name', $name);
     return $record;
 }
 /**
  * The standarized way to print out redcords. This should
  * RETURN the string to print out.
  */
 public function print_record(MsRecord $record)
 {
     global $msConfiguration;
     $tmpl = $this->record_template;
     if ($record->get_type()) {
         $tmpl .= '-' . $record->get_type();
     }
     return wfMsgData($tmpl, $record->data);
     /*
     $tmpl = wfMsg($this->record_template);
     if($tmpl == '<'.$this->record_template.'>') { # the output when there's no such page
     	print $this->record_template." does not exist.<p>";
     	$tmpl = wgMsg($msConfiguration['default-record-message']);
     }
     $ret = strtr($tmpl, $record->data);
     return $ret;
     */
 }
 function fetch($query)
 {
     $fetch_url = str_replace('$1', urlencode($query->keyword), self::$url);
     $page = file_get_contents($fetch_url);
     if (!$page) {
         throw MWException('Performing viral zone search failed');
     }
     // typische Eintraege haben so einen Form:
     // alles ohne Leerzeichen!
     /*
     	<h4 class="column_name">VIRUSNAME <small>[SHORTFORM]</small></h4>
     	<div class="column_hr"><div class="context">
     	<a href="/viralzone/all_by_species/236.html">dsDNA (baltimore)</a><br />
     	<a href="/viralzone/all_by_species/176.html">Herpesviridae (family)</a><br />
     	<a href="/viralzone/all_by_species/526.html">Macavirus (genus)</a><br /></div></div>
     */
     // Let's get the genus... don't know if thats right ;-)
     if (!preg_match_all(self::$parser, strstr($page, 'h3'), $matches, PREG_SET_ORDER)) {
         // no matches... so let's check wether we got anything
         if (preg_match('/NO VIRUS FOUND/i', $page)) {
             // return... an empty record array.
             return array();
         } else {
             // the parsing seems to be broken
             throw new MWException('Regex on viral zone output did not match!');
         }
     }
     // Don't need to much memory -- delete page
     unset($page);
     // We'll have pretty much matchings. Parse them
     $records = array();
     // MsRecord array // wanted format: virusname => array(link label=>full link url)
     $latest_record = false;
     // will hold the latest record
     #var_dump($matches); exit(0);
     foreach ($matches as $entry) {
         // since the regex always contains all parentheses, [1] is only
         // filled when we have matched a h4, starting a new record.
         if (strlen($entry[1])) {
             #print("Adding new record; $entry[1].\n");
             if ($latest_record) {
                 $records[] = $latest_record;
             }
             $latest_record = new MsRecord($this);
             $latest_record->set_data('name', $entry[1]);
             # fill fields stupidly with default values:
             $latest_record->set_data('baltimore_link', '');
             $latest_record->set_data('family_link', '');
             $latest_record->set_data('genus_link', '');
             $latest_record->set_data('baltimore', "''Baltimore nicht angegeben''");
             $latest_record->set_data('family', "''Familie nicht angegeben''");
             $latest_record->set_data('genus', "''Genus nicht angegeben''");
             #$latest_virus = $entry[1];
             #$records[$latest_virus] = array();
         } else {
             #print("Found nice other information concerning $entry[4]\n");
             # something like 'family' => 'Herpesviridae'
             $latest_record->set_data($entry[4], $entry[3]);
             # and something like 'family_link' => '/viralzone/all_by_species/...'
             $latest_record->set_data($entry[4] . '_link', self::$domain . $entry[2]);
         }
         #flush();
     }
     # and for the very last item:
     if ($latest_record) {
         $records[] = $latest_record;
     }
     #		print "These are the records:<pre>"; var_dump($records);
     # create "best links" for each record:
     /*foreach($records as $record) {
     			if($record->get_data('genus'))
     				$record->set_data('link', $record->get_data('genus_link'));
     			else if($record->get_data('family'))
     				$record->set_data('link', $record->get_data('family_link'));
     			else if($record->get_data('baltimore'))
     				$record->set_data('link', $record->get_data('baltimore_link'));
     			else	$record->set_data('link', 'http://www.google.dei);
     		}*/
     return $records;
 }