Issues (1751)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/modules/mod_edit.php (10 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
	/*
3
		This class is meant to make it easy to create inline editable pages. The class should not be instantiated, instead
4
		you just call (in pinp) edit::showSpan($data->name, "$nls[name]");
5
	
6
	*/
7
8
	include_once($this->store->get_config("code")."modules/mod_page.php");
9
10
	class edit {
11
		function reset() {
12
			global $AR;
13
			$context = pobject::getContext();
14
			$me      = $context["arCurrentObject"];
15
16
			if (edit::getEditMode()) {
17
				$lang = $me->_getvar('vdLanguage');
18
				if (!$lang) {
19
					$lang = $me->nls;
20
				}
21
22
				$vedorPath      = $me->path;
23
				$vedorUrl       = $me->make_local_url();
24
				$vedorParentUrl = $me->make_local_url('..');
25
				$vedorLanguage  = $lang;
26
				$vedorUrlNls    = $me->make_local_url("",$lang);
27
				$vedorSiteNls   = $me->make_local_url($me->currentsite(), $lang);
28
29
				
30
				$vedorNlsList = array();
31
				$config       = $me->loadConfig();
32
				foreach($config->nls->list as $nls => $lang) {
33
					$vedorNlsList[$me->make_local_url("",$nls).edit::getEditTemplate()] = $AR->nls->list[$nls];
34
				}
35
36
				echo "<script type='vedor/reset' data-vedor-path='$vedorPath' data-vedor-url='$vedorUrl' data-vedor-parent-url='$vedorParentUrl' ";
37
				echo "data-vedor-nls-list='" . json_encode($vedorNlsList) . "' data-vedor-language='$vedorLanguage' ";
38
				echo "data-vedor-url-nls='$vedorUrlNls' data-vedor-site-nls='$vedorSiteNls'>\n";
39
				echo "</script>";
40
			}
41
		}
42
43
		function init() {
44
			global $ARCurrent;
45
			if (edit::getEditMode()) {
46
				$context                = pobject::getContext();
47
				$me                     = $context["arCurrentObject"];
48
49
				$ARCurrent->nolangcheck = true;
50
				$ARCurrent->allnls      = true;
51
				$options                = $me->call("editor.ini");
52
53
				echo "<script type='vedor/editorSettings'>";
54
				echo json_encode($options);
55
				echo "</script>";
56
			}
57
		}
58
59
		function setEditMode($mode=false, $template='user.edit.page.html', $prefix="editable_") {
60
			global $mod_edit_data;
61
			$mod_edit_data['editmode']     = $mode;
62
			$mod_edit_data['edittemplate'] = $template;
63
			$mod_edit_data['editprefix']   = $prefix;
64
		}
65
66
		function getEditMode() {
67
			global $mod_edit_data;
68
			return $mod_edit_data['editmode'];
69
		}
70
71
		function getEditTemplate() {
72
			global $mod_edit_data;
73
			return $mod_edit_data['edittemplate'];
74
		}
75
76
		function getEditPrefix() {
77
			global $mod_edit_data;
78
			return $mod_edit_data['editprefix'];
79
		}
80
81
		function getEditTarget() {
82
			return '_self';
83
		}
84
85
		function registerDataField() {
86
			/* private method */
87
			global $mod_edit_data;
88
			$id     = ++$mod_edit_data['id'];
89
			return $id;
90
		}
91
92
		function getVedorVars($me, $name) {
93
			$vedorVars  = "data-vedor-path='" . $me->path . "' data-vedor-id='" . $me->id . "' data-vedor-field='" . $name . "'".
94
			              " ar:path='" . $me->path . "' ar:id='" . $me->id . "'";
95
96
			return $vedorVars;		
97
		}
98
99 View Code Duplication
		function showInputText($var, $name, $title='', $extra='') {
100
			$context = pobject::getContext();
101
			$me      = $context["arCurrentObject"];
102
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
103
				$id        = edit::registerDataField();
104
				$prefix    = edit::getEditPrefix();
105
				$vedorVars = edit::getVedorVars($me, $name);
106
107
				echo "<input type='text' class='editable' id='".$prefix.$id."' $vedorVars title='$title' value=\"";
108
				echo htmlspecialchars($var);
109
				echo "\" $extra>";
110
			} else if (!edit::isEmpty($var)) {
111
				echo $var;
112
			}
113
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
114
		}
115
116 View Code Duplication
		function showInput($var, $name, $title, $type='text', $extra='') {
117
			$context = pobject::getContext();
118
			$me      = $context["arCurrentObject"];
119
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
120
				$id        = edit::registerDataField();
121
				$prefix    = edit::getEditPrefix();
122
				$vedorVars = edit::getVedorVars($me, $name);
123
124
				echo "<input name='$name' type='$type' class='editable' id='".$prefix.$id."' $vedorVars title='$title' value=\"";
125
				echo htmlspecialchars($var);
126
				echo "\" $extra>";			
127
			} else if (!edit::isEmpty($var)) {
128
				echo $var;
129
			}
130
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
131
		}
132
133
		function registerGroup($name, $id) {
134
			$context = pobject::getContext();
135
			$me      = $context["arCurrentObject"];
136
			/* private method - adds $id to group $name, a change in any member of the group, forces dirty on all members */
137
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
138
				$prefix = edit::getEditPrefix();
139
				echo "<script type='vedor/registerGroup' data-vedor-group='$name' data-vedor-id='$prefix$id'></script>\n";
140
			}
141
		}
142
143
		function showCheckbox($var, $name, $title, $extra='', $group='', $value='1' ) {
144
			$context = pobject::getContext();
145
			$me      = $context["arCurrentObject"];
146
			if(edit::getEditMode() && $me->CheckSilent('edit')) {
147
				$id=edit::registerDataField();
148
				if ($group) {
149
					edit::registerGroup($group, $id);
150
				}
151
				edit::ShowInput(0, $name, $title, 'hidden');
152
				$checked = "";
153
				if( $var == $value ) {
154
					$checked = "checked";
155
				}
156
				$prefix    = edit::getEditPrefix();
157
				$vedorVars = edit::getVedorVars($me, $name);
158
				echo "<input name='$name' type='checkbox' class='editable' id='".$prefix.$id."' $vedorVars title='$title' value='$value' $extra $checked>";
159
			} else if( !edit::isEmpty($var)) {
160
				echo $var;
161
			}
162
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
163
		}
164
165
		function showRadio($var, $name, $value, $title, $extra='' ) {
166
			$context = pobject::getContext();
167
			$me = $context["arCurrentObject"];
168
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
169
				$id = edit::registerDataField();
170
				$checked = "";
171
				if( $var == $value ) {
172
					$checked = "checked";
173
				}
174
				$prefix = edit::getEditPrefix();
175
				$vedorVars = edit::getVedorVars($me, $name);
176
177
				echo "<input name='$name' type='radio' class='editable' id='".$prefix.$id."' $vedorVars title='$title' value=\"".htmlspecialchars($value)."\" $extra $checked>";
178
			} else if( !edit::isEmpty($var)) {
179
				echo $var;
180
			}
181
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
182
		}
183
184
		function showSelect($var, $name, $title, $list, $bykey=false, $extra='') {
185
			$context = pobject::getContext();
186
			$me      = $context["arCurrentObject"];
187
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
188
				$id        = edit::registerDataField();
189
				$prefix    = edit::getEditPrefix();
190
				$vedorVars = edit::getVedorVars($me, $name);
191
192
				echo "<select class='editable' id='".$prefix.$id."' $vedorVars title='$title' $extra>";
193
				foreach ($list as $key => $value) {
194
					echo "<option";
195
					if ($bykey) {
196
						echo " value=\"$key\"";
197
						if (
198
							($key==$var) ||
199
							(is_array($var) && in_array($key, $var))
200
						) {
201
							echo " selected";
202
						}
203
					} else {
204
						echo " value=\"$value\"";
205
						if (
206
							($value==$var) ||
207
							(is_array($var) && in_array($value, $var))
208
						) {
209
							echo " selected";
210
						}
211
					}
212
					echo ">$value</option>\n";
213
				}
214
				echo "</select>";
215
			} else if (!edit::isEmpty($var)) {
216
				echo $var;
217
			}
