1 |
<?php |
1 |
<?php |
2 |
|
2 |
|
3 |
// Process supplied parameters as direct link (link to some deep place |
3 |
// Direct Link is technology used for permanent link into deep place of the web. |
- |
|
4 |
// This script is opened when mod_rewrite gets url with no page but with some |
- |
|
5 |
// parameter (query string, separated by ?). The web is trying to find |
- |
|
6 |
// script with the best language (for example DirectLink.en.php). Those scripts |
- |
|
7 |
// are wrappers only. We can then look which language was used and generate |
4 |
// in the web structure). |
8 |
// the right language version of link or selection. |
5 |
// |
9 |
// |
6 |
// This script is usualy called via mod_rewrite when user enter |
- |
|
7 |
// no page with some parameter. |
10 |
// For example www.mlab.cz?xxx |
8 |
// |
11 |
// |
- |
|
12 |
// If there is invalid keyword (xxx in the example above) the script generates |
- |
|
13 |
// selecteion HTML page (with table of posibilities). If the keyword is valid |
- |
|
14 |
// (found in a list) then the page is automatically redirected to the right |
- |
|
15 |
// place. We try to use user's prefered language. |
- |
|
16 |
// |
- |
|
17 |
// In the file DirectLink.inc there is list of keywords and links to go. |
- |
|
18 |
// |
9 |
// (c)miho2007 / www.mlab.cz |
19 |
// Written by (c)miho2007 for www.mlab.cz |
10 |
|
20 |
|
11 |
|
21 |
|
12 |
// Clear variables |
22 |
// Clear variables |
13 |
unset($Redirect); |
23 |
unset($Redirect); |
14 |
unset($RedirectUpper); |
24 |
unset($RedirectUpper); |
15 |
unset($RedirectToPage); |
25 |
unset($RedirectToPage); |
16 |
unset($Lang); |
26 |
unset($Lang); |
17 |
|
27 |
|
18 |
// Include redirect definitions (as an array) |
28 |
// Include redirect definitions (as an array) |
19 |
include_once("DirectLink.inc"); |
29 |
include_once("DirectLink.inc"); |
20 |
|
30 |
|
21 |
// Do all upcase |
31 |
// Make all keywords upcase |
22 |
foreach($Redirect as $Key => $Value) |
32 |
foreach($Redirect as $Key => $Value) |
23 |
{ |
33 |
{ |
24 |
$RedirectUpper[strtoupper($Key)]=$Value; |
34 |
$RedirectUpper[strtoupper($Key)]=$Value; |
25 |
} |
35 |
} |
26 |
|
36 |
|
27 |
// Process language |
37 |
// Process language (extract lang from the name of the script) |
28 |
$Lang=$_SERVER[SCRIPT_FILENAME]; |
38 |
$Lang=$_SERVER[SCRIPT_FILENAME]; |
29 |
$Lang=preg_replace("/(?:.+)\.(.+)\.(.*)/i","$1",$Lang); |
39 |
$Lang=preg_replace("/(?:.+)\.(.+)\.(.*)/i","$1",$Lang); |
30 |
if ($Lang==$_SERVER[SCRIPT_FILENAME]) $Lang=""; |
40 |
if ($Lang==$_SERVER[SCRIPT_FILENAME]) $Lang=""; |
31 |
|
41 |
|
32 |
// Find redirect |
42 |
// Find redirect |
33 |
$RedirectToPage=$RedirectUpper[strtoupper(urldecode($_SERVER[QUERY_STRING]))]; |
43 |
$RedirectToPage=$RedirectUpper[strtoupper(urldecode($_SERVER[QUERY_STRING]))]; |
34 |
|
44 |
|
35 |
// If not found -> list all posibilities |
45 |
// If not found -> list all posibilities |
36 |
if ($RedirectToPage=="") |
46 |
if ($RedirectToPage=="") |
37 |
{ |
47 |
{ |
38 |
// File Name |
48 |
// Template File Name |
39 |
if ($Lang=="") |
49 |
if ($Lang=="") |
40 |
$Lang="en"; |
50 |
$Lang="en"; |
41 |
$FileName="DirectLink.$Lang.tmpl"; |
51 |
$FileName="DirectLink.$Lang.tmpl"; |
- |
|
52 |
|
42 |
// Read Template |
53 |
// Read Template |
43 |
$Template=@file($FileName); |
54 |
$Template=@file($FileName); |
- |
|
55 |
|
44 |
// Trim Lines |
56 |
// Trim Lines |
45 |
if ($Template<>FALSE) |
57 |
if ($Template<>FALSE) |
46 |
{ |
58 |
{ |
47 |
foreach($Template as $Key => $Line) |
59 |
foreach($Template as $Key => $Line) |
48 |
{ |
60 |
{ |
49 |
$Template[$Key]=rtrim($Line); |
61 |
$Template[$Key]=rtrim($Line); |
50 |
} |
62 |
} |
51 |
$Template=implode("\n",$Template); |
63 |
$Template=implode("\n",$Template); |
52 |
} |
64 |
} |
- |
|
65 |
|
- |
|
66 |
// Read parametrs from Template |
- |
|
67 |
|
- |
|
68 |
// Dodělat tuto část včetně odsazení tabulky |
- |
|
69 |
// <<DIRECTLINK Rychlý odkaz>> |
- |
|
70 |
// <<REDIRECTION Přesměrování>> |
- |
|
71 |
$Template=preg_replace("/.*<<DIRECTLINK +(.*)>>/im","",$Template); |
- |
|
72 |
$Template=preg_replace("/.*<<REDIRECTION +(.*)>>/im","",$Template); |
- |
|
73 |
|
53 |
// Generate List |
74 |
// Generate List (table) |
54 |
$Table =""; |
75 |
$Table =""; |
55 |
$Table.="<table>\n"; |
76 |
$Table.="<table>\n"; |
56 |
$Table.=" <tr>\n"; |
77 |
$Table.=" <tr>\n"; |
57 |
$Table.=" <th> Direct Link </th>\n"; |
78 |
$Table.=" <th> Direct Link </th>\n"; |
58 |
$Table.=" <th> Redirected to </th>\n"; |
79 |
$Table.=" <th> Redirected to </th>\n"; |
59 |
$Table.=" </tr>\n"; |
80 |
$Table.=" </tr>\n"; |
60 |
foreach($Redirect as $Key => $Value) |
81 |
foreach($Redirect as $Key => $Value) |
61 |
{ |
82 |
{ |
62 |
$Table.=" <tr>\n"; |
83 |
$Table.=" <tr>\n"; |
63 |
$Table.=" <td> $Key </td>\n"; |
84 |
$Table.=" <td> $Key </td>\n"; |
64 |
$Table.=" <td> $Value </td>\n"; |
85 |
$Table.=" <td> $Value </td>\n"; |
65 |
$Table.=" </tr>\n"; |
86 |
$Table.=" </tr>\n"; |
66 |
} |
87 |
} |
67 |
$Table.="<table>\n"; |
88 |
$Table.="<table>\n"; |
- |
|
89 |
|
68 |
// Put it into Template |
90 |
// Put it into Template |
69 |
if ($Template<>"") |
91 |
if ($Template<>"") |
70 |
print str_ireplace("<<Table>>", $Table, $Template); |
92 |
print str_ireplace("<<TABLE>>", $Table, $Template); |
71 |
else |
93 |
else |
72 |
print $Table; |
94 |
print $Table; // We have No Template |
- |
|
95 |
|
73 |
// Finished |
96 |
// Finished |
74 |
return 0; |
97 |
return 0; |
75 |
} |
98 |
} |
76 |
else |
99 |
else |
77 |
{ |
100 |
{ |
- |
|
101 |
// We have redirection |
78 |
if ($Lang<>"") |
102 |
if ($Lang<>"") |
79 |
if (file_exists($_SERVER["DOCUMENT_ROOT"].$RedirectToPage.".".$Lang.".html")) |
103 |
if (file_exists($_SERVER["DOCUMENT_ROOT"].$RedirectToPage.".".$Lang.".html")) |
80 |
$RedirectToPage.=".".$Lang.".html"; |
104 |
$RedirectToPage.=".".$Lang.".html"; |
81 |
} |
105 |
} |
82 |
|
106 |
|
83 |
// Redirect page |
107 |
// Redirect page |
84 |
header("HTTP/1.1 301 Moved Permanently"); |
108 |
header("HTTP/1.1 301 Moved Permanently"); |
85 |
header("Location: ".$RedirectToPage); |
109 |
header("Location: ".$RedirectToPage); |
86 |
header("Connection: close"); |
110 |
header("Connection: close"); |
87 |
|
111 |
|
88 |
?> |
112 |
?> |