| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Dissertation-Appendices

Page history last edited by Nicolas Cynober 16 years, 6 months ago

Back to dissertation.

 


7. Appendices


 

7.1. PLAuth code

/**
* PLAuth class file.
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @link http://www.portallib.net/
* @license http://www.portallib.net/license/
* @version 1.0 6/09/2007
* @package PortalLib
*/

 
/**
* PLAuth
*
* PLAuth handles authentification through OpenID
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @version 1.0 6/09/2007
* @package PortalLib
*/

class PLAuth extends TTextBox {
 
/**
* Array:
* $error['code']
* $error['description']
*/

protected $error;
 
/**
* Initiate the component with a default textbox style
*/

public function onInit($param){
parent::OnInit($param);
 
/* Default Style */
$this->setStyle("background-image:url('../../../core/comps/PLAuth/openid.png');
background-repeat:no-repeat;
padding-left:20px;"
);
}
 
/**
* Request OpenID provider for authentification
*/

public function login(){
$openid = new SimpleOpenID;
$uri = $this->getText();
$openid->SetIdentity($uri);
$openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
$openid->SetRequiredFields(array('email','fullname'));
$openid->SetOptionalFields(array('dob','gender','postcode','country','language','timezone'));
if ($openid->GetOpenIDServer()){
$openid->SetApprovedURL('http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
$openid->Redirect();
}else{
$this->error = $openid->GetError();
return $this->error;
}
}
 
/**
* Check if the authentification has been validated by the provider
*/

public function isValid(){
if($_GET['openid_mode'] == 'id_res'){
$openid = new SimpleOpenID;
$openid->SetIdentity($_GET['openid_identity']);
$openid_validation_result = $openid->ValidateWithServer();
if ($openid_validation_result == true){
return true;
}else if($openid->IsError() == true){
$this->error = $openid->GetError();
return false;
}else{
$this->error = array('code'=>'','description'=>'INVALID AUTHORIZATION');
return false;
}
}else if ($_GET['openid_mode'] == 'cancel'){
return false;
}
}
 
/**
* Return errors
*/

public function getError(){
return $this->error;
}
 
/**
* Check for the provider response
*/

public function isOpenIDResponse(){
if($_GET['openid_mode']) return true;
else return false;
}
}

7.2. PLProfile code

 

7.2.1. PLProfileImport

<?php
 
define("RDFAPI_INCLUDE_DIR", ".");
require_once(RDFAPI_INCLUDE_DIR . "RdfAPI.php");
require_once("foaf.php");
 
/**
* PLProfileImport class file.
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @link http://www.portallib.net/
* @license http://www.portallib.net/license/
* @version 1.0 6/09/2007
* @package PortalLib
*/

 
/**
* PLProfileImport
*
* PLProfileImport handles external FOAF profiles.
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @version 1.0 6/09/2007
* @package PortalLib
*/

class PLProfileImport extends TTextBox {
 
/**
* Initiate the component with a default textbox style
*/

public function onInit($param){
parent::OnInit($param);
 
/* Default Style */
$this->setStyle("background-image:url(./protected/controls/lib/portallib/comps/PLProfile/foaf.png);
background-repeat:no-repeat;
padding-left:40px;"
);
}
 
/**
* Return an HTML table describing the entire RDF file
*/

public function getHtmlTable(){
$url = $this->getText();
$model = ModelFactory::getDefaultModel();
$model->load($url);
ob_start();
$model->writeAsHtmlTable();
$result = ob_get_contents();
ob_end_clean();
return $result;
}
 
/**
* Return a FOAF object containing file's attributes
* NOTE: The XML_FOAF parser didn't work for me so I've decided to use directly RAP.
* e.g.:
* $parser = new XML_FOAF_Parser();
* -> Fatal error: Cannot re-assign $this in /usr/share/pear/XML/FOAF/RAP/model/DbModel.php on line 839
*/

public function getFoafObject(){
 
$foaf = new foaf();
$url = $this->getText();
$model = ModelFactory::getDefaultModel();
$model->load($url);
 
$rdfTypeResource = new Resource("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type");
$foafPersonResource = new Resource("http://xmlns.com/foaf/0.1/", "Person");
$peopleResource = $model->findFirstMatchingStatement(NULL, $rdfTypeResource, $foafPersonResource)->getSubject();
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "name");
$foaf->setName($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "title");
$foaf->setTitle($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "givenname");
$foaf->setGivenName($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "family_name");
$foaf->setFamilyName($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "nick");
$foaf->setNick($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "mbox");
if($object = $model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)){
$foaf->setMbox($object->getLabelObject());
}
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "mbox_sha1sum");
$foaf->setMbox_sha1sum($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "homepage");
$foaf->setHomepage($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "depiction");
$foaf->setDepiction($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "workplaceHomepage");
$foaf->setWorkplaceHomepage($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "workInfoHomepage");
$foaf->setWorkInfoHomepage($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "schoolHomepage");
$foaf->setSchoolHomepage($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "phone");
$foaf->setPhone($model->findFirstMatchingStatement($peopleResource, $rdfTypeResource, NULL)->getLabelObject());
 
$rdfTypeResource = new Resource("http://xmlns.com/foaf/0.1/", "name");
$names = $model->find(NULL, $rdfTypeResource, NULL); //Not the best way to retreive friends.
$namesIterator = $names->getStatementIterator();
$friends = array();
while ($namesIterator->hasNext()) {
$name = $namesIterator->next()->getLabelObject();
if($name != $foaf->getName()){
$friends[] = $name;
}
}
$foaf->setFriends($friends);
 
return $foaf;
}
 
}
 
?>

7.2.2. PLProfileExport

<?php
 
require_once("/usr/share/pear/XML/FOAF.php");
require_once("foaf.php");
 
/**
* PLProfileExport class file.
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @link http://www.portallib.net/
* @license http://www.portallib.net/license/
* @version 1.0 9/09/2007
* @package PortalLib
*/

 
/**
* PLProfileImport
*
* PLProfileImport handles external FOAF profiles.
*
* @author Nicolas Cynober <nicolas.cynober@gmail.com>
* @version 1.0 9/09/2007
* @package PortalLib
*/

class PLProfileExport extends TButton {
 
/**
* Initiate the component with a default button style
*/

public function onInit($param){
parent::OnInit($param);
 
/* Default Style */
$this->setStyle("background-image:url('../../../core/comps/PLProfile/foaf.png');
background-repeat:no-repeat;
width:40px;
height:25px;"
);
}
 
public function getFoafXml($foafObject){
 
$xmlfoaf = new XML_FOAF();
$xmlfoaf->newAgent();
$xmlfoaf->setName($foafObject->getName());
if($foafObject->getTitle())$xmlfoaf->setTitle($foafObject->getTitle());
if($foafObject->getGivenName())$xmlfoaf->setGivenName($foafObject->getGivenName());
if($foafObject->getFamilyName())$xmlfoaf->setFamilyName($foafObject->getFamilyName());
if($foafObject->getNick())$xmlfoaf->addNick($foafObject->getNick());
if($foafObject->getMbox())$xmlfoaf->addMbox($foafObject->getMbox());
if($foafObject->getMbox_sha1sum())$xmlfoaf->addMboxSha1Sum($foafObject->getMbox_sha1sum());
if($foafObject->getHomepage())$xmlfoaf->addHomepage($foafObject->getHomepage());
if($foafObject->getDepiction())$xmlfoaf->addDepiction($foafObject->getDepiction());
if($foafObject->getWorkplaceHomepage())$xmlfoaf->addWorkplaceHomepage($foafObject->getWorkplaceHomepage());
if($foafObject->getWorkInfoHomepage())$xmlfoaf->addWorkInfoHomepage($foafObject->getWorkInfoHomepage());
if($foafObject->getSchoolHomepage())$xmlfoaf->addSchoolHomepage($foafObject->getSchoolHomepage());
if($foafObject->getPhone())$xmlfoaf->addPhone($foafObject->getPhone());
 
return $xmlfoaf->get();
 
}
 
}
 
?>

Comments (0)

You don't have permission to comment on this page.