2 rcs_id('$Id: FoafViewer.php,v 1.3 2004-06-16 10:38:59 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 // see doc/README.foaf
80 if (findFile('XML/FOAF/Parser.php','missing_ok'))
81 require_once 'XML/FOAF/Parser.php';
82 //$ErrorManager->popErrorHandler();
83 if (!class_exists('XML_FOAF_Parser'))
84 return $this->error(_("required pear library XML/FOAF/Parser.php not found in include_path"));
86 extract($this->getArgs($argstr, $request));
87 // Get our FOAF File from the foaf plugin argument or $_GET['foaf']
88 if (empty($foaf)) $foaf = $request->getArg('foaf');
89 $chooser = HTML::form(array('method'=>'get','action'=>$request->getURLtoSelf()),
90 HTML::h4(_("FOAF File URI")),
91 HTML::input(array('id'=>'foaf','name'=>'foaf','type'=>'text','size'=>'80','value'=>$foaf)),
93 //HTML::p("Pretty HTML"),
94 HTML::input(array('id'=>'pretty','name'=>'pretty','type'=>'radio','checked'=>'checked'),_("Pretty HTML")),
95 //HTML::p("Original URL (Redirect)"),
96 HTML::input(array('id'=>'original','name'=>'original','type'=>'radio'),_("Original URL (Redirect)")),
98 HTML::input(array('type'=>'submit','value'=>_("Parse FOAF")))
99 //HTML::label(array('for'=>'foaf'),"FOAF File URI"),
106 if (substr($foaf,0,7) != "http://") {
107 return $this->error(_("foaf must be a URI starting with http://"));
110 if (!empty($original)) {
111 $request->redirect($foaf);
114 $foaffile = url_get_contents($foaf);
117 return HTML(HTML::p("Resource isn't available: Something went wrong, probably a 404!"));
119 // Create new Parser object
120 $parser = new XML_FOAF_Parser;
121 // Parser FOAF into $foaffile
122 $parser->parseFromMem($foaffile);
123 $a = $parser->toArray();
125 $html = HTML(HTML::h1(@$a[0]["name"]),
130 HTML::tr(HTML::td(_("Title")),
131 HTML::td($a[0]["title"])) : null,
132 (@$a[0]["homepage"][0]) ?
133 $this->iterateHTML($a[0],"homepage",$a["dc"]) : null,
134 (@$a[0]["weblog"][0]) ?
135 $this->iterateHTML($a[0],"weblog",$a["dc"]) : null,
138 HTML::tr(HTML::td("Full Name"),
139 (@$a[0]["name"][0]) ?
140 HTML::td(@$a[0]["name"]) :
141 (@$a[0]["firstname"][0] && @$a[0]["surname"][0]) ?
142 HTML::td(@$a[0]["firstname"][0] . " " . @$a[0]["surname"][0])
145 HTML::tr(HTML::td("Full Name"),
146 (@$a[0]["name"][0]) ?
147 HTML::td(@$a[0]["name"]) : null
149 (@$a[0]["nick"][0]) ?
150 $this->iterateHTML($a[0],"nick",$a["dc"])
152 (@$a[0]["mboxsha1sum"][0]) ?
153 $this->iterateHTML($a[0],"mboxsha1sum",$a["dc"])
155 (@$a[0]["depiction"][0]) ?
156 $this->iterateHTML($a[0],"depiction",$a["dc"])
158 (@$a[0]["seealso"][0]) ?
159 $this->iterateHTML($a[0],"seealso",$a["dc"])
161 HTML::tr(HTML::td("Source"),
163 HTML::a(array('href'=>@$foaf),"RDF")
170 $html->pushContent(HTML::hr(),$chooser);
178 * Renders array elements as HTML. May be used recursively.
180 * @param $array Source array
181 * @param $index Element Index to use.
182 * @todo Make sure it can look more than 1 layer deep
183 * @todo Pass in dublincore metadata
185 function iterateHTML($array,$index,$dc=NULL) {
186 for ($i=0;$i<count($array[$index]);$i++) {
187 //Cater for different types
188 $string = $array[$index][$i];
190 if ($index == "mboxsha1sum") {
191 $string = '<a href="http://beta.plink.org/profile/' . $array[$index][$i] . '">'
192 .'<img src="http://beta.plink.org/images/plink.png" alt="Plink - ' . $array[$index][$i] . '" /></a>';
194 else if ($index == "depiction") {
195 $string = '<img src="' . $array[$index][$i] . '" />';
197 else if ((substr($array[$index][$i],0,7) == "http://") || (substr($array[$index][$i],0,7) == "mailto:")) {
198 $string = '<a href="' . $array[$index][$i] . '"';
200 if (@$dc["description"][$array[$index][$i]]) {
201 $string .= ' title="' . $dc["description"][$array[$index][$i]] . '"';
204 if (@$dc["title"][$array[$index][$i]]) {
205 $string .= $dc["title"][$array[$index][$i]];
208 $string .= $array[$index][$i];
212 @$html .= "<tr><td>" . $index . "</td><td>" . $string . "</td></tr>";
215 return HTML::raw($html);
220 // $Log: not supported by cvs2svn $
221 // Revision 1.2 2004/06/13 13:54:25 rurban
222 // Catch fatals on the four dump calls (as file and zip, as html and mimified)
223 // FoafViewer: Check against external requirements, instead of fatal.
224 // Change output for xhtmldumps: using file:// urls to the local fs.
225 // Catch SOAP fatal by checking for GOOGLE_LICENSE_KEY
226 // Import GOOGLE_LICENSE_KEY and FORTUNE_DIR from config.ini.
228 // Revision 1.1 2004/06/08 21:38:21 rurban
229 // based on dans version 0.0.2 - simplified
237 // c-hanging-comment-ender-p: nil
238 // indent-tabs-mode: nil