@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | function __construct() { |
15 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) ); |
|
16 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) ); |
|
15 | + add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated')); |
|
16 | + add_action('timber/twig/filters', array($this, 'add_timber_filters')); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * @deprecated since 0.20.7 |
24 | 24 | * @return Twig_Environment |
25 | 25 | */ |
26 | - function add_timber_filters_deprecated( $twig ) { |
|
27 | - $twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) ); |
|
28 | - $twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) ); |
|
29 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) ); |
|
30 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) ); |
|
31 | - $twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){ |
|
26 | + function add_timber_filters_deprecated($twig) { |
|
27 | + $twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id')); |
|
28 | + $twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class'))); |
|
29 | + $twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify'))); |
|
30 | + $twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify'))); |
|
31 | + $twig->addFilter(new Twig_SimpleFilter('string', function($arr, $glue = ' ') { |
|
32 | 32 | return twig_join_filter($arr, $glue); |
33 | - } ) ); |
|
33 | + } )); |
|
34 | 34 | return $twig; |
35 | 35 | } |
36 | 36 | |
@@ -40,151 +40,151 @@ discard block |
||
40 | 40 | * @param Twig_Environment $twig |
41 | 41 | * @return Twig_Environment |
42 | 42 | */ |
43 | - function add_timber_filters( $twig ) { |
|
43 | + function add_timber_filters($twig) { |
|
44 | 44 | /* image filters */ |
45 | - $twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) ); |
|
46 | - $twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) ); |
|
47 | - $twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) ); |
|
48 | - $twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) ); |
|
45 | + $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize'))); |
|
46 | + $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize'))); |
|
47 | + $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox'))); |
|
48 | + $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg'))); |
|
49 | 49 | |
50 | 50 | /* debugging filters */ |
51 | - $twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) ); |
|
52 | - $twig->addFilter( new Twig_SimpleFilter( 'get_class', 'get_class' ) ); |
|
53 | - $twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) ); |
|
54 | - $twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) { |
|
55 | - return print_r( $arr, true ); |
|
56 | - } ) ); |
|
57 | - $twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) { |
|
58 | - return '<pre>' . self::object_docs( $arr, true ) . '</pre>'; |
|
59 | - } ) ); |
|
51 | + $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs')); |
|
52 | + $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class')); |
|
53 | + $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type')); |
|
54 | + $twig->addFilter(new Twig_SimpleFilter('print_r', function($arr) { |
|
55 | + return print_r($arr, true); |
|
56 | + } )); |
|
57 | + $twig->addFilter(new Twig_SimpleFilter('print_a', function($arr) { |
|
58 | + return '<pre>' . self::object_docs($arr, true) . '</pre>'; |
|
59 | + } )); |
|
60 | 60 | |
61 | 61 | /* other filters */ |
62 | - $twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) ); |
|
63 | - $twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) ); |
|
64 | - $twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) ); |
|
65 | - $twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) ); |
|
66 | - $twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) ); |
|
67 | - $twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) ); |
|
68 | - $twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) ); |
|
69 | - $twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) ); |
|
70 | - $twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) ); |
|
71 | - $twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) ); |
|
72 | - |
|
73 | - $twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) { |
|
74 | - return TimberURLHelper::get_rel_url( $link, true ); |
|
75 | - } ) ); |
|
76 | - |
|
77 | - $twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) ); |
|
78 | - |
|
79 | - $twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) { |
|
80 | - return TimberHelper::trim_words( $text, $len ); |
|
81 | - } ) ); |
|
62 | + $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes')); |
|
63 | + $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array'))); |
|
64 | + $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words')); |
|
65 | + $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function'))); |
|
66 | + $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags'))); |
|
67 | + $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title')); |
|
68 | + $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode')); |
|
69 | + $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago'))); |
|
70 | + $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop')); |
|
71 | + $twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators'))); |
|
72 | + |
|
73 | + $twig->addFilter(new Twig_SimpleFilter('relative', function($link) { |
|
74 | + return TimberURLHelper::get_rel_url($link, true); |
|
75 | + } )); |
|
76 | + |
|
77 | + $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date'))); |
|
78 | + |
|
79 | + $twig->addFilter(new Twig_SimpleFilter('truncate', function($text, $len) { |
|
80 | + return TimberHelper::trim_words($text, $len); |
|
81 | + } )); |
|
82 | 82 | |
83 | 83 | /* actions and filters */ |
84 | - $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) { |
|
84 | + $twig->addFunction(new Twig_SimpleFunction('action', function($context) { |
|
85 | 85 | $args = func_get_args(); |
86 | - array_shift( $args ); |
|
86 | + array_shift($args); |
|
87 | 87 | $args[] = $context; |
88 | - call_user_func_array( 'do_action', $args ); |
|
89 | - }, array( 'needs_context' => true ) ) ); |
|
88 | + call_user_func_array('do_action', $args); |
|
89 | + }, array('needs_context' => true))); |
|
90 | 90 | |
91 | - $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () { |
|
91 | + $twig->addFilter(new Twig_SimpleFilter('apply_filters', function() { |
|
92 | 92 | $args = func_get_args(); |
93 | - $tag = current( array_splice( $args, 1, 1 ) ); |
|
93 | + $tag = current(array_splice($args, 1, 1)); |
|
94 | 94 | |
95 | - return apply_filters_ref_array( $tag, $args ); |
|
96 | - } ) ); |
|
97 | - $twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) ); |
|
98 | - $twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) ); |
|
95 | + return apply_filters_ref_array($tag, $args); |
|
96 | + } )); |
|
97 | + $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function'))); |
|
98 | + $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function'))); |
|
99 | 99 | |
100 | - $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) ); |
|
100 | + $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode')); |
|
101 | 101 | |
102 | 102 | /* TimberObjects */ |
103 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) { |
|
104 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
105 | - foreach ( $pid as &$p ) { |
|
106 | - $p = new $PostClass( $p ); |
|
103 | + $twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid, $PostClass = 'TimberPost') { |
|
104 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
105 | + foreach ($pid as &$p) { |
|
106 | + $p = new $PostClass($p); |
|
107 | 107 | } |
108 | 108 | return $pid; |
109 | 109 | } |
110 | - return new $PostClass( $pid ); |
|
111 | - } ) ); |
|
112 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
113 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
114 | - foreach ( $pid as &$p ) { |
|
115 | - $p = new $ImageClass( $p ); |
|
110 | + return new $PostClass($pid); |
|
111 | + } )); |
|
112 | + $twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid, $ImageClass = 'TimberImage') { |
|
113 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
114 | + foreach ($pid as &$p) { |
|
115 | + $p = new $ImageClass($p); |
|
116 | 116 | } |
117 | 117 | return $pid; |
118 | 118 | } |
119 | - return new $ImageClass( $pid ); |
|
120 | - } ) ); |
|
121 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
122 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
123 | - foreach ( $pid as &$p ) { |
|
124 | - $p = new $TermClass( $p ); |
|
119 | + return new $ImageClass($pid); |
|
120 | + } )); |
|
121 | + $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function($pid, $TermClass = 'TimberTerm') { |
|
122 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
123 | + foreach ($pid as &$p) { |
|
124 | + $p = new $TermClass($p); |
|
125 | 125 | } |
126 | 126 | return $pid; |
127 | 127 | } |
128 | - return new $TermClass( $pid ); |
|
129 | - } ) ); |
|
130 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) { |
|
131 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
132 | - foreach ( $pid as &$p ) { |
|
133 | - $p = new $UserClass( $p ); |
|
128 | + return new $TermClass($pid); |
|
129 | + } )); |
|
130 | + $twig->addFunction(new Twig_SimpleFunction('TimberUser', function($pid, $UserClass = 'TimberUser') { |
|
131 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
132 | + foreach ($pid as &$p) { |
|
133 | + $p = new $UserClass($p); |
|
134 | 134 | } |
135 | 135 | return $pid; |
136 | 136 | } |
137 | - return new $UserClass( $pid ); |
|
138 | - } ) ); |
|
137 | + return new $UserClass($pid); |
|
138 | + } )); |
|
139 | 139 | |
140 | 140 | /* TimberObjects Alias */ |
141 | - $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) { |
|
142 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
143 | - foreach ( $pid as &$p ) { |
|
144 | - $p = new $PostClass( $p ); |
|
141 | + $twig->addFunction(new Twig_SimpleFunction('Post', function($pid, $PostClass = 'TimberPost') { |
|
142 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
143 | + foreach ($pid as &$p) { |
|
144 | + $p = new $PostClass($p); |
|
145 | 145 | } |
146 | 146 | return $pid; |
147 | 147 | } |
148 | - return new $PostClass( $pid ); |
|
149 | - } ) ); |
|
150 | - $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
151 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
152 | - foreach ( $pid as &$p ) { |
|
153 | - $p = new $ImageClass( $p ); |
|
148 | + return new $PostClass($pid); |
|
149 | + } )); |
|
150 | + $twig->addFunction(new Twig_SimpleFunction('Image', function($pid, $ImageClass = 'TimberImage') { |
|
151 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
152 | + foreach ($pid as &$p) { |
|
153 | + $p = new $ImageClass($p); |
|
154 | 154 | } |
155 | 155 | return $pid; |
156 | 156 | } |
157 | - return new $ImageClass( $pid ); |
|
158 | - } ) ); |
|
159 | - $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
160 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
161 | - foreach ( $pid as &$p ) { |
|
162 | - $p = new $TermClass( $p ); |
|
157 | + return new $ImageClass($pid); |
|
158 | + } )); |
|
159 | + $twig->addFunction(new Twig_SimpleFunction('Term', function($pid, $TermClass = 'TimberTerm') { |
|
160 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
161 | + foreach ($pid as &$p) { |
|
162 | + $p = new $TermClass($p); |
|
163 | 163 | } |
164 | 164 | return $pid; |
165 | 165 | } |
166 | - return new $TermClass( $pid ); |
|
167 | - } ) ); |
|
168 | - $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) { |
|
169 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
170 | - foreach ( $pid as &$p ) { |
|
171 | - $p = new $UserClass( $p ); |
|
166 | + return new $TermClass($pid); |
|
167 | + } )); |
|
168 | + $twig->addFunction(new Twig_SimpleFunction('User', function($pid, $UserClass = 'TimberUser') { |
|
169 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
170 | + foreach ($pid as &$p) { |
|
171 | + $p = new $UserClass($p); |
|
172 | 172 | } |
173 | 173 | return $pid; |
174 | 174 | } |
175 | - return new $UserClass( $pid ); |
|
176 | - } ) ); |
|
175 | + return new $UserClass($pid); |
|
176 | + } )); |
|
177 | 177 | |
178 | 178 | /* bloginfo and translate */ |
179 | - $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) { |
|
180 | - return get_bloginfo( $show, $filter ); |
|
181 | - } ) ); |
|
182 | - $twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) { |
|
183 | - return __( $text, $domain ); |
|
184 | - } ) ); |
|
179 | + $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw') { |
|
180 | + return get_bloginfo($show, $filter); |
|
181 | + } )); |
|
182 | + $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default') { |
|
183 | + return __($text, $domain); |
|
184 | + } )); |
|
185 | 185 | /* get_twig is deprecated, use timber/twig */ |
186 | - $twig = apply_filters( 'get_twig', $twig ); |
|
187 | - $twig = apply_filters( 'timber/twig', $twig ); |
|
186 | + $twig = apply_filters('get_twig', $twig); |
|
187 | + $twig = apply_filters('timber/twig', $twig); |
|
188 | 188 | return $twig; |
189 | 189 | } |
190 | 190 | |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | * @param mixed $arr |
195 | 195 | * @return array |
196 | 196 | */ |
197 | - function to_array( $arr ) { |
|
198 | - if ( is_array( $arr ) ) { |
|
197 | + function to_array($arr) { |
|
198 | + if ( is_array($arr) ) { |
|
199 | 199 | return $arr; |
200 | 200 | } |
201 | - $arr = array( $arr ); |
|
201 | + $arr = array($arr); |
|
202 | 202 | return $arr; |
203 | 203 | } |
204 | 204 | |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | * @param string $function_name |
209 | 209 | * @return mixed |
210 | 210 | */ |
211 | - function exec_function( $function_name ) { |
|
211 | + function exec_function($function_name) { |
|
212 | 212 | $args = func_get_args(); |
213 | - array_shift( $args ); |
|
213 | + array_shift($args); |
|
214 | 214 | if ( is_string($function_name) ) { |
215 | - $function_name = trim( $function_name ); |
|
215 | + $function_name = trim($function_name); |
|
216 | 216 | } |
217 | - return call_user_func_array( $function_name, ( $args ) ); |
|
217 | + return call_user_func_array($function_name, ($args)); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string $content |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - function twig_pretags( $content ) { |
|
227 | - return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content ); |
|
226 | + function twig_pretags($content) { |
|
227 | + return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @param array $matches |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - function convert_pre_entities( $matches ) { |
|
237 | - return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] ); |
|
236 | + function convert_pre_entities($matches) { |
|
237 | + return str_replace($matches[1], htmlentities($matches[1]), $matches[0]); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * @deprecated 0.20.7 |
243 | 243 | * @return string |
244 | 244 | */ |
245 | - function body_class( $body_classes ) { |
|
245 | + function body_class($body_classes) { |
|
246 | 246 | ob_start(); |
247 | - if ( is_array( $body_classes ) ) { |
|
248 | - $body_classes = explode( ' ', $body_classes ); |
|
247 | + if ( is_array($body_classes) ) { |
|
248 | + $body_classes = explode(' ', $body_classes); |
|
249 | 249 | } |
250 | - body_class( $body_classes ); |
|
250 | + body_class($body_classes); |
|
251 | 251 | $return = ob_get_contents(); |
252 | 252 | ob_end_clean(); |
253 | 253 | return $return; |
@@ -260,20 +260,20 @@ discard block |
||
260 | 260 | * @param string $format (optional) |
261 | 261 | * @return string |
262 | 262 | */ |
263 | - function intl_date( $date, $format = null ) { |
|
263 | + function intl_date($date, $format = null) { |
|
264 | 264 | if ( $format === null ) { |
265 | - $format = get_option( 'date_format' ); |
|
265 | + $format = get_option('date_format'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | if ( $date instanceof DateTime ) { |
269 | 269 | $timestamp = $date->getTimestamp(); |
270 | - } else if (is_numeric( $date ) && strtotime( $date ) === false ) { |
|
271 | - $timestamp = intval( $date ); |
|
270 | + } else if ( is_numeric($date) && strtotime($date) === false ) { |
|
271 | + $timestamp = intval($date); |
|
272 | 272 | } else { |
273 | - $timestamp = strtotime( $date ); |
|
273 | + $timestamp = strtotime($date); |
|
274 | 274 | } |
275 | 275 | |
276 | - return date_i18n( $format, $timestamp ); |
|
276 | + return date_i18n($format, $timestamp); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | //debug |
@@ -285,17 +285,17 @@ discard block |
||
285 | 285 | * @param bool $methods |
286 | 286 | * @return string |
287 | 287 | */ |
288 | - function object_docs( $obj, $methods = true ) { |
|
289 | - $class = get_class( $obj ); |
|
290 | - $properties = (array)$obj; |
|
288 | + function object_docs($obj, $methods = true) { |
|
289 | + $class = get_class($obj); |
|
290 | + $properties = (array) $obj; |
|
291 | 291 | if ( $methods ) { |
292 | 292 | /** @var array $methods */ |
293 | 293 | $methods = $obj->get_method_values(); |
294 | 294 | } |
295 | - $rets = array_merge( $properties, $methods ); |
|
296 | - ksort( $rets ); |
|
297 | - $str = print_r( $rets, true ); |
|
298 | - $str = str_replace( 'Array', $class . ' Object', $str ); |
|
295 | + $rets = array_merge($properties, $methods); |
|
296 | + ksort($rets); |
|
297 | + $str = print_r($rets, true); |
|
298 | + $str = str_replace('Array', $class . ' Object', $str); |
|
299 | 299 | return $str; |
300 | 300 | } |
301 | 301 | |
@@ -306,15 +306,15 @@ discard block |
||
306 | 306 | * @param string $format_future |
307 | 307 | * @return string |
308 | 308 | */ |
309 | - function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) { |
|
309 | + function time_ago($from, $to = null, $format_past = '%s ago', $format_future = '%s from now') { |
|
310 | 310 | $to = $to === null ? time() : $to; |
311 | - $to = is_int( $to ) ? $to : strtotime( $to ); |
|
312 | - $from = is_int( $from ) ? $from : strtotime( $from ); |
|
311 | + $to = is_int($to) ? $to : strtotime($to); |
|
312 | + $from = is_int($from) ? $from : strtotime($from); |
|
313 | 313 | |
314 | 314 | if ( $from < $to ) { |
315 | - return sprintf( $format_past, human_time_diff( $from, $to ) ); |
|
315 | + return sprintf($format_past, human_time_diff($from, $to)); |
|
316 | 316 | } else { |
317 | - return sprintf( $format_future, human_time_diff( $to, $from ) ); |
|
317 | + return sprintf($format_future, human_time_diff($to, $from)); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -324,18 +324,18 @@ discard block |
||
324 | 324 | * @param string $second_delimiter |
325 | 325 | * @return string |
326 | 326 | */ |
327 | - function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) { |
|
328 | - $length = count( $arr ); |
|
327 | + function add_list_separators($arr, $first_delimiter = ',', $second_delimiter = 'and') { |
|
328 | + $length = count($arr); |
|
329 | 329 | $list = ''; |
330 | - foreach( $arr as $index => $item ) { |
|
330 | + foreach ($arr as $index => $item) { |
|
331 | 331 | if ( $index < $length - 2 ) { |
332 | - $delimiter = $first_delimiter.' '; |
|
332 | + $delimiter = $first_delimiter . ' '; |
|
333 | 333 | } elseif ( $index == $length - 2 ) { |
334 | - $delimiter = ' '.$second_delimiter.' '; |
|
334 | + $delimiter = ' ' . $second_delimiter . ' '; |
|
335 | 335 | } else { |
336 | 336 | $delimiter = ''; |
337 | 337 | } |
338 | - $list = $list.$item.$delimiter; |
|
338 | + $list = $list . $item . $delimiter; |
|
339 | 339 | } |
340 | 340 | return $list; |
341 | 341 | } |