2 rcs_id('$Id: FoafViewer.php,v 1.2 2004-06-13 13:54:25 rurban Exp $');
4 //ini_set('include_path','.;C:/php/pear');
7 * Basic FoafViewPlugin for PHPWiki.
9 * Please note; this is <em>heavily</em> based on an example file distributed with XML_FOAF 0.2
11 * <kbd>foaf=uri</kbd> - Used to determine the URI of a FOAF file.
12 * <kbd>original=true</kbd> - Simply dumps contents of $foaf
14 * @author Daniel O'Connor <http://ahsonline.com.au/dod/FOAF.rdf>
15 * @author Davey Shafik <http://pear.php.net/user/davey>
18 * @bug XML_FOAF 0.2 has problems with named RDF nodes (ie, http://www.ahsonline.com.au/dod/FOAF.rdf).
19 * Davey knows, will be fixing this soon.
20 * @todo "Friends" component
21 * @todo Named URLs (DC metadata)
22 * @todo "View in FOAFNAUT/foafexplorer/other"
23 * @bug Full name !available incorrectly handled.
27 * FoafViewer: Parse an RDF FOAF file and extract information to render as HTML
28 * usage: <?plugin FoafViewer foaf=http://www.ahsonline.com.au/dod/rawksuga.rdf original=true?>
29 * author: Daniel O'Connor <http://www.ahsonline.com.au/dod/FOAF.rdf>
31 * phpwiki version based on version 0.0.2 by Daniel O'Connor
35 * - use the phpwiki internal user foaf data (stored by a UserPreferences extension)
36 * - fix the pear FOAF Parser or we'll write our own (based on our XmlParser)
38 class WikiPlugin_FoafViewer
41 // The handler is handled okay. The only problem is that it still
43 function _error_handler($error) {
44 if (strstr($error->errstr,"Failed opening required 'XML/FOAF/Parser.php'"))
46 elseif (strstr($error->errstr,'No such file or directory'))
52 return _("FoafViewer");
55 function getDescription() {
56 return _("Parse an RDF FOAF file and extract information to render as HTML");
59 function getVersion() {
60 return preg_replace("/[Revision: $]/", '',
64 function getDefaultArguments() {
65 return array( 'foaf' => false, // the URI to parse
71 function run($dbi, $argstr, $request, $basepage) {
73 /* ignore fatal on loading */
76 $ErrorManager->pushErrorHandler(new WikiMethodCb($this,'_error_handler'));
78 // Require the XML_FOAF_Parser class. This is a pear library not included with phpwiki.
79 //if (findFile('XML/FOAF/Parser.php','missing_ok'))
80 require_once 'XML/FOAF/Parser.php';
81 //$ErrorManager->popErrorHandler();
82 if (!class_exists('XML_FOAF_Parser'))
83 return $this->error(_("required pear library XML/FOAF/Parser.php not found in include_path"));
85 extract($this->getArgs($argstr, $request));
86 // Get our FOAF File from the foaf plugin argument or $_GET['foaf']
87 if (empty($foaf)) $foaf = $request->getArg('foaf');
88 $chooser = HTML::form(array('method'=>'get','action'=>$request->getURLtoSelf()),
89 HTML::h4(_("FOAF File URI")),
90 HTML::input(array('id'=>'foaf','name'=>'foaf','type'=>'text','size'=>'80','value'=>$foaf)),
92 //HTML::p("Pretty HTML"),
93 HTML::input(array('id'=>'pretty','name'=>'pretty','type'=>'radio','checked'=>'checked'),_("Pretty HTML")),
94 //HTML::p("Original URL (Redirect)"),
95 HTML::input(array('id'=>'original','name'=>'original','type'=>'radio'),_("Original URL (Redirect)")),
97 HTML::input(array('type'=>'submit','value'=>_("Parse FOAF")))
98 //HTML::label(array('for'=>'foaf'),"FOAF File URI"),
105 if (substr($foaf,0,7) != "http://") {
106 return $this->error(_("foaf must be a URI starting with http://"));
109 if (!empty($original)) {
110 $request->redirect($foaf);
113 $foaffile = url_get_contents($foaf);
116 return HTML(HTML::p("Resource isn't available: Something went wrong, probably a 404!"));
118 // Create new Parser object
119 $parser = new XML_FOAF_Parser;
120 // Parser FOAF into $foaffile
121 $parser->parseFromMem($foaffile);
122 $a = $parser->toArray();
124 $html = HTML(HTML::h1(@$a[0]["name"]),
129 HTML::tr(HTML::td(_("Title")),
130 HTML::td($a[0]["title"])) : null,
131 (@$a[0]["homepage"][0]) ?
132 $this->iterateHTML($a[0],"homepage",$a["dc"]) : null,
133 (@$a[0]["weblog"][0]) ?
134 $this->iterateHTML($a[0],"weblog",$a["dc"]) : null,
137 HTML::tr(HTML::td("Full Name"),
138 (@$a[0]["name"][0]) ?
139 HTML::td(@$a[0]["name"]) :
140 (@$a[0]["firstname"][0] && @$a[0]["surname"][0]) ?
141 HTML::td(@$a[0]["firstname"][0] . " " . @$a[0]["surname"][0])
144 HTML::tr(HTML::td("Full Name"),
145 (@$a[0]["name"][0]) ?
146 HTML::td(@$a[0]["name"]) : null
148 (@$a[0]["nick"][0]) ?
149 $this->iterateHTML($a[0],"nick",$a["dc"])
151 (@$a[0]["mboxsha1sum"][0]) ?
152 $this->iterateHTML($a[0],"mboxsha1sum",$a["dc"])
154 (@$a[0]["depiction"][0]) ?
155 $this->iterateHTML($a[0],"depiction",$a["dc"])
157 (@$a[0]["seealso"][0]) ?
158 $this->iterateHTML($a[0],"seealso",$a["dc"])
160 HTML::tr(HTML::td("Source"),
162 HTML::a(array('href'=>@$foaf),"RDF")
169 $html->pushContent(HTML::hr(),$chooser);
177 * Renders array elements as HTML. May be used recursively.
179 * @param $array Source array
180 * @param $index Element Index to use.
181 * @todo Make sure it can look more than 1 layer deep
182 * @todo Pass in dublincore metadata
184 function iterateHTML($array,$index,$dc=NULL) {
185 for ($i=0;$i<count($array[$index]);$i++) {
186 //Cater for different types
187 $string = $array[$index][$i];
189 if ($index == "mboxsha1sum") {
190 $string = '<a href="http://beta.plink.org/profile/' . $array[$index][$i] . '">'
191 .'<img src="http://beta.plink.org/images/plink.png" alt="Plink - ' . $array[$index][$i] . '" /></a>';
193 else if ($index == "depiction") {
194 $string = '<img src="' . $array[$index][$i] . '" />';
196 else if ((substr($array[$index][$i],0,7) == "http://") || (substr($array[$index][$i],0,7) == "mailto:")) {
197 $string = '<a href="' . $array[$index][$i] . '"';
199 if (@$dc["description"][$array[$index][$i]]) {
200 $string .= ' title="' . $dc["description"][$array[$index][$i]] . '"';
203 if (@$dc["title"][$array[$index][$i]]) {
204 $string .= $dc["title"][$array[$index][$i]];
207 $string .= $array[$index][$i];
211 @$html .= "<tr><td>" . $index . "</td><td>" . $string . "</td></tr>";
214 return HTML::raw($html);
219 // $Log: not supported by cvs2svn $
220 // Revision 1.1 2004/06/08 21:38:21 rurban
221 // based on dans version 0.0.2 - simplified
229 // c-hanging-comment-ender-p: nil
230 // indent-tabs-mode: nil