/** * Upload a file into the repository. * * @uses $CFG * @uses $USER * @param string $upload The array index of the uploaded file. * @param string $path The full path to the file on the local filesystem. * @param string $uuid The UUID of the folder where the file is being uploaded to. * @param bool $useadmin Set to false to make sure that the administrative user configured in * the plug-in is not used for this operation (default: true). * @param string $filename The name of the file to be uploaded - used when a duplicate file is to be renamed * @param object $filemeta The file meta data of the file to be uploaded when overwriting * @return object Node values for the uploaded file. */ function elis_files_upload_file($upload = '', $path = '', $uuid = '', $useadmin = true, $filename = '', $olduuid = false, $filemeta = null) { global $CFG, $USER; require_once($CFG->libdir.'/filelib.php'); // assign file info from filemeta if ($filemeta) { $filename = empty($filename) ? $filemeta->name : $filename; $filepath = $filemeta->filepath.$filemeta->name; $filemime = $filemeta->type; $filesize = $filemeta->size; } else if (!empty($upload)) { if (!isset($_FILES[$upload]) || !empty($_FILES[$upload]->error)) { return false; } $filename = (empty($filename)) ? $_FILES[$upload]['name']: $filename; $filepath = $_FILES[$upload]['tmp_name']; $filemime = $_FILES[$upload]['type']; $filesize = $_FILES[$upload]['size']; } else if (!empty($path)) { if (!is_file($path)) { return false; } $filename = (empty($filename)) ? basename($path): $filename; $filepath = $path; $filemime = mimeinfo('type', $filename); $filesize = filesize($path); } else { return false; } if (!$repo = repository_factory::factory('elisfiles')) { return false; } if (!(ELIS_files::$version = elis_files_get_repository_version())) { return false; } // error_log("elis_files_upload_file('$upload', '$path', '$uuid', $useadmin): version = ". ELIS_files::$version); if (empty($uuid)) { $uuid = $repo->get_root()->uuid; } $xfermethod = get_config('elisfiles', 'file_transfer_method'); switch ($xfermethod) { case ELIS_FILES_XFER_WS: return elis_files_upload_ws($filename, $filepath, $filemime, $filesize, $uuid, $useadmin, $repo); break; case ELIS_FILES_XFER_FTP: return elis_files_upload_ftp($filename, $filepath, $filemime, $filesize, $uuid, $useadmin); break; default: // TBD // error_log("elis_files_upload_file(): Invalid ELIS files setting for 'file_transfer_method' = {$xfermethod}"); return false; } }
/** * Look for a file * * @param string $search_text The search text entered, which contains tokens * representing either file name or file content * @param int $page The page we are showing the contents for * @param int $categories An array of category ids to filter on (i.e. results * must be in one or more to be included), or NULL to not filter * by category * @return array A data structure equivalent to the return value of "get_listing", * containing the filter listing */ function search($search_text, $page = 1, $categories = NULL) { global $CFG, $COURSE, $OUTPUT, $USER; require_once($CFG->dirroot.'/repository/elisfiles/lib/lib.php'); $ret = array(); $shared = 0; $oid = 0; // Set id if (!empty($USER->id)) { $uid = $USER->id; $cid = 0; } if (!empty($COURSE->id)) { $cid = $COURSE->id; $uid = 0; } // setting userid... if ($this->context->contextlevel === CONTEXT_USER) { $userid = $USER->id; } else { $userid = 0; } $courseid = $COURSE->id; $uuid = false; if ($ruuid = $this->elis_files->get_repository_location($courseid, $userid, $shared, $oid)) { $uuid = $ruuid; } else if ($duuid = $this->elis_files->get_default_browsing_location($courseid, $userid, $shared, $oid)) { $uuid = $duuid; } $uuuid = $this->elis_files->get_user_store($USER->id); if ($uuid == $uuuid) { $uid = $USER->id; } else { $uid = 0; } $canedit = self::check_editing_permissions($COURSE->id, $shared, $oid, $uuid, $uid); $ret['canedit'] = $canedit; $ret['detailcols'] = array(array('field'=>'created', 'title'=>get_string('datecreated','repository_elisfiles')), array('field'=>'modified', 'title'=>get_string('datemodified','repository_elisfiles')), array('field'=>'owner', 'title'=>get_string('modifiedby','repository_elisfiles')) ); $ret['dynload'] = true; $ret['nologin'] = true; $ret['showselectedactions'] = true; $ret['showcurrentactions'] = false; // do not show current actions for search results because we are not in a folder // Can only have either course or user id set if (!empty($cid) && !empty($uid)) { $cid = 0; } // Set permissible browsing locations $ret['locations'] = array(); $this->elis_files->file_browse_options($cid, $uid, $shared, $oid, $ret['locations']); $ret['list'] = array(); // Obtain the list of matching files $query = $this->get_search_query($search_text, $categories); $response = elis_files_utils_invoke_service('/moodle/lucenesearch?searchquery='.rawurlencode($query)); $sxml = RLsimpleXMLelement($response); if ($sxml and $entries = $sxml->xpath('//entry')) { foreach ($entries as $entry) { // Include shared and oid parameters $uuid = (string)$entry->uuid; if ($properties = $this->elis_files->get_info($uuid)) { if (strcmp($properties->type, "cmis:folder") !== 0 && strcmp($properties->type, "folder") !== 0) { $params = array('path'=>$uuid, 'shared'=>(boolean)$shared, 'oid'=>(int)$oid, 'cid'=>(int)$cid, 'uid'=>(int)$uid); $encodedpath = base64_encode(serialize($params)); $filesize = isset($properties->filesize) ? $properties->filesize : ''; $created = isset($properties->created) ? $properties->created : ''; $modified = isset($properties->modified) ? $properties->modified : ''; $owner = isset($properties->owner) ? $properties->owner : ''; $alfresco_version = elis_files_get_repository_version(); if ($alfresco_version == '3.2.1') { $thumbnail = $OUTPUT->pix_url(file_extension_icon($entry->filename, 90))->out(false); } else { $thumbnail = $OUTPUT->pix_url(file_extension_icon($entry->icon, 90))->out(false); } $ret['list'][] = array('title'=>$properties->title, 'path'=>$encodedpath, 'size' => $filesize, 'thumbnail' => $thumbnail, 'datecreated'=>$created, 'datemodified'=>$modified, 'author'=>$owner, 'source'=>$uuid); } } } } return $ret; }
function get_defaults() { // Initialize the alfresco version if (!(self::$version = elis_files_get_repository_version())) { return false; } // Set the file and folder type if (!isset(self::$type_document)) { if (self::is_version('3.2')) { self::$type_folder = 'folder'; self::$type_document = 'document'; } else if (self::is_version('3.4')) { self::$type_folder = 'cmis:folder'; self::$type_document = 'cmis:document'; } } return true; }