/home/a/aquarion/sites/www.aquarionics.com/epistula/include/xfml.inc
All my code (That is, anything not in the "Others" list on the right) is BSD licenced.
You can also view this page as text/plain or colour-coded source
<?PHP
/*******************************************************************************
XFML Class
********************************************************************************
Create XFML files
$Id: xfml.inc,v 1.1.1.1 2004/05/16 17:39:19 aquarion Exp $
$log$
*******************************************************************************/
class xfml {
var $editor;
var $licence;
var $facet;
var $topic;
var $page;
function xfml() {
global $_EP;
$this->editor = array(
'name' => $_EP['adminname'],
'url' => $_EP['url'],
'email' => $_EP['admin']
);
$this->licence = array("text" => "This map may be freely downloaded and viewed, but cannot be republished without permission from the owner", "name" => "Basic Licence");
}
function build(){
global $_EP;
$out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
."<?xml-stylesheet type=\"text/xsl\" href=\"/assets/alter.xsl\"?>"
."<xfml version=\"1.0\" url=\"http://xfml.org/spec/example.xml\" language=\"en-gb\">\n"
."<!--This document conforms to XFML Core. See http://purl.oclc.org/NET/xfml/core/-->\n"
."<mapInfo>\n"
."\t<managingEditor>\n"
."\t\t<name>".$this->editor['name']."</name>\n"
."\t\t<email>".$this->editor['email']."</email>\n"
."\t\t<url>".$this->editor['url']."</url>\n"
."\t</managingEditor>\n"
."\t<webMaster>\n"
."\t\t<name>".$_EP['adminname']."</name>\n"
."\t\t<email>".$_EP['admin']."</email>\n"
."\t\t<url>".$_EP['url']."</url>\n"
."\t</webMaster>\n"
."\t<publisher>\n"
."\t\t<name>".$_EP['book']."</name>\n"
."\t\t<url>".$_EP['url']."</url>\n"
."\t</publisher>\n"
# ."\t<license>\n"
# ."\t<text>".$this->licence['text']."</text>\n"
# ."\t<name>".$this->licence['name']."</name>\n"
# ."\t</license>\n"
."\t<generator>\n"
."\t\t<name>Epistula/".$_EP['version']."</name>\n"
."\t\t<url>http://www.aquarionics.com/projects/epistula</url>\n"
."\t</generator>\n"
."</mapInfo>\n";
foreach ($this->facet as $id => $facet){
// $xfml->facet[] = array('id' => "id", 'name' => "Name");
$out .= "<facet id=\"".$id."\">".$facet['name']."</facet>\n";
}
foreach ($this->topic as $id => $topic){
/* $xfml->topic[] = array(
'id' => "Identifyer, Cannot be number",
'facetid' = 'Facet we belong to',
'name' => "Name of Topic",
['parent' => "Parent topic id",]
['description' => "Description" ,]
'connect' => array ('url of topic to link to http://map#topicid', (repeat)),
'psi' => array ('published subject indicator concept. (Unique per topic)', (repeat)),
);*/
if (isset($topic['parent'])){
$parent = " parentTopicid=\"".$topic['parent']."\"";
} else {
$parent = "";
}
$out .= "<topic id=\"".$id."\" facetid=\"".$topic['facetid']."\"".$parent.">\n"
. "\t<name>".$topic['name']."</name>\n";
if (isset($topic['description'])){
$out .= "\t<description>".preg_replace("/&/","&",$topic['description'])."</description>\n";
}
if (count($topic['connect']) != 0){
foreach ($topic['connect'] as $connect){
$out .= "\t<connect>".$connect."</connect>\n";
}
}
if (count($topic['psi']) != 0){
foreach ($topic['psi'] as $psi){
$out .= "\t<psi>".$psi."</psi>\n";
}
}
$out .= "</topic>\n";
}
foreach ($this->page as $page){
$out .= "<page url=\"".$page['url']."\">\n"
. "\t<title>".$page['title']."</title>\n";
if (count($page['occour']) != 0){
foreach ($page['occour'] as $occour){
$out .= "\t<occurrence topicid=\"".$occour['topic']."\" strength=\"".$occour['strength']."\" />\n";
}
}
$out .= "</page>\n";
}
$out .= "</xfml>";
return $out;
} // End build()
}
preg_match("/(.*)\.xfml$/",$wanted[2],$chapter);
$chapter = $chapter[1];
if (!in_array($chapter, $types)){
if ($wanted[2] == ""){
$page->title = "XFML Files";
foreach ($types as $type){
$xfmlfiles[] = array('name' => $type, 'link' => $type.".xfml");
}
$page->content .= $page->item($page->menu($xfmlfiles));
#$page->content .= "One day there will be a menu here ($chapter)";
} else {
$page->status=404;
}
} else {
$xfml = new xfml;
$xfml->facet['month'] = array('name' => "Month Posted");
# $xfml->facet['week'] = array('id' => "week", 'name' => "Week Posted");
$xfml->facet['category'] = array('name' => "Categories Posted To");
$xfml->facet['location'] = array('name' => "Location posted from");
$xfml->facet['author'] = array('name' => "Author");
$query = "select * from location";
$result = safequery($query);
while ($row = mysql_fetch_assoc($result)){
$topic = array(
'facetid' => 'location',
'name' => htmlentities(decodeHTML($row['name'])),
'description' => $row['name'] ,
# 'connect' => array ('url of topic to link to http://map#topicid', (repeat)),
# 'psi' => array ('published subject indicator concept. (Unique per topic)', (repeat)),
);
$connect = array();
foreach ($types as $type){
if ($type != $chapter){
$connect[] = $_EP['url']."/meta/xfml/".$type.".xfml#location".$row['id'];
}
}
$topic['connect'] = $connect;
#$topic['psi'] = array($_EP['url']."/category/".ep_encode($row['name']));
$xfml->topic[$row['latlong']] = $topic;
}
mysql_free_result($result);
$query = "select * from category";
$result = safequery($query);
while ($row = mysql_fetch_assoc($result)){
$topic = array(
'facetid' => 'category',
'name' => htmlentities(decodeHTML($row['name'])),
'description' => $row['description'] ,
# 'connect' => array ('url of topic to link to http://map#topicid', (repeat)),
# 'psi' => array ('published subject indicator concept. (Unique per topic)', (repeat)),
);
if ($row['parent'] != 0){
$topic['parent'] = "cat".$row['parent'];
}
$connect = array();
foreach ($types as $type){
if ($type != $chapter){
$connect[] = $_EP['url']."/meta/xfml/".$type.".xfml#cat".$row['id'];
}
}
$topic['connect'] = $connect;
$topic['psi'] = array($_EP['url']."/category/".ep_encode($row['name']));
$xfml->topic["cat".$row['id']] = $topic;
}
mysql_free_result($result);
$query = "select *, unix_timestamp(date_created) as epoch from ".$chapter;#." limit 100";
$result = safequery($query);
while ($row = mysql_fetch_assoc($result)){
$monthid = date("MY",$row['epoch']);
if (!isset($xfml->topic[$monthid])){
$topic = array(
'facetid' => 'month',
'name' => date("F Y",$row['epoch']),
'description' => "Posts during ".date("F Y",$row['epoch']) ,
'parent' => "year".date("Y",$row['epoch']),
# 'connect' => array ('url of topic to link to http://map#topicid', (repeat)),
'psi' => array ($_EP['url'].'/archive/'.$chapter.'/'.date("Y/m",$row['epoch'])),
);
if (!isset($xfml->topic["year".date("Y",$row['epoch'])])){
$topic = array(
'facetid' => 'month',
'name' => date("F Y",$row['epoch']),
'description' => "Posts made during ".date("Y",$row['epoch']),
);
}
if ($row['parent'] != 0){
$topic['parent'] = "cat".$parent['parent'];
}
$connect = array();
foreach ($types as $type){
if ($type != $chapter){
$connect[] = $_EP['url']."/meta/xfml/".$type.".xfml#".$monthid;
}
}
$topic['connect'] = $connect;
$topic['psi'] = array($_EP['url']."/archive/".date("Y/m"));
$xfml->topic[$monthid] = $topic;
}
$Page = array (
'url' => getPermalink($chapter, $row['id']),
'title' => htmlentities(decodeHTML($row['title'])),
);
$occour = array();
$cats = getCat($chapter,$row['id']);
foreach ($cats as $cat){
$occour[] = array('topic' => "cat".$cat['id'], 'strength' => 1);
}
$Page['occour'] = $occour;
$locid = $row['location'];
$Page['occour'][] = array('topic' => $monthid, 'strength' => 1);
$Page['occour'][] = array('topic' => $locid, 'strength' => 1);
$xfml->page[] = $Page;
}
$out = $xfml->build();
$finalOutput = print_r_to_var($out);
}
?>
Using a heavily customised version of Tom's PHPCode2ValidXHTML Thing