Subversion Repositories oidplus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1207 daniel-mar 1
 
2
Path functions in OIDplus
3
=========================
4
 
5
How to get relative/absolute paths, e.g. when you are in a plugin?
6
 
7
Here is an overview of the methods `OIDplus::localpath()` and `OIDplus::webpath()`:
8
 
9
                              +---------------------------------------------------------------------------------
10
                              |      Local path                               URL
11
    --------------------------+---------------------------------------------------------------------------------
12
                              |
13
       Get relative path      |      OIDplus::localpath(null, true)           OIDplus::webpath(null, OIDplus::PATH_RELATIVE)
14
       to base directory      |      Example: ../                             Example: ../
15
                              |                                               or
16
                              |                                               OIDplus::webpath(null, OIDplus::PATH_RELATIVE_TO_ROOT)
17
                              |                                               Example: /oidplus/
18
                              |
19
                              |
20
       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
22
                              |                                               or
23
                              |                                               OIDplus::webpath('file.jpg', OIDplus::PATH_RELATIVE_TO_ROOT)
24
                              |                                               Example: /oidplus/xyz/file.jpg
25
                              |
26
                              |
27
       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/
29
                              |
30
                              |
31
       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
33
                              |
34
    --------------------------+---------------------------------------------------------------------------------
35
 
36
 
37
These function ensure that directories end with a trailing path delimiter.
38
 
39
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`.
41
 
42
Usage examples
43
--------------
44
 
45
Here are some ways to test it:
46
 
47
    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";
49
    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";
51
 
52
    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";
54
    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";
56
 
57
    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";
59
    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";
61
 
62
    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";
64
    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";