Documentation here.'; // Function that will handle the wizard-like behaviour function dispatch() { if (empty ($_GET['step'])) $step = 0; else $step = (int) $_GET['step']; // load the header $this->header(); switch ($step) { case 0 : $this->greet(); break; case 1 : $this->iii_start(); break; case 2: $this->iii_getrecords(); break; case 3: $this->ktnxbye(); break; } // load the footer $this->footer(); } function header() { echo '
'; echo '

'.__('Scriblio III Importer').'

'; } function footer() { echo '
'; } function greet() { echo '
'; echo '

'.__('Howdy! Start here to import records from a Innovative Interfaces (III) ILS system into Scriblio.').'

'; echo '

'.__('This has not been tested much. Mileage may vary.').'

'; echo '
'; echo '

'; echo '
'; if(!function_exists('mb_convert_encoding')){ echo '

'; echo '

'.__('This PHP install does not support multibyte string functions, including mb_convert_encoding. Without that function, this importer can't convert the character encoding from records in the ILS into UTF-8. Accented characters will likely not import correctly.').'

'; } echo '

'; echo '
'; echo '

or jump immediately to
'. __('(goes to default Scriblio importer)').'

'; echo '
'; echo '
'; } function ktnxbye() { echo '
'; echo '

'.__('All done.').'

'; echo '
'; } function iii_start(){ $prefs = get_option('scrib_iiiimporter'); $temp['scrib_iii-sourceprefix'] = $prefs['scrib_iii-sourceprefix']; $temp['scrib_iii-sourceinnopac'] = $prefs['scrib_iii-sourceinnopac']; $temp['scrib_iii-warnings'] = array(); $temp['scrib_iii-errors'] = array(); $temp['scrib_iii-record_start'] = $prefs['scrib_iii-record_start']; $temp['scrib_iii-record_end'] = ''; $temp['scrib_iii-records_harvested'] = 0; update_option('scrib_iiiimporter', $temp); $this->iii_options(); } function iii_options(){ $prefs = get_option('scrib_iiiimporter'); echo '
'; echo '

'.__('All Scriblio records have a 'sourceid,' a unique alphanumeric string that's used to avoid creating duplicate records and, in some installations, link back to the source system for current availability information.').'

'; echo '

'.__('The sourceid is made up of two parts: the prefix that you assign, and the bib number from the Innopac. Theoretically, you chould gather records from 1,296 different systems, it's a big world.').'

'; echo '
'; ?>


'; echo '
'; echo '
'; } function iii_getrecords(){ if(empty($_POST['scrib_iii-sourceprefix']) || empty($_POST['scrib_iii-sourceinnopac']) || empty($_POST['scrib_iii-record_start'])){ echo '

'.__('Sorry, there has been an error.').'

'; echo '

Please complete all fields

'; return; } // save these settings so we can try them again later $prefs = get_option('scrib_iiiimporter'); $prefs['scrib_iii-sourceprefix'] = strtolower(ereg_replace('[^a-z|A-Z|0-9]', '', $_POST['scrib_iii-sourceprefix'])); stripslashes($_POST['scrib_iii-sourceprefix']); $prefs['scrib_iii-sourceinnopac'] = ereg_replace('[^a-z|A-Z|0-9|-|\.]', '', $_POST['scrib_iii-sourceinnopac']); $prefs['scrib_iii-record_start'] = (int) $_POST['scrib_iii-record_start']; $prefs['scrib_iii-record_end'] = (int) $_POST['scrib_iii-record_end']; update_option('scrib_iiiimporter', $prefs); $interval = 50; if(!$prefs['scrib_iii-record_end'] || ($prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start'] < $interval)) $interval = $prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start']; if($prefs['scrib_iii-record_end'] - $prefs['scrib_iii-record_start'] < 1) $interval = 1; ini_set('memory_limit', '1024M'); set_time_limit(0); ignore_user_abort(TRUE); error_reporting(E_ERROR); if(!empty($_POST['scrib_iii-debug'])){ $host = $prefs['scrib_iii-sourceinnopac']; $bibn = (int) $prefs['scrib_iii-record_start']; echo '

The III Record:

';			
			echo $this->iii_get_record($host, $bibn);
			echo '

The Tags and Display Record:

';

			$test_pancake = $this->iii_parse_record($this->iii_get_record($host, $bibn), $bibn);
			print_r($test_pancake);
			echo '
'; echo '

The Raw Excerpt:

'. $test_pancake['the_excerpt'] .'

'; echo '

The Raw Content:

'. $test_pancake['the_content'] .'

'; echo '

The SourceID: '. $test_pancake['the_sourceid'] .'

'; // bring back that form echo '

'.__('III Options').'

'; $this->iii_options(); }else{ // import with status $host = ereg_replace('[^a-z|A-Z|0-9|-|\.]', '', $_POST['scrib_iii-sourceinnopac']); $count = 0; echo "

Reading $interval records from {$prefs['scrib_iii-sourceinnopac']}. Please be patient.

"; echo '
    '; for($bibn = $prefs['scrib_iii-record_start'] ; $bibn <= ($prefs['scrib_iii-record_start'] + $interval) ; $bibn++ ){ if($record = $this->iii_get_record( $host , $bibn )){ $bibr = $this->iii_parse_record( $record , $bibn ); echo "
  1. {$bibr['the_title']} {$bibr['the_sourceid']}
  2. "; $count++; } } echo '
'; $prefs['scrib_iii-warnings'] = array_merge($prefs['scrib_iii-warnings'], $this->warn); $prefs['scrib_iii-errors'] = array_merge($prefs['scrib_iii-errors'], $this->error); $prefs['scrib_iii-records_harvested'] = $prefs['scrib_iii-records_harvested'] + $count; update_option('scrib_iiiimporter', $prefs); if($bibn < $prefs['scrib_iii-record_end']){ $prefs['scrib_iii-record_start'] = $prefs['scrib_iii-record_start'] + $interval; update_option('scrib_iiiimporter', $prefs); $this->iii_options(); ?>

