1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
file_tree.php
См. документацию.
1
<?php
2
3
class
CFileTree
4
{
5
protected
$inPath
=
'/'
;
6
protected
$path
=
''
;
7
protected
$dir
=
false
;
8
9
public
function
__construct
($in_path =
"/"
)
10
{
11
$this->inPath = preg_replace(
"#[\\\\/]+#"
,
"/"
, $in_path);
12
}
13
14
public
function
Start
(
$path
=
"/"
)
15
{
16
$this->
path
= preg_replace(
"#[\\\\/]+#"
,
"/"
, $this->inPath . trim(
$path
,
"/"
));
17
18
if
(!file_exists($this->
path
) || is_file($this->
path
))
19
{
20
$last =
self::ExtractFileFromPath
($this->
path
);
21
$this->dir = $this->
ReadDir
($this->
path
);
22
if
(is_array($this->dir))
23
{
24
while
(
count
($this->dir))
25
{
26
if
(strcmp($this->dir[0], $last) > 0)
27
{
28
break
;
29
}
30
array_shift($this->dir);
31
}
32
}
33
}
34
}
35
36
public
function
GetNextFile
()
37
{
38
if
(!is_array($this->dir))
39
{
40
$this->dir = $this->
ReadDir
($this->
path
);
41
if
(!is_array($this->dir))
42
{
43
return
false
;
44
}
45
}
46
47
$next = current($this->dir);
48
next($this->dir);
49
50
if
($next ===
false
)
51
{
52
//try to go up dir tree
53
if
($this->
GoUp
())
54
{
55
return
$this->
GetNextFile
();
56
}
57
else
58
{
59
return
false
;
60
}
61
}
62
elseif
(is_file($next))
63
{
64
//it's our target
65
return
$next;
66
}
67
else
68
{
69
//it's dir or link try to go deeper
70
$this->
path
= $next;
71
$this->dir =
false
;
72
return
true
;
73
}
74
}
75
76
public
static
function
ExtractFileFromPath
(&
$path
)
77
{
78
$arPath
= explode(
"/"
,
$path
);
79
$last = array_pop(
$arPath
);
80
$path
= implode(
"/"
,
$arPath
);
81
return
$path
.
"/"
. $last;
82
}
83
84
protected
function
GoUp
()
85
{
86
$last_dir =
self::ExtractFileFromPath
($this->
path
);
87
//We are not going to go up anymore
88
if
(mb_strlen($this->
path
.
"/"
) < mb_strlen($this->inPath))
89
{
90
return
false
;
91
}
92
93
$this->dir = $this->
ReadDir
($this->
path
);
94
//This shouldn't happen so try to go up one more level
95
if
(!is_array($this->dir))
96
{
97
return
$this->
GoUp
();
98
}
99
100
//Skip all dirs till current
101
while
(
count
($this->dir))
102
{
103
if
(strcmp($this->dir[0], $last_dir) > 0)
104
{
105
break
;
106
}
107
array_shift($this->dir);
108
}
109
110
if
(!empty($this->dir))
111
{
112
return
true
;
113
}
//there is more work to do
114
else
115
{
116
return
$this->
GoUp
();
117
}
// try to go upper
118
}
119
120
protected
function
ReadDir
(
$dir
)
121
{
122
$dir
= rtrim(
$dir
,
"/"
);
123
if
(is_dir(
$dir
))
124
{
125
$dh = opendir(
$dir
);
126
if
($dh)
127
{
128
$result
= [];
129
while
((
$f
= readdir($dh)) !==
false
)
130
{
131
if
(
$f
==
"."
||
$f
==
".."
)
132
{
133
continue
;
134
}
135
$result
[] =
$dir
.
"/"
.
$f
;
136
}
137
closedir($dh);
138
sort(
$result
);
139
140
//try to delete an empty directory
141
if
(empty(
$result
))
142
{
143
@rmdir(
$dir
);
144
}
145
146
return
$result
;
147
}
148
}
149
return
false
;
150
}
151
}
CFileTree
Определения
file_tree.php:4
CFileTree\ReadDir
ReadDir($dir)
Определения
file_tree.php:120
CFileTree\GoUp
GoUp()
Определения
file_tree.php:84
CFileTree\__construct
__construct($in_path="/")
Определения
file_tree.php:9
CFileTree\$path
$path
Определения
file_tree.php:6
CFileTree\$dir
$dir
Определения
file_tree.php:7
CFileTree\Start
Start($path="/")
Определения
file_tree.php:14
CFileTree\$inPath
$inPath
Определения
file_tree.php:5
CFileTree\GetNextFile
GetNextFile()
Определения
file_tree.php:36
CFileTree\ExtractFileFromPath
static ExtractFileFromPath(&$path)
Определения
file_tree.php:76
$f
$f
Определения
component_props.php:52
$arPath
$arPath
Определения
file_edit.php:72
$result
$result
Определения
get_property_values.php:14
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
path
path
Определения
template_copy.php:201
bitrix
modules
main
classes
general
file_tree.php
Создано системой
1.14.0