@VERSION $Id$
== CHANGELOG ==
-
-Alfresco PHP Libarary was modified by Moodle, because of class name conflict.
-See, Service/Repository.php & Service/WebService/AlfrescoWebService.php
-All the changes are marked as "Moodle"
+1. Rename class name , see Service/Repository.php & Service/WebService/AlfrescoWebService.php
+2. Change library path name
+3. In Alfresco_Repository class construct function, set _port to 80 if it is not specified
== Alfresco PHP Libarary ==
Installation and developer documentation for the Alfresco PHP Library can be found on the Alfresco Wiki.
+Get the source from http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/modules/php-sdk
== Documentation Links ==
-<?php\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
-\r
-require_once("Functions.php");\r
-\r
-class ContentData extends BaseObject\r
-{ \r
- private $_isPopulated = false;\r
- private $_isDirty = false;\r
- \r
- private $_node;\r
- private $_property;\r
- \r
- private $_mimetype;\r
- private $_size;\r
- private $_encoding; \r
- private $_url;\r
- private $_newContent;\r
- private $_newFileContent;\r
- \r
- public function __construct($node, $property, $mimetype=null, $encoding=null, $size=-1)\r
- {\r
- $this->_node = $node;\r
- $this->_property = $property;\r
- $this->_mimetype = $mimetype;\r
- $this->_encoding = $encoding;\r
- if ($size != -1)\r
- {\r
- $this->size = $size;\r
- } \r
- $this->_isPopulated = false;\r
- } \r
- \r
- public function setPropertyDetails($node, $property)\r
- {\r
- $this->_node = $node;\r
- $this->_property = $property;\r
- }\r
- \r
- public function __toString()\r
- {\r
- $this->populateContentData();\r
- }\r
- \r
- public function getNode()\r
- {\r
- return $this->_node;\r
- }\r
- \r
- public function getProperty()\r
- {\r
- return $this->_property;\r
- }\r
- \r
- public function getIsDirty()\r
- {\r
- return $this->_isDirty;\r
- }\r
- \r
- public function getMimetype()\r
- {\r
- $this->populateContentData();\r
- return $this->_mimetype;\r
- }\r
- \r
- public function setMimetype($mimetype)\r
- {\r
- $this->populateContentData();\r
- $this->_mimetype = $mimetype;\r
- }\r
- \r
- public function getSize()\r
- {\r
- $this->populateContentData();\r
- return $this->_size;\r
- }\r
- \r
- public function getEncoding()\r
- {\r
- $this->populateContentData();\r
- return $this->_encoding;\r
- }\r
- \r
- public function setEncoding($encoding)\r
- {\r
- $this->populateContentData();\r
- $this->_encoding = $encoding;\r
- }\r
- \r
- public function getUrl()\r
- {\r
- // TODO what should be returned if the content has been updated??\r
- \r
- $this->populateContentData();\r
- $result = null;\r
- if ($this->_url != null)\r
- { \r
- $result = $this->_url."?ticket=".$this->_node->session->ticket;\r
- }\r
- return $result;\r
- }\r
- \r
- public function getGuestUrl()\r
- {\r
- // TODO what should be returned if the content has been updated??\r
- \r
- $this->populateContentData(); \r
- $result = null;\r
- if ($this->_url != null)\r
- { \r
- $result = $this->_url."?guest=true";\r
- }\r
- return $result;\r
- }\r
- \r
- public function getContent()\r
- {\r
- $this->populateContentData();\r
- \r
- $result = null; \r
- if ($this->_isDirty == true)\r
- {\r
- if ($this->_newFileContent != null)\r
- {\r
- $handle = fopen($this->_newFileContent, "rb");\r
- $result = stream_get_contents($handle);\r
- fclose($handle); \r
- }\r
- else if ($this->_newContent != null)\r
- {\r
- $result = $this->_newContent; \r
- } \r
- }\r
- else\r
- {\r
- if ($this->getUrl() != null)\r
- {\r
- $handle = fopen($this->getUrl(), "rb");\r
- $result = stream_get_contents($handle);\r
- fclose($handle); \r
- }\r
- }\r
- return $result;\r
- }\r
- \r
- public function setContent($content)\r
- {\r
- $this->populateContentData();\r
- $this->_isDirty = true;\r
- $this->_newContent = $content; \r
- }\r
- \r
- public function writeContentFromFile($fileName)\r
- {\r
- $this->populateContentData();\r
- $this->_isDirty = true;\r
- $this->_newFileContent = $fileName; \r
- }\r
- \r
- public function readContentToFile($fileName)\r
- {\r
- $handle = fopen($fileName, "wb");\r
- fwrite($handle, $this->getContent());\r
- fclose($handle); \r
- }\r
- \r
- public function onBeforeSave(&$statements, $where)\r
- {\r
- if ($this->_isDirty == true)\r
- {\r
- // Check mimetype has been set\r
- if ($this->_mimetype == null)\r
- {\r
- throw new Exception("A mime type for the content property ".$this->_property." on node ".$this->_node->__toString()." must be set");\r
- }\r
- \r
- // If a file has been specified then read content from there\r
- //$content = null;\r
- if ($this->_newFileContent != null)\r
- {\r
- // Upload the content to the repository\r
- $contentData = upload_file($this->node->session, $this->_newFileContent, $this->_mimetype, $this->_encoding);\r
- \r
- // Set the content property value\r
- $this->addStatement(\r
- $statements, \r
- "update", \r
- array("property" => array(\r
- "name" => $this->property,\r
- "isMultiValue" => false,\r
- "value" => $contentData)) + $where); \r
- }\r
- else\r
- {\r
- // Add the writeContent statement\r
- $this->addStatement(\r
- $statements, \r
- "writeContent", \r
- array(\r
- "property" => $this->_property,\r
- "content" => $this->_newContent,\r
- "format" => array(\r
- "mimetype" => $this->_mimetype,\r
- "encoding" => $this->_encoding)) + \r
- $where); \r
- } \r
- }\r
- }\r
- \r
- public function onAfterSave()\r
- {\r
- $this->_isDirty = false;\r
- $this->_isPopulated = false;\r
- $this->_mimetype = null;\r
- $this->__size = null;\r
- $this->__encoding = null; \r
- $this->__url = null;\r
- $this->__newContent = null;\r
- }\r
- \r
- private function populateContentData()\r
- {\r
- //echo "isPopulated:".$this->_isPopulated."; node:".$this->_node."; property:".$this->_property."<br>";\r
- if ($this->_isPopulated == false && $this->_node != null && $this->_property != null && $this->_node->isNewNode == false)\r
- { \r
- $result = $this->_node->session->contentService->read( array(\r
- "items" => array(\r
- "nodes" => array(\r
- "store" => $this->_node->store->__toArray(),\r
- "uuid" => $this->_node->id)), \r
- "property" => $this->_property) );\r
- if (isset($result->content) == true)\r
- { \r
- if (isset($result->content->length) == true)\r
- { \r
- $this->_size = $result->content->length;\r
- }\r
- if (isset($result->content->format->mimetype) == true)\r
- { \r
- $this->_mimetype = $result->content->format->mimetype;\r
- }\r
- if (isset($result->content->format->encoding) == true)\r
- {\r
- $this->_encoding = $result->content->format->encoding;\r
- }\r
- if (isset($result->content->url) == true)\r
- {\r
- $this->_url = $result->content->url;\r
- }\r
- } \r
- \r
- $this->_isPopulated = true;\r
- }\r
- }\r
- \r
- private function addStatement(&$statements, $statement, $body)\r
- { \r
- $result = array(); \r
- if (array_key_exists($statement, $statements) == true) \r
- {\r
- $result = $statements[$statement];\r
- }\r
- $result[] = $body;\r
- $statements[$statement] = $result;\r
- }\r
-}\r
-?>\r
+<?php
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+// change by moodle
+require_once($CFG->libdir."/alfresco/Service/Functions.php");
+
+class ContentData extends BaseObject
+{
+ private $_isPopulated = false;
+ private $_isDirty = false;
+
+ private $_node;
+ private $_property;
+
+ private $_mimetype;
+ private $_size;
+ private $_encoding;
+ private $_url;
+ private $_newContent;
+ private $_newFileContent;
+
+ public function __construct($node, $property, $mimetype=null, $encoding=null, $size=-1)
+ {
+ $this->_node = $node;
+ $this->_property = $property;
+ $this->_mimetype = $mimetype;
+ $this->_encoding = $encoding;
+ if ($size != -1)
+ {
+ $this->size = $size;
+ }
+ $this->_isPopulated = false;
+ }
+
+ public function setPropertyDetails($node, $property)
+ {
+ $this->_node = $node;
+ $this->_property = $property;
+ }
+
+ public function __toString()
+ {
+ $this->populateContentData();
+ return "mimetype=".$this->mimetype."|encoding=".$this->encoding."|size=".$this->size;
+ }
+
+ public function getNode()
+ {
+ return $this->_node;
+ }
+
+ public function getProperty()
+ {
+ return $this->_property;
+ }
+
+ public function getIsDirty()
+ {
+ return $this->_isDirty;
+ }
+
+ public function getMimetype()
+ {
+ $this->populateContentData();
+ return $this->_mimetype;
+ }
+
+ public function setMimetype($mimetype)
+ {
+ $this->populateContentData();
+ $this->_mimetype = $mimetype;
+ }
+
+ public function getSize()
+ {
+ $this->populateContentData();
+ return $this->_size;
+ }
+
+ public function getEncoding()
+ {
+ $this->populateContentData();
+ return $this->_encoding;
+ }
+
+ public function setEncoding($encoding)
+ {
+ $this->populateContentData();
+ $this->_encoding = $encoding;
+ }
+
+ public function getUrl()
+ {
+ // TODO what should be returned if the content has been updated??
+
+ $this->populateContentData();
+ $result = null;
+ if ($this->_url != null)
+ {
+ $result = $this->_url."?ticket=".$this->_node->session->ticket;
+ }
+ return $result;
+ }
+
+ public function getGuestUrl()
+ {
+ // TODO what should be returned if the content has been updated??
+
+ $this->populateContentData();
+ $result = null;
+ if ($this->_url != null)
+ {
+ $result = $this->_url."?guest=true";
+ }
+ return $result;
+ }
+
+ public function getContent()
+ {
+ $this->populateContentData();
+
+ $result = null;
+ if ($this->_isDirty == true)
+ {
+ if ($this->_newFileContent != null)
+ {
+ $handle = fopen($this->_newFileContent, "rb");
+ $result = stream_get_contents($handle);
+ fclose($handle);
+ }
+ else if ($this->_newContent != null)
+ {
+ $result = $this->_newContent;
+ }
+ }
+ else
+ {
+ if ($this->getUrl() != null)
+ {
+ $handle = fopen($this->getUrl(), "rb");
+ $result = stream_get_contents($handle);
+ fclose($handle);
+ }
+ }
+ return $result;
+ }
+
+ public function setContent($content)
+ {
+ $this->populateContentData();
+ $this->_isDirty = true;
+ $this->_newContent = $content;
+ }
+
+ public function writeContentFromFile($fileName)
+ {
+ $this->populateContentData();
+ $this->_isDirty = true;
+ $this->_newFileContent = $fileName;
+ }
+
+ public function readContentToFile($fileName)
+ {
+ $handle = fopen($fileName, "wb");
+ fwrite($handle, $this->getContent());
+ fclose($handle);
+ }
+
+ public function onBeforeSave(&$statements, $where)
+ {
+ if ($this->_isDirty == true)
+ {
+ // Check mimetype has been set
+ if ($this->_mimetype == null)
+ {
+ throw new Exception("A mime type for the content property ".$this->_property." on node ".$this->_node->__toString()." must be set");
+ }
+
+ // If a file has been specified then read content from there
+ //$content = null;
+ if ($this->_newFileContent != null)
+ {
+ // Upload the content to the repository
+ $contentData = upload_file($this->node->session, $this->_newFileContent, $this->_mimetype, $this->_encoding);
+
+ // Set the content property value
+ $this->addStatement(
+ $statements,
+ "update",
+ array("property" => array(
+ "name" => $this->property,
+ "isMultiValue" => false,
+ "value" => $contentData)) + $where);
+ }
+ else
+ {
+ // Add the writeContent statement
+ $this->addStatement(
+ $statements,
+ "writeContent",
+ array(
+ "property" => $this->_property,
+ "content" => $this->_newContent,
+ "format" => array(
+ "mimetype" => $this->_mimetype,
+ "encoding" => $this->_encoding)) +
+ $where);
+ }
+ }
+ }
+
+ public function onAfterSave()
+ {
+ $this->_isDirty = false;
+ $this->_isPopulated = false;
+ $this->_mimetype = null;
+ $this->__size = null;
+ $this->__encoding = null;
+ $this->__url = null;
+ $this->__newContent = null;
+ }
+
+ private function populateContentData()
+ {
+ //echo "isPopulated:".$this->_isPopulated."; node:".$this->_node."; property:".$this->_property."<br>";
+ if ($this->_isPopulated == false && $this->_node != null && $this->_property != null && $this->_node->isNewNode == false)
+ {
+ $result = $this->_node->session->contentService->read( array(
+ "items" => array(
+ "nodes" => array(
+ "store" => $this->_node->store->__toArray(),
+ "uuid" => $this->_node->id)),
+ "property" => $this->_property) );
+ if (isset($result->content) == true)
+ {
+ if (isset($result->content->length) == true)
+ {
+ $this->_size = $result->content->length;
+ }
+ if (isset($result->content->format->mimetype) == true)
+ {
+ $this->_mimetype = $result->content->format->mimetype;
+ }
+ if (isset($result->content->format->encoding) == true)
+ {
+ $this->_encoding = $result->content->format->encoding;
+ }
+ if (isset($result->content->url) == true)
+ {
+ $this->_url = $result->content->url;
+ }
+ }
+
+ $this->_isPopulated = true;
+ }
+ }
+
+ private function addStatement(&$statements, $statement, $body)
+ {
+ $result = array();
+ if (array_key_exists($statement, $statements) == true)
+ {
+ $result = $statements[$statement];
+ }
+ $result[] = $body;
+ $statements[$statement] = $result;
+ }
+}
+?>
-<?php\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
- \r
- require_once("Repository.php");\r
- require_once("Session.php");\r
- \r
- /**\r
- * Uploads a file into content store and returns the content data string which\r
- * can be used to populate a content property.\r
- * \r
- * @param $session the session\r
- * @param $filePath the file location\r
- * @return String the content data that can be used to update the content property\r
- */\r
- function upload_file($session, $filePath, $mimetype=null, $encoding=null)\r
- {\r
- $result = null;\r
- \r
- // Check for the existance of the file\r
- if (file_exists($filePath) == false)\r
- {\r
- throw new Exception("The file ".$filePath."does no exist.");\r
- }\r
- \r
- // Get the file name and size\r
- $fileName = basename($filePath);\r
- $fileSize = filesize($filePath);\r
- \r
- // Get the address and the \r
- $host = $session->repository->host; \r
- $port = $session->repository->port;\r
- \r
- // Get the IP address for the target host\r
- $address = gethostbyname($host);\r
- \r
- // Create a TCP/IP socket\r
- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);\r
- if ($socket === false) \r
- {\r
- throw new Exception ("socket_create() failed: reason: " . socket_strerror(socket_last_error()));\r
- } \r
- \r
- // Connect the socket to the repository\r
- $result = socket_connect($socket, $address, $port);\r
- if ($result === false) \r
- {\r
- throw new Exception("socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)));\r
- } \r
- \r
- // Write the request header onto the socket\r
- $url = "/alfresco/upload/".urlencode($fileName)."?ticket=".$session->ticket;\r
- if ($mimetype != null)\r
- {\r
- // Add mimetype if specified\r
- $url .= "&mimetype=".$mimetype;\r
- }\r
- if ($encoding != null)\r
- {\r
- // Add encoding if specified\r
- $url .= "&encoding=".$encoding;\r
- }\r
- $in = "PUT ".$url." HTTP/1.1\r\n".\r
- "Content-Length: ".$fileSize."\r\n".\r
- "Host: ".$address.":".$port."\r\n".\r
- "Connection: Keep-Alive\r\n".\r
- "\r\n"; \r
- socket_write($socket, $in, strlen($in));\r
- \r
- // Write the content found in the file onto the socket\r
- $handle = fopen($filePath, "r");\r
- while (feof($handle) == false)\r
- {\r
- $content = fread($handle, 1024);\r
- socket_write($socket, $content, strlen($content)); \r
- } \r
- fclose($handle);\r
- \r
- // Read the response\r
- $recv = socket_read ($socket, 2048, PHP_BINARY_READ);\r
- $index = strpos($recv, "contentUrl");\r
- if ($index !== false)\r
- {\r
- $result = substr($recv, $index); \r
- }\r
- \r
- // Close the socket\r
- socket_close($socket);\r
- \r
- return $result;\r
- } \r
-?>\r
+<?php
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+ // change by moodle
+ require_once($CFG->libdir."/alfresco/Service/Repository.php");
+ require_once($CFG->libdir."/alfresco/Service/Session.php");
+
+ /**
+ * Uploads a file into content store and returns the content data string which
+ * can be used to populate a content property.
+ *
+ * @param $session the session
+ * @param $filePath the file location
+ * @return String the content data that can be used to update the content property
+ */
+ function upload_file($session, $filePath, $mimetype=null, $encoding=null)
+ {
+ $result = null;
+
+ // Check for the existance of the file
+ if (file_exists($filePath) == false)
+ {
+ throw new Exception("The file ".$filePath."does no exist.");
+ }
+
+ // Get the file name and size
+ $fileName = basename($filePath);
+ $fileSize = filesize($filePath);
+
+ // Get the address and the
+ $host = $session->repository->host;
+ $port = $session->repository->port;
+
+ // Get the IP address for the target host
+ $address = gethostbyname($host);
+
+ // Create a TCP/IP socket
+ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+ if ($socket === false)
+ {
+ throw new Exception ("socket_create() failed: reason: " . socket_strerror(socket_last_error()));
+ }
+
+ // Connect the socket to the repository
+ $result = socket_connect($socket, $address, $port);
+ if ($result === false)
+ {
+ throw new Exception("socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)));
+ }
+
+ // Write the request header onto the socket
+ $url = "/alfresco/upload/".urlencode($fileName)."?ticket=".$session->ticket;
+ if ($mimetype != null)
+ {
+ // Add mimetype if specified
+ $url .= "&mimetype=".$mimetype;
+ }
+ if ($encoding != null)
+ {
+ // Add encoding if specified
+ $url .= "&encoding=".$encoding;
+ }
+ $in = "PUT ".$url." HTTP/1.1\r\n".
+ "Content-Length: ".$fileSize."\r\n".
+ "Host: ".$address.":".$port."\r\n".
+ "Connection: Keep-Alive\r\n".
+ "\r\n";
+ socket_write($socket, $in, strlen($in));
+
+ // Write the content found in the file onto the socket
+ $handle = fopen($filePath, "r");
+ while (feof($handle) == false)
+ {
+ $content = fread($handle, 1024);
+ socket_write($socket, $content, strlen($content));
+ }
+ fclose($handle);
+
+ // Read the response
+ $recv = socket_read ($socket, 2048, PHP_BINARY_READ);
+ $index = strpos($recv, "contentUrl");
+ if ($index !== false)
+ {
+ $result = substr($recv, $index);
+ }
+
+ // Close the socket
+ socket_close($socket);
+
+ return $result;
+ }
+?>
-<?php\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
- \r
- require_once "LoggerConfig.php";\r
- \r
- class Logger\r
- { \r
- private $componentName;\r
- \r
- public function __construct($componentName = null)\r
- {\r
- $this->componentName = $componentName;\r
- } \r
- \r
- public function isDebugEnabled()\r
- {\r
- return $this->isEnabled(DEBUG);\r
- }\r
- \r
- public function debug($message)\r
- {\r
- $this->write(DEBUG, $message); \r
- }\r
- \r
- public function isWarningEnabled()\r
- {\r
- return $this->isEnabled(WARNING);\r
- }\r
- \r
- public function warning($message)\r
- {\r
- $this->write(WARNING, $message); \r
- }\r
- \r
- public function isInformationEnabled()\r
- {\r
- return $this->isEnabled(INFORMATION); \r
- }\r
- \r
- public function information($message)\r
- {\r
- $this->write(INFORMATION, $message); \r
- }\r
- \r
- private function isEnabled($logLevel)\r
- {\r
- global $componentLogLevels, $defaultLogLevel;\r
- \r
- $logLevels = $defaultLogLevel;\r
- if ($this->componentName != null && isset($componentLogLevels[$this->componentName]) == true)\r
- {\r
- $logLevels = $componentLogLevels[$this->componentName];\r
- }\r
- \r
- return in_array($logLevel, $logLevels);\r
- }\r
- \r
- private function write($logLevel, $message)\r
- {\r
- global $logFile;\r
- \r
- $handle = fopen($logFile, "a");\r
- fwrite($handle, $logLevel." ".date("G:i:s d/m/Y")." - ".$message."\r\n");\r
- fclose($handle);\r
- }\r
- }\r
-?>\r
+<?php
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+ require_once "LoggerConfig.php";
+
+ class Logger
+ {
+ private $componentName;
+
+ public function __construct($componentName = null)
+ {
+ $this->componentName = $componentName;
+ }
+
+ public function isDebugEnabled()
+ {
+ return $this->isEnabled(DEBUG);
+ }
+
+ public function debug($message)
+ {
+ $this->write(DEBUG, $message);
+ }
+
+ public function isWarningEnabled()
+ {
+ return $this->isEnabled(WARNING);
+ }
+
+ public function warning($message)
+ {
+ $this->write(WARNING, $message);
+ }
+
+ public function isInformationEnabled()
+ {
+ return $this->isEnabled(INFORMATION);
+ }
+
+ public function information($message)
+ {
+ $this->write(INFORMATION, $message);
+ }
+
+ private function isEnabled($logLevel)
+ {
+ global $componentLogLevels, $defaultLogLevel;
+
+ $logLevels = $defaultLogLevel;
+ if ($this->componentName != null && isset($componentLogLevels[$this->componentName]) == true)
+ {
+ $logLevels = $componentLogLevels[$this->componentName];
+ }
+
+ return in_array($logLevel, $logLevels);
+ }
+
+ private function write($logLevel, $message)
+ {
+ global $logFile;
+
+ $handle = fopen($logFile, "a");
+ fwrite($handle, $logLevel." ".date("G:i:s d/m/Y")." - ".$message."\r\n");
+ fclose($handle);
+ }
+ }
+?>
-<?php\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
- \r
-define("DEBUG", "Debug");\r
-define("WARNING", "Warning");\r
-define("INFO", "Information");\r
-\r
-$debugLevel = array(DEBUG, WARNING, INFO);\r
-$warningLevel = array(WARNING, INFO);\r
-$infoLevel = array(INFO);\r
-$noneLevel = array();\r
-\r
-$defaultLogLevel = $infoLevel;\r
-\r
-$logFile = "c:/work/AlfrescoPHPLog.txt"; \r
-$componentLogLevels = array(\r
- "integration.mediawiki.ExternalStoreAlfresco" => $debugLevel\r
- );\r
- \r
- \r
-?>\r
+<?php
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+define("DEBUG", "Debug");
+define("WARNING", "Warning");
+define("INFO", "Information");
+
+$debugLevel = array(DEBUG, WARNING, INFO);
+$warningLevel = array(WARNING, INFO);
+$infoLevel = array(INFO);
+$noneLevel = array();
+
+$defaultLogLevel = $infoLevel;
+
+$logFile = "c:/work/AlfrescoPHPLog.txt";
+$componentLogLevels = array(
+ "integration.mediawiki.ExternalStoreAlfresco" => $debugLevel
+ );
+
+
+?>
// Set the property values\r
foreach ($properties as $name=>$value)\r
{\r
- $name = $this->expandToFullName($name);\r
+ $name = $this->_session->namespaceMap->getFullName($name);\r
$this->_properties[$name] = $value;\r
} \r
}\r
\r
- public function setContent($property, $mimetype=null, $encoding=null, $content=null)\r
+ public function updateContent($property, $mimetype, $encoding="UTF-8", $content=null)\r
{\r
list($property) = $this->_session->namespaceMap->getFullNames(array($property));\r
$contentData = new ContentData($this, $property, $mimetype, $encoding);\r
-<?php\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
-\r
-require_once 'WebService/WebServiceFactory.php';\r
-require_once 'BaseObject.php';\r
-\r
-if (isset($_SESSION) == false)\r
-{\r
- // Start the session\r
- session_start();\r
-} \r
- \r
-class Al_Repository extends BaseObject // Moodle\r
-{\r
- private $_connectionUrl; \r
- private $_host;\r
- private $_port;\r
-\r
- public function __construct($connectionUrl="http://localhost:8080/alfresco/api")\r
- {\r
- $this->_connectionUrl = $connectionUrl; \r
- $parts = parse_url($connectionUrl);\r
- $this->_host = $parts["host"];\r
- $this->_port = $parts["port"];\r
- }\r
- \r
- public function getConnectionUrl()\r
- {\r
- return $this->_connectionUrl;\r
- }\r
- \r
- public function getHost()\r
- {\r
- return $this->_host; \r
- }\r
- \r
- public function getPort()\r
- {\r
- return $this->_port;\r
- }\r
- \r
- public function authenticate($userName, $password)\r
- {\r
- // TODO need to handle exceptions!\r
- \r
- $authenticationService = WebServiceFactory::getAuthenticationService($this->_connectionUrl);\r
- $result = $authenticationService->startSession(array (\r
- "username" => $userName,\r
- "password" => $password\r
- ));\r
- \r
- // Get the ticket and sessionId\r
- $ticket = $result->startSessionReturn->ticket;\r
- $sessionId = $result->startSessionReturn->sessionid;\r
- \r
- // Store the session id for later use\r
- if ($sessionId != null)\r
- {\r
- $sessionIds = null;\r
- if (isset($_SESSION["sessionIds"]) == false)\r
- {\r
- $sessionIds = array();\r
- }\r
- else\r
- {\r
- $sessionIds = $_SESSION["sessionIds"];\r
- }\r
- $sessionIds[$ticket] = $sessionId;\r
- $_SESSION["sessionIds"] = $sessionIds;\r
- }\r
- \r
- return $ticket;\r
- }\r
- \r
- public function createSession($ticket=null)\r
- {\r
- $session = null;\r
- \r
- if ($ticket == null)\r
- {\r
- // TODO get ticket from some well known location ie: the $_SESSION\r
- } \r
- else\r
- {\r
- // TODO would be nice to be able to check that the ticket is still valid!\r
- \r
- // Create new session\r
- $session = new Session($this, $ticket); \r
- }\r
- \r
- return $session;\r
- }\r
- \r
- /**\r
- * For a given ticket, returns the realated session id, null if one can not be found.\r
- */\r
- public static function getSessionId($ticket)\r
- {\r
- $result = null;\r
- if (isset($_SESSION["sessionIds"]) == true)\r
- {\r
- $result = $_SESSION["sessionIds"][$ticket];\r
- }\r
- return $result;\r
-\r
- }\r
-\r
-}\r
- \r
- ?>\r
+<?php
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+// change by moodle
+require_once $CFG->libdir.'/alfresco/Service/WebService/WebServiceFactory.php';
+require_once $CFG->libdir.'/alfresco/Service/BaseObject.php';
+
+if (isset($_SESSION) == false)
+{
+ // Start the session
+ session_start();
+}
+
+// change by moodle
+class Alfresco_Repository extends BaseObject
+{
+ private $_connectionUrl;
+ private $_host;
+ private $_port;
+
+ public function __construct($connectionUrl="http://localhost:8080/alfresco/api")
+ {
+ $this->_connectionUrl = $connectionUrl;
+ $parts = parse_url($connectionUrl);
+ $this->_host = $parts["host"];
+ if (empty($parts["port"])) {
+ $this->_port = 80;
+ } else {
+ $this->_port = $parts["port"];
+ }
+ }
+
+ public function getConnectionUrl()
+ {
+ return $this->_connectionUrl;
+ }
+
+ public function getHost()
+ {
+ return $this->_host;
+ }
+
+ public function getPort()
+ {
+ return $this->_port;
+ }
+
+ public function authenticate($userName, $password)
+ {
+ // TODO need to handle exceptions!
+
+ $authenticationService = WebServiceFactory::getAuthenticationService($this->_connectionUrl);
+ $result = $authenticationService->startSession(array (
+ "username" => $userName,
+ "password" => $password
+ ));
+
+ // Get the ticket and sessionId
+ $ticket = $result->startSessionReturn->ticket;
+ $sessionId = $result->startSessionReturn->sessionid;
+
+ // Store the session id for later use
+ if ($sessionId != null)
+ {
+ $sessionIds = null;
+ if (isset($_SESSION["sessionIds"]) == false)
+ {
+ $sessionIds = array();
+ }
+ else
+ {
+ $sessionIds = $_SESSION["sessionIds"];
+ }
+ $sessionIds[$ticket] = $sessionId;
+ $_SESSION["sessionIds"] = $sessionIds;
+ }
+
+ return $ticket;
+ }
+
+ public function createSession($ticket=null)
+ {
+ $session = null;
+
+ if ($ticket == null)
+ {
+ // TODO get ticket from some well known location ie: the $_SESSION
+ }
+ else
+ {
+ // TODO would be nice to be able to check that the ticket is still valid!
+
+ // Create new session
+ $session = new Session($this, $ticket);
+ }
+
+ return $session;
+ }
+
+ /**
+ * For a given ticket, returns the realated session id, null if one can not be found.
+ */
+ public static function getSessionId($ticket)
+ {
+ $result = null;
+ if (isset($_SESSION["sessionIds"]) == true)
+ {
+ $result = $_SESSION["sessionIds"][$ticket];
+ }
+ return $result;
+
+ }
+
+}
+
+ ?>
public function getNodeFromString($value)\r
{\r
// TODO\r
- throw Exception("getNode($value) no yet implemented");\r
+ throw new Exception("getNode($value) not yet implemented");\r
}\r
\r
/**\r
return $sessionId;\r
}\r
}\r
-?>
\ No newline at end of file
+?>\r
-<?php\r
-\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
-\r
-class AlfrescoWebService extends SoapClient\r
-{\r
- private $securityExtNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";\r
- private $wsUtilityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";\r
- private $passwordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";\r
-\r
- private $ticket;\r
- \r
- public function __construct($wsdl, $options = array('trace' => true, 'exceptions' => true), $ticket = null)\r
- {\r
- // Store the current ticket\r
- $this->ticket = $ticket;\r
-\r
- // Call the base class\r
- parent::__construct($wsdl, $options);\r
- }\r
-\r
- public function __call($function_name, $arguments=array())\r
- {\r
- return $this->__soapCall($function_name, $arguments);\r
- }\r
-\r
- public function __soapCall($function_name, $arguments=array(), $options=array(), $input_headers=array(), $output_headers=array())\r
- {\r
- if (isset($this->ticket))\r
- {\r
- // Automatically add a security header \r
- $input_headers[] = new SoapHeader($this->securityExtNS, "Security", null, 1);\r
- \r
- // Set the JSESSION cookie value\r
- $sessionId = Al_Repository::getSessionId($this->ticket); // Moodle\r
- if ($sessionId != null)\r
- {\r
- $this->__setCookie("JSESSIONID", $sessionId);\r
- }\r
- }\r
- \r
- return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers); \r
- }\r
- \r
- public function __doRequest($request, $location, $action, $version)\r
- {\r
- // If this request requires authentication we have to manually construct the\r
- // security headers.\r
- if (isset($this->ticket))\r
- { \r
- $dom = new DOMDocument("1.0");\r
- $dom->loadXML($request);\r
-\r
- $securityHeader = $dom->getElementsByTagName("Security");\r
-\r
- if ($securityHeader->length != 1)\r
- {\r
- throw new Exception("Expected length: 1, Received: " . $securityHeader->length . ". No Security Header, or more than one element called Security!");\r
- }\r
- \r
- $securityHeader = $securityHeader->item(0);\r
-\r
- // Construct Timestamp Header\r
- $timeStamp = $dom->createElementNS($this->wsUtilityNS, "Timestamp");\r
- $createdDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+24, date("i"), date("s"), date("m"), date("d"), date("Y")));\r
- $expiresDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+25, date("i"), date("s"), date("m"), date("d"), date("Y")));\r
- $created = new DOMElement("Created", $createdDate, $this->wsUtilityNS);\r
- $expires = new DOMElement("Expires", $expiresDate, $this->wsUtilityNS);\r
- $timeStamp->appendChild($created);\r
- $timeStamp->appendChild($expires);\r
-\r
- // Construct UsernameToken Header\r
- $userNameToken = $dom->createElementNS($this->securityExtNS, "UsernameToken");\r
- $userName = new DOMElement("Username", "username", $this->securityExtNS);\r
- $passWord = $dom->createElementNS($this->securityExtNS, "Password");\r
- $typeAttr = new DOMAttr("Type", $this->passwordType);\r
- $passWord->appendChild($typeAttr);\r
- $passWord->appendChild($dom->createTextNode($this->ticket));\r
- $userNameToken->appendChild($userName);\r
- $userNameToken->appendChild($passWord);\r
-\r
- // Construct Security Header\r
- $securityHeader->appendChild($timeStamp);\r
- $securityHeader->appendChild($userNameToken);\r
-\r
- // Save the XML Request\r
- $request = $dom->saveXML();\r
- }\r
-\r
- return parent::__doRequest($request, $location, $action, $version);\r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+class AlfrescoWebService extends SoapClient
+{
+ private $securityExtNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
+ private $wsUtilityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
+ private $passwordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
+
+ private $ticket;
+
+ public function __construct($wsdl, $options = array('trace' => true, 'exceptions' => true), $ticket = null)
+ {
+ // Store the current ticket
+ $this->ticket = $ticket;
+
+ // Call the base class
+ parent::__construct($wsdl, $options);
+ }
+
+ public function __call($function_name, $arguments=array())
+ {
+ return $this->__soapCall($function_name, $arguments);
+ }
+
+ public function __soapCall($function_name, $arguments=array(), $options=array(), $input_headers=array(), $output_headers=array())
+ {
+ if (isset($this->ticket))
+ {
+ // Automatically add a security header
+ $input_headers[] = new SoapHeader($this->securityExtNS, "Security", null, 1);
+
+ // Set the JSESSION cookie value
+ // change by moodle
+ $sessionId = Alfresco_Repository::getSessionId($this->ticket);
+ if ($sessionId != null)
+ {
+ $this->__setCookie("JSESSIONID", $sessionId);
+ }
+ }
+
+ return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers);
+ }
+
+ public function __doRequest($request, $location, $action, $version)
+ {
+ // If this request requires authentication we have to manually construct the
+ // security headers.
+ if (isset($this->ticket))
+ {
+ $dom = new DOMDocument("1.0");
+ $dom->loadXML($request);
+
+ $securityHeader = $dom->getElementsByTagName("Security");
+
+ if ($securityHeader->length != 1)
+ {
+ throw new Exception("Expected length: 1, Received: " . $securityHeader->length . ". No Security Header, or more than one element called Security!");
+ }
+
+ $securityHeader = $securityHeader->item(0);
+
+ // Construct Timestamp Header
+ $timeStamp = $dom->createElementNS($this->wsUtilityNS, "Timestamp");
+ $createdDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+24, date("i"), date("s"), date("m"), date("d"), date("Y")));
+ $expiresDate = date("Y-m-d\TH:i:s\Z", mktime(date("H")+25, date("i"), date("s"), date("m"), date("d"), date("Y")));
+ $created = new DOMElement("Created", $createdDate, $this->wsUtilityNS);
+ $expires = new DOMElement("Expires", $expiresDate, $this->wsUtilityNS);
+ $timeStamp->appendChild($created);
+ $timeStamp->appendChild($expires);
+
+ // Construct UsernameToken Header
+ $userNameToken = $dom->createElementNS($this->securityExtNS, "UsernameToken");
+ $userName = new DOMElement("Username", "username", $this->securityExtNS);
+ $passWord = $dom->createElementNS($this->securityExtNS, "Password");
+ $typeAttr = new DOMAttr("Type", $this->passwordType);
+ $passWord->appendChild($typeAttr);
+ $passWord->appendChild($dom->createTextNode($this->ticket));
+ $userNameToken->appendChild($userName);
+ $userNameToken->appendChild($passWord);
+
+ // Construct Security Header
+ $securityHeader->appendChild($timeStamp);
+ $securityHeader->appendChild($userNameToken);
+
+ // Save the XML Request
+ $request = $dom->saveXML();
+ }
+
+ return parent::__doRequest($request, $location, $action, $version);
+ }
+}
+
+?>
-<?php\r
-\r
-/*\r
- * Copyright (C) 2005 Alfresco, Inc.\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
-\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
-\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
-\r
- * As a special exception to the terms and conditions of version 2.0 of \r
- * the GPL, you may redistribute this Program in connection with Free/Libre \r
- * and Open Source Software ("FLOSS") applications as described in Alfresco's \r
- * FLOSS exception. You should have recieved a copy of the text describing \r
- * the FLOSS exception, and it is also available here: \r
- * http://www.alfresco.com/legal/licensing"\r
- */\r
-\r
-require_once 'AlfrescoWebService.php';\r
-\r
-class WebServiceFactory\r
-{\r
- public static function getAuthenticationService($path)\r
- {\r
- $path .= '/AuthenticationService?wsdl';\r
- return new AlfrescoWebService($path, array());\r
- }\r
-\r
- public static function getRepositoryService($path, $ticket)\r
- {\r
- $path .= '/RepositoryService?wsdl';\r
- return new AlfrescoWebService($path, array(), $ticket);\r
- }\r
- \r
- public static function getContentService($path, $ticket)\r
- {\r
- $path .= '/ContentService?wsdl';\r
- return new AlfrescoWebService($path, array(), $ticket);\r
- }\r
- \r
- public static function getAdministrationService($path, $ticket)\r
- {\r
- $path .= '/AdministrationService?wsdl';\r
- return new AlfrescoWebService($path, array(), $ticket);\r
- } \r
- \r
- public static function getAuthoringService($path, $ticket)\r
- {\r
- $path .= '/AuthoringService?wsdl';\r
- return new AlfrescoWebService($path, array(), $ticket);\r
- }\r
-}\r
-\r
-?>
\ No newline at end of file
+<?php
+
+/*
+ * Copyright (C) 2005 Alfresco, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+// changed by moodle
+require_once ($CFG->libdir.'/alfresco/Service/WebService/AlfrescoWebService.php');
+
+class WebServiceFactory
+{
+ public static function getAuthenticationService($path)
+ {
+ $path .= '/AuthenticationService?wsdl';
+ return new AlfrescoWebService($path, array('location'=>$path));
+ }
+
+ public static function getRepositoryService($path, $ticket)
+ {
+ $path .= '/RepositoryService?wsdl';
+ return new AlfrescoWebService($path, array('location'=>$path), $ticket);
+ }
+
+ public static function getContentService($path, $ticket)
+ {
+ $path .= '/ContentService?wsdl';
+ return new AlfrescoWebService($path, array('location'=>$path), $ticket);
+ }
+
+ public static function getAdministrationService($path, $ticket)
+ {
+ $path .= '/AdministrationService?wsdl';
+ return new AlfrescoWebService($path, array('location'=>$path), $ticket);
+ }
+
+ public static function getAuthoringService($path, $ticket)
+ {
+ $path .= '/AuthoringService?wsdl';
+ return new AlfrescoWebService($path, array('location'=>$path), $ticket);
+ }
+}
+
+?>
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
-require_once($CFG->libdir . '/soaplib.php');
class repository_alfresco extends repository {
- private $repo = null;
+ private $instance = null;
private $ticket = null;
- private $sess = null;
+ private $user_session = null;
private $store = null;
public function __construct($repositoryid, $context = SITEID, $options = array()) {
global $SESSION, $CFG;
- parent::__construct ($repositoryid, $context, $options);
+ parent::__construct($repositoryid, $context, $options);
+ $this->sessname = 'alfresco_ticket_'.$this->id;
if (class_exists('SoapClient')) {
require_once($CFG->libdir . '/alfresco/Service/Repository.php');
require_once($CFG->libdir . '/alfresco/Service/Session.php');
require_once($CFG->libdir . '/alfresco/Service/SpacesStore.php');
require_once($CFG->libdir . '/alfresco/Service/Node.php');
- $this->repo = new Al_Repository($this->alfresco_url);
- $this->sess_name = 'alfresco_ticket_'.$this->id;
+ // setup alfresco instance
+ $this->instance = new Alfresco_Repository($this->options['alfresco_url']);
$this->username = optional_param('al_username', '', PARAM_RAW);
$this->password = optional_param('al_password', '', PARAM_RAW);
try{
- if ( empty($SESSION->{$this->sess_name}) && !empty($this->username) && !empty($this->password)) {
- $this->ticket = $this->repo->authenticate($this->username, $this->password);
- $SESSION->{$this->sess_name} = $this->ticket;
+ // deal with user logging in
+ if (empty($SESSION->{$this->sessname}) && !empty($this->username) && !empty($this->password)) {
+ $this->ticket = $this->instance->authenticate($this->username, $this->password);
+ $SESSION->{$this->sessname} = $this->ticket;
} else {
- $this->ticket = $SESSION->{$this->sess_name};
+ if (!empty($SESSION->{$this->sessname})) {
+ $this->ticket = $SESSION->{$this->sessname};
+ }
}
- $this->sess = $this->repo->createSession($this->ticket);
- $this->store = new SpacesStore($this->sess);
+ $this->user_session = $this->instance->createSession($this->ticket);
+ $this->store = new SpacesStore($this->user_session);
} catch (Exception $e) {
$this->logout();
}
public function logout() {
global $SESSION;
- unset($SESSION->{$this->sess_name});
+ unset($SESSION->{$this->sessname});
return $this->print_login();
}
public function check_login() {
global $SESSION;
- return !empty($SESSION->{$this->sess_name});
+ return !empty($SESSION->{$this->sessname});
}
private function get_url($node) {
$ret = array();
$ret['dynload'] = true;
$ret['list'] = array();
- $url = $this->alfresco_url;
+ $url = $this->options['alfresco_url'];
$pattern = '#^(.*)api#';
preg_match($pattern, $url, $matches);
$ret['manage'] = $matches[1].'faces/jsp/dashboards/container.jsp';
if (empty($uuid)) {
$this->current_node = $this->store->companyHome;
} else {
- $this->current_node = $this->sess->getNode($this->store, $uuid);
+ $this->current_node = $this->user_session->getNode($this->store, $uuid);
}
$folder_filter = "{http://www.alfresco.org/model/content/1.0}folder";
$file_filter = "{http://www.alfresco.org/model/content/1.0}content";
{
$ret['list'][] = array('title'=>$child->child->cm_name,
'path'=>$child->child->id,
- 'thumbnail'=>$CFG->httpswwwroot.'/pix/f/folder.gif',
+ 'thumbnail'=>$CFG->httpswwwroot.'/pix/f/folder-32.png',
'children'=>array());
} elseif ($child->child->type == $file_filter) {
$ret['list'][] = array('title'=>$child->child->cm_name,
public function get_file($uuid, $file = '') {
global $CFG;
- $node = $this->sess->getNode($this->store, $uuid);
+ $node = $this->user_session->getNode($this->store, $uuid);
$url = $this->get_url($node);
$path = $this->prepare_file($file);
$fp = fopen($path, 'w');
public function print_search($client_id) {
$str = parent::print_search($client_id);
$str .= '<label>Space: </label><br /><select name="space">';
- foreach ($this->sess->stores as $v) {
+ foreach ($this->user_session->stores as $v) {
$str .= '<option ';
if ($v->__toString() === 'workspace://SpacesStore') {
$str .= 'selected ';
public function search($search_text) {
global $CFG;
$space = optional_param('space', 'workspace://SpacesStore', PARAM_RAW);
- $currentStore = $this->sess->getStoreFromString($space);
- $nodes = $this->sess->query($currentStore, $search_text);
+ $currentStore = $this->user_session->getStoreFromString($space);
+ $nodes = $this->user_session->query($currentStore, $search_text);
$ret = array();
$ret['list'] = array();
foreach($nodes as $v) {