218
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
219
		}
220
221
		function fixSource($var) { // replace the fixed source code span with the fixed source code (base64encoded in vd:source)
222
			global $ARnls;
223
224
			if (
225
				preg_match('/<(span|div)[^>]*vd:cookieconsentrequired="true"[^>]*>.*<span.*vd:endsource="true".*>.*<\/span>.*<\/(span|div)>/isU', $var) &&
226
				ldGetUserCookie("ARCookieConsent") != true
227
			) {
228
				$var = preg_replace_callback(
229
					'/<(span|div)[^>]*vd:source="([^"]*)"[^>]*>.*<span.*vd:endsource="true".*>.*<\/span>.*<\/(span|div)>/isU',
230
					function($matches) use ($ARnls) {
0 ignored issues
show
The parameter $matches is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
231
						return "[" . $ARnls['vd_cookie_consent_required'] . "]";
232
					}, $var);
233
			} else {
234
235
				$var = preg_replace_callback(
236
					'/<(span|div)[^>]*vd:source="([^"]*)"[^>]*>.*<span.*vd:endsource="true".*>.*<\/span>.*<\/(span|div)>/isU',
237
					function($matches) {
238
						return base64_decode($matches[2]);
239
					}, $var);
240
			}
241
	
242
			return $var;
243
		}
244
245
		function fixEditSource($var) {
246
			$var = preg_replace_callback(
247
				'/(<(span|div)[^>]*vd:source=")([^"]*)("[^>]*>).*(<span[^>]*vd:endsource="true".*>.*<\/span>.*<\/(span|div)>)/isU',
248
				function($matches) {
249
					return $matches[1] . $matches[3] . $matches[4] . base64_decode($matches[3]) . $matches[5];
250
				}, $var);
251
	
252
			return $var;
253
		}
254
		
255 View Code Duplication
		function showSpan($var, $name, $title='', $extra='') {
256
			$context = pobject::getContext();
257
			$me      = $context["arCurrentObject"];
258
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
259
				$id        = edit::registerDataField();
260
				$prefix    = edit::getEditPrefix();
261
				$vedorVars = edit::getVedorVars($me, $name);
262
263
				echo "<span class='editable' id='".$prefix.$id."' $vedorVars title='$title' $extra>";
264
				echo edit::fixEditSource(page::parse($var));
265
				echo "</span>";
266
			} else if (!edit::isEmpty($var)) {
267
				echo page::stripARNameSpace(edit::fixSource(page::parse($var)));
268
			}
269
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
270
		}
271
272 View Code Duplication
		function showTextSpan($var, $name, $title='', $extra='') {
273
			$context = pobject::getContext();
274
			$me      = $context["arCurrentObject"];
275
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
276
				$id        = edit::registerDataField();
277
				$prefix    = edit::getEditPrefix();
278
				$vedorVars = edit::getVedorVars($me, $name);
279
280
				echo "<span class='editable text-only' id='".$prefix.$id."' $vedorVars title='$title' $extra>";
281
				echo page::parse($var);
282
				echo "</span>";
283
			} else if (!edit::isEmpty($var)) {
284
				echo page::parse($var);
285
			}
286
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
287
		}
288
289 View Code Duplication
		function showDiv($var, $name, $title='', $extra='') {
290
			$context = pobject::getContext();
291
			$me      = $context["arCurrentObject"];
292
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
293
				$id        = edit::registerDataField();
294
				$prefix    = edit::getEditPrefix();
295
				$vedorVars = edit::getVedorVars($me, $name);
296
297
				echo "<div class='editable' id='".$prefix.$id."' $vedorVars title='$title' $extra>";
298
				echo edit::fixEditSource(page::parse($var));
299
				echo "</div>";
300
			} else if (!edit::isEmpty($var)) {
301
				echo page::stripARNameSpace(edit::fixSource(page::parse($var)));
302
			}
303
			return $id;
0 ignored issues
show
The variable $id does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
304
		}
305
306
		function startContainer() {
307
			$context = pobject::getContext();
308
			$me      = $context["arCurrentObject"];
309
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
310
				echo "<span ar:type='container' ar:path='".$me->path."' ar:id='".$me->id."'>";
311
			}
312
		}
313
314
		function endContainer() {
315
			$context = pobject::getContext();
316
			$me      = $context["arCurrentObject"];
317
			if (edit::getEditMode() && $me->CheckSilent('edit')) {
318
				echo "</span>";
319
			}
320
		}
321
322 View Code Duplication
		function showLink($path='', $extra='', $url=false, $localurl=false) { 
323
			$context = pobject::getContext();
324
			$me      = $context["arCurrentObject"];
325
			if (!$localurl) {
326
				$_url	= $me->make_url($path);
327
			} else {
328
				$_url	= $me->make_local_url($path);
329
			}
330
			if (edit::getEditMode()) {
331
				echo "<a onClick='parent.browseTo(this.href); return false;' href='".$_url.edit::getEditTemplate()."?vdLanguage=".$me->_getvar('vdLanguage')."' $extra target='".edit::getEditTarget()."'>";
332
			} else {
333
				if (!$url) {
334
					if ($_url) {
335
						$url = $_url;
336
					} else {
337
						$url = $me->make_url($path);
338
					}
339
				}
340
				echo "<a href='".$url."' $extra>";
341
			}
342
		}
343
344 View Code Duplication
		function showEditableLink($path='', $extra='', $url=false, $localurl=false) {
345
			$context = pobject::getContext();
346
			$me      = $context["arCurrentObject"];
347
			if (!$localurl) {
348
				$_url	= $me->make_url($path);
349
			} else {
350
				$_url	= $me->make_local_url($path);
351
			}
352
			if (edit::getEditMode()) {
353
				echo "<a onClick=\"event.cancelBubble=true\" onDblClick=\"parent.browseTo('".$_url.edit::getEditTemplate()."?vdLanguage=".$me->_getvar('vdLanguage')."')\" $extra>";
354
			} else {
355
				if (!$url) {
356
					if ($_url) {
357
						$url = $_url;
358
					} else {
359
						$url = $me->make_url($path);
360
					}
361
				}
362
				echo "<a href='".$url."' $extra>";				
363
			}
364
		}
365
		
366
		function showHref($path='', $extra='', $localurl=false) {
367
			$context = pobject::getContext();
368
			$me      = $context["arCurrentObject"];
369
			if (!$localurl) {
370
				$_url	= $me->make_url($path);
371
			} else {
372
				$_url	= $me->make_local_url($path);
373
			}
374
			if (edit::getEditMode()) {
375
				echo "href='".$_url.edit::getEditTemplate()."?vdLanguage=".$me->_getvar('vdLanguage')."' $extra target='".edit::getEditTarget()."'";
376
			} else {
377
				echo "href='".$_url."'";
378
			}
379
		}
380
381
        function showUrl($path='', $localurl=false) {
382
			$context = pobject::getContext();
383
			$me      = $context["arCurrentObject"];
384
			if (!$localurl) {
385
				$_url	= $me->make_url($path);
386
			} else {
387
				$_url	= $me->make_local_url($path);
388
			}
389
            if (edit::getEditMode()) {
390
                echo $_url.edit::getEditTemplate()."?vdLanguage=".$me->_getvar('vdLanguage');
391
            } else {
392
                echo $_url;
393
            }
394
        }
