|
1
|
|
|
<?php |
|
2
|
|
|
namespace Page; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* CoreAdmin |
|
6
|
|
|
* This is a set of page properties and helper methods for any generic EE Admin page stuff. Typically, |
|
7
|
|
|
* specific EE Admin Page will extend this for their functionality. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Page |
|
10
|
|
|
* @author Darren Ethier |
|
11
|
|
|
* @since 1.0.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
class CoreAdmin |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
const URL_PREFIX = 'admin.php?page='; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Absolute url to admin for the testing site. eg. `http://www.example.com/wp-admin |
|
21
|
|
|
* This should be set by anything using this Page object by calling setAdminPath($admin_path) first. |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $root_admin_url =''; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Set the root admin url for all admin pages. |
|
28
|
|
|
* @param $admin_url |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function setRootAdminUrl($admin_url) |
|
31
|
|
|
{ |
|
32
|
|
|
self::$root_admin_url = self::trailingSlashIt($admin_url); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get the EE admin url for the given properties. |
|
38
|
|
|
* @param string $page |
|
39
|
|
|
* @param string $action |
|
40
|
|
|
* @param string $additional_params |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
44
|
|
|
{ |
|
45
|
|
|
$url = self::rootAdminUrl() . self::URL_PREFIX . $page; |
|
46
|
|
|
$url .= $action ? '&action=' . $action : ''; |
|
47
|
|
|
$url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
48
|
|
|
return $url; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get what is set for the root_admin_url property. |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected static function rootAdminUrl() |
|
57
|
|
|
{ |
|
58
|
|
|
return self::$root_admin_url; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Appends a trailing slash. |
|
64
|
|
|
* |
|
65
|
|
|
* Will remove trailing forward and backslashes if it exists already before adding |
|
66
|
|
|
* a trailing forward slash. This prevents double slashing a string or path. |
|
67
|
|
|
* |
|
68
|
|
|
* The primary use of this is for paths and thus should be used for paths. It is |
|
69
|
|
|
* not restricted to paths and offers no specific path support. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $string What to add the trailing slash to. |
|
72
|
|
|
* @return string String with trailing slash added. |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function trailingSlashIt($string) |
|
75
|
|
|
{ |
|
76
|
|
|
return self::unTrailingSlashIt($string) . '/'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Removes trailing forward slashes and backslashes if they exist. |
|
81
|
|
|
* |
|
82
|
|
|
* The primary use of this is for paths and thus should be used for paths. It is |
|
83
|
|
|
* not restricted to paths and offers no specific path support. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $string What to remove the trailing slashes from. |
|
86
|
|
|
* @return string String without the trailing slashes. |
|
87
|
|
|
*/ |
|
88
|
|
|
public static function unTrailingSlashit($string) |
|
89
|
|
|
{ |
|
90
|
|
|
return rtrim($string, '/\\'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |