32 function CombinePaths($sBasePath, $sFolder)
34 return RemoveFromEnd($sBasePath,
'/').
'/'.RemoveFromStart($sFolder,
'/');
43 function GetResourceTypePath($resourceType, $sCommand)
47 if ($sCommand ==
"QuickUpload")
48 return $Config[
'QuickUploadPath'][$resourceType];
49 else return $Config[
'FileTypesPath'][$resourceType];
59 function GetResourceTypeDirectory($resourceType, $sCommand)
62 if ($sCommand ==
"QuickUpload")
64 if (strlen($Config[
'QuickUploadAbsolutePath'][$resourceType]) > 0)
65 return $Config[
'QuickUploadAbsolutePath'][$resourceType];
68 return Server_MapPath($Config[
'QuickUploadPath'][$resourceType]);
70 if (strlen($Config[
'FileTypesAbsolutePath'][$resourceType]) > 0)
71 return $Config[
'FileTypesAbsolutePath'][$resourceType];
74 return Server_MapPath($Config[
'FileTypesPath'][$resourceType]);
86 function GetUrlFromPath($resourceType, $folderPath, $sCommand)
88 return CombinePaths(GetResourceTypePath($resourceType, $sCommand), $folderPath);
97 function RemoveExtension($fileName)
99 return substr($fileName, 0, strrpos($fileName,
'.'));
109 function ServerMapFolder($resourceType, $folderPath, $sCommand)
112 $sResourceTypePath = GetResourceTypeDirectory($resourceType, $sCommand);
115 $sErrorMsg = CreateServerFolder($sResourceTypePath);
116 if ($sErrorMsg !=
'')
117 SendError(1,
"Error creating folder \"{$sResourceTypePath}\" ({$sErrorMsg})");
120 return CombinePaths($sResourceTypePath, $folderPath);
129 function GetParentFolder($folderPath)
131 $sPattern =
"-[/\\\\][^/\\\\]+[/\\\\]?$-";
132 return preg_replace($sPattern,
'', $folderPath);
142 function CreateServerFolder($folderPath, $lastFolder = null)
145 $sParent = GetParentFolder($folderPath);
148 while (strpos($folderPath,
'//') !==
false)
150 $folderPath = str_replace(
'//',
'/', $folderPath);
154 if (!empty($sParent) && !file_exists($sParent))
157 if (!is_null($lastFolder) && $lastFolder === $sParent) {
158 return "Can't create $folderPath directory";
161 $sErrorMsg = CreateServerFolder($sParent, $folderPath);
162 if ($sErrorMsg !=
'')
166 if (!file_exists($folderPath))
173 ini_set(
'track_errors',
'1');
175 if (isset($Config[
'ChmodOnFolderCreate']) && !$Config[
'ChmodOnFolderCreate'])
179 $permissions =
'0777';
180 if (isset($Config[
'ChmodOnFolderCreate']) && $Config[
'ChmodOnFolderCreate'])
182 $permissions = (string) $Config[
'ChmodOnFolderCreate'];
184 $permissionsdec = octdec($permissions);
185 $permissionsdec |= octdec(
'0111');
186 dol_syslog(
"io.php permission = ".$permissions.
" ".$permissionsdec.
" ".decoct($permissionsdec));
188 $oldumask = umask(0);
189 mkdir($folderPath, $permissionsdec);
193 $sErrorMsg = $php_errormsg;
196 ini_restore(
'track_errors');
197 ini_restore(
'error_reporting');
208 function GetRootPath()
213 $sRealPath = realpath(
'./');
215 $sRealPath = rtrim($sRealPath,
"\\/");
218 $sSelfPath = substr($sSelfPath, 0, strrpos($sSelfPath,
'/'));
220 $sSelfPath = str_replace(
'/', DIRECTORY_SEPARATOR, $sSelfPath);
222 $position = strpos($sRealPath, $sSelfPath);
226 if ($position ===
false || $position <> strlen($sRealPath) - strlen($sSelfPath))
227 SendError(1,
'Sorry, can\'t map "UserFilesPath" to a physical path. You must set the "UserFilesAbsolutePath" value in "editor/filemanager/connectors/php/config.php".');
229 return substr($sRealPath, 0, $position);
237 function Server_MapPath($path)
240 if (function_exists(
'apache_lookup_uri')) {
241 $info = apache_lookup_uri($path);
242 return $info->filename.$info->path_info;
247 return GetRootPath().$path;
257 function IsAllowedExt($sExtension, $resourceType)
261 $arAllowed = $Config[
'AllowedExtensions'][$resourceType];
262 $arDenied = $Config[
'DeniedExtensions'][$resourceType];
264 if (count($arAllowed) > 0 && !in_array($sExtension, $arAllowed))
267 if (count($arDenied) > 0 && in_array($sExtension, $arDenied))
279 function IsAllowedType($resourceType)
282 if (!in_array($resourceType, $Config[
'ConfigAllowedTypes']))
294 function IsAllowedCommand($sCommand)
298 if (!in_array($sCommand, $Config[
'ConfigAllowedCommands']))
309 function GetCurrentFolder()
314 $sCurrentFolder = isset($_GET[
'CurrentFolder']) ?
GETPOST(
'CurrentFolder',
'', 1) :
'/';
317 if (!preg_match(
'|/$|', $sCurrentFolder))
318 $sCurrentFolder .=
'/';
319 if (strpos($sCurrentFolder,
'/') !== 0)
320 $sCurrentFolder =
'/'.$sCurrentFolder;
323 while (strpos($sCurrentFolder,
'//') !==
false) {
324 $sCurrentFolder = str_replace(
'//',
'/', $sCurrentFolder);
328 if (strpos($sCurrentFolder,
'..') || strpos($sCurrentFolder,
"\\"))
331 if (preg_match(
",(/\.)|[[:cntrl:]]|(//)|(\\\\)|([\:\*\?\"<>\|]),", $sCurrentFolder))
334 return $sCurrentFolder;
343 function SanitizeFolderName($sNewFolderName)
345 $sNewFolderName = stripslashes($sNewFolderName);
348 $sNewFolderName = preg_replace(
'/\\.|\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/',
'_', $sNewFolderName);
350 return $sNewFolderName;
359 function SanitizeFileName($sNewFileName)
363 $sNewFileName = stripslashes($sNewFileName);
366 if ($Config[
'ForceSingleExtension'])
367 $sNewFileName = preg_replace(
'/\\.(?![^.]*$)/',
'_', $sNewFileName);
370 $sNewFileName = preg_replace(
'/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/',
'_', $sNewFileName);
372 return $sNewFileName;
384 function SendUploadResults($errorNumber, $fileUrl =
'', $fileName =
'', $customMsg =
'')
389 <script
type=
"text/javascript">
390 (
function(){var d=document.domain;
while (
true){
try{var A=window.parent.document.domain;
break;}
catch(e) {};d=d.replace(/.*?(?:\.|$)/,
'');
if (d.length==0)
break;
try{document.domain=d;}
catch (e){
break;}}})();
393 if ($errorNumber && $errorNumber != 201) {
398 $rpl = array(
'\\' =>
'\\\\',
'"' =>
'\\"');
399 echo
'window.parent.OnUploadCompleted('.$errorNumber.
',"'.strtr($fileUrl, $rpl).
'","'.strtr($fileName, $rpl).
'", "'.strtr($customMsg, $rpl).
'");';
416 function SendCKEditorResults($callback, $sFileUrl, $customMsg =
'')
418 echo
'<script type="text/javascript">';
420 $rpl = array(
'\\' =>
'\\\\',
'"' =>
'\\"');
422 echo
'window.parent.CKEDITOR.tools.callFunction("'.$callback.
'","'.strtr($sFileUrl, $rpl).
'", "'.strtr($customMsg, $rpl).
'");';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print $_SERVER["PHP_SELF"]
Edit parameters.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type