395
396
		function isEmpty($var) {
397
			if (strpos($var, 'vd:source')===false) {
398
				return trim(preg_replace('/&nbsp;/',' ',strip_tags($var, '<script><input><img><object><embed><iframe>')))=='';
399
			} else {
400
				return false;
401
			}
402
		}
403
	}
404
405
	class pinp_edit {
406
407
		function _reset() {
408
			return edit::reset();
409
		}
410
411
		function _init() {
412
			return edit::init();
413
		}
414
415
		function _setEditMode($mode=false, $template='user.edit.page.html', $prefix='editable_') {
416
			return edit::setEditMode($mode, $template, $prefix);
417
		}
418
419
		function _getEditMode() {
420
			return edit::getEditMode();
421
		}
422
423
		function _getEditTemplate() {
424
			return edit::getEditTemplate();
425
		}
426
427
		function _getEditPrefix() {
428
			return edit::getEditPrefix();
429
		}
430
431
		function _getEditTarget() {
432
			return edit::getEditTarget();
433
		}
434
435
		function _registerDataField($name) {
436
			$id      = edit::registerDataField();
437
			// FIXME: Temporary fix voor older code which still use registerDataField
438
			$context = pobject::getContext();
439
			$me      = $context["arCurrentObject"];
440
			$prefix  = edit::getEditPrefix();
441
			echo "<script> parent.registerDataField('".$prefix.$id."','".AddCSlashes($name, ARESCAPE)."','".$me->path."'
442
				,".$me->id."); </script>\n";
443
			return $id;
444
445
		}
446
447
		function _registerGroup($name, $id) {
448
			return edit::registerGroup($name, $id);
449
		}
450
		
451
		function _showInputText($var, $name, $title='', $extra='') {
452
			return edit::showInputText($var, $name, $title, $extra);
453
		}
454
455
		function _showInput($var, $name, $title, $type='text', $extra='') {
456
			return edit::showInput($var, $name, $title, $type, $extra);
457
		}
458
459
		function _showCheckbox($var, $name, $title, $extra='', $group='', $value='1' ) {
460
			return edit::showCheckbox($var, $name, $title, $extra, $group, $value );
461
		}
462
463
		function _showRadio($var, $name, $value, $title, $extra='' ) {
464
			return edit::showRadio($var, $name, $value, $title, $extra );
465
		}
466
467
		function _showSelect($var, $name, $title, $list, $bykey=false, $extra='') {
468
			return edit::showSelect($var, $name, $title, $list, $bykey, $extra);
469
		}
470
471
		function _showSpan($var, $name, $title='', $extra='') {
472
			return edit::showSpan($var, $name, $title, $extra);
473
		}
474
475
		function _showTextSpan($var, $name, $title='', $extra='') {
476
			return edit::showTextSpan($var, $name, $title, $extra);
477
		}
478
479
		function _showDiv($var, $name, $title='', $extra='') {
480
			return edit::showDiv($var, $name, $title, $extra);
481
		}
482
483
		function _startContainer() {
484
			return edit::startContainer();
485
		}
486
487
		function _endContainer() {
488
			return edit::endContainer();
489
		}
490
491
		function _showLink($path='', $extra='', $url=false, $localurl=false) {
492
			return edit::showLink($path, $extra, $url, $localurl);
493
		}
494
495
		function _showEditableLink($path='', $extra='', $url=false, $localurl=false) {
496
			return edit::showEditableLink($path, $extra, $url, $localurl);			
497
		}
498
		
499
		function _showHref($path='', $localurl='') {
500
			return edit::showHref($path, $localurl);
501
		}
502
503
		function _showUrl($path='', $localurl=false) {
504
			return edit::showUrl($path, $localurl);
505
		}
506
507
		function _isEmpty($var) {
508
			return edit::isEmpty($var);
509
		}
510
	}
511
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
512