2008-09-19 04:49:38 +00:00
|
|
|
<?php
|
2009-12-17 03:40:38 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle 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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-05-12 04:14:53 +08:00
|
|
|
/**
|
|
|
|
* This plugin is used to access alfresco repository
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @package repository_alfresco
|
|
|
|
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
require_once($CFG->dirroot . '/repository/lib.php');
|
|
|
|
|
2008-09-19 04:49:38 +00:00
|
|
|
/**
|
|
|
|
* repository_alfresco class
|
2009-12-17 09:00:04 +00:00
|
|
|
* This is a class used to browse files from alfresco
|
2008-09-19 04:49:38 +00:00
|
|
|
*
|
2010-09-06 11:29:21 +00:00
|
|
|
* @since 2.0
|
2012-05-12 04:14:53 +08:00
|
|
|
* @package repository_alfresco
|
|
|
|
* @copyright 2009 Dongsheng Cai {@link http://dongsheng.org}
|
2010-09-06 11:29:21 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-09-19 04:49:38 +00:00
|
|
|
*/
|
|
|
|
class repository_alfresco extends repository {
|
|
|
|
private $ticket = null;
|
2009-06-05 06:55:07 +00:00
|
|
|
private $user_session = null;
|
2008-09-19 04:49:38 +00:00
|
|
|
private $store = null;
|
2010-07-28 09:49:11 +00:00
|
|
|
private $alfresco;
|
2008-09-19 04:49:38 +00:00
|
|
|
|
2010-03-16 03:21:59 +00:00
|
|
|
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
|
2008-09-19 04:49:38 +00:00
|
|
|
global $SESSION, $CFG;
|
2009-06-05 06:55:07 +00:00
|
|
|
parent::__construct($repositoryid, $context, $options);
|
|
|
|
$this->sessname = 'alfresco_ticket_'.$this->id;
|
2008-10-27 02:57:29 +00:00
|
|
|
if (class_exists('SoapClient')) {
|
2008-10-28 03:13:31 +00:00
|
|
|
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');
|
2010-07-28 09:49:11 +00:00
|
|
|
// setup alfresco
|
2009-12-17 09:00:04 +00:00
|
|
|
$server_url = '';
|
|
|
|
if (!empty($this->options['alfresco_url'])) {
|
|
|
|
$server_url = $this->options['alfresco_url'];
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2010-07-28 09:49:11 +00:00
|
|
|
$this->alfresco = new Alfresco_Repository($this->options['alfresco_url']);
|
2008-10-27 02:57:29 +00:00
|
|
|
$this->username = optional_param('al_username', '', PARAM_RAW);
|
|
|
|
$this->password = optional_param('al_password', '', PARAM_RAW);
|
|
|
|
try{
|
2009-06-05 06:55:07 +00:00
|
|
|
// deal with user logging in
|
|
|
|
if (empty($SESSION->{$this->sessname}) && !empty($this->username) && !empty($this->password)) {
|
2010-07-28 09:49:11 +00:00
|
|
|
$this->ticket = $this->alfresco->authenticate($this->username, $this->password);
|
2009-12-16 22:14:17 +00:00
|
|
|
$SESSION->{$this->sessname} = $this->ticket;
|
2008-10-27 02:57:29 +00:00
|
|
|
} else {
|
2009-06-05 06:55:07 +00:00
|
|
|
if (!empty($SESSION->{$this->sessname})) {
|
2009-12-16 22:14:17 +00:00
|
|
|
$this->ticket = $SESSION->{$this->sessname};
|
2009-06-05 06:55:07 +00:00
|
|
|
}
|
2008-10-27 02:57:29 +00:00
|
|
|
}
|
2010-07-28 09:49:11 +00:00
|
|
|
$this->user_session = $this->alfresco->createSession($this->ticket);
|
2009-06-05 06:55:07 +00:00
|
|
|
$this->store = new SpacesStore($this->user_session);
|
2008-10-27 02:57:29 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->logout();
|
2008-09-23 01:19:27 +00:00
|
|
|
}
|
2008-10-27 02:57:29 +00:00
|
|
|
$this->current_node = null;
|
2008-10-28 03:13:31 +00:00
|
|
|
} else {
|
|
|
|
$this->disabled = true;
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 09:00:04 +00:00
|
|
|
|
2008-09-19 04:49:38 +00:00
|
|
|
public function print_login() {
|
|
|
|
if ($this->options['ajax']) {
|
2010-09-21 08:22:04 +00:00
|
|
|
$user_field = new stdClass();
|
2008-09-19 04:49:38 +00:00
|
|
|
$user_field->label = get_string('username', 'repository_alfresco').': ';
|
|
|
|
$user_field->id = 'alfresco_username';
|
|
|
|
$user_field->type = 'text';
|
|
|
|
$user_field->name = 'al_username';
|
2009-11-01 12:51:40 +00:00
|
|
|
|
2010-09-21 08:22:04 +00:00
|
|
|
$passwd_field = new stdClass();
|
2008-09-19 04:49:38 +00:00
|
|
|
$passwd_field->label = get_string('password', 'repository_alfresco').': ';
|
|
|
|
$passwd_field->id = 'alfresco_password';
|
|
|
|
$passwd_field->type = 'password';
|
|
|
|
$passwd_field->name = 'al_password';
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
$ret['login'] = array($user_field, $passwd_field);
|
|
|
|
return $ret;
|
2009-06-08 06:25:53 +00:00
|
|
|
} else {
|
|
|
|
echo '<table>';
|
|
|
|
echo '<tr><td><label>'.get_string('username', 'repository_alfresco').'</label></td>';
|
|
|
|
echo '<td><input type="text" name="al_username" /></td></tr>';
|
|
|
|
echo '<tr><td><label>'.get_string('password', 'repository_alfresco').'</label></td>';
|
|
|
|
echo '<td><input type="password" name="al_password" /></td></tr>';
|
|
|
|
echo '</table>';
|
|
|
|
echo '<input type="submit" value="Enter" />';
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logout() {
|
|
|
|
global $SESSION;
|
2009-06-05 06:55:07 +00:00
|
|
|
unset($SESSION->{$this->sessname});
|
2008-09-19 04:49:38 +00:00
|
|
|
return $this->print_login();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function check_login() {
|
|
|
|
global $SESSION;
|
2009-06-05 06:55:07 +00:00
|
|
|
return !empty($SESSION->{$this->sessname});
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function get_url($node) {
|
|
|
|
$result = null;
|
|
|
|
if ($node->type == "{http://www.alfresco.org/model/content/1.0}content") {
|
|
|
|
$contentData = $node->cm_content;
|
|
|
|
if ($contentData != null) {
|
|
|
|
$result = $contentData->getUrl();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result = "index.php?".
|
|
|
|
"&uuid=".$node->id.
|
|
|
|
"&name=".$node->cm_name.
|
|
|
|
"&path=".'Company Home';
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2009-12-17 09:00:04 +00:00
|
|
|
/**
|
|
|
|
* Get a file list from alfresco
|
|
|
|
*
|
|
|
|
* @param string $uuid a unique id of directory in alfresco
|
|
|
|
* @param string $path path to a directory
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-02-18 06:52:54 +00:00
|
|
|
public function get_listing($uuid = '', $path = '') {
|
2009-06-30 02:12:16 +00:00
|
|
|
global $CFG, $SESSION, $OUTPUT;
|
2008-09-19 04:49:38 +00:00
|
|
|
$ret = array();
|
|
|
|
$ret['dynload'] = true;
|
|
|
|
$ret['list'] = array();
|
2009-12-17 09:00:04 +00:00
|
|
|
$server_url = $this->options['alfresco_url'];
|
2008-09-24 05:18:18 +00:00
|
|
|
$pattern = '#^(.*)api#';
|
2009-12-17 09:00:04 +00:00
|
|
|
if ($return = preg_match($pattern, $server_url, $matches)) {
|
|
|
|
$ret['manage'] = $matches[1].'faces/jsp/dashboards/container.jsp';
|
|
|
|
}
|
2008-09-24 05:18:18 +00:00
|
|
|
|
MDL-22984 using standard plugin name string for repositories
AMOS BEGIN
MOV [repositoryname,repository_alfresco],[pluginname,repository_alfresco]
MOV [repositoryname,repository_boxnet],[pluginname,repository_boxnet]
MOV [repositoryname,repository_dropbox],[pluginname,repository_dropbox]
MOV [repositoryname,repository_filesystem],[pluginname,repository_filesystem]
MOV [repositoryname,repository_flickr],[pluginname,repository_flickr]
MOV [repositoryname,repository_flickr_public],[pluginname,repository_flickr_public]
MOV [repositoryname,repository_googledocs],[pluginname,repository_googledocs]
MOV [repositoryname,repository_local],[pluginname,repository_local]
MOV [repositoryname,repository_merlot],[pluginname,repository_merlot]
MOV [repositoryname,repository_picasa],[pluginname,repository_picasa]
MOV [repositoryname,repository_recent],[pluginname,repository_recent]
MOV [repositoryname,repository_s3],[pluginname,repository_s3]
MOV [repositoryname,repository_upload],[pluginname,repository_upload]
MOV [repositoryname,repository_url],[pluginname,repository_url]
MOV [repositoryname,repository_user],[pluginname,repository_user]
MOV [repositoryname,repository_webdav],[pluginname,repository_webdav]
MOV [repositoryname,repository_wikimedia],[pluginname,repository_wikimedia]
MOV [repositoryname,repository_youtube],[pluginname,repository_youtube]
AMOS END
2010-07-04 12:52:10 +00:00
|
|
|
$ret['path'] = array(array('name'=>get_string('pluginname', 'repository_alfresco'), 'path'=>''));
|
2008-09-19 04:49:38 +00:00
|
|
|
|
2009-06-05 08:14:57 +00:00
|
|
|
try {
|
|
|
|
if (empty($uuid)) {
|
|
|
|
$this->current_node = $this->store->companyHome;
|
|
|
|
} else {
|
|
|
|
$this->current_node = $this->user_session->getNode($this->store, $uuid);
|
|
|
|
}
|
2009-12-17 09:00:04 +00:00
|
|
|
|
2009-06-05 08:14:57 +00:00
|
|
|
$folder_filter = "{http://www.alfresco.org/model/content/1.0}folder";
|
|
|
|
$file_filter = "{http://www.alfresco.org/model/content/1.0}content";
|
2009-12-17 09:00:04 +00:00
|
|
|
|
|
|
|
// top level sites folder
|
2012-07-19 13:39:06 +08:00
|
|
|
$sites_filter = "{http://www.alfresco.org/model/site/1.0}sites";
|
2009-12-17 09:00:04 +00:00
|
|
|
// individual site
|
2012-07-19 13:39:06 +08:00
|
|
|
$site_filter = "{http://www.alfresco.org/model/site/1.0}site";
|
2009-12-17 09:00:04 +00:00
|
|
|
|
2009-06-05 08:14:57 +00:00
|
|
|
foreach ($this->current_node->children as $child)
|
2008-09-19 04:49:38 +00:00
|
|
|
{
|
2009-12-17 09:00:04 +00:00
|
|
|
if ($child->child->type == $folder_filter or
|
|
|
|
$child->child->type == $sites_filter or
|
|
|
|
$child->child->type == $site_filter)
|
2009-06-05 08:14:57 +00:00
|
|
|
{
|
|
|
|
$ret['list'][] = array('title'=>$child->child->cm_name,
|
|
|
|
'path'=>$child->child->id,
|
2012-05-21 15:17:53 +08:00
|
|
|
'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
|
2009-06-05 08:14:57 +00:00
|
|
|
'children'=>array());
|
|
|
|
} elseif ($child->child->type == $file_filter) {
|
|
|
|
$ret['list'][] = array('title'=>$child->child->cm_name,
|
2012-05-21 15:17:53 +08:00
|
|
|
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->child->cm_name, 90))->out(false),
|
2009-06-05 08:14:57 +00:00
|
|
|
'source'=>$child->child->id);
|
|
|
|
}
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
2009-06-05 08:14:57 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
unset($SESSION->{$this->sessname});
|
|
|
|
$ret = $this->print_login();
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2009-12-17 09:00:04 +00:00
|
|
|
/**
|
|
|
|
* Download a file from alfresco
|
|
|
|
*
|
|
|
|
* @param string $uuid a unique id of directory in alfresco
|
|
|
|
* @param string $path path to a directory
|
|
|
|
* @return array
|
|
|
|
*/
|
2008-09-19 04:49:38 +00:00
|
|
|
public function get_file($uuid, $file = '') {
|
2009-06-05 06:55:07 +00:00
|
|
|
$node = $this->user_session->getNode($this->store, $uuid);
|
2008-09-19 04:49:38 +00:00
|
|
|
$url = $this->get_url($node);
|
2012-07-31 10:31:36 +08:00
|
|
|
return parent::get_file($url, $file);
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 10:56:30 +08:00
|
|
|
/**
|
|
|
|
* Return file URL
|
|
|
|
*
|
|
|
|
* @param string $url the url of file
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_link($uuid) {
|
|
|
|
$node = $this->user_session->getNode($this->store, $uuid);
|
|
|
|
$url = $this->get_url($node);
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2010-07-05 07:27:49 +00:00
|
|
|
public function print_search() {
|
|
|
|
$str = parent::print_search();
|
2012-11-09 11:55:24 +08:00
|
|
|
$str .= html_writer::label(get_string('space', 'repository_alfresco'), 'space', false, array('class' => 'accesshide'));
|
2012-11-05 15:06:33 +08:00
|
|
|
$str .= html_writer::empty_tag('br');
|
|
|
|
$str .= '<select id="space" name="space">';
|
2009-12-16 22:14:17 +00:00
|
|
|
foreach ($this->user_session->stores as $v) {
|
2009-04-21 05:53:35 +00:00
|
|
|
$str .= '<option ';
|
2008-09-23 01:19:27 +00:00
|
|
|
if ($v->__toString() === 'workspace://SpacesStore') {
|
2009-04-21 05:53:35 +00:00
|
|
|
$str .= 'selected ';
|
2008-09-23 01:19:27 +00:00
|
|
|
}
|
2009-04-21 05:53:35 +00:00
|
|
|
$str .= 'value="';
|
|
|
|
$str .= $v->__toString().'">';
|
|
|
|
$str .= $v->__toString();
|
|
|
|
$str .= '</option>';
|
2008-09-23 01:19:27 +00:00
|
|
|
}
|
2009-04-21 05:53:35 +00:00
|
|
|
$str .= '</select>';
|
|
|
|
return $str;
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 09:00:04 +00:00
|
|
|
/**
|
|
|
|
* Look for a file
|
|
|
|
*
|
|
|
|
* @param string $search_text
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-03-26 11:47:15 +02:00
|
|
|
public function search($search_text, $page = 0) {
|
2008-09-23 01:19:27 +00:00
|
|
|
$space = optional_param('space', 'workspace://SpacesStore', PARAM_RAW);
|
2009-12-16 22:14:17 +00:00
|
|
|
$currentStore = $this->user_session->getStoreFromString($space);
|
2009-06-05 06:55:07 +00:00
|
|
|
$nodes = $this->user_session->query($currentStore, $search_text);
|
2008-09-19 04:49:38 +00:00
|
|
|
$ret = array();
|
|
|
|
$ret['list'] = array();
|
2008-09-23 01:19:27 +00:00
|
|
|
foreach($nodes as $v) {
|
|
|
|
$ret['list'][] = array('title'=>$v->cm_name, 'source'=>$v->id);
|
|
|
|
}
|
2008-09-19 04:49:38 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2009-12-17 09:00:04 +00:00
|
|
|
/**
|
|
|
|
* Enable mulit-instance
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2008-09-19 04:49:38 +00:00
|
|
|
public static function get_instance_option_names() {
|
|
|
|
return array('alfresco_url');
|
|
|
|
}
|
|
|
|
|
2009-12-17 09:00:04 +00:00
|
|
|
/**
|
|
|
|
* define a configuration form
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2012-06-12 22:15:09 +08:00
|
|
|
public static function instance_config_form($mform) {
|
2008-12-11 03:19:46 +00:00
|
|
|
if (!class_exists('SoapClient')) {
|
2008-10-27 02:57:29 +00:00
|
|
|
$mform->addElement('static', null, get_string('notice'), get_string('soapmustbeenabled', 'repository_alfresco'));
|
2008-12-11 03:19:46 +00:00
|
|
|
return false;
|
2008-10-27 02:57:29 +00:00
|
|
|
}
|
2008-09-19 04:49:38 +00:00
|
|
|
$mform->addElement('text', 'alfresco_url', get_string('alfresco_url', 'repository_alfresco'), array('size' => '40'));
|
2009-06-08 06:36:38 +00:00
|
|
|
$mform->addElement('static', 'alfreco_url_intro', '', get_string('alfrescourltext', 'repository_alfresco'));
|
2008-09-19 04:49:38 +00:00
|
|
|
$mform->addRule('alfresco_url', get_string('required'), 'required', null, 'client');
|
2010-08-25 04:15:56 +00:00
|
|
|
return true;
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|
2009-12-17 09:00:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if SOAP extension enabled
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2008-10-27 02:57:29 +00:00
|
|
|
public static function plugin_init() {
|
|
|
|
if (!class_exists('SoapClient')) {
|
|
|
|
print_error('soapmustbeenabled', 'repository_alfresco');
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-11-02 06:45:12 +00:00
|
|
|
public function supported_returntypes() {
|
2011-02-24 10:56:30 +08:00
|
|
|
return (FILE_INTERNAL | FILE_EXTERNAL);
|
2009-11-02 06:45:12 +00:00
|
|
|
}
|
2008-09-19 04:49:38 +00:00
|
|
|
}
|