本文整理汇总了PHP中FileManager::add_document方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::add_document方法的具体用法?PHP FileManager::add_document怎么用?PHP FileManager::add_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::add_document方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80);
if (strcmp($name, $filtered) != 0) {
/*$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);*/
$this->rename($result['hash'], $filtered);
}
$realPath = $this->realpath($result['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
\FileManager::add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']);
}
return $result;
}
示例2: add_audio
function add_audio()
{
$course_info = api_get_course_info();
$filepath = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/';
if (!is_dir($filepath . 'audio')) {
mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
$audio_id = FileManager::add_document($course_info, '/audio', 'folder', 0, 'audio');
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
}
$key = 'file';
if (!isset($_FILES[$key]['name']) || !isset($_FILES[$key]['tmp_name'])) {
return false;
}
$result = DocumentManager::upload_document($_FILES, '/audio', null, null, 0, 'rename', false, false);
$file_path = null;
if ($result) {
$file_path = basename($result['path']);
// Store the mp3 file in the lp_item table.
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql_insert_audio = "UPDATE {$tbl_lp_item} SET audio = '" . Database::escape_string($file_path) . "'\n WHERE c_id = {$course_info['real_id']} AND id = '" . Database::escape_string($this->db_id) . "'";
Database::query($sql_insert_audio);
}
return $file_path;
}
示例3: replace_urls_inside_content_html_from_copy_course
/**
* Replace urls inside content html from a copy course
* @param string content html
* @param string origin course code
* @param string destination course directory
* @return string new content html with replaced urls or return false if content is not a string
*/
static function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory, $origin_course_path_from_zip = null, $origin_course_info_path = null)
{
if (empty($content_html)) {
return false;
}
$orig_source_html = DocumentManager::get_resources_from_source_html($content_html);
$orig_course_info = api_get_course_info($origin_course_code);
//Course does not exist in the current DB probably this cames from a zip file?
if (empty($orig_course_info)) {
if (!empty($origin_course_path_from_zip)) {
$orig_course_path = $origin_course_path_from_zip . '/';
$orig_course_info_path = $origin_course_info_path;
}
} else {
$orig_course_path = api_get_path(SYS_PATH) . 'courses/' . $orig_course_info['path'] . '/';
$orig_course_info_path = $orig_course_info['path'];
}
$destination_course_code = CourseManager::get_course_id_from_path($destination_course_directory);
$destination_course_info = api_get_course_info($destination_course_code);
$dest_course_path = api_get_path(SYS_COURSE_PATH) . $destination_course_directory . '/';
$user_id = api_get_user_id();
if (!empty($orig_source_html)) {
foreach ($orig_source_html as $source) {
// get information about source url
$real_orig_url = $source[0];
// url
$scope_url = $source[1];
// scope (local, remote)
$type_url = $source[2];
// tyle (rel, abs, url)
// Get path and query from origin url
$orig_parse_url = parse_url($real_orig_url);
$real_orig_path = isset($orig_parse_url['path']) ? $orig_parse_url['path'] : null;
$real_orig_query = isset($orig_parse_url['query']) ? $orig_parse_url['query'] : null;
// Replace origin course code by destination course code from origin url query
$dest_url_query = '';
if (!empty($real_orig_query)) {
$dest_url_query = '?' . $real_orig_query;
if (strpos($dest_url_query, $origin_course_code) !== false) {
$dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query);
}
}
if ($scope_url == 'local') {
if ($type_url == 'abs' || $type_url == 'rel') {
$document_file = strstr($real_orig_path, 'document');
if (strpos($real_orig_path, $document_file) !== false) {
$origin_filepath = $orig_course_path . $document_file;
$destination_filepath = $dest_course_path . $document_file;
// copy origin file inside destination course
if (file_exists($origin_filepath)) {
$filepath_dir = dirname($destination_filepath);
if (!is_dir($filepath_dir)) {
$perm = api_get_permissions_for_new_directories();
$result = @mkdir($filepath_dir, $perm, true);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $filepath_dir);
//Add to item properties to the new folder
$doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'folder', 0, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
if (!file_exists($destination_filepath)) {
$result = @copy($origin_filepath, $destination_filepath);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $destination_filepath);
$size = filesize($destination_filepath);
//Add to item properties to the file
$doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'file', $size, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
}
// Replace origin course path by destination course path
if (strpos($content_html, $real_orig_url) !== false) {
//$origin_course_code
$url_course_path = str_replace($orig_course_info_path . '/' . $document_file, '', $real_orig_path);
$destination_url = $url_course_path . $destination_course_directory . '/' . $document_file . $dest_url_query;
//If the course code doesn't exist in the path? what we do? Nothing! see BT#1985
if (strpos($real_orig_path, $origin_course_code) === false) {
$url_course_path = $real_orig_path;
$destination_url = $real_orig_path;
}
$content_html = str_replace($real_orig_url, $destination_url, $content_html);
}
}
// replace origin course code by destination course code from origin url
if (strpos($real_orig_url, '?') === 0) {
$dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url);
$content_html = str_replace($real_orig_url, $dest_url, $content_html);
}
} else {
if ($type_url == 'url') {
}
//.........这里部分代码省略.........
示例4: get_lang
if (!$_FILES['userFile']['size']) {
$dialogBox .= get_lang('SendFileError') . '<br />' . get_lang('Notice') . ' : ' . get_lang('MaxFileSize') . ' ' . ini_get('upload_max_filesize');
} else {
$unzip = 0;
if (preg_match('/\\.zip$/i', $_FILES['userFile']['name'])) {
//if it's a zip, allow zip upload
$unzip = 1;
}
if ($finish == 0) {
// Generate new test folder if on first step of file upload.
$filename = api_replace_dangerous_char(trim($_FILES['userFile']['name']), 'strict');
$fld = GenerateHpFolder($document_sys_path . $uploadPath . '/');
//$doc_id = FileManager::add_document($_course, '/HotPotatoes_files/'.$fld, 'folder', 0, $fld);
//api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
@mkdir($document_sys_path . $uploadPath . '/' . $fld, api_get_permissions_for_new_directories());
$doc_id = FileManager::add_document($_course, '/HotPotatoes_files/' . $fld, 'folder', 0, $fld);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
} else {
// It is not the first step... get the filename directly from the system params.
$filename = $_FILES['userFile']['name'];
}
$allow_output_on_success = false;
if (FileManager::handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath . '/' . $fld, api_get_user_id(), null, null, $unzip, '', $allow_output_on_success)) {
if ($finish == 2) {
$imgparams = $_POST['imgparams'];
$checked = CheckImageName($imgparams, $filename);
if ($checked) {
$imgcount = $imgcount - 1;
} else {
$dialogBox .= $filename . ' ' . get_lang('NameNotEqual');
FileManager::my_delete($document_sys_path . $uploadPath . '/' . $fld . '/' . $filename);
示例5: downloadMP3_pediaphon
/**
* This function save a post into a file mp3 from pediaphon services
*
* @param $filepath
* @param $dir
* @author Juan Carlos Raña Trabado <herodoto@telefonica.net>
* @version january 2011, chamilo 1.8.8
*/
function downloadMP3_pediaphon($filepath, $dir)
{
$location = 'create_audio.php?' . api_get_cidreq() . '&id=' . Security::remove_XSS($_POST['document_id']) . '&dt2a=pediaphon';
//security
if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
echo '<script>window.location.href="' . $location . '"</script>';
return;
}
global $_user;
$_course = api_get_course_info();
$clean_title = trim($_POST['title']);
$clean_title = Database::escape_string($clean_title);
$clean_text = trim($_POST['text']);
$clean_voices = Security::remove_XSS($_POST['voices']);
if (empty($clean_title) || empty($clean_text) || empty($clean_voices)) {
echo '<script>window.location.href="' . $location . '"</script>';
return;
}
$clean_title = Security::remove_XSS($clean_title);
$clean_title = Database::escape_string($clean_title);
$clean_title = str_replace(' ', '_', $clean_title);
//compound file names
$clean_text = Security::remove_XSS($clean_text);
$clean_lang = Security::remove_XSS($_POST['lang']);
$clean_speed = Security::remove_XSS($_POST['speed']);
$extension = 'mp3';
$audio_filename = $clean_title . '.' . $extension;
$audio_title = str_replace('_', ' ', $clean_title);
//prevent duplicates
if (file_exists($filepath . '/' . $clean_title . '.' . $extension)) {
$i = 1;
while (file_exists($filepath . '/' . $clean_title . '_' . $i . '.' . $extension)) {
$i++;
}
$audio_filename = $clean_title . '_' . $i . '.' . $extension;
$audio_title = $clean_title . '_' . $i . '.' . $extension;
$audio_title = str_replace('_', ' ', $audio_title);
}
$documentPath = $filepath . '/' . $audio_filename;
//prev for a fine unicode, borrowed from main api TODO:clean
// Safe replacements for some non-letter characters (whitout blank spaces)
$search = array("", "\t", "\n", "\r", "\v", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
$replace = array('', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
$filename = $clean_text;
// Encoding detection.
$encoding = api_detect_encoding($filename);
// Converting html-entities into encoded characters.
$filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
// Transliteration to ASCII letters, they are not dangerous for filesystems.
$filename = api_transliterate($filename, 'x', $encoding);
// Replacing remaining dangerous non-letter characters.
$clean_text = str_replace($search, $replace, $filename);
//adding the file
if ($clean_lang == 'de') {
$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
$find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/(.*)\\.mp3\\"/';
} else {
$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_' . $clean_lang . '.cgi';
//en, es, fr
$find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/' . $clean_lang . '\\/(.*)\\.mp3\\"/';
}
$data = "stimme=" . $clean_voices . "&inputtext=" . $clean_text . "&speed=" . $clean_speed . "&go=go";
$opts = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", "Content-Length: " . strlen($data) . "\r\n", 'content' => $data));
$context = stream_context_create($opts);
$previous_returntext2voice = file_get_contents($url_pediaphon, false, $context);
//clean file contents
$search_source = preg_match($find_t2v, $previous_returntext2voice, $hits);
$souce_end = substr($hits[0], 0, -1);
$returntext2voice = file_get_contents($souce_end);
//make a temporal file for get the file size
$tmpfname = tempnam("/tmp", "CTF");
$handle = fopen($tmpfname, "w");
fwrite($handle, $returntext2voice);
fclose($handle);
// Check if there is enough space in the course to save the file
if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) {
unlink($tmpfname);
die(get_lang('UplNotEnoughSpace'));
}
//erase temporal file
unlink($tmpfname);
//save file
file_put_contents($documentPath, $returntext2voice);
//add document to database
$current_session_id = api_get_session_id();
$groupId = $_SESSION['_gid'];
$file_size = filesize($documentPath);
$relativeUrlPath = $dir;
$doc_id = FileManager::add_document($_course, $relativeUrlPath . $audio_filename, 'file', filesize($documentPath), $audio_title);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
Display::display_confirmation_message(get_lang('DocumentCreated'));
//return to location
//.........这里部分代码省略.........
示例6: dealPerPage
/**
* Manages page splitting
* @param string Page header
* @param string Page body
* @return void
*/
function dealPerPage($header, $body)
{
$_course = api_get_course_info();
// Split document to pages.
$pages = explode('||page_break||', $body);
$first_item = 0;
foreach ($pages as $key => $page_content) {
// For every pages, we create a new file.
$key += 1;
$page_content = $this->format_page_content($header, $page_content, $this->base_work_dir . $this->created_dir);
$html_file = $this->created_dir . '-' . $key . '.html';
$handle = fopen($this->base_work_dir . $this->created_dir . '/' . $html_file, 'w+');
fwrite($handle, $page_content);
fclose($handle);
$document_id = FileManager::add_document($_course, $this->created_dir . $html_file, 'file', filesize($this->base_work_dir . $this->created_dir . $html_file), $html_file);
$slide_name = '';
if ($document_id) {
// Put the document in item_property update.
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_SESSION['_uid'], 0, 0, null, null, api_get_session_id());
$infos = pathinfo($this->filepath);
$slide_name = 'Page ' . str_repeat('0', 2 - strlen($key)) . $key;
$previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, '');
if ($this->first_item == 0) {
$this->first_item = $previous;
}
// Code for text indexing.
if (api_get_setting('search_enabled') == 'true') {
if (isset($_POST['index_document']) && $_POST['index_document']) {
//Display::display_normal_message(print_r($_POST));
$di = new ChamiloIndexer();
isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : ($lang = 'english');
$di->connectDb(null, null, $lang);
$ic_slide = new IndexableChunk();
$ic_slide->addValue('title', $slide_name);
$specific_fields = get_specific_field_list();
$all_specific_terms = '';
foreach ($specific_fields as $specific_field) {
if (isset($_REQUEST[$specific_field['code']])) {
$sterms = trim($_REQUEST[$specific_field['code']]);
$all_specific_terms .= ' ' . $sterms;
if (!empty($sterms)) {
$sterms = explode(',', $sterms);
foreach ($sterms as $sterm) {
$ic_slide->addTerm(trim($sterm), $specific_field['code']);
}
}
}
}
$page_content = $all_specific_terms . ' ' . $page_content;
$ic_slide->addValue('content', $page_content);
// Add a comment to say terms separated by commas.
$courseid = api_get_course_id();
$ic_slide->addCourseId($courseid);
$ic_slide->addToolId(TOOL_LEARNPATH);
$lp_id = $this->lp_id;
$xapian_data = array(SE_COURSE_ID => $courseid, SE_TOOL_ID => TOOL_LEARNPATH, SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id), SE_USER => (int) api_get_user_id());
$ic_slide->xapian_data = serialize($xapian_data);
$di->addChunk($ic_slide);
// Index and return search engine document id.
$did = $di->index();
if ($did) {
// Save it to db.
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did)
VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)';
$sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did);
Database::query($sql);
}
}
}
}
}
}
示例7: exportPicture
/**
* Exports a picture to another question
*
* @author - Olivier Brouckaert
* @param integer $questionId - ID of the target question
* @return boolean - true if copied, otherwise false
*/
public function exportPicture($questionId, $course_info)
{
$course_id = $course_info['real_id'];
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$destination_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/images';
$source_path = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . '/document/images';
// if the question has got an ID and if the picture exists
if ($this->id && !empty($this->picture)) {
$picture = explode('.', $this->picture);
$extension = $picture[sizeof($picture) - 1];
$picture = 'quiz-' . $questionId . '.' . $extension;
$result = @copy($source_path . '/' . $this->picture, $destination_path . '/' . $picture) ? true : false;
//If copy was correct then add to the database
if ($result) {
$sql = "UPDATE {$TBL_QUESTIONS} SET picture='" . Database::escape_string($picture) . "'\n WHERE c_id = {$course_id} AND iid='" . intval($questionId) . "'";
Database::query($sql);
$document_id = FileManager::add_document($course_info, '/images/' . $picture, 'file', filesize($destination_path . '/' . $picture), $picture);
if ($document_id) {
return api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id());
}
}
return $result;
}
return false;
}
示例8: create_document
/**
* Create a new document //still needs some finetuning
* @param array $_course
* @return string
*/
public function create_document($_course)
{
$course_id = api_get_course_int_id();
global $charset;
$dir = isset($_GET['dir']) ? $_GET['dir'] : $_POST['dir'];
// Please, do not modify this dirname formatting.
if (strstr($dir, '..')) {
$dir = '/';
}
if ($dir[0] == '.') {
$dir = substr($dir, 1);
}
if ($dir[0] != '/') {
$dir = '/' . $dir;
}
if ($dir[strlen($dir) - 1] != '/') {
$dir .= '/';
}
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $dir;
if (empty($_POST['dir']) && empty($_GET['dir'])) {
//Generates folder
$result = $this->generate_lp_folder($_course);
$dir = $result['dir'];
$filepath = $result['filepath'];
}
if (!is_dir($filepath)) {
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
$dir = '/';
}
// stripslashes() before calling api_replace_dangerous_char() because $_POST['title']
// is already escaped twice when it gets here.
$title = api_replace_dangerous_char(stripslashes($_POST['title']));
$title = FileManager::disable_dangerous_file($title);
$filename = $title;
$content = $_POST['content_lp'];
$tmp_filename = $filename;
$i = 0;
while (file_exists($filepath . $tmp_filename . '.html')) {
$tmp_filename = $filename . '_' . ++$i;
}
$filename = $tmp_filename . '.html';
$content = stripslashes($content);
$content = str_replace(api_get_path(WEB_COURSE_PATH), api_get_path(REL_PATH) . 'courses/', $content);
// Change the path of mp3 to absolute.
// The first regexp deals with ../../../ urls.
$content = preg_replace("|(flashvars=\"file=)(\\.+/)+|", "\$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/', $content);
// The second regexp deals with audio/ urls.
$content = preg_replace("|(flashvars=\"file=)([^/]+)/|", "\$1" . api_get_path(REL_COURSE_PATH) . $_course['path'] . '/document/$2/', $content);
// For flv player: To prevent edition problem with firefox, we have to use a strange tip (don't blame me please).
$content = str_replace('</body>', '<style type="text/css">body{}</style></body>', $content);
if (!file_exists($filepath . $filename)) {
if ($fp = @fopen($filepath . $filename, 'w')) {
fputs($fp, $content);
fclose($fp);
$file_size = filesize($filepath . $filename);
$save_file_path = $dir . $filename;
$document_id = FileManager::add_document($_course, $save_file_path, 'file', $file_size, $tmp_filename);
if ($document_id) {
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), null, null, null, null, api_get_session_id());
$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
if ($new_comment || $new_title) {
$tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_comment) {
$ct .= ", comment='" . Database::escape_string($new_comment) . "'";
}
if ($new_title) {
$ct .= ", title='" . Database::escape_string(htmlspecialchars($new_title, ENT_QUOTES, $charset)) . "' ";
}
$sql_update = "UPDATE " . $tbl_doc . " SET " . substr($ct, 1) . " WHERE c_id = " . $course_id . " AND id = " . $document_id;
Database::query($sql_update);
}
}
return $document_id;
}
}
}
示例9: IN
}
if (count($lp_items_to_remove_audio) > 0) {
$sql = "UPDATE {$tbl_lp_item} SET audio = '' WHERE c_id = {$course_id} AND id IN (" . $in . ")";
$result = Database::query($sql);
}
// Uploading the audio files.
foreach ($_FILES as $key => $value) {
if (substr($key, 0, 7) == 'mp3file' and !empty($_FILES[$key]['tmp_name'])) {
// The id of the learning path item.
$lp_item_id = str_ireplace('mp3file', '', $key);
// Create the audio folder if it does not exist yet.
$_course = api_get_course_info();
$filepath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/';
if (!is_dir($filepath . 'audio')) {
mkdir($filepath . 'audio', api_get_permissions_for_new_directories());
$audio_id = FileManager::add_document($_course, '/audio', 'folder', 0, 'audio');
api_item_property_update($_course, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
}
// Check if file already exits into document/audio/
$file_name = $_FILES[$key]['name'];
$file_name = stripslashes($file_name);
// Add extension to files without one (if possible).
$file_name = FileManager::add_ext_on_mime($file_name, $_FILES[$key]['type']);
$clean_name = api_replace_dangerous_char($file_name);
// No "dangerous" files.
$clean_name = FileManager::disable_dangerous_file($clean_name);
$check_file_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/audio/' . $clean_name;
// If the file exists we generate a new name.
if (file_exists($check_file_path)) {
$filename_components = explode('.', $clean_name);
// Gettting the extension of the file.
示例10: add_docs_to_visio
function add_docs_to_visio($files = array())
{
$_course = api_get_course_info();
foreach ($files as $file) {
list($slide_name, $file_name) = explode('||', $file);
// '||' is used as separator between slide name (with accents) and file name (without accents).
$slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset);
$slide_name = str_replace('’', '\'', $slide_name);
$slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset);
$slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding());
$did = FileManager::add_document($_course, $this->created_dir . '/' . urlencode($file_name), 'file', filesize($this->base_work_dir . $this->created_dir . '/' . $file_name), $slide_name);
if ($did) {
api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, null, null, null, api_get_session_id());
}
}
}
示例11: export2doc
/**
* Function export last wiki page version to document area
* @author Juan Carlos Raña <herodoto@telefonica.net>
*/
function export2doc($doc_id)
{
$_course = api_get_course_info();
$groupId = api_get_group_id();
$session_id = api_get_session_id();
$data = get_wiki_data($doc_id);
if (empty($data)) {
return false;
}
$wikiTitle = $data['title'];
$wikiContents = $data['content'];
$template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}">
<head>
<title>{TITLE}</title>
<meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
<style type="text/css" media="screen, projection">
/*<![CDATA[*/
{CSS}
/*]]>*/
</style>
{ASCIIMATHML_SCRIPT}</head>
<body dir="{TEXT_DIRECTION}">
{CONTENT}
</body>
</html>';
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH) . api_get_setting('stylesheets') . '/default.css';
if (file_exists($css_file)) {
$css = @file_get_contents($css_file);
} else {
$css = '';
}
// Fixing some bugs in css files.
$root_rel = api_get_path(REL_PATH);
$css_path = 'main/css/';
$theme = api_get_setting('stylesheets') . '/';
$css = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css);
$css = str_replace('main/', $root_rel . 'main/', $css);
$css = str_replace('images/', $root_rel . $css_path . $theme . 'images/', $css);
$css = str_replace('../../img/', $root_rel . 'main/img/', $css);
$asciimathmal_script = Text::api_contains_asciimathml($wikiContents) || Text::api_contains_asciisvg($wikiContents) ? '<script src="' . api_get_path(TO_REL, SCRIPT_ASCIIMATHML) . '" type="text/javascript"></script>' . "\n" : '';
$template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}'), array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script), $template);
if (0 != $groupId) {
$groupPart = '_group' . $groupId;
// and add groupId to put the same document title in different groups
$group_properties = GroupManager::get_group_properties($groupId);
$groupPath = $group_properties['directory'];
} else {
$groupPart = '';
$groupPath = '';
}
$exportDir = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/document' . $groupPath;
$exportFile = api_replace_dangerous_char($wikiTitle, 'strict') . $groupPart;
//$clean_wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents));
//$array_clean_wikiContents= explode('|', $clean_wikiContents);
$wikiContents = trim(preg_replace("/\\[[\\[]?([^\\]|]*)[|]?([^|\\]]*)\\][\\]]?/", "\$1", $wikiContents));
//TODO: put link instead of title
$wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
// replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents
if (api_strpos($wikiContents, '../../courses/') !== false) {
$web_course_path = api_get_path(WEB_COURSE_PATH);
$wikiContents = str_replace('../../courses/', $web_course_path, $wikiContents);
}
$doc_id = 0;
$i = 1;
while (file_exists($exportDir . '/' . $exportFile . '_' . $i . '.html')) {
$i++;
}
//only export last version, but in new export new version in document area
$wikiFileName = $exportFile . '_' . $i . '.html';
$exportPath = $exportDir . '/' . $wikiFileName;
file_put_contents($exportPath, $wikiContents);
$doc_id = FileManager::add_document($_course, $groupPath . '/' . $wikiFileName, 'file', filesize($exportPath), $wikiTitle);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId);
return $doc_id;
// TODO: link to go document area
}
示例12: gmdate
}
}
if ($is_our_server) {
if (api_get_setting('service_visio', 'active') == 'true') {
//check encryption key
$string1 = $_GET['course_code'] . $_GET['user_id'] . gmdate('Ymd') . $_configuration['security_key'];
$string2 = $_GET['course_code'] . $_GET['user_id'] . (gmdate('Ymd') - 1) . $_configuration['security_key'];
if (md5($string1) == $_GET['checker'] or md5($string2) == $_GET['checker']) {
$course_info = api_get_course_info($_GET['course_code']);
$target = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/audio/';
$basename = basename($_FILES['file']['name']);
$target = $target . $basename;
if (!move_uploaded_file($_FILES['file']['tmp_name'], $target)) {
error_log(__FILE__ . ':' . __LINE__ . ': File upload to ' . $target . ' failed', 0);
} else {
$id = FileManager::add_document($course_info, '/audio/' . $basename, 'file', filesize($target), $basename);
if ($id !== false) {
$res = api_item_property_update($course_info, TOOL_DOCUMENT, $id, 'DocumentAdded', $_GET['user_id']);
if ($res === false) {
error_log(__FILE__ . ':' . __LINE__ . ': Something went wrong with item properties update of ' . $target, 0);
} else {
//make sound invisible?
//$res = api_item_property_update($course_info,TOOL_DOCUMENT,$id,'invisible',$_GET['user_id']);
}
} else {
error_log(__FILE__ . ':' . __LINE__ . ': Could not create document record for document ' . $target, 0);
}
}
} else {
error_log(__FILE__ . ':' . __LINE__ . ': Attempting to save file but hash check did not suceed (hacking attempt?)', 0);
}
示例13: updateSound
/**
* changes the exercise sound file
*
* @author - Olivier Brouckaert
* @param - string $sound - exercise sound file
* @param - string $delete - ask to delete the file
*/
public function updateSound($sound, $delete)
{
global $audioPath, $documentPath;
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
if ($sound['size'] && (strstr($sound['type'], 'audio') || strstr($sound['type'], 'video'))) {
$this->sound = $sound['name'];
if (@move_uploaded_file($sound['tmp_name'], $audioPath . '/' . $this->sound)) {
$query = "SELECT 1 FROM {$TBL_DOCUMENT} WHERE c_id = " . $this->course_id . " AND path='" . str_replace($documentPath, '', $audioPath) . '/' . $this->sound . "'";
$result = Database::query($query);
if (!Database::num_rows($result)) {
$id = FileManager::add_document($this->course, str_replace($documentPath, '', $audioPath) . '/' . $this->sound, 'file', $sound['size'], $sound['name']);
api_item_property_update($this->course, TOOL_DOCUMENT, $id, 'DocumentAdded', api_get_user_id());
FileManager::item_property_update_on_folder($this->course, str_replace($documentPath, '', $audioPath), api_get_user_id());
}
}
} elseif ($delete && is_file($audioPath . '/' . $this->sound)) {
$this->sound = '';
}
}
示例14: str_replace
$title_to_save = str_replace('_', ' ', $title_to_save);
}
$documentPath = $saveDir . '/' . $webcamname_to_save;
//read content
$content = file_get_contents('php://input');
if (!$content) {
print "ERROR: Failed to read data\n";
exit;
}
//make a temporal file for get the file size
$tmpfname = tempnam("/tmp", "CTF");
$handle = fopen($tmpfname, "w");
fwrite($handle, $content);
fclose($handle);
// Check if there is enough space in the course to save the file
if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) {
unlink($tmpfname);
die(get_lang('UplNotEnoughSpace'));
}
//erase temporal file
unlink($tmpfname);
//add to disk
$fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
//add document to database
$doc_id = FileManager::add_document($_course, $webcamdir . '/' . $webcamname_to_save, 'file', filesize($documentPath), $title_to_save);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
///
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $documentPath;
print "{$url}\n";
示例15: elseif
} elseif ($currentTool == 'document/editpaint') {
$documentPath = $saveDir . '/' . $paintFileName;
//add new document to disk
file_put_contents($documentPath, $contents);
//check path
if (!isset($_SESSION['paint_file'])) {
api_not_allowed();
die;
}
if ($_SESSION['paint_file'] == $paintFileName) {
$document_id = DocumentManager::get_document_id($_course, $relativeUrlPath . '/' . $paintFileName);
FileManager::update_existing_document($_course, $document_id, filesize($documentPath), null);
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $_user['user_id'], $groupId, null, null, null, $current_session_id);
} else {
//add a new document
$doc_id = FileManager::add_document($_course, $relativeUrlPath . '/' . $paintFileName, 'file', filesize($documentPath), $title);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
}
}
//delete temporal file
$temp_file_2delete = $_SESSION['temp_realpath_image'];
unlink($temp_file_2delete);
//Clean sessions and return to Chamilo file list
unset($_SESSION['paint_dir']);
unset($_SESSION['paint_file']);
unset($_SESSION['whereami']);
unset($_SESSION['temp_realpath_image']);
if (!isset($_SESSION['exit_pixlr'])) {
$location = api_get_path(WEB_CODE_PATH) . 'document/document.php';
echo '<script>window.parent.location.href="' . $location . '"</script>';
api_not_allowed(true);