[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This plugin is used to access alfresco repository 19 * 20 * @since Moodle 2.0 21 * @package repository_alfresco 22 * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 require_once($CFG->dirroot . '/repository/lib.php'); 26 27 /** 28 * repository_alfresco class 29 * This is a class used to browse files from alfresco 30 * 31 * @since Moodle 2.0 32 * @package repository_alfresco 33 * @copyright 2009 Dongsheng Cai {@link http://dongsheng.org} 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class repository_alfresco extends repository { 37 private $ticket = null; 38 private $user_session = null; 39 private $store = null; 40 private $alfresco; 41 42 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { 43 global $SESSION, $CFG; 44 parent::__construct($repositoryid, $context, $options); 45 $this->sessname = 'alfresco_ticket_'.$this->id; 46 if (class_exists('SoapClient')) { 47 require_once($CFG->libdir . '/alfresco/Service/Repository.php'); 48 require_once($CFG->libdir . '/alfresco/Service/Session.php'); 49 require_once($CFG->libdir . '/alfresco/Service/SpacesStore.php'); 50 require_once($CFG->libdir . '/alfresco/Service/Node.php'); 51 // setup alfresco 52 $server_url = ''; 53 if (!empty($this->options['alfresco_url'])) { 54 $server_url = $this->options['alfresco_url']; 55 } else { 56 return; 57 } 58 $this->alfresco = new Alfresco_Repository($this->options['alfresco_url']); 59 $this->username = optional_param('al_username', '', PARAM_RAW); 60 $this->password = optional_param('al_password', '', PARAM_RAW); 61 try{ 62 // deal with user logging in 63 if (empty($SESSION->{$this->sessname}) && !empty($this->username) && !empty($this->password)) { 64 $this->ticket = $this->alfresco->authenticate($this->username, $this->password); 65 $SESSION->{$this->sessname} = $this->ticket; 66 } else { 67 if (!empty($SESSION->{$this->sessname})) { 68 $this->ticket = $SESSION->{$this->sessname}; 69 } 70 } 71 $this->user_session = $this->alfresco->createSession($this->ticket); 72 $this->store = new SpacesStore($this->user_session); 73 } catch (Exception $e) { 74 $this->logout(); 75 } 76 $this->current_node = null; 77 } else { 78 $this->disabled = true; 79 } 80 } 81 82 public function print_login() { 83 if ($this->options['ajax']) { 84 $user_field = new stdClass(); 85 $user_field->label = get_string('username', 'repository_alfresco').': '; 86 $user_field->id = 'alfresco_username'; 87 $user_field->type = 'text'; 88 $user_field->name = 'al_username'; 89 90 $passwd_field = new stdClass(); 91 $passwd_field->label = get_string('password', 'repository_alfresco').': '; 92 $passwd_field->id = 'alfresco_password'; 93 $passwd_field->type = 'password'; 94 $passwd_field->name = 'al_password'; 95 96 $ret = array(); 97 $ret['login'] = array($user_field, $passwd_field); 98 return $ret; 99 } else { 100 echo '<table>'; 101 echo '<tr><td><label>'.get_string('username', 'repository_alfresco').'</label></td>'; 102 echo '<td><input type="text" name="al_username" /></td></tr>'; 103 echo '<tr><td><label>'.get_string('password', 'repository_alfresco').'</label></td>'; 104 echo '<td><input type="password" name="al_password" /></td></tr>'; 105 echo '</table>'; 106 echo '<input type="submit" value="Enter" />'; 107 } 108 } 109 110 public function logout() { 111 global $SESSION; 112 unset($SESSION->{$this->sessname}); 113 return $this->print_login(); 114 } 115 116 public function check_login() { 117 global $SESSION; 118 return !empty($SESSION->{$this->sessname}); 119 } 120 121 private function get_url($node) { 122 $result = null; 123 if ($node->type == "{http://www.alfresco.org/model/content/1.0}content") { 124 $contentData = $node->cm_content; 125 if ($contentData != null) { 126 $result = $contentData->getUrl(); 127 } 128 } else { 129 $result = "index.php?". 130 "&uuid=".$node->id. 131 "&name=".$node->cm_name. 132 "&path=".'Company Home'; 133 } 134 return $result; 135 } 136 137 /** 138 * Get a file list from alfresco 139 * 140 * @param string $uuid a unique id of directory in alfresco 141 * @param string $path path to a directory 142 * @return array 143 */ 144 public function get_listing($uuid = '', $path = '') { 145 global $CFG, $SESSION, $OUTPUT; 146 $ret = array(); 147 $ret['dynload'] = true; 148 $ret['list'] = array(); 149 $server_url = $this->options['alfresco_url']; 150 $pattern = '#^(.*)api#'; 151 if ($return = preg_match($pattern, $server_url, $matches)) { 152 $ret['manage'] = $matches[1].'faces/jsp/dashboards/container.jsp'; 153 } 154 155 $ret['path'] = array(array('name'=>get_string('pluginname', 'repository_alfresco'), 'path'=>'')); 156 157 try { 158 if (empty($uuid)) { 159 $this->current_node = $this->store->companyHome; 160 } else { 161 $this->current_node = $this->user_session->getNode($this->store, $uuid); 162 } 163 164 $folder_filter = "{http://www.alfresco.org/model/content/1.0}folder"; 165 $file_filter = "{http://www.alfresco.org/model/content/1.0}content"; 166 167 // top level sites folder 168 $sites_filter = "{http://www.alfresco.org/model/site/1.0}sites"; 169 // individual site 170 $site_filter = "{http://www.alfresco.org/model/site/1.0}site"; 171 172 foreach ($this->current_node->children as $child) 173 { 174 if ($child->child->type == $folder_filter or 175 $child->child->type == $sites_filter or 176 $child->child->type == $site_filter) 177 { 178 $ret['list'][] = array('title'=>$child->child->cm_name, 179 'path'=>$child->child->id, 180 'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false), 181 'children'=>array()); 182 } elseif ($child->child->type == $file_filter) { 183 $ret['list'][] = array('title'=>$child->child->cm_name, 184 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($child->child->cm_name, 90))->out(false), 185 'source'=>$child->child->id); 186 } 187 } 188 } catch (Exception $e) { 189 unset($SESSION->{$this->sessname}); 190 $ret = $this->print_login(); 191 } 192 return $ret; 193 } 194 195 /** 196 * Download a file from alfresco 197 * 198 * @param string $uuid a unique id of directory in alfresco 199 * @param string $path path to a directory 200 * @return array 201 */ 202 public function get_file($uuid, $file = '') { 203 $node = $this->user_session->getNode($this->store, $uuid); 204 $url = $this->get_url($node); 205 return parent::get_file($url, $file); 206 } 207 208 public function print_search() { 209 $str = parent::print_search(); 210 $str .= html_writer::label(get_string('space', 'repository_alfresco'), 211 'repository_alfresco_space', 212 false, 213 array('class' => 'accesshide')); 214 $str .= '<select id="repository_alfresco_space" class="alfresco-workplace" name="space">'; 215 foreach ($this->user_session->stores as $v) { 216 $str .= '<option '; 217 if ($v->__toString() === 'workspace://SpacesStore') { 218 $str .= 'selected '; 219 } 220 $str .= 'value="'; 221 $str .= $v->__toString().'">'; 222 $str .= $v->__toString(); 223 $str .= '</option>'; 224 } 225 $str .= '</select>'; 226 return $str; 227 } 228 229 /** 230 * Look for a file 231 * 232 * @param string $search_text 233 * @return array 234 */ 235 public function search($search_text, $page = 0) { 236 $space = optional_param('space', 'workspace://SpacesStore', PARAM_RAW); 237 $currentStore = $this->user_session->getStoreFromString($space); 238 $nodes = $this->user_session->query($currentStore, $search_text); 239 $ret = array(); 240 $ret['list'] = array(); 241 foreach($nodes as $v) { 242 $ret['list'][] = array('title'=>$v->cm_name, 'source'=>$v->id); 243 } 244 return $ret; 245 } 246 247 /** 248 * Enable mulit-instance 249 * 250 * @return array 251 */ 252 public static function get_instance_option_names() { 253 return array('alfresco_url'); 254 } 255 256 /** 257 * define a configuration form 258 * 259 * @return bool 260 */ 261 public static function instance_config_form($mform) { 262 if (!class_exists('SoapClient')) { 263 $mform->addElement('static', null, get_string('notice'), get_string('soapmustbeenabled', 'repository_alfresco')); 264 return false; 265 } 266 $mform->addElement('text', 'alfresco_url', get_string('alfresco_url', 'repository_alfresco'), array('size' => '40')); 267 $mform->setType('alfresco_url', PARAM_URL); 268 $mform->addElement('static', 'alfreco_url_intro', '', get_string('alfrescourltext', 'repository_alfresco')); 269 $mform->addRule('alfresco_url', get_string('required'), 'required', null, 'client'); 270 return true; 271 } 272 273 /** 274 * Check if SOAP extension enabled 275 * 276 * @return bool 277 */ 278 public static function plugin_init() { 279 if (!class_exists('SoapClient')) { 280 print_error('soapmustbeenabled', 'repository_alfresco'); 281 return false; 282 } else { 283 return true; 284 } 285 } 286 public function supported_returntypes() { 287 return FILE_INTERNAL; 288 } 289 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |