本文整理汇总了PHP中add_document函数的典型用法代码示例。如果您正苦于以下问题:PHP add_document函数的具体用法?PHP add_document怎么用?PHP add_document使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_document函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check_and_create_resource_directory
function check_and_create_resource_directory($repository_path, $resource_directory, $resource_directory_name)
{
global $permissions_for_new_directories;
$resource_directory_full_path = substr($repository_path, 0, strlen($repository_path) - 1) . $resource_directory . '/';
if (!is_dir($resource_directory_full_path)) {
if (@mkdir($resource_directory_full_path, $permissions_for_new_directories)) {
// While we are in a course: Registering the newly created folder in the course's database.
if (api_is_in_course()) {
global $_course, $_user;
global $group_properties, $to_group_id;
$group_directory = !empty($group_properties['directory']) ? $group_properties['directory'] : '';
$doc_id = add_document($_course, $group_directory . $resource_directory, 'folder', 0, $resource_directory_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
}
return true;
}
return false;
}
return true;
}
示例2: api_get_path
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
$saveDir = $dirBaseDocuments . $webcamdir;
$current_session_id = api_get_session_id();
$groupId = api_get_group_id();
//Avoid duplicates
$webcamname_to_save = $webcamname;
$title_to_save = str_replace('_', ' ', $webcamname);
$webcamname_noex = basename($webcamname, ".jpg");
if (file_exists($saveDir . '/' . $webcamname_noex . '.' . $ext)) {
$i = 1;
while (file_exists($saveDir . '/' . $webcamname_noex . '_' . $i . '.' . $ext)) {
$i++;
}
$webcamname_to_save = $webcamname_noex . '_' . $i . '.' . $ext;
$title_to_save = $webcamname_noex . '_' . $i . '.' . $ext;
$title_to_save = str_replace('_', ' ', $title_to_save);
}
$documentPath = $saveDir . '/' . $webcamname_to_save;
//read content
//Change to move_uploaded_file() function instead file_get_contents() to adapt the new lib
$content = move_uploaded_file($_FILES['webcam']['tmp_name'], $documentPath);
if (!$content) {
print "PHP ERROR: Failed to read data\n";
exit;
}
//add document to database
$doc_id = 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 get_lang('ClipSent');
示例3: display_document_form
/**
* Returns the form to update or create a document
*
* @param string Action (add/edit)
* @param integer ID of the lp_item (if already exists)
* @param mixed Integer if document ID, string if info ('new')
* @return string HTML form
*/
function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
{
global $charset, $_course;
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
$path_parts = pathinfo($extra_info['dir']);
$no_display_edit_textarea = false;
//If action==edit document
//We don't display the document form if it's not an editable document (html or txt file)
if ($action == "edit") {
if (is_array($extra_info)) {
if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
$no_display_edit_textarea = true;
}
}
}
$no_display_add = false;
//If action==add an existing document
//We don't display the document form if it's not an editable document (html or txt file)
if ($action == "add") {
if (is_numeric($extra_info)) {
$sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info);
$result = Database::query($sql_doc, __FILE__, __LINE__);
$path_file = Database::result($result, 0, 0);
$path_parts = pathinfo($path_file);
if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
$no_display_add = true;
}
}
}
// create css folder
$css_name = api_get_setting('stylesheets');
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm) ? $perm : '0770');
$css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css';
if (!is_dir($css_folder)) {
mkdir($css_folder);
chmod($css_folder, $perm);
$doc_id = add_document($_course, '/css', 'folder', 0, 'css');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
}
if (!file_exists($css_folder . '/templates.css')) {
if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) {
$template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css'));
$template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content);
file_put_contents($css_folder . '/templates.css', $template_content);
}
}
if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
$table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE);
$user_id = api_get_user_id();
// Session used by the ajax request when we are using php 5.3
$_SESSION['dbName'] = $_course['dbName'];
// setting some paths
$img_dir = api_get_path(REL_CODE_PATH) . 'img/';
$default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/';
if (!isset($_GET['resource'])) {
// Load a template into a document
$query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid']));
$result = Database::query($query, __FILE__, __LINE__);
$obj = Database::fetch_object($result);
$valcontent = $obj->content;
$valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty');
if (isset($_GET['tplid']) && $_GET['tplid'] == 0) {
$valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>';
}
$template_css = '';
if (strpos($valcontent, '/css/templates.css') === false) {
$template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />';
}
$js = '';
if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
$js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
$js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL;
if (api_get_setting('show_glossary_in_documents') != 'none') {
$js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>';
if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
$js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
} else {
$js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
}
}
}
$valcontent = str_replace('{CSS}', $template_css . $js, $valcontent);
if (strpos($valcontent, '/css/templates.css') === false) {
$valcontent = str_replace('</head>', $template_css . '</head>', $valcontent);
}
if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
$valcontent = str_replace('</head>', $js . '</head>', $valcontent);
//.........这里部分代码省略.........
示例4: 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 = 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 (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);
}
}
}
}
}
示例5: import_pdfs
/**
* Import PDFs
* @param string Filename
* @param string The subdirectory in which to put the files in each course
*/
function import_pdfs($file, $subDir = '/')
{
$baseDir = api_get_path(SYS_ARCHIVE_PATH);
$uploadPath = 'pdfimport/';
$errors = array();
if (!is_dir($baseDir . $uploadPath)) {
@mkdir($baseDir . $uploadPath);
}
if (!unzip_uploaded_file($_FILES['import_file'], $uploadPath, $baseDir, 1024 * 1024 * 1024)) {
error_log('Could not unzip uploaded file in ' . __FILE__ . ', line ' . __LINE__);
return $errors;
}
$list = scandir($baseDir . $uploadPath);
$i = 0;
foreach ($list as $file) {
if (substr($file, 0, 1) == '.' or !is_file($baseDir . $uploadPath . $file)) {
continue;
}
$parts = preg_split('/_/', $file);
$course = api_get_course_info($parts[0]);
if (count($course) > 0) {
// Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name)
$fileSize = filesize($baseDir . $uploadPath . $file);
$docId = add_document($course, $subDir . '/' . $file, 'file', $fileSize, $parts[1] . ' ' . substr($parts[2], 0, -4));
if ($docId > 0) {
if (!is_file($baseDir . $uploadPath . $file)) {
error_log($baseDir . $uploadPath . $file . ' does not exists in ' . __FILE__);
}
if (is_file(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file)) {
error_log(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file . ' exists at destination in ' . __FILE__);
}
if (!is_writeable(api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir)) {
error_log('Destination ' . api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . ' is NOT writeable in ' . __FILE__);
}
// Place each file in its folder in each course
$move = rename($baseDir . $uploadPath . $file, api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $subDir . '/' . $file);
api_item_property_update($course, TOOL_DOCUMENT, $docId, 'DocumentAdded', api_get_user_id());
// Redo visibility
api_set_default_visibility($docId, TOOL_DOCUMENT);
$errors[] = array('Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']);
// Now add a link to the file from the Course description tool
$link = '<p>Sílabo de la asignatura <a href="' . api_get_path(WEB_CODE_PATH) . 'document/document.php?cidReq=' . $course['code'] . '&id_session=0&gidReq=0&action=download&id=' . $docId . '" target="_blank"><img src="' . api_get_path(WEB_IMG_PATH) . 'icons/32/pdf.png"></a></p>';
$course_description = new CourseDescription();
$session_id = api_get_session_id();
$course_description->set_course_id($course['real_id']);
$course_description->set_session_id($session_id);
$course_description->set_title('Presentación de la asignatura');
$course_description->set_content($link);
$course_description->set_description_type(1);
$course_description->insert();
}
} else {
error_log($parts[0] . ' is not a course, apparently');
$errors[] = array('Line' => 0, 'Code' => $parts[0], 'Title' => $parts[0] . ' - ' . get_lang('CodeDoesNotExists'));
}
$i++;
//found at least one entry that is not a dir or a .
}
if ($i == 0) {
$errors[] = array('Line' => 0, 'Code' => '.', 'Title' => get_lang('NoPDFFoundAtRoot'));
}
return $errors;
}
示例6: 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}\n WHERE c_id = " . $this->course_id . " AND path='" . str_replace($documentPath, '', $audioPath) . '/' . $this->sound . "'";
$result = Database::query($query);
if (!Database::num_rows($result)) {
$id = 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());
item_property_update_on_folder($this->course, str_replace($documentPath, '', $audioPath), api_get_user_id());
}
}
} elseif ($delete && is_file($audioPath . '/' . $this->sound)) {
$this->sound = '';
}
}
示例7: api_get_course_info
$filepath = Security::remove_XSS(urldecode($_GET['filepath']));
$dir = Security::remove_XSS(urldecode($_GET['dir']));
$course_code = Security::remove_XSS(urldecode($_GET['course_code']));
$_course = api_get_course_info($course_code);
$filename = trim($_GET['filename']);
$filename = Security::remove_XSS($filename);
$filename = Database::escape_string($filename);
$filename = api_replace_dangerous_char($filename);
$filename = disable_dangerous_file($filename);
$title = trim(str_replace('_chnano_.', '.', $filename));
//hide nanogong wav tag at title
$title = str_replace('_', ' ', $title);
$documentPath = $filepath . $filename;
if ($nano_user_id != api_get_user_id() || api_get_user_id() == 0 || $nano_user_id == 0) {
echo 'Not allowed';
exit;
}
// Do not use here check Fileinfo method because return: text/plain
if (!file_exists($documentPath)) {
//add document to disk
move_uploaded_file($_FILES['voicefile']['tmp_name'], $documentPath);
//add document to database
$current_session_id = $nano_session_id;
$groupId = $nano_group_id;
$file_size = filesize($documentPath);
$relativeUrlPath = $dir;
$doc_id = add_document($_course, $relativeUrlPath . $filename, 'file', filesize($documentPath), $title);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $nano_user_id, $groupId, null, null, null, $current_session_id);
} else {
return get_lang('FileExistRename');
}
示例8: CreateServerFolder
function CreateServerFolder($folderPath, $lastFolder = null)
{
global $Config;
$sParent = GetParentFolder($folderPath);
// Ensure the folder path has no double-slashes, or mkdir may fail on certain platforms
while (strpos($folderPath, '//') !== false) {
$folderPath = str_replace('//', '/', $folderPath);
}
// Check if the parent exists, or create it.
if (!empty($sParent) && !file_exists($sParent)) {
//prevents agains infinite loop when we can't create root folder
if (!is_null($lastFolder) && $lastFolder === $sParent) {
return "Can't create {$folderPath} directory";
}
$sErrorMsg = CreateServerFolder($sParent, $folderPath);
if ($sErrorMsg != '') {
return $sErrorMsg;
}
}
if (!file_exists($folderPath)) {
// Turn off all error reporting.
error_reporting(0);
$php_errormsg = '';
// Enable error tracking to catch the error.
ini_set('track_errors', '1');
if (isset($Config['ChmodOnFolderCreate']) && !$Config['ChmodOnFolderCreate']) {
mkdir($folderPath);
} else {
$permissions = 0777;
// $permissions = 0770 ;
if (isset($Config['ChmodOnFolderCreate'])) {
$permissions = $Config['ChmodOnFolderCreate'];
}
// To create the folder with 0777 permissions, we need to set umask to zero.
//$oldumask = umask(0) ;
mkdir($folderPath, $permissions);
//umask( $oldumask ) ;
}
// While we are in a course: Registering the newly created folder in the course's database.
if (api_is_in_course()) {
global $_course, $_user;
$repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
$to_group_id = 0;
if (api_is_in_group()) {
global $group_properties;
$to_group_id = $group_properties['id'];
}
$folder_path = preg_replace("/^.*" . TOOL_DOCUMENT . "/", "", $folderPath);
//
$folder_path = preg_replace("/\\/\$/", "", $folder_path);
// should be done in 1 regexp I guess ...
// $folder_path = substr($folderPath, strpos($folderPath, $repository_path) + strlen($repository_path) - 1);
$folder_name = explode('/', $folder_path);
$folder_name = $folder_name[count($folder_name) - 1];
$doc_id = add_document($_course, $folder_path, 'folder', 0, $folder_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], $to_group_id);
}
$sErrorMsg = $php_errormsg;
// Restore the configurations.
ini_restore('track_errors');
ini_restore('error_reporting');
return $sErrorMsg;
} else {
return '';
}
}
示例9: dealPerPage
/**
* Manages page splitting
* @param string Page header
* @param string Page body
* @return void
*/
function dealPerPage($header, $body)
{
$em = Database::getManager();
$_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 = 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', api_get_user_id(), 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.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) {
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
// Save it to db.
$searchEngineRef = new \Chamilo\CoreBundle\Entity\SearchEngineRef();
$searchEngineRef->setCourse($course)->setToolId(TOOL_LEARNPATH)->setRefIdHighLevel($lp_id)->setRefIdSecondLevel($previous)->setSearchDid($did);
$em->persist($searchEngineRef);
$em->flush();
}
}
}
}
}
}
示例10: upload
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
$sessionId = api_get_session_id();
if ($this->allow()) {
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80, '', true);
if (strcmp($name, $filtered) != 0) {
$result = $this->customRename($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);
$documentId = add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']);
api_item_property_update($this->connector->course, TOOL_DOCUMENT, $documentId, 'DocumentAdded', api_get_user_id(), null, null, null, null, $sessionId);
}
//error_log(print_r($this->error(),1));
return $result;
}
return false;
}
示例11: FileUpload
function FileUpload($resourceType, $currentFolder, $sCommand)
{
if (!isset($_FILES)) {
global $_FILES;
}
$sErrorNumber = '0';
$sFileName = '';
if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
global $Config;
$oFile = $_FILES['NewFile'];
// Map the virtual path to the local server path.
$sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
// Get the uploaded file name.
$sFileName = $oFile['name'];
$sFileName = SanitizeFileName($sFileName, $oFile['type']);
$sOriginalFileName = $sFileName;
// Get the extension.
$sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
$sExtension = strtolower($sExtension);
if (isset($Config['SecureImageUploads'])) {
if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
$sErrorNumber = '202';
}
}
if (isset($Config['HtmlExtensions'])) {
if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
$sErrorNumber = '202';
}
}
// Check if it is an allowed extension.
if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
$iCounter = 0;
while (true) {
$sFilePath = $sServerDir . $sFileName;
if (is_file($sFilePath)) {
$iCounter++;
$sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
$sErrorNumber = '0';
// Change $sErrorNumber '201' to '0' to allow create record files renamed
} else {
move_uploaded_file($oFile['tmp_name'], $sFilePath);
if (is_file($sFilePath)) {
if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
break;
}
$permissions = 0777;
if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
$permissions = $Config['ChmodOnUpload'];
}
//$oldumask = umask(0) ;
chmod($sFilePath, $permissions);
//umask( $oldumask ) ;
}
break;
}
}
if (file_exists($sFilePath)) {
//previous checks failed, try once again
if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
@unlink($sFilePath);
$sErrorNumber = '202';
} else {
if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
@unlink($sFilePath);
$sErrorNumber = '202';
}
}
}
} else {
$sErrorNumber = '202';
}
} else {
$sErrorNumber = '202';
}
if ($sErrorNumber == '0') {
// While we are in a course: Registering the newly uploaded file in the course's database.
if (api_is_in_course()) {
global $_course, $_user;
$repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
$to_group_id = 0;
if (api_is_in_group()) {
global $group_properties;
$to_group_id = $group_properties['id'];
}
if (file_exists($sFilePath)) {
$file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
$path = explode('/', $file_path);
$file_name = $path[count($path) - 1];
$path[count($path) - 1] = '';
$folder_path = '/' + implode('/', $path);
$file_size = @filesize($sFilePath);
$doc_id = add_document($_course, $file_path, 'file', $file_size, $file_name);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
item_property_update_on_folder($_course, $folder_path, $_user['user_id']);
}
}
}
$sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
$sFileUrl = CombinePaths($sFileUrl, $sFileName);
SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
//.........这里部分代码省略.........
示例12: 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 = 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 = 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;
}
}
}
示例13: get_lang
}
//if the size is not defined, it's probably because there has been an error or no file was submitted
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']));
$fld = GenerateHpFolder($document_sys_path . $uploadPath . '/');
@mkdir($document_sys_path . $uploadPath . '/' . $fld, api_get_permissions_for_new_directories());
$doc_id = 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 (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');
my_delete($document_sys_path . $uploadPath . '/' . $fld . '/' . $filename);
示例14: _processFiles
/**
* Process upload files. The file must be an
* uploaded file. If 'validate_images' is set to
* true, only images will be processed. Any duplicate
* file will be renamed. See Files::copyFile for details
* on renaming.
* @param string $relative the relative path where the file
* should be copied to.
* @param array $file the uploaded file from $_FILES
* @return boolean true if the file was processed successfully,
* false otherwise
*/
function _processFiles($relative, $file)
{
global $_course;
if ($file['error'] != 0) {
return false;
}
if (!is_file($file['tmp_name'])) {
return false;
}
if (!is_uploaded_file($file['tmp_name'])) {
Files::delFile($file['tmp_name']);
return false;
}
$file['name'] = replace_dangerous_char($file['name'], 'strict');
$file_name = $file['name'];
$extension = explode('.', $file_name);
$count = count($extension);
if ($count == 1) {
$extension = '';
} else {
$extension = strtolower($extension[$count - 1]);
}
// Checking for image by file extension first, using the configuration file.
if (!in_array($extension, $this->config['accepted_extensions'])) {
Files::delFile($file['tmp_name']);
return false;
}
// Second, filtering using a special function of the system.
$result = filter_extension($file_name);
if ($result == 0 || $file_name != $file['name']) {
Files::delFile($file['tmp_name']);
return false;
}
// Checking for a valid image by reading binary file (partially in most cases).
if ($this->config['validate_images']) {
$imgInfo = @getImageSize($file['tmp_name']);
if (!is_array($imgInfo)) {
Files::delFile($file['tmp_name']);
return false;
}
}
//now copy the file
$path = Files::makePath($this->getBaseDir(), $relative);
$result = Files::copyFile($file['tmp_name'], $path, $file['name']);
//no copy error
if (!is_int($result)) {
if (isset($_course) && !empty($_course) && isset($_course['code'])) {
//adding the document to the DB
global $to_group_id;
// looking for the /document/ folder
$document_path = substr($path, strpos($path, '/document/') + 9, strlen($path));
// /shared_folder/4/name
$document_path .= $result;
$chamiloFile = $file['name'];
$chamiloFileSize = $file['size'];
if (!empty($group_properties['directory'])) {
$chamiloFolder = $group_properties['directory'] . $chamiloFolder;
}
$doc_id = add_document($_course, $document_path, 'file', $chamiloFileSize, $chamiloFile);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $to_group_id, null, null, null, api_get_session_id());
}
$dimensionsIndex = isset($_REQUEST['uploadSize']) ? $_REQUEST['uploadSize'] : 0;
// If maximum size is specified, constrain image to it.
if ($this->config['maxWidth'][$dimensionsIndex] > 0 && $this->config['maxHeight'][$dimensionsIndex] > 0) {
$img = Image_Transform::factory(IMAGE_CLASS);
$img->load($path . $result);
// image larger than max dimensions?
if ($img->img_x > $this->config['maxWidth'][$dimensionsIndex] || $img->img_y > $this->config['maxHeight'][$dimensionsIndex]) {
$percentage = min($this->config['maxWidth'][$dimensionsIndex] / $img->img_x, $this->config['maxHeight'][$dimensionsIndex] / $img->img_y);
$img->scale($percentage);
}
$img->save($path . $result);
$img->free();
}
}
// Delete tmp files.
Files::delFile($file['tmp_name']);
return false;
}
示例15: str_replace
$rows = str_replace(")(", "),(", $rows);
//pone comas en cada fila
$new_field_name = $column_new['meta_data_new_table']['field_name'];
$new_table_name = $column_new['meta_data_new_table']['table_name'];
$result = $link->query("INSERT INTO {$name_db_new}.{$new_table_name} ( {$new_field_name} ) VALUES {$rows}");
if ($result) {
echo "<br>Exito {$new_table_name}";
} else {
echo "<br>Error {$new_table_name}" . mysqli_error($link);
}
$offset = $offset + $cantidad_new_table;
//paginador de registros
}
} else {
if ($new_table['is_document'] == 'true' and $new_table['new_table'] == false) {
add_document($table_name, $link, $name_db_new, $name_db_old, $db_old[$name_db_old][$table_name], $new_table['num_consultas']);
exit;
} else {
if (isset($column_new['relations']) and $new_table['new_table'] != false) {
$columns_old .= $column_old . ",";
$columns_new .= $columns[$column_old]['relations']['fk_name'] . ",";
} else {
$columns_old .= $column_old . ",";
$columns_new .= $column_new . ",";
}
}
}
}
$columns_old = rtrim($columns_old, ',');
//quita última coma (,)
$columns_new = rtrim($columns_new, ',');