Commit 2db4840d77c074d8621634fb5003fe2782531d09

Authored by Paul Barrett
1 parent ad5f0420

Code changes to allow CMISSpaces (and similar clients) to work with the URL stru…

…ctures used by Alfresco and Drupal

Committed by: Paul Barrett
ktapi/ktapi.inc.php
... ... @@ -834,9 +834,9 @@ class KTAPI
834 834 * @param string $foldername The folder name
835 835 * @return object $folder The KTAPI_Folder object
836 836 */
837   - public function &get_folder_by_name($foldername)
  837 + public function &get_folder_by_name($foldername, $parentId = 1)
838 838 {
839   - $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, 1);
  839 + $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, $parentId);
840 840 return $folder;
841 841 }
842 842  
... ...
ktatompub/lib/cmis/KTCMISAPPFeed.inc.php
... ... @@ -56,6 +56,7 @@ class KTCMISAPPFeed extends KTAPDoc {
56 56 public function __construct($baseURI = NULL, $title = NULL, $link = NULL, $updated = NULL, $author = NULL, $id = NULL)
57 57 {
58 58 parent::__construct();
  59 +
59 60 $this->baseURI = $baseURI;
60 61 $this->id = $id;
61 62 $this->title = $title;
... ... @@ -65,6 +66,7 @@ class KTCMISAPPFeed extends KTAPDoc {
65 66 private function constructHeader()
66 67 {
67 68 $feed = $this->newElement('feed');
  69 + $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2007/app'));
68 70 $feed->appendChild($this->newAttr('xmlns','http://www.w3.org/2005/Atom'));
69 71 $feed->appendChild($this->newAttr('xmlns:cmis','http://www.cmis.org/2008/05'));
70 72 $this->feed = &$feed;
... ... @@ -76,7 +78,7 @@ class KTCMISAPPFeed extends KTAPDoc {
76 78  
77 79 $link = $this->newElement('link');
78 80 $link->appendChild($this->newAttr('rel','self'));
79   - $link->appendChild($this->newAttr('href', $this->baseURI . $_SERVER['QUERY_STRING']));
  81 + $link->appendChild($this->newAttr('href', $this->baseURI . trim($_SERVER['QUERY_STRING'], '/')));
80 82 $feed->appendChild($link);
81 83  
82 84 if (!is_null($this->title))
... ... @@ -103,8 +105,18 @@ class KTCMISAPPFeed extends KTAPDoc {
103 105  
104 106 public function &newField($name = NULL, $value = NULL, &$entry = NULL)
105 107 {
106   - $field = $this->newElement('cmis:' . $name,$value);
107   - if(isset($entry))$entry->appendChild($field);
  108 + $append = false;
  109 +
  110 + if(func_num_args() > 3)
  111 + {
  112 + $append = ((func_get_arg(3) === true) ? true : false);
  113 + }
  114 +
  115 + $field = $this->newElement('cmis:' . $name,$value);
  116 +
  117 + if (isset($entry)) $entry->appendChild($field);
  118 + else if ($append) $this->feed->appendChild($field);
  119 +
108 120 return $field;
109 121 }
110 122  
... ...
ktatompub/services/cmis/ObjectFeed.inc.php
... ... @@ -9,10 +9,14 @@ class CMISObjectFeed {
9 9 * @param array $cmisEntry The entry data
10 10 * @param string $parent The parent folder
11 11 */
12   - static public function createEntry(&$feed, $cmisEntry, $parent)
  12 + static public function createEntry(&$feed, $cmisEntry, $parent, $path)
13 13 {
  14 + preg_match('/^\/?cmis\/folder\/(.*)\/[^\/]*\/?$/', trim($_SERVER['QUERY_STRING'], '/'), $matches);
  15 + $path = $matches[1];
  16 + $parent = preg_replace('/\/[^\/]*$/', '', $path);
  17 +
14 18 $entry = $feed->newEntry();
15   - $feed->newId('urn:uuid:' . $cmisEntry['properties']['ObjectId']['value'] . '-'
  19 + $feed->newId('urn:uuid:' . $cmisEntry['properties']['Name']['value'] . '-'
16 20 . strtolower($cmisEntry['properties']['ObjectTypeId']['value']), $entry);
17 21  
18 22 /*
... ... @@ -29,26 +33,28 @@ class CMISObjectFeed {
29 33 // $entry->appendChild($link);
30 34 $link = $feed->newElement('link');
31 35 $link->appendChild($feed->newAttr('rel','cmis-parent'));
32   - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $parent));
  36 + $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $path));
33 37 $entry->appendChild($link);
34 38  
35 39 if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'folder')
36 40 {
37 41 $link = $feed->newElement('link');
38 42 $link->appendChild($feed->newAttr('rel','cmis-folderparent'));
39   - $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $parent));
  43 + $link->appendChild($feed->newAttr('href', CMIS_BASE_URI . 'folder/' . $path));
40 44 $entry->appendChild($link);
41 45 $link = $feed->newElement('link');
42 46 $link->appendChild($feed->newAttr('rel','cmis-children'));
43 47 $link->appendChild($feed->newAttr('href', CMIS_BASE_URI
44 48 . strtolower($cmisEntry['properties']['ObjectTypeId']['value'])
45   - . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/children'));
  49 + . '/' . $path . '/' . urlencode($cmisEntry['properties']['Name']['value'])
  50 + . '/children'));
46 51 $entry->appendChild($link);
47 52 $link = $feed->newElement('link');
48 53 $link->appendChild($feed->newAttr('rel','cmis-descendants'));
49 54 $link->appendChild($feed->newAttr('href', CMIS_BASE_URI
50 55 . strtolower($cmisEntry['properties']['ObjectTypeId']['value'])
51   - . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/descendants'));
  56 + . '/' . $path . '/' . urlencode($cmisEntry['properties']['Name']['value'])
  57 + . '/descendants'));
52 58 $entry->appendChild($link);
53 59 }
54 60  
... ...
ktatompub/services/cmis/checkedout.inc.php
... ... @@ -20,11 +20,11 @@ $NavigationService->startSession($username, $password);
20 20 $repositories = $RepositoryService->getRepositories();
21 21 $repositoryId = $repositories[0]['repositoryId'];
22 22  
23   -$output = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmis="http://www.cmis.org/2008/05">
24   -<id>urn:uuid:checkedout</id>
25   -<link rel="self" href="' . CMIS_BASE_URI . 'checkedout"/>
26   -<title>Checked out Documents</title>
27   -<cmis:hasMoreItems>false</cmis:hasMoreItems>
28   -</feed>';
  23 +$feed = new KTCMISAPPFeed(KT_APP_BASE_URI, 'Checked out Documents', null, null, null, 'urn:uuid:checkedout');
  24 +
  25 +$entry = null;
  26 +$feed->newField('hasMoreItems', 'false', $entry, true);
  27 +
  28 +$output = $feed->getAPPdoc();
29 29  
30 30 ?>
... ...
ktatompub/services/cmis/folder.inc.php
... ... @@ -18,7 +18,7 @@ class CMISFolderFeed extends CMISObjectFeed {
18 18 * @param string $feedType children or descendants
19 19 * @return string CMIS AtomPub feed
20 20 */
21   - static public function getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $feedType)
  21 + static public function getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $feedType)
22 22 {
23 23 if ($feedType == 'children')
24 24 {
... ... @@ -30,25 +30,15 @@ class CMISFolderFeed extends CMISObjectFeed {
30 30 }
31 31 else
32 32 {
33   - // error, we shouldn't be here
34   - }
35   -
36   - // TODO dynamically get the requested folder's name to display correctly
37   - if ($folderId == 'F1')
38   - {
39   - $folderName = 'Root Folder';
40   - }
41   - else
42   - {
43   - $folderName = 'Folder';
  33 + // error, we shouldn't be here, if we are then the wrong function was called
44 34 }
45 35  
46 36 $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $folderName . ' ' . ucwords($feedType), null, null, null,
47   - 'urn:uuid:' . $folderId . '-' . $feedType);
  37 + 'urn:uuid:' . $folderName . '-' . $feedType);
48 38  
49 39 foreach($entries as $cmisEntry)
50 40 {
51   - CMISFolderFeed::createEntry($feed, $cmisEntry, $folderId);
  41 + CMISFolderFeed::createEntry($feed, $cmisEntry, $folderName);
52 42 }
53 43  
54 44 // <cmis:hasMoreItems>false</cmis:hasMoreItems>
... ... @@ -490,6 +480,62 @@ class CMISFolderFeed extends CMISObjectFeed {
490 480 return $output;
491 481 }
492 482  
  483 + static public function getFolderData($query, &$locationName, &$tree)
  484 + {
  485 + $folderId = null;
  486 +
  487 + // TODO proper login credentials, or rather use the existing session available from the underlying CMIS code
  488 + $ktapi = new KTAPI();
  489 + $ktapi->start_session('admin', 'admin');
  490 +
  491 + $numQ = count($query);
  492 +
  493 + if($query[$numQ-1] == 'children' || $query[$numQ-1] == 'descendants') {
  494 + $offset = 1;
  495 + $tree = $query[$numQ-1];
  496 + }
  497 +
  498 + $folderName = urldecode($query[$numQ-($offset+1)]);
  499 +
  500 + $locationName = $folderName;
  501 +
  502 + if ($numQ <= 5)
  503 + {
  504 + $parentId = 1;
  505 + }
  506 + else
  507 + {
  508 + $count = 2;
  509 + $lastParent = 0;
  510 +
  511 + while(++$count <= ($numQ - 3))
  512 + {
  513 + if ($lastParent == 0)
  514 + {
  515 + $idUp = 1;
  516 + }
  517 + else
  518 + {
  519 + $idUp = $lastParent;
  520 + }
  521 +
  522 + $folderName = urldecode($query[$count]);
  523 + $folder = $ktapi->get_folder_by_name($folderName, $idUp);
  524 +
  525 + if (PEAR::isError($folder)) break;
  526 +
  527 + $currentId = $folder->get_folderid();
  528 + $lastParent = $currentId;
  529 + }
  530 +
  531 + $parentId = $lastParent;
  532 + }
  533 +
  534 + $folder = $ktapi->get_folder_by_name($locationName, $parentId);
  535 + $folderId = CMISUtil::encodeObjectId('Folder', $folder->get_folderid());
  536 +
  537 + return $folderId;
  538 + }
493 539 }
494 540  
495 541 include 'services/cmis/RepositoryService.inc.php';
... ... @@ -500,19 +546,21 @@ $RepositoryService = new RepositoryService();
500 546 $repositories = $RepositoryService->getRepositories();
501 547 $repositoryId = $repositories[0]['repositoryId'];
502 548  
503   -if (isset($query[3]) && (($query[3] == 'children') || ($query[3] == 'descendants')))
  549 +$folderId = CMISFolderFeed::getFolderData($query, $folderName, $tree);
  550 +
  551 +if (isset($tree) && (($tree == 'children') || ($tree == 'descendants')))
504 552 {
505 553 $NavigationService = new NavigationService();
506 554 $NavigationService->startSession($username, $password);
507 555  
508   - $output = CMISFolderFeed::getFolderChildrenFeed($NavigationService, $repositoryId, $query[2], $query[3]);
  556 + $output = CMISFolderFeed::getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $tree);
509 557 }
510 558 else
511 559 {
512 560 $ObjectService = new ObjectService();
513 561 $ObjectService->startSession($username, $password);
514 562  
515   - $output = CMISFolderFeed::getFolderFeed($ObjectService, $repositoryId, $query[2]);
  563 + $output = CMISFolderFeed::getFolderFeed($ObjectService, $repositoryId, $folderId);
516 564 }
517 565  
518 566 ?>
... ...
ktatompub/services/cmis/index.php
... ... @@ -7,7 +7,8 @@
7 7 include_once('lib/cmis/KTCMISAPPServiceDoc.inc.php');
8 8 include_once('lib/cmis/KTCMISAPPFeed.inc.php');
9 9  
10   -define ('CMIS_BASE_URI', KT_APP_BASE_URI . 'cmis/');
  10 +define ('CMIS_BASE_URI', trim(KT_APP_BASE_URI, '/') . 'cmis/');
  11 +//echo KT_APP_BASE_URI;exit;
11 12 // hack for links not yet working in KT, use Alfresco to move things forward
12 13 //define ('CMIS_BASE_URI_ALF', 'http://127.0.0.1:8080/alfresco/service/api/');
13 14 //define ('CMIS_BASE_URI', 'http://10.33.4.34:8080/alfresco/service/api/');
... ... @@ -18,7 +19,7 @@ $username = $_SERVER[&#39;PHP_AUTH_USER&#39;];
18 19 $password = $_SERVER['PHP_AUTH_PW'];
19 20  
20 21 // NOTE this is just for demonstration purposes and attempting to auth with clients which send the username/password differently
21   -// TODO disable once we have Drupal compatible login working
  22 +// TODO disable once we have at least Drupal compatible login working, can re-enable if necessary
22 23 if (($username == '') && ($password == ''))
23 24 {
24 25 $username = $password = 'admin';
... ...
ktatompub/services/cmis/servicedocument.inc.php
... ... @@ -6,6 +6,9 @@
6 6 * NOTE Includes the results of a repositoryInfo call as well as service links
7 7 */
8 8  
  9 +// NOTE currently we only support one repository, which will be the first one found in the repositories.xml config
  10 +// TODO multiple repositories as individual workspaces
  11 +
9 12 include 'services/cmis/RepositoryService.inc.php';
10 13 $RepositoryService = new RepositoryService();
11 14  
... ...
ktatompub/services/cmis/types.inc.php
... ... @@ -35,7 +35,8 @@ switch($arg)
35 35 break;
36 36 case 'types':
37 37 $types = $RepositoryService->getTypes($repositoryId);
38   - $output = CMISTypeFeed::getTypeFeed('All Types', $types);
  38 + $type = (($query[2] == '') ? 'all' : $query[2]);
  39 + $output = CMISTypeFeed::getTypeFeed($type, $types);
39 40 break;
40 41 }
41 42  
... ... @@ -54,7 +55,23 @@ class CMISTypeFeed {
54 55 */
55 56 static public function getTypeFeed($typeDef, $types)
56 57 {
57   - $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $typeDef, null, null, null, 'urn:uuid:type-' . $query[2]);
  58 + $typesString = '';
  59 + $typesHeading = '';
  60 + switch($typeDef)
  61 + {
  62 + case 'all':
  63 + case 'children':
  64 + case 'descendants':
  65 + $typesString = 'types-' . $typeDef;
  66 + $typesHeading = 'All Types';
  67 + break;
  68 + default:
  69 + $typesString = 'type-' . $typeDef;
  70 + $typesHeading = $typeDef;
  71 + break;
  72 + }
  73 +
  74 + $feed = new KTCMISAPPFeed(KT_APP_BASE_URI, $typesHeading, null, null, null, 'urn:uuid:' . $typesString);
58 75  
59 76 foreach($types as $type)
60 77 {
... ...
lib/api/ktcmis/config/repositories.xml
... ... @@ -19,7 +19,7 @@
19 19 <vendorName>KnowledgeTree</vendorName>
20 20 <productName>KnowledgeTree Document Management System</productName>
21 21 <productVersion>3.6.2</productVersion>
22   - <rootFolderId>F1</rootFolderId>
  22 + <rootFolderId>Root%20Folder</rootFolderId>
23 23 <cmisVersionsSupported>0.61c</cmisVersionsSupported>
24 24 </repositoryInfo>
25 25 <repositoryCapabilities>
... ...