iii_done(); ?> warn = 'Record number '. $bibn .' is suppressed or deleted.'; return(FALSE); } $recordurl = 'http://'. $host .'/search/.b'. $bibn .'/.b'. $bibn .'/1%2C1%2C1%2CB/marc~b'. $bibn; if(function_exists('mb_convert_encoding')) $record = mb_convert_encoding(file_get_contents($recordurl), 'UTF-8'); else $record = file_get_contents($recordurl); if(!empty($record)){ preg_match('/
([^<]*)/', $record, $stuff);
			return($stuff[1]);
		}
		$this->error = 'Host unreachable or no parsable data found for record number '. $bibn .'.';
		return(FALSE);
	}

	function iii_done(){
		$prefs = get_option('scrib_iiiimporter');

		// click next
		echo '
'; if(count($prefs['scrib_iii-warnings'])){ echo '

Warnings

'; echo 'bottom · errors'; echo '
  1. '; echo implode($prefs['scrib_iii-warnings'], '
  2. '); echo '
'; } if(count($prefs['scrib_iii-errors'])){ echo '

Errors

'; echo 'bottom · warnings'; echo '
  1. '; echo implode($prefs['scrib_iii-errors'], '
  2. '); echo '
'; } echo '

'.__('Processing complete.').'

'; echo '

'. $prefs['scrib_iii-records_harvested'] .' '.__('records harvested.').' with '. count($prefs['scrib_iii-warnings']) .' warnings and '. count($prefs['scrib_iii-errors']) .' errors.

'; echo '

'.__('Continue to the next step to publish those harvested catalog entries.').'

'; echo '
'; echo '


'. __('(goes to default Scriblio importer)').'

'; echo '
'; echo '
'; } function iii_parse_row($lineray){ $marcrow = array(); unset($lineray[0]); foreach($lineray as $element){ $count[$element{0}]++; $elementname = $element{0}.$count[$element{0}]; $marcrow[$elementname] = trim(str_replace(' ', ' ', substr($element, 1))); } return($marcrow); } function iii_parse_record($marcrecord, $bibn){ global $scrib_import; $atomic = array(); $marcrecord = str_replace("\n ", ' ', $marcrecord); $details = explode("\n", $marcrecord); array_pop($details); array_shift($details); $details[0] = str_replace('LEADER ', '000 ', $details[0]); foreach($details as $line){ unset($lineray); unset($marc); $line = trim($line); $lineray = substr($line, 0, 3) . '|' . substr($line, 4, 2) . '|a' . substr($line, 7); $lineray = explode('|', ereg_replace('\.$', '', $lineray)); unset($lineray[1]); // Authors if(($lineray[0] == 100) || ($lineray[0] == 110)){ $marc = $this->iii_parse_row($lineray); $temp = ereg_replace(',$', '', $marc['a1'] .' '. $marc['d1']); $atomic['author'][] = $temp; }else if($lineray[0] == 110){ $marc = $this->iii_parse_row($lineray); $temp = $marc['a1']; $atomic['author'][] = $temp; }else if(($lineray[0] > 699) && ($lineray[0] < 721)){ $marc = $this->iii_parse_row($lineray); $temp = ereg_replace(',$', '', $marc['a1'] .' '. $marc['d1']); $atomic['author'][] = $temp; //Standard Numbers }else if($lineray[0] == 10){ $marc = $this->iii_parse_row($lineray); $atomic['lccn'][] = ereg_replace('[^0-9]', '', $marc['a1']); }else if($lineray[0] == 20){ $marc = $this->iii_parse_row($lineray); $temp = trim($marc['a1']) . ' '; $temp = ereg_replace('[^0-9|x|X]', '', strtolower(substr($temp, 0, strpos($temp, ' ')))); $atomic['isbn'][] = $temp; }else if($lineray[0] == 22){ $marc = $this->iii_parse_row($lineray); $temp = trim($marc['a1']) . ' '; $temp = ereg_replace('[^0-9|x|X|\-]', '', strtolower(substr($temp, 0, strpos($temp, ' ')))); $atomic['issn'][] = $temp; //Titles }else if($lineray[0] == 245){ $marc = $this->iii_parse_row($lineray); $temp = ucwords(trim(ereg_replace('/$', '', $marc['a1']) .' '. trim(ereg_replace('/$', '', $marc['b1'])))); $atomic['title'][] = $temp; $atomic['attribution'][] = $marc['c1']; }else if($lineray[0] == 240){ $marc = $this->iii_parse_row($lineray); $temp = trim(ereg_replace('/$', '', $marc['a1'] .' '. $marc['b1'])); $atomic['alttitle'][] = $temp; }else if($lineray[0] == 246){ $marc = $this->iii_parse_row($lineray); $temp = trim(ereg_replace('/$', '', $marc['a1'] .' '. $marc['b1'])); $atomic['alttitle'][] = $temp; }else if(($lineray[0] > 719) && ($lineray[0] < 741)){ $marc = $this->iii_parse_row($lineray); $temp = $marc['a1']; $atomic['alttitle'][] = $marc['a1']; //Dates }else if($lineray[0] == 260){ $marc = $this->iii_parse_row($lineray); if($marc['c1']){ $temp = str_pad(substr(ereg_replace('[^0-9]', '', $marc['c1']), 0, 4), 4 , '5'); $atomic['pubyear'][] = $temp; } }else if($lineray[0] == 5){ $atomic['acqdate'][] = $line{7}.$line{8}.$line{9}.$line{10} .'-'. $line{11}.$line{12} .'-'. $line{13}.$line{14}; }else if($lineray[0] == 8){ $temp = intval(substr($line, 14, 4)); if($temp) $atomic['pubyear'][] = substr($line, 14, 4); //Subjects }else if(($lineray[0] > 599) && ($lineray[0] < 700)){ $marc = $this->iii_parse_row($lineray); $atomic['subject'][] = implode(' -- ', $marc); if($atomic['subjkey']){ $atomic['subjkey'] = array_unique(array_merge($atomic['subjkey'], array_values($marc))); }else{ $atomic['subjkey'] = array_values($marc); } //URLs }else if($lineray[0] == 856){ $marc = $this->iii_parse_row($lineray); unset($temp); $temp['href'] = $temp['title'] = str_replace(' ', '', $marc['u1']); $temp['title'] = trim(parse_url( $temp['href'] , PHP_URL_HOST), 'www.'); if($marc['31']) $temp['title'] = $marc['31']; if($marc['z1']) $temp['title'] = $marc['z1']; $atomic['url'][] = ''. $temp['title'] .''; //Notes }else if(($lineray[0] > 299) && ($lineray[0] < 400)){ $marc = $this->iii_parse_row($lineray); $atomic['physdesc'][] = implode(' ', array_values($marc)); }else if(($lineray[0] > 399) && ($lineray[0] < 500)){ $marc = $this->iii_parse_row($lineray); $atomic['title'][] = implode("\n", array_values($marc)); }else if(($lineray[0] > 799) && ($lineray[0] < 841)){ $marc = $this->iii_parse_row($lineray); $atomic['series'][] = implode("\n", array_values($marc)); }else if(($lineray[0] > 499) && ($lineray[0] < 600)){ $line = substr($line, 7); if($lineray[0] == 504) continue; if($lineray[0] == 505){ $atomic['contents'][] = str_replace(array('> ','> ','> '), '>', '
  • '. str_replace('--', "
  • \n
  • ", trim(str_replace(array(' ', ' ', ' '), ' ', $line))) .'
  • '); continue; } $atomic['notes'][] = str_replace(' ', ' ', $line); } //Format if((!$atomic['format']) && ($lineray[0] > 239) && ($lineray[0] < 246)){ $marc = $this->iii_parse_row($lineray); $temp = ucwords(strtolower(str_replace('[', '', str_replace(']', '', $marc['h1'])))); if(eregi('^book', $temp)){ $format = 'Book'; $formats = 'Books'; }else if(eregi('^micr', $temp)){ $format = 'Microform'; }else if(eregi('^electr', $temp)){ $format = 'Website'; $formats = 'Websites'; }else if(eregi('^vid', $temp)){ $format = 'Video'; }else if(eregi('^motion', $temp)){ $format = 'Video'; }else if(eregi('^audi', $temp)){ $format = 'Audio'; }else if(eregi('^cass', $temp)){ $format = 'Audio'; }else if(eregi('^phono', $temp)){ $format = 'Audio'; }else if(eregi('^record', $temp)){ $format = 'Audio'; }else if(eregi('^sound', $temp)){ $format = 'Audio'; }else if(eregi('^carto', $temp)){ $format = 'Map'; $formats = 'Maps'; }else if(eregi('^map', $temp)){ $format = 'Map'; $formats = 'Maps'; }else if(eregi('^globe', $temp)){ $format = 'Map'; $formats = 'Maps'; }else if($temp){ $format = 'Classroom Material'; //$format = $temp; } if(!$formats) $formats = $format; if($format){ $atomic['format'][] = $format; $atomic['formats'][] = $formats; } } if($lineray[0] == '008' && substr($lineray[2], 22,1) == 'p'){ $atomic['format'][] = 'Journal'; $atomic['formats'][] = 'Journals'; } } // end the big loop $atomic = array_filter($atomic); // Records without acqdates are reserves by course/professor // we _can_ import them, but they don't have enough info // to be findable or display well. if(!$atomic['acqdate'][0] && !$atomic['author'][0]){ $this->warn = 'Record number '. $bibn .' contains no catalog date or author info, skipped.'; return(FALSE); } if(count($details) < 4){ $this->warn = 'Record number '. $bibn .' has too little cataloging data, skipped.'; return(FALSE); } if(!$atomic['format'][0]){ $atomic['format'][0] = 'Book'; } if(empty($atomic['pubyear'][0])) $atomic['pubyear'][0] = substr($atomic['acqdate'][0],0,4); if($atomic['pubyear'][0]) $atomic['pubdate'] = $atomic['pubyear'][0].substr($atomic['acqdate'][0],4); if($atomic['alttitle']) $atomic['title'] = array_unique(array_merge($atomic['title'], $atomic['alttitle'])); $atomic['the_sourceid'] = substr(ereg_replace('[^a-z|0-9]', '', strtolower($_POST['scrib_iii-sourceprefix'])), 0, 2) . $bibn; if(!empty($atomic['title']) && !empty($atomic['the_sourceid'])){ $atomic['tags']['subj'] = $atomic['subjkey']; $atomic['tags']['auth'] = $atomic['author']; $atomic['tags']['isbn'] = $atomic['isbn']; $atomic['tags']['issn'] = $atomic['issn']; $atomic['tags']['title'] = $atomic['title']; $atomic['tags']['format'] = $atomic['format']; if($sweets = $scrib_import->get_sweets($atomic['isbn'])){ if(!empty($sweets['img'])); $atomic['img'] = $sweets['img']; if(!empty($sweets['summary'])){ $atomic['shortdescription'] = $sweets['summary']; } } $atomic['the_title'] = $atomic['title'][0]; $atomic['the_pubdate'] = $atomic['pubdate'][0]; $atomic['the_acqdate'] = $atomic['acqdate'][0]; $atomic['the_excerpt'] = $scrib_import->the_excerpt($atomic); $atomic['the_content'] = $scrib_import->the_content($atomic); $scrib_import->insert_harvest($atomic); return($atomic); }else{ $this->error = 'Record number '. $bibn .' couldn't be parsed.'; return(FALSE); } } // Default constructor function ScribIII_import() { // nothing } } // Instantiate and register the importer include_once(ABSPATH . 'wp-admin/includes/import.php'); if(function_exists('register_importer')) { $scribiii_import = new ScribIII_import(); register_importer($scribiii_import->importer_code, $scribiii_import->importer_name, $scribiii_import->importer_desc, array (&$scribiii_import, 'dispatch')); } add_action('activate_'.plugin_basename(__FILE__), 'scribiii_importer_activate'); function scribiii_importer_activate() { global $wp_db_version, $scribiii_import; // Deactivate on pre 2.3 blogs if($wp_db_version<6075) { $current = get_settings('active_plugins'); array_splice($current, array_search( plugin_basename(__FILE__), $current), 1 ); update_option('active_plugins', $current); do_action('deactivate_'.plugin_basename(__FILE__)); return(FALSE); } } ?>