Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 34... Línea 34...
34
 */
34
 */
35
enum param: string {
35
enum param: string {
36
    /**
36
    /**
37
     * PARAM_ALPHA - contains only English ascii letters [a-zA-Z].
37
     * PARAM_ALPHA - contains only English ascii letters [a-zA-Z].
38
     */
38
     */
-
 
39
    #[param_clientside_regex('^[a-zA-Z]+$')]
39
    case ALPHA = 'alpha';
40
    case ALPHA = 'alpha';
Línea 40... Línea 41...
40
 
41
 
41
    /**
42
    /**
42
     * PARAM_ALPHAEXT the same contents as PARAM_ALPHA (English ascii letters [a-zA-Z]) plus the chars in quotes: "_-" allowed
43
     * PARAM_ALPHAEXT the same contents as PARAM_ALPHA (English ascii letters [a-zA-Z]) plus the chars in quotes: "_-" allowed
43
     * NOTE: originally this allowed "/" too, please use PARAM_SAFEPATH if "/" needed
44
     * NOTE: originally this allowed "/" too, please use PARAM_SAFEPATH if "/" needed
-
 
45
     */
44
     */
46
    #[param_clientside_regex('^[a-zA-Z_\-]*$')]
Línea 45... Línea 47...
45
    case ALPHAEXT = 'alphaext';
47
    case ALPHAEXT = 'alphaext';
46
 
48
 
47
    /**
49
    /**
-
 
50
     * PARAM_ALPHANUM - expected numbers 0-9 and English ascii letters [a-zA-Z] only.
48
     * PARAM_ALPHANUM - expected numbers 0-9 and English ascii letters [a-zA-Z] only.
51
     */
Línea 49... Línea 52...
49
     */
52
    #[param_clientside_regex('^[a-zA-Z0-9]*$')]
50
    case ALPHANUM = 'alphanum';
53
    case ALPHANUM = 'alphanum';
51
 
54
 
-
 
55
    /**
52
    /**
56
     * PARAM_ALPHANUMEXT - expected numbers 0-9, letters (English ascii letters [a-zA-Z]) and _- only.
Línea 53... Línea 57...
53
     * PARAM_ALPHANUMEXT - expected numbers 0-9, letters (English ascii letters [a-zA-Z]) and _- only.
57
     */
54
     */
58
    #[param_clientside_regex('^[a-zA-Z0-9_\-]*$')]
55
    case ALPHANUMEXT = 'alphanumext';
59
    case ALPHANUMEXT = 'alphanumext';
Línea 106... Línea 110...
106
    /**
110
    /**
107
     * PARAM_LOCALISEDFLOAT - a localised real/floating point number.
111
     * PARAM_LOCALISEDFLOAT - a localised real/floating point number.
108
     * This is preferred over PARAM_FLOAT for numbers typed in by the user.
112
     * This is preferred over PARAM_FLOAT for numbers typed in by the user.
109
     * Cleans localised numbers to computer readable numbers; false for invalid numbers.
113
     * Cleans localised numbers to computer readable numbers; false for invalid numbers.
110
     */
114
     */
-
 
115
    #[param_clientside_regex('^\d*([\.,])\d+$')]
111
    case LOCALISEDFLOAT = 'localisedfloat';
116
    case LOCALISEDFLOAT = 'localisedfloat';
Línea 112... Línea 117...
112
 
117
 
113
    /**
118
    /**
114
     * PARAM_HOST - expected fully qualified domain name (FQDN) or an IPv4 dotted quad (IP address)
119
     * PARAM_HOST - expected fully qualified domain name (FQDN) or an IPv4 dotted quad (IP address)
Línea 163... Línea 168...
163
    case RAW_TRIMMED = 'raw_trimmed';
168
    case RAW_TRIMMED = 'raw_trimmed';
Línea 164... Línea 169...
164
 
169
 
165
    /**
170
    /**
166
     * PARAM_SAFEDIR - safe directory name, suitable for include() and require()
171
     * PARAM_SAFEDIR - safe directory name, suitable for include() and require()
-
 
172
     */
167
     */
173
    #[param_clientside_regex('^[a-zA-Z0-9_\-]*$')]
Línea 168... Línea 174...
168
    case SAFEDIR = 'safedir';
174
    case SAFEDIR = 'safedir';
169
 
175
 
170
    /**
176
    /**
171
     * PARAM_SAFEPATH - several PARAM_SAFEDIR joined by "/", suitable for include() and require(), plugin paths
177
     * PARAM_SAFEPATH - several PARAM_SAFEDIR joined by "/", suitable for include() and require(), plugin paths
172
     * and other references to Moodle code files.
178
     * and other references to Moodle code files.
173
     *
179
     *
-
 
180
     * This is NOT intended to be used for absolute paths or any user uploaded files.
174
     * This is NOT intended to be used for absolute paths or any user uploaded files.
181
     */
Línea 175... Línea 182...
175
     */
182
    #[param_clientside_regex('^[a-zA-Z0-9\/_\-]*$')]
176
    case SAFEPATH = 'safepath';
183
    case SAFEPATH = 'safepath';
177
 
184
 
-
 
185
    /**
178
    /**
186
     * PARAM_SEQUENCE - expects a sequence of numbers like 8 to 1,5,6,4,6,8,9.  Numbers and comma only.
Línea 179... Línea 187...
179
     * PARAM_SEQUENCE - expects a sequence of numbers like 8 to 1,5,6,4,6,8,9.  Numbers and comma only.
187
     */
180
     */
188
    #[param_clientside_regex('^[0-9,]*$')]
181
    case SEQUENCE = 'sequence';
189
    case SEQUENCE = 'sequence';
Línea 314... Línea 322...
314
     * PARAM_COMPONENT is used for full component names (aka frankenstyle) such as 'mod_forum = 'core_rating', 'auth_ldap'.
322
     * PARAM_COMPONENT is used for full component names (aka frankenstyle) such as 'mod_forum = 'core_rating', 'auth_ldap'.
315
     * Short legacy subsystem names and module names are accepted too ex: 'forum = 'rating', 'user'.
323
     * Short legacy subsystem names and module names are accepted too ex: 'forum = 'rating', 'user'.
316
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
324
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
317
     * NOTE: numbers and underscores are strongly discouraged in plugin names!
325
     * NOTE: numbers and underscores are strongly discouraged in plugin names!
318
     */
326
     */
-
 
327
    #[param_clientside_regex('^[a-z][a-z0-9]*(_(?:[a-z][a-z0-9_](?!__))*)?[a-z0-9]+$')]
319
    case COMPONENT = 'component';
328
    case COMPONENT = 'component';
Línea 320... Línea 329...
320
 
329
 
321
    /**
330
    /**
322
     * PARAM_AREA is a name of area used when addressing files, comments, ratings, etc.
331
     * PARAM_AREA is a name of area used when addressing files, comments, ratings, etc.
323
     * It is usually used together with context id and component.
332
     * It is usually used together with context id and component.
324
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
333
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
-
 
334
     */
325
     */
335
    #[param_clientside_regex('^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$')]
Línea 326... Línea 336...
326
    case AREA = 'area';
336
    case AREA = 'area';
327
 
337
 
328
    /**
338
    /**
329
     * PARAM_PLUGIN is used for plugin names such as 'forum = 'glossary', 'ldap', 'paypal', 'completionstatus'.
339
     * PARAM_PLUGIN is used for plugin names such as 'forum = 'glossary', 'ldap', 'paypal', 'completionstatus'.
330
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
340
     * Only lowercase ascii letters, numbers and underscores are allowed, it has to start with a letter.
-
 
341
     * NOTE: numbers and underscores are strongly discouraged in plugin names! Underscores are forbidden in module names.
331
     * NOTE: numbers and underscores are strongly discouraged in plugin names! Underscores are forbidden in module names.
342
     */
Línea 332... Línea 343...
332
     */
343
    #[param_clientside_regex('^[a-z](?:[a-z0-9_](?!__))*[a-z0-9]+$')]
333
    case PLUGIN = 'plugin';
344
    case PLUGIN = 'plugin';
334
 
345
 
Línea 408... Línea 419...
408
 
419
 
409
        return $this->{$methodname}($value);
420
        return $this->{$methodname}($value);
Línea 410... Línea 421...
410
    }
421
    }
