diff --git a/ktatompub/Client/index.html b/ktatompub/Client/index.html index fae0993..d7c2442 100644 --- a/ktatompub/Client/index.html +++ b/ktatompub/Client/index.html @@ -20,7 +20,7 @@ - + - + */ this.libraries={ @@ -51,7 +51,7 @@ site=new function(){ 'js/ui/ui.core.js' :'jQuery UI Core', 'js/ui/ui.tabs.js' :'jQuery UI Tabs Plugin', 'js/jquery.dynatree.min.js' :'jQuery DynaTree Tree Menu Plugin', - 'js/ktApp.js' :'KT Atom Publishing Protocol Library' + 'js/KT_atom_server.js' :'KT Atom Publishing Protocol Library' } this.init=function(){ diff --git a/ktatompub/auth.php b/ktatompub/auth.php index f76ac4b..d0a8da8 100644 --- a/ktatompub/auth.php +++ b/ktatompub/auth.php @@ -42,7 +42,7 @@ * TODO: Thest HTTP Basic Auth - Try Library From Home */ -$SessionId=KTAPPHelper::login('admin','admin'); +$SessionId=KT_atom_service_helper::login('admin','admin'); $SessionId=$SessionId['session_id']; diff --git a/ktatompub/index.php b/ktatompub/index.php index 94b3aef..1809161 100644 --- a/ktatompub/index.php +++ b/ktatompub/index.php @@ -57,6 +57,7 @@ ob_start(); define('KT_APP_BASE_URI',"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/?/'); define('KT_APP_SYSTEM_URI',"http://".$_SERVER['HTTP_HOST']); +define('KT_ATOM_LIB_FOLDER','lib/'); // Define whether to use in debug mode for viewing generated structures //define('KT_APP_WEB_OUTPUT',false); //defunct @@ -67,37 +68,38 @@ define('KT_APP_SYSTEM_URI',"http://".$_SERVER['HTTP_HOST']); * Includes */ include_once('../ktapi/ktapi.inc.php'); -include_once('lib/ktAPP.inc.php'); -include_once('lib/KTAPPHelper.inc.php'); //Containing helper bridge functions to KtAPI -include_once('lib/KTAPDoc.inc.php'); //Containing the parent class allowing easy XML manipulation -include_once('lib/KTAPPServiceDoc.inc.php'); //Containing the servicedoc class allowing easy ServiceDocument generation -include_once('lib/KTAPPFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation -include_once('lib/KTAPP_ResponseFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation -include_once('lib/ktAPP_Service.inc.php'); -include_once('lib/ktApp.default_dms_services.inc.php'); +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.inc.php'); +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_service_helper.inc.php'); //Containing helper bridge functions to KtAPI +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_baseDoc.inc.php'); //Containing the parent class allowing easy XML manipulation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_serviceDoc.inc.php'); //Containing the servicedoc class allowing easy ServiceDocument generation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_responseFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_service.inc.php'); +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.default_dms_services.inc.php'); include_once('auth.php'); //Containing the authentication protocols //Start the AtomPubProtocol Routing Engine -$APP=new KTAPP(); +$APP=new KT_atom_server(); /** * Register Services * - * Registered services are classes extended from ktAPP_Service + * Registered services are classes extended from KT_atom_service * The registration process takes the following parameters * Workspace :The workspace within which the service collection will be grouped * ServiceName :This is the name by which the service/collection is exposed * ServiceClass :This is the class name of the class to be instantiated when this service is accessed * Title :This is the title given to the service/collection in the servicedocument */ -$APP->registerService('DMS','fulltree','ktAPP_Service_fullTree','Full Document Tree'); -$APP->registerService('DMS','folder','ktAPP_Service_folder','Folder Detail'); -$APP->registerService('DMS','document','ktAPP_Service_document','Document Detail'); +$APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree'); +$APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail'); +$APP->registerService('DMS','document','KT_atom_service_document','Document Detail'); //Execute the current url/header request $APP->execute(); +//echo '
'.print_r($APP,true).'
'; + //Render the resulting feed response $APP->render(); diff --git a/ktatompub/lib/KTAPDoc.inc.php b/ktatompub/lib/KT_atom_baseDoc.inc.php index 22e2d86..fd6670b 100644 --- a/ktatompub/lib/KTAPDoc.inc.php +++ b/ktatompub/lib/KT_atom_baseDoc.inc.php @@ -41,7 +41,7 @@ * Includes */ -class KTAPDoc{ +class KT_atom_baseDoc{ const XML_ENCODING='utf-8'; const XML_VERSION='1.0'; diff --git a/ktatompub/lib/KT_atom_responseFeed.inc.php b/ktatompub/lib/KT_atom_responseFeed.inc.php new file mode 100644 index 0000000..fa64117 --- /dev/null +++ b/ktatompub/lib/KT_atom_responseFeed.inc.php @@ -0,0 +1,45 @@ +constructHeader(); + $this->baseURI=$baseURI; + } + + private function constructHeader(){ + $feed=$this->newElement('feed'); + $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom')); + $this->feed=&$feed; + $this->DOM->appendChild($this->feed); + } + + public function &newEntry(){ + $entry=$this->newElement('entry'); + $this->feed->appendChild($entry); + return $entry; + } + + public function &newField($name=NULL,$value=NULL,&$attachToNode=NULL){ + $field=$this->newElement($name,$value); + if(isset($attachToNode))$attachToNode->appendChild($field); + return $field; + } + + public function render(){ + return $this->formatXmlString(trim($this->DOM->saveXML())); + } + + +} + +class KT_atom_ResponseFeed_GET extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_PUT extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_POST extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_DELETE extends KT_atom_responseFeed{} + +?> \ No newline at end of file diff --git a/ktatompub/lib/ktApp.default_dms_services.inc.php b/ktatompub/lib/KT_atom_server.default_dms_services.inc.php index 917e3a4..423b733 100644 --- a/ktatompub/lib/ktApp.default_dms_services.inc.php +++ b/ktatompub/lib/KT_atom_server.default_dms_services.inc.php @@ -6,13 +6,13 @@ * Tree structure obtained by referencing parent id * */ -class ktAPP_Service_fullTree extends ktAPP_Service { +class KT_atom_service_fulltree extends KT_atom_service { public function GET_action(){ //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); + $feed=new KT_atom_ResponseFeed_GET(KT_APP_BASE_URI); //Invoke the KtAPI to get detail about the referenced document - $tree=KTAPPHelper::getFullTree(); + $tree=KT_atom_service_helper::getFullTree(); //Create the atom response feed foreach($tree as $item){ @@ -28,7 +28,7 @@ class ktAPP_Service_fullTree extends ktAPP_Service { } public function DELETE_action(){ - $feed = new ktAPP_ResponseFeed_DELETE(); + $feed = new KT_atom_ResponseFeed_DELETE(); $this->responseFeed=$feed; } } @@ -42,13 +42,13 @@ class ktAPP_Service_fullTree extends ktAPP_Service { * Returns detail on a particular folder * */ -class ktAPP_Service_folder extends ktAPP_Service { +class KT_atom_service_folder extends KT_atom_service { public function GET_action(){ //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); + $feed=new KT_atom_responseFeed(KT_APP_BASE_URI); //Invoke the KtAPI to get detail about the referenced document - $folderDetail=KTAPPHelper::getFolderDetail($this->params[0]?$this->params[0]:1); + $folderDetail=KT_atom_service_helper::getFolderDetail($this->params[0]?$this->params[0]:1); //Create the atom response feed $entry=$feed->newEntry(); @@ -70,13 +70,13 @@ class ktAPP_Service_folder extends ktAPP_Service { * Returns detail on a particular document * */ -class ktAPP_Service_document extends ktAPP_Service { +class KT_atom_service_document extends KT_atom_service { public function GET_action(){ //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); + $feed=new KT_atom_responseFeed(KT_APP_BASE_URI); //Invoke the KtAPI to get detail about the referenced document - $docDetail=KTAPPHelper::getDocumentDetail($this->params[0]); + $docDetail=KT_atom_service_helper::getDocumentDetail($this->params[0]); //Create the atom response feed $entry=$feed->newEntry(); diff --git a/ktatompub/lib/ktAPP.inc.php b/ktatompub/lib/KT_atom_server.inc.php index 56fd1cc..7ba14cf 100644 --- a/ktatompub/lib/ktAPP.inc.php +++ b/ktatompub/lib/KT_atom_server.inc.php @@ -1,12 +1,17 @@ -queryArray=$queryArray; $this->serviceName=$service; - + $this->method=$reqMethod; + $this->workspace=$workspace; + if($workspace=='servicedocument'){ $this->serviceDocument(); return; } - + $service=$this->getRegisteredService($workspace,$serviceName); - if(is_array($service)){ $serviceClass=$service['serviceClass']; + echo 'made it'; $serviceObject=new $serviceClass($reqMethod,$requestParams,$rawRequest); $this->output=$serviceObject->render(); }else{ - echo "Could not find service:{$service['serviceFunc']} in $workspace"; //TODO: ERROR HERE + $serviceObject=new KT_atom_service($requestParams,$rawRequest); + $serviceObject->setStatus(KT_atom_service::STATUS_NOT_FOUND); + $this->output=$serviceObject->render(); } } public function registerService($workspace=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){ $workspace=strtolower(trim($workspace)); $serviceName=strtolower(trim($serviceName)); - + $serviceRecord=array( 'fileName' =>$fileName, 'serviceClass' =>$serviceClass, 'title' =>$title ); - + $this->services[$workspace][$serviceName]=$serviceRecord; } - + public function getRegisteredService($workspace,$serviceName=NULL){ $serviceName=strtolower(trim($serviceName)); if(isset($this->services[$workspace][$serviceName]))return $this->services[$workspace][$serviceName]; return false; } - + public function serviceDocument(){ - $service=new KTAPPServiceDoc(KT_APP_BASE_URI); - + $service=new KT_atom_serviceDoc(KT_APP_BASE_URI); + foreach($this->services as $workspace=>$collection){ //Creating the Default Workspace for use with standard atomPub Clients $ws=$service->newWorkspace($workspace); - + foreach($collection as $serviceName=>$serviceInstance){ $col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws); } } - + $this->output=$service->getAPPdoc(); } diff --git a/ktatompub/lib/KtAPP_Service.inc.php b/ktatompub/lib/KT_atom_service.inc.php index 459464f..511992f 100644 --- a/ktatompub/lib/KtAPP_Service.inc.php +++ b/ktatompub/lib/KT_atom_service.inc.php @@ -1,12 +1,12 @@ method=$method; $this->params=$params; $this->rawContent=$content; - $this->parsedXMLContent=json_decode(json_encode(@simplexml_load_string($this->rawContent)),true); + $this->parseHeaders(); + $this->parsedXMLContent=$this->xml2array($this->rawContent); $this->setStatus(self::STATUS_OK); - $this->responseFeed=new KTAPPFeed(KT_APP_BASE_URI); + $this->responseFeed=new KT_atom_responseFeed(KT_APP_BASE_URI); switch(strtoupper($this->method)){ case 'GET': $this->GET_action();break; case 'PUT': $this->PUT_action();break; case 'POST': $this->POST_action();break; case 'DELETE': $this->DELETE_action();break; + default: $this->UNSUPPORTED_action();break; } } public function GET_action(){ - $this->setStatus(ktAPP_Service::STATUS_OK); + $this->setStatus(KT_atom_service::STATUS_OK); } public function PUT_action(){ - $this->setStatus(ktAPP_Service::STATUS_NOT_FOUND ); + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); } public function POST_action(){ - $this->setStatus(ktAPP_Service::STATUS_NOT_FOUND ); + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); } public function DELETE_action(){ - $this->setStatus(ktAPP_Service::STATUS_NOT_FOUND ); + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); + } + + public function UNSUPPORTED_action(){ + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); } @@ -53,11 +59,26 @@ class ktAPP_Service{ return $this->responseFeed->render(); } - private function parseHeaders(){ + private function xml2array($xml){ + $array=json_decode(json_encode(@simplexml_load_string($xml)),true); //TODO - XML2ARRAY Translation + return $array; + } + private function parseHeaders(){ + $headers=null; + if(function_exists('http_get_request_headers')){ //Try to use pcre_http library if it exists + $headers=http_get_request_headers(); + }else{ + if(function_exists('apache_request_headers')){ //If not: try to use apache specific headers + $headers=apache_request_headers(); + }else{ //If not: not supported - empty headers + $headers=array(); + } + } + $this->headers=$headers; } - private function setStatus($status=NULL){ + public function setStatus($status=NULL){ header("HTTP/1.1 ".$status); } @@ -65,6 +86,5 @@ class ktAPP_Service{ if($etagValue)header('ETag: '.$etagValue); } - } ?> \ No newline at end of file diff --git a/ktatompub/lib/KTAPPServiceDoc.inc.php b/ktatompub/lib/KT_atom_serviceDoc.inc.php index 5fd44b0..2fa2d37 100644 --- a/ktatompub/lib/KTAPPServiceDoc.inc.php +++ b/ktatompub/lib/KT_atom_serviceDoc.inc.php @@ -41,10 +41,10 @@ /** * Includes */ -include_once('KTAPDoc.inc.php'); +include_once('KT_atom_baseDoc.inc.php'); -class KTAPPServiceDoc extends KTAPDoc { +class KT_atom_serviceDoc extends KT_atom_baseDoc { private $baseURI=NULL; private $service=NULL; diff --git a/ktatompub/lib/KTAPPHelper.inc.php b/ktatompub/lib/KT_atom_service_helper.inc.php index 403981d..299a0f7 100644 --- a/ktatompub/lib/KTAPPHelper.inc.php +++ b/ktatompub/lib/KT_atom_service_helper.inc.php @@ -37,7 +37,7 @@ * */ -class KTAPPHelper{ +class KT_atom_service_helper{ private static $FOLDER_LIST_PROPERTIES=array('id','title','permissions','mime_icon_path'); private static $FILE_LIST_PROPERTIES=array('id','title','document_type','created_by','created_date','checked_out_by','checked_out_date','modified_by','modified_date','owned_by','mime_type','mime_icon_path','mime_display'); private static $FOLDER_RECURSION_LEVEL=100; @@ -49,7 +49,7 @@ class KTAPPHelper{ * @return void */ public function __construct(){ - die('KTAPPHelper should not be instantiated. Only use as a static class'); + die('KT_atom_service_helper should not be instantiated. Only use as a static class'); } @@ -181,11 +181,11 @@ class KTAPPHelper{ $session = $kt->start_session($username,$password, $ip); if (PEAR::isError($session)){ - $response['status_code']=KTAPP_FAILURE; + $response['status_code']=KT_atom_server_FAILURE; $response['session_id']=''; }else{ $session= $session->get_session(); - $response['status_code'] = KTAPP_SUCCESS; + $response['status_code'] = KT_atom_server_SUCCESS; $response['session_id'] = $session; } return $response; @@ -203,10 +203,10 @@ class KTAPPHelper{ $session = $kt->get_active_session($session_id, null); if (PEAR::isError($session)){ - $response['status_code']=KTAPP_FAILURE; + $response['status_code']=KT_atom_server_FAILURE; }else{ $session->logout(); - $response['status_code'] = KTAPP_SUCCESS; + $response['status_code'] = KT_atom_server_SUCCESS; } return $response; } diff --git a/ktatompub/lib/cmis/KTCMISAPPFeed.inc.php b/ktatompub/lib/cmis/KTCMISAPPFeed.inc.php index 973681c..4fc0741 100644 --- a/ktatompub/lib/cmis/KTCMISAPPFeed.inc.php +++ b/ktatompub/lib/cmis/KTCMISAPPFeed.inc.php @@ -40,13 +40,13 @@ /** * Includes */ -include_once('../KTAPDoc.inc.php'); +include_once('../KT_atom_baseDoc.inc.php'); /** * This class generates an AtomPub CMIS feed */ -class KTCMISAPPFeed extends KTAPDoc { +class KTCMISAPPFeed extends KT_atom_baseDoc { private $baseURI = NULL; private $id = NULL; diff --git a/ktatompub/lib/cmis/KTCMISAPPServiceDoc.inc.php b/ktatompub/lib/cmis/KTCMISAPPServiceDoc.inc.php index bee707b..8284faa 100644 --- a/ktatompub/lib/cmis/KTCMISAPPServiceDoc.inc.php +++ b/ktatompub/lib/cmis/KTCMISAPPServiceDoc.inc.php @@ -39,13 +39,13 @@ /** * Includes */ -include_once('../KTAPDoc.inc.php'); +include_once('../KT_atom_baseDoc.inc.php'); /** * This class generates an AtomPub CMIS service document */ -class KTCMISAPPServiceDoc extends KTAPDoc { +class KTCMISAPPServiceDoc extends KT_atom_baseDoc { private $baseURI=NULL; private $service=NULL; diff --git a/ktatompub/lib/ktAPP_ResponseFeed.inc.php b/ktatompub/lib/ktAPP_ResponseFeed.inc.php deleted file mode 100644 index bee5aa7..0000000 --- a/ktatompub/lib/ktAPP_ResponseFeed.inc.php +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/ktatompub/phpinfo.php b/ktatompub/phpinfo.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/ktatompub/phpinfo.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/ktatompub/services/cmis/NavigationService.inc.php b/ktatompub/services/cmis/NavigationService.inc.php deleted file mode 100644 index fe47e18..0000000 --- a/ktatompub/services/cmis/NavigationService.inc.php +++ /dev/null @@ -1,124 +0,0 @@ - diff --git a/ktatompub/services/cmis/ObjectFeed.inc.php b/ktatompub/services/cmis/ObjectFeed.inc.php deleted file mode 100644 index 5c8d4f4..0000000 --- a/ktatompub/services/cmis/ObjectFeed.inc.php +++ /dev/null @@ -1,92 +0,0 @@ -newEntry(); - $feed->newId('urn:uuid:' . $cmisEntry['properties']['Name']['value'] . '-' - . strtolower($cmisEntry['properties']['ObjectTypeId']['value']), $entry); - - /* - - - - */ - - // links -// $link = $feed->newElement('link'); -// $link->appendChild($feed->newAttr('rel','self')); -// $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . strtolower($cmisEntry['properties']['ObjectTypeId']['value']) -// . '/' . $cmisEntry['properties']['ObjectId']['value'])); -// $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-parent')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $path)); - $entry->appendChild($link); - - if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'folder') - { - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-folderparent')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $path)); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-children')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI - . strtolower($cmisEntry['properties']['ObjectTypeId']['value']) - . '/' . $path . '/' . urlencode($cmisEntry['properties']['Name']['value']) - . '/children')); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-descendants')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI - . strtolower($cmisEntry['properties']['ObjectTypeId']['value']) - . '/' . $path . '/' . urlencode($cmisEntry['properties']['Name']['value']) - . '/descendants')); - $entry->appendChild($link); - } - - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-type')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($cmisEntry['properties']['ObjectTypeId']['value']))); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-repository')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'repository')); - $entry->appendChild($link); - // end links - - $entry->appendChild($feed->newElement('summary', $cmisEntry['properties']['Name']['value'])); - $entry->appendChild($feed->newElement('title', $cmisEntry['properties']['Name']['value'])); - - // main CMIS entry - $objectElement = $feed->newElement('cmis:object'); - $propertiesElement = $feed->newElement('cmis:properties'); - - foreach($cmisEntry['properties'] as $propertyName => $property) - { - $propElement = $feed->newElement('cmis:' . $property['type']); - $propElement->appendChild($feed->newAttr('cmis:name', $propertyName)); - $feed->newField('value', CMISUtil::boolToString($property['value']), $propElement); - $propertiesElement->appendChild($propElement); - } - - $objectElement->appendChild($propertiesElement); - $entry->appendChild($objectElement); - } - -} - -?> diff --git a/ktatompub/services/cmis/ObjectService.inc.php b/ktatompub/services/cmis/ObjectService.inc.php deleted file mode 100644 index 728de1f..0000000 --- a/ktatompub/services/cmis/ObjectService.inc.php +++ /dev/null @@ -1,37 +0,0 @@ - diff --git a/ktatompub/services/cmis/RepositoryService.inc.php b/ktatompub/services/cmis/RepositoryService.inc.php deleted file mode 100644 index 55a3a80..0000000 --- a/ktatompub/services/cmis/RepositoryService.inc.php +++ /dev/null @@ -1,85 +0,0 @@ - diff --git a/ktatompub/services/cmis/checkedout.inc.php b/ktatompub/services/cmis/checkedout.inc.php deleted file mode 100644 index 308baff..0000000 --- a/ktatompub/services/cmis/checkedout.inc.php +++ /dev/null @@ -1,50 +0,0 @@ -startSession($username, $password); - -$repositories = $RepositoryService->getRepositories(); -$repositoryId = $repositories[0]['repositoryId']; - -$checkedout = $NavigationService->getCheckedoutDocs($repositoryId); - -$feed = new KTCMISAPPFeed(KT_APP_BASE_URI, 'Checked out Documents', null, null, null, 'urn:uuid:checkedout'); - -foreach($checkedout as $document) -{ - $entry = $feed->newEntry(); - $objectElement = $feed->newElement('cmis:object'); - $propertiesElement = $feed->newElement('cmis:properties'); - - foreach($cmisEntry['properties'] as $propertyName => $property) - { - $propElement = $feed->newElement('cmis:' . $property['type']); - $propElement->appendChild($feed->newAttr('cmis:name', $propertyName)); - $feed->newField('value', CMISUtil::boolToString($property['value']), $propElement); - $propertiesElement->appendChild($propElement); - } - - $objectElement->appendChild($propertiesElement); - $entry->appendChild($objectElement); -} - -$entry = null; -$feed->newField('hasMoreItems', 'false', $entry, true); - -$output = $feed->getAPPdoc(); - -?> diff --git a/ktatompub/services/cmis/document.inc.php b/ktatompub/services/cmis/document.inc.php deleted file mode 100644 index 1b765b3..0000000 --- a/ktatompub/services/cmis/document.inc.php +++ /dev/null @@ -1,98 +0,0 @@ -getProperties($repositoryId, $documentId, false, false); - - $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $cmisEntry['properties']['ObjectTypeId']['value'], null, null, null, - 'urn:uuid:' . $cmisEntry['properties']['ObjectId']['value']); - - CMISDocumentFeed::createEntry($feed, $cmisEntry, $cmisEntry['properties']['ParentId']['value']); - - // false - - $output = $feed->getAPPdoc(); - - $outputs = ' - - -admin -urn:uuid:2df9d676-f173-47bb-8ec1-41fa1186b66d - - - - - - - - -2009-06-23T09:40:47.889+02:00 - -h4555-cmis-so.pdf -2009-06-23T09:40:58.524+02:00 - - -workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d -document -document -admin -2009-06-23T09:40:47.889+02:00 -admin -2009-06-23T09:40:58.524+02:00 -h4555-cmis-so.pdf -false -true -false -false - -workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d -false - - - -343084 -application/pdf -h4555-cmis-so.pdf -http://127.0.0.1:8080/alfresco/service/api/node/workspace/SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d/content.h4555-cmis-so.pdf - - - -2009-06-23T09:40:58.524+02:00 -http://127.0.0.1:8080/alfresco/images/filetypes/pdf.gif - -'; - - return $output; - } - -} - -include 'services/cmis/RepositoryService.inc.php'; -include 'services/cmis/ObjectService.inc.php'; - -$RepositoryService = new RepositoryService(); -$repositories = $RepositoryService->getRepositories(); -$repositoryId = $repositories[0]['repositoryId']; - -$ObjectService = new ObjectService(); -$ObjectService->startSession($username, $password); - -$output = CMISDocumentFeed::getDocumentFeed($ObjectService, $repositoryId, $query[2]); - -?> diff --git a/ktatompub/services/cmis/folder.inc.php b/ktatompub/services/cmis/folder.inc.php deleted file mode 100644 index 24ced47..0000000 --- a/ktatompub/services/cmis/folder.inc.php +++ /dev/null @@ -1,540 +0,0 @@ -getChildren($repositoryId, $folderId, false, false); - } - else if ($feedType == 'descendants') - { - $entries = $NavigationService->getDescendants($repositoryId, $folderId, $includeAllowableActions, $includeRelationships); - } - else - { - // error, we shouldn't be here, if we are then the wrong function was called - } - - $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $folderName . ' ' . ucwords($feedType), null, null, null, - 'urn:uuid:' . $folderName . '-' . $feedType); - - foreach($entries as $cmisEntry) - { - CMISFolderFeed::createEntry($feed, $cmisEntry, $folderName); - } - - // false - - $output = $feed->getAPPdoc(); - $outputs = ' - - urn:uuid:28537649-8af2-4c74-aa92-5d8bbecac9ce-children - - Root Folder Children - - urn:uuid:86224486-b7ae-4074-a793-82cd259b0026-folder - - - - - - DroppedDocuments - DroppedDocuments - - - - - F2 - - - Folder - - - DroppedDocuments - - - - - - - urn:uuid:86224486-b7ae-4074-a793-82cd259b0026-folder - - - - - - Test KT Folder - Test KT Folder - - - - F4 - - - - Folder - - - Test KT Folder - - - - - - - admin - urn:uuid:2df9d676-f173-47bb-8ec1-41fa1186b66d - - - - - - - - - - 2009-06-23T09:40:47.889+02:00 - - h4555-cmis-so.pdf - 2009-06-23T09:40:58.524+02:00 - - - - workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d - document - document - admin - - 2009-06-23T09:40:47.889+02:00 - admin - 2009-06-23T09:40:58.524+02:00 - h4555-cmis-so.pdf - false - - true - false - false - - workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d - - false - - - - 343084 - application/pdf - h4555-cmis-so.pdf - - http://10.33.4.34:8080/alfresco/service/api/node/workspace/SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d/content.h4555-cmis-so.pdf - - - - - - '; - - $outputs = ' - -System -Alfresco (Labs) -http://10.33.4.34:8080/alfresco/images/logo/AlfrescoLogo16.ico -urn:uuid:28537649-8af2-4c74-aa92-5d8bbecac9ce-children - - - - - -Company Home Children -2009-06-18T10:20:29.937+02:00 - -System -e98319fa-76e4-478f-8ce8-a3a0fd683e2c -urn:uuid:e98319fa-76e4-478f-8ce8-a3a0fd683e2c - - - - - - - - - - - -2009-06-18T10:20:37.788+02:00 -Site Collaboration Spaces -Sites -2009-06-18T10:20:37.874+02:00 - - - -workspace://SpacesStore/e98319fa-76e4-478f-8ce8-a3a0fd683e2c -folder -F/st_sites -System - -2009-06-18T10:20:37.788+02:00 -System -2009-06-18T10:20:37.874+02:00 -Sites -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - -2009-06-18T10:20:37.874+02:00 -http://10.33.4.34:8080/alfresco/images/icons/space-icon-default-16.gif - - -System -8c80a0f7-74b4-4bd8-bb76-a2464e4b2d10 -urn:uuid:8c80a0f7-74b4-4bd8-bb76-a2464e4b2d10 - - - - - - - - - - - -2009-06-18T10:20:29.939+02:00 -User managed definitions -Data Dictionary -2009-06-18T10:20:30.004+02:00 - - - -workspace://SpacesStore/8c80a0f7-74b4-4bd8-bb76-a2464e4b2d10 -folder -folder -System - -2009-06-18T10:20:29.939+02:00 -System -2009-06-18T10:20:30.004+02:00 -Data Dictionary -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - -2009-06-18T10:20:30.004+02:00 -http://10.33.4.34:8080/alfresco/images/icons/space-icon-default-16.gif - - -System -ba2524ef-7f3d-4ed4-84a0-8d99b6524737 -urn:uuid:ba2524ef-7f3d-4ed4-84a0-8d99b6524737 - - - - - - - - - - - -2009-06-18T10:20:30.312+02:00 -The guest root space -Guest Home - -2009-06-18T10:20:30.400+02:00 - - -workspace://SpacesStore/ba2524ef-7f3d-4ed4-84a0-8d99b6524737 -folder -folder -System - -2009-06-18T10:20:30.312+02:00 -System -2009-06-18T10:20:30.400+02:00 -Guest Home -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - -2009-06-18T10:20:30.400+02:00 -http://10.33.4.34:8080/alfresco/images/icons/space-icon-default-16.gif - - -System -86224486-b7ae-4074-a793-82cd259b0026 -urn:uuid:86224486-b7ae-4074-a793-82cd259b0026 - - - - - - - - - - - -2009-06-18T10:20:30.402+02:00 -User Homes -User Homes -2009-06-18T10:20:30.428+02:00 - - - -workspace://SpacesStore/86224486-b7ae-4074-a793-82cd259b0026 -folder -folder -System - -2009-06-18T10:20:30.402+02:00 -System -2009-06-18T10:20:30.428+02:00 -User Homes -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - -2009-06-18T10:20:30.428+02:00 -http://10.33.4.34:8080/alfresco/images/icons/space-icon-default-16.gif - - -System -0df9087f-e334-4890-a467-b60e3d6be92c -urn:uuid:0df9087f-e334-4890-a467-b60e3d6be92c - - - - - - - - - - - -2009-06-18T10:20:45.115+02:00 -Web Content Management Spaces -Web Projects -2009-06-18T10:20:45.137+02:00 - - - -workspace://SpacesStore/0df9087f-e334-4890-a467-b60e3d6be92c -folder -folder -System - -2009-06-18T10:20:45.115+02:00 -System -2009-06-18T10:20:45.137+02:00 -Web Projects -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - -2009-06-18T10:20:45.137+02:00 -http://10.33.4.34:8080/alfresco/images/icons/space-icon-default-16.gif - - -admin -urn:uuid:2df9d676-f173-47bb-8ec1-41fa1186b66d - - - - - - - - - -2009-06-23T09:40:47.889+02:00 - -h4555-cmis-so.pdf -2009-06-23T09:40:58.524+02:00 - - - -workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d -document -document -admin - -2009-06-23T09:40:47.889+02:00 -admin -2009-06-23T09:40:58.524+02:00 -h4555-cmis-so.pdf -false - -true -false -false - -workspace://SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d - -false - - - -343084 -application/pdf -h4555-cmis-so.pdf - -http://10.33.4.34:8080/alfresco/service/api/node/workspace/SpacesStore/2df9d676-f173-47bb-8ec1-41fa1186b66d/content.h4555-cmis-so.pdf - - - -2009-06-23T09:40:58.524+02:00 -http://10.33.4.34:8080/alfresco/images/filetypes/pdf.gif - -false -6 -0 - -0 -'; - - return $output; - } - - /** - * Retrieves data about a specific folder - * - * @param object $ObjectService The CMIS service - * @param string $repositoryId - * @param string $folderId - * @return string CMIS AtomPub feed - */ - static public function getFolderFeed($ObjectService, $repositoryId, $folderId) - { - $cmisEntry = $ObjectService->getProperties($repositoryId, $folderId, false, false); - - $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $cmisEntry['properties']['ObjectTypeId']['value'], null, null, null, - 'urn:uuid:' . $cmisEntry['properties']['ObjectId']['value']); - - CMISFolderFeed::createEntry($feed, $cmisEntry, $cmisEntry['properties']['ParentId']['value']); - - // false - - $output = $feed->getAPPdoc(); - - $outputs = ' - - -System -28537649-8af2-4c74-aa92-5d8bbecac9ce -urn:uuid:28537649-8af2-4c74-aa92-5d8bbecac9ce - - - - - - - - -2009-06-18T10:20:29.871+02:00 -The company root space -Company Home -2009-06-18T10:20:29.937+02:00 - - -workspace://SpacesStore/28537649-8af2-4c74-aa92-5d8bbecac9ce -folder -folder -System -2009-06-18T10:20:29.871+02:00 -System -2009-06-18T10:20:29.937+02:00 -Company Home - - - - -2009-06-18T10:20:29.937+02:00 -http://127.0.0.1:8080/alfresco/images/icons/space-icon-default-16.gif - -'; - - return $output; - } - - static public function getFolderData($query, &$folderName, &$tree) - { - $ktapi = new KTAPI(); - $ktapi->start_session('admin', 'admin'); - - $numQ = count($query); - $numFolders = $numQ-3; - $folderId = 1; - - if ($query[$numQ-1] == 'children' || $query[$numQ-1] == 'descendants') - { - $tree = $query[$numQ-1]; - } - - $start = 0; - while($start < $numFolders-1) - { - $folderName = urldecode($query[$numQ-$numFolders+$start]); - $folder = $ktapi->get_folder_by_name($folderName, $folderId); - $folderId = $folder->get_folderid(); - ++$start; - } - - return CMISUtil::encodeObjectId('Folder', $folderId); - } -} - -include 'services/cmis/RepositoryService.inc.php'; -include 'services/cmis/NavigationService.inc.php'; -include 'services/cmis/ObjectService.inc.php'; - -$RepositoryService = new RepositoryService(); -$repositories = $RepositoryService->getRepositories(); -$repositoryId = $repositories[0]['repositoryId']; - -$folderId = CMISFolderFeed::getFolderData($query, $folderName, $tree); - -if (isset($tree) && (($tree == 'children') || ($tree == 'descendants'))) -{ - $NavigationService = new NavigationService(); - $NavigationService->startSession($username, $password); - - $output = CMISFolderFeed::getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $tree); -} -else -{ - $ObjectService = new ObjectService(); - $ObjectService->startSession($username, $password); - - $output = CMISFolderFeed::getFolderFeed($ObjectService, $repositoryId, $folderId); -} - -?> diff --git a/ktatompub/services/cmis/index.php b/ktatompub/services/cmis/index.php deleted file mode 100644 index 3381d57..0000000 --- a/ktatompub/services/cmis/index.php +++ /dev/null @@ -1,45 +0,0 @@ - diff --git a/ktatompub/services/cmis/servicedocument.inc.php b/ktatompub/services/cmis/servicedocument.inc.php deleted file mode 100644 index a6e3903..0000000 --- a/ktatompub/services/cmis/servicedocument.inc.php +++ /dev/null @@ -1,61 +0,0 @@ -getRepositories(); -// fetch for default first repo; NOTE that this will probably have to change at some point, quick and dirty for now -$repositoryInfo = $RepositoryService->getRepositoryInfo($repositories[0]['repositoryId']); - -// generate service document -$service = new KTCMISAPPServiceDoc(KT_APP_BASE_URI); -$ws = $service->newWorkspace($repositoryInfo['repositoryName']); -$ws->appendChild($service->newAttr('cmis:repositoryRelationship', $repositoryInfo['repositoryRelationship'])); - -// repository information -$element = $service->newElement('cmis:repositoryInfo'); -foreach($repositoryInfo as $key => $repoData) -{ - if ($key == 'rootFolderId') - { - $repoData = CMIS_BASE_URI . 'folder/' . $repoData; - } - - if (!is_array($repoData)) - { - $element->appendChild($service->newElement('cmis:' . $key, $repoData)); - } - else - { - $elementSub = $service->newElement('cmis:' . $key); - foreach($repoData as $key2 => $data) - { - $elementSub->appendChild($service->newElement('cmis:' . $key2, CMISUtil::boolToString($data))); - } - $element->appendChild($elementSub); - } -} -$ws->appendChild($element); - -// collection links -$col = $service->newCollection(CMIS_BASE_URI . 'folder/' . $repositoryInfo['rootFolderId'] . '/children', - 'Root Folder Children Collection', 'root-children', $ws); -$col = $service->newCollection(CMIS_BASE_URI . 'folder/' . $repositoryInfo['rootFolderId'] . '/descendants', - 'Root Folder Descendant Collection', 'root-descendants', $ws); -$col = $service->newCollection(CMIS_BASE_URI . 'checkedout', 'Checked Out Document Collection', 'checkedout', $ws); -$col = $service->newCollection(CMIS_BASE_URI . 'types', 'Object Type Collection', 'types-children', $ws); -$col = $service->newCollection(CMIS_BASE_URI . 'types', 'Object Type Collection', 'types-descendants', $ws); - -$output = $service->getAPPdoc(); - -?> \ No newline at end of file diff --git a/ktatompub/services/cmis/types.inc.php b/ktatompub/services/cmis/types.inc.php deleted file mode 100644 index b55f2fa..0000000 --- a/ktatompub/services/cmis/types.inc.php +++ /dev/null @@ -1,148 +0,0 @@ -startSession($username, $password); - -// fetch repository id -$repositories = $RepositoryService->getRepositories(); -$repositoryId = $repositories[0]['repositoryId']; - -switch($arg) -{ - case 'type': - { - if (!isset($query[3])) - { - $type = ucwords($query[2]); - $types = $RepositoryService->getTypes($repositoryId, $type); - $output = CMISTypeFeed::getTypeFeed($type, $types); - } - else - { - // TODO dynamic dates, as needed everywhere - // NOTE children of types not yet implemented and we don't support any non-basic types at this time - $output = CMISTypeFeed::getTypeChildrenFeed($query[2]); - } - } - break; - case 'types': - $types = $RepositoryService->getTypes($repositoryId); - $type = (($query[2] == '') ? 'all' : $query[2]); - $output = CMISTypeFeed::getTypeFeed($type, $types); - break; -} - -/** - * Class to generate CMIS AtomPub feeds for Type responses - */ - -class CMISTypeFeed { - - /** - * Retrieves the list of types as a CMIS AtomPub feed - * - * @param string $typeDef Type requested - 'All Types' indicates a listing, else only a specific type - * @param array $types The types found - * @return string CMIS AtomPub feed - */ - static public function getTypeFeed($typeDef, $types) - { - $typesString = ''; - $typesHeading = ''; - switch($typeDef) - { - case 'all': - case 'children': - case 'descendants': - $typesString = 'types-' . $typeDef; - $typesHeading = 'All Types'; - break; - default: - $typesString = 'type-' . $typeDef; - $typesHeading = $typeDef; - break; - } - - $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $typesHeading, null, null, null, 'urn:uuid:' . $typesString); - - foreach($types as $type) - { - $entry = $feed->newEntry(); - $feed->newId('urn:uuid:type-' . strtolower($type['typeId']), $entry); - - // links - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','self')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']))); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-type')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']))); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-children')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']) . '/children')); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-descendants')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'type/' . strtolower($type['typeId']) . '/descendants')); - $entry->appendChild($link); - $link = $feed->newElement('link'); - $link->appendChild($feed->newAttr('rel','cmis-repository')); - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'repository')); - $entry->appendChild($link); - - $entry->appendChild($feed->newElement('summary', $type['typeId'] . ' Type')); - $entry->appendChild($feed->newElement('title', $type['typeId'])); - - // main CMIS entry - $feedElement = $feed->newElement('cmis:' . strtolower($type['typeId']) . 'Type'); - foreach($type as $property => $value) - { - $feed->newField($property, CMISUtil::boolToString($value), $feedElement); - } - - $entry->appendChild($feedElement); - } - - $output = $feed->getAPPdoc(); - - return $output; - } - - /** - * Retrieves a list of child types for the supplied type - * - * NOTE this currently returns a hard coded empty list, since we do not currently support child types - * TODO make dynamic if/when we support checking for child types (we don't actually need to support child types themselves) - * - * @param string $type - * @return string CMIS AtomPub feed - */ - static public function getTypeChildrenFeed($type) - { - $output = ' - -urn:uuid:type-' . $type . '-children - - - -Child types of ' . $type . ' -2009-06-23T13:40:32.786+02:00 -false -'; - - return $output; - } - -} - -?> \ No newline at end of file diff --git a/ktatompub/services/document.inc.php b/ktatompub/services/document.inc.php deleted file mode 100644 index 7bcd33f..0000000 --- a/ktatompub/services/document.inc.php +++ /dev/null @@ -1,56 +0,0 @@ -. - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, - * California 94120-7775, or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): - * Mark Holtzhausen - * - */ - - //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); - - //Invoke the KtAPI to get detail about the referenced document - $docDetail=KTAPPHelper::getDocumentDetail($query[1]); - - //Create the atom response feed - $entry=$feed->newEntry(); - foreach($docDetail['results'] as $property=>$value){ - $feed->newField($property,$value,$entry); - } - //Add a downloaduri field manually - $feed->newField('downloaduri',urlencode(KT_APP_SYSTEM_URI.'/action.php?kt_path_info=ktcore.actions.document.view&fDocumentId='.$docDetail['results']['document_id']),$entry); - - //Generate and set the output - $output=$feed->getAPPdoc(); -?> \ No newline at end of file diff --git a/ktatompub/services/fulltree.inc.php b/ktatompub/services/fulltree.inc.php deleted file mode 100644 index 000ffe2..0000000 --- a/ktatompub/services/fulltree.inc.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, - * California 94120-7775, or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): - * Mark Holtzhausen - * - */ - - //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); - - //Invoke the KtAPI to get detail about the referenced document - $tree=KTAPPHelper::getFullTree(); - - //Create the atom response feed - foreach($tree as $item){ - $id=$item['id']; - $entry=$feed->newEntry(); - $feed->newField('id',$id,$entry); - foreach($item as $property=>$value){ - $feed->newField($property,$value,$entry); - } - } - - - //Generate and set the output - $output=$feed->getAPPdoc(); -?> \ No newline at end of file diff --git a/ktatompub/services/servicedocument.inc.php b/ktatompub/services/servicedocument.inc.php deleted file mode 100644 index 949e9d2..0000000 --- a/ktatompub/services/servicedocument.inc.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, - * California 94120-7775, or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): - * Mark Holtzhausen - * - */ - - $service=new KTAPPServiceDoc(KT_APP_BASE_URI); - - //Creating the Default Workspace for use with standard atomPub Clients - $ws=$service->newWorkspace('DMS'); - $col=$service->newCollection(KT_APP_BASE_URI.'fulltree/','Full Document Tree',$ws); - $col=$service->newCollection(KT_APP_BASE_URI.'folder/','Folder Detail',$ws); - $col=$service->newCollection(KT_APP_BASE_URI.'document/','Document Detail',$ws); - $col=$service->newCollection(KT_APP_BASE_URI.'mimetypes/','Supported Mime Types',$ws); - - -/* NOT YET IMPLEMENTED - Conceptual Spec Only * / - //Creating an additional Enhanced Workspace for webservices via atomPub - $ws=$service->newWorkspace('REST'); - $col=$service->newCollection(KT_APP_BASE_URI.'REST/serviceList','Full Document Tree',$ws); - $col=$service->newCollection(KT_APP_BASE_URI.'REST/[controller]/[function]/[param1]/[param2]','RPC via REST',$ws); -/* */ - - - $output=$service->getAPPdoc(); -?> \ No newline at end of file diff --git a/ktatompub/xmlparsetest.php b/ktatompub/xmlparsetest.php index 588e897..33a0117 100644 --- a/ktatompub/xmlparsetest.php +++ b/ktatompub/xmlparsetest.php @@ -1,30 +1,27 @@ '; - private $namespaces=array(); - - public function __construct($xml=NULL){ - if($xml)$this->xml=simplexml_load_string($xml); - $this->namespaces=$this->xml->getNamespaces(true); - } - - public function parse2array(){ - return $this->parseTag($this->xml); + public static function parse($xml){ + return self::parsetag(simplexml_load_string($xml)); } - private function parsetag($xml,$ns=NULL){ + private static function parsetag($xml,$ns=NULL,$rootXML=NULL){ + if(!$rootXML)$rootXML=$xml; $tagName=$xml->getName(); if($ns)$tagName=$ns.':'.$tagName; - //$tagAttributes=(array)$xml->attributes(); $tagAttributes=isset($tagAttributes['@attributes'])?$tagAttributes['@attributes']:array(); $array=array(); - $array[$tagName]['@attributes']=$this->getAttributes($xml); - if($this->hasChildren($xml)){ - $children=$this->getChildren($xml); - foreach($children as $childName=>$child){ - $childName=split(':',$childName); - $childParsed=$this->parsetag($child,$childName[0]); - $array[$tagName]=array_merge($array[$tagName],$childParsed); + $array[$tagName]['@attributes']=self::getAttributes($xml,$rootXML); + if(self::hasChildren($xml,$rootXML)){ + $children=self::getChildren($xml,$rootXML); + echo ''.$tagName.'
'.print_r($children,true).'
'; + foreach($children as $fullChildName=>$childCollection){ + //$child=$childCollection; + $childName=split(':',$fullChildName); + foreach($childCollection as $child){ + $childParsed=self::parsetag($child,$childName[0],$rootXML); + //$cIndex=count($array[$tagName][$childName]); + $array[$tagName][]=$childParsed; + } } }else{ @@ -33,13 +30,14 @@ class xml2array{ return $array; } - private function hasChildren($xml){ - return count($this->getChildren($xml))>0; + private static function hasChildren($xml,$rootXML){ + return count(self::getChildren($xml,$rootXML))>0; } - private function getAttributes($xml){ + private static function getAttributes($xml,$rootXML){ $attr=array(); - foreach($this->namespaces as $namespace=>$uri){ + $namespaces=$rootXML->getNamespaces(true); + foreach($namespaces as $namespace=>$uri){ $nsAttrs=(array)$xml->attributes($uri); $nsAttrs=isset($nsAttrs['@attributes'])?$nsAttrs['@attributes']:array(); foreach($nsAttrs as $nsAttr=>$nsAttrVal){ //TODO: Support for multiple same name tags @@ -49,12 +47,16 @@ class xml2array{ return $attr; } - private function getChildren($xml){ + private static function getChildren($xml,$rootXML){ $children=array(); - foreach($this->namespaces as $namespace=>$uri){ + $namespaces=$rootXML->getNamespaces(true); + foreach($namespaces as $namespace=>$uri){ $nsChildren=$xml->children($uri); foreach($nsChildren as $nsChild){ //TODO: Support for multiple same name tags - $children[$namespace.':'.$nsChild->getName()]=$nsChild; + $childRealName=$namespace.':'.$nsChild->getName(); + if(!isset($children[$childRealName]))$children[$childRealName]=array(); + if(!is_array($children[$childRealName]))$children[$childRealName]=array(); + $children[$childRealName][]=$nsChild; } } return $children; @@ -63,6 +65,7 @@ class xml2array{ } + $xml=' @@ -121,15 +124,15 @@ $xml=' $sxml=simplexml_load_string($xml); $struct=json_decode(json_encode($sxml),true); -$nxml=new xml2array($xml); + echo '
'.htmlentities($xml).'
'; //echo '
'.print_r($struct,true).'
'; //echo '
'.print_r($sxml,true).'
'; //cho '
'.print_r(xml2array($xml),true).'
'; -echo '
'.print_r($nxml->parse2array(),true).'
'; +echo '
'.print_r(xml2array::parse($xml),true).'
'; -echo http_get_request_headers(); +//echo http_get_request_headers(); ?> \ No newline at end of file diff --git a/ktatompub/services/folder.inc.php b/webservice/atompub/auth.php index 2d49982..d0a8da8 100644 --- a/ktatompub/services/folder.inc.php +++ b/webservice/atompub/auth.php @@ -32,23 +32,18 @@ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. - * Contributor( s): + * Contributor( s): * Mark Holtzhausen * */ - //Create a new response feed - $feed=new KTAPPFeed(KT_APP_BASE_URI); +/** + * Automatic Login bypassing HTTP Basic Auth + * TODO: Thest HTTP Basic Auth - Try Library From Home + */ - //Invoke the KtAPI to get detail about the referenced document - $folderDetail=KTAPPHelper::getFolderDetail($query[1]); +$SessionId=KT_atom_service_helper::login('admin','admin'); +$SessionId=$SessionId['session_id']; - //Create the atom response feed - $entry=$feed->newEntry(); - foreach($folderDetail as $property=>$value){ - $feed->newField($property,$value,$entry); - } - //Generate and set the output - $output=$feed->getAPPdoc(); ?> \ No newline at end of file diff --git a/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php b/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php new file mode 100644 index 0000000..423b733 --- /dev/null +++ b/webservice/atompub/demodms/KT_atom_server.default_dms_services.inc.php @@ -0,0 +1,93 @@ +newEntry(); + $feed->newField('id',$id,$entry); + foreach($item as $property=>$value){ + $feed->newField($property,$value,$entry); + } + } + //Expose the responseFeed + $this->responseFeed=$feed; + } + + public function DELETE_action(){ + $feed = new KT_atom_ResponseFeed_DELETE(); + $this->responseFeed=$feed; + } +} + + + + +/** + * AtomPub Service: folder + * + * Returns detail on a particular folder + * + */ +class KT_atom_service_folder extends KT_atom_service { + public function GET_action(){ + //Create a new response feed + $feed=new KT_atom_responseFeed(KT_APP_BASE_URI); + + //Invoke the KtAPI to get detail about the referenced document + $folderDetail=KT_atom_service_helper::getFolderDetail($this->params[0]?$this->params[0]:1); + + //Create the atom response feed + $entry=$feed->newEntry(); + foreach($folderDetail as $property=>$value){ + $feed->newField($property,$value,$entry); + } + + //Expose the responseFeed + $this->responseFeed=$feed; + } +} + + + + +/** + * AtomPub Service: document + * + * Returns detail on a particular document + * + */ +class KT_atom_service_document extends KT_atom_service { + public function GET_action(){ + //Create a new response feed + $feed=new KT_atom_responseFeed(KT_APP_BASE_URI); + + //Invoke the KtAPI to get detail about the referenced document + $docDetail=KT_atom_service_helper::getDocumentDetail($this->params[0]); + + //Create the atom response feed + $entry=$feed->newEntry(); + foreach($docDetail['results'] as $property=>$value){ + $feed->newField($property,$value,$entry); + } + //Add a downloaduri field manually + $feed->newField('downloaduri',urlencode(KT_APP_SYSTEM_URI.'/action.php?kt_path_info=ktcore.actions.document.view&fDocumentId='.$docDetail['results']['document_id']),$entry); + + //Expose the responseFeed + $this->responseFeed=$feed; + } +} +?> \ No newline at end of file diff --git a/webservice/atompub/demodms/KT_atom_service_helper.inc.php b/webservice/atompub/demodms/KT_atom_service_helper.inc.php new file mode 100644 index 0000000..299a0f7 --- /dev/null +++ b/webservice/atompub/demodms/KT_atom_service_helper.inc.php @@ -0,0 +1,227 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): + * Mark Holtzhausen + * + */ + +class KT_atom_service_helper{ + private static $FOLDER_LIST_PROPERTIES=array('id','title','permissions','mime_icon_path'); + private static $FILE_LIST_PROPERTIES=array('id','title','document_type','created_by','created_date','checked_out_by','checked_out_date','modified_by','modified_date','owned_by','mime_type','mime_icon_path','mime_display'); + private static $FOLDER_RECURSION_LEVEL=100; + private static $kt=NULL; + + /** + * Make sure the class is always treated statically and never instantiated. + * + * @return void + */ + public function __construct(){ + die('KT_atom_service_helper should not be instantiated. Only use as a static class'); + } + + + /** + * Get the KT singleton instance + * + * @return object + */ + public static function getKt(){ + if(!isset(self::$kt)){ + self::$kt=new KTAPI(); + self::$kt->get_active_session(session_id()); + } + return self::$kt; + } + + + /** + * Get the subfolders of the indicated folder + * + * @param integer $folderId + * @return array + */ + public static function getSubFolders($folderId=NULL){ + if(!(int)$folderId)$folderId=1; //Default to root folder + $folderInfo=self::getKT()->get_folder_contents($folderId,1); + $subfolders=array(); + foreach($folderInfo['results']['items'] as $item){ + if($item['item_type']=='F'){ + $subfolders[$item[id]]=self::extractFromArray($item,self::$FOLDER_LIST_PROPERTIES); + } + } + return $subfolders; + } + + + /** + * Get every folder & document in the repository + * + * @param integer $parent the id of the folder to start recursing from - defaults to root folder [1] + * @return array + */ + public static function getFullTree($parent=NULL){ + if(!(int)$parent)$parent=1; + $ktTree=self::getKT()->get_folder_contents($parent,1); + $appTree=array(); + foreach($ktTree['results']['items'] as $item){ + $newItem=array(); + $newItem['parent']=$parent; + $newItem['type']=$item['item_type']; + $newItem['title']=$item['title']; + $newItem['filename']=$item['filename']; + $newItem['id']=$item['id']; +// $newItem['fullrecord']=$item; + $appTree[]=$newItem; + if($newItem['type']=='F')$appTree=array_merge($appTree,self::getFullTree($item['id'])); + } + return $appTree; + } + + + /** + * Get detail about the folder + * + * @param integer $folderId The id of the folder to get detail on. + * @return array + */ + public static function getFolderDetail($folderId=NULL){ + $ktInfo=self::getKT()->get_folder_by_id($folderId); + return $ktInfo->get_detail(); + } + + + /** + * Get detail about the indicated document + * + * @param integer $docId The document Id + * @return array + */ + public static function getDocumentDetail($docId=NULL){ + $ktInfo=self::getKT()->get_document_detail($docId); + return $ktInfo; + } + + + /** + * Get a list of all the documents in a folder. + * + * @param integer $folderId The id of the folder + * @return array + */ + public static function getFileList($folderId=NULL){ + $folderContents=self::getKt()->get_folder_contents($folderId,1); + $folderFiles=array(); + foreach($folderContents['results']['items'] as $item){ + if($item['item_type']=='D'){ + $folderFiles[$item['id']]=self::extractFromArray($item,self::$FILE_LIST_PROPERTIES); + } + } + return $folderFiles; + } + + + /** + * Returns an array containing only the associated values from $array where the keys were found in $keyArray + * + * @param array $array The array to be processed + * @param array $keyArray The list of keys to extract from the array + * @return array + */ + public static function extractFromArray($array,$keyArray){ + $newArray=array(); + foreach($keyArray as $key){ + $newArray[$key]=isset($array[$key])?$array[$key]:NULL; + } + return $newArray; + } + + /** + * Log in to KT easily + * + * @param string $username + * @param string $password + * @param string $ip + * @return object Containing the status_code of the login and session id + */ + function login($username, $password, $ip=null){ + $kt = self::getKt(); + + $session = $kt->start_session($username,$password, $ip); + if (PEAR::isError($session)){ + $response['status_code']=KT_atom_server_FAILURE; + $response['session_id']=''; + }else{ + $session= $session->get_session(); + $response['status_code'] = KT_atom_server_SUCCESS; + $response['session_id'] = $session; + } + return $response; + } + + + /** + * Log out of KT using the session id + * + * @param string $session_id + * @return object Containing the status_code of the logout attempt + */ + function logout($session_id){ + $kt = self::getKt(); + $session = $kt->get_active_session($session_id, null); + + if (PEAR::isError($session)){ + $response['status_code']=KT_atom_server_FAILURE; + }else{ + $session->logout(); + $response['status_code'] = KT_atom_server_SUCCESS; + } + return $response; + } + + /** + * Check whether the session_id is logged into KT + * + * @param string $session_id + * @return boolean + */ + function isLoggedIn($session_id){ + $kt=self::getKt(); + $session=$kt->get_active_session($session_id); + return !PEAR::isError($session); + } + +} +?> \ No newline at end of file diff --git a/ktatompub/services/mimetypes.inc.php b/webservice/atompub/index.php index 000f45d..f70ac0d 100644 --- a/ktatompub/services/mimetypes.inc.php +++ b/webservice/atompub/index.php @@ -32,25 +32,75 @@ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. - * Contributor( s): + * Contributor( s): * Mark Holtzhausen * */ - //Create a new response feed - $mimetypes=KTMime::getAllMimeTypes(); - - //Invoke the KtAPI to get detail about the referenced document - $feed=new KTAPPFeed(KT_APP_BASE_URI); - - //Create the atom response feed - foreach($mimetypes as $mimeType){ - $entry=$feed->newEntry(); - foreach($mimeType as $property=>$value){ - $feed->newField($property,$value,$entry); - } - } - - //Generate and set the output - $output=$feed->getAPPdoc(); +ob_start(); + +/** + * Constants + */ + +/** + * To sidestep url rewrites but still retain the atomPub URL convention, + * the entry point is: index.php?/ + * eg. 1. Accessing the servicedocument: http://example.com/ktatompub/index.php?/servicedocument + * 2. Accessing the folder service: http://example.com/ktatompub/index.php?/folder/1 + * + * If URL rewrites are used, they should point any reference below + * this folder to index.php?/ + * + * Because index.php is accessed as the default document, the url can be shortened to http://example.com/ktatompub/?/ + */ + +define('KT_APP_BASE_URI',"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/?/'); +define('KT_APP_SYSTEM_URI',"http://".$_SERVER['HTTP_HOST']); +define('KT_ATOM_LIB_FOLDER','../classes/atompub/'); + +// Define whether to use in debug mode for viewing generated structures +//define('KT_APP_WEB_OUTPUT',false); //defunct + + + +/** + * Includes + */ +include_once('../../ktapi/ktapi.inc.php'); +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.inc.php'); +include_once('demodms/KT_atom_service_helper.inc.php'); //Containing helper bridge functions to KtAPI +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_baseDoc.inc.php'); //Containing the parent class allowing easy XML manipulation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_serviceDoc.inc.php'); //Containing the servicedoc class allowing easy ServiceDocument generation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_responseFeed.inc.php'); //Containing the response feed class allowing easy atom feed generation +include_once(KT_ATOM_LIB_FOLDER.'KT_atom_service.inc.php'); +include_once('demodms/KT_atom_server.default_dms_services.inc.php'); +include_once('auth.php'); //Containing the authentication protocols + + +//Start the AtomPubProtocol Routing Engine +$APP=new KT_atom_server(); + +/** + * Register Services + * + * Registered services are classes extended from KT_atom_service + * The registration process takes the following parameters + * Workspace :The workspace within which the service collection will be grouped + * ServiceName :This is the name by which the service/collection is exposed + * ServiceClass :This is the class name of the class to be instantiated when this service is accessed + * Title :This is the title given to the service/collection in the servicedocument +*/ +$APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree'); +$APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail'); +$APP->registerService('DMS','document','KT_atom_service_document','Document Detail'); + +//Execute the current url/header request +$APP->execute(); + +//echo '
'.print_r($APP,true).'
'; + +//Render the resulting feed response +$APP->render(); + ?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_baseDoc.inc.php b/webservice/classes/atompub/KT_atom_baseDoc.inc.php new file mode 100644 index 0000000..fd6670b --- /dev/null +++ b/webservice/classes/atompub/KT_atom_baseDoc.inc.php @@ -0,0 +1,128 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): + * Mark Holtzhausen + * + */ + +/** + * Includes + */ + +class KT_atom_baseDoc{ + const XML_ENCODING='utf-8'; + const XML_VERSION='1.0'; + + public $DOM=NULL; + + public function __construct(){ + $this->DOM=new DOMDocument(self::XML_VERSION ,self::XML_ENCODING); + } + + public function &newAttr($name=NULL){ + $node=$this->DOM->createAttribute($name); + if(func_num_args()>1){ + $val=func_get_arg(1); + $node->value=$val; + } + return $node; + } + + public function &newElement($name=NULL){ + if(func_num_args()>1){ + $val=func_get_arg(1); + $node=$this->DOM->createElement($name,$val); + }else{ + $node=$this->DOM->createElement($name); + } + return $node; + } + + public function &newCDATA($data=NULL){ + $this->DOM->createCDATASection($data); + } + + public function &newB64Stream($tagName=NULL,$tagAttrs=array(),$streamString=NULL){ + $e=$this->newElement($tagName,chunk_split(base64_encode($streamString),75)); + foreach($tagAttrs as $attr=>$val){ + $attr=$this->newAttr($attr,$val); + $e->appendChild($attr); + } + return $e; + } + + + + public function formatXmlString($xml) { + // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries) + $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml); + + // now indent the tags + $token = strtok($xml, "\n"); + $result = ''; // holds formatted version as it is built + $pad = 0; // initial indent + $matches = array(); // returns from preg_matches() + + // scan each line and adjust indent based on opening/closing tags + while ($token !== false) : + + // test for the various tag states + + // 1. open and closing tags on same line - no change + if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) : + $indent=0; + // 2. closing tag - outdent now + elseif (preg_match('/^<\/\w/', $token, $matches)) : + $pad--; + // 3. opening tag - don't pad this one, only subsequent tags + elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) : + $indent=1; + // 4. no indentation needed + else : + $indent = 0; + endif; + + // pad the line with the required number of leading spaces + $line = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT); + $result .= $line . "\n"; // add to the cumulative result, with linefeed + $token = strtok("\n"); // get the next token + $pad += $indent; // update the pad size for subsequent lines + endwhile; + + return $result; + } +} + +?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_responseFeed.inc.php b/webservice/classes/atompub/KT_atom_responseFeed.inc.php new file mode 100644 index 0000000..fa64117 --- /dev/null +++ b/webservice/classes/atompub/KT_atom_responseFeed.inc.php @@ -0,0 +1,45 @@ +constructHeader(); + $this->baseURI=$baseURI; + } + + private function constructHeader(){ + $feed=$this->newElement('feed'); + $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom')); + $this->feed=&$feed; + $this->DOM->appendChild($this->feed); + } + + public function &newEntry(){ + $entry=$this->newElement('entry'); + $this->feed->appendChild($entry); + return $entry; + } + + public function &newField($name=NULL,$value=NULL,&$attachToNode=NULL){ + $field=$this->newElement($name,$value); + if(isset($attachToNode))$attachToNode->appendChild($field); + return $field; + } + + public function render(){ + return $this->formatXmlString(trim($this->DOM->saveXML())); + } + + +} + +class KT_atom_ResponseFeed_GET extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_PUT extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_POST extends KT_atom_responseFeed{} +class KT_atom_ResponseFeed_DELETE extends KT_atom_responseFeed{} + +?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_server.inc.php b/webservice/classes/atompub/KT_atom_server.inc.php new file mode 100644 index 0000000..7ba14cf --- /dev/null +++ b/webservice/classes/atompub/KT_atom_server.inc.php @@ -0,0 +1,87 @@ +queryArray=$queryArray; + $this->serviceName=$service; + $this->method=$reqMethod; + $this->workspace=$workspace; + + if($workspace=='servicedocument'){ + $this->serviceDocument(); + return; + } + + $service=$this->getRegisteredService($workspace,$serviceName); + if(is_array($service)){ + $serviceClass=$service['serviceClass']; + echo 'made it'; + $serviceObject=new $serviceClass($reqMethod,$requestParams,$rawRequest); + $this->output=$serviceObject->render(); + }else{ + $serviceObject=new KT_atom_service($requestParams,$rawRequest); + $serviceObject->setStatus(KT_atom_service::STATUS_NOT_FOUND); + $this->output=$serviceObject->render(); + } + } + + public function registerService($workspace=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){ + $workspace=strtolower(trim($workspace)); + $serviceName=strtolower(trim($serviceName)); + + $serviceRecord=array( + 'fileName' =>$fileName, + 'serviceClass' =>$serviceClass, + 'title' =>$title + ); + + $this->services[$workspace][$serviceName]=$serviceRecord; + } + + public function getRegisteredService($workspace,$serviceName=NULL){ + $serviceName=strtolower(trim($serviceName)); + if(isset($this->services[$workspace][$serviceName]))return $this->services[$workspace][$serviceName]; + return false; + } + + public function serviceDocument(){ + $service=new KT_atom_serviceDoc(KT_APP_BASE_URI); + + foreach($this->services as $workspace=>$collection){ + //Creating the Default Workspace for use with standard atomPub Clients + $ws=$service->newWorkspace($workspace); + + foreach($collection as $serviceName=>$serviceInstance){ + $col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws); + } + } + + $this->output=$service->getAPPdoc(); + } + + public function render(){ + ob_end_clean(); + header('Content-type: text/xml'); + echo $this->output; + } +} + +?> \ No newline at end of file diff --git a/webservice/classes/atompub/KT_atom_service.inc.php b/webservice/classes/atompub/KT_atom_service.inc.php new file mode 100644 index 0000000..511992f --- /dev/null +++ b/webservice/classes/atompub/KT_atom_service.inc.php @@ -0,0 +1,90 @@ +method=$method; + $this->params=$params; + $this->rawContent=$content; + $this->parseHeaders(); + $this->parsedXMLContent=$this->xml2array($this->rawContent); + $this->setStatus(self::STATUS_OK); + $this->responseFeed=new KT_atom_responseFeed(KT_APP_BASE_URI); + switch(strtoupper($this->method)){ + case 'GET': $this->GET_action();break; + case 'PUT': $this->PUT_action();break; + case 'POST': $this->POST_action();break; + case 'DELETE': $this->DELETE_action();break; + default: $this->UNSUPPORTED_action();break; + } + } + + public function GET_action(){ + $this->setStatus(KT_atom_service::STATUS_OK); + } + + public function PUT_action(){ + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); + } + + public function POST_action(){ + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); + } + + public function DELETE_action(){ + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); + } + + public function UNSUPPORTED_action(){ + $this->setStatus(KT_atom_service::STATUS_NOT_FOUND ); + } + + + public function render(){ + return $this->responseFeed->render(); + } + + private function xml2array($xml){ + $array=json_decode(json_encode(@simplexml_load_string($xml)),true); //TODO - XML2ARRAY Translation + return $array; + } + + private function parseHeaders(){ + $headers=null; + if(function_exists('http_get_request_headers')){ //Try to use pcre_http library if it exists + $headers=http_get_request_headers(); + }else{ + if(function_exists('apache_request_headers')){ //If not: try to use apache specific headers + $headers=apache_request_headers(); + }else{ //If not: not supported - empty headers + $headers=array(); + } + } + $this->headers=$headers; + } + + public function setStatus($status=NULL){ + header("HTTP/1.1 ".$status); + } + + private function setEtag($etagValue=NULL){ + if($etagValue)header('ETag: '.$etagValue); + } + +} +?> \ No newline at end of file diff --git a/ktatompub/lib/KTAPPFeed.inc.php b/webservice/classes/atompub/KT_atom_serviceDoc.inc.php index c1c677c..2fa2d37 100644 --- a/ktatompub/lib/KTAPPFeed.inc.php +++ b/webservice/classes/atompub/KT_atom_serviceDoc.inc.php @@ -32,7 +32,7 @@ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. - * Contributor( s): + * Contributor( s): * Mark Holtzhausen * */ @@ -41,75 +41,98 @@ /** * Includes */ -include_once('KTAPDoc.inc.php'); - -/* Remember to include support for feed attributes / nodes - - - - Example Feed - - 2003-12-13T18:30:02Z - - John Doe - - urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 - - - Atom-Powered Robots Run Amok - - urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 2003-12-13T18:30:02Z - Some text. - - - - -*/ +include_once('KT_atom_baseDoc.inc.php'); -class KTAPPFeed extends KTAPDoc { - +class KT_atom_serviceDoc extends KT_atom_baseDoc { + private $baseURI=NULL; - private $feed=NULL; - + private $service=NULL; - public function __construct($baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL){ + + public function __construct($baseURI=NULL){ parent::__construct(); - $this->constructHeader(); + $this->constructServiceDocumentHeaders(); $this->baseURI=$baseURI; } - - private function constructHeader(){ - $feed=$this->newElement('feed'); - $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom')); - $this->feed=&$feed; - $this->DOM->appendChild($this->feed); + + private function constructServiceDocumentHeaders(){ + $service=$this->newElement('service'); + $service->appendChild($this->newAttr('xmlns','http://www.w3.org/2007/app')); + $service->appendChild($this->newAttr('xmlns:atom','http://www.w3.org/2005/Atom')); + $this->service=&$service; + $this->DOM->appendChild($this->service); } - - public function &newEntry(){ - $entry=$this->newElement('entry'); - $this->feed->appendChild($entry); - return $entry; + + public function &newWorkspace($title=NULL){ + $ws=$this->newElement('workspace'); + $ws->appendChild($this->newElement('atom:title',$title)); + $this->service->appendChild($ws); + return $ws; } - - public function &newField($name=NULL,$value=NULL,&$entry=NULL){ - $field=$this->newElement($name,$value); - if(isset($entry))$entry->appendChild($field); - return $field; + + public function &newCollection($url=NULL,$title=NULL,&$ws=NULL){ + $collection=$this->newElement('collection'); + $collection->appendChild($this->newAttr('href',$url)); + $collection->appendChild($this->newElement('atom:title',$title)); + if(isset($ws))$ws->appendChild($collection); + return $collection; } - + + public function &newAccept($docType=NULL,&$collection=NULL){ + if($docType){ + $accept=$this->newElement('accept',$docType); + }else{ + $accept=$this->newElement('accept'); + } + if($collection)$collection->appendChild($accept); + return $accept; + } + + public function getAPPdoc(){ return $this->formatXmlString(trim($this->DOM->saveXML())); } + +} + + - public function render(){ - return $this->getAPPdoc(); - } -} +/** + + + + Main Site + + My Blog Entries + + + + Pictures + image/png + image/jpeg + image/gif + + + + Sidebar Blog + + Remaindered Links + application/atom+xml;type=entry + + + + + + + + + */ + + ?> \ No newline at end of file