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