PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
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.8.2, at includes/functions.php

151 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Defines common functionality used throughout the plugin.
4 *
5 * @package WP_Stream
6 */
7
8 /**
9 * Gets a specific external variable by name and optionally filters it.
10 *
11 * This is a polyfill function intended to be used in place of PHP's
12 * filter_input() function, which can occasionally be unreliable.
13 *
14 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
15 * @param string $variable_name Name of a variable to get.
16 * @param int $filter The ID of the filter to apply.
17 * @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.
18 *
19 * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
20 */
21 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
22 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
23 }
24
25 /**
26 * Filters a variable with a specified filter.
27 *
28 * This is a polyfill function intended to be used in place of PHP's
29 * filter_var() function, which can occasionally be unreliable.
30 *
31 * @param string $var Value to filter.
32 * @param int $filter The ID of the filter to apply.
33 * @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.
34 *
35 * @return Returns the filtered data, or FALSE if the filter fails.
36 */
37 function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
38 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
39 }
40
41 /**
42 * Converts a time into an ISO 8601 extended formatted string.
43 *
44 * @param int|bool $time Seconds since unix epoch.
45 * @param int $offset Timezone offset.
46 *
47 * @return string an ISO 8601 extended formatted time
48 */
49 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
50 if ( $time ) {
51 $microtime = (float) $time . '.0000';
52 } else {
53 $microtime = microtime( true );
54 }
55
56 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
57 $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
58
59 $timezone = new DateTimeZone( $offset_string );
60 $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
61
62 return $date->format( 'Y-m-d\TH:i:sO' );
63 }
64
65 /**
66 * Encode to JSON in a way that is also backwards compatible
67 *
68 * @param mixed $data Data to be encoded.
69 * @param int $options Compression options (optional).
70 * @param int $depth Tree depth limit (optional).
71 *
72 * @return string
73 */
74 function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
75 if ( function_exists( 'wp_json_encode' ) ) {
76 $json = wp_json_encode( $data, $options, $depth );
77 } else {
78 // @codingStandardsIgnoreStart
79 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
80 $json = json_encode( $data, $options );
81 } else {
82 $json = json_encode( $data, $options, $depth );
83 }
84 // @codingStandardsIgnoreEnd
85 }
86
87 return $json;
88 }
89
90 /**
91 * Return an array of sites for a network in a way that is also backwards compatible
92 *
93 * @param string|array $args Argument to filter results by.
94 *
95 * @return array
96 */
97 function wp_stream_get_sites( $args = array() ) {
98 if ( empty( $args['limit'] ) ) {
99 $args['limit'] = 0;
100 }
101
102 if ( function_exists( 'get_sites' ) ) {
103 // Account for get_sites() which uses 'number' while wp_get_sites() uses 'limit'.
104 $args['number'] = $args['limit'];
105
106 $sites = get_sites( $args );
107 } else {
108 $sites = array();
109 foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
110 $sites[] = WP_Site::get_instance( $site['blog_id'] );
111 }
112 }
113
114 return $sites;
115 }
116
117 /**
118 * Check if Stream is running on WordPress.com VIP
119 *
120 * @return bool
121 */
122 function wp_stream_is_vip() {
123 return function_exists( 'wpcom_vip_load_plugin' );
124 }
125
126 /**
127 * Check if the default front-end WP Cron is enabled. It doesn't
128 * mean that the Cron is disabled in general.
129 *
130 * @return bool
131 */
132 function wp_stream_is_cron_enabled() {
133 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
134 }
135
136 /**
137 * Get the asset min suffix if defined.
138 *
139 * @return string
140 */
141 function wp_stream_min_suffix() {
142 $min = '';
143 $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
144
145 if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
146 $min = 'min.';
147 }
148
149 return $min;
150 }
151