diff -Naur -X pattern.txt moodle_original/blocks/referencement/block_referencement.php www\moodle/blocks/referencement/block_referencement.php --- moodle_original/blocks/referencement/block_referencement.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/blocks/referencement/block_referencement.php 2010-06-14 09:51:11.437500000 +0200 @@ -0,0 +1,57 @@ +title = get_string('title','block_referencement'); + $this->version = 2010021100; + } + + function get_content() { + global $CFG; + global $USER; + require_once($CFG->dirroot.'/auth/cas/CAS/CAS.php'); + if ($this->content !== NULL) { + return $this->content; + } + + $this->content = new object(); + + //link to the sheet list + $this->content->text = '' + .get_string('workflow','block_referencement').''; + + //link to the ori-search portal + $this->content->text .= '
' + .get_string('orisearch','block_referencement').''; + + + $this->content->footer = ''; + return $this->content; + } + + function has_config() { + return true; + } + + function specialization() { + global $CFG; + + //default values - makes empty values impossible, and send to oai-ori homesite. + if( empty($CFG->block_referencement_workflow_url) ) + $CFG->block_referencement_workflow_url = 'http://www.ori-oai.org/display/ORIOAIworkflow/Version+1.5'; + + if( empty($CFG->block_referencement_orioaisearch_url) ) + $CFG->block_referencement_orioaisearch_url = 'http://www.ori-oai.org/display/ORIOAIsearch/Version+1.5'; + } +} + +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/blocks/referencement/settings.php www\moodle/blocks/referencement/settings.php --- moodle_original/blocks/referencement/settings.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/blocks/referencement/settings.php 2010-06-16 10:20:58.708368600 +0200 @@ -0,0 +1,66 @@ +add(new admin_setting_configtext('block_referencement_workflow_url', + 'WorkFlow URL', + get_string('workflowdesc','block_referencement'), + 'http://www.ori-oai.org/display/ORIOAIworkflow/Version+1.5',PARAM_URL, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_workflow_soapwsdl', + 'WorkFlow WSDL location', + get_string('workflowwsdl','block_referencement'), + '/xfire/OriWorkflowService?WSDL',PARAM_URL, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_orioaisearch_url', + 'ORI-search URL', + get_string('orisearchdesc','block_referencement'), + 'http://www.ori-oai.org/display/ORIOAIsearch/Version+1.5',PARAM_URL, '80%' )); + + +$settings->add(new admin_setting_configtext('block_referencement_orioaisearch_callbackparam', + 'ORI-search callback parameter name', + get_string('orisearchparam','block_referencement'), + 'service',PARAM_ALPHA, '80%' )); + + +$settings->add(new admin_setting_configtext('block_referencement_host', + 'Repository host URL', + get_string('hostdesc','block_referencement'), + 'cmis.demo.nuxeo.org',PARAM_HOST, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_port', + 'Repository access port', + get_string('portdesc','block_referencement'), + '80',PARAM_INT, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_site', + 'Repository site uri', + get_string('sitedesc','block_referencement'), + '/nuxeo',PARAM_PATH, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_accesspoint', + 'Repository access point', + get_string('accesspointdesc','block_referencement'), + '/site/cmis/repository',PARAM_PATH, '80%' )); + + +$settings->add(new admin_setting_configtext('block_referencement_relativeremotepath', + 'Relative remote path', + get_string('relativeremotedesc','block_referencement'), + '/default-domain/workspaces/%u/cours/',PARAM_PATH, '80%' )); + +$settings->add(new admin_setting_configtext('block_referencement_universalurl', + 'Universal link uri', + get_string('universallinkdesc','block_referencement'), + '/site/esupversions/',PARAM_PATH, '80%' )); + +$settings->add(new admin_setting_configcheckbox('block_referencement_allowonfiledeposit', + 'Allow Referencement on file deposit', + get_string('allowonfiledeposit', 'block_referencement'), 0)); + + +$settings->add(new admin_setting_configcheckbox('block_referencement_allowonorisearch', + 'Allow Using referenced resources', + get_string('alloworisearch', 'block_referencement'), 0)); + + +?> diff -Naur -X pattern.txt moodle_original/files/index.php www\moodle/files/index.php --- moodle_original/files/index.php 2009-09-29 08:05:58.000000000 +0200 +++ www\moodle/files/index.php 2010-06-14 09:51:11.218750000 +0200 @@ -22,6 +22,7 @@ $save = optional_param('save', 0, PARAM_BOOL); $text = optional_param('text', '', PARAM_RAW); $confirm = optional_param('confirm', 0, PARAM_BOOL); + $doreference = optional_param('doreference', 0, PARAM_BOOL); if ($choose) { if (count(explode('.', $choose)) > 2) { @@ -199,10 +200,18 @@ require_once($CFG->dirroot.'/lib/uploadlib.php'); if ($save and confirm_sesskey()) { - $course->maxbytes = 0; // We are ignoring course limits + $course->maxbytes = 0; // We are ignoring course limits $um = new upload_manager('userfile',false,false,$course,false,0); $dir = "$basedir$wdir"; if ($um->process_file_uploads($dir)) { + if($doreference){ + $url = $CFG->wwwroot.'/lib/repository/depositandreferencement.php'; + $url .= '?resourcereference='.urlencode($um->files['userfile']['fullpath']); + echo ''; + } notify(get_string('uploadedfile')); } // um will take care of error reporting. @@ -226,6 +235,10 @@ echo " "; echo " sesskey\" />"; upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false); + if($CFG->block_referencement_allowonfiledeposit){ + echo " "; + echo " ".get_string('doreference', 'resource'); + } echo " "; echo " "; echo ""; diff -Naur -X pattern.txt moodle_original/lib/repository/cmis.php www\moodle/lib/repository/cmis.php --- moodle_original/lib/repository/cmis.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/cmis.php 2010-07-13 10:02:04.593750000 +0200 @@ -0,0 +1,246 @@ +libdir.'/filelib.php'); + +function makecookiefromcasticket(){ + + global $CFG; + //get configuration for CAS + $casconfig = get_config('auth/cas'); + if($casconfig == NULL || $casconfig->proxycas != 1){ + error(get_string('notcasproxy','referencement')); + } + //construct url to connect + $host = $CFG->block_referencement_host; + $port = $CFG->block_referencement_port; + $siteuri = $CFG->block_referencement_site; + $accesspoint = $CFG->block_referencement_accesspoint; + $baseURL = 'http://'.str_replace('//','/',$host.":".$port.'/'.$siteuri.'/'.$accesspoint); + //create CAS proxy + $CAS = new CASClient($casconfig->version,TRUE,$casconfig->hostname,(Integer)$casconfig->port,$casconfig->baseuri); + $CAS->setNoCasServerValidation(); + $CAS->forceAuthentication(); + //get a ticket + if($CAS->hasPGT()){ + $err_code = 0; + $output = ''; + $casticket = $CAS->retrievePT($baseURL,$err_code,$output); + if($err_code==3) + { + error(get_string('pgtexpired','referencement')); + } + } + else + { + error(get_string('notcasproxy','referencement')); + } + if(empty($casticket)){ + error("unable to get CAS ticket"); + } + + + //add ticket to the url + $request = $baseURL.'?ticket='.$casticket; + //add service to the url + $request .= '&service='.$baseURL; + + + $ch = curl_init($request); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HTTPGET, true); + curl_setopt($ch, CURLOPT_HEADER, true); + + $result = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if($code != 200){ + return NULL; + } + + $matches = array(); + preg_match("#Set-Cookie:(.+);#i",$result,$matches); + if(empty($matches[1])) + { + return NULL; + } + $cookie = $matches[1]; + + return $cookie; +} + + +class CMISRepositoryClient { + protected $host,$port,$siteuri,$accesspoint; + protected $baseURL; + protected $client; + public $authenticated; + + function CMISRepositoryClient($login, $password,$host,$port, $siteuri,$accesspoint) + { + if($port == 0){ + $port = 80; + } + $this->login = $login; + $this->password = $password; + + $this->host = $host; + $this->port = $port; + $this->siteuri = $siteuri; + $this->accesspoint = $accesspoint; + + //construct URL + $this->baseURL = 'http://'.str_replace('//','/',$this->host.":".$this->port.'/'.$this->siteuri.'/'.$this->accesspoint); + try{ + $this->client =& new CMISService($this->baseURL,$login,$password,NULL,'CMISREPOSITORY'.md5($login),'makecookiefromcasticket'); + }catch(Exception $e){ + error(get_string('cmisclienterror','referencement')); + } + $this->authenticated = $this->client->authenticated; + } + + //return file id + function uploadfile($relativeremotepath,$absolutelocalpath,$filename,$override=false,$newversion=false) + { + global $CFG; + //for conveniance, add a slash at the end of the remote path + if($relativeremotepath[strlen($relativeremotepath)-1] != '/') + { + $relativeremotepath.='/'; + } + $lowerrelativeremotepath = strtolower($relativeremotepath); + + //check if a same-named file already exists + $file = $this->client->getObjectByPath($relativeremotepath.$filename); + if($file === 0){ + error('bad login or server unavaible'); + } + if(empty($file->id)){ + //test with lowercase remotepath + $file = $this->client->getObjectByPath($lowerrelativeremotepath.$filename); + } + + if(!empty($file->id)){ + if($override==false) + { + //ask user for wath to do. + $this->existingfile($filename); + } + else + { + //delete the existing file,and continue + $this->client->deleteObject($file->id); + } + } + + //check if the remote directory exists, if not: try to create it + $folder = $this->client->getObjectByPath($relativeremotepath); + $folderId = $folder->id; + if(empty($folder->id)) + { + //test with lowcase + $folder = $this->client->getObjectByPath($lowerrelativeremotepath); + $folderId = $folder->id; + if(empty($folder->id)){ + $folderId = $this->createfolder($relativeremotepath); + } + } + + if(empty($folderId)){ + error(get_string('remotefoldererror','referencement')); + } + + //get the mime type of the file + $mimetype = mimeinfo('type', $filename); + + //get the file's contents + $ffile = fopen($absolutelocalpath,'r'); + $content = stream_get_contents($ffile); + fclose($ffile); + if($content == false) + { + error(get_string('cannotreadfile','error',$absolutelocalpath)); + } + + //upload + $file = $this->client->createDocument($folderId,$filename,array(),$content,$mimetype); + if($file == false){ + error(get_string('cannotcreatedocument','referencement',$relativeremotepath)); + } + + if($file == false) + { + error(get_string('cannotuploadfile','error',$absolutelocalpath)); + } + + + return $file->id; + } + + function createfolder($relativeremotepath) + { + + $root = $this->client->getObjectByPath('/'); + $folds = explode('/',$relativeremotepath); + $lastid = $root->id; + $lastfold = ''; + foreach($folds as $f) + { + if(empty($f)) continue; + + $lastfold .= '/'.$f; + $tmp = $this->client->getObjectByPath($lastfold); + if(empty($tmp->id)) + { + $tmp = $this->client->createFolder($lastid,$f); + } + $lastid = $tmp->id; + if(empty($lastid)){ + return null; + } + } + return $lastid; + } + + function existingfile($filename) + { + global $CFG; + $fileext= substr($filename,strrpos($filename,'.')); + $filename = substr($filename,0,strrpos($filename,'.')); + $mform = new MoodleQuickForm('existingfile','POST',''); + $mform->addElement('header', 'existingfilehead', get_string('advertise', 'referencement')); + $mform->addElement('radio','groupaction','',get_string('replace','referencement'),'replace'); + $newnamegroup = array(); + $newnamegroup[] = $mform->createElement('radio','groupaction',null,get_string('createNew','referencement'),'createNew'); + $newnamegroup[] = $mform->createElement('text','newname','','value="'.$filename.'"'); + $newnamegroup[] = $mform->createElement('static','fileext','',$fileext); + $mform->addGroup($newnamegroup); + $mform->addElement('radio','groupaction','',get_string('nothing','referencement'),'nothing'); + $mform->addElement('submit', 'validatebutton',get_string('validate','referencement')); + $mform->addElement('hidden','fileext',$fileext); + $mform->setDefault('groupaction', 'nothing'); + foreach($_POST as $k=>$v) + { + if($k == 'newname' || $k == 'groupaction' || $k == 'validatebutton') continue; + if(is_array($v)) + { + foreach($v as $key=>$val){ + $mform->addElement('hidden',$k.'['.$key.']',$val); + } + }else{ + $mform->addElement('hidden',$k,$v); + } + } + print_header(); + $mform->display(); + print_footer();die; + } + + +} + + + +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/lib/repository/cmis_repository_wrapper.php www\moodle/lib/repository/cmis_repository_wrapper.php --- moodle_original/lib/repository/cmis_repository_wrapper.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/cmis_repository_wrapper.php 2010-07-12 16:54:00.187500000 +0200 @@ -0,0 +1,999 @@ + "http://docs.oasis-open.org/ns/cmis/core/200908/", + "cmisra" => "http://docs.oasis-open.org/ns/cmis/restatom/200908/", + "atom" => "http://www.w3.org/2005/Atom", + "app" => "http://www.w3.org/2007/app", + ); + + function __construct($url,$username=null,$password=null,$options=null,$cookiename=null,$retrieveCookie=null) { + try{ + $this->connect($url,$username,$password,$options,$cookiename,$retrieveCookie); + }catch(Exception $e){ + throw $e; + } + } + + static function getOpUrl($url,$options=null) { + if (is_array($options) && (count($options) > 0)) { + $needs_question=strstr($url,"?") === false; + return $url . ($needs_question?"?":"&") . http_build_query($options); + } else { + return $url; + } + } + + /** + * connect to the cmis end point + * if $cookiename != null, username and password will not be used + * + */ + function connect($url,$username,$password,$options,$cookiename,$retrieveCookie) { + // TODO: Make this work with cookies + $this->url = $url; + $this->username = $username; + $this->password = $password; + $this->cookiename = $cookiename; + $this->retrieveCookie = $retrieveCookie; + $this->auth_options=$options; + $this->authenticated = false; + try{ + $retval=$this->doGet($this->url); + }catch(Exception $e){ + throw $e; + } + if ($retval->code == 200 || $retval->code == 201) { + $this->authenticated=true; + $this->workspace = CMISRepositoryWrapper::extractWorkspace($retval->body); + } + } + + function doGet($url) { + try{ + return $this->doRequest($url); + }catch(Exception $e){ + throw $e; + } + } + + function doDelete($url) { + return $this->doRequest($url,"DELETE"); + } + + function doPost($url,$content,$contentType,$charset=null) { + $ret= $this->doRequest($url,"POST",$content,$contentType); + return $ret; + } + + function doPut($url,$content,$contentType,$charset=null) { + return $this->doRequest($url,"PUT",$content,$contentType); + } + + function doRequest($url,$method="GET",$content=null,$contentType=null,$charset=null,$secondtry=false) { + // Process the HTTP request + // 'til now only the GET request has been tested + // Does not URL encode any inputs yet + if (is_array($this->auth_options)) { + $url=CMISRepositoryWrapper::getOpUrl($url,$this->auth_options); + } + $session = curl_init($url); + curl_setopt($session,CURLOPT_HEADER,false); + curl_setopt($session,CURLOPT_RETURNTRANSFER,true); + curl_setopt($session,CURLOPT_FOLLOWLOCATION,true); + //cookie-mode + if($this->cookiename){ + //check if a cookie exists with the given name, and if it's the first try + if(!empty($_COOKIE[$this->cookiename]) && !$secondtry) + { + $this->cookie = $_COOKIE[$this->cookiename]; + } + else //no cookie, or second try : get a new cookie and store it + { + if(empty($this->cookie)){ + //call the external function to get the cookie + $this->cookie = call_user_func($this->retrieveCookie); + if($this->cookie == NULL){ + throw new Exception("Unable to get cookie for CMIS connection"); + } + //write the cookie + setcookie($this->cookiename,$this->cookie,0,'/'); + } + } + curl_setopt($session,CURLOPT_COOKIE,$this->cookie); + } + //user/password - mode + elseif ($this->username) { + curl_setopt($session,CURLOPT_USERPWD,$this->username . ":" . $this->password); + } + curl_setopt($session,CURLOPT_CUSTOMREQUEST,$method); + if ($contentType) { + $headers=array(); + $headers["Content-Type"]=$contentType; + curl_setopt($session,CURLOPT_HTTPHEADER, $headers); + } + if ($content) { + curl_setopt($session,CURLOPT_POSTFIELDS, $content); + } + if ($method == "POST") { + curl_setopt($session, CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType)); + curl_setopt($session,CURLOPT_POST,true); + } + //TODO: Make this storage optional + $retval = new stdClass(); + $retval->url=$url; + $retval->method=$method; + $retval->content_sent=$content; + $retval->content_type_sent=$contentType; + $retval->body=curl_exec($session); + $retval->code = curl_getinfo($session,CURLINFO_HTTP_CODE); + $retval->content_type=curl_getinfo($session,CURLINFO_CONTENT_TYPE); + $retval->content_length=curl_getinfo($session,CURLINFO_CONTENT_LENGTH_DOWNLOAD); + curl_close($session); + $this->last_request=$retval; + //Unauthorized request + if($retval->code ==401 || $retval->code==500){ + if($secondtry){ + //second try already made : abord request + return NULL; + } + //make a second try with a new cookie + else{ + //unset the curent cookie; + $this->cookie = NULL; + @setcookie($this->cookiename,''); + //second try + return $this->doRequest($url,$method,$content,$contentType,$charset,true); + } + } + return $retval; + } + + function getLastRequest() { + return $this->last_request; + } + + function getLastRequestBody() { + return $this->last_request->body; + } + + function getLastRequestCode() { + return $this->last_request->code; + } + + function getLastRequestContentType() { + return $this->last_request->content_type; + } + + function getLastRequestContentLength() { + return $this->last_request->content_length; + } + + function getLastRequestURL() { + return $this->last_request->url; + } + + function getLastRequestMethod() { + return $this->last_request->method; + } + + function getLastRequestContentTypeSent() { + return $this->last_request->content_type_sent; + } + + function getLastRequestContentSent() { + return $this->last_request->content_sent; + } + + // Static Utility Functions + static function processTemplate($template,$values=array()) { + // Fill in the blanks -- + $retval=$template; + if (is_array($values)) { + foreach ($values as $name => $value) { + $retval = str_replace("{" . $name . "}",$value,$retval); + } + } + // Fill in any unpoupated variables with "" + return preg_replace("/{[a-zA-Z0-9_]+}/","",$retval); + + } + + static function doXQuery($xmldata,$xquery) { + $doc=new DOMDocument(); + $doc->loadXML($xmldata); + return CMISRepositoryWrapper::doXQueryFromNode($doc,$xquery); + } + + static function doXQueryFromNode($xmlnode,$xquery) { + // Perform an XQUERY on a NODE + // Register the 4 CMIS namespaces + $xpath=new DomXPath($xmlnode); + foreach (CMISRepositoryWrapper::$namespaces as $nspre => $nsuri) { + $xpath->registerNamespace($nspre,$nsuri); + } + return $xpath->query($xquery); + + } + static function getLinksArray($xmlnode) { + // Gets the links of an object or a workspace + // Distinguishes between the two "down" links + // -- the children link is put into the associative array with the "down" index + // -- the descendants link is put into the associative array with the "down-tree" index + // These links are distinquished by the mime type attribute, but these are probably the only two links that share the same rel .. + // so this was done as a one off + $links = array(); + $link_nodes = $xmlnode->getElementsByTagName("link"); + foreach ($link_nodes as $ln) { + if ($ln->attributes->getNamedItem("rel")->nodeValue == "down" && $ln->attributes->getNamedItem("type")->nodeValue == "application/cmistree+xml") { + //Descendents and Childredn share same "rel" but different document type + $links["down-tree"] = $ln->attributes->getNamedItem("href")->nodeValue; + } else { + $links[$ln->attributes->getNamedItem("rel")->nodeValue] = $ln->attributes->getNamedItem("href")->nodeValue; + } + } + return $links; + } + static function extractObject($xmldata) { + $doc=new DOMDocument(); + $doc->loadXML($xmldata); + return CMISRepositoryWrapper::extractObjectFromNode($doc); + + } + static function extractObjectFromNode($xmlnode) { + // Extracts the contents of an Object and organizes them into: + // -- Links + // -- Properties + // -- the Object ID + // RRM -- NEED TO ADD ALLOWABLEACTIONS + $retval = new stdClass(); + $retval->links=CMISRepositoryWrapper::getLinksArray($xmlnode); + $retval->properties=array(); + $prop_nodes = $xmlnode->getElementsByTagName("object")->item(0)->getElementsByTagName("properties")->item(0)->childNodes; + foreach ($prop_nodes as $pn) { + if ($pn->attributes) { + $retval->properties[$pn->attributes->getNamedItem("propertyDefinitionId")->nodeValue] = @$pn->getElementsByTagName("value")->item(0)->nodeValue; + } + } + $retval->uuid=$xmlnode->getElementsByTagName("id")->item(0)->nodeValue; + $retval->id=$retval->properties["cmis:objectId"]; + return $retval; + } + + static function extractTypeDef($xmldata) { + $doc=new DOMDocument(); + $doc->loadXML($xmldata); + return CMISRepositoryWrapper::extractTypeDefFromNode($doc); + + } + static function extractTypeDefFromNode($xmlnode) { + // Extracts the contents of an Object and organizes them into: + // -- Links + // -- Properties + // -- the Object ID + // RRM -- NEED TO ADD ALLOWABLEACTIONS + $retval = new stdClass(); + $retval->links=CMISRepositoryWrapper::getLinksArray($xmlnode); + $retval->properties=array(); + $retval->attributes=array(); + $result = CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//cmisra:type/*"); + foreach ($result as $node) { + if ((substr($node->nodeName,0,13) == "cmis:property") && (substr($node->nodeName,-10) == "Definition")){ + $id=$node->getElementsByTagName("id")->item(0)->nodeValue; + $cardinality=$node->getElementsByTagName("cardinality")->item(0)->nodeValue; + $propertyType=$node->getElementsByTagName("propertyType")->item(0)->nodeValue; + // Stop Gap for now + $retval->properties[$id]= array( + "cmis:propertyType" =>$propertyType, + "cmis:cardinality" =>$cardinality, + ); + } else { + $retval->attributes[$node->nodeName]= $node->nodeValue; + } + $retval->id=$retval->attributes["cmis:id"]; + } + +/* + * + + + + $prop_nodes = $xmlnode->getElementsByTagName("object")->item(0)->getElementsByTagName("properties")->item(0)->childNodes; + foreach ($prop_nodes as $pn) { + if ($pn->attributes) { + $retval->properties[$pn->attributes->getNamedItem("propertyDefinitionId")->nodeValue] = $pn->getElementsByTagName("value")->item(0)->nodeValue; + } + } + $retval->uuid=$xmlnode->getElementsByTagName("id")->item(0)->nodeValue; + $retval->id=$retval->properties["cmis:objectId"]; + */ + return $retval; + } + + static function extractObjectFeed($xmldata) { + //Assumes only one workspace for now + $doc=new DOMDocument(); + $doc->loadXML($xmldata); + return CMISRepositoryWrapper::extractObjectFeedFromNode($doc); + } + static function extractObjectFeedFromNode($xmlnode) { + // Process a feed and extract the objects + // Does not handle hierarchy + // Provides two arrays + // -- one sequential array (a list) + // -- one hash table indexed by objectID + $retval = new stdClass(); + $retval->objectList=array(); + $retval->objectsById=array(); + $result = CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//atom:entry"); + foreach ($result as $node) { + $obj = CMISRepositoryWrapper::extractObjectFromNode($node); + $retval->objectsById[$obj->id]=$obj; + $retval->objectList[]=&$retval->objectsById[$obj->id]; + } + return $retval; + } + + static function extractWorkspace($xmldata) { + //Assumes only one workspace for now + $doc=new DOMDocument(); + $doc->loadXML($xmldata); + return CMISRepositoryWrapper::extractWorkspaceFromNode($doc); + } + static function extractWorkspaceFromNode($xmlnode) { + // Assumes only one workspace for now + // Load up the workspace object with arrays of + // links + // URI Templates + // Collections + // Capabilities + // General Repository Information + $retval = new stdClass(); + $retval->links=CMISRepositoryWrapper::getLinksArray($xmlnode); + $retval->uritemplates=array(); + $retval->collections=array(); + $retval->capabilities=array(); + $retval->repositoryInfo=array(); + $result= CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//cmisra:uritemplate"); + foreach ($result as $node) { + $retval->uritemplates[$node->getElementsByTagName("type")->item(0)->nodeValue] = + $node->getElementsByTagName("template")->item(0)->nodeValue; + } + $result= CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//app:collection"); + foreach ($result as $node) { + $retval->collections[$node->getElementsByTagName("collectionType")->item(0)->nodeValue] = + $node->attributes->getNamedItem("href")->nodeValue; + } + $result = CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//cmis:capabilities/*"); + foreach ($result as $node) { + $retval->capabilities[$node->nodeName]= $node->nodeValue; + } + $result = CMISRepositoryWrapper::doXQueryFromNode($xmlnode,"//cmisra:repositoryInfo/*"); + foreach ($result as $node) { + if ($node->nodeName != "cmis:capabilities") { + $retval->repositoryInfo[$node->nodeName]= $node->nodeValue; + } + } + + return $retval; + } +} + +// Option Contants for Array Indexing +// -- Generally optional flags that control how much information is returned +// -- Change log token is an anomoly -- but included in URL as parameter +define("OPT_MAX_ITEMS","maxItems"); +define("OPT_SKIP_COUNT","skipCount"); +define("OPT_FILTER","filter"); +define("OPT_INCLUDE_PROPERTY_DEFINITIONS","includePropertyDefinitions"); +define("OPT_INCLUDE_RELATIONSHIPS","includeRelationships"); +define("OPT_INCLUDE_POLICY_IDS","includePolicyIds"); +define("OPT_RENDITION_FILTER","renditionFilter"); +define("OPT_INCLUDE_ACL","includeACL"); +define("OPT_INCLUDE_ALLOWABLE_ACTIONS","includeAllowableActions"); +define("OPT_DEPTH","depth"); +define("OPT_CHANGE_LOG_TOKEN","changeLogToken"); + +define("LINK_ALLOWABLE_ACTIONS","http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions"); + +define("MIME_ATOM_XML",'application/atom+xml'); +define("MIME_ATOM_XML_ENTRY",'application/atom+xml;type=entry'); +define("MIME_ATOM_XML_FEED",'application/atom+xml;type=feed'); +define("MIME_CMIS_TREE",'application/cmistree+xml'); +define("MIME_CMIS_QUERY",'application/cmisquery+xml'); + + +// Many Links have a pattern to them based upon objectId -- but can that be depended upon? + +class CMISService extends CMISRepositoryWrapper { + var $_link_cache; + + /* + * constructor function. + * if $cookiename is not null, username and password will not be used + * + * $retrieveCookie must be a fonction that RETURN the cookie, and DO NOT write it + */ + function __construct($url,$username,$password,$options=null,$cookiename=null,$retrieveCookie=null) { + parent::__construct($url,$username,$password,$options,$cookiename,$retrieveCookie); + $this->_link_cache=array(); + $this->_title_cache=array(); + $this->_objTypeId_cache=array(); + $this->_type_cache=array(); + } + + // Utility Methods -- Added Titles + // Should refactor to allow for single object + function cacheEntryInfo($obj) { + $this->_link_cache[$obj->id]=$obj->links; + $this->_title_cache[$obj->id]=$obj->properties["cmis:name"]; // Broad Assumption Here? + $this->_objTypeId_cache[$obj->id]=$obj->properties["cmis:objectTypeId"]; + } + + function cacheFeedInfo ($objs) { + foreach ($objs->objectList as $obj) { + $this->cacheEntryInfo($obj); + } + } + + function cacheTypeInfo ($tDef) { + $this->_type_cache[$tDef->id] = $tDef; + } + + function getPropertyType($typeId,$propertyId) { + if ($this->_type_cache[$typeId]) { + return $this->_type_cache[$typeId]->properties[$propertyId]["cmis:propertyType"]; + } + $obj=$this->getTypeDefinition($typeId); + return $obj->properties[$propertyId]["cmis:propertyType"]; + } + + function getObjectType($objectId) { + if ($this->_objTypeId_cache[$objectId]) { + return $this->_objTypeId_cache[$objectId]; + } + $obj=$this->getObject($objectId); + return $obj->properties["cmis:objectTypeId"]; + } + + function getTitle($objectId) { + if ($this->_title_cache[$objectId]) { + return $this->_title_cache[$objectId]; + } + $obj=$this->getObject($objectId); + return $obj->properties["cmis:name"]; + } + function getLink($objectId,$linkName) { + if ($this->_link_cache[$objectId][$linkName]) { + return $this->_link_cache[$objectId][$linkName]; + } + $obj=$this->getObject($objectId); + return $obj->links[$linkName]; + } + + // Repository Services + function getRepositories() { + throw Exception("Not Implemented"); + } + + function getRepositoryInfo() { + return $this->workspace; + } + + function getTypeChildren() { + throw Exception("Not Implemented"); + } + + function getTypeDescendants() { + throw Exception("Not Implemented"); + } + + function getTypeDefinition($typeId,$options=array()) { // Nice to have + $varmap=$options; + $varmap["id"]=$typeId; + $myURL = $this->processTemplate($this->workspace->uritemplates['typebyid'],$varmap); + $ret=$this->doGet($myURL); + $obj=$this->extractTypeDef($ret->body); + $this->cacheTypeInfo($obj); + return $obj; + } + + function getObjectTypeDefinition($objectId) { // Nice to have + $myURL = $this->getLink($objectId,"describedby"); + $ret=$this->doGet($myURL); + $obj=$this->extractTypeDef($ret->body); + $this->cacheTypeInfo($obj); + return $obj; + } + //Navigation Services + function getFolderTree() { // Would Be Useful + throw Exception("Not Implemented"); + } + + function getDescendants() { // Nice to have + throw Exception("Not Implemented"); + } + + function getChildren($objectId,$options=array()) { + $myURL = $this->getLink($objectId,"down"); + //TODO: Need GenURLQueryString Utility + $ret=$this->doGet($myURL); + $objs=$this->extractObjectFeed($ret->body); + $this->cacheFeedInfo($objs); + return $objs; + } + + function getFolderParent($objectId,$options=array()) { //yes + $myURL = $this->getLink($objectId,"up"); + //TODO: Need GenURLQueryString Utility + $ret=$this->doGet($myURL); + $obj=$this->extractObjectEntry($ret->body); + $this->cacheEntryInfo($obj); + return $obj; + } + + function getObjectParents($objectId,$options=array()) { // yes + $myURL = $this->getLink($objectId,"up"); + //TODO: Need GenURLQueryString Utility + $ret=$this->doGet($myURL); + $objs=$this->extractObjectFeed($ret->body); + $this->cacheFeedInfo($objs); + return $objs; + } + + function getCheckedOutDocs($options=array()) { + $obj_url = $this->workspace->collections['checkedout']; + $ret = $this->doGet($obj_url); + $objs=$this->extractObjectFeed($ret->body); + $this->cacheFeedInfo($objs); + return $objs; + } + + //Discovery Services + + static function getQueryTemplate() { + ob_start(); + echo '' . "\n"; +echo' + +{q} +{searchAllVersions} +{includeAllowableActions} +{includeRelationships} +{renditionFilter} +{maxItems} +{skipCount} + +'; + return ob_get_clean(); + } + function query($q,$options=array()) { + static $query_template; + if (!isset($query_template)) { + $query_template = CMISService::getQueryTemplate(); + } + $hash_values=$options; + $hash_values['q'] = $q; + $post_value = CMISRepositoryWrapper::processTemplate($query_template,$hash_values); + $ret = $this->doPost($this->workspace->collections['query'],$post_value,MIME_CMIS_QUERY); + $objs = $this->extractObjectFeed($ret->body); + $this->cacheFeedInfo($objs); + return $objs; + } + + function getContentChanges() { + throw Exception("Not Implemented"); + } + + //Object Services + static function getEntryTemplate() { + ob_start(); + echo '' . "\n"; +echo ' + +{title} +{SUMMARY} +{CONTENT} +{PROPERTIES} + +'; + return ob_get_clean(); + } + + static function getPropertyTemplate() { + ob_start(); +echo' + + {properties} + +'; + return ob_get_clean(); + } + + function processPropertyTemplates($objectType,$propMap) { + static $propTemplate; + static $propertyTypeMap; + if (!isset($propTemplate)) { + $propTemplate = CMISService::getPropertyTemplate(); + } + if (!isset($propertyTypeMap)) { // Not sure if I need to do this like this + $propertyTypeMap = array ( + "integer" => "Integer", + "boolean" => "Boolean", + "datetime" => "DateTime", + "decimal" => "Decimal", + "html" => "Html", + "id" => "Id", + "string" => "String", + "url" => "Url", + "xml" => "Xml", + ); + } + $propertyContent=""; + $hash_values=array(); + foreach ($propMap as $propId => $propValue) { + $hash_values['propertyType']=$propertyTypeMap[$this->getPropertyType($objectType,$propId)]; + $hash_values['propertyId']=$propId; + if (is_array($propValue)) { + $first_one=true; + $hash_values['properties']=""; + foreach ($propValue as $val) { + //This is a bit of a hack + if ($first_one) { + $first_one=false; + } else { + $hash_values['properties'] .= "\n"; + } + $hash_values['properties'] .= $val; + } + } else { + $hash_values['properties']=$propValue; + } + //echo "HASH:\n"; + //print_r(array("template" =>$propTemplate, "Hash" => $hash_values)); + $propertyContent .= CMISRepositoryWrapper::processTemplate($propTemplate,$hash_values); + } + return $propertyContent; + } + + static function getContentEntry($content,$content_type="application/octet-stream") { + static $contentTemplate; + if (!isset($contentTemplate)) { + $contentTemplate = CMISService::getContentTemplate(); + } + if ($content) { + return CMISRepositoryWrapper::processTemplate($contentTemplate,array("content" => base64_encode($content),"content_type" => $content_type)); + } else { + return ""; + } + } + + static function getSummaryTemplate() { + ob_start(); +echo' + {summary} +'; + return ob_get_clean(); + } + + static function getContentTemplate() { + ob_start(); +echo' + + + {content_type} + + + {content} + + +'; + return ob_get_clean(); + } + static function createAtomEntry($name,$properties) { + + } + function getObject($objectId,$options=array()) { + $varmap=$options; + $varmap["id"]=$objectId; + $obj_url = $this->processTemplate($this->workspace->uritemplates['objectbyid'],$varmap); + $ret = $this->doGet($obj_url); + $obj=$this->extractObject($ret->body); + $this->cacheEntryInfo($obj); + return $obj; + } + + function getObjectByPath($path,$options=array()) { + $varmap=$options; + $varmap["path"]=$path; + $obj_url = $this->processTemplate($this->workspace->uritemplates['objectbypath'],$varmap); + $ret = $this->doGet($obj_url); + if($ret->code == 404){ + return false; + } + $obj=$this->extractObject($ret->body); + $this->cacheEntryInfo($obj); + return $obj; + } + + function getProperties($objectId,$options=array()) { + // May need to set the options array default -- + return $this->getObject($objectId,$options); + } + + function getAllowableActions($objectId,$options=array()) { + // get stripped down version of object (for the links) and then get the allowable actions? + // Low priority -- can get all information when getting object + throw Exception("Not Implemented"); + } + + function getRenditions($objectId,$options=array(OPT_RENDITION_FILTER => "*")) { + return getObject($objectId,$options); + } + + function getContentStream($objectId,$options=array()) { // Yes + $myURL = $this->getLink($objectId,"edit-media"); + $ret=$this->doGet($myURL); + // doRequest stores the last request information in this object + return $ret->body; + } + + function postObject($folderId,$objectName,$objectType,$properties=array(),$content=null,$content_type="application/octet-stream",$options=array()) { // Yes + $myURL = $this->getLink($folderId,"down"); + // TODO: Need Proper Query String Handling + // Assumes that the 'down' link does not have a querystring in it + $myURL = CMISRepositoryWrapper::getOpUrl($myURL,$options); + static $entry_template; + if (!isset($entry_template)) { + $entry_template = CMISService::getEntryTemplate(); + } + if (is_array($properties)) { + $hash_values=$properties; + } else { + $hash_values=array(); + } + if (!isset($hash_values["cmis:objectTypeId"])) { + $hash_values["cmis:objectTypeId"]=$objectType; + } + $properties_xml = $this->processPropertyTemplates($objectType,$hash_values); + if (is_array($options)) { + $hash_values=$options; + } else { + $hash_values=array(); + } + $hash_values["PROPERTIES"]=$properties_xml; + $hash_values["SUMMARY"]=CMISService::getSummaryTemplate(); + if ($content) { + $hash_values["CONTENT"]=CMISService::getContentEntry($content,$content_type); + } + if (!isset($hash_values['title'])) { + $hash_values['title'] = $objectName; + } + if (!isset($hash_values['summary'])) { + $hash_values['summary'] = $objectName; + } + $post_value = CMISRepositoryWrapper::processTemplate($entry_template,$hash_values); + $ret = $this->doPost($myURL,$post_value,MIME_ATOM_XML_ENTRY); + if($ret == null || $ret->code == 500) + { + return false; + } + + $obj=$this->extractObject($ret->body); + $this->cacheEntryInfo($obj); + return $obj; + } + + function createDocument($folderId,$fileName,$properties=array(),$content=null,$content_type="application/octet-stream",$options=array()) { // Yes + return $this->postObject($folderId,$fileName,"cmis:document",$properties,$content,$content_type,$options); + } + + function createDocumentFromSource() { //Yes? + throw Exception("Not Implemented in This Binding"); + } + + function createFolder($folderId,$folderName,$properties=array(),$options=array()) { // Yes + return $this->postObject($folderId,$folderName,"cmis:folder",$properties,null,null,$options); + } + + function createRelationship() { // Not in first Release + throw Exception("Not Implemented"); + } + + function createPolicy() { // Not in first Release + throw Exception("Not Implemented"); + } + + function updateProperties($objectId,$properties=array(),$options=array()) { // Yes + $varmap=$options; + $varmap["id"]=$objectId; + $objectName=$this->getTitle($objectId); + $objectType=$this->getObjectType($objectId); + $obj_url = $this->getLink($objectId,"edit"); + $obj_url = CMISRepositoryWrapper::getOpUrl($obj_url,$options); + static $entry_template; + if (!isset($entry_template)) { + $entry_template = CMISService::getEntryTemplate(); + } + if (is_array($properties)) { + $hash_values=$properties; + } else { + $hash_values=array(); + } + $properties_xml = $this->processPropertyTemplates($objectType,$hash_values); + if (is_array($options)) { + $hash_values=$options; + } else { + $hash_values=array(); + } + $hash_values["PROPERTIES"]=$properties_xml; + $hash_values["SUMMARY"]=CMISService::getSummaryTemplate(); + if (!isset($hash_values['title'])) { + $hash_values['title'] = $objectName; + } + if (!isset($hash_values['summary'])) { + $hash_values['summary'] = $objectName; + } + $put_value = CMISRepositoryWrapper::processTemplate($entry_template,$hash_values); + $ret= $this->doPut($obj_url,$put_value,MIME_ATOM_XML_ENTRY); + $obj=$this->extractObject($ret->body); + $this->cacheEntryInfo($obj); + return $obj; + } + + function moveObject($objectId,$targetFolderId,$sourceFolderId,$options=array()) { //yes + $options['sourceFolderId']=$sourceFolderId; + return $this->postObject($targetFolderId,$this->getTitle($objectId),$this->getObjectType($objectId),array("cmis:objectId" => $objectId),null,null,$options); + } + + function deleteObject($objectId,$options=array()) { //Yes + $varmap=$options; + $varmap["id"]=$objectId; + $obj_url = $this->getLink($objectId,"edit"); + $ret = $this->doDelete($obj_url); + return; + } + + function deleteTree() { // Nice to have + throw Exception("Not Implemented"); + } + + function setContentStream($objectId,$content,$content_type,$options=array()) { //Yes + $myURL = $this->getLink($objectId,"edit-media"); + $ret=$this->doPut($myURL,$content,$content_type); + } + + function deleteContentStream($objectId,$options=array()) { //yes + $myURL = $this->getLink($objectId,"edit-media"); + $ret=$this->doDelete($myURL); + return; + } + + //Versioning Services + function getPropertiesOfLatestVersion($objectId,$options=array()) { + throw Exception("Not Implemented"); + } + + function getObjectOfLatestVersion($objectId,$options=array()) { + throw Exception("Not Implemented"); + } + + function getAllVersions() { + throw Exception("Not Implemented"); + } + + function checkOut($objectId) { + $objectName=$this->getTitle($objectId); + $objectType=$this->getObjectType($objectId); + $obj_url = $this->workspace->collections['checkedout']; + static $entry_template; + if (!isset($entry_template)) { + $entry_template = CMISService::getEntryTemplate(); + } + + $hash_values=array(); + $hash_values['cmis:objectId'] = $objectId; + $properties_xml = $this->processPropertyTemplates($objectType,$hash_values); + + $hash_values=array(); + $hash_values["PROPERTIES"]=$properties_xml; + $hash_values["SUMMARY"]=CMISService::getSummaryTemplate(); + if (!isset($hash_values['title'])) { + $hash_values['title'] = $objectName; + } + if (!isset($hash_values['summary'])) { + $hash_values['summary'] = $objectName; + } + $post_value = CMISRepositoryWrapper::processTemplate($entry_template,$hash_values); + $res = $this->doPost($obj_url,$post_value,MIME_ATOM_XML_ENTRY); + print_r($res); + } + + function checkIn($objectId) { + $obj_url = $this->getLink($objectId,"edit"); + $obj_url .= '?checkin=true'; + $content = ''; + + $res = $this->doPut($obj_url,$content,MIME_ATOM_XML_ENTRY); + + print_r($res); + } + + function cancelCheckOut() { + throw Exception("Not Implemented"); + } + + function deleteAllVersions() { + throw Exception("Not Implemented"); + } + + //Relationship Services + function getObjectRelationships() { + // get stripped down version of object (for the links) and then get the relationships? + // Low priority -- can get all information when getting object + throw Exception("Not Implemented"); + } + + //Multi-Filing Services + function addObjectToFolder() { // Probably + throw Exception("Not Implemented"); + } + + function removeObjectFromFolder() { //Probably + throw Exception("Not Implemented"); + } + + //Policy Services + function getAppliedPolicies() { + throw Exception("Not Implemented"); + } + + function applyPolicy() { + throw Exception("Not Implemented"); + } + + function removePolicy() { + throw Exception("Not Implemented"); + } + + //ACL Services + function getACL() { + throw Exception("Not Implemented"); + } + + function applyACL() { + throw Exception("Not Implemented"); + } +} +?> diff -Naur -X pattern.txt moodle_original/lib/repository/depositandreferencement.php www\moodle/lib/repository/depositandreferencement.php --- moodle_original/lib/repository/depositandreferencement.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/depositandreferencement.php 2010-06-14 09:51:11.375000000 +0200 @@ -0,0 +1,25 @@ + close the window. +if(empty($referenceurl)){ + echo '';die; +} + +doreferencement($referenceurl); + + +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/lib/repository/lib.php www\moodle/lib/repository/lib.php --- moodle_original/lib/repository/lib.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/lib.php 2010-07-21 15:30:48.010990200 +0200 @@ -0,0 +1,174 @@ +libdir.'/repository/cmis.php'); +require_once($CFG->libdir.'/soaplib.php'); +require_once($CFG->dirroot.'/auth/cas/CAS/CAS.php'); + +//return the url to directly access the ressource +function upload($resourcereference) +{ + global $USER; + global $CFG; + + //test if a filename has been set 'manually' (return from existingfile) + if(isset($_POST['fileext'])){ + $filename = $_POST['newname'].$_POST['fileext']; + } + else{ + //get the file name, without any directory + $slashpos = strrpos($resourcereference,'/'); + if($slashpos == false) + { + $slashpos = strrpos($resourcereference,'\\'); + } + else + { + $filename = substr($resourcereference,$slashpos+1); + } + } + + //For windows conveniance : replace / by \ + if (getenv("OS")=="Windows_NT"){ + $resourcereference = str_replace('/','\\',$resourcereference); + } + + $override=false; + $newversion = false; + + if(isset($_POST['groupaction'])) + { + switch($_POST['groupaction']) + { + case 'replace': + $override=true; + break; + case 'createNew': + $filename = $_POST['newname'].$_POST['fileext']; + break; + case 'newVersion': + $newversion = true; + break; + case 'nothing': + return; + } + } + + + $host = $CFG->block_referencement_host; + $port = $CFG->block_referencement_port; + $siteuri = $CFG->block_referencement_site; + $accesspoint = $CFG->block_referencement_accesspoint; + $remotepath = $CFG->block_referencement_relativeremotepath; + $universallink = $CFG->block_referencement_universalurl; + + $login = $USER->username; + $password = ''; + + if(!empty($USER->id)) + { + // %u = firstname-lastname + $remotepath = str_replace('%u', strtolower($USER->firstname.'-'.$USER->lastname),$remotepath); + // %l = login + $remotepath = str_replace('%l', strtolower($login),$remotepath); + + $client =& new CMISRepositoryClient($login,$password,$host,$port,$siteuri,$accesspoint); + if(!$client->authenticated){ + error(get_string('cmisclienterror','referencement')); + } + $fileid = $client->uploadfile($remotepath,$resourcereference,$filename,$override,$newversion); + return 'http://'.str_replace('//','/',$host.':'.$port.'/'.$siteuri.'/'.$universallink.'/'.$fileid); + } + else + { + error(get_string('unlogged','referencement')); + } +} + + +// +function doreferencement($urltoreference) +{ + if(isset($_POST['workflowtype'])) + { + return; + } + global $CFG; + global $USER; + $wsdl = $CFG->block_referencement_workflow_url . $CFG->block_referencement_workflow_soapwsdl; + if( substr($CFG->block_referencement_workflow_url,0,7) == 'http://'){ + $host = substr($CFG->block_referencement_workflow_url,7); + }else if(substr($CFG->block_referencement_workflow_url,0,8) == 'https://' ){ + $host = substr($CFG->block_referencement_workflow_url,8); + } + $host = substr($host,0,strpos($host,'/')); + if(strstr($host,':')){ + $port = substr($host,strpos($host,':')+1); + $host = substr($host,0,strpos($host,':')); + }else{ + $port = 80; + } + $testconnection = @fsockopen($host, $port, &$errno, &$errstr, 30); + if(!$testconnection) + { + error(get_string('oriserverout','referencement')); + } + try{ + $client = new SoapClient($wsdl); + $user = $USER->username; + //get avaible metadata types for current user + $params = array('in0'=>$user); + $result = $client->getMetadataTypes1($params); + } + catch(Exception $e){ + error('ORI-OAI ERROR : '.$e->faultstring); + } + + $myarray = $result->out->entry; + $reftypes = array(); + foreach($myarray as $k=>$v) + { + if(substr($v->key,0,3) == 'tef'){continue;} + $reftypes[$v->key] = $v->value; + } + $reftypes['nothing'] = get_string('donothing','referencement'); + + + $mform = new MoodleQuickForm('wftype','POST',''); + $mform->addElement('header', 'wftypehead', get_string('referencetype', 'referencement')); + foreach($reftypes as $k=>$v) + { + $mform->addElement('radio','workflowtype','',$v,$k); + } + foreach($_POST as $k=>$v) + { + if($k == 'newname' || $k == 'groupaction') continue; + if(is_array($v)) + { + foreach($v as $key=>$val){ + $mform->addElement('hidden',$k.'['.$key.']',$val); + } + }else{ + $mform->addElement('hidden',$k,$v); + } + } + $button = $mform->addElement('submit', 'validate',get_string('validate','referencement')); + $buttonattributes = array('onclick'=>'var url = \'/lib/repository/referencement.php?referenceurl='.urlencode($urltoreference) + .'&referencename='.urlencode($_POST['name']).'&\'; + var reftype = document.getElementsByName(\'workflowtype\'); + for(i=0;iupdateAttributes($buttonattributes); + print_header(); + $mform->display(); + print_footer();die; +} diff -Naur -X pattern.txt moodle_original/lib/repository/rapatriement.php www\moodle/lib/repository/rapatriement.php --- moodle_original/lib/repository/rapatriement.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/rapatriement.php 2010-07-13 10:38:43.562500000 +0200 @@ -0,0 +1,208 @@ + +
'; + echo $string; + echo '
+ +
'; + print_footer(); + die; +} + + +$fileurl = required_param('fileurl'); +$fileurl = urldecode($fileurl); + +$courseid = required_param('course'); + +$action = optional_param('groupaction',''); + +if($action == 'nothing'){ + echo "";die; +} +if($action == 'createNew'){ + $filename = $_POST['newname'].$_POST['fileext']; + $dest = $CFG->dataroot.'/'.$courseid.'/'.$filename; +}else{ + $filename = required_param('filename'); +} + +$dest = $CFG->dataroot.'/'.$courseid.'/'.$filename; + + +if($action == 'replace'){ + if(!unlink($dest)){ + $message = get_string('cantdelete','referencement'); + } +} + +//get the data +$ch = curl_init($fileurl); +curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); +curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); +curl_setopt($ch, CURLOPT_HTTPGET, true); +curl_setopt($ch, CURLOPT_HEADER, false); + +$result = curl_exec($ch); +$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); +$mimetype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); +curl_close($ch); + +//forbiden OR not found OR auth needed +if($code == 404 || $code == 403 || $code == 401){ + //get the host of the ressource + $hostname = substr($fileurl,strpos($fileurl,'//')+2); + $endpos = strpos($hostname,':'); + if($endpos === false){ + $endpos = strpos($hostname,'/'); + } + $hostname = substr($hostname,0,$endpos); + + //if the host is the same as the configured one for file deposit : + if($hostname == $CFG->block_referencement_host){ + //and if a cookie is present for this host : + if($_COOKIE['CMISREPOSITORY'.md5($USER->username)]){ + $cookie = $_COOKIE['CMISREPOSITORY'.$USER->username]; + //try to get data with this cookie + $ch = curl_init($fileurl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HTTPGET, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_COOKIE,$cookie); + $result = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $mimetype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); + curl_close($ch); + } + } + + if($code != 200){ + messageandclose(get_string('accesadvise','referencement')); + } +} + + +//else (???) => unknown error. +if($code != 200){ + messageandclose(get_string('unknownerror','referencement')); +} + + +//if data is html : it's a website (or an error page??) => advertissment +if(substr($mimetype,0,9)=='text/html' || $code != 200){ + messageandclose(get_string('htmlmimetype','referencement')); +} + +$extension = false; +//TODO : enhance! +if($mimetype == 'application/pdf'){ + $extension = 'pdf'; +}else{ + $mimeexts = get_mimetypes_array(); + foreach($mimeexts as $ext=>$val){ + if($val['type'] == $mimetype){ + $extension = $ext; + break; + } + } +} + +if($extension == false){ + messageandclose(get_string('badextension','referencement')); +} + + +//test correct file name +if(!ereg("^[0-9a-zA-Z\.]+$", $filename) ) +{ + $mform = new MoodleQuickForm('specialchars','POST','rapatriement.php'); + $mform->addElement('header', 'specialcharsheader', get_string('badfilename', 'referencement')); + $txtgrp = array(); + $txtgrp[] = $mform->createElement('text', 'newname','', 'value="'.$filename.'" size="60%" style="text-align:right"'); + $txtgrp[] = $mform->createElement('static','extension','','.'.$extension); + $mform->addGroup($txtgrp); + $group = array(); + $group[] =& $mform->createElement('submit', 'submitbutton',get_string('validate','referencement')); + $button = $group[] =& $mform->createElement('button', 'cancelbutton',get_string('nothing','referencement')); + $buttonattributes = array('onclick'=>"window.close();"); + $button->updateAttributes($buttonattributes); + $mform->addGroup($group); + $mform->addElement('hidden','fileurl',$fileurl); + $mform->addElement('hidden','course',$courseid); + $mform->addElement('hidden','groupaction','createNew'); + $mform->addElement('hidden','fileext','.'.$extension); + + print_header(); + $mform->display(); + print_footer();die; +} + + + + + +//test existing file +if(file_exists($dest)){ + $fileext= substr($filename,strrpos($filename,'.')); + $filenamenoext = substr($filename,0,strrpos($filename,'.')); + print_header(); + if(isset($message)){ + echo '
'; + echo $message; + echo '
'; + } + + $mform = new MoodleQuickForm('existingfile','POST','rapatriement.php'); + $mform->addElement('header', 'existingfilehead', get_string('existingfile', 'referencement')); + + $mform->addElement('radio','groupaction','',get_string('replace','referencement'),'replace'); + $newnamegroup = array(); + $newnamegroup[] = $mform->createElement('radio','groupaction',null,get_string('createNew','referencement'),'createNew'); + $newnamegroup[] = $mform->createElement('text','newname','','value="'.$filenamenoext.'"'); + $newnamegroup[] = $mform->createElement('static','extension','','.'.$extension); + + $mform->addGroup($newnamegroup); + $mform->setDefault('groupaction', 'replace'); + + $group = array(); + $group[] =& $mform->createElement('submit', 'submitbutton',get_string('validate','referencement')); + $button = $group[] =& $mform->createElement('button', 'cancelbutton',get_string('nothing','referencement')); + $buttonattributes = array('onclick'=>"window.close();"); + $button->updateAttributes($buttonattributes); + $mform->addGroup($group); + $mform->addElement('hidden','fileext',$fileext); + $mform->addElement('hidden','fileurl',$fileurl); + $mform->addElement('hidden','course',$courseid); + $mform->addElement('hidden','filename',$filename); + + $mform->display(); + print_footer();die; +} + + +//write data in the new file +else{ + $newfile = fopen($dest,'w'); + fwrite($newfile,$result); + fclose($newfile); + $url = $CFG->wwwroot.'/files/index.php?id='.$courseid.'&choose=id_reference_value'; + echo "";die; +} +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/lib/repository/referencement.php www\moodle/lib/repository/referencement.php --- moodle_original/lib/repository/referencement.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/referencement.php 2010-08-22 14:24:26.421750000 +0200 @@ -0,0 +1,129 @@ +getElementsByTagName($container); + foreach($conts as $c) + { + $elts = $c->getElementsByTagName($element); + foreach($elts as $e) + { + $c->removeChild($e); + } + $newelt = $domdocument->createElement($prefix.':'.$element); + $newtxtelt = $domdocument->createTextNode($data); + $newelt->appendChild($newtxtelt); + $c->appendChild($newelt); + } +} + + +//get required parameters +$referenceurl = required_param('referenceurl'); +$referencetype = required_param('referencetype'); +$referencename = optional_param('referencename'); + +$wsdl = $CFG->block_referencement_workflow_url . $CFG->block_referencement_workflow_soapwsdl; + +$user = $USER->username; + +//create the client +try{ + $client = new SoapClient($wsdl); +} +catch(Exception $e) +{ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +//create new empty workflow instance +$params = array( +'in0'=>null, +'in1'=>$referencetype, +'in2'=>$user ); + +try{ + $result = $client->newWorkflowInstance($params); +}catch(Exception $e){ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +$id = $result->out; + +//get idp of created instance +$params = array( +'in0'=>$id, +'in1'=>$user); +try{ + $result = $client->getIdp($params); +}catch(Exception $e){ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +//get xml content of created instance +$idp = $result->out; + +$params = array('in0'=>$idp); +try{ + $result = $client->getXMLForms($params); +}catch(Exception $e){ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +//modify xml content to introduce rigth url location and date +$dom = new DOMDocument(); +$dom->loadXML($result->out); + +//lom sheet +if( strstr($referencetype,'ressource_pedago') ) +{ + dom_replace($dom,'technical','lom','location',$referenceurl); + + dom_replace($dom,'date','lom', 'dateTime',date('Y-m-d')); + + dom_replace($dom,'title','lom','string',$referencename); +} +//dublincore sheet +elseif( substr($referencetype,0,2) == 'dc' ) +{ + dom_replace($dom,'dc','dc','identifier',$referenceurl); + + dom_replace($dom,'dc','dc', 'date',date('Y-m-d')); + + dom_replace($dom,'dc','dc','title',$referencename); +} + +$xml = $dom->saveXML(); +//save xml contents +$params = array( +'in0'=>$idp, +'in1'=>$xml); +try{ + $client->saveXML($params); +}catch(Exception $e){ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +//get url of the created workflow instance in md-editor +$params = array('in0'=>$idp); +try{ + $result = $client->getMdEditorUrl($params); +}catch(Exception $e){ + error($e->faultstring,$CFG->block_referencement_workflow_url); +} + +if(is_array($result->out->entry)){ + $url = $result->out->entry[0]->value .'/'. $idp; +} +else{ + $url = $result->out->entry->value .'/'. $idp; +} +/*echo $url.'
'; + echo $xml;die;*/ +header('Location: '.$url); + +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/lib/repository/searchcallback.php www\moodle/lib/repository/searchcallback.php --- moodle_original/lib/repository/searchcallback.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/lib/repository/searchcallback.php 2010-07-09 09:30:47.609375000 +0200 @@ -0,0 +1,49 @@ + +var mid = new RegExp("(MoodleSession=[^;,]*)","g"); +var incomeid = (window.opener!=null)? mid.exec(window.opener.document.cookie)[0] : ""; +mid = new RegExp("(MoodleSession=[^;,]*)","g"); +var homeid = mid.exec(window.document.cookie)[0]; + +if(incomeid != homeid){ + alert("Your Moodle session key is not a valide one."); window.close(); +} +else{ +'; + +if($action == 'link'){ + echo 'var chbox = window.opener.document.getElementsByName("doreference")[0]; + chbox.checked=false; + chbox.disabled=true; + window.opener.document.getElementById("id_reference_value").value = "'.urldecode($resource).'"; + window.close();'; +} +elseif($action == 'download'){ + echo 'var reg = new RegExp("(course.*)","g"); + var chaine = window.opener.location.toString(); + var course = window.opener.document.getElementsByName("course")[0]; + var options = "menubar=1,location=1,scrollbars,resizable,width=800,height=600"; + chaine = chaine.replace(reg,"lib/repository/rapatriement.php"); + + chaine = chaine + "?fileurl=" + encodeURIComponent("'.$resource.'") + + "&course=" + course.value + "&filename=" + "'.$title.'"; + window.location = chaine;'; +} +else{ + echo 'alert("Invalid action");window.close();'; +} +echo '}'; + +?> \ No newline at end of file diff -Naur -X pattern.txt moodle_original/mod/resource/settings.php www\moodle/mod/resource/settings.php --- moodle_original/mod/resource/settings.php 2010-08-31 08:04:30.000000000 +0200 +++ www\moodle/mod/resource/settings.php 2007-12-24 10:17:52.000000000 +0100 @@ -1,4 +1,4 @@ -dirroot.'/mod/resource/lib.php'); @@ -18,6 +18,9 @@ $settings->add(new admin_setting_configpasswordunmask('resource_secretphrase', get_string('password'), get_string('configsecretphrase', 'resource'), random_string(20))); +$settings->add(new admin_setting_configcheckbox('resource_allowlocalfiles', get_string('allowlocalfiles', 'resource'), + get_string('configallowlocalfiles', 'resource'), 0)); + $woptions = array('' => get_string('pagewindow', 'resource'), 'checked' => get_string('newwindow', 'resource')); $settings->add(new admin_setting_configselect('resource_popup', get_string('display', 'resource'), get_string('configpopup', 'resource'), '', $woptions)); diff -Naur -X pattern.txt moodle_original/mod/resource/type/file/localfile.php www\moodle/mod/resource/type/file/localfile.php --- moodle_original/mod/resource/type/file/localfile.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/mod/resource/type/file/localfile.php 2010-06-14 09:51:11.093750000 +0200 @@ -0,0 +1,50 @@ +resource_allowlocalfiles) { + error('You cannot access this script'); + } + + print_header(get_string('localfilechoose', 'resource')); + + print_simple_box(get_string('localfileinfo', 'resource'), 'center'); + + ?> + + +
+
+
+
+
+ + +
+
+
+ + diff -Naur -X pattern.txt moodle_original/mod/resource/type/file/localpath.php www\moodle/mod/resource/type/file/localpath.php --- moodle_original/mod/resource/type/file/localpath.php 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/mod/resource/type/file/localpath.php 2010-06-14 09:51:11.109375000 +0200 @@ -0,0 +1,57 @@ + + + wwwroot.'/user/edit.php?course='.SITEID), 'center'); + + ?> + + +
+
+
+
+ + +
+ + +
+
+
+ diff -Naur -X pattern.txt moodle_original/mod/resource/type/file/resource.class.php www\moodle/mod/resource/type/file/resource.class.php --- moodle_original/mod/resource/type/file/resource.class.php 2010-08-31 08:04:30.000000000 +0200 +++ www\moodle/mod/resource/type/file/resource.class.php 2010-07-12 16:52:25.953125000 +0200 @@ -1,8 +1,9 @@ -windowpopup); $resource->options = ''; - } else { + } else { if (empty($resource->framepage)) { $resource->options = ''; } else { @@ -181,6 +184,31 @@ } $resource->alltext = implode(',', $optionlist); + + //ORI-OAI Referencement + if($resource->doreference && (empty($_POST['groupaction']) || $_POST['groupaction']!= 'nothing')) + { + require_once($CFG->libdir.'/javascript.php'); + require_once($CFG->libdir.'/repository/lib.php'); + //check: return from existingfile or selectreferencetype + if(empty($_POST['referenceurl'])) + { + //if ressource is an url => just get it + if( substr($resource->reference,0,7) == 'http://'){ + $referenceurl = $resource->reference; + } + //else, upload the file in a repository and get the result as url + else + { + $coursedirpath = $CFG->dataroot.'/'.$this->course->id; + $referenceurl = upload($coursedirpath.'/'.$resource->reference); + } + //put the url in POST + $_POST['referenceurl'] = $referenceurl; + } + //new workflow instance + doreferencement($_POST['referenceurl']); + } } @@ -266,12 +294,12 @@ } else if ($mimetype == 'application/pdf' || $mimetype == 'application/x-pdf') { $resourcetype = "pdf"; //no need embedded, html file types behave like unknown file type - + } else if ($mimetype == "audio/x-pn-realaudio-plugin") { // It's a realmedia file $resourcetype = "rm"; $embedded = true; } - } + } $isteamspeak = (stripos($resource->reference, 'teamspeak://') === 0); @@ -307,6 +335,20 @@ $fullurl .= '&'.$querystring; } } + + } else if ($CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { // Localpath + $localpath = get_user_preferences('resource_localpath', 'D:'); + $relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference); + + if ($querystring) { + $relativeurl .= '?'.$querystring; + } + + $relativeurl = str_replace('\\', '/', $relativeurl); + $relativeurl = str_replace(' ', '%20', $relativeurl); + $fullurl = 'file:///'.htmlentities($relativeurl); + $localpath = true; + } else { // Normal uploaded file $forcedownloadsep = '?'; if ($resource->options == 'forcedownload') { @@ -315,6 +357,25 @@ $fullurl = get_file_url($course->id.'/'.$resource->reference, $querys); } + /// Print a notice and redirect if we are trying to access a file on a local file system + /// and the config setting has been disabled + if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { + if ($inpopup) { + print_header($pagetitle, $course->fullname); + } else { + $navigation = build_navigation($this->navlinks, $cm); + print_header($pagetitle, $course->fullname, $navigation, + "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); + } + notify(get_string('notallowedlocalfileaccess', 'resource', '')); + if ($inpopup) { + close_window_button(); + } + print_footer('none'); + die; + } + + /// Check whether this is supposed to be a popup, but was called directly if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window $navigation = build_navigation($this->navlinks, $cm); @@ -349,7 +410,7 @@ $frameset = optional_param('frameset', '', PARAM_ALPHA); if (empty($frameset) and !$embedded and !$inpopup and ($resource->options == "frame" || $resource->options == "objectframe") and empty($USER->screenreader)) { - /// display the resource into a object tag + /// display the resource into a object tag if ($resource->options == "objectframe") { /// Yahoo javascript libaries for updating embedded object size require_js(array('yui_utilities')); @@ -363,6 +424,11 @@ print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); $options = new object(); $options->para = false; + if (!empty($localpath)) { // Show some help + echo ''; + } echo ''; /// embedded file into iframe if the resource is on another domain @@ -424,7 +490,11 @@ echo "" . format_string($course->shortname) . ": ".strip_tags(format_string($resource->name,true))."\n"; echo "resource_framesize,*\">"; echo "id}&type={$resource->type}&frameset=top\" title=\"".get_string('modulename','resource')."\"/>"; - echo ""; + if (!empty($localpath)) { // Show it like this so we interpose some HTML + echo "id}&type={$resource->type}&inpopup=true\" title=\"".get_string('modulename','resource')."\"/>"; + } else { + echo ""; + } echo ""; echo ""; exit; @@ -451,6 +521,12 @@ $options = new object(); $options->para = false; echo '
'.format_text($resource->summary, FORMAT_HTML, $options).'
'; + if (!empty($localpath)) { // Show some help + echo ''; + } print_footer('empty'); exit; } @@ -468,7 +544,7 @@ update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self")); } - + if ($resourcetype == "image") { echo '
'; echo "name,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />"; @@ -582,7 +658,7 @@ echo '
'; } else if ($resourcetype == "rm") { - echo '
'; + echo '
'; echo ''; echo ''; echo ''; @@ -593,7 +669,7 @@ echo ''; echo ''; echo ''; - echo '
'; + echo '
'; } else if ($resourcetype == "quicktime") { echo '
'; @@ -662,6 +738,13 @@ } } else { // Display the resource on it's own + if (!empty($localpath)) { // Show a link to help work around browser security + echo ''; + echo ""; + } redirect($fullurl); } @@ -681,7 +764,7 @@ return md5(getremoteaddr().$CFG->resource_secretphrase); } - function setup_preprocessing(&$defaults){ + function setup_preprocessing(&$defaults){ if (isset($defaults['options']) and $defaults['options'] === 'forcedownload') { $defaults['forcedownload'] = 1; @@ -704,7 +787,7 @@ if (array_key_exists('options', $defaults)) { if ($defaults['options']=='frame') { $defaults['framepage'] = 1; - } else if ($defaults['options']=='objectframe') { + } else if ($defaults['options']=='objectframe') { $defaults['framepage'] = 2; } else { $defaults['framepage'] = 0; @@ -731,11 +814,17 @@ global $CFG, $RESOURCE_WINDOW_OPTIONS; $this->set_parameters(); // set the parameter array for the form + - $mform->addElement('choosecoursefile', 'reference', get_string('location'), null, array('maxlength' => 255, 'size' => 48)); + $localfiles = $mform->addElement('choosecoursefile', 'reference', get_string('location'), null, array('maxlength' => 255, 'size' => 48)); + $str = $localfiles->_elements[1]->_attributes['onclick']; + $str = 'var chbox = window.document.getElementsByName("doreference")[0]; + chbox.disabled=false; '.$str; + $localfiles->_elements[1]->_attributes['onclick'] = $str; $mform->setDefault('reference', $CFG->resource_defaulturl); $mform->addGroupRule('reference', array('value' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255, 'client')))); $mform->addRule('name', null, 'required', null, 'client'); + if (!empty($CFG->resource_websearch)) { $searchbutton = $mform->addElement('button', 'searchbutton', get_string('searchweb', 'resource').'...'); @@ -745,6 +834,32 @@ $searchbutton->updateAttributes($buttonattributes); } + if (!empty($CFG->resource_allowlocalfiles)) { + $lfbutton = $mform->addElement('button', 'localfilesbutton', get_string('localfilechoose', 'resource').'...'); + $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400'; + $url = '/mod/resource/type/file/localfile.php?choose=id_reference_value'; + $buttonattributes = array('title'=>get_string('localfilechoose', 'resource'), 'onclick'=>"return openpopup('$url', '" + . $lfbutton->getName()."', '$options', 0);"); + $lfbutton->updateAttributes($buttonattributes); + } + + if($CFG->block_referencement_allowonorisearch){ + $orisearchbutton = $mform->addElement('button','orisearchbutton', get_string('orifilesearch','resource')); + $options = 'menubar=1,location=1,scrollbars,resizable,width=950,height=760'; + + $url = $CFG->block_referencement_orioaisearch_url; + if(strstr($url,'?') == false){ + $url.='?'; + }else { + $url.='&'; + } + $url .= $CFG->block_referencement_orioaisearch_callbackparam.'='.urlencode($CFG->wwwroot.'/lib/repository/searchcallback.php'); + + $buttonattributes = array('title'=>get_string('orifilesearch', 'resource'), + 'onclick'=>"var p = window.open('$url','ORI-SEARCH','$options'); p.focus()"); + $orisearchbutton->updateAttributes($buttonattributes); + $mform->setHelpButton('orisearchbutton', array('orifilesearch', get_string('orifilesearch','resource'), '')); + } $mform->addElement('header', 'displaysettings', get_string('display', 'resource')); $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource')); @@ -758,7 +873,7 @@ $navoptions = array(0 => get_string('keepnavigationvisibleno','resource'), 1 => get_string('keepnavigationvisibleyesframe','resource'), 2 => get_string('keepnavigationvisibleyesobject','resource')); $mform->addElement('select', 'framepage', get_string('keepnavigationvisible', 'resource'), $navoptions); - + $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource')); $mform->setDefault('framepage', 0); $mform->disabledIf('framepage', 'windowpopup', 'eq', 1); @@ -808,6 +923,12 @@ $mform->setDefault($parametername, '-'); } + + if($CFG->block_referencement_allowonfiledeposit){ + $mform->addElement('header','referencement',get_string('referencement','resource')); + $mform->addElement('checkbox', 'doreference', get_string('doreference', 'resource')); + $mform->setHelpButton('doreference', array('referencement', get_string('referencement','resource'), '')); + } } } diff -Naur -X pattern.txt moodle_original/mod/resource/type/repository/resource.class.php www\moodle/mod/resource/type/repository/resource.class.php --- moodle_original/mod/resource/type/repository/resource.class.php 2010-08-31 08:04:30.000000000 +0200 +++ www\moodle/mod/resource/type/repository/resource.class.php 2009-05-02 08:07:10.000000000 +0200 @@ -1,4 +1,4 @@ -resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { + if ($inpopup) { + print_header($pagetitle, $course->fullname); + } else { + print_header($pagetitle, $course->fullname, $navigation, "", "", true, + update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); + } + notify(get_string('notallowedlocalfileaccess', 'resource', '')); + if ($inpopup) { + close_window_button(); + } + print_footer('none'); + die; + } + + /// Check whether this is supposed to be a popup, but was called directly if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window @@ -332,7 +351,11 @@ echo "" . format_string($course->shortname) . ": ".strip_tags(format_string($resource->name,true))."\n"; echo "resource_framesize,*\">"; echo "id}&type={$resource->type}&frameset=top\" title=\"".get_string('modulename','resource')."\"/>"; - echo ""; + if (!empty($localpath)) { // Show it like this so we interpose some HTML + echo "id}&type={$resource->type}&inpopup=true\" title=\"".get_string('modulename','resource')."\"/>"; + } else { + echo ""; + } echo ""; echo ""; exit; @@ -351,10 +374,16 @@ update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); echo '
'.format_text($resource->summary, FORMAT_HTML, $formatoptions).'
'; + if (!empty($localpath)) { // Show some help + echo ''; + } echo ''; exit; } + /// Display the actual resource if ($embedded) { // Display resource embedded in page @@ -459,6 +488,12 @@ } } else { // Display the resource on it's own + if (!empty($localpath)) { // Show a link to help work around browser security + echo ''; + echo "

($fullurl)

"; + } redirect($fullurl); } diff -Naur -X pattern.txt moodle_original/pix/i/sheetlist.gif www\moodle/pix/i/sheetlist.gif --- moodle_original/pix/i/sheetlist.gif 1970-01-01 01:00:00.000000000 +0100 +++ www\moodle/pix/i/sheetlist.gif 2010-06-14 09:51:11.171875000 +0200 @@ -0,0 +1,2 @@ +GIF89a÷€€€€€€€€€€€€ÀÀÀÿÿÿÿÿÿÿÿÿÿÿÿ3f™Ìÿ3333f3™3Ì3ÿff3fff™fÌfÿ™™3™f™™™Ì™ÿÌÌ3ÌfÌ™ÌÌÌÿÿÿ3ÿfÿ™ÿÌÿÿ3333f3™3Ì3ÿ3333333f33™33Ì33ÿ3f3f33ff3f™3fÌ3fÿ3™3™33™f3™™3™Ì3™ÿ3Ì3Ì33Ìf3Ì™3ÌÌ3Ìÿ3ÿ3ÿ33ÿf3ÿ™3ÿÌ3ÿÿff3fff™fÌfÿf3f33f3ff3™f3Ìf3ÿffff3fffff™ffÌffÿf™f™3f™ff™™f™Ìf™ÿfÌfÌ3fÌffÌ™fÌÌfÌÿfÿfÿ3fÿffÿ™fÿÌfÿÿ™™3™f™™™Ì™ÿ™3™33™3f™3™™3Ì™3ÿ™f™f3™ff™f™™fÌ™fÿ™™™™3™™f™™™™™Ì™™ÿ™Ì™Ì3™Ìf™Ì™™ÌÌ™Ìÿ™ÿ™ÿ3™ÿf™ÿ™™ÿÌ™ÿÿÌÌ3ÌfÌ™ÌÌÌÿÌ3Ì33Ì3fÌ3™Ì3ÌÌ3ÿÌfÌf3ÌffÌf™ÌfÌÌfÿ̙̙3Ì™fÌ™™Ì™ÌÌ™ÿÌÌÌÌ3ÌÌfÌÌ™ÌÌÌÌÌÿÌÿÌÿ3ÌÿfÌÿ™ÌÿÌÌÿÿÿÿ3ÿfÿ™ÿÌÿÿÿ3ÿ33ÿ3fÿ3™ÿ3Ìÿ3ÿÿfÿf3ÿffÿf™ÿfÌÿfÿÿ™ÿ™3ÿ™fÿ™™ÿ™Ìÿ™ÿÿÌÿÌ3ÿÌfÿÌ™ÿÌÌÿÌÿÿÿÿÿ3ÿÿfÿÿ™ÿÿÌÿÿÿ!ù,­ÿ ˆb @ ¢È†¢à¿|ñ)ÌFQ[ÄQh«å*[¢Ž ·!$¨ Û¿l­°eƒ+– ‡ ieÃÖJ&Ëm±TUƒ9¨¶Z+cálé" +/^°Ý \ No newline at end of file