3 * RAP - RDF API for PHP
6 !Why not bare bones RAP?
7 RAP is too hard to work with, it provides all of the needed power and functionality, but this means that it tends to get a bit complex to deal with.
9 !What does XML_FOAF do?
10 Its a parser and creator of FOAF files. It was written by [David Shafik|http://beta.plink.org/profile/26b2e3834d83a5ca3fc81e5a942862f7a2bcb653] (Plink), and is currently not ''stable''.
12 Its really easy to use:
15 require_once 'XML/FOAF.php';
17 $foaf = new XML_FOAF();
19 $foaf->newAgent('person');
20 $foaf->setName('Davey Shafik');
21 $foaf->setTitle('Mr');
22 $foaf->setFirstName('Davey');
23 $foaf->setSurname('Shafik');
24 $foaf->addMbox('mailto:davey@php.net',TRUE); // see also: XML_FOAF::setMboxSha1Sum();
25 $foaf->addHomepage('http://pixelated-dreams.com/~davey/');
26 $foaf->addWeblog('http://pixelated-dreams.com/blog');
27 $foaf->addImg('http://pixelated-dreams.com/~davey/me.jpg');
28 $foaf->addPage('http://pixelated-dreams.com/~davey/CV','Curriculum Vitae','Davey Shafiks Curriculum Vitae');
29 $foaf->addPage('http://www.php-mag.net/itr/online_artikel/psecom,id,484,nodeid,114.html','Sticking The Fork In','Creating Daemons in PHP');
30 $foaf->addPage('http://pawscon.com/', 'PHP and Web Standards Conference UK 2004', 'A Conference dedicated to PHP, Web Standards and the Semantic Web');
31 $foaf->addPhone('07776293539');
32 $foaf->addJabberID('fractured_realities@jabber.org');
33 $foaf->addTheme('http://php.net');
34 $foaf->addOnlineAccount('Davey','http://freenode.info','http://xmlns.com/foaf/0.1/OnlineChatAccount');
35 $foaf->addOnlineGamingAccount('Davey_S','http://www.there.com');
36 $foaf->addWorkplaceHomepage('http://www.pawscon.com');
37 $foaf->addSchoolHomepage('http://www.nobel.herts.sch.uk/');
38 $foaf->addInterest('http://xmlns.com/foaf/0.1/');
39 $foaf->addFundedBy('http://synapticmedia.net');
40 $foaf->addLogo('http://paws.davey.is-a-geek.com/images/paws.jpg');
41 $foaf->setBasedNear(52.565475,-1.162895);
42 $foaf->addDepiction('http://example.org/depiction/');
43 $foaf->addDepiction('http://example.org/depiction/2');
45 // Content of a <foaf:knows><foaf:Person /></foaf:knows>
46 $matt = new XML_FOAF();
47 $matt->newAgent('person');
48 $matt->setName('Matt McClanahan');
49 $matt->addNick('mattmcc');
50 $matt->addMboxSha1Sum('0cd5f54daf6aa59d1071ea6bf2973e0171ece606',TRUE);
51 $matt->addSeeAlso('http://mmcc.cx/foaf.rdf');
52 $matt->addJabberID('mattmcc@jabber.com');
53 $matt->addOnlineChatAccount('mattmcc','http://freenode.info','http://xmlns.com/foaf/0.1/OnlineChatAccount');
55 $foaf->addKnows($matt);
57 // Another <foaf:knows><foaf:Person /></foaf:knows>
59 Although we use another instance of XML_FOAF, we could re-use
60 the one from above ($matt)
62 $libby = new XML_FOAF();
63 $libby->newAgent('person');
64 $libby->setName('Libby Miller');
65 $libby->addMbox('mailto:libby.miller@bristol.ac.uk');
66 $libby->addSeeAlso('http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf');
69 $foaf->addKnows($libby);
71 $mcd = new XML_FOAF();
72 $mcd->newAgent('Organization');
73 $mcd->setName('McDonalds');
74 $mcd->addHomepage('http://www.mcdonalds.com/');
76 $foaf->addKnows($mcd);
78 if (!isset($_GET['xml'])) {
79 echo "<pre>" .htmlentities($foaf->get()). "</pre>";
81 show_source(__FILE__);
83 header('Content-Type: text/xml');
88 <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:foaf="http://xmlns.com/foaf/0.1/"
89 xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
90 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
91 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
93 <foaf:name>Davey Shafik</foaf:name>
94 <foaf:title>Mr</foaf:title>
95 <foaf:firstName>Davey</foaf:firstName>
96 <foaf:surname>Shafik</foaf:surname>
97 <foaf:mbox_sha1sum>26b2e3834d83a5ca3fc81e5a942862f7a2bcb653</foaf:mbox_sha1sum>
98 <foaf:homepage rdf:resource="http://pixelated-dreams.com/~davey/" />
99 <foaf:img rdf:resource="http://pixelated-dreams.com/~davey/me.jpg" />
101 <foaf:Document rdf:about="http://pixelated-dreams.com/~davey/CV/">
102 <dc:title>Curriculum Vitae</dc:title>
105 <foaf:phone rdf:resource="tel:07776293539" />
106 <foaf:workplaceHomepage rdf:resource="http://www.pawscon.com" />
107 <foaf:schoolHomepage rdf:resource="http://www.nobel.herts.sch.uk/" />
108 <foaf:interest rdf:resource="http://xmlns.com/foaf/0.1/" />
110 <geo:Point geo:lat="52.565475" geo:long="-1.162895" />
114 <foaf:name>Matt McClanahan</foaf:name>
115 <foaf:nick>mattmcc</foaf:nick>
116 <foaf:mbox_sha1sum>0cd5f54daf6aa59d1071ea6bf2973e0171ece606</foaf:mbox_sha1sum>
117 <rdfs:seeAlso rdf:resource="http://mmcc.cx/foaf.rdf" />
122 <foaf:name>Libby Miller</foaf:name>
123 <foaf:mbox rdf:resource="mailto:libby.miller@bristol.ac.uk" />
124 <rdfs:seeAlso rdf:resource="http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf" />
134 Parsing isn't so hard either:
136 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
137 <html xmlns="http://www.w3.org/1999/xhtml">
139 <title>XML_FOAF_Parser Example</title>
140 <meta name="Author" content="" />
141 <meta name="Keywords" content="" />
142 <meta name="Description" content="" />
143 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
144 <style type="text/css">
145 table,th,td { border: 1px solid black; }
150 // Get our FOAF File from $_GET['foaf']
151 if (!isset($_REQUEST['foaf'])) {
152 echo "<strong>Please enter a FOAF file below";
154 $foaf = file_get_contents($_REQUEST['foaf']);
156 // Require the XML_FOAF_Parser class
157 require_once 'XML/FOAF/Parser.php';
159 // Create new Parser object
160 $parser = new XML_FOAF_Parser;
163 echo '<h1>XML_FOAF_Parser Example</h1>';
164 if (isset($_REQUEST['xml'])) {
165 echo '<pre>' .htmlentities($foaf). '</pre>';
168 // Parser our FOAF in $foaf
169 $parser->parseFromMem($foaf);
171 if (isset($_REQUEST['table'])) {
172 // Show our FOAF as an HTML table
173 echo "<h2>FOAF as HTML Table</h2>";
174 echo $parser->toHTML($parser->toArray());
177 if (isset($_REQUEST['array'])) {
178 // Show the contents of the FOAF Data array
179 echo "<h2>FOAF as Array</h2>";
181 var_dump($parser->toArray());
186 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
188 <label>FOAF File URI: <input type="text" name="foaf" value="<?php echo(@$_REQUEST['foaf']) ?>" /></label>
190 Show XML: <input type="checkbox" name="xml" value="true" />
192 Show as HTML Table: <input type="checkbox" name="table" value="true" checked="checked" />
194 Show as Array: <input type="checkbox" name="array" value="true" />
196 <input type="submit" value="Parse FOAF!" />
203 !How will the plugin(s) work?
204 # FoafViewerPlugin is embedded in a normal phpwiki page, with default arguments coming from $_GET varibles.
205 # FoafMakePlugin will get some kind of user id from the database, and retrieve any stored information about the user - outputting as FOAF.
207 !Installing PEAR / XML_FOAF
208 The XML_FOAF pear library will not be included with phpwiki, so you have to install the pear
209 library by your own and be sure that the pear path is in the include_path.
211 Reason: XML_FOAF is based on XML_Parser and XML_Tree, but phpwiki uses its own XML parser and XML
212 tree representation, so it would be unneccesary and incompatible duplication of the same thing.
214 See: http://pear.php.net/package/XML_FOAF
215 PHP Version: PHP 4.3.0 or newer
216 PEAR Package: XML_Tree 1.1 or newer
217 PEAR Package: XML_Beautifier 0.2.2 or newer
219 Pear is dead simple to install.
222 Start > Run > Command.com
227 Follow your nose for a bit. I'm sure you can blunder through it. Next, install the needed modules.
229 pear download XML_FOAF
230 pear download XML_Tree
231 pear download XML_Beautifier
233 pear install XML_Tree
234 pear install XML_Beautifier
235 pear install XML_FOAF
237 Now, chances are, you won't get away with it all this easy, but if you can't get pear to install XML_FOAF (no ''stable'' package available), then follow these steps next
238 # Download [XML_FOAF 0.2|http://pear.php.net/get/XML_FOAF-0.2.tgz]
239 # Extract XML_FOAF-0.2.tgz/XML_FOAF-0.2/FOAF/ to C:\php\pear\XML\FOAF
240 # Extract documentation to c:\php\pear\docs\
242 One other thing: make sure your php.ini points to the right location in the ''include_path'' directive!