Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3768947
book.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
book.php
View Options
<?php
class
Book
{
/**
* OCLC number
*/
public
$OCLC
;
public
function
queryWorldCatFromOCLC
()
{
$oclc
=
(
string
)(
int
)
$this
->
OCLC
;
$url
=
'http://www.worldcat.org/oclc/'
.
$oclc
;
$rdf
=
new
EasyRdf_Graph
(
$url
.
'.rdf'
);
$rdf
->
load
();
$resources
=
$rdf
->
resources
();
$book
=
$resources
[
$url
];
//Core info
$this
->
Title
=
(
string
)
$book
->
getLiteral
(
'schema:name'
);
$publisherData
=
$book
->
get
(
'schema:publisher'
);
if
(
$publisherData
)
{
$this
->
Publisher
=
(
string
)
$publisherData
->
get
(
'schema:name'
);
}
//Publishing date
$date
=
(
string
)
$book
->
getLiteral
(
'schema:datePublished'
);
if
(
strlen
(
$date
)
==
4
)
{
$this
->
YYYY
=
$date
;
}
else
{
echo
'<div class="alert-box">Publishing date: '
,
$date
,
" / check the template, the code doesn't know how to parse this format and only made a guess. "
,
'<a href="" class="close">×</a></div>'
;
$date
=
date_parse
(
$date
);
$this
->
YYYY
=
$date
[
'year'
];
$this
->
MM
=
$date
[
'month'
];
$this
->
DD
=
$date
[
'day'
];
}
//Authors
$this
->
Authors
=
[];
//TODO: look type mapping
$contributors
=
$book
->
allResources
(
'schema:contributor'
);
foreach
(
$contributors
as
$contributor
)
{
$this
->
Authors
[]
=
[
(
string
)
$contributor
->
get
(
'schema:givenName'
),
(
string
)
$contributor
->
get
(
'schema:familyName'
)
];
}
//Kludge for library:placeOfPublication
//We have generally two links, one for the city, one for the country.
//Only the city has a schema:name, the country is only a reference.
$rdf_content
=
file_get_contents
(
$url
.
'.rdf'
);
if
(
preg_match_all
(
'@<library:placeOfPublication rdf:resource="(.*)"/>@'
,
$rdf_content
,
$matches
))
{
foreach
(
$matches
[
1
]
as
$place
)
{
if
(
$cityCandidate
=
(
string
)
$resources
[
$place
]->
get
(
'schema:name'
))
{
$this
->
Place
=
$cityCandidate
;
break
;
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 25, 11:33 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260046
Default Alt Text
book.php (2 KB)
Attached To
Mode
rSTG Source templates generator
Attached
Detach File
Event Timeline
Log In to Comment