]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - doc/README.foaf
Allow bold, italics or underlined for numbers
[SourceForge/phpwiki.git] / doc / README.foaf
1 !FoaF
2 !Technology
3 * RAP - RDF API for PHP
4 * XML_FOAF, PEAR
5
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.
8
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''.
11
12 Its really easy to use:
13 <verbatim>
14 <?php
15 require_once 'XML/FOAF.php';
16 // Main FOAF
17 $foaf = new XML_FOAF();
18
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');
44
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');
54 // Add to Main FOAF
55 $foaf->addKnows($matt);
56
57 // Another <foaf:knows><foaf:Person /></foaf:knows>
58 /*
59 Although we use another instance of XML_FOAF, we could re-use
60 the one from above ($matt)
61 */
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');
67
68 // Add to Main FOAF
69 $foaf->addKnows($libby);
70
71 $mcd = new XML_FOAF();
72 $mcd->newAgent('Organization');
73 $mcd->setName('McDonalds');
74 $mcd->addHomepage('http://www.mcdonalds.com/');
75
76 $foaf->addKnows($mcd);
77
78 if (!isset($_GET['xml'])) {
79 echo "<pre>" .htmlentities($foaf->get()). "</pre>";
80 echo "<hr />";
81 show_source(__FILE__);
82 } else {
83 header('Content-Type: text/xml');
84 $foaf->dump();
85 }
86
87 /* Output
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#">
92 <foaf:Person>
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" />
100    <foaf:page>
101            <foaf:Document rdf:about="http://pixelated-dreams.com/~davey/CV/">
102                    <dc:title>Curriculum Vitae</dc:title>
103            </foaf:Document>
104    </foaf:page>
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/" />
109    <foaf:based_near>
110            <geo:Point geo:lat="52.565475" geo:long="-1.162895" />
111    </foaf:based_near>
112    <foaf:knows>
113            <foaf:Person>
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" />
118            </foaf:Person>
119    </foaf:knows>
120    <foaf:knows>
121            <foaf:Person>
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" />
125            </foaf:Person>
126    </foaf:knows>
127 </foaf:Person>
128 </rdf:RDF>
129 */
130 ?>
131 </verbatim>
132
133 !Parsing
134 Parsing isn't so hard either:
135 <verbatim>
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">
138         <head>
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=UTF-8" />
144                 <style type="text/css">
145                         table,th,td { border: 1px solid black; }
146                 </style>
147         </head>
148         <body>
149                 <?php
150 // Get our FOAF File from $_GET['foaf']
151 if (!isset($_REQUEST['foaf'])) {
152 echo "<strong>Please enter a FOAF file below";
153 } else {
154 $foaf = file_get_contents($_REQUEST['foaf']);
155
156 // Require the XML_FOAF_Parser class
157 require_once 'XML/FOAF/Parser.php';
158
159 // Create new Parser object
160 $parser = new XML_FOAF_Parser;
161
162 // Start of output
163 echo '<h1>XML_FOAF_Parser Example</h1>';
164 if (isset($_REQUEST['xml'])) {
165 echo '<pre>' .htmlentities($foaf). '</pre>';
166 }
167
168 // Parser our FOAF in $foaf
169 $parser->parseFromMem($foaf);
170
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());
175 }
176
177 if (isset($_REQUEST['array'])) {
178 // Show the contents of the FOAF Data array
179 echo "<h2>FOAF as Array</h2>";
180 echo "<pre>";
181 var_dump($parser->toArray());
182 echo "</pre>";
183 }
184 }
185 ?>
186                 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
187                         <p>
188                                 <label>FOAF File URI: <input type="text" name="foaf" value="<?php echo(@$_REQUEST['foaf']) ?>" /></label>
189                                 <br />
190                                 Show XML: <input type="checkbox" name="xml" value="true" />
191                                 <br />
192                                 Show as HTML Table: <input type="checkbox" name="table" value="true" checked="checked" />
193                                 <br />
194                                 Show as Array: <input type="checkbox" name="array" value="true" />
195                                 <br />
196                                 <input type="submit" value="Parse FOAF!" />
197                         </p>
198                 </form>
199         </body>
200 </html>
201 </verbatim>
202
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.
206
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.
210
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.
213
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
218
219 PEAR is dead simple to install.
220 !! Win32
221 <verbatim>
222 Start > Run > Command.com
223 cd\
224 cd c:\php
225 go-pear
226 </verbatim>
227 Follow your nose for a bit. I'm sure you can blunder through it. Next, install the needed modules.
228 <verbatim>
229 pear download XML_FOAF
230 pear download XML_Tree
231 pear download XML_Beautifier
232 pear upgrade-all
233 pear install XML_Tree
234 pear install XML_Beautifier
235 pear install XML_FOAF
236 </verbatim>
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\
241
242 One other thing: make sure your php.ini points to the right location in the ''include_path'' directive!