/i", $tag_list[$count]) )
{
$replaceBy[$count] = " $param_name =\"showinframes.php?file=" . $upload_path.$file_path_list[$count]."\" target=\"_self\" ";
}
else
{
$replaceBy[$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: ";
$replaceBy[$count] = $replaceWhat[$count];
}
}
else if ($is_absolute_hyperlink)
{
//$message .= "Absolute hyperlink, don't change, add target=_self: ";
$replaceBy[$count] = " $param_name=\"" . $file_path_list[$count] . "\" target =\"_self\"";
}
else
{
//don't change anything
//$message .= "Local anchor, don't change: ";
$replaceBy[$count] = $replaceWhat[$count];
}
//$message .= "In tag $count, " . htmlentities($tag_list[$count])
// . ", parameter " . $replaceWhat[$count] . " replaced by " . $replaceBy[$count] . "
"; //debug
}
//if (isset($message) && $message == true) api_display_debug_info($message); //debug
$buffer = str_replace($replaceWhat, $replaceBy, $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 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=='/')?'':'/';
//build the form
$form .= "".get_lang('MissingImagesDetected')."
\n"
."\n";
return $form;
}
//------------------------------------------------------------------------------
/**
* This recursive function can be used during the upgrade process form older versions of Dokeos
* 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);
//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);
}
//file!
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);
if(!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file))
{
$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!
";
}
}
}
}
/*
==============================================================================
DEPRECATED FUNCTIONS
==============================================================================
*/
/**
* @deprecated Use transliteration instead, it is applicable for all languages.
*
* Replaces all accentuated characters by non-accentuated characters for filenames, as
* well as special HTML characters by their HTML entity's first letter.
*
* Although this method is not absolute, it gives good results in general. It first
* transforms the string to HTML entities (ô, @oslash;, etc) then removes the
* HTML character part to result in simple characters (o, o, etc).
* In the case of special characters (out of alphabetical value) like and <,
* it will still replace them by the first letter of the HTML entity (n, l, ...) but it
* is still an acceptable method, knowing we're filtering filenames here...
* @param string The accentuated string
* @return string The escaped string, not absolutely correct but satisfying
*/
function replace_accents($string, $encoding = null) {
/*
global $charset;
$string = api_htmlentities($string,ENT_QUOTES,$charset);
$res = preg_replace("/&([a-z])[a-z]+;/i","$1",$string);
return $res;
*/
return api_transliterate($string, 'x', $encoding);
}
/**
* @deprecated Use transliteration instead, it is applicable for all languages.
*/
function remove_accents($string, $encoding = null) {
/*
$string = strtr ( $string, "�����������������������������������������������������", "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn");
return $string;
*/
return api_transliterate($string, 'x', $encoding);
}