1 |
<?php |
1 |
<?php |
2 |
|
2 |
|
3 |
|
3 |
|
4 |
// Zpracovává odkazy ve formátu http://www.mlab.cz/PermaLink/Projekt/DalšíCesta |
4 |
// Zpracovává odkazy ve formátu http://www.mlab.cz/PermaLink/Projekt/DalšíCesta |
5 |
// Skript se volá ze souborů /PermaLink.cs.php a /PermaLink.en.php kde se nastavuje proměnná $Lang |
5 |
// Skript se volá ze souborů /PermaLink.cs.php a /PermaLink.en.php kde se nastavuje proměnná $Lang |
6 |
// První slovo (až po lomítko) za PermaLink se chápe jako jméno modulu/projektu nebo adresáře/sekce. |
6 |
// První slovo (až po lomítko) za PermaLink se chápe jako jméno modulu/projektu nebo adresáře/sekce. |
7 |
// Pokud zadanému jménu odpovídá jediný odkaz, provede se hned přesměrování, jinak se vypíše seznam kandidátů. |
7 |
// Pokud zadanému jménu odpovídá jediný odkaz, provede se hned přesměrování, jinak se vypíše seznam kandidátů. |
8 |
// Pro snadné odkázání lze permanentní odkaz doplnit cestou k adresáři či souboru v rámci projektu. |
8 |
// Pro snadné odkázání lze permanentní odkaz doplnit cestou k adresáři či souboru v rámci projektu. |
9 |
|
9 |
|
10 |
|
10 |
|
11 |
define(DISPLAY_ALL_IF_EMPTY , true); // Povol zobrazení všech sekcí a projektů když je zadaný prázdný permalink |
11 |
define('DISPLAY_ALL_IF_EMPTY' , true); // Povol zobrazení všech sekcí a projektů když je zadaný prázdný permalink |
12 |
define(MAX_DEPTH, 50); // Maximální hloubka prohledávání adresářů (pojistka proti zacyklené struktuře adresářů) |
12 |
define('MAX_DEPTH', 50); // Maximální hloubka prohledávání adresářů (pojistka proti zacyklené struktuře adresářů) |
13 |
|
13 |
|
14 |
require_once('Common.php'); // Modul společných funkcí |
14 |
require_once('Common.php'); // Modul společných funkcí |
15 |
require_once('DirMetadata.php'); // Modul pro načítání informace o adresářích |
15 |
require_once('DirMetadata.php'); // Modul pro načítání informace o adresářích |
16 |
require_once('TemplateEngine.php'); // Stroj pro práci s templejty |
16 |
require_once('TemplateEngine.php'); // Stroj pro práci s templejty |
17 |
|
17 |
|
18 |
// Převezmi odkaz |
18 |
// Převezmi odkaz |
19 |
if($_REQUEST['PermaLink']!='') |
19 |
if($_REQUEST['PermaLink']!='') |
20 |
// Odkaz z formuláře |
20 |
// Odkaz z formuláře |
21 |
$LinkFull = $_REQUEST['PermaLink']; |
21 |
$LinkFull = $_REQUEST['PermaLink']; |
22 |
else |
22 |
else |
23 |
// Odkaz z cesty |
23 |
// Odkaz z cesty |
24 |
$LinkFull = $_SERVER['PATH_INFO']; |
24 |
$LinkFull = $_SERVER['PATH_INFO']; |
25 |
|
25 |
|
26 |
// Decode entities ? |
26 |
// Decode entities ? |
27 |
// $LinkFull=htmlspecialchars_decode($LinkFull); |
27 |
// $LinkFull=htmlspecialchars_decode($LinkFull); |
28 |
|
28 |
|
29 |
// Split PermaLink and aditional Path |
29 |
// Split PermaLink and aditional Path |
30 |
$LinkFull = ltrim($LinkFull, DIRECTORY_SEPARATOR); |
30 |
$LinkFull = ltrim($LinkFull, DIRECTORY_SEPARATOR); |
31 |
$LinkFull = rtrim($LinkFull, DIRECTORY_SEPARATOR); |
31 |
$LinkFull = rtrim($LinkFull, DIRECTORY_SEPARATOR); |
32 |
$SeparatorPosition = strpos($LinkFull, DIRECTORY_SEPARATOR); |
32 |
$SeparatorPosition = strpos($LinkFull, DIRECTORY_SEPARATOR); |
33 |
if ($SeparatorPosition===false) |
33 |
if ($SeparatorPosition===false) |
34 |
{ |
34 |
{ |
35 |
$LinkPath = ''; |
35 |
$LinkPath = ''; |
36 |
$Link = $LinkFull; |
36 |
$Link = $LinkFull; |
37 |
} |
37 |
} |
38 |
else |
38 |
else |
39 |
{ |
39 |
{ |
40 |
$LinkPath = substr($LinkFull, $SeparatorPosition+1); |
40 |
$LinkPath = substr($LinkFull, $SeparatorPosition+1); |
41 |
$Link = substr($LinkFull, 0, $SeparatorPosition); |
41 |
$Link = substr($LinkFull, 0, $SeparatorPosition); |
42 |
} |
42 |
} |
43 |
unset($SeparatorPosition); |
43 |
unset($SeparatorPosition); |
44 |
|
44 |
|
45 |
// Najdi cíle pro PermaLink |
45 |
// Najdi cíle pro PermaLink |
46 |
$PermaLinkArray = array(); |
46 |
$PermaLinkArray = array(); |
47 |
if(DISPLAY_ALL_IF_EMPTY or !($Link==='')) |
47 |
if(DISPLAY_ALL_IF_EMPTY or !($Link==='')) |
48 |
{ |
48 |
{ |
49 |
// Načti seznam všech projektů a sekcí (od začátku) |
49 |
// Načti seznam všech projektů a sekcí (od začátku) |
50 |
$ProjectsAndSections = RecurseDirs('/'); |
50 |
$ProjectsAndSections = RecurseDirs('/'); |
51 |
|
51 |
|
52 |
// Převeď projekty a sekce na permalinky |
52 |
// Převeď projekty a sekce na permalinky |
53 |
$AllPermas = PermaLinkCreateArray($ProjectsAndSections); |
53 |
$AllPermas = PermaLinkCreateArray($ProjectsAndSections); |
54 |
unset($ProjectsAndSections); |
54 |
unset($ProjectsAndSections); |
55 |
|
55 |
|
56 |
if($LinkFull==='') |
56 |
if($LinkFull==='') |
57 |
{ |
57 |
{ |
58 |
// Prázdný permalink - zkopíruj vše |
58 |
// Prázdný permalink - zkopíruj vše |
59 |
$PermaLinkArray = $AllPermas; |
59 |
$PermaLinkArray = $AllPermas; |
60 |
} |
60 |
} |
61 |
else |
61 |
else |
62 |
{ |
62 |
{ |
63 |
// Najdi zadaný permalink |
63 |
// Najdi zadaný permalink |
64 |
$PermaLinkArray = PermaLinkFind($AllPermas, PermaLinkCreateKey($Link)); |
64 |
$PermaLinkArray = PermaLinkFind($AllPermas, PermaLinkCreateKey($Link)); |
65 |
} |
65 |
} |
66 |
unset($AllPermas); |
66 |
unset($AllPermas); |
67 |
} |
67 |
} |
68 |
$PermaLinkCount = count($PermaLinkArray); |
68 |
$PermaLinkCount = count($PermaLinkArray); |
69 |
//print_rx('Found Permalinks', $PermaLinkArray); |
69 |
//print_rx('Found Permalinks', $PermaLinkArray); |
70 |
|
70 |
|
71 |
// Nalezen právě jeden odkaz bez přídavné cesty - rovnou přesměruj |
71 |
// Nalezen právě jeden odkaz bez přídavné cesty - rovnou přesměruj |
72 |
if($PermaLinkCount==1 and $LinkPath==='') |
72 |
if($PermaLinkCount==1 and $LinkPath==='') |
73 |
Redirect($PermaLinkArray[0]['Path'], $Lang); // ------------------------------------->>> |
73 |
Redirect($PermaLinkArray[0]['Path'], $Lang); // ------------------------------------->>> |
74 |
|
74 |
|
75 |
// Setřiď nalezené (třídí primárně podle první položky, což je lowercase verze permalinku) |
75 |
// Setřiď nalezené (třídí primárně podle první položky, což je lowercase verze permalinku) |
76 |
sort($PermaLinkArray); |
76 |
sort($PermaLinkArray); |
77 |
|
77 |
|
78 |
// *************************** |
78 |
// *************************** |
79 |
// Zpracuj PermaLink bez cesty |
79 |
// Zpracuj PermaLink bez cesty |
80 |
// *************************** |
80 |
// *************************** |
81 |
if ($LinkPath==='') |
81 |
if ($LinkPath==='') |
82 |
{ |
82 |
{ |
83 |
// Založ objekt templejtu a načti jej |
83 |
// Založ objekt templejtu a načti jej |
84 |
$Template = new TemplateEngine(); |
84 |
$Template = new TemplateEngine(); |
85 |
$error = $Template->LoadTemplate($_SERVER['DOCUMENT_ROOT'].'/'.TEMPLATE_PERMALINK, $Lang); |
85 |
$error = $Template->LoadTemplate($_SERVER['DOCUMENT_ROOT'].'/'.TEMPLATE_PERMALINK, $Lang); |
86 |
if ($error!='') |
86 |
if ($error!='') |
87 |
Error($error); |
87 |
Error($error); |
88 |
|
88 |
|
89 |
// Generuj dynamický obsah do proměnných (společná část) |
89 |
// Generuj dynamický obsah do proměnných (společná část) |
90 |
$Template->SetVariable('InfoThisLink', $LinkFull ); |
90 |
$Template->SetVariable('InfoThisLink', $LinkFull ); |
91 |
$Template->SetVariable('InfoThisServer', $_SERVER['HTTP_HOST']); |
91 |
$Template->SetVariable('InfoThisServer', $_SERVER['HTTP_HOST']); |
92 |
|
92 |
|
93 |
// Nalezeno více položek - zjisti více informací a vlož je do templejtu |
93 |
// Nalezeno více položek - zjisti více informací a vlož je do templejtu |
94 |
$Lines = ''; |
94 |
$Lines = ''; |
95 |
if($PermaLinkCount>1) |
95 |
if($PermaLinkCount>1) |
96 |
{ |
96 |
{ |
97 |
// Nachystej společné hodnoty z templejtu |
97 |
// Nachystej společné hodnoty z templejtu |
98 |
$PictureGlue = $Template->GetVariable('InfoPictureGlue'); |
98 |
$PictureGlue = $Template->GetVariable('InfoPictureGlue'); |
99 |
$PictureAlt = $Template->GetVariable('InfoPictureAlt'); |
99 |
$PictureAlt = $Template->GetVariable('InfoPictureAlt'); |
100 |
$PictureNoPicture = '/'.TEMPLATE_PATH.'/'.$Template->GetVariable('InfoNoPicture'); |
100 |
$PictureNoPicture = '/'.TEMPLATE_PATH.'/'.$Template->GetVariable('InfoNoPicture'); |
101 |
// Načti informace o projektu |
101 |
// Načti informace o projektu |
102 |
$DirInfo = new DirMetadata(); |
102 |
$DirInfo = new DirMetadata(); |
103 |
foreach($PermaLinkArray as $Data) |
103 |
foreach($PermaLinkArray as $Data) |
104 |
{ |
104 |
{ |
105 |
// Naplň proměnné pro definici položky |
105 |
// Naplň proměnné pro definici položky |
106 |
// Type / Picture / PermaLink / Path |
106 |
// Type / Picture / PermaLink / Path |
107 |
$Variables['InfoType'] = $Data['Type']; |
107 |
$Variables['InfoType'] = $Data['Type']; |
108 |
$Variables['InfoPicture'] = CreatePicturesLink($Data['Path'], $PictureGlue, $PictureAlt, $PictureNoPicture, 150); |
108 |
$Variables['InfoPicture'] = CreatePicturesLink($Data['Path'], $PictureGlue, $PictureAlt, $PictureNoPicture); |
109 |
$Variables['InfoPermaLink'] = "<a href=\"".PermaLinkCreateLink($Data['PermaLink'])."\">{$Data['PermaLink']}</a>"; |
109 |
$Variables['InfoPermaLink'] = "<a href=\"".PermaLinkCreateLink($Data['PermaLink'])."\">{$Data['PermaLink']}</a>"; |
110 |
$PathMarked = MarkPath($Data['Path']); |
110 |
$PathMarked = MarkPath($Data['Path']); |
111 |
$Variables['InfoPath'] = "<a href=\"".CreateProjectLink($Data['Path'], $Lang)."\">$PathMarked</a>"; |
111 |
$Variables['InfoPath'] = "<a href=\"".CreateProjectLink($Data['Path'], $Lang)."\">$PathMarked</a>"; |
112 |
unset($PathMarked); |
112 |
unset($PathMarked); |
113 |
|
113 |
|
114 |
// Zjisti informace o projektu |
114 |
// Zjisti informace o projektu |
115 |
if($Data['Type']==="Section") |
115 |
if($Data['Type']==="Section") |
116 |
$DirInfo->LoadDirInfo($Data['Path'].'/'.DIRINFO, $Lang); |
116 |
$DirInfo->LoadDirInfo($Data['Path'].'/'.DIRINFO, $Lang); |
117 |
else |
117 |
else |
118 |
$DirInfo->LoadDirInfo($Data['Path'].'/'.PRJINFO, $Lang); |
118 |
$DirInfo->LoadDirInfo($Data['Path'].'/'.PRJINFO, $Lang); |
119 |
|
119 |
|
120 |
// Vlož všechny zjištěné informace |
120 |
// Vlož všechny zjištěné informace |
121 |
foreach($DirInfo->DirData as $Key => $ItemInfo) |
121 |
foreach($DirInfo->DirData as $Key => $ItemInfo) |
122 |
$Variables[$Key] = $ItemInfo; |
122 |
$Variables[$Key] = $ItemInfo; |
123 |
|
123 |
|
124 |
// Ošetři chybějící popis |
124 |
// Ošetři chybějící popis |
125 |
if($Variables['InfoShortDescription']=='' and $Variables['InfoLongDescription']=='') |
125 |
if($Variables['InfoShortDescription']=='' and $Variables['InfoLongDescription']=='') |
126 |
$Variables['InfoShortDescription'] = $Template->GetVariable('InfoNoText'); |
126 |
$Variables['InfoShortDescription'] = $Template->GetVariable('InfoNoText'); |
127 |
|
127 |
|
128 |
// Proveď substituci a střádej výsledek (po položkách) |
128 |
// Proveď substituci a střádej výsledek (po položkách) |
129 |
$Lines .= $Template->Substitute($Variables, $Template->GetVariable('InfoLine')); |
129 |
$Lines .= $Template->Substitute($Variables, $Template->GetVariable('InfoLine')); |
130 |
|
130 |
|
131 |
// Zahoď nalezená data (aby se nepoužily v dalším cyklu) |
131 |
// Zahoď nalezená data (aby se nepoužily v dalším cyklu) |
132 |
unset($Variables); |
132 |
unset($Variables); |
133 |
} |
133 |
} |
134 |
|
134 |
|
135 |
// Vlož řádky do templejtu |
135 |
// Vlož řádky do templejtu |
136 |
$Template->SetVariable('InfoLine', $Lines); |
136 |
$Template->SetVariable('InfoLine', $Lines); |
137 |
} |
137 |
} |
138 |
else |
138 |
else |
139 |
{ |
139 |
{ |
140 |
// Nenalezeno nic (nebo prázdné zadání) |
140 |
// Nenalezeno nic (nebo prázdné zadání) |
141 |
$Template->SetVariable('InfoLine', $Template->GetVariable('InfoNoData')); |
141 |
$Template->SetVariable('InfoLine', $Template->GetVariable('InfoNoData')); |
142 |
} |
142 |
} |
143 |
|
143 |
|
144 |
// Odešli výsledek klientovi |
144 |
// Odešli výsledek klientovi |
145 |
echo $Template->GetPage(); |
145 |
echo $Template->GetPage(); |
146 |
return; |
146 |
return; |
147 |
} |
147 |
} |
148 |
else |
148 |
else |
149 |
// ************************** |
149 |
// ************************** |
150 |
// Zpracuj PermaLink s cestou |
150 |
// Zpracuj PermaLink s cestou |
151 |
// ************************** |
151 |
// ************************** |
152 |
{ |
152 |
{ |
153 |
// Založ objekt templejtu a načti jej |
153 |
// Založ objekt templejtu a načti jej |
154 |
$Template = new TemplateEngine(); |
154 |
$Template = new TemplateEngine(); |
155 |
$error = $Template->LoadTemplate($_SERVER['DOCUMENT_ROOT'].'/'.TEMPLATE_PERMALINK_PATH, $Lang); |
155 |
$error = $Template->LoadTemplate($_SERVER['DOCUMENT_ROOT'].'/'.TEMPLATE_PERMALINK_PATH, $Lang); |
156 |
if ($error!='') |
156 |
if ($error!='') |
157 |
Error($error); |
157 |
Error($error); |
158 |
|
158 |
|
159 |
// Generuj dynamický obsah do proměnných (společná část) |
159 |
// Generuj dynamický obsah do proměnných (společná část) |
160 |
$Template->SetVariable('InfoThisLink', $LinkFull ); |
160 |
$Template->SetVariable('InfoThisLink', $LinkFull ); |
161 |
$Template->SetVariable('InfoThisServer', $_SERVER['HTTP_HOST']); |
161 |
$Template->SetVariable('InfoThisServer', $_SERVER['HTTP_HOST']); |
162 |
|
162 |
|
163 |
// Načti proměnné z templejtu |
163 |
// Načti proměnné z templejtu |
164 |
$Glue = $Template->GetVariable('InfoNamesGlue'); |
164 |
$Glue = $Template->GetVariable('InfoNamesGlue'); |
165 |
|
165 |
|
166 |
// Prohledej adresáře (nestriktní verze) |
166 |
// Prohledej adresáře (nestriktní verze) |
167 |
// ------------------------------------- |
167 |
// ------------------------------------- |
168 |
$FilesPathArray = array(); |
168 |
$FilesPathArray = array(); |
169 |
$FilesPathCount = 0; |
169 |
$FilesPathCount = 0; |
170 |
|
170 |
|
171 |
// Rozděl cestu na dílky |
171 |
// Rozděl cestu na dílky |
172 |
$LinkPathArray = explode('/', $LinkPath); |
172 |
$LinkPathArray = explode('/', $LinkPath); |
173 |
$LinkPathDepth = count($LinkPathArray); |
173 |
$LinkPathDepth = count($LinkPathArray); |
174 |
//print_rx("Path to be found", $LinkPathArray); |
174 |
//print_rx("Path to be found", $LinkPathArray); |
175 |
|
175 |
|
176 |
// Cyklus přes všechny nalezené permalinky |
176 |
// Cyklus přes všechny nalezené permalinky |
177 |
foreach($PermaLinkArray as $Item) |
177 |
foreach($PermaLinkArray as $Item) |
178 |
{ |
178 |
{ |
179 |
// Rekurentně procházej atrukturu adresáře |
179 |
// Rekurentně procházej atrukturu adresáře |
180 |
// Podadresáře přidávej průběžně na konec pole |
180 |
// Podadresáře přidávej průběžně na konec pole |
181 |
// První položka je hloubka zanoření (indexuje $LinkPathArray) |
181 |
// První položka je hloubka zanoření (indexuje $LinkPathArray) |
182 |
// Střádej nalezené položky do pole $LinkPathData |
182 |
// Střádej nalezené položky do pole $LinkPathData |
183 |
$Dirs = array(); |
183 |
$Dirs = array(); |
184 |
$Dirs[] = array('Depth'=>0, 'Path'=>$Item['Path']); |
184 |
$Dirs[] = array('Depth'=>0, 'Path'=>$Item['Path']); |
185 |
// Omez hloubku procházení adresářů |
185 |
// Omez hloubku procházení adresářů |
186 |
for ($i=0; $i<count($Dirs) and $i<MAX_DEPTH; $i++) |
186 |
for ($i=0; $i<count($Dirs) and $i<MAX_DEPTH; $i++) |
187 |
{ |
187 |
{ |
188 |
//print "At Depth " . $Dirs[$i]['Depth'] . " Reading Directory " . $Dirs[$i]['Path'] . PHP_EOL; |
188 |
//print "At Depth " . $Dirs[$i]['Depth'] . " Reading Directory " . $Dirs[$i]['Path'] . PHP_EOL; |
189 |
//print "Looking for " . $LinkPathArray[$Dirs[$i]['Depth']] . PHP_EOL; |
189 |
//print "Looking for " . $LinkPathArray[$Dirs[$i]['Depth']] . PHP_EOL; |
190 |
$GlobFlags = GLOB_NOSORT; |
190 |
$GlobFlags = GLOB_NOSORT; |
191 |
if ($LinkPathDepth>$Dirs[$i]['Depth']+1) |
191 |
if ($LinkPathDepth>$Dirs[$i]['Depth']+1) |
192 |
{ |
192 |
{ |
193 |
// Nejsme ještě u konce cesty - přidej jen adresáře |
193 |
// Nejsme ještě u konce cesty - přidej jen adresáře |
194 |
$GlobFlags |= GLOB_ONLYDIR; |
194 |
$GlobFlags |= GLOB_ONLYDIR; |
195 |
} |
195 |
} |
196 |
// Čti adresáře |
196 |
// Čti adresáře |
197 |
$SubDirs = glob($_SERVER['DOCUMENT_ROOT'].$Dirs[$i]['Path'].DIRECTORY_SEPARATOR.'*', $GlobFlags); |
197 |
$SubDirs = glob($_SERVER['DOCUMENT_ROOT'].$Dirs[$i]['Path'].DIRECTORY_SEPARATOR.'*', $GlobFlags); |
198 |
foreach($SubDirs as $Item) |
198 |
foreach($SubDirs as $Item) |
199 |
{ |
199 |
{ |
200 |
// Převeď na cestu od rootu webu |
200 |
// Převeď na cestu od rootu webu |
201 |
$CurentName = basename($Item); |
201 |
$CurentName = basename($Item); |
202 |
$CurentPath = $Dirs[$i]['Path' ]; |
202 |
$CurentPath = $Dirs[$i]['Path' ]; |
203 |
$CurentDepth = $Dirs[$i]['Depth']; |
203 |
$CurentDepth = $Dirs[$i]['Depth']; |
204 |
//print " $CurentName\n"; |
204 |
//print " $CurentName\n"; |
205 |
// ===> POROVNÁNÍ JE ZDE <=== |
205 |
// ===> POROVNÁNÍ JE ZDE <=== |
206 |
if(mb_strtolower(PermaLinkFilter($CurentName))===mb_strtolower(PermaLinkFilter($LinkPathArray[$CurentDepth]))) |
206 |
if(mb_strtolower(PermaLinkFilter($CurentName))===mb_strtolower(PermaLinkFilter($LinkPathArray[$CurentDepth]))) |
207 |
{ |
207 |
{ |
208 |
//print" ^----> $CurentDepth : $CurentPath/$CurentName\n"; |
208 |
//print" ^----> $CurentDepth : $CurentPath/$CurentName\n"; |
209 |
// Přidej další adresář do rekurze |
209 |
// Přidej další adresář do rekurze |
210 |
if(is_dir($Item)) |
210 |
if(is_dir($Item)) |
211 |
{ |
211 |
{ |
212 |
$Dirs[] = array('Depth'=>$CurentDepth+1, 'Path'=>$CurentPath.'/'.$CurentName); |
212 |
$Dirs[] = array('Depth'=>$CurentDepth+1, 'Path'=>$CurentPath.'/'.$CurentName); |
213 |
} |
213 |
} |
214 |
// Nalezený soubor v adresáři |
214 |
// Nalezený soubor v adresáři |
215 |
if(is_file($Item)) |
215 |
if(is_file($Item)) |
216 |
{ |
216 |
{ |
217 |
//print " ^----> File: $Item\n"; |
217 |
//print " ^----> File: $Item\n"; |
218 |
$FilesPathArray[$Dirs[$i]['Path']][]=$CurentName; |
218 |
$FilesPathArray[$Dirs[$i]['Path']][]=$CurentName; |
219 |
$FilesPathCount++; |
219 |
$FilesPathCount++; |
220 |
} |
220 |
} |
221 |
} |
221 |
} |
222 |
// V posledním adresáři přidej všechny soubory |
222 |
// V posledním adresáři přidej všechny soubory |
223 |
if($CurentDepth>=$LinkPathDepth) |
223 |
if($CurentDepth>=$LinkPathDepth) |
224 |
{ |
224 |
{ |
225 |
//print " Test ".$_SERVER['DOCUMENT_ROOT'].$CurentPath.'/'.$CurentName.PHP_EOL; |
225 |
//print " Test ".$_SERVER['DOCUMENT_ROOT'].$CurentPath.'/'.$CurentName.PHP_EOL; |
226 |
if (is_file($_SERVER['DOCUMENT_ROOT'].$CurentPath.'/'.$CurentName)) |
226 |
if (is_file($_SERVER['DOCUMENT_ROOT'].$CurentPath.'/'.$CurentName)) |
227 |
{ |
227 |
{ |
228 |
//print " ^----> File All: $Item\n"; |
228 |
//print " ^----> File All: $Item\n"; |
229 |
$FilesPathArray[$CurentPath][]=$CurentName; |
229 |
$FilesPathArray[$CurentPath][]=$CurentName; |
230 |
$FilesPathCount++; |
230 |
$FilesPathCount++; |
231 |
} |
231 |
} |
232 |
} |
232 |
} |
233 |
} |
233 |
} |
234 |
//print("\n"); |
234 |
//print("\n"); |
235 |
} |
235 |
} |
236 |
} |
236 |
} |
237 |
//print_rx('Found Files', $FilesPathArray); |
237 |
//print_rx('Found Files', $FilesPathArray); |
238 |
//print "Files Found Count $FilesPathCount\n"; |
238 |
//print "Files Found Count $FilesPathCount\n"; |
239 |
|
239 |
|
240 |
/* |
240 |
/* |
241 |
// Prohledej adresáře a soubory (striktní verze) |
241 |
// Prohledej adresáře a soubory (striktní verze) |
242 |
// --------------------------------------------- |
242 |
// --------------------------------------------- |
243 |
$EatIt = strlen($_SERVER['DOCUMENT_ROOT']); |
243 |
$EatIt = strlen($_SERVER['DOCUMENT_ROOT']); |
244 |
foreach($PermaLinkArray as $Item) |
244 |
foreach($PermaLinkArray as $Item) |
245 |
{ |
245 |
{ |
246 |
$Path = $_SERVER['DOCUMENT_ROOT'].$Item['Path'].DIRECTORY_SEPARATOR.$LinkPath; |
246 |
$Path = $_SERVER['DOCUMENT_ROOT'].$Item['Path'].DIRECTORY_SEPARATOR.$LinkPath; |
247 |
if (is_file($Path)) |
247 |
if (is_file($Path)) |
248 |
{ |
248 |
{ |
249 |
$FilesPathArray[substr(dirname($Path), $EatIt)] = array(basename($Path)); |
249 |
$FilesPathArray[substr(dirname($Path), $EatIt)] = array(basename($Path)); |
250 |
$FilesPathCount++; |
250 |
$FilesPathCount++; |
251 |
} |
251 |
} |
252 |
if (is_dir($Path)) |
252 |
if (is_dir($Path)) |
253 |
{ |
253 |
{ |
254 |
foreach (scandir($Path) as $DirItem) |
254 |
foreach (scandir($Path) as $DirItem) |
255 |
{ |
255 |
{ |
256 |
if (is_file($Path.DIRECTORY_SEPARATOR.$DirItem)) |
256 |
if (is_file($Path.DIRECTORY_SEPARATOR.$DirItem)) |
257 |
{ |
257 |
{ |
258 |
$FilesPathArray[substr($Path, $EatIt)][]=$DirItem; |
258 |
$FilesPathArray[substr($Path, $EatIt)][]=$DirItem; |
259 |
$FilesPathCount++; |
259 |
$FilesPathCount++; |
260 |
} |
260 |
} |
261 |
} |
261 |
} |
262 |
} |
262 |
} |
263 |
} |
263 |
} |
264 |
print_rx('Nalezene soubory', $FilesPathArray); |
264 |
print_rx('Nalezene soubory', $FilesPathArray); |
265 |
print "$FilesPathCoutn\n"; |
265 |
print "$FilesPathCoutn\n"; |
266 |
*/ |
266 |
*/ |
267 |
|
267 |
|
268 |
// Nalezen právě jeden odkaz na soubor - rovnou přesměruj |
268 |
// Nalezen právě jeden odkaz na soubor - rovnou přesměruj |
269 |
if($FilesPathCount===1) |
269 |
if($FilesPathCount===1) |
270 |
{ |
270 |
{ |
271 |
reset($FilesPathArray); |
271 |
reset($FilesPathArray); |
272 |
$tmp = current($FilesPathArray); |
272 |
$tmp = current($FilesPathArray); |
273 |
$Path = key($FilesPathArray).'/'.$tmp[0]; |
273 |
$Path = key($FilesPathArray).'/'.$tmp[0]; |
274 |
RedirectToFile($Path); // ------------------------------------->>> |
274 |
RedirectToFile($Path); // ------------------------------------->>> |
275 |
} |
275 |
} |
276 |
|
276 |
|
277 |
// Nalezeno více položek - zjisti více informací a vlož je do templejtu |
277 |
// Nalezeno více položek - zjisti více informací a vlož je do templejtu |
278 |
$Lines = ''; |
278 |
$Lines = ''; |
279 |
if($FilesPathCount>0) |
279 |
if($FilesPathCount>0) |
280 |
{ |
280 |
{ |
281 |
foreach($FilesPathArray as $Path=>$FileArray) |
281 |
foreach($FilesPathArray as $Path=>$FileArray) |
282 |
{ |
282 |
{ |
283 |
$Variables['InfoName']=CreateFilesLink($Path, '<br>', ''); |
283 |
$Variables['InfoName']=CreateFilesLink($Path, '<br>', ''); |
284 |
$FileNames = ''; |
284 |
$FileNames = ''; |
285 |
foreach($FileArray as $FileItem) |
285 |
foreach($FileArray as $FileItem) |
286 |
{ |
286 |
{ |
287 |
$FileNames .= '<br> '.$FileItem; |
287 |
$FileNames .= '<br> '.$FileItem; |
288 |
} |
288 |
} |
289 |
$Variables['InfoPath'] = $Path; |
289 |
$Variables['InfoPath'] = $Path; |
290 |
$Variables['InfoNames'] = CreateFilesLink2($Path, $FileArray, $Glue); |
290 |
$Variables['InfoNames'] = CreateFilesLink2($Path, $FileArray, $Glue); |
291 |
|
291 |
|
292 |
// Proveď substituci a střádej výsledek (po položkách) |
292 |
// Proveď substituci a střádej výsledek (po položkách) |
293 |
$Lines .= $Template->Substitute($Variables, $Template->GetVariable('InfoLine')); |
293 |
$Lines .= $Template->Substitute($Variables, $Template->GetVariable('InfoLine')); |
294 |
|
294 |
|
295 |
// Zahoď nalezená data (aby se nepoužily v dalším cyklu) |
295 |
// Zahoď nalezená data (aby se nepoužily v dalším cyklu) |
296 |
unset($Variables); |
296 |
unset($Variables); |
297 |
} |
297 |
} |
298 |
// Vlož řádky do templejtu |
298 |
// Vlož řádky do templejtu |
299 |
$Template->SetVariable('InfoLine', $Lines); |
299 |
$Template->SetVariable('InfoLine', $Lines); |
300 |
} |
300 |
} |
301 |
else |
301 |
else |
302 |
{ |
302 |
{ |
303 |
// Nenalezeno nic |
303 |
// Nenalezeno nic |
304 |
$Template->SetVariable('InfoLine', $Template->GetVariable('InfoNoData')); |
304 |
$Template->SetVariable('InfoLine', $Template->GetVariable('InfoNoData')); |
305 |
} |
305 |
} |
306 |
|
306 |
|
307 |
// Odešli výsledek klientovi |
307 |
// Odešli výsledek klientovi |
308 |
echo $Template->GetPage(); |
308 |
echo $Template->GetPage(); |
309 |
return; |
309 |
return; |
310 |
} |
310 |
} |
311 |
|
311 |
|
312 |
?> |
312 |
?> |