!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: 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 $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 /* 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 "
" .htmlentities($foaf->get()). "
"; echo "
"; show_source(__FILE__); } else { header('Content-Type: text/xml'); $foaf->dump(); } /* Output Davey Shafik Mr Davey Shafik 26b2e3834d83a5ca3fc81e5a942862f7a2bcb653 Curriculum Vitae Matt McClanahan mattmcc 0cd5f54daf6aa59d1071ea6bf2973e0171ece606 Libby Miller */ ?>
!Parsing Parsing isn't so hard either: XML_FOAF_Parser Example 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 '

XML_FOAF_Parser Example

'; if (isset($_REQUEST['xml'])) { echo '
' .htmlentities($foaf). '
'; } // Parser our FOAF in $foaf $parser->parseFromMem($foaf); if (isset($_REQUEST['table'])) { // Show our FOAF as an HTML table echo "

FOAF as HTML Table

"; echo $parser->toHTML($parser->toArray()); } if (isset($_REQUEST['array'])) { // Show the contents of the FOAF Data array echo "

FOAF as Array

"; echo "
";
var_dump($parser->toArray());
echo "
"; } } ?>


Show XML:
Show as HTML Table:
Show as Array:

!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 Start > Run > Command.com cd\ cd c:\php go-pear Follow your nose for a bit. I'm sure you can blunder through it. Next, install the needed modules. 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 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!