/i", $tag_list[$count])) {
$replace_by[$count] = " $param_name =\"showinframes.php?file=" . $upload_path.$file_path_list[$count]."\" target=\"_self\" ";
} else {
$replace_by[$count] = " $param_name =\"download.php?doc_url=" . $upload_path.$file_path_list[$count]."\" ";
}
} else {
// "mailto" or url already fixed, leave as is
//$message .= "Already fixed or contains mailto: ";
$replace_by[$count] = $replace_what[$count];
}
} elseif ($is_absolute_hyperlink) {
//$message .= "Absolute hyperlink, don't change, add target=_self: ";
$replace_by[$count] = " $param_name=\"" . $file_path_list[$count] . "\" target =\"_self\"";
} else {
// Don't change anything
//$message .= "Local anchor, don't change: ";
$replace_by[$count] = $replace_what[$count];
}
//$message .= "In tag $count, " . htmlentities($tag_list[$count])
// . ", parameter " . $replace_what[$count] . " replaced by " . $replace_by[$count] . "
"; //debug
}
//if ($message) api_display_debug_info($message); //debug
$buffer = str_replace($replace_what, $replace_by, $buffer);
return $buffer;
}
/**
* Checks the extension of a file, if it's .htm or .html
* we use search_img_from_html to get all image paths in the file
*
* @param string $file
* @return array paths
* @see check_for_missing_files() uses search_img_from_html()
*/
function check_for_missing_files($file) {
if (strrchr($file, '.') == '.htm' || strrchr($file, '.') == '.html') {
$img_file_path = search_img_from_html($file);
return $img_file_path;
}
return false;
}
/**
* This function builds a form that asks for the missing images in a html file
* maybe we should do this another way?
*
* @param array $missing_files
* @param string $upload_path
* @param string $file_name
* @return string the form
*/
function build_missing_files_form($missing_files, $upload_path, $file_name) {
// Do we need a / or not?
$added_slash = ($upload_path == '/') ? '' : '/';
$folder_id = DocumentManager::get_document_id(api_get_course_info(), $upload_path);
// Build the form
$form .= "".get_lang('MissingImagesDetected')."
"
."";
return $form;
}
/**
* This recursive function can be used during the upgrade process form older versions of Chamilo
* It crawls the given directory, checks if the file is in the DB and adds it if it's not
*
* @param string $base_work_dir
* @param string $current_path, needed for recursivity
*/
function add_all_documents_in_folder_to_database($_course, $user_id, $base_work_dir, $current_path = '', $to_group_id = 0) {
$current_session_id = api_get_session_id();
$path = $base_work_dir.$current_path;
// Open dir
$handle = opendir($path);
if (is_dir($path)) {
// Run trough
while ($file = readdir($handle)) {
if ($file == '.' || $file == '..') continue;
$completepath = "$path/$file";
// Directory?
if (is_dir($completepath)) {
$title = get_document_title($file);
$safe_file = replace_dangerous_char($file);
@rename($path.'/'.$file, $path.'/'.$safe_file);
// If we can't find the file, add it
if (!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file)) {
$document_id = add_document($_course, $current_path.'/'.$safe_file, 'folder', 0, $title);
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, null, null, null, $current_session_id);
//echo $current_path.'/'.$safe_file.' added!
';
}
// Recursive
add_all_documents_in_folder_to_database($_course,$user_id,$base_work_dir,$current_path.'/'.$safe_file, $to_group_id);
} else {
//Rename
$safe_file = disable_dangerous_file(replace_dangerous_char($file, 'strict'));
@rename($base_work_dir.$current_path.'/'.$file, $base_work_dir.$current_path.'/'.$safe_file);
$document_id = DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file);
if (!$document_id) {
$title = get_document_title($file);
$size = filesize($base_work_dir.$current_path.'/'.$safe_file);
$document_id = add_document($_course, $current_path.'/'.$safe_file, 'file', $size, $title);
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, null, null, null, $current_session_id);
//echo $current_path.'/'.$safe_file.' added!
';
} else {
api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', $user_id, $to_group_id, null, null, null, $current_session_id);
}
}
}
}
}