File: README.foaf

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (242 lines) | stat: -rw-r--r-- 8,733 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
!FoaF
!Technology
* RAP - RDF API for PHP
* XML_FOAF, Pear

!Why not bare bones RAP?
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.

!What does XML_FOAF do?
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''.

Its really easy to use:
<verbatim>
<?php
require_once 'XML/FOAF.php';
// Main FOAF
$foaf = new XML_FOAF();

$foaf->newAgent('person');
$foaf->setName('Davey Shafik');
$foaf->setTitle('Mr');
$foaf->setFirstName('Davey');
$foaf->setSurname('Shafik');
$foaf->addMbox('mailto:davey@php.net',TRUE); // see also: XML_FOAF::setMboxSha1Sum();
$foaf->addHomepage('http://pixelated-dreams.com/~davey/');
$foaf->addWeblog('http://pixelated-dreams.com/blog');
$foaf->addImg('http://pixelated-dreams.com/~davey/me.jpg');
$foaf->addPage('http://pixelated-dreams.com/~davey/CV','Curriculum Vitae','Davey Shafiks Curriculum Vitae');
$foaf->addPage('http://www.php-mag.net/itr/online_artikel/psecom,id,484,nodeid,114.html','Sticking The Fork In','Creating Daemons in PHP');
$foaf->addPage('http://pawscon.com/', 'PHP and Web Standards Conference UK 2004', 'A Conference dedicated to PHP, Web Standards and the Semantic Web');
$foaf->addPhone('07776293539');
$foaf->addJabberID('fractured_realities@jabber.org');
$foaf->addTheme('http://php.net');
$foaf->addOnlineAccount('Davey','http://freenode.info','http://xmlns.com/foaf/0.1/OnlineChatAccount');
$foaf->addOnlineGamingAccount('Davey_S','http://www.there.com');
$foaf->addWorkplaceHomepage('http://www.pawscon.com');
$foaf->addSchoolHomepage('http://www.nobel.herts.sch.uk/');
$foaf->addInterest('http://xmlns.com/foaf/0.1/');
$foaf->addFundedBy('http://synapticmedia.net');
$foaf->addLogo('http://paws.davey.is-a-geek.com/images/paws.jpg');
$foaf->setBasedNear(52.565475,-1.162895);
$foaf->addDepiction('http://example.org/depiction/');
$foaf->addDepiction('http://example.org/depiction/2');

// Content of a <foaf:knows><foaf:Person /></foaf:knows>
$matt = new XML_FOAF();
$matt->newAgent('person');
$matt->setName('Matt McClanahan');
$matt->addNick('mattmcc');
$matt->addMboxSha1Sum('0cd5f54daf6aa59d1071ea6bf2973e0171ece606',TRUE);
$matt->addSeeAlso('http://mmcc.cx/foaf.rdf');
$matt->addJabberID('mattmcc@jabber.com');
$matt->addOnlineChatAccount('mattmcc','http://freenode.info','http://xmlns.com/foaf/0.1/OnlineChatAccount');
// Add to Main FOAF
$foaf->addKnows($matt);

// Another <foaf:knows><foaf:Person /></foaf:knows>
/*
Although we use another instance of XML_FOAF, we could re-use
the one from above ($matt)
*/
$libby = new XML_FOAF();
$libby->newAgent('person');
$libby->setName('Libby Miller');
$libby->addMbox('mailto:libby.miller@bristol.ac.uk');
$libby->addSeeAlso('http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf');

// Add to Main FOAF
$foaf->addKnows($libby);

$mcd = new XML_FOAF();
$mcd->newAgent('Organization');
$mcd->setName('McDonalds');
$mcd->addHomepage('http://www.mcdonalds.com/');

$foaf->addKnows($mcd);

if (!isset($_GET['xml'])) {
echo "<pre>" .htmlentities($foaf->get()). "</pre>";
echo "<hr />";
show_source(__FILE__);
} else {
header('Content-Type: text/xml');
$foaf->dump();
}

/* Output
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<foaf:Person>
   <foaf:name>Davey Shafik</foaf:name>
   <foaf:title>Mr</foaf:title>
   <foaf:firstName>Davey</foaf:firstName>
   <foaf:surname>Shafik</foaf:surname>
   <foaf:mbox_sha1sum>26b2e3834d83a5ca3fc81e5a942862f7a2bcb653</foaf:mbox_sha1sum>
   <foaf:homepage rdf:resource="http://pixelated-dreams.com/~davey/" />
   <foaf:img rdf:resource="http://pixelated-dreams.com/~davey/me.jpg" />
   <foaf:page>
	   <foaf:Document rdf:about="http://pixelated-dreams.com/~davey/CV/">
		   <dc:title>Curriculum Vitae</dc:title>
	   </foaf:Document>
   </foaf:page>
   <foaf:phone rdf:resource="tel:07776293539" />
   <foaf:workplaceHomepage rdf:resource="http://www.pawscon.com" />
   <foaf:schoolHomepage rdf:resource="http://www.nobel.herts.sch.uk/" />
   <foaf:interest rdf:resource="http://xmlns.com/foaf/0.1/" />
   <foaf:based_near>
	   <geo:Point geo:lat="52.565475" geo:long="-1.162895" />
   </foaf:based_near>
   <foaf:knows>
	   <foaf:Person>
		   <foaf:name>Matt McClanahan</foaf:name>
		   <foaf:nick>mattmcc</foaf:nick>
		   <foaf:mbox_sha1sum>0cd5f54daf6aa59d1071ea6bf2973e0171ece606</foaf:mbox_sha1sum>
		   <rdfs:seeAlso rdf:resource="http://mmcc.cx/foaf.rdf" />
	   </foaf:Person>
   </foaf:knows>
   <foaf:knows>
	   <foaf:Person>
		   <foaf:name>Libby Miller</foaf:name>
		   <foaf:mbox rdf:resource="mailto:libby.miller@bristol.ac.uk" />
		   <rdfs:seeAlso rdf:resource="http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf" />
	   </foaf:Person>
   </foaf:knows>
</foaf:Person>
</rdf:RDF>
*/
?>
</verbatim>

!Parsing
Parsing isn't so hard either:
<verbatim>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 	<head>
 		<title>XML_FOAF_Parser Example</title>
 		<meta name="Author" content="" />
 		<meta name="Keywords" content="" />
 		<meta name="Description" content="" />
 		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 		<style type="text/css">
			table,th,td { border: 1px solid black; }
		</style>
	</head>
	<body>
		<?php
// Get our FOAF File from $_GET['foaf']
if (!isset($_REQUEST['foaf'])) {
echo "<strong>Please enter a FOAF file below";
} else {
$foaf = file_get_contents($_REQUEST['foaf']);

// Require the XML_FOAF_Parser class
require_once 'XML/FOAF/Parser.php';

// Create new Parser object
$parser = new XML_FOAF_Parser;

// Start of output
echo '<h1>XML_FOAF_Parser Example</h1>';
if (isset($_REQUEST['xml'])) {
echo '<pre>' .htmlentities($foaf). '</pre>';
}

// Parser our FOAF in $foaf
$parser->parseFromMem($foaf);

if (isset($_REQUEST['table'])) {
// Show our FOAF as an HTML table
echo "<h2>FOAF as HTML Table</h2>";
echo $parser->toHTML($parser->toArray());
}

if (isset($_REQUEST['array'])) {
// Show the contents of the FOAF Data array
echo "<h2>FOAF as Array</h2>";
echo "<pre>";
var_dump($parser->toArray());
echo "</pre>";
}
}
?>
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<p>
				<label>FOAF File URI: <input type="text" name="foaf" value="<?php echo(@$_REQUEST['foaf']) ?>" /></label>
				<br />
				Show XML: <input type="checkbox" name="xml" value="true" />
				<br />
				Show as HTML Table: <input type="checkbox" name="table" value="true" checked="checked" />
				<br />
				Show as Array: <input type="checkbox" name="array" value="true" />
				<br />
				<input type="submit" value="Parse FOAF!" />
			</p>
		</form>
	</body>
</html>
</verbatim>

!How will the plugin(s) work?
# FoafViewerPlugin is embedded in a normal phpwiki page, with default arguments coming from $_GET varibles.
# FoafMakePlugin will get some kind of user id from the database, and retrieve any stored information about the user - outputting as FOAF.

!Installing PEAR / XML_FOAF
The XML_FOAF pear library will not be included with phpwiki, so you have to install the pear 
library by your own and be sure that the pear path is in the include_path.

Reason: XML_FOAF is based on XML_Parser and XML_Tree, but phpwiki uses its own XML parser and XML 
tree representation, so it would be unneccesary and incompatible duplication of the same thing.

See: http://pear.php.net/package/XML_FOAF
PHP Version: PHP 4.3.0 or newer
PEAR Package: XML_Tree 1.1 or newer
PEAR Package: XML_Beautifier 0.2.2 or newer

Pear is dead simple to install.
!! Win32
<verbatim>
Start > Run > Command.com
cd\
cd c:\php
go-pear
</verbatim>
Follow your nose for a bit. I'm sure you can blunder through it. Next, install the needed modules.
<verbatim>
pear download XML_FOAF
pear download XML_Tree
pear download XML_Beautifier
pear upgrade-all
pear install XML_Tree
pear install XML_Beautifier
pear install XML_FOAF
</verbatim>
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
# Download [XML_FOAF 0.2|http://pear.php.net/get/XML_FOAF-0.2.tgz]
# Extract XML_FOAF-0.2.tgz/XML_FOAF-0.2/FOAF/ to C:\php\pear\XML\FOAF
# Extract documentation to c:\php\pear\docs\

One other thing: make sure your php.ini points to the right location in the ''include_path'' directive!