531 |
miho |
1 |
<?php |
|
|
2 |
|
|
|
3 |
// Process supplied parameters as direct link (link to some deep place |
|
|
4 |
// in the web structure). |
|
|
5 |
// |
|
|
6 |
// This script is usualy called via mod_rewrite when user enter |
|
|
7 |
// no page with some parameter. |
|
|
8 |
// |
|
|
9 |
// (c)miho2007 / www.mlab.cz |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
// Clear variables |
|
|
13 |
unset($Redirect); |
536 |
miho |
14 |
unset($RedirectUpper); |
531 |
miho |
15 |
unset($RedirectToPage); |
|
|
16 |
unset($Lang); |
|
|
17 |
|
|
|
18 |
// Include redirect definitions (as an array) |
|
|
19 |
include_once("DirectLink.inc"); |
|
|
20 |
|
|
|
21 |
// Do all upcase |
|
|
22 |
foreach($Redirect as $Key => $Value) |
|
|
23 |
{ |
536 |
miho |
24 |
$RedirectUpper[strtoupper($Key)]=$Value; |
531 |
miho |
25 |
} |
|
|
26 |
|
|
|
27 |
// Process language |
|
|
28 |
$Lang=$_SERVER[SCRIPT_FILENAME]; |
|
|
29 |
$Lang=preg_replace("/(?:.+)\.(.+)\.(.*)/i","$1",$Lang); |
|
|
30 |
if ($Lang==$_SERVER[SCRIPT_FILENAME]) $Lang=""; |
|
|
31 |
|
|
|
32 |
// Find redirect |
536 |
miho |
33 |
$RedirectToPage=$RedirectUpper[strtoupper(urldecode($_SERVER[QUERY_STRING]))]; |
531 |
miho |
34 |
|
|
|
35 |
// If not found -> list all posibilities |
|
|
36 |
if ($RedirectToPage=="") |
|
|
37 |
{ |
536 |
miho |
38 |
// File Name |
|
|
39 |
if ($Lang=="") |
|
|
40 |
$Lang="en"; |
|
|
41 |
$FileName="DirectLink.$Lang.tmpl"; |
|
|
42 |
// Read Template |
|
|
43 |
$Template=@file($FileName); |
|
|
44 |
// Trim Lines |
|
|
45 |
if ($Template<>FALSE) |
|
|
46 |
{ |
|
|
47 |
foreach($Template as $Key => $Line) |
|
|
48 |
{ |
|
|
49 |
$Template[$Key]=rtrim($Line); |
|
|
50 |
} |
|
|
51 |
$Template=implode("\n",$Template); |
|
|
52 |
} |
|
|
53 |
// Generate List |
|
|
54 |
$Table =""; |
|
|
55 |
$Table.="<table>\n"; |
|
|
56 |
$Table.=" <tr>\n"; |
|
|
57 |
$Table.=" <th> Direct Link </th>\n"; |
|
|
58 |
$Table.=" <th> Redirected to </th>\n"; |
|
|
59 |
$Table.=" </tr>\n"; |
|
|
60 |
foreach($Redirect as $Key => $Value) |
|
|
61 |
{ |
|
|
62 |
$Table.=" <tr>\n"; |
|
|
63 |
$Table.=" <td> $Key </td>\n"; |
|
|
64 |
$Table.=" <td> $Value </td>\n"; |
|
|
65 |
$Table.=" </tr>\n"; |
|
|
66 |
} |
|
|
67 |
$Table.="<table>\n"; |
|
|
68 |
// Put it into Template |
|
|
69 |
if ($Template<>"") |
|
|
70 |
print str_ireplace("<<Table>>", $Table, $Template); |
|
|
71 |
else |
|
|
72 |
print $Table; |
|
|
73 |
// Finished |
|
|
74 |
return 0; |
531 |
miho |
75 |
} |
|
|
76 |
else |
|
|
77 |
{ |
536 |
miho |
78 |
if ($Lang<>"") |
|
|
79 |
if (file_exists($_SERVER["DOCUMENT_ROOT"].$RedirectToPage.".".$Lang.".html")) |
531 |
miho |
80 |
$RedirectToPage.=".".$Lang.".html"; |
|
|
81 |
} |
|
|
82 |
|
|
|
83 |
// Redirect page |
|
|
84 |
header("HTTP/1.1 301 Moved Permanently"); |
|
|
85 |
header("Location: ".$RedirectToPage); |
|
|
86 |
header("Connection: close"); |
|
|
87 |
|
|
|
88 |
?> |