Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Holek/cite-gen
base: 0d25b1d437
...
head fork: Holek/cite-gen
compare: e90a081977
  • 7 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
View
28 includes/abstractClasses.php
@@ -48,18 +48,22 @@ static function prepareInput($input)
*/
abstract class Parser
{
- function __construct($input) {}
- function getTitle() {}
- function getOutput() {}
- function getErrors() {}
+ protected $title = false;
+ protected $errors = array();
- /**
- * Reduce memory usage
- */
- function __destruct() {
- foreach ( $this as $name => $value ) {
- unset( $this->$name );
- }
+ public function __construct($input) {
+ $this->fetch($input);
+ }
+
+ abstract public function fetch($identifier);
+
+ public function getTitle() {
+ return $this->title;
+ }
+ abstract public function getOutput();
+
+ public function getErrors() {
+ return $this->errors;
}
}
@@ -110,4 +114,4 @@ public function fetch($id) {}
public function save() {}
}
-?>
+?>
View
5 index.php
@@ -28,6 +28,7 @@
// Functions, abstract classes
require_once('./includes/Functions.php');
require_once('./includes/abstractClasses.php');
+require_once('./parsers/ISBN/ISBNBaseParser.php');
// I18N files
require_once('./messages/Names.php');
@@ -229,9 +230,9 @@
foreach($selectedParsers[$inputEntry['parser']] as $parserClass)
{
$parserRaw = new $parserClass($inputEntry['data']);
- $debug .= "Using $parserClass for ".$inputEntry['data'].": Got title '".$parserRaw->getTitle()."'\n";
if ($parserRaw->getTitle())
{
+ $debug .= "Using $parserClass for \"".$inputEntry['data']."\": Got title \"".$parserRaw->getTitle()."\"\n";
$templateRaw = $parserRaw->getOutput();
$template = $outputTemplates[$inputEntry['parser']];
@@ -241,6 +242,8 @@
unset($parserRaw,$templateRaw,$template);
break;
+ } else {
+ $debug .= "$parserClass does not seem to have entry for \"".$inputEntry['data']."\"\n";
}
}
}
View
79 parsers/ISBN/Congress.php
@@ -8,29 +8,9 @@
* @license GNU General Public Licence 2.0 or later
*/
-class Congress extends Parser {
+class Congress extends ISBNBaseParser {
- protected $website;
-
- private $title;
- private $lastNames = array();
- private $firstNames = array();
- private $date;
- private $publisher;
- private $place;
- private $source;
- private $ISBN;
-
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($ISBN)
+ public function fetch($ISBN)
{
$url = @file_get_contents('http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&maximumRecords=1&recordSchema=dc&query='.$ISBN);
if (!$url)
@@ -72,59 +52,8 @@ public function __construct($ISBN)
}
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
+ protected function getSiteLanguage() {
+ return 'en';
}
-
- /**
- * Book info getter
- *
- * @return array
- */
- public function getOutput()
- {
- // Array consisting of values, which keys are named
- // after English Wikipedia {{Cite book}} template,
- // with one exception: array '__names' consisting of
- // subarrays 'last' and 'first'.
- // These are equivalents of 'last' and 'first' fields,
- // and these are arrays; some Wikipedias
- // (ie. Polish) are using multiple author fields.
- // In that case each last name in array has first name
- // at the same index as it (ie. $this->lastNames[3]
- // has to correspond with $this->firstNames[3];
- // it has to be the same author)
-
- // Here you can also sort which fields are meant to be shown first
- // at the generated template. Simply the first one goes first. ;)
- return array(
- '__names' => array(
- 'last' => $this->lastNames,
- 'first' => $this->firstNames
- ),
- 'title' => $this->title,
- 'date' => $this->date,
- 'publisher' => $this->publisher,
- 'location' => translateWithInterwiki($this->place,'en'),
- 'isbn' => $this->ISBN,
- '__sourceurl' => $this->source
- );
- }
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
79 parsers/ISBN/DNB.php
@@ -8,29 +8,9 @@
* @license GNU General Public Licence 2.0 or later
*/
-class DNB extends Parser {
+class DNB extends ISBNBaseParser {
- protected $website;
-
- private $title;
- private $lastNames = array();
- private $firstNames = array();
- private $date;
- private $publisher;
- private $place;
- private $source;
- private $ISBN;
-
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($ISBN)
+ public function fetch($ISBN)
{
$fh = fopen($this->source = 'https://portal.d-nb.de/opac.htm?method=showFullRecord&currentPosition=0&currentResultId='.$ISBN.'%2526any','r');
if ($fh) // if file found
@@ -73,60 +53,9 @@ public function __construct($ISBN)
}
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
- }
-
- /**
- * Book info getter
- *
- * @return array
- */
- public function getOutput()
- {
- // Array consisting of values, which keys are named
- // after English Wikipedia {{Cite book}} template,
- // with one exception: array '__names' consisting of
- // subarrays 'last' and 'first'.
- // These are equivalents of 'last' and 'first' fields,
- // and these are arrays; some Wikipedias
- // (ie. Polish) are using multiple author fields.
- // In that case each last name in array has first name
- // at the same index as it (ie. $this->lastNames[3]
- // has to correspond with $this->firstNames[3];
- // it has to be the same author)
-
- // Here you can also sort which fields are meant to be shown first
- // at the generated template. Simply the first one goes first. ;)
- return array(
- '__names' => array(
- 'last' => $this->lastNames,
- 'first' => $this->firstNames
- ),
- 'title' => $this->title,
- 'date' => $this->date,
- 'publisher' => $this->publisher,
- 'location' => translateWithInterwiki($this->place,'de'),
- 'isbn' => $this->ISBN,
- '__sourceurl' => $this->source
- );
+ protected function getSiteLanguage() {
+ return 'de';
}
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
57 parsers/ISBN/ISBNBaseParser.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * {{Cite book}} generator.
+ *
+ * @addtogroup Includes
+ * @author Marcin Cieślak
+ * @copyright © 2012 Marcin Cieślak
+ * @license GNU General Public Licence 2.0 or later
+ */
+
+abstract class ISBNBaseParser extends Parser {
+ protected $lastNames = array();
+ protected $firstNames = array();
+ protected $date;
+ protected $publisher;
+ protected $place;
+ protected $source;
+ protected $ISBN;
+
+
+ /**
+ * Book info getter
+ *
+ * @return array
+ */
+ public function getOutput()
+ {
+ // Array consisting of values, which keys are named
+ // after English Wikipedia {{Cite book}} template,
+ // with one exception: array '__names' consisting of
+ // subarrays 'last' and 'first'.
+ // These are equivalents of 'last' and 'first' fields,
+ // and these are arrays; some Wikipedias
+ // (ie. Polish) are using multiple author fields.
+ // In that case each last name in array has first name
+ // at the same index as it (ie. $this->lastNames[3]
+ // has to correspond with $this->firstNames[3];
+ // it has to be the same author)
+
+ // Here you can also sort which fields are meant to be shown first
+ // at the generated template. Simply the first one goes first. ;)
+ return array(
+ '__names' => array(
+ 'last' => $this->lastNames,
+ 'first' => $this->firstNames
+ ),
+ 'title' => $this->title,
+ 'date' => $this->date,
+ 'publisher' => $this->publisher,
+ 'location' => translateWithInterwiki($this->place, $this->getSiteLanguage()),
+ 'isbn' => $this->ISBN,
+ '__sourceurl' => $this->source
+ );
+ }
+
+ abstract protected function getSiteLanguage();
+}
View
88 parsers/ISBN/Nukat.php
@@ -8,29 +8,9 @@
* @license GNU General Public Licence 2.0 or later
*/
-class Nukat extends Parser {
+class Nukat extends ISBNBaseParser {
- protected $website;
-
- private $title;
- private $lastNames = array();
- private $firstNames = array();
- private $date;
- private $publisher;
- private $place;
- private $source;
- private $ISBN;
-
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($ISBN)
+ public function fetch($ISBN)
{
global $debug;
$ini = parse_ini_file('./parsers/ISBN/Nukat.ini');
@@ -40,7 +20,7 @@ public function __construct($ISBN)
{
$this->errors[]= array('base-disabled','NUKAT');
}
- if (strpos($data, 'Brak wyników wyszukiwania') === false)
+ if (strpos($data, '<!-- Bib record -->') !== false)
{
$array = array();
preg_match_all(',
@@ -54,14 +34,11 @@ public function __construct($ISBN)
</td>
</tr>,m', $data, $temp);
-
for ($i = 0; $i < count( $temp[1] ); $i ++) {
$array[ mb_strtolower($temp[1][$i]) ] = trim(preg_replace( array(
'@<a[^>]*?>@siu', '@</a>@siu'), '', $temp[2][$i]
));
}
- $debug .= var_export($array, TRUE);
-
$this->title = preg_replace('#/.*$#', '', $array['tytuł']);
preg_match('#(.*?), (.*?) \(#', $array['autor'], $author);
@@ -76,67 +53,14 @@ public function __construct($ISBN)
$this->source = $address . "&skin=reader";
$this->ISBN = $ISBN;
- }
- else
- {
+ } else {
$this->title = false;
}
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
+ protected function getSiteLanguage() {
+ return 'pl';
}
-
- /**
- * Book info getter
- *
- * @return array
- */
- public function getOutput()
- {
- // Array consisting of values, which keys are named
- // after English Wikipedia {{Cite book}} template,
- // with one exception: array '__names' consisting of
- // subarrays 'last' and 'first'.
- // These are equivalents of 'last' and 'first' fields,
- // and these are arrays; some Wikipedias
- // (ie. Polish) are using multiple author fields.
- // In that case each last name in array has first name
- // at the same index as it (ie. $this->lastNames[3]
- // has to correspond with $this->firstNames[3];
- // it has to be the same author)
-
- // Here you can also sort which fields are meant to be shown first
- // at the generated template. Simply the first one goes first. ;)
- return array(
- '__names' => array(
- 'last' => $this->lastNames,
- 'first' => $this->firstNames
- ),
- 'title' => $this->title,
- 'date' => $this->date,
- 'publisher' => $this->publisher,
- 'location' => translateWithInterwiki($this->place,'pl'),
- 'isbn' => $this->ISBN,
- '__sourceurl' => $this->source
- );
- }
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
79 parsers/ISBN/Warsaw.php
@@ -8,29 +8,9 @@
* @license GNU General Public Licence 2.0 or later
*/
-class Warsaw extends Parser {
+class Warsaw extends ISBNBaseParser {
- protected $website;
-
- private $title;
- private $lastNames = array();
- private $firstNames = array();
- private $date;
- private $publisher;
- private $place;
- private $source;
- private $ISBN;
-
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($ISBN)
+ public function fetch($ISBN)
{
$url = @file_get_contents('http://alpha.bn.org.pl/search~S4*pol?/i/i/,,,/marc&FF=i'.$ISBN);
if (!$url)
@@ -146,59 +126,8 @@ private function getParamsArray($data)
return $array;
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
+ protected function getSiteLanguage() {
+ return 'pl';
}
-
- /**
- * Book info getter
- *
- * @return array
- */
- public function getOutput()
- {
- // Array consisting of values, which keys are named
- // after English Wikipedia {{Cite book}} template,
- // with one exception: array '__names' consisting of
- // subarrays 'last' and 'first'.
- // These are equivalents of 'last' and 'first' fields,
- // and these are arrays; some Wikipedias
- // (ie. Polish) are using multiple author fields.
- // In that case each last name in array has first name
- // at the same index as it (ie. $this->lastNames[3]
- // has to correspond with $this->firstNames[3];
- // it has to be the same author)
-
- // Here you can also sort which fields are meant to be shown first
- // at the generated template. Simply the first one goes first. ;)
- return array(
- '__names' => array(
- 'last' => $this->lastNames,
- 'first' => $this->firstNames
- ),
- 'title' => $this->title,
- 'date' => $this->date,
- 'publisher' => $this->publisher,
- 'location' => translateWithInterwiki($this->place,'pl'),
- 'isbn' => $this->ISBN,
- '__sourceurl' => $this->source
- );
- }
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
83 parsers/ISBN/isbnDB.php
@@ -8,30 +8,11 @@
* @license GNU General Public Licence 2.0 or later
*/
-class isbnDB extends Parser {
+class isbnDB extends ISBNBaseParser {
- protected $website;
+ protected $refname;
- private $title;
- private $lastNames = array();
- private $firstNames = array();
- private $date;
- private $publisher;
- private $place;
- private $source;
- private $ISBN;
- private $refname;
-
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($ISBN)
+ public function fetch($ISBN)
{
// To connect to ISBNdb.com database
// you have to obtain you own key
@@ -95,60 +76,14 @@ public function __construct($ISBN)
}
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
+ protected function getSiteLanguage() {
+ return 'en';
}
- /**
- * Book info getter
- *
- * @return array
- */
- public function getOutput()
- {
- // Array consisting of values, which keys are named
- // after English Wikipedia {{Cite book}} template,
- // with one exception: array '__names' consisting of
- // subarrays 'last' and 'first'.
- // These are equivalents of 'last' and 'first' fields,
- // and these are arrays; some Wikipedias
- // (ie. Polish) are using multiple author fields.
- // In that case each last name in array has first name
- // at the same index as it (ie. $this->lastNames[3]
- // has to correspond with $this->firstNames[3];
- // it has to be the same author)
-
- // Here you can also sort which fields are meant to be shown first
- // at the generated template. Simply the first one goes first. ;)
- return array(
- '__names' => array(
- 'last' => $this->lastNames,
- 'first' => $this->firstNames
- ),
- 'title' => $this->title,
- 'date' => $this->date,
- 'publisher' => $this->publisher,
- 'location' => translateWithInterwiki($this->place,'en'),
- 'isbn' => $this->ISBN,
- '__sourceurl' => $this->source,
- '__refname' => $this->refname
- );
+ public function getOutput() {
+ $o = parent::getOutput();
+ $o['__refname'] = $this->refname;
+ return $o;
}
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
32 parsers/PMID/PMID.php
@@ -10,7 +10,6 @@
class PMID extends Parser {
- private $title;
private $lastNames = array();
private $firstNames = array();
private $journal;
@@ -24,16 +23,7 @@ class PMID extends Parser {
private $PMID;
private $refname;
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class isbnDB
- */
- public function __construct($PMID)
+ public function fetch($PMID)
{
$this->source = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id='.$PMID.'&retmode=xml';
$url = file_get_contents($this->source);
@@ -88,16 +78,6 @@ public function __construct($PMID)
}
}
- /**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
- }
-
/**
* Book info getter
*
@@ -138,15 +118,5 @@ public function getOutput()
'__sourceurl' => 'http://www.ncbi.nlm.nih.gov/pubmed/'.$this->PMID.'?dopt=Abstract'
);
}
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
-
}
?>
View
33 parsers/WWW/WWW.php
@@ -10,20 +10,10 @@
class WWW extends Parser {
- private $title;
private $refname;
private $url;
- /**
- * Array consisting of errors reported on the way
- * @var array
- */
- private $errors = array();
-
- /**
- * Constructor for objects of class WWW
- */
- public function __construct($url)
+ public function fetch($url)
{
$fh = fopen($url,'r');
if ($fh) // if file found
@@ -78,7 +68,7 @@ public function __construct($url)
}
if ($this->title != '')
{
- $this->url = $url;
+ $this->title = $url;
}
else
{
@@ -93,16 +83,6 @@ public function __construct($url)
}
/**
- * Title getter. Returns book title if found, FALSE if not found.
- *
- * @return mixed
- */
- public function getTitle()
- {
- return $this->title;
- }
-
- /**
* URL info getter
*
* @return array
@@ -118,14 +98,5 @@ public function getOutput()
'__sourceurl' => $this->url
);
}
-
- /**
- * Returns $errors.
- * @see isbnDB::$errors
- */
- public function getErrors()
- {
- return $this->errors;
- }
}
?>

No commit comments for this range

Something went wrong with that request. Please try again.