Commit 11661790c6de38a4d67802b179af0d05fd9b3f08

Authored by Megan Watson
2 parents 44695155 f6bfb3ed

Merge branch 'edge' of git@github.com:ktgit/knowledgetree into edge

webservice/atompub/demodms/KT_atom_service_helper.inc.php
@@ -38,10 +38,10 @@ @@ -38,10 +38,10 @@
38 */ 38 */
39 39
40 class KT_atom_service_helper{ 40 class KT_atom_service_helper{
41 - private static $FOLDER_LIST_PROPERTIES=array('id','title','permissions','mime_icon_path');  
42 - 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');  
43 - private static $FOLDER_RECURSION_LEVEL=100;  
44 - private static $kt=NULL; 41 + protected static $FOLDER_LIST_PROPERTIES=array('id','title','permissions','mime_icon_path');
  42 + protected 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');
  43 + protected static $FOLDER_RECURSION_LEVEL=100;
  44 + protected static $kt=NULL;
45 45
46 /** 46 /**
47 * Make sure the class is always treated statically and never instantiated. 47 * Make sure the class is always treated statically and never instantiated.
webservice/atompub/index.php
@@ -68,6 +68,7 @@ define('KT_ATOM_LIB_FOLDER','../classes/atompub/'); @@ -68,6 +68,7 @@ define('KT_ATOM_LIB_FOLDER','../classes/atompub/');
68 * Includes 68 * Includes
69 */ 69 */
70 include_once('../../ktapi/ktapi.inc.php'); 70 include_once('../../ktapi/ktapi.inc.php');
  71 +include_once(KT_ATOM_LIB_FOLDER.'XMLns2array.inc.php');
71 include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.inc.php'); 72 include_once(KT_ATOM_LIB_FOLDER.'KT_atom_server.inc.php');
72 include_once('demodms/KT_atom_service_helper.inc.php'); //Containing helper bridge functions to KtAPI 73 include_once('demodms/KT_atom_service_helper.inc.php'); //Containing helper bridge functions to KtAPI
73 include_once(KT_ATOM_LIB_FOLDER.'KT_atom_baseDoc.inc.php'); //Containing the parent class allowing easy XML manipulation 74 include_once(KT_ATOM_LIB_FOLDER.'KT_atom_baseDoc.inc.php'); //Containing the parent class allowing easy XML manipulation
@@ -91,6 +92,8 @@ $APP=new KT_atom_server(); @@ -91,6 +92,8 @@ $APP=new KT_atom_server();
91 * ServiceClass :This is the class name of the class to be instantiated when this service is accessed 92 * ServiceClass :This is the class name of the class to be instantiated when this service is accessed
92 * Title :This is the title given to the service/collection in the servicedocument 93 * Title :This is the title given to the service/collection in the servicedocument
93 */ 94 */
  95 +$APP->addWorkspaceTag('dms','atom:title','Standard DMS');
  96 +
94 $APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree'); 97 $APP->registerService('DMS','fulltree','KT_atom_service_fulltree','Full Document Tree');
95 $APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail'); 98 $APP->registerService('DMS','folder','KT_atom_service_folder','Folder Detail');
96 $APP->registerService('DMS','document','KT_atom_service_document','Document Detail'); 99 $APP->registerService('DMS','document','KT_atom_service_document','Document Detail');
@@ -102,5 +105,6 @@ $APP->execute(); @@ -102,5 +105,6 @@ $APP->execute();
102 105
103 //Render the resulting feed response 106 //Render the resulting feed response
104 $APP->render(); 107 $APP->render();
  108 +//print_r($APP);
105 109
106 ?> 110 ?>
107 \ No newline at end of file 111 \ No newline at end of file
webservice/classes/atompub/KT_atom_baseDoc.inc.php
@@ -83,8 +83,6 @@ class KT_atom_baseDoc{ @@ -83,8 +83,6 @@ class KT_atom_baseDoc{
83 return $e; 83 return $e;
84 } 84 }
85 85
86 -  
87 -  
88 public function formatXmlString($xml) { 86 public function formatXmlString($xml) {
89 // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries) 87 // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
90 $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml); 88 $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml);
webservice/classes/atompub/KT_atom_responseFeed.inc.php
1 <?php 1 <?php
2 class KT_atom_responseFeed extends KT_atom_baseDoc { 2 class KT_atom_responseFeed extends KT_atom_baseDoc {
3 3
4 - private $baseURI=NULL;  
5 - private $feed=NULL; 4 + protected $baseURI=NULL;
  5 + protected $feed=NULL;
6 6
7 7
8 public function __construct($baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL){ 8 public function __construct($baseURI=NULL,$title=NULL,$link=NULL,$updated=NULL,$author=NULL,$id=NULL){
@@ -11,7 +11,7 @@ class KT_atom_responseFeed extends KT_atom_baseDoc { @@ -11,7 +11,7 @@ class KT_atom_responseFeed extends KT_atom_baseDoc {
11 $this->baseURI=$baseURI; 11 $this->baseURI=$baseURI;
12 } 12 }
13 13
14 - private function constructHeader(){ 14 + protected function constructHeader(){
15 $feed=$this->newElement('feed'); 15 $feed=$this->newElement('feed');
16 $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom')); 16 $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom'));
17 $this->feed=&$feed; 17 $this->feed=&$feed;
webservice/classes/atompub/KT_atom_server.inc.php
1 <?php 1 <?php
2 class KT_atom_server{ 2 class KT_atom_server{
3 - private $services=array();  
4 - private $errors=array();  
5 - private $output='';  
6 - private $queryArray=array();  
7 - private $serviceName='';  
8 - private $method='';  
9 - private $workspace=''; 3 + protected $services=array();
  4 + protected $workspaceDetail=array();
  5 + protected $errors=array();
  6 + protected $output='';
  7 + protected $queryArray=array();
  8 + protected $serviceName='';
  9 + protected $method='';
  10 + protected $workspace='';
10 11
11 12
12 public function __construct(){ 13 public function __construct(){
13 } 14 }
14 15
  16 + /**
  17 + * Run the server switchboard - find the correct service class to instantiate, execute & render that class with the passed parameteres
  18 + *
  19 + */
15 public function execute(){ 20 public function execute(){
16 $reqMethod=trim(strtoupper($_SERVER['REQUEST_METHOD'])); 21 $reqMethod=trim(strtoupper($_SERVER['REQUEST_METHOD']));
17 $queryArray=split('/',trim($_SERVER['QUERY_STRING'],'/')); 22 $queryArray=split('/',trim($_SERVER['QUERY_STRING'],'/'));
@@ -37,14 +42,18 @@ class KT_atom_server{ @@ -37,14 +42,18 @@ class KT_atom_server{
37 $serviceObject=new $serviceClass($reqMethod,$requestParams,$rawRequest); 42 $serviceObject=new $serviceClass($reqMethod,$requestParams,$rawRequest);
38 $this->output=$serviceObject->render(); 43 $this->output=$serviceObject->render();
39 }else{ 44 }else{
  45 +// $this->serviceDocument();
  46 +// return;
40 $serviceObject=new KT_atom_service($requestParams,$rawRequest); 47 $serviceObject=new KT_atom_service($requestParams,$rawRequest);
41 $serviceObject->setStatus(KT_atom_service::STATUS_NOT_FOUND); 48 $serviceObject->setStatus(KT_atom_service::STATUS_NOT_FOUND);
42 $this->output=$serviceObject->render(); 49 $this->output=$serviceObject->render();
43 } 50 }
  51 + $this->serviceObject=$serviceObject;
44 } 52 }
45 53
46 - public function registerService($workspace=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){  
47 - $workspace=strtolower(trim($workspace)); 54 +
  55 + public function registerService($workspaceCode=NULL,$serviceName=NULL,$serviceClass=NULL,$title=NULL){
  56 + $workspaceCode=strtolower(trim($workspaceCode));
48 $serviceName=strtolower(trim($serviceName)); 57 $serviceName=strtolower(trim($serviceName));
49 58
50 $serviceRecord=array( 59 $serviceRecord=array(
@@ -53,7 +62,13 @@ class KT_atom_server{ @@ -53,7 +62,13 @@ class KT_atom_server{
53 'title' =>$title 62 'title' =>$title
54 ); 63 );
55 64
56 - $this->services[$workspace][$serviceName]=$serviceRecord; 65 + $this->services[$workspaceCode][$serviceName]=$serviceRecord;
  66 + }
  67 +
  68 + public function addWorkspaceTag($workspaceCode=NULL,$TagName=NULL,$tagValue=NULL){
  69 + $workspaceCode=strtolower(trim($workspaceCode));
  70 + if(!isset($this->workspaceDetail[$workspaceCode]))$this->workspaceDetail[$workspaceCode]=array();
  71 + $this->workspaceDetail[$workspaceCode][$TagName]=$tagValue;
57 } 72 }
58 73
59 public function getRegisteredService($workspace,$serviceName=NULL){ 74 public function getRegisteredService($workspace,$serviceName=NULL){
@@ -67,7 +82,18 @@ class KT_atom_server{ @@ -67,7 +82,18 @@ class KT_atom_server{
67 82
68 foreach($this->services as $workspace=>$collection){ 83 foreach($this->services as $workspace=>$collection){
69 //Creating the Default Workspace for use with standard atomPub Clients 84 //Creating the Default Workspace for use with standard atomPub Clients
70 - $ws=$service->newWorkspace($workspace); 85 + $ws=$service->newWorkspace();
  86 +
  87 + $hadDetail=false;
  88 + if(isset($this->workspaceDetail[$workspace]))if(is_array($this->workspaceDetail[$workspace])){
  89 + foreach ($this->workspaceDetail[$workspace] as $wsTag=>$wsValue){
  90 + $ws->appendChild($service->newElement($wsTag,$wsValue));
  91 + $hadDetail=true;
  92 + }
  93 + }
  94 + if(!$hadDetail){
  95 + $ws->appendChild($service->newElement('atom:title',$workspace));
  96 + }
71 97
72 foreach($collection as $serviceName=>$serviceInstance){ 98 foreach($collection as $serviceName=>$serviceInstance){
73 $col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws); 99 $col=$service->newCollection(KT_APP_BASE_URI.$workspace.'/'.$serviceName.'/',$serviceInstance['title'],$ws);
webservice/classes/atompub/KT_atom_service.inc.php
@@ -59,12 +59,16 @@ class KT_atom_service{ @@ -59,12 +59,16 @@ class KT_atom_service{
59 return $this->responseFeed->render(); 59 return $this->responseFeed->render();
60 } 60 }
61 61
62 - private function xml2array($xml){  
63 - $array=json_decode(json_encode(@simplexml_load_string($xml)),true); //TODO - XML2ARRAY Translation 62 + protected function xml2array($xml){
  63 + if(class_exists('')){
  64 + $array=XMLns2array::parse($xml);
  65 + }else{
  66 + $array=json_decode(json_encode(@simplexml_load_string($xml)),true);
  67 + }
64 return $array; 68 return $array;
65 } 69 }
66 70
67 - private function parseHeaders(){ 71 + protected function parseHeaders(){
68 $headers=null; 72 $headers=null;
69 if(function_exists('http_get_request_headers')){ //Try to use pcre_http library if it exists 73 if(function_exists('http_get_request_headers')){ //Try to use pcre_http library if it exists
70 $headers=http_get_request_headers(); 74 $headers=http_get_request_headers();
@@ -82,7 +86,7 @@ class KT_atom_service{ @@ -82,7 +86,7 @@ class KT_atom_service{
82 header("HTTP/1.1 ".$status); 86 header("HTTP/1.1 ".$status);
83 } 87 }
84 88
85 - private function setEtag($etagValue=NULL){ 89 + protected function setEtag($etagValue=NULL){
86 if($etagValue)header('ETag: '.$etagValue); 90 if($etagValue)header('ETag: '.$etagValue);
87 } 91 }
88 92
webservice/classes/atompub/KT_atom_serviceDoc.inc.php
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33 * must display the words "Powered by KnowledgeTree" and retain the original 33 * must display the words "Powered by KnowledgeTree" and retain the original
34 * copyright notice. 34 * copyright notice.
35 - * Contributor( s): 35 + * Contributor( s):
36 * Mark Holtzhausen <mark@knowledgetree.com> 36 * Mark Holtzhausen <mark@knowledgetree.com>
37 * 37 *
38 */ 38 */
@@ -45,32 +45,32 @@ include_once(&#39;KT_atom_baseDoc.inc.php&#39;); @@ -45,32 +45,32 @@ include_once(&#39;KT_atom_baseDoc.inc.php&#39;);
45 45
46 46
47 class KT_atom_serviceDoc extends KT_atom_baseDoc { 47 class KT_atom_serviceDoc extends KT_atom_baseDoc {
48 -  
49 - private $baseURI=NULL;  
50 - private $service=NULL;  
51 48
52 - 49 + protected $baseURI=NULL;
  50 + protected $service=NULL;
  51 +
  52 +
53 public function __construct($baseURI=NULL){ 53 public function __construct($baseURI=NULL){
54 parent::__construct(); 54 parent::__construct();
55 $this->constructServiceDocumentHeaders(); 55 $this->constructServiceDocumentHeaders();
56 $this->baseURI=$baseURI; 56 $this->baseURI=$baseURI;
57 } 57 }
58 -  
59 - private function constructServiceDocumentHeaders(){ 58 +
  59 + protected function constructServiceDocumentHeaders(){
60 $service=$this->newElement('service'); 60 $service=$this->newElement('service');
61 $service->appendChild($this->newAttr('xmlns','http://www.w3.org/2007/app')); 61 $service->appendChild($this->newAttr('xmlns','http://www.w3.org/2007/app'));
62 $service->appendChild($this->newAttr('xmlns:atom','http://www.w3.org/2005/Atom')); 62 $service->appendChild($this->newAttr('xmlns:atom','http://www.w3.org/2005/Atom'));
63 $this->service=&$service; 63 $this->service=&$service;
64 $this->DOM->appendChild($this->service); 64 $this->DOM->appendChild($this->service);
65 } 65 }
66 - 66 +
67 public function &newWorkspace($title=NULL){ 67 public function &newWorkspace($title=NULL){
68 $ws=$this->newElement('workspace'); 68 $ws=$this->newElement('workspace');
69 - $ws->appendChild($this->newElement('atom:title',$title)); 69 + if($title)$ws->appendChild($this->newElement('atom:title',$title));
70 $this->service->appendChild($ws); 70 $this->service->appendChild($ws);
71 - return $ws; 71 + return $ws;
72 } 72 }
73 - 73 +
74 public function &newCollection($url=NULL,$title=NULL,&$ws=NULL){ 74 public function &newCollection($url=NULL,$title=NULL,&$ws=NULL){
75 $collection=$this->newElement('collection'); 75 $collection=$this->newElement('collection');
76 $collection->appendChild($this->newAttr('href',$url)); 76 $collection->appendChild($this->newAttr('href',$url));
@@ -78,7 +78,7 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc { @@ -78,7 +78,7 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc {
78 if(isset($ws))$ws->appendChild($collection); 78 if(isset($ws))$ws->appendChild($collection);
79 return $collection; 79 return $collection;
80 } 80 }
81 - 81 +
82 public function &newAccept($docType=NULL,&$collection=NULL){ 82 public function &newAccept($docType=NULL,&$collection=NULL){
83 if($docType){ 83 if($docType){
84 $accept=$this->newElement('accept',$docType); 84 $accept=$this->newElement('accept',$docType);
@@ -88,12 +88,12 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc { @@ -88,12 +88,12 @@ class KT_atom_serviceDoc extends KT_atom_baseDoc {
88 if($collection)$collection->appendChild($accept); 88 if($collection)$collection->appendChild($accept);
89 return $accept; 89 return $accept;
90 } 90 }
91 -  
92 - 91 +
  92 +
93 public function getAPPdoc(){ 93 public function getAPPdoc(){
94 return $this->formatXmlString(trim($this->DOM->saveXML())); 94 return $this->formatXmlString(trim($this->DOM->saveXML()));
95 } 95 }
96 - 96 +
97 } 97 }
98 98
99 99
webservice/classes/atompub/XMLns2array.inc.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +class XMLns2array{
  4 +
  5 + private static $namespaces=null;
  6 +
  7 + /**
  8 + * Parse an XML document into an array. Supports namespaces. Uses SimpleXML
  9 + *
  10 + * @param String/SimpleXMLElement $xml
  11 + * @return Array
  12 + */
  13 + public static function parse($xml){
  14 + $xml=(get_class($xml)=='SimpleXMLElement')?$xml:@simplexml_load_string($xml);
  15 + if(get_class($xml)!='SimpleXMLElement') die('The string passed is not a valid XML string or an SimpleXMLElement');
  16 + self::$namespaces=$xml->getNamespaces(true);
  17 + return self::parsetag($xml);
  18 + }
  19 +
  20 + /**
  21 + * Parse a single tag recursively calling self to parse children.
  22 + *
  23 + * @param SimpleXMLElement $xml The SimpleXMLElement to convert to an array
  24 + * @return Array
  25 + */
  26 + private static function parsetag($xml){
  27 + $array=array();
  28 + $array['@attributes']=self::getAttributes($xml);
  29 + $array['@children']=array();
  30 + if(self::hasChildren($xml)){
  31 + $children=self::getChildren($xml);
  32 + $tmpChildren=array();
  33 + foreach($children as $fullChildName=>$childCollection){
  34 + $childName=split(':',$fullChildName);
  35 + $fullChildName=trim($fullChildName,' :');
  36 + foreach($childCollection as $child){
  37 + $childParsed=self::parsetag($child);
  38 + if(!isset($tmpChildren[$fullChildName]))$tmpChildren[$fullChildName]=array();
  39 + $tmpChildren[$fullChildName][]=$childParsed;
  40 + }
  41 + $array['@children']=array_merge($array['@children'],$tmpChildren);
  42 + }
  43 + }else{
  44 + $array['@value']=(string)$xml;
  45 + }
  46 + return $array;
  47 + }
  48 +
  49 + /**
  50 + * Tests whether a node has children
  51 + *
  52 + * @param SimpleXMLElement $xml The node to test
  53 + * @return Array
  54 + */
  55 + private static function hasChildren($xml){
  56 + return count(self::getChildren($xml))>0;
  57 + }
  58 +
  59 + /**
  60 + * Gets the attributes of a node
  61 + *
  62 + * @param SimpleXMLElement $xml The node to process
  63 + * @return Array
  64 + */
  65 + private static function getAttributes($xml){
  66 + $attr=array();
  67 + foreach(self::$namespaces as $namespace=>$uri){
  68 + $nsAttrs=(array)$xml->attributes($uri);
  69 + $nsAttrs=isset($nsAttrs['@attributes'])?$nsAttrs['@attributes']:array();
  70 + foreach($nsAttrs as $nsAttr=>$nsAttrVal){
  71 + $attr[$namespace.':'.$nsAttr]=$nsAttrVal;
  72 + }
  73 + }
  74 + return $attr;
  75 + }
  76 +
  77 + /**
  78 + * Returns the children of a node
  79 + *
  80 + * @param SimpleXMLElement $xml The node to process
  81 + * @return unknown
  82 + */
  83 + private static function getChildren($xml){
  84 + $children=array();
  85 + foreach(self::$namespaces as $namespace=>$uri){
  86 + $nsChildren=$xml->children($uri);
  87 + foreach($nsChildren as $nsChild){
  88 + $childRealName=$namespace.':'.$nsChild->getName();
  89 + if(!isset($children[$childRealName]))$children[$childRealName]=array();
  90 + if(!is_array($children[$childRealName]))$children[$childRealName]=array();
  91 + $children[$childRealName][]=$nsChild;
  92 + }
  93 + }
  94 + return $children;
  95 + }
  96 +
  97 +}
  98 +?>
0 \ No newline at end of file 99 \ No newline at end of file