Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
PK!9g4xUxU Record.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Record /** * Represents a single MARC record * * A MARC record contains a leader and zero or more fields held within a * linked list structure. Fields are represented by {@link File_MARC_Data_Field} * objects. * * @category File_Formats * @package File_MARC * @author Christoffer Landtman * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Record { // {{{ properties /** * Contains a linked list of {@link File_MARC_Data_Field} objects for * this record * @var File_MARC_List */ protected $fields; /** * Record leader * @var string */ protected $leader; /** * Non-fatal warnings generated during parsing * @var array */ protected $warnings; /** * XMLWriter for writing collections * * @var XMLWriter */ protected $marcxml; /** * MARC instance for access to the XML header/footer methods * We need this so that we can properly wrap a collection of MARC records. * * @var File_MARC */ protected $marc; // }}} // {{{ Constructor: function __construct() /** * Start function * * Set all variables to defaults to create new File_MARC_Record object * * @param File_MARC $marc MARC record from File_MARC or File_MARCXML * * @return true */ function __construct($marc = null) { $this->fields = new File_MARC_List(); $this->setLeader(str_repeat(' ', 24)); if (!$marc) { $marc = new File_MARC(null, File_MARC::SOURCE_STRING); // oh the hack } $this->marc = $marc; $this->marcxml = $marc->getXMLWriter(); } // }}} // {{{ Destructor: function __destruct() /** * Destroys the data field */ function __destruct() { $this->fields = null; $this->warnings = null; } // }}} // {{{ getLeader() /** * Get MARC leader * * Returns the leader for the MARC record. No validation * on the specified leader is performed. * * @return string returns the leader */ function getLeader() { return (string)$this->leader; } // }}} // {{{ setLeader() /** * Set MARC record leader * * Sets the leader for the MARC record. No validation * on the specified leader is performed. * * @param string $leader Leader * * @return string returns the leader */ function setLeader($leader) { $this->leader = $leader; return $this->leader; } // }}} // {{{ appendField() /** * Appends field to MARC record * * Adds a {@link File_MARC_Control_Field} or {@link File_MARC_Data_Field} * object to the end of the existing list of fields. * * @param File_MARC_Field $new_field The field to add * * @return File_MARC_Field The field that was added */ function appendField(File_MARC_Field $new_field) { /* Append as the last field in the record */ $this->fields->appendNode($new_field); return $new_field; } // }}} // {{{ prependField() /** * Prepends field to MARC record * * Adds a {@link File_MARC_Control_Field} or {@link File_MARC_Data_Field} * object to the start of to the existing list of fields. * * @param File_MARC_Field $new_field The field to add * * @return File_MARC_Field The field that was added */ function prependField(File_MARC_Field $new_field) { $this->fields->prependNode($new_field); return $new_field; } // }}} // {{{ insertField() /** * Inserts a field in the MARC record relative to an existing field * * Inserts a {@link File_MARC_Control_Field} or {@link File_MARC_Data_Field} * object before or after a specified existing field. * * * // Example: Insert a new field before the first 650 field * * // Create the new field * $subfields[] = new File_MARC_Subfield('a', 'Scott, Daniel.'); * $new_field = new File_MARC_Data_Field('100', $subfields, 0, null); * * // Retrieve the target field for our insertion point * $subject = $record->getFields('650'); * * // Insert the new field * if (is_array($subject)) { * $record->insertField($new_field, $subject[0], true); * } * elseif ($subject) { * $record->insertField($new_field, $subject, true); * } * * * @param File_MARC_Field $new_field The field to add * @param File_MARC_Field $existing_field The target field * @param bool $before Insert the new field before the existing field if true, after the existing field if false * * @return File_MARC_Field The field that was added */ function insertField(File_MARC_Field $new_field, File_MARC_Field $existing_field, $before = false) { $this->fields->insertNode($new_field, $existing_field, $before); return $new_field; } // }}} // {{{ _buildDirectory() /** * Build record directory * * Generate the directory of the record according to the current contents * of the record. * * @return array Array ($fields, $directory, $total, $base_address) */ private function _buildDirectory() { // Vars $fields = array(); $directory = array(); $data_end = 0; foreach ($this->fields as $field) { // No empty fields allowed if (!$field->isEmpty()) { // Get data in raw format $str = $field->toRaw(); $fields[] = $str; // Create directory entry $len = strlen($str); $direntry = sprintf("%03s%04d%05d", $field->getTag(), $len, $data_end); $directory[] = $direntry; $data_end += $len; } } /** * Rules from MARC::Record::USMARC */ $base_address = File_MARC::LEADER_LEN + // better be 24 (count($directory) * File_MARC::DIRECTORY_ENTRY_LEN) + // all the directory entries 1; // end-of-field marker $total = $base_address + // stuff before first field $data_end + // Length of the fields 1; // End-of-record marker return array($fields, $directory, $total, $base_address); } // }}} // {{{ setLeaderLengths() /** * Set MARC record leader lengths * * Set the Leader lengths of the record according to defaults specified in * {@link http://www.loc.gov/marc/bibliographic/ecbdldrd.html} * * @param int $record_length Record length * @param int $base_address Base address of data * * @return bool Success or failure */ function setLeaderLengths($record_length, $base_address) { if (!is_int($record_length)) { return false; } if (!is_int($base_address)) { return false; } // Set record length $this->setLeader(substr_replace($this->getLeader(), sprintf("%05d", $record_length), 0, 5)); $this->setLeader(substr_replace($this->getLeader(), sprintf("%05d", $base_address), File_MARC::DIRECTORY_ENTRY_LEN, 5)); $this->setLeader(substr_replace($this->getLeader(), '22', 10, 2)); $this->setLeader(substr_replace($this->getLeader(), '4500', 20, 4)); if (strlen($this->getLeader()) > File_MARC::LEADER_LEN) { // Avoid incoming leaders that are mangled to be overly long $this->setLeader(substr($this->getLeader(), 0, File_MARC::LEADER_LEN)); $this->addWarning("Input leader was too long; truncated to " . File_MARC::LEADER_LEN . " characters"); } return true; } // }}} // {{{ getField() /** * Return the first {@link File_MARC_Data_Field} or * {@link File_MARC_Control_Field} object that matches the specified tag * name. Returns false if no match is found. * * @param string $spec tag name * @param bool $pcre if true, then match as a regular expression * * @return {@link File_MARC_Data_Field}|{@link File_MARC_Control_Field} first field that matches the requested tag name */ function getField($spec = null, $pcre = null) { foreach ($this->fields as $field) { if (($pcre && preg_match("/$spec/", $field->getTag())) || (!$pcre && $spec == $field->getTag()) ) { return $field; } } return false; } // }}} // {{{ getFields() /** * Return an array or {@link File_MARC_List} containing all * {@link File_MARC_Data_Field} or {@link File_MARC_Control_Field} objects * that match the specified tag name. If the tag name is omitted all * fields are returned. * * @param string $spec tag name * @param bool $pcre if true, then match as a regular expression * * @return File_MARC_List|array {@link File_MARC_Data_Field} or * {@link File_MARC_Control_Field} objects that match the requested tag name */ function getFields($spec = null, $pcre = null) { if (!$spec) { return $this->fields; } // Okay, we're actually looking for something specific $matches = array(); foreach ($this->fields as $field) { if (($pcre && preg_match("/$spec/", $field->getTag())) || (!$pcre && $spec == $field->getTag()) ) { $matches[] = $field; } } return $matches; } // }}} // {{{ deleteFields() /** * Delete all occurrences of a field matching a tag name from the record. * * @param string $tag tag for the fields to be deleted * @param bool $pcre if true, then match as a regular expression * * @return int number of fields that were deleted */ function deleteFields($tag, $pcre = null) { $cnt = 0; foreach ($this->getFields() as $field) { if (($pcre && preg_match("/$tag/", $field->getTag())) || (!$pcre && $tag == $field->getTag()) ) { $field->delete(); $cnt++; } } return $cnt; } // }}} // {{{ addWarning() /** * Add a warning to the MARC record that something non-fatal occurred during * parsing. * * @param string $warning warning message * * @return true */ public function addWarning($warning) { $this->warnings[] = $warning; } // }}} // {{{ getWarnings() /** * Return the array of warnings from the MARC record. * * @return array warning messages */ public function getWarnings() { return $this->warnings; } // }}} // {{{ output methods /** * ========== OUTPUT METHODS ========== */ // {{{ toRaw() /** * Return the record in raw MARC format. * * If you have modified an existing MARC record or created a new MARC * record, use this method to save the record for use in other programs * that accept the MARC format -- for example, your integrated library * system. * * * // Example: Modify a record and save the output to a file * $record->deleteFields('650'); * * // Now that the record has no subject fields, save it to disk * fopen($file, '/home/dan/no_subject.mrc', 'w'); * fwrite($file, $record->toRaw()); * fclose($file); * * * @return string Raw MARC data */ function toRaw() { list($fields, $directory, $record_length, $base_address) = $this->_buildDirectory(); $this->setLeaderLengths($record_length, $base_address); /** * Glue together all parts */ return $this->getLeader().implode("", $directory).File_MARC::END_OF_FIELD.implode("", $fields).File_MARC::END_OF_RECORD; } // }}} // {{{ __toString() /** * Return the MARC record in a pretty printed string * * This method produces an easy-to-read textual display of a MARC record. * * The structure is roughly: * _ * _ * * @return string Formatted representation of MARC record */ function __toString() { // Begin output $formatted = "LDR " . $this->getLeader() . "\n"; foreach ($this->fields as $field) { if (!$field->isEmpty()) { $formatted .= $field->__toString() . "\n"; } } return $formatted; } // }}} // {{{ toJSON() /** * Return the MARC record in JSON format * * This method produces a JSON representation of a MARC record. The input * encoding must be UTF8, otherwise the returned values will be corrupted. * * @return string representation of MARC record in JSON format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toJSON() { $json = new StdClass(); $json->leader = utf8_encode($this->getLeader()); /* Start fields */ $fields = array(); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch(get_class($field)) { case "File_MARC_Control_Field": $fields[] = array(utf8_encode($field->getTag()) => utf8_encode($field->getData())); break; case "File_MARC_Data_Field": $subs = array(); foreach ($field->getSubfields() as $sf) { $subs[] = array(utf8_encode($sf->getCode()) => utf8_encode($sf->getData())); } $contents = new StdClass(); $contents->ind1 = utf8_encode($field->getIndicator(1)); $contents->ind2 = utf8_encode($field->getIndicator(2)); $contents->subfields = $subs; $fields[] = array(utf8_encode($field->getTag()) => $contents); break; } } } /* End fields and record */ $json->fields = $fields; $json_rec = json_encode($json); // Required because json_encode() does not let us stringify integer keys return preg_replace('/("subfields":)(.*?)\["([^\"]+?)"\]/', '\1\2{"0":"\3"}', $json_rec); } // }}} // {{{ toJSONHash() /** * Return the MARC record in Bill Dueber's MARC-HASH JSON format * * This method produces a JSON representation of a MARC record as defined * at http://robotlibrarian.billdueber.com/new-interest-in-marc-hash-json/ * The input * encoding must be UTF8, otherwise the returned values will * be corrupted. * * @return string representation of MARC record in JSON format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toJSONHash() { $json = new StdClass(); $json->type = "marc-hash"; $json->version = array(1, 0); $json->leader = utf8_encode($this->getLeader()); /* Start fields */ $fields = array(); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch(get_class($field)) { case "File_MARC_Control_Field": $fields[] = array(utf8_encode($field->getTag()), utf8_encode($field->getData())); break; case "File_MARC_Data_Field": $subs = array(); foreach ($field->getSubfields() as $sf) { $subs[] = array(utf8_encode($sf->getCode()), utf8_encode($sf->getData())); } $contents = array( utf8_encode($field->getTag()), utf8_encode($field->getIndicator(1)), utf8_encode($field->getIndicator(2)), $subs ); $fields[] = $contents; break; } } } /* End fields and record */ $json->fields = $fields; return json_encode($json); } // }}} // {{{ toXML() /** * Return the MARC record in MARCXML format * * This method produces an XML representation of a MARC record that * attempts to adhere to the MARCXML standard documented at * http://www.loc.gov/standards/marcxml/ * * @param string $encoding output encoding for the MARCXML record * @param bool $indent pretty-print the MARCXML record * @param bool $single wrap the element in a element * * @return string representation of MARC record in MARCXML format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toXML($encoding = "UTF-8", $indent = true, $single = true) { $this->marcxml->setIndent($indent); if ($single) { $this->marcxml->startElement("collection"); $this->marcxml->writeAttribute("xmlns", "http://www.loc.gov/MARC21/slim"); $this->marcxml->startElement("record"); } else { $this->marcxml->startElement("record"); $this->marcxml->writeAttribute("xmlns", "http://www.loc.gov/MARC21/slim"); } // MARCXML schema has some strict requirements // We'll set reasonable defaults to avoid invalid MARCXML $xmlLeader = $this->getLeader(); // Record status if ($xmlLeader[5] == " ") { // Default to "n" (new record) $xmlLeader[5] = "n"; } // Type of record if ($xmlLeader[6] == " ") { // Default to "a" (language material) $xmlLeader[6] = "a"; } $this->marcxml->writeElement("leader", $xmlLeader); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch(get_class($field)) { case "File_MARC_Control_Field": $this->marcxml->startElement("controlfield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->text($field->getData()); $this->marcxml->endElement(); // end control field break; case "File_MARC_Data_Field": $this->marcxml->startElement("datafield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->writeAttribute("ind1", $field->getIndicator(1)); $this->marcxml->writeAttribute("ind2", $field->getIndicator(2)); foreach ($field->getSubfields() as $subfield) { $this->marcxml->startElement("subfield"); $this->marcxml->writeAttribute("code", $subfield->getCode()); $this->marcxml->text($subfield->getData()); $this->marcxml->endElement(); // end subfield } $this->marcxml->endElement(); // end data field break; } } } $this->marcxml->endElement(); // end record if ($single) { $this->marcxml->endElement(); // end collection $this->marcxml->endDocument(); } return $this->marcxml->outputMemory(); } // }}} } // }}} PK!(#~ Exception.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Exception extends PEAR_Exception /** * The File_MARC_Exception class enables error-handling * for the File_MARC package. * * @category File_Formats * @package File_MARC * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Exception extends PEAR_Exception { // {{{ Error codes /** * File could not be opened */ const ERROR_INVALID_FILE = -1; /** * User passed an unknown SOURCE_ constant */ const ERROR_INVALID_SOURCE = -2; /** * MARC record ended with an invalid terminator */ const ERROR_INVALID_TERMINATOR = -3; /** * No directory was found for the MARC record */ const ERROR_NO_DIRECTORY = -4; /** * An entry in the MARC directory was not 12 bytes */ const ERROR_INVALID_DIRECTORY_LENGTH = -5; /** * An entry in the MARC directory specified an invalid tag */ const ERROR_INVALID_DIRECTORY_TAG = -6; /** * An entry in the MARC directory specified an invalid tag length */ const ERROR_INVALID_DIRECTORY_TAG_LENGTH = -7; /** * An entry in the MARC directory specified an invalid field offset */ const ERROR_INVALID_DIRECTORY_OFFSET = -8; /** * An entry in the MARC directory runs past the end of the record */ const ERROR_INVALID_DIRECTORY = -9; /** * A field does not end with the expected end-of-field character */ const ERROR_FIELD_EOF = -10; /** * A field has invalid indicators */ const ERROR_INVALID_INDICATORS = -11; /** * A subfield is defined, but has no data */ const ERROR_EMPTY_SUBFIELD = -12; /** * An indicator other than 1 or 2 was requested */ const ERROR_INVALID_INDICATOR_REQUEST = -13; /** * An invalid mode for adding a field was specified */ const ERROR_INSERTFIELD_MODE = -14; /** * An invalid object was passed instead of a File_MARC_Field object */ const ERROR_INVALID_FIELD = -15; /** * An invalid object was passed instead of a File_MARC_Subfield object */ const ERROR_INVALID_SUBFIELD = -16; /** * An invalid mode for adding a subfield was specified */ const ERROR_INSERTSUBFIELD_MODE = -17; /** * The length in the MARC leader does not match the actual record length */ const ERROR_INCORRECT_LENGTH = -18; /** * The length field in the leader was less than five characters long */ const ERROR_MISSING_LENGTH = -19; /** * A five-digit length could not be found in the MARC leader */ const ERROR_NONNUMERIC_LENGTH = -20; /** * Tag does not adhere to MARC standards */ const ERROR_INVALID_TAG = -21; /** * A field has invalid indicators */ const ERROR_INVALID_INDICATOR = -22; // }}} // {{{ error messages public static $messages = array( self::ERROR_EMPTY_SUBFIELD => 'No subfield data found in tag "%tag%"', self::ERROR_FIELD_EOF => 'Field for tag "%tag%" does not end with an end of field character', self::ERROR_INCORRECT_LENGTH => 'Invalid record length: Leader says "%record_length%" bytes; actual record length is "%actual%"', self::ERROR_INSERTFIELD_MODE => 'insertField() mode "%mode%" was not recognized', self::ERROR_INSERTSUBFIELD_MODE => 'insertSubfield() mode "%mode%" was not recognized', self::ERROR_INVALID_DIRECTORY => 'Directory entry for tag "%tag%" runs past the end of the record', self::ERROR_INVALID_DIRECTORY_LENGTH => 'Invalid directory length', self::ERROR_INVALID_DIRECTORY_OFFSET => 'Invalid offset "%offset%" for tag "%tag%" in directory', self::ERROR_INVALID_DIRECTORY_TAG => 'Invalid tag "%tag%" in directory', self::ERROR_INVALID_DIRECTORY_TAG_LENGTH => 'Invalid length "%len%" in directory for tag "%tag%"', self::ERROR_INVALID_FIELD => 'Specified field must be a File_MARC_Data_Field or File_MARC_Control_Field object, but was "%field%"', self::ERROR_INVALID_FILE => 'Invalid input file "%filename%"', self::ERROR_INVALID_INDICATOR_REQUEST => 'Attempt to access indicator "%indicator%" failed; 1 and 2 are the only valid indicators', self::ERROR_INVALID_INDICATORS => 'Invalid indicators "%indicators%" forced to blanks for tag "%tag%"', self::ERROR_INVALID_SOURCE => "Invalid source for MARC records", self::ERROR_INVALID_SUBFIELD => 'Specified field must be a File_MARC_Subfield object, but was "%class%"', self::ERROR_INVALID_TAG => 'Tag "%tag%" is not a valid tag.', self::ERROR_INVALID_TERMINATOR => 'Invalid record terminator', self::ERROR_MISSING_LENGTH => "Couldn't find record length", self::ERROR_NO_DIRECTORY => 'No directory found', self::ERROR_NONNUMERIC_LENGTH => 'Record length "%record_length%" is not numeric', self::ERROR_INVALID_INDICATOR => 'Illegal indicator "%indicator%" in field "%tag%" forced to blank', ); // }}} // {{{ formatError() /** * Replaces placeholder tokens in an error message with actual values. * * This method enables you to internationalize the messages for the * File_MARC class by simply replacing the File_MARC_Exception::$messages * array with translated values for the messages. * * @param string $message Error message containing placeholders * @param array $errorValues Actual values to substitute for placeholders * * @return string Formatted message */ public static function formatError($message, $errorValues) { foreach ($errorValues as $token => $value) { $message = preg_replace("/\%$token\%/", $value, $message); } return $message; } // }}} } // }}} PK!ShhList.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_List extends SplDoublyLinkedList /** * The File_MARC_List class extends the SplDoublyLinkedList class * to override the key() method in a meaningful way for foreach() iterators. * * For the list of {@link File_MARC_Field} objects in a {@link File_MARC_Record} * object, the key() method returns the tag name of the field. * * For the list of {@link File_MARC_Subfield} objects in a {@link * File_MARC_Data_Field} object, the key() method returns the code of * the subfield. * * * // Iterate through the fields in a record with key=>value iteration * foreach ($record->getFields() as $tag=>$value) { * print "$tag: "; * if ($value instanceof File_MARC_Control_Field) { * print $value->getData(); * } * else { * // Iterate through the subfields in this data field * foreach ($value->getSubfields() as $code=>$subdata) { * print "_$code"; * } * } * print "\n"; * } * * * @category File_Formats * @package File_MARC * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_List extends SplDoublyLinkedList { // {{{ properties /** * Position of the subfield * @var int */ protected $position; // }}} // {{{ key() /** * Returns the tag for a {@link File_MARC_Field} object, or the code * for a {@link File_MARC_Subfield} object. * * This method enables you to use a foreach iterator to retrieve * the tag or code as the key for the iterator. * * @return string returns the tag or code */ function key() { if ($this->current() instanceof File_MARC_Field) { return $this->current()->getTag(); } elseif ($this->current() instanceof File_MARC_Subfield) { return $this->current()->getCode(); } return false; } // }}} // {{{ function insertNode() /** * Inserts a node into the linked list, based on a reference node that * already exists in the list. * * @param mixed $new_node New node to add to the list * @param mixed $existing_node Reference position node * @param bool $before Insert new node before or after the existing node * * @return bool Success or failure **/ public function insertNode($new_node, $existing_node, $before = false) { $pos = 0; $exist_pos = $existing_node->getPosition(); $this->rewind(); // Now add the node according to the requested mode switch ($before) { case true: $this->add($exist_pos, $new_node); break; // after case false: if ($this->offsetExists($exist_pos + 1)) { $this->add($exist_pos + 1, $new_node); } else { $this->appendNode($new_node); return true; } break; } // Fix positions $this->rewind(); while ($n = $this->current()) { $n->setPosition($pos); $this->next(); $pos++; } return true; } // }}} // {{{ function appendNode() /** * Adds a node onto the linked list. * * @param mixed $new_node New node to add to the list * * @return void **/ public function appendNode($new_node) { $pos = $this->count(); $new_node->setPosition($pos); $this->push($new_node); } // }}} // {{{ function prependNode() /** * Adds a node to the start of the linked list. * * @param mixed $new_node New node to add to the list * * @return void **/ public function prependNode($new_node) { $this->insertNode($new_node, $this->bottom(), true); } // }}} // {{{ function deleteNode() /** * Deletes a node from the linked list. * * @param mixed $node Node to delete from the list * * @return void **/ public function deleteNode($node) { $target_pos = $node->getPosition(); $this->rewind(); $pos = 0; // Omit target node and adjust pos of remainder $done = false; try { while ($n = $this->current()) { if ($pos == $target_pos && !$done) { $done = true; $this->next(); $this->offsetUnset($pos); } elseif ($pos >= $target_pos) { $n->setPosition($pos); $pos++; $this->next(); } else { $pos++; $this->next(); } } } catch (Exception $e) { // no-op - shift() throws an exception, sigh } } // }}} // {{{ setPosition() /** * Sets position of the subfield * * @param string $pos new position of the subfield * * @return void */ function setPosition($pos) { $this->position = $pos; } // }}} // {{{ getPosition() /** * Return position of the subfield * * @return int data */ function getPosition() { return $this->position; } // }}} } // }}} PK!+ Field.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ require_once 'File/MARC/List.php'; // {{{ class File_MARC_Field extends File_MARC_List /** * The File_MARC_Field class is expected to be extended to reflect the * requirements of control and data fields. * * Every MARC field contains a tag name. * * @category File_Formats * @package File_MARC * @author Christoffer Landtman * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Field extends File_MARC_List { // {{{ properties /** * The tag name of the Field * @var string */ protected $tag; // }}} // {{{ Constructor: function __construct() /** * File_MARC_Field constructor * * Create a new {@link File_MARC_Field} object from passed arguments. We * define placeholders for the arguments required by child classes. * * @param string $tag tag * @param string $subfields placeholder for subfields or control data * @param string $ind1 placeholder for first indicator * @param string $ind2 placeholder for second indicator */ function __construct($tag, $subfields = null, $ind1 = null, $ind2 = null) { $this->tag = $tag; // Check if valid tag if (!preg_match("/^[0-9A-Za-z]{3}$/", $tag)) { $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_TAG], array("tag" => $tag)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_TAG); } } // }}} // {{{ Destructor: function __destruct() /** * Destroys the data field */ function __destruct() { $this->tag = null; } // }}} // {{{ getTag() /** * Returns the tag for this {@link File_MARC_Field} object * * @return string returns the tag number of the field */ function getTag() { return (string)$this->tag; } // }}} // {{{ setTag() /** * Sets the tag for this {@link File_MARC_Field} object * * @param string $tag new value for the tag * * @return string returns the tag number of the field */ function setTag($tag) { $this->tag = $tag; return $this->getTag(); } // }}} // {{{ isEmpty() /** * Is empty * * Checks if the field is empty. * * @return bool Returns true if the field is empty, otherwise false */ function isEmpty() { if ($this->getTag()) { return false; } // It is empty return true; } // }}} // {{{ isControlField() /** * Is control field * * Checks if the field is a control field. * * @return bool Returns true if the field is a control field, otherwise false */ function isControlField() { if (get_class($this) == 'File_MARC_Control_Field') { return true; } return false; } // }}} // {{{ isDataField() /** * Is data field * * Checks if the field is a data field. * * @return bool Returns true if the field is a data field, otherwise false */ function isDataField() { if (get_class($this) == 'File_MARC_Data_Field') { return true; } return false; } // }}} /** * ========== OUTPUT METHODS ========== */ // {{{ __toString() /** * Return Field formatted * * Return Field as a formatted string. * * @return string Formatted output of Field */ function __toString() { return (string)$this->getTag(); } // }}} // {{{ toRaw() /** * Return field in raw MARC format (stub) * * Return the field formatted in raw MARC for saving into MARC files. This * stub method is extended by the child classes. * * @return bool Raw MARC */ function toRaw() { return false; } // }}} // {{{ formatField() /** * Pretty print a MARC_Field object without tags, indicators, etc. * * @param array $exclude Subfields to exclude from formatted output * * @return string Returns the formatted field data */ function formatField($exclude = array('2')) { if ($this->isControlField()) { return $this->getData(); } else { $out = ''; foreach ($this->getSubfields() as $subfield) { if (substr($this->getTag(), 0, 1) == '6' and (in_array($subfield->getCode(), array('v','x','y','z')))) { $out .= ' -- ' . $subfield->getData(); } elseif (!in_array($subfield->getCode(), $exclude)) { $out .= ' ' . $subfield->getData(); } } return trim($out); } } // }}} } // }}} PK!IC(A(ALint/CodeData.phpnu[ and available for download at * http://search.cpan.org/~eijabb/ * * Current MARC::Lint::CodeData version used as basis for this module: 1.37 * * PHP version 5 * * LICENSE: This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @category File_Formats * @package File_MARC * @author Demian Katz * @author Dan Scott * @copyright 2003-2019 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Record.php 308146 2011-02-08 20:36:20Z dbs $ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Lint /** * Contains codes from the MARC code lists for Geographic Areas, Languages, and * Countries. * * Code data is used for validating fields 008, 040, 041, and 043. * * Also, sources for subfield 2 in 600-651 and 655. * * Note: According to the official MARC documentation, Sears is not a valid 655 * term. The code data below treats it as valid, in anticipation of a change in * the official documentation. * * @category File_Formats * @package File_MARC * @author Demian Katz * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Lint_CodeData { // {{{ properties /** * Valid Geographic Area Codes * @var array */ public $geogAreaCodes; /** * Obsolete Geographic Area Codes * @var array */ public $obsoleteGeogAreaCodes; /** * Valid Language Codes * @var array */ public $languageCodes; /** * Obsolete Language Codes * @var array */ public $obsoleteLanguageCodes; /** * Valid Country Codes * @var array */ public $countryCodes; /** * Obsolete Country Codes * @var array */ public $obsoleteCountryCodes; /** * Valid sources for fields 600-651 * @var array */ public $sources600_651; /** * Obsolete sources for fields 600-651 * @var array */ public $obsoleteSources600_651; /** * Valid sources for field 655 * @var array */ public $sources655; /** * Obsolete sources for field 655 * @var array */ public $obsoleteSources655; // }}} // {{{ Constructor: function __construct() /** * Start function * * Initialize code arrays. * * @return true */ public function __construct() { // @codingStandardsIgnoreStart // fill the valid Geographic Area Codes array $this->geogAreaCodes = explode("\t", "a------ a-af--- a-ai--- a-aj--- a-ba--- a-bg--- a-bn--- a-br--- a-bt--- a-bx--- a-cb--- a-cc--- a-cc-an a-cc-ch a-cc-cq a-cc-fu a-cc-ha a-cc-he a-cc-hh a-cc-hk a-cc-ho a-cc-hp a-cc-hu a-cc-im a-cc-ka a-cc-kc a-cc-ki a-cc-kn a-cc-kr a-cc-ku a-cc-kw a-cc-lp a-cc-mh a-cc-nn a-cc-pe a-cc-sh a-cc-sm a-cc-sp a-cc-ss a-cc-su a-cc-sz a-cc-ti a-cc-tn a-cc-ts a-cc-yu a-ccg-- a-cck-- a-ccp-- a-ccs-- a-ccy-- a-ce--- a-ch--- a-cy--- a-em--- a-gs--- a-ii--- a-io--- a-iq--- a-ir--- a-is--- a-ja--- a-jo--- a-kg--- a-kn--- a-ko--- a-kr--- a-ku--- a-kz--- a-le--- a-ls--- a-mk--- a-mp--- a-my--- a-np--- a-nw--- a-ph--- a-pk--- a-pp--- a-qa--- a-si--- a-su--- a-sy--- a-ta--- a-th--- a-tk--- a-ts--- a-tu--- a-uz--- a-vt--- a-ye--- aa----- ab----- ac----- ae----- af----- ag----- ah----- ai----- ak----- am----- an----- ao----- aopf--- aoxp--- ap----- ar----- as----- at----- au----- aw----- awba--- awgz--- ay----- az----- b------ c------ cc----- cl----- d------ dd----- e------ e-aa--- e-an--- e-au--- e-be--- e-bn--- e-bu--- e-bw--- e-ci--- e-cs--- e-dk--- e-er--- e-fi--- e-fr--- e-ge--- e-gi--- e-gr--- e-gw--- e-gx--- e-hu--- e-ic--- e-ie--- e-it--- e-kv--- e-lh--- e-li--- e-lu--- e-lv--- e-mc--- e-mm--- e-mo--- e-mv--- e-ne--- e-no--- e-pl--- e-po--- e-rb--- e-rm--- e-ru--- e-sm--- e-sp--- e-sw--- e-sz--- e-uk--- e-uk-en e-uk-ni e-uk-st e-uk-ui e-uk-wl e-un--- e-ur--- e-urc-- e-ure-- e-urf-- e-urk-- e-urn-- e-urp-- e-urr-- e-urs-- e-uru-- e-urw-- e-vc--- e-xn--- e-xo--- e-xr--- e-xv--- e-yu--- ea----- eb----- ec----- ed----- ee----- el----- en----- eo----- ep----- er----- es----- ev----- ew----- f------ f-ae--- f-ao--- f-bd--- f-bs--- f-cd--- f-cf--- f-cg--- f-cm--- f-cx--- f-dm--- f-ea--- f-eg--- f-et--- f-ft--- f-gh--- f-gm--- f-go--- f-gv--- f-iv--- f-ke--- f-lb--- f-lo--- f-ly--- f-mg--- f-ml--- f-mr--- f-mu--- f-mw--- f-mz--- f-ng--- f-nr--- f-pg--- f-rh--- f-rw--- f-sa--- f-sd--- f-sf--- f-sg--- f-sh--- f-sj--- f-sl--- f-so--- f-sq--- f-ss--- f-sx--- f-tg--- f-ti--- f-tz--- f-ua--- f-ug--- f-uv--- f-za--- fa----- fb----- fc----- fd----- fe----- ff----- fg----- fh----- fi----- fl----- fn----- fq----- fr----- fs----- fu----- fv----- fw----- fz----- h------ i------ i-bi--- i-cq--- i-fs--- i-hm--- i-mf--- i-my--- i-re--- i-se--- i-xa--- i-xb--- i-xc--- i-xo--- l------ ln----- lnaz--- lnbm--- lnca--- lncv--- lnfa--- lnjn--- lnma--- lnsb--- ls----- lsai--- lsbv--- lsfk--- lstd--- lsxj--- lsxs--- m------ ma----- mb----- me----- mm----- mr----- n------ n-cn--- n-cn-ab n-cn-bc n-cn-mb n-cn-nf n-cn-nk n-cn-ns n-cn-nt n-cn-nu n-cn-on n-cn-pi n-cn-qu n-cn-sn n-cn-yk n-cnh-- n-cnm-- n-cnp-- n-gl--- n-mx--- n-us--- n-us-ak n-us-al n-us-ar n-us-az n-us-ca n-us-co n-us-ct n-us-dc n-us-de n-us-fl n-us-ga n-us-hi n-us-ia n-us-id n-us-il n-us-in n-us-ks n-us-ky n-us-la n-us-ma n-us-md n-us-me n-us-mi n-us-mn n-us-mo n-us-ms n-us-mt n-us-nb n-us-nc n-us-nd n-us-nh n-us-nj n-us-nm n-us-nv n-us-ny n-us-oh n-us-ok n-us-or n-us-pa n-us-ri n-us-sc n-us-sd n-us-tn n-us-tx n-us-ut n-us-va n-us-vt n-us-wa n-us-wi n-us-wv n-us-wy n-usa-- n-usc-- n-use-- n-usl-- n-usm-- n-usn-- n-uso-- n-usp-- n-usr-- n-uss-- n-ust-- n-usu-- n-xl--- nc----- ncbh--- nccr--- nccz--- nces--- ncgt--- ncho--- ncnq--- ncpn--- nl----- nm----- np----- nr----- nw----- nwaq--- nwaw--- nwbb--- nwbf--- nwbn--- nwcj--- nwco--- nwcu--- nwdq--- nwdr--- nweu--- nwgd--- nwgp--- nwhi--- nwht--- nwjm--- nwla--- nwli--- nwmj--- nwmq--- nwna--- nwpr--- nwsc--- nwsd--- nwsn--- nwst--- nwsv--- nwtc--- nwtr--- nwuc--- nwvb--- nwvi--- nwwi--- nwxa--- nwxi--- nwxk--- nwxm--- p------ pn----- po----- poas--- pobp--- poci--- pocw--- poea--- pofj--- pofp--- pogg--- pogu--- poji--- pokb--- poki--- poln--- pome--- pomi--- ponl--- ponn--- ponu--- popc--- popl--- pops--- posh--- potl--- poto--- pott--- potv--- poup--- powf--- powk--- pows--- poxd--- poxe--- poxf--- poxh--- ps----- q------ r------ s------ s-ag--- s-bl--- s-bo--- s-ck--- s-cl--- s-ec--- s-fg--- s-gy--- s-pe--- s-py--- s-sr--- s-uy--- s-ve--- sa----- sn----- sp----- t------ u------ u-ac--- u-at--- u-at-ac u-at-ne u-at-no u-at-qn u-at-sa u-at-tm u-at-vi u-at-we u-atc-- u-ate-- u-atn-- u-cs--- u-nz--- w------ x------ xa----- xb----- xc----- xd----- zd----- zju---- zma---- zme---- zmo---- zne---- zo----- zpl---- zs----- zsa---- zsu---- zur---- zve----"); // fill the obsolete Geographic Area Codes array $this->obsoleteGeogAreaCodes = explode("\t", "t-ay--- e-ur-ai e-ur-aj nwbc--- e-ur-bw f-by--- pocp--- e-url-- cr----- v------ e-ur-er et----- e-ur-gs pogn--- nwga--- nwgs--- a-hk--- ei----- f-if--- awiy--- awiw--- awiu--- e-ur-kz e-ur-kg e-ur-lv e-ur-li a-mh--- cm----- e-ur-mv n-usw-- a-ok--- a-pt--- e-ur-ru pory--- nwsb--- posc--- a-sk--- posn--- e-uro-- e-ur-ta e-ur-tk e-ur-un e-ur-uz a-vn--- a-vs--- nwvr--- e-urv-- a-ys---"); // fill the valid Language Codes array $this->languageCodes = explode("\t", " aar abk ace ach ada ady afa afh afr ain aka akk alb ale alg alt amh ang anp apa ara arc arg arm arn arp art arw asm ast ath aus ava ave awa aym aze bad bai bak bal bam ban baq bas bat bej bel bem ben ber bho bih bik bin bis bla bnt bos bra bre btk bua bug bul bur byn cad cai car cat cau ceb cel cha chb che chg chi chk chm chn cho chp chr chu chv chy cmc cop cor cos cpe cpf cpp cre crh crp csb cus cze dak dan dar day del den dgr din div doi dra dsb dua dum dut dyu dzo efi egy eka elx eng enm epo est ewe ewo fan fao fat fij fil fin fiu fon fre frm fro frr frs fry ful fur gaa gay gba gem geo ger gez gil gla gle glg glv gmh goh gon gor got grb grc gre grn gsw guj gwi hai hat hau haw heb her hil him hin hit hmn hmo hrv hsb hun hup iba ibo ice ido iii ijo iku ile ilo ina inc ind ine inh ipk ira iro ita jav jbo jpn jpr jrb kaa kab kac kal kam kan kar kas kau kaw kaz kbd kha khi khm kho kik kin kir kmb kok kom kon kor kos kpe krc krl kro kru kua kum kur kut lad lah lam lao lat lav lez lim lin lit lol loz ltz lua lub lug lui lun luo lus mac mad mag mah mai mak mal man mao map mar mas may mdf mdr men mga mic min mis mkh mlg mlt mnc mni mno moh mon mos mul mun mus mwl mwr myn myv nah nai nap nau nav nbl nde ndo nds nep new nia nic niu nno nob nog non nor nqo nso nub nwc nya nym nyn nyo nzi oci oji ori orm osa oss ota oto paa pag pal pam pan pap pau peo per phi phn pli pol pon por pra pro pus que raj rap rar roa roh rom rum run rup rus sad sag sah sai sal sam san sas sat scn sco sel sem sga sgn shn sid sin sio sit sla slo slv sma sme smi smj smn smo sms sna snd snk sog som son sot spa srd srn srp srr ssa ssw suk sun sus sux swa swe syc syr tah tai tam tat tel tem ter tet tgk tgl tha tib tig tir tiv tkl tlh tli tmh tog ton tpi tsi tsn tso tuk tum tup tur tut tvl twi tyv udm uga uig ukr umb und urd uzb vai ven vie vol vot wak wal war was wel wen wln wol xal xho yao yap yid yor ypk zap zbl zen zha znd zul zun zxx zza"); // fill the obsolete Language Codes array $this->obsoleteLanguageCodes = explode("\t", "ajm esk esp eth far fri gag gua int iri cam kus mla max mol lan gal lap sao gae scc scr sho snh sso swz tag taj tar tru tsw"); // fill the valid Country Codes array $this->countryCodes = explode("\t", "aa abc aca ae af ag ai aj aku alu am an ao aq aru as at au aw ay azu ba bb bcc bd be bf bg bh bi bl bm bn bo bp br bs bt bu bv bw bx ca cau cb cc cd ce cf cg ch ci cj ck cl cm co cou cq cr ctu cu cv cw cx cy dcu deu dk dm dq dr ea ec eg em enk er es et fa fg fi fj fk flu fm fp fr fs ft gau gb gd gh gi gl gm go gp gr gs gt gu gv gw gy gz hiu hm ho ht hu iau ic idu ie ii ilu inu io iq ir is it iv iy ja ji jm jo ke kg kn ko ksu ku kv kyu kz lau lb le lh li lo ls lu lv ly mau mbc mc mdu meu mf mg miu mj mk ml mm mnu mo mou mp mq mr msu mtu mu mv mw mx my mz na nbu ncu ndu ne nfc ng nhu nik nju nkc nl nmu nn no np nq nr nsc ntc nu nuc nvu nw nx nyu nz ohu oku onc oru ot pau pc pe pf pg ph pic pk pl pn po pp pr pw py qa qea quc rb re rh riu rm ru rw sa sc scu sd sdu se sf sg sh si sj sl sm sn snc so sp sq sr ss st stk su sw sx sy sz ta tc tg th ti tk tl tma tnu to tr ts tu tv txu tz ua uc ug uik un up utu uv uy uz vau vb vc ve vi vm vp vra vtu wau wea wf wiu wj wk wlk ws wvu wyu xa xb xc xd xe xf xga xh xj xk xl xm xn xna xo xoa xp xr xra xs xv xx xxc xxk xxu ye ykc za "); // fill the obsolete Country Codes array $this->obsoleteCountryCodes = explode("\t", "ai air ac ajr bwr cn cz cp ln cs err gsr ge gn hk iw iu jn kzr kgr lvr lir mh mvr nm pt rur ry xi sk xxr sb sv tar tt tkr unr uk ui us uzr vn vs wb ys yu "); // the codes cash, lcsh, lcshac, mesh, nal, and rvm are covered by 2nd // indicators in 600-655 // they are only used when indicators are not available $this->sources600_651 = explode("\t", "aass aat abne aedoml afo afset agrifors agrovoc agrovocf agrovocs aiatsisl aiatsisp aiatsiss aktp albt allars apaist armac asft ashlnl asrcrfcd asrcseo asrctoa asth ated atg atla aucsh bare barn bhb bella bet bhammf bhashe bib1814 bibalex biccbmc bicssc bidex bisacsh bisacmt bisacrt bjornson blcpss blmlsh blnpn bokbas bt btr cabt cash cbk cck ccsa cct ccte cctf cdcng ceeus chirosh cht ciesiniv cilla collett conorsi csahssa csalsct csapa csh csht cstud czenas czmesh dacs dbn dcs ddcri ddcrit ddcut dissao dit dltlt dltt drama dtict ebfem eclas eet eflch eks embiaecid embne emnmus ept erfemn ericd est eum eurovocen eurovocfr eurovocsl fast fes finmesh fire fmesh fnhl francis fssh galestne gccst gcipmedia gcipplatform gem gemet georeft gnd gnis gst gtt hamsun hapi hkcan helecon henn hlasstg hoidokki hrvmesh huc humord iaat ibsen ica icpsr idas idsbb idszbz idszbzes idszbzna idszbzzg idszbzzh idszbzzk iescs iest ilot ilpt inist inspect ipat ipsp isis itglit itoamc itrt jhpb jhpk jlabsh juho jupo jurivoc kaa kaba kao kassu kauno kaunokki kdm khib kito kitu kkts koko kssbar kta kto ktpt ktta kubikat kula kulo kupu lacnaf lapponica larpcal lcac lcdgt lcmpt lcsh lcshac lcstt lctgm lemac lemb liito liv lnmmbr local ltcsh lua maaq maotao mar masa mech mero mesh mipfesd mmm mpirdes msc msh mtirdes musa muso muzeukc muzeukn muzvukci naf nal nalnaf nasat nbdbt nbiemnfag ncjt ndlsh netc ndllsh nicem nimacsc nlgaf nlgkk nlgsh nlmnaf no-ubo-mr noraf noram norbok normesh noubomn noubojur nsbncf nskps ntcpsc ntcsd ntids ntissc nzggn nznb odlt ogst onet opms ordnok pascal pepp peri pha pkk pleiades pmbok pmcsg pmont pmt poliscit popinte precis prvt psychit puho quiding qlsp qrma qrmak qtglit raam ram rasuqam renib reo rero rerovoc rma rpe rswk rswkaf rugeo rurkp rvm rvmgd samisk sanb sao sbiao sbt scbi scgdst scisshl scot sears sfit sgc sgce shbe she shsples sigle sipri sk skon slem smda snt socio solstad sosa spines ssg sthus stw swd swemesh taika tasmas taxhs tbit tbjvp tekord tero tesa tesbhaecid test tgn tha thema thesoz thia tho thub tips tisa tlka tlsh toit trfarn trfbmb trfgr trfoba trfzb trt trtsa tsht tsr ttka ttll tucua udc ukslc ulan umitrist unbisn unbist unescot usaidt valo vcaadu vffyl vmj waqaf watrest wgst wot wpicsh ysa yso"); $this->obsoleteSources600_651 = explode("\t", "cash lcsh lcshac mesh nal nobomn noubojor reroa rvm"); $this->sources655 = explode("\t", "aat afset aiatsisl aiatsisp aiatsiss aktp alett amg asrcrfcd asrcseo asrctoa asth aucsh barn barngf bib1814 bibalex biccbmc bidex bgtchm bisacsh bisacmt bisacrt bjornson bt cash chirosh cct cdcng cjh collett conorsi csht czenas dacs dcs dct ddcut eet eflch embne emnmus ept erfemn ericd estc eurovocen eurovocsl fast fbg fgtpcm finmesh fire ftamc galestne gatbeg gem gmd gmgpc gnd gsafd gst gtlm hamsun hapi hkcan hoidokki ica ilot isbdcontent isbdmedia itglit itrt jhpb jhpk kkts lacnaf lcgft lcmpt lcsh lcshac lcstt lctgm lemac lobt local maaq mar marccategory marcform marcgt marcsmd mech mesh migfg mim msh muzeukc muzeukn muzeukv muzvukci nal nalnaf nbdbgf nbiemnfag ndlsh netc ngl nimafc nlgaf nlgkk nlgsh nlmnaf nmc no-ubo-mr noraf noram nsbncf ntids nzcoh nzggn nznb onet opms ordnok pkk pmcsg pmt proysen quiding qlsp qrmak qtglit raam radfg rasuqam rbbin rbgenr rbmscv rbpap rbpri rbprov rbpub rbtyp rdabf rdabs rdacarrier rdaco rdacontent rdacpc rdact rdafnm rdafs rdaft rdagen rdagrp rdagw rdalay rdamat rdamedia rdamt rdapf rdapm rdapo rdarm rdarr rdaspc rdatc rdatr rdavf reo rerovoc reveal rma rswk rswkaf rugeo rvm rvmgf sao saogf scbi sears sgc sgce sgp sipri skon snt socio spines ssg stw swd swemesh tbit thema tesa tgfbne thesoz tho thub toit tsht tucua ukslc ulan vgmsgg vgmsng vmj waqaf"); $this->obsoleteSources655 = explode("\t", "cash ftamc lcsh lcshac marccarrier marccontent marcmedia mesh nal reroa rvm"); // @codingStandardsIgnoreEnd } // }}} } // }}} PK!RA;A;Data_Field.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Data_Field extends File_MARC_Field /** * The File_MARC_Data_Field class represents a single field in a MARC record. * * A MARC data field consists of a tag name, two indicators which may be null, * and zero or more subfields represented by {@link File_MARC_Subfield} objects. * Subfields are held within a linked list structure. * * @category File_Formats * @package File_MARC * @author Christoffer Landtman * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Data_Field extends File_MARC_Field { // {{{ properties /** * Value of the first indicator * @var string */ protected $ind1; /** * Value of the second indicator * @var string */ protected $ind2; /** * Linked list of subfields * @var File_MARC_List */ protected $subfields; // }}} // {{{ Constructor: function __construct() /** * {@link File_MARC_Data_Field} constructor * * Create a new {@link File_MARC_Data_Field} object. The only required * parameter is a tag. This enables programs to build up new fields * programmatically. * * * // Example: Create a new data field * * // We can optionally create an array of subfields first * $subfields[] = new File_MARC_Subfield('a', 'Scott, Daniel.'); * * // Create the new 100 field complete with a _a subfield and an indicator * $new_field = new File_MARC_Data_Field('100', $subfields, 0, null); * * * @param string $tag tag * @param array $subfields array of {@link File_MARC_Subfield} objects * @param string $ind1 first indicator * @param string $ind2 second indicator */ function __construct($tag, array $subfields = null, $ind1 = null, $ind2 = null) { $this->subfields = new File_MARC_List(); parent::__construct($tag); $this->ind1 = $this->_validateIndicator($ind1); $this->ind2 = $this->_validateIndicator($ind2); // we'll let users add subfields after if they so desire if ($subfields) { $this->addSubfields($subfields); } } // }}} // {{{ Destructor: function __destruct() /** * Destroys the data field */ function __destruct() { $this->subfields = null; $this->ind1 = null; $this->ind2 = null; parent::__destruct(); } // }}} // {{{ Explicit destructor: function delete() /** * Destroys the data field * * @return true */ function delete() { $this->__destruct(); } // }}} // {{{ protected function _validateIndicator() /** * Validates an indicator field * * Validates the value passed in for an indicator. This routine ensures * that an indicator is a single character. If the indicator value is null, * then this method returns a single character. * * If the indicator value contains more than a single character, this * throws an exception. * * @param string $indicator Value of the indicator to be validated * * @return string Returns the indicator, or space if the indicator was null */ private function _validateIndicator($indicator) { if ($indicator == null) { $indicator = ' '; } elseif (strlen($indicator) > 1) { $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_INDICATOR], array("tag" => $this->getTag(), "indicator" => $indicator)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_INDICATOR); } return $indicator; } // }}} // {{{ appendSubfield() /** * Appends subfield to subfield list * * Adds a File_MARC_Subfield object to the end of the existing list * of subfields. * * @param File_MARC_Subfield $new_subfield The subfield to add * * @return File_MARC_Subfield the new File_MARC_Subfield object */ function appendSubfield(File_MARC_Subfield $new_subfield) { /* Append as the last subfield in the field */ $this->subfields->appendNode($new_subfield); } // }}} // {{{ prependSubfield() /** * Prepends subfield to subfield list * * Adds a File_MARC_Subfield object to the start of the existing list * of subfields. * * @param File_MARC_Subfield $new_subfield The subfield to add * * @return File_MARC_Subfield the new File_MARC_Subfield object */ function prependSubfield(File_MARC_Subfield $new_subfield) { $this->subfields->unshift($new_subfield); return $new_subfield; } // }}} // {{{ insertSubfield() /** * Inserts a field in the MARC record relative to an existing field * * Inserts a {@link File_MARC_Subfield} object before or after an existing * subfield. * * @param File_MARC_Subfield $new_field The subfield to add * @param File_MARC_Subfield $existing_field The target subfield * @param bool $before Insert the subfield before the existing subfield if true; after the existing subfield if false * * @return File_MARC_Subfield The new subfield */ function insertSubfield(File_MARC_Subfield $new_field, File_MARC_Subfield $existing_field, $before = false) { $this->subfields->insertNode($new_field, $existing_field, $before); return $new_field; } // }}} // {{{ addSubfields() /** * Adds an array of subfields to a {@link File_MARC_Data_Field} object * * Appends subfields to existing subfields in the order in which * they appear in the array. For finer grained control of the subfield * order, use {@link appendSubfield()}, {@link prependSubfield()}, * or {@link insertSubfield()} to add each subfield individually. * * @param array $subfields array of {@link File_MARC_Subfield} objects * * @return int returns the number of subfields that were added */ function addSubfields(array $subfields) { /* * Just in case someone passes in a single File_MARC_Subfield * instead of an array */ if ($subfields instanceof File_MARC_Subfield) { $this->appendSubfield($subfields); return 1; } // Add subfields $cnt = 0; foreach ($subfields as $subfield) { $this->appendSubfield($subfield); $cnt++; } return $cnt; } // }}} // {{{ deleteSubfield() /** * Delete a subfield from the field. * * @param File_MARC_Subfield $subfield The subfield to delete * * @return void */ function deleteSubfield(File_MARC_Subfield $subfield) { $this->subfields->deleteNode($subfield); } // }}} // {{{ getIndicator() /** * Get the value of an indicator * * @param int $ind number of the indicator (1 or 2) * * @return string returns indicator value if it exists, otherwise false */ function getIndicator($ind) { if ($ind == 1) { return (string)$this->ind1; } elseif ($ind == 2) { return (string)$this->ind2; } else { $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_INDICATOR_REQUEST], array("indicator" => $indicator)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_INDICATOR_REQUEST); } return false; } // }}} // {{{ setIndicator() /** * Set the value of an indicator * * @param int $ind number of the indicator (1 or 2) * @param string $value value of the indicator * * @return string returns indicator value if it exists, otherwise false */ function setIndicator($ind, $value) { switch ($ind) { case 1: $this->ind1 = $this->_validateIndicator($value); break; case 2: $this->ind2 = $this->_validateIndicator($value); break; default: $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_INDICATOR_REQUEST], array("indicator" => $ind)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_INDICATOR_REQUEST); return false; } return $this->getIndicator($ind); } // }}} // {{{ getSubfield() /** * Returns the first subfield that matches a requested code. * * @param string $code subfield code for which the * {@link File_MARC_Subfield} is retrieved * @param bool $pcre if true, then match as a regular expression * * @return File_MARC_Subfield returns the first subfield that matches * $code, or false if no codes match $code */ function getSubfield($code = null, $pcre = null) { // iterate merrily through the subfields looking for the requested code foreach ($this->subfields as $sf) { if (($pcre && preg_match("/$code/", $sf->getCode())) || (!$pcre && $code == $sf->getCode()) ) { return $sf; } } // No matches were found return false; } // }}} // {{{ getSubfields() /** * Returns an array of subfields that match a requested code, * or a {@link File_MARC_List} that contains all of the subfields * if the requested code is null. * * @param string $code subfield code for which the * {@link File_MARC_Subfield} is retrieved * @param bool $pcre if true, then match as a regular expression * * @return File_MARC_List|array returns a linked list of all subfields * if $code is null, an array of {@link File_MARC_Subfield} objects if * one or more subfields match, or an empty array if no codes match $code */ function getSubfields($code = null, $pcre = null) { $results = array(); // return all subfields if no specific subfields were requested if ($code === null) { $results = $this->subfields; return $results; } // iterate merrily through the subfields looking for the requested code foreach ($this->subfields as $sf) { if (($pcre && preg_match("/$code/", $sf->getCode())) || (!$pcre && $code == $sf->getCode()) ) { $results[] = $sf; } } return $results; } // }}} // {{{ isEmpty() /** * Checks if the field is empty. * * Checks if the field is empty. If the field has at least one subfield * with data, it is not empty. * * @return bool Returns true if the field is empty, otherwise false */ function isEmpty() { // If $this->subfields is null, we must have deleted it if (!$this->subfields) { return true; } // Iterate through the subfields looking for some data foreach ($this->subfields as $subfield) { // Check if subfield has data if (!$subfield->isEmpty()) { return false; } } // It is empty return true; } // }}} /** * ========== OUTPUT METHODS ========== */ // {{{ __toString() /** * Return Field formatted * * Return Field as a formatted string. * * @return string Formatted output of Field */ function __toString() { // Variables $lines = array(); // Process tag and indicators $pre = sprintf("%3s %1s%1s", $this->tag, $this->ind1, $this->ind2); // Process subfields foreach ($this->subfields as $subfield) { $lines[] = sprintf("%6s _%1s%s", $pre, $subfield->getCode(), $subfield->getData()); $pre = ""; } return join("\n", $lines); } // }}} // {{{ toRaw() /** * Return Field in Raw MARC * * Return the Field formatted in Raw MARC for saving into MARC files * * @return string Raw MARC */ function toRaw() { $subfields = array(); foreach ($this->subfields as $subfield) { if (!$subfield->isEmpty()) { $subfields[] = $subfield->toRaw(); } } return (string)$this->ind1.$this->ind2.implode("", $subfields).File_MARC::END_OF_FIELD; } // }}} // {{{ getContents() /** * Return fields data content as joined string * * Return all the fields data content as a joined string * * @param string $joinChar A string used to join the data conntent. * Default is an empty string * * @return string Joined string */ function getContents($joinChar = '') { $contents = array(); foreach($this->subfields as $subfield) { $contents[] = $subfield->getData(); } return implode($joinChar, $contents); } // }}} } // }}} PK!lz`Control_Field.phpnu[ * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Control_Field extends File_MARC_Field /** * The File_MARC_Control_Field class represents a single control field * in a MARC record. * * A MARC control field consists of a tag name and control data. * * @category File_Formats * @package File_MARC * @author Christoffer Landtman * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Control_Field extends File_MARC_Field { // {{{ Properties /** * Value of field, if field is a Control field * @var string */ protected $data; // }}} // {{{ Constructor: function __construct() /** * Field init function * * Create a new {@link File_MARC_Control_Field} object from passed arguments * * @param string $tag tag * @param string $data control field data * @param string $ind1 placeholder for class strictness * @param string $ind2 placeholder for class strictness */ function __construct($tag, $data, $ind1 = null, $ind2 = null) { $this->data = $data; parent::__construct($tag); } // }}} // {{{ Destructor: function __destruct() /** * Destroys the control field */ function __destruct() { $this->data = null; parent::__destruct(); } // }}} // {{{ Explicit destructor: function delete() /** * Destroys the control field * * @return true */ function delete() { $this->__destruct(); } // }}} // {{{ getData() /** * Get control field data * * @return string returns data in control field */ function getData() { return (string)$this->data; } // }}} // {{{ isEmpty() /** * Is empty * * Checks if the field contains data * * @return bool Returns true if the field is empty, otherwise false */ function isEmpty() { return ($this->data) ? false : true; } // }}} // {{{ setData() /** * Set control field data * * @param string $data data for the control field * * @return bool returns the new data in the control field */ function setData($data) { $this->data = $data; return $this->getData(); } // }}} // {{{ __toString() /** * Return as a formatted string * * Return the control field as a formatted string for pretty printing * * @return string Formatted output of control Field */ function __toString() { return sprintf("%3s %s", $this->tag, $this->data); } // }}} // {{{ toRaw() /** * Return as raw MARC * * Return the control field formatted in Raw MARC for saving into MARC files * * @return string Raw MARC */ function toRaw() { return (string)$this->data.File_MARC::END_OF_FIELD; } // }}} } // }}} PK!Ɍ599Lint.phpnu[ and available at http://search.cpan.org/~eijabb/ * * Current MARC::Lint version used as basis for this module: 1.52 * * PHP version 5 * * LICENSE: This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @category File_Formats * @package File_MARC * @author Demian Katz * @author Dan Scott * @copyright 2003-2019 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Record.php 308146 2011-02-08 20:36:20Z dbs $ * @link http://pear.php.net/package/File_MARC */ require_once 'File/MARC/Lint/CodeData.php'; require_once 'Validate/ISPN.php'; // {{{ class File_MARC_Lint /** * Class for testing validity of MARC records against MARC21 standard. * * @category File_Formats * @package File_MARC * @author Demian Katz * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Lint { // {{{ properties /** * Rules used for testing records * @var array */ protected $rules; /** * A File_MARC_Lint_CodeData object for validating codes * @var File_MARC_Lint_CodeData */ protected $data; /** * A Validate_ISPN object for validating ISBN numbers * @var Validate_ISPN */ protected $validateIspn; /** * Warnings generated during analysis * @var array */ protected $warnings = array(); // }}} // {{{ Constructor: function __construct() /** * Start function * * Set up rules for testing MARC records. * * @return true */ public function __construct() { $this->parseRules(); $this->data = new File_MARC_Lint_CodeData(); $this->validateIspn = new Validate_ISPN(); } // }}} // {{{ getWarnings() /** * Check the provided MARC record and return an array of warning messages. * * @param File_MARC_Record $marc Record to check * * @return array */ public function checkRecord($marc) { // Reset warnings: $this->warnings = array(); // Fail if we didn't get a valid object: if (!is_a($marc, 'File_MARC_Record')) { $this->warn('Must pass a File_MARC_Record object to checkRecord'); } else { $this->checkDuplicate1xx($marc); $this->checkMissing245($marc); $this->standardFieldChecks($marc); } return $this->warnings; } // }}} // {{{ warn() /** * Add a warning. * * @param string $warning Warning to add * * @return void */ protected function warn($warning) { $this->warnings[] = $warning; } // }}} // {{{ checkDuplicate1xx() /** * Check for multiple 1xx fields. * * @param File_MARC_Record $marc Record to check * * @return void */ protected function checkDuplicate1xx($marc) { $result = $marc->getFields('1[0-9][0-9]', true); $count = count($result); if ($count > 1) { $this->warn( "1XX: Only one 1XX tag is allowed, but I found $count of them." ); } } // }}} // {{{ checkMissing245() /** * Check for missing 245 field. * * @param File_MARC_Record $marc Record to check * * @return void */ protected function checkMissing245($marc) { $result = $marc->getFields('245'); if (count($result) == 0) { $this->warn('245: No 245 tag.'); } } // }}} // {{{ standardFieldChecks() /** * Check all fields against the standard rules encoded in the class. * * @param File_MARC_Record $marc Record to check * * @return void */ protected function standardFieldChecks($marc) { $fieldsSeen = array(); foreach ($marc->getFields() as $current) { $tagNo = $current->getTag(); // if 880 field, inherit rules from tagno in subfield _6 if ($tagNo == 880) { if ($sub6 = $current->getSubfield(6)) { $tagNo = substr($sub6->getData(), 0, 3); $tagrules = isset($this->rules[$tagNo]) ? $this->rules[$tagNo] : null; // 880 is repeatable, but its linked field may not be if (isset($tagrules['repeatable']) && $tagrules['repeatable'] == 'NR' && isset($fieldsSeen['880.'.$tagNo]) ) { $this->warn("$tagNo: Field is not repeatable."); } $fieldsSeen['880.'.$tagNo] = isset($fieldsSeen['880.'.$tagNo]) ? $fieldsSeen['880.'.$tagNo] + 1 : 1; } else { $this->warn("880: No subfield 6."); $tagRules = null; } } else { // Default case -- not an 880 field: $tagrules = isset($this->rules[$tagNo]) ? $this->rules[$tagNo] : null; if (isset($tagrules['repeatable']) && $tagrules['repeatable'] == 'NR' && isset($fieldsSeen[$tagNo]) ) { $this->warn("$tagNo: Field is not repeatable."); } $fieldsSeen[$tagNo] = isset($fieldsSeen[$tagNo]) ? $fieldsSeen[$tagNo] + 1 : 1; } // Treat data fields differently from control fields: if (intval(ltrim($tagNo, '0')) >= 10) { if (!empty($tagrules)) { $this->checkIndicators($tagNo, $current, $tagrules); $this->checkSubfields($tagNo, $current, $tagrules); } } else { // Control field: if (strstr($current->toRaw(), chr(hexdec('1F')))) { $this->warn( "$tagNo: Subfields are not allowed in fields lower than 010" ); } } // Check to see if a checkxxx() function exists, and call it on the // field if it does $method = 'check' . $tagNo; if (method_exists($this, $method)) { $this->$method($current); } } } // }}} // {{{ checkIndicators() /** * Check the indicators for the provided field. * * @param string $tagNo Tag number being checked * @param File_MARC_Field $field Field to check * @param array $rules Rules to use for checking * * @return void */ protected function checkIndicators($tagNo, $field, $rules) { for ($i = 1; $i <= 2; $i++) { $ind = $field->getIndicator($i); if ($ind === false || $ind == ' ') { $ind = 'b'; } if (!strstr($rules['ind' . $i]['values'], $ind)) { // Make indicator blank value human-readable for message: if ($ind == 'b') { $ind = 'blank'; } $this->warn( "$tagNo: Indicator $i must be " . $rules['ind' . $i]['hr_values'] . " but it's \"$ind\"" ); } } } // }}} // {{{ checkSubfields() /** * Check the subfields for the provided field. * * @param string $tagNo Tag number being checked * @param File_MARC_Field $field Field to check * @param array $rules Rules to use for checking * * @return void */ protected function checkSubfields($tagNo, $field, $rules) { $subSeen = array(); foreach ($field->getSubfields() as $current) { $code = $current->getCode(); $data = $current->getData(); $subrules = isset($rules['sub' . $code]) ? $rules['sub' . $code] : null; if (empty($subrules)) { $this->warn("$tagNo: Subfield _$code is not allowed."); } elseif ($subrules['repeatable'] == 'NR' && isset($subSeen[$code])) { $this->warn("$tagNo: Subfield _$code is not repeatable."); } if (preg_match('/\r|\t|\n/', $data)) { $this->warn( "$tagNo: Subfield _$code has an invalid control character" ); } $subSeen[$code] = isset($subSeen[$code]) ? $subSeen[$code]++ : 1; } } // }}} // {{{ check020() /** * Looks at 020$a and reports errors if the check digit is wrong. * Looks at 020$z and validates number if hyphens are present. * * @param File_MARC_Field $field Field to check * * @return void */ protected function check020($field) { foreach ($field->getSubfields() as $current) { $data = $current->getData(); // remove any hyphens $isbn = str_replace('-', '', $data); // remove nondigits $isbn = preg_replace('/^\D*(\d{9,12}[X\d])\b.*$/', '$1', $isbn); if ($current->getCode() == 'a') { if ((substr($data, 0, strlen($isbn)) != $isbn)) { $this->warn("020: Subfield a may have invalid characters."); } // report error if no space precedes a qualifier in subfield a if (preg_match('/\(/', $data) && !preg_match('/[X0-9] \(/', $data)) { $this->warn( "020: Subfield a qualifier must be preceded by space, $data." ); } // report error if unable to find 10-13 digit string of digits in // subfield 'a' if (!preg_match('/(?:^\d{10}$)|(?:^\d{13}$)|(?:^\d{9}X$)/', $isbn)) { $this->warn( "020: Subfield a has the wrong number of digits, $data." ); } else { if (strlen($isbn) == 10) { if (!$this->validateIspn->isbn10($isbn)) { $this->warn("020: Subfield a has bad checksum, $data."); } } else if (strlen($isbn) == 13) { if (!$this->validateIspn->isbn13($isbn)) { $this->warn( "020: Subfield a has bad checksum (13 digit), $data." ); } } } } else if ($current->getCode() == 'z') { // look for valid isbn in 020$z if (preg_match('/^ISBN/', $data) || preg_match('/^\d*\-\d+/', $data) ) { // ################################################## // ## Turned on for now--Comment to unimplement #### // ################################################## if ((strlen($isbn) == 10) && ($this->validateIspn->isbn10($isbn) == 1) ) { $this->warn("020: Subfield z is numerically valid."); } } } } } // }}} // {{{ check041() /** * Warns if subfields are not evenly divisible by 3 unless second indicator is 7 * (future implementation would ensure that each subfield is exactly 3 characters * unless ind2 is 7--since subfields are now repeatable. This is not implemented * here due to the large number of records needing to be corrected.). Validates * against the MARC Code List for Languages (). * * @param File_MARC_Field $field Field to check * * @return void */ protected function check041($field) { // warn if length of each subfield is not divisible by 3 unless ind2 is 7 if ($field->getIndicator(2) != '7') { foreach ($field->getSubfields() as $sub) { $code = $sub->getCode(); $data = $sub->getData(); if (strlen($data) % 3 != 0) { $this->warn( "041: Subfield _$code must be evenly divisible by 3 or " . "exactly three characters if ind2 is not 7, ($data)." ); } else { for ($i = 0; $i < strlen($data); $i += 3) { $chk = substr($data, $i, 3); if (!in_array($chk, $this->data->languageCodes)) { $obs = $this->data->obsoleteLanguageCodes; if (in_array($chk, $obs)) { $this->warn( "041: Subfield _$code, $data, may be obsolete." ); } else { $this->warn( "041: Subfield _$code, $data ($chk)," . " is not valid." ); } } } } } } } // }}} // {{{ check043() /** * Warns if each subfield a is not exactly 7 characters. Validates each code * against the MARC code list for Geographic Areas (). * * @param File_MARC_Field $field Field to check * * @return void */ protected function check043($field) { foreach ($field->getSubfields('a') as $suba) { // warn if length of subfield a is not exactly 7 $data = $suba->getData(); if (strlen($data) != 7) { $this->warn("043: Subfield _a must be exactly 7 characters, $data"); } else if (!in_array($data, $this->data->geogAreaCodes)) { if (in_array($data, $this->data->obsoleteGeogAreaCodes)) { $this->warn("043: Subfield _a, $data, may be obsolete."); } else { $this->warn("043: Subfield _a, $data, is not valid."); } } } } // }}} // {{{ check245() /** * -Makes sure $a exists (and is first subfield). * -Warns if last character of field is not a period * --Follows LCRI 1.0C, Nov. 2003 rather than MARC21 rule * -Verifies that $c is preceded by / (space-/) * -Verifies that initials in $c are not spaced * -Verifies that $b is preceded by :;= (space-colon, space-semicolon, * space-equals) * -Verifies that $h is not preceded by space unless it is dash-space * -Verifies that data of $h is enclosed in square brackets * -Verifies that $n is preceded by . (period) * --As part of that, looks for no-space period, or dash-space-period * (for replaced elipses) * -Verifies that $p is preceded by , (no-space-comma) when following $n and * . (period) when following other subfields. * -Performs rudimentary article check of 245 2nd indicator vs. 1st word of * 245$a (for manual verification). * * Article checking is done by internal checkArticle method, which should work * for 130, 240, 245, 440, 630, 730, and 830. * * @param File_MARC_Field $field Field to check * * @return void */ protected function check245($field) { if (count($field->getSubfields('a')) == 0) { $this->warn("245: Must have a subfield _a."); } // Convert subfields to array and set flags indicating which subfields are // present while we're at it. $tmp = $field->getSubfields(); $hasSubfields = $subfields = array(); foreach ($tmp as $current) { $subfields[] = $current; $hasSubfields[$current->getCode()] = true; } // 245 must end in period (may want to make this less restrictive by allowing // trailing spaces) // do 2 checks--for final punctuation (MARC21 rule), and for period // (LCRI 1.0C, Nov. 2003) $lastChar = substr($subfields[count($subfields)-1]->getData(), -1); if (!in_array($lastChar, array('.', '?', '!'))) { $this->warn("245: Must end with . (period)."); } else if ($lastChar != '.') { $this->warn( "245: MARC21 allows ? or ! as final punctuation but LCRI 1.0C, Nov." . " 2003 (LCPS 1.7.1 for RDA records), requires period." ); } // Check for first subfield // subfield a should be first subfield (or 2nd if subfield '6' is present) if (isset($hasSubfields['6'])) { // make sure there are at least 2 subfields if (count($subfields) < 2) { $this->warn("245: May have too few subfields."); } else { $first = $subfields[0]->getCode(); $second = $subfields[1]->getCode(); if ($first != '6') { $this->warn("245: First subfield must be _6, but it is $first"); } if ($second != 'a') { $this->warn( "245: First subfield after subfield _6 must be _a, but it " . "is _$second" ); } } } else { // 1st subfield must be 'a' $first = $subfields[0]->getCode(); if ($first != 'a') { $this->warn("245: First subfield must be _a, but it is _$first"); } } // End check for first subfield // subfield c, if present, must be preceded by / // also look for space between initials if (isset($hasSubfields['c'])) { foreach ($subfields as $i => $current) { // 245 subfield c must be preceded by / (space-/) if ($current->getCode() == 'c') { if ($i > 0 && !preg_match('/\s\/$/', $subfields[$i-1]->getData()) ) { $this->warn("245: Subfield _c must be preceded by /"); } // 245 subfield c initials should not have space if (preg_match('/\b\w\. \b\w\./', $current->getData())) { $this->warn( "245: Subfield _c initials should not have a space." ); } break; } } } // each subfield b, if present, should be preceded by :;= (colon, semicolon, // or equals sign) if (isset($hasSubfields['b'])) { // 245 subfield b should be preceded by space-:;= (colon, semicolon, or // equals sign) foreach ($subfields as $i => $current) { if ($current->getCode() == 'b' && $i > 0 && !preg_match('/ [:;=]$/', $subfields[$i-1]->getData()) ) { $this->warn( "245: Subfield _b should be preceded by space-colon, " . "space-semicolon, or space-equals sign." ); } } } // each subfield h, if present, should be preceded by non-space if (isset($hasSubfields['h'])) { // 245 subfield h should not be preceded by space foreach ($subfields as $i => $current) { // report error if subfield 'h' is preceded by space (unless // dash-space) if ($current->getCode() == 'h') { $prev = $subfields[$i-1]->getData(); if ($i > 0 && !preg_match('/(\S$)|(\-\- $)/', $prev)) { $this->warn( "245: Subfield _h should not be preceded by space." ); } // report error if subfield 'h' does not start with open square // bracket with a matching close bracket; could have check // against list of valid values here $data = $current->getData(); if (!preg_match('/^\[\w*\s*\w*\]/', $data)) { $this->warn( "245: Subfield _h must have matching square brackets," . " $data." ); } } } } // each subfield n, if present, must be preceded by . (period) if (isset($hasSubfields['n'])) { // 245 subfield n must be preceded by . (period) foreach ($subfields as $i => $current) { // report error if subfield 'n' is not preceded by non-space-period // or dash-space-period if ($current->getCode() == 'n' && $i > 0) { $prev = $subfields[$i-1]->getData(); if (!preg_match('/(\S\.$)|(\-\- \.$)/', $prev)) { $this->warn( "245: Subfield _n must be preceded by . (period)." ); } } } } // each subfield p, if present, must be preceded by a , (no-space-comma) // if it follows subfield n, or by . (no-space-period or // dash-space-period) following other subfields if (isset($hasSubfields['p'])) { // 245 subfield p must be preceded by . (period) or , (comma) foreach ($subfields as $i => $current) { if ($current->getCode() == 'p' && $i > 0) { $prev = $subfields[$i-1]; // case for subfield 'n' being field before this one (allows // dash-space-comma) if ($prev->getCode() == 'n' && !preg_match('/(\S,$)|(\-\- ,$)/', $prev->getData()) ) { $this->warn( "245: Subfield _p must be preceded by , (comma) " . "when it follows subfield _n." ); } else if ($prev->getCode() != 'n' && !preg_match('/(\S\.$)|(\-\- \.$)/', $prev->getData()) ) { $this->warn( "245: Subfield _p must be preceded by . (period)" . " when it follows a subfield other than _n." ); } } } } // check for invalid 2nd indicator $this->checkArticle($field); } // }}} // {{{ checkArticle() /** * Check of articles is based on code from Ian Hamilton. This version is more * limited in that it focuses on English, Spanish, French, Italian and German * articles. Certain possible articles have been removed if they are valid * English non-articles. This version also disregards 008_language/041 codes * and just uses the list of articles to provide warnings/suggestions. * * source for articles = * * Should work with fields 130, 240, 245, 440, 630, 730, and 830. Reports error * if another field is passed in. * * @param File_MARC_Field $field Field to check * * @return void */ protected function checkArticle($field) { // add articles here as needed // Some omitted due to similarity with valid words (e.g. the German 'die'). static $article = array( 'a' => 'eng glg hun por', 'an' => 'eng', 'das' => 'ger', 'dem' => 'ger', 'der' => 'ger', 'ein' => 'ger', 'eine' => 'ger', 'einem' => 'ger', 'einen' => 'ger', 'einer' => 'ger', 'eines' => 'ger', 'el' => 'spa', 'en' => 'cat dan nor swe', 'gl' => 'ita', 'gli' => 'ita', 'il' => 'ita mlt', 'l' => 'cat fre ita mlt', 'la' => 'cat fre ita spa', 'las' => 'spa', 'le' => 'fre ita', 'les' => 'cat fre', 'lo' => 'ita spa', 'los' => 'spa', 'os' => 'por', 'the' => 'eng', 'um' => 'por', 'uma' => 'por', 'un' => 'cat spa fre ita', 'una' => 'cat spa ita', 'une' => 'fre', 'uno' => 'ita', ); // add exceptions here as needed // may want to make keys lowercase static $exceptions = array( 'A & E', 'A & ', 'A-', 'A+', 'A is ', 'A isn\'t ', 'A l\'', 'A la ', 'A posteriori', 'A priori', 'A to ', 'El Nino', 'El Salvador', 'L is ', 'L-', 'La Salle', 'Las Vegas', 'Lo cual', 'Lo mein', 'Lo que', 'Los Alamos', 'Los Angeles', ); // get tagno to determine which indicator to check and for reporting $tagNo = $field->getTag(); // retrieve tagno from subfield 6 if 880 field if ($tagNo == '880' && ($sub6 = $field->getSubfield('6'))) { $tagNo = substr($sub6->getData(), 0, 3); } // $ind holds nonfiling character indicator value $ind = ''; // $first_or_second holds which indicator is for nonfiling char value $first_or_second = ''; if (in_array($tagNo, array(130, 630, 730))) { $ind = $field->getIndicator(1); $first_or_second = '1st'; } else if (in_array($tagNo, array(240, 245, 440, 830))) { $ind = $field->getIndicator(2); $first_or_second = '2nd'; } else { $this->warn( 'Internal error: ' . $tagNo . " is not a valid field for article checking\n" ); return; } if (!is_numeric($ind)) { $this->warn($tagNo . ": Non-filing indicator is non-numeric"); return; } // get subfield 'a' of the title field $titleField = $field->getSubfield('a'); $title = $titleField ? $titleField->getData() : ''; // warn about out-of-range skip indicators (note: this feature is an // addition to the PHP code; it is not ported directly from MARC::Lint). if ($ind > strlen($title)) { $this->warn($tagNo . ": Non-filing indicator is out of range"); return; } $char1_notalphanum = 0; // check for apostrophe, quote, bracket, or parenthesis, before first word // remove if found and add to non-word counter while (preg_match('/^["\'\[\(*]/', $title)) { $char1_notalphanum++; $title = preg_replace('/^["\'\[\(*]/', '', $title); } // split title into first word + rest on space, parens, bracket, apostrophe, // quote, or hyphen preg_match('/^([^ \(\)\[\]\'"\-]+)([ \(\)\[\]\'"\-])?(.*)/i', $title, $hits); $firstword = isset($hits[1]) ? $hits[1] : ''; $separator = isset($hits[2]) ? $hits[2] : ''; $etc = isset($hits[3]) ? $hits[3] : ''; // get length of first word plus the number of chars removed above plus one // for the separator $nonfilingchars = strlen($firstword) + $char1_notalphanum + 1; // check to see if first word is an exception $isan_exception = false; foreach ($exceptions as $current) { if (substr($title, 0, strlen($current)) == $current) { $isan_exception = true; break; } } // lowercase chars of $firstword for comparison with article list $firstword = strtolower($firstword); // see if first word is in the list of articles and not an exception $isan_article = !$isan_exception && isset($article[$firstword]); // if article then $nonfilingchars should match $ind if ($isan_article) { // account for quotes, apostrophes, parens, or brackets before 2nd word if (strlen($separator) && preg_match('/^[ \(\)\[\]\'"\-]+/', $etc)) { while (preg_match('/^[ "\'\[\]\(\)*]/', $etc)) { $nonfilingchars++; $etc = preg_replace('/^[ "\'\[\]\(\)*]/', '', $etc); } } if ($nonfilingchars != $ind) { $this->warn( $tagNo . ": First word, $firstword, may be an article, check " . "$first_or_second indicator ($ind)." ); } } else { // not an article so warn if $ind is not 0 if ($ind != '0') { $this->warn( $tagNo . ": First word, $firstword, does not appear to be an " . "article, check $first_or_second indicator ($ind)." ); } } } // }}} // {{{ parseRules() /** * Support method for constructor to load MARC rules. * * @return void */ protected function parseRules() { // Break apart the rule data on line breaks: $lines = explode("\n", $this->getRawRules()); // Each group of data is split by a blank line -- process one group // at a time: $currentGroup = array(); foreach ($lines as $currentLine) { if (empty($currentLine) && !empty($currentGroup)) { $this->processRuleGroup($currentGroup); $currentGroup = array(); } else { $currentGroup[] = preg_replace("/\s+/", " ", $currentLine); } } // Still have unprocessed data after the loop? Handle it now: if (!empty($currentGroup)) { $this->processRuleGroup($currentGroup); } } // }}} // {{{ processRuleGroup() /** * Support method for parseRules() -- process one group of lines representing * a single tag. * * @param array $rules Rule lines to process * * @return void */ protected function processRuleGroup($rules) { // The first line is guaranteed to exist and gives us some basic info: list($tag, $repeatable, $description) = explode(' ', $rules[0]); $this->rules[$tag] = array( 'repeatable' => $repeatable, 'desc' => $description ); // We may or may not have additional details: for ($i = 1; $i < count($rules); $i++) { list($key, $value, $lineDesc) = explode(' ', $rules[$i] . ' '); if (substr($key, 0, 3) == 'ind') { // Expand ranges: $value = str_replace('0-9', '0123456789', $value); $this->rules[$tag][$key] = array( 'values' => $value, 'hr_values' => $this->getHumanReadableIndicatorValues($value), 'desc'=> $lineDesc ); } else { if (strlen($key) <= 1) { $this->rules[$tag]['sub' . $key] = array( 'repeatable' => $value, 'desc' => $lineDesc ); } elseif (strstr($key, '-')) { list($startKey, $endKey) = explode('-', $key); for ($key = $startKey; $key <= $endKey; $key++) { $this->rules[$tag]['sub' . $key] = array( 'repeatable' => $value, 'desc' => $lineDesc ); } } } } } // }}} // {{{ getHumanReadableIndicatorValues() /** * Turn a set of indicator rules into a human-readable list. * * @param string $rules Indicator rules * * @return string */ protected function getHumanReadableIndicatorValues($rules) { // No processing needed for blank rule: if ($rules == 'blank') { return $rules; } // Create string: $string = ''; $length = strlen($rules); for ($i = 0; $i < $length; $i++) { $current = substr($rules, $i, 1); if ($current == 'b') { $current = 'blank'; } $string .= $current; if ($length - $i == 2) { $string .= ' or '; } else if ($length - $i > 2) { $string .= ', '; } } return $string; } // }}} // {{{ getRawRules() /** * Support method for parseRules() -- get the raw rules from MARC::Lint. * * @return string */ protected function getRawRules() { // When updating rules, don't forget to escape the dollar signs in the text! // It would be simpler to change from HEREDOC to NOWDOC syntax, but that // would raise the requirements to PHP 5.3. // @codingStandardsIgnoreStart return << * @author Dan Scott * @copyright 2003-2008 Oy Realnode Ab, Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id$ * @link http://pear.php.net/package/File_MARC */ // {{{ class File_MARC_Subfield /** * The File_MARC_Subfield class represents a single subfield in a MARC * record field. * * Represents a subfield within a MARC field and implements all management * functions related to a single subfield. This class also implements * the possibility of duplicate subfields within a single field, for example * 650 _z Test1 _z Test2. * * @category File_Formats * @package File_MARC * @author Christoffer Landtman * @author Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARC_Subfield { // {{{ properties /** * Subfield code, e.g. _a, _b * @var string */ protected $code; /** * Data contained by the subfield * @var string */ protected $data; /** * Position of the subfield * @var int */ protected $position; // }}} // {{{ Constructor: function __construct() /** * File_MARC_Subfield constructor * * Create a new subfield to represent the code and data * * @param string $code Subfield code * @param string $data Subfield data */ function __construct($code, $data) { $this->code = $code; $this->data = $data; } // }}} // {{{ Destructor: function __destruct() /** * Destroys the subfield */ function __destruct() { $this->code = null; $this->data = null; $this->position = null; } // }}} // {{{ Explicit destructor: function delete() /** * Destroys the subfield * * @return true */ function delete() { $this->__destruct(); } // }}} // {{{ getCode() /** * Return code of the subfield * * @return string Tag name */ function getCode() { return (string)$this->code; } // }}} // {{{ getData() /** * Return data of the subfield * * @return string data */ function getData() { return (string)$this->data; } // }}} // {{{ getPosition() /** * Return position of the subfield * * @return int data */ function getPosition() { return $this->position; } // }}} // {{{ __toString() /** * Return string representation of subfield * * @return string String representation */ public function __toString() { $pretty = '[' . $this->getCode() . ']: ' . $this->getData(); return $pretty; } // }}} // {{{ toRaw() /** * Return the USMARC representation of the subfield * * @return string USMARC representation */ function toRaw() { $result = File_MARC::SUBFIELD_INDICATOR.$this->code.$this->data; return (string)$result; } // }}} // {{{ setCode() /** * Sets code of the subfield * * @param string $code new code for the subfield * * @return string code */ function setCode($code) { if ($code) { // could check more stringently; m/[a-Z]/ or the likes $this->code = $code; } else { // code must be _something_; raise error return false; } return true; } // }}} // {{{ setData() /** * Sets data of the subfield * * @param string $data new data for the subfield * * @return string data */ function setData($data) { $this->data = $data; return true; } // }}} // {{{ setPosition() /** * Sets position of the subfield * * @param string $pos new position of the subfield * * @return void */ function setPosition($pos) { $this->position = $pos; } // }}} // {{{ isEmpty() /** * Checks whether the subfield is empty or not * * @return bool True or false */ function isEmpty() { // There is data if (strlen($this->data)) { return false; } // There is no data return true; } // }}} } // }}} PK!9g4xUxU Record.phpnu[PK!(#~ UException.phpnu[PK!ShhusList.phpnu[PK!+ Field.phpnu[PK!IC(A(ALint/CodeData.phpnu[PK!RA;A;Data_Field.phpnu[PK!lz`&Control_Field.phpnu[PK!Ɍ599Z8Lint.phpnu[PK!7*c ]rSubfield.phpnu[PK [