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

144 lines 4.6 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 ( function_exists( 'get_sites' ) ) {
99 $sites = get_sites( $args );
100 } else {
101 $sites = array();
102 foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility
103 $sites[] = WP_Site::get_instance( $site['blog_id'] );
104 }
105 }
106
107 return $sites;
108 }
109
110 /**
111 * Check if Stream is running on WordPress.com VIP
112 *
113 * @return bool
114 */
115 function wp_stream_is_vip() {
116 return function_exists( 'wpcom_vip_load_plugin' );
117 }
118
119 /**
120 * Check if the default front-end WP Cron is enabled. It doesn't
121 * mean that the Cron is disabled in general.
122 *
123 * @return bool
124 */
125 function wp_stream_is_cron_enabled() {
126 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
127 }
128
129 /**
130 * Get the asset min suffix if defined.
131 *
132 * @return string
133 */
134 function wp_stream_min_suffix() {
135 $min = '';
136 $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
137
138 if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
139 $min = 'min.';
140 }
141
142 return $min;
143 }
144