-
 
422
 
-
 
423
    /**
-
 
424
     * Get the clientside regular expression for this parameter.
-
 
425
     *
-
 
426
     * @return null|string
-
 
427
     */
-
 
428
    public function get_clientside_expression(): ?string {
-
 
429
        $ref = new \ReflectionClassConstant(self::class, $this->name);
-
 
430
        $attributes = $ref->getAttributes(param_clientside_regex::class);
-
 
431
        if (count($attributes) === 0) {
-
 
432
            return null;
-
 
433
        }
-
 
434
 
-
 
435
        return $attributes[0]->newInstance()->regex;
-
 
436
    }
411
 
437
 
412
    /**
438
    /**
413
     * Returns a value for the named variable, taken from request arguments.
439
     * Returns a value for the named variable, taken from request arguments.
414
     *
440
     *
415
     * This function should be used to initialise all required values
441
     * This function should be used to initialise all required values
Línea 1039... Línea 1065...
1039
                // Root-relative, ok!
1065
                // Root-relative, ok!
1040
            } else if (preg_match('/^' . preg_quote($CFG->wwwroot . '/', '/') . '/i', $param)) {
1066
            } else if (preg_match('/^' . preg_quote($CFG->wwwroot . '/', '/') . '/i', $param)) {
1041
                // Absolute, and matches our wwwroot.
1067
                // Absolute, and matches our wwwroot.
1042
            } else {
1068
            } else {
1043
                // Relative - let's make sure there are no tricks.
1069
                // Relative - let's make sure there are no tricks.
1044
                if (validateUrlSyntax('/' . $param, 's-u-P-a-p-f+q?r?') && !preg_match('/javascript:/i', $param)) {
1070
                if (validateUrlSyntax('/' . $param, 's-u-P-a-p-f+q?r?') &&
-
 
1071
                        !preg_match('/javascript(?:.*\/{2,})?:/i', rawurldecode($param))) {
1045
                    // Looks ok.
1072
                    // Valid relative local URL.
1046
                } else {
1073
                } else {
1047
                    $param = '';
1074
                    $param = '';
1048
                }
1075
                }
1049
            }
1076
            }
1050
        }
1077
        }
Línea 1160... Línea 1187...
1160
     *
1187
     *
1161
     * @param mixed $param
1188
     * @param mixed $param
1162
     * @return string
1189
     * @return string
1163
     */
1190
     */
1164
    protected function clean_param_value_capability(mixed $param): string {
1191
    protected function clean_param_value_capability(mixed $param): string {
1165
        if (get_capability_info($param)) {
1192
        if (!empty($param) && get_capability_info($param)) {
1166
            return $param;
1193
            return $param;
1167
        } else {
1194
        } else {
1168
            return '';
1195
            return '';
1169
        }
1196
        }
1170
    }
1197
    }