|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Page Framework |
|
4
|
|
|
* |
|
5
|
|
|
* http://en.michaeluno.jp/admin-page-framework/ |
|
6
|
|
|
* Copyright (c) 2013-2016 Michael Uno; Licensed MIT |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Put deprecated utility methods together. |
|
12
|
|
|
* |
|
13
|
|
|
* @since 3.5.3 |
|
14
|
|
|
* @package AdminPageFramework |
|
15
|
|
|
* @subpackage Utility |
|
16
|
|
|
* @internal |
|
17
|
|
|
* @deprecated |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AdminPageFramework_Utility_Deprecated { |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @deprecated 3.7.10 Use `getCSSMinified()` instead. |
|
23
|
|
|
* @since 3.8.8 Moved from `AdminPageFramework_Utility_String`. |
|
24
|
|
|
*/ |
|
25
|
|
|
static public function minifyCSS( $sCSSRules ) { |
|
|
|
|
|
|
26
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getCSSMinified()' ); |
|
27
|
|
|
return AdminPageFramework_Utility_String::getCSSMinified( $sCSSRules ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @deprecated 3.8.0 Use `getLengthSanitized()` instead. |
|
32
|
|
|
* @since 3.8.8 Moved from `AdminPageFramework_Utility_String`. |
|
33
|
|
|
*/ |
|
34
|
|
|
static public function sanitizeLength( $sLength, $sUnit='px' ) { |
|
|
|
|
|
|
35
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getLengthSanitized()' ); |
|
36
|
|
|
return AdminPageFramework_Utility_String::getLengthSanitized( $sLength, $sUnit ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Retrieves a corresponding array value from the given array. |
|
41
|
|
|
* |
|
42
|
|
|
* When there are multiple arrays and they have similar index structures but it's not certain if one has the key and the others, |
|
43
|
|
|
* use this method to retrieve the corresponding key value. |
|
44
|
|
|
* |
|
45
|
|
|
* @remark This is mainly used by the field array to insert user-defined key values. |
|
46
|
|
|
* @return string|array If the key does not exist in the passed array, it will return the default. If the subject value is not an array, it will return the subject value itself. |
|
47
|
|
|
* @since 2.0.0 |
|
48
|
|
|
* @since 2.1.3 Added the $bBlankToDefault parameter that sets the default value if the subject value is empty. |
|
49
|
|
|
* @since 2.1.5 Changed the scope to public static from protected as converting all the utility methods to all public static. |
|
50
|
|
|
* @since 3.5.3 Moved from `AdminPageFramework_Utility_Array`. |
|
51
|
|
|
* @deprecated 3.5.3 Use `getElement()`. |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function getCorrespondingArrayValue( $vSubject, $sKey, $sDefault='', $bBlankToDefault=false ) { |
|
54
|
|
|
|
|
55
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getElement()' ); |
|
56
|
|
|
|
|
57
|
|
|
// If $vSubject is null, |
|
58
|
|
|
if ( ! isset( $vSubject ) ) { |
|
59
|
|
|
return $sDefault; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// If the $bBlankToDefault flag is set and the subject value is a blank string, return the default value. |
|
63
|
|
|
if ( $bBlankToDefault && $vSubject == '' ) { |
|
64
|
|
|
return $sDefault; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// If $vSubject is not an array, |
|
68
|
|
|
if ( ! is_array( $vSubject ) ) { |
|
69
|
|
|
return ( string ) $vSubject; |
|
70
|
|
|
} // consider it as string. |
|
71
|
|
|
|
|
72
|
|
|
// Consider $vSubject as array. |
|
73
|
|
|
if ( isset( $vSubject[ $sKey ] ) ) { |
|
74
|
|
|
return $vSubject[ $sKey ]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $sDefault; |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Check if the given array is an associative array. |
|
83
|
|
|
* |
|
84
|
|
|
* @since 3.0.0 |
|
85
|
|
|
* @since 3.5.3 Moved from `AdminPageFramework_Utility_Array`. |
|
86
|
|
|
*/ |
|
87
|
|
|
static public function isAssociativeArray( array $aArray ) { |
|
|
|
|
|
|
88
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ ); |
|
89
|
|
|
return ( bool ) count( array_filter( array_keys( $aArray ), 'is_string' ) ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Finds the dimension depth of the given array. |
|
94
|
|
|
* |
|
95
|
|
|
* @since 2.0.0 |
|
96
|
|
|
* @since 3.5.3 Moved from `AdminPageFramework_Utility_Array`. |
|
97
|
|
|
* @remark There is a limitation that this only checks the first element so if the second or other elements have deeper dimensions, it will not be caught. |
|
98
|
|
|
* @param array $array the subject array to check. |
|
99
|
|
|
* @return integer returns the number of dimensions of the array. |
|
100
|
|
|
* @deprecated 3.5.3 |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function getArrayDimension( $array ) { |
|
103
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ ); |
|
104
|
|
|
return ( is_array( reset( $array ) ) ) |
|
105
|
|
|
? self::getArrayDimension( reset( $array ) ) + 1 |
|
|
|
|
|
|
106
|
|
|
: 1; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Returns the element value of the given field element. |
|
111
|
|
|
* |
|
112
|
|
|
* When there are multiple input/select tags in one field such as for the radio and checkbox input type, |
|
113
|
|
|
* the framework user can specify the key to apply the element value. In this case, this method will be used. |
|
114
|
|
|
* |
|
115
|
|
|
* @since 3.0.0 |
|
116
|
|
|
* @since 3.5.3 Moved from `AdminPageFramework_FieldType_Base`. |
|
117
|
|
|
* @deprecated 3.5.3 Use the `getElement()` method. |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function getFieldElementByKey( $asElement, $sKey, $asDefault='' ) { |
|
120
|
|
|
|
|
121
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__, 'getElement()' ); |
|
122
|
|
|
|
|
123
|
|
|
if ( ! is_array( $asElement ) || ! isset( $sKey ) ) { |
|
124
|
|
|
return $asElement; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$aElements = &$asElement; // it is an array |
|
128
|
|
|
return isset( $aElements[ $sKey ] ) |
|
129
|
|
|
? $aElements[ $sKey ] |
|
130
|
|
|
: $asDefault; |
|
131
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Shift array elements until it gets an element that yields true and re-index with numeric keys. |
|
136
|
|
|
* |
|
137
|
|
|
* @since 3.0.1 |
|
138
|
|
|
* @since 3.5.3 Moved from `AdminPageFramework_Utility_Array`. |
|
139
|
|
|
* @deprecated 3.5.3 This was used to sanitise dimensional key arrays but it does not seem to necessary. |
|
140
|
|
|
* @return array |
|
141
|
|
|
*/ |
|
142
|
|
|
static public function shiftTillTrue( array $aArray ) { |
|
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __FUNCTION__ ); |
|
145
|
|
|
|
|
146
|
|
|
foreach( $aArray as &$vElem ) { |
|
147
|
|
|
|
|
148
|
|
|
if ( $vElem ) { break; } |
|
149
|
|
|
unset( $vElem ); |
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
return array_values( $aArray ); |
|
153
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Generates a string of attributes to be embedded in an HTML tag from an associative array. |
|
158
|
|
|
* |
|
159
|
|
|
* For example, |
|
160
|
|
|
* <code> |
|
161
|
|
|
* array( 'id' => 'my_id', 'name' => 'my_name', 'style' => 'background-color:#fff' ) |
|
162
|
|
|
* </code> |
|
163
|
|
|
* becomes |
|
164
|
|
|
* <code> |
|
165
|
|
|
* id="my_id" name="my_name" style="background-color:#fff" |
|
166
|
|
|
* </code> |
|
167
|
|
|
* |
|
168
|
|
|
* This is mostly used by methods to output input fields. |
|
169
|
|
|
* |
|
170
|
|
|
* @since 3.0.0 |
|
171
|
|
|
* @since 3.3.0 Made it allow empty value. |
|
172
|
|
|
* @since 3.5.3 Deprecated. Moved from `AdminPageFramework_Utility`. |
|
173
|
|
|
* @return string |
|
174
|
|
|
* @deprecated Use getAttributes() in `AdminPageFramework_WPUtility`. |
|
175
|
|
|
*/ |
|
176
|
|
|
static public function getAttributes( array $aAttributes ) { |
|
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
AdminPageFramework_Utility::showDeprecationNotice( __METHOD__, 'AdminPageFramework_WPUtility::getAttributes()' ); |
|
179
|
|
|
|
|
180
|
|
|
$_sQuoteCharactor ="'"; |
|
181
|
|
|
$_aOutput = array(); |
|
182
|
|
|
foreach( $aAttributes as $sAttribute => $sProperty ) { |
|
183
|
|
|
|
|
184
|
|
|
// Must be resolved as a string. |
|
185
|
|
|
if ( in_array( gettype( $sProperty ), array( 'array', 'object' ) ) ) { |
|
186
|
|
|
continue; |
|
187
|
|
|
} |
|
188
|
|
|
$_aOutput[] = "{$sAttribute}={$_sQuoteCharactor}{$sProperty}{$_sQuoteCharactor}"; |
|
189
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
return implode( ' ', $_aOutput ); |
|
192
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|