/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 array $courseInfo
* @param array $userInfo
* @param string $base_work_dir
* @param string $folderPath
* @param int $sessionId
* @param int $groupId
* @param bool $output
* @param array $parent
* @param string $uploadPath
*
*/
function add_all_documents_in_folder_to_database(
$courseInfo,
$userInfo,
$base_work_dir,
$folderPath,
$sessionId = 0,
$groupId = 0,
$output = false,
$parent = array()
) {
if (empty($userInfo) || empty($courseInfo)) {
return false;
}
$userId = $userInfo['user_id'];
// Open dir
$handle = opendir($folderPath);
$files = array();
if (is_dir($folderPath)) {
// Run trough
while ($file = readdir($handle)) {
if ($file == '.' || $file == '..') {
continue;
}
$parentPath = null;
if (!empty($parent) && isset($parent['path'])) {
$parentPath = $parent['path'];
if ($parentPath == '/') {
$parentPath = null;
}
}
$completePath = $parentPath.'/'.$file;
$sysFolderPath = $folderPath.'/'.$file;
// Is directory?
if (is_dir($sysFolderPath)) {
$newFolderData = create_unexisting_directory(
$courseInfo,
$userId,
$sessionId,
$groupId,
null,
$base_work_dir,
$completePath,
null,
null,
true
);
$files[$file] = $newFolderData;
// Recursive
add_all_documents_in_folder_to_database(
$courseInfo,
$userInfo,
$base_work_dir,
$sysFolderPath,
$sessionId,
$groupId,
$output,
$newFolderData
);
} else {
// Rename
$uploadedFile = array(
'name' => $file,
'tmp_name' => $sysFolderPath,
'size' => filesize($sysFolderPath),
'type' => null,
'from_file' => true,
'move_file' => true
);
handle_uploaded_document(
$courseInfo,
$uploadedFile,
$base_work_dir,
$parentPath,
$userId,
$groupId,
null,
0,
'overwrite',
$output,
false,
null,
$sessionId
);
}
}
}
}