1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class pinp_keepurl { |
4
|
|
|
|
5
|
|
|
public static function _make_path($path=".") { |
6
|
|
|
global $ARCurrent; |
7
|
|
|
$context = pobject::getContext(); |
8
|
|
|
$me = $context["arCurrentObject"]; |
9
|
|
|
$path = $me->make_path($path); |
10
|
|
|
$newpath = $path; |
11
|
|
|
$redirects = $ARCurrent->shortcut_redirect; |
12
|
|
|
if (is_array($redirects)) { |
13
|
|
View Code Duplication |
while (count($redirects) && ($redir = array_pop($redirects)) && substr($newpath, 0, strlen($redir['dest'])) == $redir['dest'] && $redir['keepurl']) { |
14
|
|
|
$newpath = $redir['src'].substr($newpath, strlen($redir['dest'])); |
15
|
|
|
} |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
return $newpath; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function _loadConfig($path='.') { |
22
|
|
|
global $ARCurrent; |
23
|
|
|
$context = pobject::getContext(); |
24
|
|
|
$me = $context["arCurrentObject"]; |
25
|
|
|
$path = $me->make_path($path); |
26
|
|
|
if (@count($ARCurrent->shortcut_redirect)) { |
27
|
|
|
$redir = reset($ARCurrent->shortcut_redirect); |
28
|
|
|
if ($redir["keepurl"]) { // && substr($path, 0, strlen($redir["dest"])) == $redir["dest"]) { |
29
|
|
|
$path = $redir["src"]; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
$config=$me->loadConfig($path); |
33
|
|
|
return $config; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function _currentsection($path=".") { |
37
|
|
|
$config = self::_loadConfig($path); |
38
|
|
|
return $config->section; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function _currentsite($path=".") { |
42
|
|
|
$config = self::_loadConfig($path); |
43
|
|
|
return $config->site; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function _get($path, $template, $args='') { |
47
|
|
|
global $ARCurrent; |
48
|
|
|
// for now we have to remove all current redirects |
49
|
|
|
$old_redirects = $ARCurrent->shortcut_redirect; |
50
|
|
|
$ARCurrent->shortcut_redirect = Array(); |
51
|
|
|
$realpath = self::_make_real_path($path, $ARCurrent->shortcut_redirect); |
52
|
|
|
if ($realpath) { |
53
|
|
|
$context = pobject::getContext(); |
54
|
|
|
$me = $context["arCurrentObject"]; |
55
|
|
|
$result = $me->get( $realpath, $template, $args ); |
56
|
|
|
} else { |
57
|
|
|
$result = Array(); |
58
|
|
|
} |
59
|
|
|
// restore redirects |
60
|
|
|
$ARCurrent->shortcut_redirect = $old_redirects; |
61
|
|
|
return $result; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public static function _make_real_path($path, &$redirects = Array()) { |
65
|
1 |
|
$context = pobject::getContext(); |
66
|
1 |
|
$me = $context["arCurrentObject"]; |
67
|
|
|
|
68
|
1 |
|
$path = $me->make_path($path); |
69
|
1 |
|
$originalPath = $path; |
70
|
1 |
|
while ($path != $prevPath && !$me->exists($path)) { |
|
|
|
|
71
|
|
|
$prevPath = $path; |
72
|
|
|
$path = $me->make_path($path.'../'); |
73
|
|
|
} |
74
|
1 |
|
if ($path != $originalPath) { |
75
|
|
|
$shortcut = current($me->get($path, 'system.get.phtml')); |
76
|
|
|
if (!$shortcut || !$shortcut->AR_implements('pshortcut')) { |
77
|
|
|
$result = $originalPath; |
78
|
|
|
} else { |
79
|
|
|
if (!is_array($redirects)) { |
80
|
|
|
$redirects = Array(); |
81
|
|
|
} |
82
|
|
|
$subpath = substr($originalPath, strlen($path)); |
83
|
|
|
$target = $shortcut->call('system.get.target.phtml'); |
84
|
|
|
array_push($redirects, Array("src" => $path, "dest" => $target, "keepurl" => $shortcut->data->keepurl)); |
85
|
|
|
if ($me->exists($target.$subpath)) { |
86
|
|
|
$result = $target.$subpath; |
87
|
|
|
} else { |
88
|
|
|
$result = self::_make_real_path($target.$subpath, $redirects); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} else { |
92
|
1 |
|
$result = $path; |
93
|
|
|
} |
94
|
1 |
|
return $result; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: