PluginProbe
Stream – Activity Log & Audit Trail / 3.2.1
Stream – Activity Log & Audit Trail v3.2.1
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / includes / functions.php

functions.php in Stream – Activity Log & Audit Trail 3.2.1, at includes/functions.php

126 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gets a specific external variable by name and optionally filters it.
4 *
5 * This is a polyfill function intended to be used in place of PHP's
6 * filter_input() function, which can occasionally be unreliable.
7 *
8 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
9 * @param string $variable_name Name of a variable to get.
10 * @param int $filter The ID of the filter to apply.
11 * @param mixed $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array.
12 *
13 * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
14 */
15 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
16 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
17 }
18
19 /**
20 * Filters a variable with a specified filter.
21 *
22 * This is a polyfill function intended to be used in place of PHP's
23 * filter_var() function, which can occasionally be unreliable.
24 *
25 * @param string $var Value to filter.
26 * @param int $filter The ID of the filter to apply.
27 * @param mixed $options Associative array of options or bitwise disjunction of flags. If filter accepts options, flags can be provided in "flags" field of array. For the "callback" filter, callable type should be passed. The callback must accept one argument, the value to be filtered, and return the value after filtering/sanitizing it.
28 *
29 * @return Returns the filtered data, or FALSE if the filter fails.
30 */
31 function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
32 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
33 }
34
35 /**
36 * Converts a time into an ISO 8601 extended formatted string.
37 *
38 * @param int|bool $time Seconds since unix epoc
39 * @param int $offset Hour offset
40 *
41 * @return string an ISO 8601 extended formatted time
42 */
43 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
44 if ( $time ) {
45 $microtime = (float) $time . '.0000';
46 } else {
47 $microtime = microtime( true );
48 }
49
50 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
51 $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
52
53 $timezone = new DateTimeZone( $offset_string );
54 $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
55
56 return sprintf(
57 '%s%03d%s',
58 $date->format( 'Y-m-d\TH:i:s.' ),
59 floor( $date->format( 'u' ) / 1000 ),
60 $date->format( 'O' )
61 );
62 }
63
64 /**
65 * Encode to JSON in a way that is also backwards compatible
66 *
67 * @param mixed $data
68 * @param int $options (optional)
69 * @param int $depth (optional)
70 *
71 * @return string
72 */
73 function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
74 if ( function_exists( 'wp_json_encode' ) ) {
75 $json = wp_json_encode( $data, $options, $depth );
76 } else {
77 // @codingStandardsIgnoreStart
78 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
79 $json = json_encode( $data, $options );
80 } else {
81 $json = json_encode( $data, $options, $depth );
82 }
83 // @codingStandardsIgnoreEnd
84 }
85
86 return $json;
87 }
88
89 /**
90 * Return an array of sites for a network in a way that is also backwards compatible
91 *
92 * @param string|array $args
93 *
94 * @return array
95 */
96 function wp_stream_get_sites( $args = array() ) {
97 if ( function_exists( 'get_sites' ) ) {
98 $sites = get_sites( $args );
99 } else {
100 $sites = array();
101 foreach ( wp_get_sites( $args ) as $site ) {
102 $sites[] = WP_Site::get_instance( $site['blog_id'] );
103 }
104 }
105
106 return $sites;
107 }
108
109 /**
110 * Check if Stream is running on WordPress.com VIP
111 *
112 * @return bool
113 */
114 function wp_stream_is_vip() {
115 return function_exists( 'wpcom_vip_load_plugin' );
116 }
117
118 /**
119 * True if native WP Cron is enabled, otherwise false
120 *
121 * @return bool
122 */
123 function wp_stream_is_cron_enabled() {
124 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
125 }
126