ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
ilRisReader Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilRisReader:

Public Member Functions

 __construct ($options=[])
 
 parseString (string $string)
 Parse a string of RIS data. More...
 
 getRecords ()
 

Data Fields

const RIS_EOL = "\r\n"
 
const LINE_REGEX = '/^(([A-Z1-9]{2})\s+-(.*))|(.*)$/'
 

Protected Member Functions

 parseArray (array $lines)
 Take an array of lines and parse them into an RIS record. More...
 
 cleanData (array &$lines)
 Clean up the data before processing. More...
 

Protected Attributes

array $data = []
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning This class has been adapted from the original RISReader class in the abandoned technosophos/LibRIS library. Many thanks to technosophos for the original work!

See also
https://github.com/technosophos/LibRIS/blob/master/src/LibRIS/RISReader.php

Definition at line 24 of file class.ilRisReader.php.

Constructor & Destructor Documentation

◆ __construct()

ilRisReader::__construct (   $options = [])

Definition at line 31 of file class.ilRisReader.php.

32  {
33  }

Member Function Documentation

◆ cleanData()

ilRisReader::cleanData ( array &  $lines)
protected

Clean up the data before processing.

Parameters
array$linesIndexed array of lines of data.

Definition at line 108 of file class.ilRisReader.php.

Referenced by parseArray().

108  : void
109  {
110  if ($lines === []) {
111  return;
112  }
113 
114  // Currently, we only need to strip a BOM if it exists.
115  // Thanks to Derik Badman (http://madinkbeard.com/) for finding the
116  // bug and suggesting this fix:
117  // http://blog.philipp-michels.de/?p=32
118  $first = $lines[0];
119  if (substr((string) $first, 0, 3) === pack('CCC', 0xef, 0xbb, 0xbf)) {
120  $lines[0] = substr((string) $first, 3);
121  }
122  }
+ Here is the caller graph for this function:

◆ getRecords()

ilRisReader::getRecords ( )

Definition at line 97 of file class.ilRisReader.php.

References $data.

97  : array
98  {
99  return $this->data;
100  }

◆ parseArray()

ilRisReader::parseArray ( array  $lines)
protected

Take an array of lines and parse them into an RIS record.

Definition at line 57 of file class.ilRisReader.php.

References cleanData(), and null.

Referenced by parseString().

57  : void
58  {
59  $recordset = [];
60 
61  // Do any cleaning and normalizing.
62  $this->cleanData($lines);
63 
64  $record = [];
65  $lastTag = null;
66  foreach ($lines as $line) {
67  $line = trim((string) $line);
68  $matches = [];
69 
70  preg_match(self::LINE_REGEX, $line, $matches);
71  if (!empty($matches[3])) {
72  $lastTag = $matches[2];
73  $record[$matches[2]][] = trim($matches[3]);
74  } // End record and prep a new one.
75  elseif (!empty($matches[2]) && $matches[2] === 'ER') {
76  $lastTag = null;
77  $recordset[] = $record;
78  $record = [];
79  } elseif (!empty($matches[4])) {
80  // Append to the last one.
81  // We skip leading info (like BOMs).
82  if (!empty($lastTag)) {
83  $lastEntry = count($record[$lastTag]) - 1;
84  // We trim because some encoders add tabs or multiple spaces.
85  // Standard is silent on how this should be handled.
86  $record[$lastTag][$lastEntry] .= ' ' . trim($matches[4]);
87  }
88  }
89  }
90  if ($record !== []) {
91  $recordset[] = $record;
92  }
93 
94  $this->data = $recordset;
95  }
cleanData(array &$lines)
Clean up the data before processing.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseString()

ilRisReader::parseString ( string  $string)

Parse a string of RIS data.

This will parse an RIS record into a representative data structure.

Parameters
string$stringRIS-formatted data in a string.
StreamContext$contextThe stream context (in desired) for handling the file.
Return values
arrayAn indexed array of individual sources, each of which is an associative array of entry details. (See LibRIS)

Definition at line 48 of file class.ilRisReader.php.

References parseArray().

48  : void
49  {
50  $contents = explode(self::RIS_EOL, $string);
51  $this->parseArray($contents);
52  }
parseArray(array $lines)
Take an array of lines and parse them into an RIS record.
+ Here is the call graph for this function:

Field Documentation

◆ $data

array ilRisReader::$data = []
protected

Definition at line 29 of file class.ilRisReader.php.

Referenced by getRecords().

◆ LINE_REGEX

const ilRisReader::LINE_REGEX = '/^(([A-Z1-9]{2})\s+-(.*))|(.*)$/'

Definition at line 27 of file class.ilRisReader.php.

◆ RIS_EOL

const ilRisReader::RIS_EOL = "\r\n"

Definition at line 26 of file class.ilRisReader.php.

Referenced by ilBiblRisFileReaderWrapper\parseContent().


The documentation for this class was generated from the following file: