Source for file FOAF.php
Documentation is available at FOAF.php
1 <?php 2 /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ 3 // +----------------------------------------------------------------------+ 4 // | PHP version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2002 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 3.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/3_0.txt | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Davey Shafik <davey@php.net> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id: fsource_XML_FOAF__FOAF.php.html,v 1.2 2004/01/15 19:06:48 davey Exp $ 20 21 /** 22 * FOAF Creator 23 * @package XML_FOAF 24 * @category XML 25 */ 26 27 require_once 'XML/FOAF/Common.php'; 28 29 /** 30 * FOAF Creator 31 * 32 * @package XML_FOAF 33 * @author Davey <davey@php.net> 34 * @version 0.2 35 * @copyright Copyright 2003 Davey Shafik and Synaptic Media. All Rights Reserved. 36 * @example docs/examples/example1.php Basic Usage of XML_FOAF 37 * @todo Implement PEAR_Error handling 38 */ 39 40 class XML_FOAF extends XML_FOAF_Common 41 { 42 43 /** 44 * @var object XML_Tree object containing the FOAF RDF/XML Tree 45 */ 46 47 var $foaf = null; 48 49 /** 50 * @var array Contains all namespaces in use 51 */ 52 53 var $namespaces = array(); 54 55 /** 56 * @var array Contains XML_Tree Child nodes for all FOAF elements 57 */ 58 59 var $children = array(); 60 61 /** 62 * @var object XML_Tree object for the FOAF 63 */ 64 65 var $xml_tree = null; 66 67 /** 68 * XML_FOAF Constructor 69 * @access private 70 */ 71 72 function __construct () 73 { 74 $this->_setXmlns(); 75 } 76 77 /** 78 * XML_FOAF PHP4 Compatible Constructor 79 * @see XML_FOAF::__construct 80 */ 81 82 function XML_FOAF () 83 { 84 $this->__construct(); 85 } 86 87 /** 88 * Create new FOAF Agent 89 * 90 * @foafstatus Unstable 91 * @param string $agent_type Agent type, this can be Person, Organization, Group, Agent. 92 * @access public 93 * @return void 94 * @link http://xmlns.com/foaf/0.1/#term_Organization FOAF Specification - foaf:Organization 95 * @link http://xmlns.com/foaf/0.1/#term_Group FOAF Specification - foaf:Group 96 * @link http://xmlns.com/foaf/0.1/#term_Person FOAF Specification - foaf:Person 97 * @link http://xmlns.com/foaf/0.1/#term_Agent FOAF Specification - foaf:Agent 98 */ 99 100 function newAgent($agent_type = 'Person') 101 { 102 require_once 'XML/Tree.php'; 103 $this->xml_tree = new XML_Tree; 104 $agent_type = strtolower($agent_type); 105 $this->agent = $agent_type; 106 switch ($agent_type) { 107 case 'group': 108 $this->foaf =& $this->xml_tree->addRoot('foaf:Group'); 109 break; 110 case 'organization': 111 $this->foaf =& $this->xml_tree->addRoot('foaf:Organization'); 112 break; 113 case 'agent': 114 $this->foaf =& $this->xml_tree->addRoot('foaf:Agent'); 115 case 'person': 116 default: 117 $this->foaf =& $this->xml_tree->addRoot('foaf:Person'); 118 break; 119 } 120 } 121 122 /** 123 * Set the foaf:name of the Agent 124 * 125 * @foafstatus Testing 126 * @param string $name Name for the Agent. 127 * @access public 128 * @return void 129 * @link http://xmlns.com/foaf/0.1/#term_name FOAF Specification - foaf:name 130 * @todo Allow for the xml:lang to be specified 131 */ 132 133 function setName($name) 134 { 135 $this->children['name'] =& $this->foaf->addChild('foaf:name', $name); 136 } 137 138 /** 139 * Add a foaf:depiction element 140 * 141 * @foafstatus Testing 142 * @param string $uri URI For the Depicted image 143 * @access public 144 * @return void 145 * @link http://xmlns.com/foaf/0.1/#term_depiction FOAF Specification - foaf:depiction 146 */ 147 148 function addDepiction($uri) 149 { 150 $this->children['depiction'][] =& $this->foaf->addChild('foaf:depiction', '', array('rdf:resource' => $uri)); 151 } 152 153 /** 154 * Add a foaf:fundedBy element 155 * 156 * @foafstatus Unstable 157 * @param string $uri URI for the funder 158 * @access public 159 * @return void 160 * @link http://xmlns.com/foaf/0.1/#term_fundedBy FOAF Specification - foaf:fundedBy 161 */ 162 163 function addFundedBy($uri) 164 { 165 $this->children['fundedby'][] =& $this->foaf->addChild('foaf:fundedBy', '', array('rdf:resource' => $uri)); 166 } 167 168 /** 169 * Add a foaf:logo element 170 * 171 * @foafstatus Testing 172 * @param string $uri URI for Logo Image 173 * @access public 174 * @return void 175 * @link http://xmlns.com/foaf/0.1/#term_logo FOAF Specification - foaf:logo 176 */ 177 178 function addLogo($uri) 179 { 180 $this->children['logo'][] =& $this->foaf->addChild('foaf:logo', '', array('rdf:resource' => $uri)); 181 } 182 183 /** 184 * Add a foaf:page element 185 * 186 * @foafstatus Testing 187 * @param string $document_uri URI for the Document being reference 188 * @param string $title Title for the Document 189 * @param string $description Description for the Document 190 * @access public 191 * @return void 192 * @link http://xmlns.com/foaf/0.1/#term_page FOAF Specification - foaf:page 193 */ 194 195 function addPage($document_uri,$title = null,$description = null) 196 { 197 $page =& $this->foaf->addChild('foaf:page'); 198 $document =& $page->addChild('foaf:Document', '', array('rdf:about' => $document_uri)); 199 if(!is_null($title)) { 200 $document->addChild('dc:title', $title); 201 } 202 if(!is_null($description)) { 203 $document->addChild('dc:description', $description); 204 } 205 $this->children['page'][] =& $page; 206 } 207 208 /** 209 * Add a foaf:theme element 210 * 211 * @foafstatus unstable 212 * @param string $uri URI for the Theme 213 * @access public 214 * @return void 215 * @link http://xmlns.com/foaf/0.1/#term_theme FOAF Specification - foaf:theme 216 */ 217 218 function addTheme($uri) 219 { 220 $this->children['theme'][] =& $this->foaf->addChild('foaf:theme', '', array('rdf:resource' => $uri)); 221 } 222 223 /** 224 * set foaf:title 225 * 226 * @foafstatus testing 227 * @param string $title foaf:Agents title 228 * @access public 229 * @return void 230 * @link http://xmlns.com/foaf/0.1/#term_title FOAF Specification - foaf:title 231 */ 232 233 function setTitle($title) 234 { 235 $this->children['title'] =& $this->foaf->addChild('foaf:title', $title); 236 } 237 238 /** 239 * Add a foaf:nick element 240 * 241 * @foafstatus testing 242 * @param string $nick foaf:Agents Nickname 243 * @access public 244 * @return void 245 * @link http://xmlns.com/foaf/0.1/#term_nick FOAF Specification - foaf:nick 246 */ 247 248 function addNick($nick) 249 { 250 $this->children['nick'][] =& $this->foaf->addChild('foaf:nick', $nick); 251 } 252 253 /** 254 * set foaf:givenname 255 * 256 * @foafstatus testing 257 * @param string $given_name foaf:Agents Given Name 258 * @access public 259 * @return void 260 * @link http://xmlns.com/foaf/0.1/#term_givenname FOAF Specification - foaf:givenname 261 */ 262 263 function setGivenName($given_name) 264 { 265 $this->children['givenname'] =& $this->foaf->addChild('foaf:givenname', $given_name); 266 } 267 268 /** 269 * Add a foaf:phone element 270 * 271 * @foafstatus testing 272 * @param string $phone foaf:Agents Phone Number 273 * @access public 274 * @return void 275 * @link http://xmlns.com/foaf/0.1/#term_phone FOAF Specification - foaf:phone 276 */ 277 278 function addPhone($phone) 279 { 280 if (substr($phone,0,4) != 'tel:') { 281 $phone = 'tel:' .$phone; 282 } 283 $this->children['phone'][] =& $this->foaf->addChild('foaf:phone', '', array('rdf:resource' => $phone)); 284 } 285 286 /** 287 * Add a foaf:mbox or foaf:mbox_sha1sum element 288 * 289 * @foafstatus testing 290 * @param string $mbox Mailbox, either a mailto:addr, addr or an sha1 sum of mailto:addr 291 * @param boolean $sha1 Whether or not to use foaf:mbox_sha1sum 292 * @param boolean $is_sha1_hash Whether or not given $mbox is already an sha1 sum 293 * @access public 294 * @return void 295 * @see XML_FOAF::setMboxSha1Sum 296 * @link http://xmlns.com/foaf/0.1/#term_mbox_sha1sum FOAF Specification - foaf:mbox_sha1sum 297 * @link http://xmlns.com/foaf/0.1/#term_mbox FOAF Specification - foaf:mbox 298 */ 299 300 function addMbox($mbox,$sha1 = false,$is_sha1_hash = false) 301 { 302 if (substr($mbox,0,7) != 'mailto:' && $is_sha1_hash == false) { 303 $mbox = 'mailto:' .$mbox; 304 } 305 306 if ($sha1 == true) { 307 if ($is_sha1_hash == false) { 308 $mbox = sha1($mbox); 309 } 310 $this->children['mbox_sha1sum'][] =& $this->foaf->addChild('foaf:mbox_sha1sum', $mbox); 311 } else { 312 $this->children['mbox'][] =& $this->foaf->addChild('foaf:mbox', '', array('rdf:resource' => $mbox)); 313 } 314 315 } 316 317 /** 318 * Add a foaf:mbox_sha1sum element 319 * 320 * @foafstatus testing 321 * @param string $mbox Mailbox, either a mailto:addr, addr or an sha1 sum of mailto:addr 322 * @param boolean $is_sha1_hash Whether or not given $mbox is already an sha1 sum 323 * @access public 324 * @return void 325 * @link http://xmlns.com/foaf/0.1/#term_mbox_sha1sum FOAF Specification - foaf:mbox_sha1sum 326 */ 327 328 function addMboxSha1Sum($mbox,$is_sha1_sum = false) 329 { 330 $this->addMbox($mbox, true, $is_sha1_sum); 331 } 332 333 /** 334 * set foaf:gender 335 * 336 * @foafstatus testing 337 * @param string $gender foaf:Agents Gender (typically 'male' or 'female') 338 * @access public 339 * @return void 340 * @link http://xmlns.com/foaf/0.1/#term_gender FOAF Specification - foaf:gender 341 */ 342 343 function setGender($gender) 344 { 345 $this->children['gender'] =& $this->foaf->addChild('foaf:gender', strtolower($gender)); 346 } 347 348 /** 349 * Add a foaf:jabberID element 350 * 351 * @foafstatus testing 352 * @param string $jabbed_id A Jabber ID 353 * @access public 354 * @return void 355 * @link http://xmlns.com/foaf/0.1/#term_jabberID FOAF Specification - foaf:jabberID 356 */ 357 358 function addJabberID($jabber_id) 359 { 360 $this->children['jabbberid'][] =& $this->foaf->addChild('foaf:jabberID', $jabber_id); 361 } 362 363 /** 364 * Add a foaf:aimChatID element 365 * 366 * @foafstatus testing 367 * @param string $aim_chat_id An AIM Username 368 * @access public 369 * @return void 370 * @link http://xmlns.com/foaf/0.1/#term_aimChatID FOAF Specification - foaf:aimChatID 371 */ 372 373 function addAimChatID($aim_chat_id) 374 { 375 $this->children['aimchatid'][] =& $this->foaf->addChild('foaf:aimChatID', $aim_chat_id); 376 } 377 378 /** 379 * Add a foaf:icqChatID element 380 * 381 * @foafstatus testing 382 * @param string $icq_chat_id An ICQ Number 383 * @access public 384 * @return void 385 * @link http://xmlns.com/foaf/0.1/#term_icqChatID FOAF Specification - foaf:icqChatID 386 */ 387 388 function addIcqChatID($icq_chat_id) 389 { 390 $this->children['icqchatid'][] =& $this->foaf->addChild('foaf:icqChatID', $icq_chat_id); 391 } 392 393 /** 394 * Add a foaf:yahooChatID element 395 * 396 * @foafstatus testing 397 * @param string $yahoo_chat_id A Yahoo! Messenger ID 398 * @access public 399 * @return void 400 * @link http://xmlns.com/foaf/0.1/#term_yahooChatID FOAF Specification - foaf:yahooChatID 401 */ 402 403 function addYahooChatID($yahoo_chat_id) 404 { 405 $this->children['yahoochatid'][] =& $this->foaf->addChild('foaf:yahooChatID', $yahoo_chat_id); 406 } 407 408 /** 409 * Add a foaf:msnChatID element 410 * 411 * @foafstatus testing 412 * @param string $msn_chat_id A MSN Chat username 413 * @access public 414 * @return void 415 * @link http://xmlns.com/foaf/0.1/#term_msnChatID FOAF Specification - foaf:msnChatID 416 */ 417 418 function addMsnChatID($msn_chat_id) 419 { 420 $this->children['msnchatid'][] =& $this->foaf->addChild('foaf:msnChatID', $msn_chat_id); 421 } 422 423 /** 424 * Add a foaf:OnlineAccount element 425 * 426 * @foafstatus unstable 427 * @param string $account_name Account Name 428 * @param string $account_service_homepage URI to Account Service Homepage 429 * @param string $acount_type Account type (e.g http://xmlns.com/foaf/0.1/OnlineChatAccount) 430 * @access public 431 * @return void 432 * @see XML_FOAF::setOnlineChatAccount,XML_FOAF::setMsnChatID,XML_FOAF::setIcqChatID,XML_FOAF::setAimChatID 433 * @see XML_FOAF::setYahooChatID,XML_FOAF::setJabberID,XML_FOAF::setOnlineGamingAccount,XML_FOAF::setOnlineEcommerceAccount 434 * @link http://xmlns.com/foaf/0.1/#term_accountServiceHomepage FOAF Specification - foaf:accountServiceHomepage 435 * @link http://xmlns.com/foaf/0.1/#term_accountName FOAF Specification - foaf:accountName 436 * @link http://xmlns.com/foaf/0.1/#term_OnlineAccount FOAF Specification - foaf:OnlineAccount 437 * @link http://xmlns.com/foaf/0.1/#term_holdsAccount FOAF Specification - foaf:holdsAccount 438 */ 439 440 function addOnlineAccount($account_name,$account_service_homepage = null,$account_type = null) 441 { 442 $holds_account =& $this->foaf->addChild('foaf:holdsAccount'); 443 $online_account =& $holds_account->addChild('foaf:OnlineAccount'); 444 $online_account->addChild('foaf:accountName', $account_name); 445 if (!is_null($account_service_homepage)) { 446 $online_account->addChild('foaf:accountServiceHomepage', '', array('rdf:resource' => $account_service_homepage)); 447 } 448 if (!is_null($account_type)) { 449 $online_account->addChild('rdf:type', '', array('rdf:resource' => $account_type)); 450 } 451 $this->children['holdsaccount'][] =& $holds_account; 452 } 453 454 /** 455 * Add a foaf:OnlineChatAccount element 456 * 457 * @foafstatus unstable 458 * @param string $account_name Account Name 459 * @param string $account_service_homepage URI Tto Account Service Homepage 460 * @access public 461 * @return void 462 * @see XML_FOAF::setOnlineAccount,XML_FOAF::setMsnChatID,XML_FOAF::setIcqChatID,XML_FOAF::setAimChatID 463 * @see XML_FOAF::setYahooChatID,XML_FOAF::setJabberID,XML_FOAF::setOnlineGamingAccount,XML_FOAF::setOnlineEcommerceAccount 464 * @link http://xmlns.com/foaf/0.1/#term_accountServiceHomepage FOAF Specification - foaf:accountServiceHomepage 465 * @link http://xmlns.com/foaf/0.1/#term_accountName FOAF Specification - foaf:accountName 466 * @link http://xmlns.com/foaf/0.1/#term_OnlineChatAccount FOAF Specification - foaf:OnlineChatAccount 467 * @link http://xmlns.com/foaf/0.1/#term_holdsAccount FOAF Specification - foaf:holdsAccount 468 */ 469 470 function addOnlineChatAccount($account_name,$account_service_homepage) 471 { 472 $holds_account =& $this->foaf->addChild('foaf:holdsAccount'); 473 $online_chat_account =& $holds_account->addChild('foaf:OnlineChatAccount'); 474 $online_chat_account->addChild('foaf:accountName', $account_name); 475 if (!is_null($account_service_homepage)) { 476 $online_chat_account->addChild('foaf:accountServiceHomepage', '', array('rdf:resource' => $account_service_homepage)); 477 } 478 $this->children['holdsaccount'][] =& $holds_account; 479 } 480 481 /** 482 * Add a foaf:OnlineGamingAccount element 483 * 484 * @foafstatus unstable 485 * @param string $account_name Account Name 486 * @param string $account_service_homepage URI Tto Account Service Homepage 487 * @access public 488 * @return void 489 * @see XML_FOAF::setOnlineAccount,XML_FOAF::setMsnChatID,XML_FOAF::setIcqChatID,XML_FOAF::setAimChatID 490 * @see XML_FOAF::setYahooChatID,XML_FOAF::setJabberID,XML_FOAF::setOnlineChatAccount,XML_FOAF::setOnlineEcommerceAccount 491 * @link http://xmlns.com/foaf/0.1/#term_accountServiceHomepage FOAF Specification - foaf:accountServiceHomepage 492 * @link http://xmlns.com/foaf/0.1/#term_accountName FOAF Specification - foaf:accountName 493 * @link http://xmlns.com/foaf/0.1/#term_OnlineChatAccount FOAF Specification - foaf:OnlineChatAccount 494 * @link http://xmlns.com/foaf/0.1/#term_holdsAccount FOAF Specification - foaf:holdsAccount 495 */ 496 497 function addOnlineGamingAccount($account_name,$account_service_homepage) 498 { 499 $holds_account =& $this->foaf->addChild('foaf:holdsAccount'); 500 $online_gaming_account =& $holds_account->addChild('foaf:OnlineGamingAccount'); 501 $online_gaming_account->addChild('foaf:accountName', $account_name); 502 if (!is_null($account_service_homepage)) { 503 $online_gaming_account->addChild('foaf:accountServiceHomepage', '', array('rdf:resource' => $account_service_homepage)); 504 } 505 $this->children['holdsaccount'][] =& $holds_account; 506 } 507 508 /** 509 * Add a foaf:OnlineEcommerceAccount element 510 * 511 * @foafstatus unstable 512 * @param string $account_name Account Name 513 * @param string $account_service_homepage URI Tto Account Service Homepage 514 * @access public 515 * @return void 516 * @see XML_FOAF::setOnlineAccount,XML_FOAF::setMsnChatID,XML_FOAF::setIcqChatID,XML_FOAF::setAimChatID 517 * @see XML_FOAF::setYahooChatID,XML_FOAF::setJabberID,XML_FOAF::setOnlineChatAccount,XML_FOAF::setOnlineGamingAccount 518 * @link http://xmlns.com/foaf/0.1/#term_accountServiceHomepage FOAF Specification - foaf:accountServiceHomepage 519 * @link http://xmlns.com/foaf/0.1/#term_accountName FOAF Specification - foaf:accountName 520 * @link http://xmlns.com/foaf/0.1/#term_OnlineChatAccount FOAF Specification - foaf:OnlineChatAccount 521 * @link http://xmlns.com/foaf/0.1/#term_holdsAccount FOAF Specification - foaf:holdsAccount 522 */ 523 524 function addOnlineEcommerceAccount($account_name,$account_service_homepage) 525 { 526 $holds_account =& $this->foaf->addChild('foaf:holdsAccount'); 527 $online_ecommerce_account =& $holds_account->addChild('foaf:OnlineEcommerceAccount'); 528 $online_ecommerce_account->addChild('foaf:accountName', $account_name); 529 if (!is_null($account_service_homepage)) { 530 $online_ecommerce_account->addChild('foaf:accountServiceHomepage', '', array('rdf:resource' => $account_service_homepage)); 531 } 532 $this->children['holdsaccount'][] =& $holds_account; 533 } 534 535 /** 536 * Add a foaf:homepage element 537 * 538 * @foafstatus stable 539 * @param string $uri URI for the Homepage 540 * @access public 541 * @return void 542 * @link http://xmlns.com/foaf/0.1/#term_homepage FOAF Specification - foaf:homepage 543 */ 544 545 function addHomepage($uri) 546 { 547 $this->children['homepage'][] =& $this->foaf->addChild('foaf:homepage', '', array('rdf:resource' => $uri)); 548 } 549 550 /** 551 * Add a foaf:weblog element 552 * 553 * @foafstatus testing 554 * @param string $uri URI for the weblog 555 * @access public 556 * @return void 557 * @link http://xmlns.com/foaf/0.1/#term_weblog FOAF Specification - foaf:weblog 558 */ 559 560 function addWeblog($uri) 561 { 562 $this->children['weblog'][] =& $this->foaf->addChild('foaf:weblog', '', array('rdf:resource' => $uri)); 563 } 564 565 /** 566 * Add a foaf:made element 567 * @foafstatus testing 568 * @param string $uri URI for the thing foaf:Agent made 569 * @access public 570 * @return void 571 * @link http://xmlns.com/foaf/0.1/#term_made 572 */ 573 574 function addMade($uri) 575 { 576 $this->children['made'][] =& $this->foaf->addChild('foaf:made', '', array('rdf:resource' => $uri)); 577 } 578 579 /**#@+ 580 * @todo Return a PEAR_Error instead of false 581 */ 582 583 /* foaf:Person */ 584 585 /** 586 * set foaf:geekcode 587 * 588 * @foafstatus testing 589 * @param string $geek_code foaf:Agents Geek Code 590 * @access public 591 * @return boolean 592 * @link http://www.joereiss.net/geek/geek.html Geek Code Generator 593 * @link http://www.geekcode.com/geek.html Geek Code official website 594 * @link http://xmlns.com/foaf/0.1/#term_geekcode FOAF Specification - foaf:geekcode 595 */ 596 597 function setGeekcode($geek_code) 598 { 599 if($this->isAllowedForAgent('geekcode')) { 600 $this->children['geekcode'] =& $this->foaf->addChild('foaf:geekcode', $geek_code); 601 return true; 602 } else { 603 return false; 604 } 605 } 606 607 /** 608 * set foaf:firstName 609 * 610 * @foafstatus testing 611 * @param string $first_name foaf:Agents First Name 612 * @access public 613 * @return boolean 614 * @see XML_FOAF::setGivenName,XML_FOAF::setName 615 * @link http://xmlns.com/foaf/0.1/#term_firstName FOAF Specification - foaf:firstName 616 */ 617 618 function setFirstName($first_name) 619 { 620 if($this->isAllowedForAgent('firstname')) { 621 $this->children['firstname'] =& $this->foaf->addChild('foaf:firstName', $first_name); 622 return true; 623 } else { 624 return false; 625 } 626 } 627 628 /** 629 * set foaf:surname 630 * 631 * @foafstatus testing 632 * @param string $surname foaf:Agents Surname 633 * @access public 634 * @return boolean 635 * @link http://xmlns.com/foaf/0.1/#term_surname FOAF Specification - foaf:surname 636 */ 637 638 function setSurname($surname) 639 { 640 if($this->isAllowedForAgent('surname')) { 641 $this->children['surname'] =& $this->foaf->addChild('foaf:surname', $surname); 642 return true; 643 } else { 644 return false; 645 } 646 } 647 648 /** 649 * set foaf:familyName 650 * 651 * @foafstatus testing 652 * @param string $family_name foaf:Agents Family name 653 * @access public 654 * @return boolean 655 * @link http://xmlns.com/foaf/0.1/#term_firstName FOAF Specification - foaf:familyName 656 */ 657 658 function setFamilyName($family_name) 659 { 660 if($this->isAllowedForAgent('family_name')) { 661 $this->children['familyname'] =& $this->foaf->addChild('foaf:family_name', $family_name); 662 return true; 663 } else { 664 return false; 665 } 666 } 667 668 /** 669 * set foaf:plan 670 * 671 * @foafstatus testing 672 * @param string $plan .plan file contents 673 * @access public 674 * @return boolean 675 * @link http://xmlns.com/foaf/0.1/#term_plan FOAF Specification - foaf:plan 676 */ 677 678 function setPlan($plan) 679 { 680 if($this->isAllowedForAgent('plan')) { 681 $this->children['plan'] =& $this->foaf->addChild('foaf:plan', $plan); 682 return true; 683 } else { 684 return false; 685 } 686 } 687 688 /** 689 * Add a foaf:img element 690 * 691 * @foafstatus testing 692 * @param string $uri URI for the img being depicted 693 * @access public 694 * @return boolean 695 * @link http://xmlns.com/foaf/0.1/#term_img FOAF Specification - foaf:img 696 */ 697 698 function addImg($uri) 699 { 700 if($this->isAllowedForAgent('img')) { 701 $this->children['img'][] =& $this->foaf->addChild('foaf:img', '', array('rdf:resource' => $uri)); 702 return true; 703 } else { 704 return false; 705 } 706 } 707 708 /** 709 * Add a foaf:myersBriggs elements 710 * 711 * @foafstatus testing 712 * @param string $myers_briggs Myers Briggs Personality classification 713 * @access public 714 * @return boolean 715 * @link http://www.teamtechnology.co.uk/tt/t-articl/mb-simpl.htm Myers Briggs - Working out your type 716 * @link http://xmlns.com/foaf/0.1/#term_myersBriggs FOAF Specification - foaf:myersBriggs 717 */ 718 719 function addMyersBriggs($myers_briggs) 720 { 721 if($this->isAllowedForAgent('myersbriggs')) { 722 $this->children['myersbriggs'][] =& $this->foaf->addChild('foaf:myersBriggs', $myers_briggs); 723 return true; 724 } else { 725 return false; 726 } 727 } 728 729 /** 730 * Add a foaf:workplaceHome element 731 * 732 * @foafstatus testing 733 * @param string $uri URI for the Workplace Homepage 734 * @access public 735 * @return boolean 736 * @link http://xmlns.com/foaf/0.1/#term_workplaceHomepage FOAF Specification - foaf:workplaceHomepage 737 */ 738 739 function addWorkplaceHomepage($uri) 740 { 741 if ($this->isAllowedForAgent('workplaceHomepage')) { 742 $this->children['workplacehomepage'][] =& $this->foaf->addChild('foaf:workplaceHomepage', '', array('rdf:resource' => $uri)); 743 return true; 744 } else { 745 return false; 746 } 747 } 748 749 /** 750 * Add a foaf:workInfoHomepage element 751 * 752 * @foafstatus testing 753 * @param string $uri URI for Work Information Homepage 754 * @access public 755 * @return boolean 756 * @link http://xmlns.com/foaf/0.1/#term_workInfoHomepage FOAF Specification - foaf:workInfoHomepage 757 */ 758 759 function addWorkInfoHomepage($uri) 760 { 761 if($this->isAllowedForAgent('workInfoHomepage')) { 762 $this->children['workinfohomepage'][] =& $this->foaf->addChild('foaf:workInfoHomepage', '', array('rdf:resource' => $uri)); 763 return true; 764 } else { 765 return false; 766 } 767 } 768 769 /** 770 * Add a foaf:schoolHomepage element 771 * 772 * @foafstatus testing 773 * @param string $uri URI for School Homepage 774 * @access public 775 * @return boolean 776 * @link http://xmlns.com/foaf/0.1/#term_schoolHomepage FOAF Specification - foaf:schoolHomepage 777 */ 778 779 function addSchoolHomepage($uri) 780 { 781 if($this->isAllowedForAgent('schoolHomepage')) { 782 $this->childen['schoolhomepage'][] = $this->foaf->addChild('foaf:schoolHomepage', '', array('rdf:resource' => $uri)); 783 return true; 784 } else { 785 return false; 786 } 787 } 788 789 /** 790 * Add a foaf:publications elements 791 * 792 * @foafstatus unstable 793 * @param string $uri URI to the publications 794 * @access public 795 * @return boolean 796 * @link http://xmlns.com/foaf/0.1/#term_publications FOAF Specification - foaf:publications 797 */ 798 799 function addPublications($uri) 800 { 801 if($this->isAllowedForAgent('publications')) { 802 $this->children['publications'][] =& $this->foaf->addChild('foaf:publications', '', array('rdf:resource' => $uri)); 803 return true; 804 } else { 805 return false; 806 } 807 } 808 809 /** 810 * Add a foaf:currentProject element 811 * 812 * @foafstatus testing 813 * @param string $uri URI to a current projects homepage 814 * @access public 815 * @return boolean 816 * @link http://xmlns.com/foaf/0.1/#term_currentProject FOAF Specification - foaf:currentProject 817 */ 818 819 function addCurrentProject($uri) 820 { 821 if($this->isAllowedForAgent('currentProject')) { 822 $this->children['currentproject'][] =& $this->foaf->addChild('foaf:currentProject', '', array('rdf:resource' => $uri)); 823 return true; 824 } else { 825 return false; 826 } 827 } 828 829 /** 830 * Add a foaf:pastProject element 831 * 832 * @foafstatus testing 833 * @param string $uri URI to a past projects homepage 834 * @access public 835 * @return boolean 836 * @link http://xmlns.com/foaf/0.1/#term_pastProject FOAF Specification - foaf:pastProject 837 */ 838 839 function addPastProject($uri) 840 { 841 if($this->isAllowedForAgent('pastProject')) { 842 $this->children['pastproject'][] =& $this->foaf->addChild('foaf:pastProject', '', array('rdf:resource' => $uri)); 843 return true; 844 } else { 845 return false; 846 } 847 } 848 849 /** 850 * set foaf:basedNear 851 * 852 * @foafstatus unstable 853 * @param float $geo_lat Latitute for the geo:Point 854 * @param float $geo_long Longitude for the geo:Point 855 * @access public 856 * @return boolean 857 * @link http://xmlns.com/foaf/0.1/#term_based_near FOAF Specification - foaf:basedNear 858 * @link http://www.w3.org/2003/01/geo/ An RDF Geo Vocabulary: Point/lat/long/alt 859 * @link http://esw.w3.org/topic/GeoInfo GeoInfo Wiki 860 * @link http://rdfweb.org/topic/UsingBasedNear Using foaf:based_near 861 */ 862 863 function setBasedNear($geo_lat,$geo_long) 864 { 865 if($this->isAllowedForAgent('based_near')) { 866 $this->namespaces['geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#'; 867 $based_near =& $this->foaf->addChild('foaf:based_near'); 868 $geo_point =& $based_near->addChild('geo:Point', '', array('geo:lat' => $geo_lat, 'geo:long' => $geo_long)); 869 $this->children['basednear'][] =& $based_near; 870 return true; 871 } else { 872 return false; 873 } 874 } 875 876 /* foaf:Person && foaf:Group */ 877 878 /** 879 * Add a foaf:interest element 880 * 881 * @foafstatus testing 882 * @param string $uri URI with Info about the Interest 883 * @access public 884 * @return boolean 885 * @link http://xmlns.com/foaf/0.1/#term_interest 886 */ 887 888 function addInterest($uri) 889 { 890 if($this->isAllowedForAgent('interest')) { 891 $this->children['interest'][] =& $this->foaf->addChild('foaf:interest', '', array('rdf:resource' => $uri)); 892 } else { 893 return FALSE; 894 } 895 } 896 897 /* foaf:Group */ 898 899 /** 900 * Add a foaf:member element 901 * 902 * @foafstatus unstable 903 * @param object $foaf_agent XML_FOAF object (with a foaf:agent set) 904 * @access public 905 * @return boolean 906 * @link http://xmlns.com/foaf/0.1/#term_member FOAF Specification - foaf:member 907 */ 908 909 function &addMember(&$foaf_agent) 910 { 911 if($this->isAllowedForAgent('member')) { 912 $member =& $this->foaf->addChild('foaf:member'); 913 $member->addChild($foaf_agent); 914 $this->children['member'][] =& $member; 915 return true; 916 } else { 917 return false; 918 } 919 } 920 921 /** 922 * Set foaf:membershipClass 923 * 924 * @foafstatus unstable 925 * @param mixed $membership_class XML String or XML_Tree/XML_Tree_Node object 926 * @access public 927 * @return boolean 928 * @link http://xmlns.com/foaf/0.1/#term_membershipClass FOAF Specification - foaf:membershipClass 929 */ 930 931 function setMembershipClass(&$membership_class) 932 { 933 if ($this->isAllowedForAgent('membershipClass')) { 934 if (is_string($membership_class)) { 935 $membership_tree = new XML_Tree; 936 $membership_tree->getTreeFromString($membership_class); 937 $this->children['membershipclass'] =& $this->foaf->addChild($membership_tree); 938 } else { 939 $this->children['membershipclass'] =& $this->foaf->addChild($membership_class); 940 } 941 return true; 942 } else { 943 return false; 944 } 945 } 946 947 /**#@-*/ 948 949 /* end of Agent only methods */ 950 951 /** 952 * set rdfs:seeAlso 953 * 954 * @param string $uri URI for the resource 955 * @access public 956 * @return boolean 957 * @link http://www.w3.org/TR/rdf-schema/#ch_seealso RDF Schema Specification - rdfs:seeAlso 958 */ 959 960 function addSeeAlso($uri) 961 { 962 $this->children['seealso'][] =& $this->foaf->addChild('rdfs:seeAlso', '', array('rdf:resource' => $uri)); 963 } 964 965 /** 966 * set a foaf:knows 967 * 968 * @foafstatus testing 969 * @param object $foaf_agent XML_FOAF Object for the foaf:knows Agent 970 * @access public 971 * @return boolean 972 * @link http://xmlns.com/foaf/0.1/#term_knows FOAF Specification - foaf:knows 973 */ 974 975 function &addKnows(&$foaf_agent) 976 { 977 $this->knows =& $this->foaf->addChild('foaf:knows'); 978 $this->knows->addChild($foaf_agent->foaf); 979 return true; 980 } 981 982 /** 983 * Add an XML_Tree, XML_Tree_Node object or XML String to the FOAF 984 * 985 * @param mixed $xml_tree XML_Tree, XML_Tree_Node or XML String 986 * @access public 987 * @return boolean 988 */ 989 990 function addChild(&$xml_tree) 991 { 992 if (is_array($xml_tree)) { 993 if (is_string($xml_tree['xml'])) { 994 $tree = new XML_Tree; 995 $tree->getTreeFromString($xml_tree['xml']); 996 $xml_tree['child']->addChild($tree); 997 } else { 998 $xml_tree['child']->addChild($xml_tree['xml']); 999 } 1000 } else { 1001 if (is_string($xml_tree)) { 1002 $tree = new XML_Tree; 1003 $tree->getTreeFromString($xml_tree); 1004 $this->foaf->addChild($tree); 1005 } else { 1006 $this->foaf->addChild($xml_tree); 1007 } 1008 } 1009 } 1010 1011 /** 1012 * Echo the FOAF RDF/XML tree 1013 * 1014 * @param boolean $without_rdf Ouput RDF/XML inside <rdf:RDF> root elements 1015 * @access public 1016 * @return boolean 1017 */ 1018 1019 function dump($without_rdf = false) 1020 { 1021 echo $this->get($without_rdf); 1022 return true; 1023 } 1024 1025 /** 1026 * Return the FOAF RDF/XML tree 1027 * 1028 * @param boolean $without_rdf Return RDF/XML inside <rdf:RDF> root element 1029 * @access public 1030 * @return string 1031 */ 1032 1033 function toXML($without_rdf = false) 1034 { 1035 if ($without_rdf == false) { 1036 $foaf = "<rdf:RDF " .$this->_getXmlns(). ">\n" .$this->foaf->get(). "\n</rdf:RDF>"; 1037 } else { 1038 $foaf = $this->foaf->get(); 1039 } 1040 require_once 'XML/Beautifier.php'; 1041 $beautifier = new XML_Beautifier(); 1042 $foaf = $beautifier->formatString($foaf); 1043 return $foaf; 1044 } 1045 1046 /** 1047 * Alias for toXML 1048 * 1049 * @param boolean $without_rdf Return RDF/XML inside <rdf:RDF> root element 1050 * @access public 1051 * @return string 1052 */ 1053 1054 function get($without_rdf = false) 1055 { 1056 return $this->toXML($without_rdf); 1057 } 1058 1059 1060 /** 1061 * Set an XML Namespace 1062 * 1063 * @param string $qualifier XML Namespace qualifier 1064 * @param string $uri XML Namespace URI 1065 * @access public 1066 * @return boolean 1067 */ 1068 1069 function addXmlns($qualifier,$uri) 1070 { 1071 $this->namespaces[$qualifier] = $uri; 1072 } 1073 1074 /** 1075 * Return XML Namespaces as xml attributes 1076 * 1077 * @access private 1078 * @return string 1079 */ 1080 1081 function _getXmlns() 1082 { 1083 $namespaces = ''; 1084 foreach ($this->namespaces as $qualifier => $uri) { 1085 $namespaces .= ' xmlns:' .$qualifier. ' = "' .$uri. '"'; 1086 } 1087 return $namespaces; 1088 } 1089 1090 /** 1091 * Set default XML Namespaces 1092 * 1093 * @access private 1094 * @return void 1095 */ 1096 1097 function _setXmlns() 1098 { 1099 $this->namespaces['foaf'] = "http://xmlns.com/foaf/0.1/"; 1100 $this->namespaces['rdf'] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 1101 $this->namespaces['rdfs'] = "http://www.w3.org/2000/01/rdf-schema#"; 1102 $this->namespaces['dc'] = "http://purl.org/dc/elements/1.1/"; 1103 } 1104 } 1105 1106 /* 1107 foaf:Person 1108 geekcode, firstName, surname, family_name, plan, img, myersBriggs, workplaceHomepage, workInfoHomepage, schoolHomepage, knows, interest, topic_interest, publications, currentProject, pastProject, based_near, name, maker, depiction, fundedBy, logo, page, theme, dnaChecksum, title, nick, givenname, phone, mbox, mbox_sha1sum, gender, jabberID, aimChatID, icqChatID, yahooChatID, msnChatID, homepage, weblog, made, holdsAccount 1109 1110 foaf:Organization 1111 name, maker, depiction, fundedBy, logo, page, theme, dnaChecksum, title, nick, givenname, phone, mbox, mbox_sha1sum, gender, jabberID, aimChatID, icqChatID, yahooChatID, msnChatID, homepage, weblog, made, holdsAccount 1112 1113 foaf:Group 1114 member, membershipClass, name, maker, depiction, fundedBy, logo, page, theme, dnaChecksum, title, nick, givenname, phone, mbox, mbox_sha1sum, gender, jabberID, aimChatID, icqChatID, yahooChatID, msnChatID, homepage, weblog, made, holdsAccount 1115 */ 1116 1117 ?>
|