Rev 1207 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1207 | Rev 1288 | ||
---|---|---|---|
1 | 1 | ||
2 | Path functions in OIDplus |
2 | Path functions in OIDplus |
3 | ========================= |
3 | ========================= |
4 | 4 | ||
5 | How to get relative/absolute paths, e.g. when you are in a plugin? |
5 | How to get relative/absolute paths, e.g. when you are in a plugin? |
6 | 6 | ||
7 | Here is an overview of the methods `OIDplus::localpath()` and `OIDplus::webpath()`: |
7 | Here is an overview of the methods `OIDplus::localpath()` and `OIDplus::webpath()`: |
8 | 8 | ||
9 | +--------------------------------------------------------------------------------- |
9 | +--------------------------------------------------------------------------------- |
10 | | Local path URL |
10 | | Local path URL |
11 | --------------------------+--------------------------------------------------------------------------------- |
11 | --------------------------+--------------------------------------------------------------------------------- |
12 | | |
12 | | |
- | 13 | Canonical form of the | n/a OIDplus::canonicalURL(null) |
|
- | 14 | URL in the browser | Example: https://www.example.com/oidplus/?goto=abc&lang=de |
|
- | 15 | (Params preserved and | OIDplus::canonicalURL('def') |
|
- | 16 | ordered) | Example: https://www.example.com/oidplus/?goto=def&lang=de |
|
- | 17 | | |
|
- | 18 | | |
|
- | 19 | URL of the system | n/a OIDplus::getSystemUrl(OIDplus::PATH_RELATIVE) |
|
- | 20 | | Example: ../ |
|
- | 21 | | OIDplus::getSystemUrl(OIDplus::PATH_RELATIVE_TO_ROOT) |
|
- | 22 | | Example: /oidplus/ |
|
- | 23 | | OIDplus::getSystemUrl(OIDplus::PATH_RELATIVE_TO_ROOT_CANONICAL) |
|
- | 24 | | Example: /oidplus/ (if baseconfig CANONICAL_SYSTEM_URL is set) |
|
- | 25 | | OIDplus::getSystemUrl(OIDplus::PATH_ABSOLUTE) |
|
- | 26 | | Example: http://www.example.com/oidplus/ |
|
- | 27 | | OIDplus::getSystemUrl(OIDplus::PATH_ABSOLUTE_CANONICAL) |
|
- | 28 | | Example: http://www.example.org/oidplus/ (if baseconfig CANONICAL_SYSTEM_URL is set) |
|
- | 29 | | |
|
- | 30 | | |
|
13 | Get relative path | OIDplus::localpath(null, true) OIDplus::webpath(null, OIDplus::PATH_RELATIVE) |
31 | Get relative path | OIDplus::localpath(null, true) OIDplus::webpath(null, OIDplus::PATH_RELATIVE) |
14 | to base directory | Example: ../ Example: ../ |
32 | to base directory | Example: ../ Example: ../ |
15 | | or |
33 | | or |
16 | | OIDplus::webpath(null, OIDplus::PATH_RELATIVE_TO_ROOT) |
34 | | OIDplus::webpath(null, OIDplus::PATH_RELATIVE_TO_ROOT) |
17 | | Example: /oidplus/ |
35 | | Example: /oidplus/ |
18 | | |
36 | | |
19 | | |
37 | | |
20 | Get relative path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE) |
38 | Get relative path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE) |
21 | to any file/dir | Example: xyz/file.jpg Example: xyz/file.jpg |
39 | to any file/dir | Example: xyz/file.jpg Example: xyz/file.jpg |
22 | | or |
40 | | or |
23 | | OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE_TO_ROOT) |
41 | | OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE_TO_ROOT) |
24 | | Example: /oidplus/xyz/file.jpg |
42 | | Example: /oidplus/xyz/file.jpg |
25 | | |
43 | | |
26 | | |
44 | | |
27 | Get absolute path | OIDplus::localpath(null, false) OIDplus::webpath(null, OIDplus::PATH_ABSOLUTE) |
45 | Get absolute path | OIDplus::localpath(null, false) OIDplus::webpath(null, OIDplus::PATH_ABSOLUTE) |
28 | to base directory | Example: /var/www/oidplus/ Example: https://www.example.com/oidplus/ |
46 | to base directory | Example: /var/www/oidplus/ Example: https://www.example.com/oidplus/ |
29 | | |
47 | | |
30 | | |
48 | | |
31 | Get absolute path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_ABSOLUTE) |
49 | Get absolute path | OIDplus::localpath('file.jpg', true) OIDplus::webpath('file.jpg', OIDplus::PATH_ABSOLUTE) |
32 | to any file/dir | Example: /var/www/oidplus/xyz/file.jpg Example: https://www.example.com/oidplus/xyz/file.jpg |
50 | to any file/dir | Example: /var/www/oidplus/xyz/file.jpg Example: https://www.example.com/oidplus/xyz/file.jpg |
33 | | |
51 | | |
34 | --------------------------+--------------------------------------------------------------------------------- |
52 | --------------------------+--------------------------------------------------------------------------------- |
35 | 53 | ||
36 | 54 | ||
37 | These function ensure that directories end with a trailing path delimiter. |
55 | These function ensure that directories end with a trailing path delimiter. |
38 | 56 | ||
39 | If you want to prefer the canonical system url (that can be set with the base config setting `CANONICAL_SYSTEM_URL`), |
57 | If you want to prefer the canonical system url (that can be set with the base config setting `CANONICAL_SYSTEM_URL`), |
40 | then you can replace `OIDplus::PATH_ABSOLUTE` with `OIDplus::PATH_ABSOLUTE_CANONICAL`. |
58 | then you can replace `OIDplus::PATH_ABSOLUTE` with `OIDplus::PATH_ABSOLUTE_CANONICAL`. |
41 | 59 | ||
42 | Usage examples |
60 | Usage examples |
43 | -------------- |
61 | -------------- |
44 | 62 | ||
45 | Here are some ways to test it: |
63 | Here are some ways to test it: |
46 | 64 | ||
47 | echo "Rel Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_RELATIVE));echo "\n"; |
65 | echo "Rel Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_RELATIVE));echo "\n"; |
48 | echo "Rel Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_RELATIVE));echo "\n"; |
66 | echo "Rel Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_RELATIVE));echo "\n"; |
49 | echo "Rel Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_RELATIVE));echo "\n"; |
67 | echo "Rel Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_RELATIVE));echo "\n"; |
50 | echo "Rel Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE));echo "\n"; |
68 | echo "Rel Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE));echo "\n"; |
51 | 69 | ||
52 | echo "Abs Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE));echo "\n"; |
70 | echo "Abs Webpath null: ";print_r(OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE));echo "\n"; |
53 | echo "Abs Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_ABSOLUTE));echo "\n"; |
71 | echo "Abs Webpath non-existing: ";print_r(OIDplus::webpath('xxx',OIDplus::PATH_ABSOLUTE));echo "\n"; |
54 | echo "Abs Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_ABSOLUTE));echo "\n"; |
72 | echo "Abs Webpath existing: ";print_r(OIDplus::webpath('test',OIDplus::PATH_ABSOLUTE));echo "\n"; |
55 | echo "Abs Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE));echo "\n"; |
73 | echo "Abs Webpath self: ";print_r(OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE));echo "\n"; |
56 | 74 | ||
57 | echo "Rel localpath null: ";print_r(OIDplus::localpath(null,true));echo "\n"; |
75 | echo "Rel localpath null: ";print_r(OIDplus::localpath(null,true));echo "\n"; |
58 | echo "Rel localpath non-existing: ";print_r(OIDplus::localpath('xxx',true));echo "\n"; |
76 | echo "Rel localpath non-existing: ";print_r(OIDplus::localpath('xxx',true));echo "\n"; |
59 | echo "Rel localpath existing: ";print_r(OIDplus::localpath('test',true));echo "\n"; |
77 | echo "Rel localpath existing: ";print_r(OIDplus::localpath('test',true));echo "\n"; |
60 | echo "Rel localpath self: ";print_r(OIDplus::localpath(__DIR__,true));echo "\n"; |
78 | echo "Rel localpath self: ";print_r(OIDplus::localpath(__DIR__,true));echo "\n"; |
61 | 79 | ||
62 | echo "Abs localpath null: ";print_r(OIDplus::localpath(null,false));echo "\n"; |
80 | echo "Abs localpath null: ";print_r(OIDplus::localpath(null,false));echo "\n"; |
63 | echo "Abs localpath non-existing: ";print_r(OIDplus::localpath('xxx',false));echo "\n"; |
81 | echo "Abs localpath non-existing: ";print_r(OIDplus::localpath('xxx',false));echo "\n"; |
64 | echo "Abs localpath existing: ";print_r(OIDplus::localpath('test',false));echo "\n"; |
82 | echo "Abs localpath existing: ";print_r(OIDplus::localpath('test',false));echo "\n"; |
65 | echo "Abs localpath self: ";print_r(OIDplus::localpath(__DIR__,false));echo "\n"; |
83 | echo "Abs localpath self: ";print_r(OIDplus::localpath(__DIR__,false));echo "\n"; |