Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
9496fdd2
Commit
9496fdd2
authored
12 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
parents
84438d82
86f3c8eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/admin/security_other.php
+2
-0
2 additions, 0 deletions
htdocs/admin/security_other.php
htdocs/core/lib/files.lib.php
+125
-91
125 additions, 91 deletions
htdocs/core/lib/files.lib.php
with
127 additions
and
91 deletions
htdocs/admin/security_other.php
+
2
−
0
View file @
9496fdd2
...
...
@@ -321,6 +321,8 @@ print '</form>';
print
'</table>'
;
dol_fiche_end
();
// Form to test upload
print
'<br>'
;
$formfile
=
new
FormFile
(
$db
);
...
...
This diff is collapsed.
Click to expand it.
htdocs/core/lib/files.lib.php
+
125
−
91
View file @
9496fdd2
...
...
@@ -51,8 +51,20 @@ function dol_basename($pathfile)
*/
function
dol_dir_list
(
$path
,
$types
=
"all"
,
$recursive
=
0
,
$filter
=
""
,
$excludefilter
=
""
,
$sortcriteria
=
"name"
,
$sortorder
=
SORT_ASC
,
$mode
=
0
)
{
global
$db
,
$hookmanager
;
dol_syslog
(
"files.lib.php::dol_dir_list path="
.
$path
.
" types="
.
$types
.
" recursive="
.
$recursive
.
" filter="
.
$filter
.
" excludefilter="
.
json_encode
(
$excludefilter
));
if
(
!
is_object
(
$hookmanager
))
{
if
(
!
class_exists
(
'HookManager'
))
{
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
require
DOL_DOCUMENT_ROOT
.
'/core/class/hookmanager.class.php'
;
$hookmanager
=
new
HookManager
(
$db
);
}
}
$hookmanager
->
initHooks
(
array
(
'fileslib'
));
$loaddate
=
(
$mode
==
1
||
$mode
==
2
)
?
true
:
false
;
$loadsize
=
(
$mode
==
1
||
$mode
==
3
)
?
true
:
false
;
...
...
@@ -60,101 +72,123 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$path
=
preg_replace
(
'/([\\/]+)$/i'
,
''
,
$path
);
$newpath
=
dol_osencode
(
$path
);
if
(
!
is_dir
(
$newpath
))
return
array
();
if
(
$dir
=
opendir
(
$newpath
))
$parameters
=
array
(
'path'
=>
$newpath
,
'types'
=>
$types
,
'recursive'
=>
$recursive
,
'filter'
=>
$filter
,
'excludefilter'
=>
$excludefilter
,
'sortcriteria'
=>
$sortcriteria
,
'sortorder'
=>
$sortorder
,
'loaddate'
=>
$loaddate
,
'loadsize'
=>
$loadsize
);
$ret
=
$hookmanager
->
executeHooks
(
'getDirList'
,
$parameters
);
if
(
!
empty
(
$hookmanager
->
resArray
))
{
$filedate
=
''
;
$filesize
=
''
;
$file_list
=
array
();
while
(
false
!==
(
$file
=
readdir
(
$dir
)))
{
if
(
!
utf8_check
(
$file
))
$file
=
utf8_encode
(
$file
);
// To be sure data is stored in utf8 in memory
$qualified
=
1
;
// Define excludefilterarray
$excludefilterarray
=
array
(
'^\.'
);
if
(
is_array
(
$excludefilter
))
{
$excludefilterarray
=
array_merge
(
$excludefilterarray
,
$excludefilter
);
}
else
if
(
$excludefilter
)
$excludefilterarray
[]
=
$excludefilter
;
// Check if file is qualified
foreach
(
$excludefilterarray
as
$filt
)
{
if
(
preg_match
(
'/'
.
$filt
.
'/i'
,
$file
))
{
$qualified
=
0
;
break
;
}
}
if
(
$qualified
)
{
$isdir
=
is_dir
(
dol_osencode
(
$path
.
"/"
.
$file
));
// Check whether this is a file or directory and whether we're interested in that type
if
(
$isdir
&&
((
$types
==
"directories"
)
||
(
$types
==
"all"
)
||
$recursive
))
{
// Add entry into file_list array
if
((
$types
==
"directories"
)
||
(
$types
==
"all"
))
{
if
(
$loaddate
||
$sortcriteria
==
'date'
)
$filedate
=
dol_filemtime
(
$path
.
"/"
.
$file
);
if
(
$loadsize
||
$sortcriteria
==
'size'
)
$filesize
=
dol_filesize
(
$path
.
"/"
.
$file
);
if
(
!
$filter
||
preg_match
(
'/'
.
$filter
.
'/i'
,
$path
.
'/'
.
$file
))
{
$file_list
[]
=
array
(
"name"
=>
$file
,
"fullname"
=>
$path
.
'/'
.
$file
,
"date"
=>
$filedate
,
"size"
=>
$filesize
,
"type"
=>
'dir'
);
}
}
// if we're in a directory and we want recursive behavior, call this function again
if
(
$recursive
)
{
$file_list
=
array_merge
(
$file_list
,
dol_dir_list
(
$path
.
"/"
.
$file
,
$types
,
$recursive
,
$filter
,
$excludefilter
,
$sortcriteria
,
$sortorder
,
$mode
));
}
}
else
if
(
!
$isdir
&&
((
$types
==
"files"
)
||
(
$types
==
"all"
)))
{
// Add file into file_list array
if
(
$loaddate
||
$sortcriteria
==
'date'
)
$filedate
=
dol_filemtime
(
$path
.
"/"
.
$file
);
if
(
$loadsize
||
$sortcriteria
==
'size'
)
$filesize
=
dol_filesize
(
$path
.
"/"
.
$file
);
if
(
!
$filter
||
preg_match
(
'/'
.
$filter
.
'/i'
,
$path
.
'/'
.
$file
))
{
$file_list
[]
=
array
(
"name"
=>
$file
,
"fullname"
=>
$path
.
'/'
.
$file
,
"date"
=>
$filedate
,
"size"
=>
$filesize
,
"type"
=>
'file'
);
}
}
}
}
closedir
(
$dir
);
// Obtain a list of columns
if
(
!
empty
(
$sortcriteria
))
{
$myarray
=
array
();
foreach
(
$file_list
as
$key
=>
$row
)
{
$myarray
[
$key
]
=
(
isset
(
$row
[
$sortcriteria
])
?
$row
[
$sortcriteria
]
:
''
);
}
// Sort the data
if
(
$sortorder
)
array_multisort
(
$myarray
,
$sortorder
,
$file_list
);
}
return
$file_list
;
return
$hookmanager
->
resArray
;
}
else
{
return
array
();
if
(
!
is_dir
(
$newpath
))
return
array
();
if
(
$dir
=
opendir
(
$newpath
))
{
$filedate
=
''
;
$filesize
=
''
;
$file_list
=
array
();
while
(
false
!==
(
$file
=
readdir
(
$dir
)))
{
if
(
!
utf8_check
(
$file
))
$file
=
utf8_encode
(
$file
);
// To be sure data is stored in utf8 in memory
$qualified
=
1
;
// Define excludefilterarray
$excludefilterarray
=
array
(
'^\.'
);
if
(
is_array
(
$excludefilter
))
{
$excludefilterarray
=
array_merge
(
$excludefilterarray
,
$excludefilter
);
}
else
if
(
$excludefilter
)
$excludefilterarray
[]
=
$excludefilter
;
// Check if file is qualified
foreach
(
$excludefilterarray
as
$filt
)
{
if
(
preg_match
(
'/'
.
$filt
.
'/i'
,
$file
))
{
$qualified
=
0
;
break
;
}
}
if
(
$qualified
)
{
$isdir
=
is_dir
(
dol_osencode
(
$path
.
"/"
.
$file
));
// Check whether this is a file or directory and whether we're interested in that type
if
(
$isdir
&&
((
$types
==
"directories"
)
||
(
$types
==
"all"
)
||
$recursive
))
{
// Add entry into file_list array
if
((
$types
==
"directories"
)
||
(
$types
==
"all"
))
{
if
(
$loaddate
||
$sortcriteria
==
'date'
)
$filedate
=
dol_filemtime
(
$path
.
"/"
.
$file
);
if
(
$loadsize
||
$sortcriteria
==
'size'
)
$filesize
=
dol_filesize
(
$path
.
"/"
.
$file
);
if
(
!
$filter
||
preg_match
(
'/'
.
$filter
.
'/i'
,
$path
.
'/'
.
$file
))
{
$file_list
[]
=
array
(
"name"
=>
$file
,
"fullname"
=>
$path
.
'/'
.
$file
,
"date"
=>
$filedate
,
"size"
=>
$filesize
,
"type"
=>
'dir'
);
}
}
// if we're in a directory and we want recursive behavior, call this function again
if
(
$recursive
)
{
$file_list
=
array_merge
(
$file_list
,
dol_dir_list
(
$path
.
"/"
.
$file
,
$types
,
$recursive
,
$filter
,
$excludefilter
,
$sortcriteria
,
$sortorder
,
$mode
));
}
}
else
if
(
!
$isdir
&&
((
$types
==
"files"
)
||
(
$types
==
"all"
)))
{
// Add file into file_list array
if
(
$loaddate
||
$sortcriteria
==
'date'
)
$filedate
=
dol_filemtime
(
$path
.
"/"
.
$file
);
if
(
$loadsize
||
$sortcriteria
==
'size'
)
$filesize
=
dol_filesize
(
$path
.
"/"
.
$file
);
if
(
!
$filter
||
preg_match
(
'/'
.
$filter
.
'/i'
,
$path
.
'/'
.
$file
))
{
$file_list
[]
=
array
(
"name"
=>
$file
,
"fullname"
=>
$path
.
'/'
.
$file
,
"date"
=>
$filedate
,
"size"
=>
$filesize
,
"type"
=>
'file'
);
}
}
}
}
closedir
(
$dir
);
// Obtain a list of columns
if
(
!
empty
(
$sortcriteria
))
{
$myarray
=
array
();
foreach
(
$file_list
as
$key
=>
$row
)
{
$myarray
[
$key
]
=
(
isset
(
$row
[
$sortcriteria
])
?
$row
[
$sortcriteria
]
:
''
);
}
// Sort the data
if
(
$sortorder
)
array_multisort
(
$myarray
,
$sortorder
,
$file_list
);
}
return
$file_list
;
}
else
{
return
array
();
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment