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

107 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Gets a specific external variable by name and optionally filters it.
5 *
6 * This is a polyfill function intended to be used in place of PHP's
7 * filter_input() function, which can occasionally be unreliable.
8 *
9 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
10 * @param string $variable_name Name of a variable to get.
11 * @param int $filter The ID of the filter to apply.
12 * @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.
13 *
14 * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
15 */
16 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
17 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
18 }
19
20 /**
21 * Filters a variable with a specified filter.
22 *
23 * This is a polyfill function intended to be used in place of PHP's
24 * filter_var() function, which can occasionally be unreliable.
25 *
26 * @param string $var Value to filter.
27 * @param int $filter The ID of the filter to apply.
28 * @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.
29 *
30 * @return Returns the filtered data, or FALSE if the filter fails.
31 */
32 function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
33 return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
34 }
35
36 /**
37 * Converts a time into an ISO 8601 extended formatted string.
38 *
39 * @param int|bool $time Seconds since unix epoc
40 * @param int $offset Hour offset
41 *
42 * @return string an ISO 8601 extended formatted time
43 */
44 function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
45 if ( $time ) {
46 $microtime = (float) $time . '.0000';
47 } else {
48 $microtime = microtime( true );
49 }
50
51 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
52 $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
53
54 $timezone = new DateTimeZone( $offset_string );
55 $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
56
57 return sprintf(
58 '%s%03d%s',
59 $date->format( 'Y-m-d\TH:i:s.' ),
60 floor( $date->format( 'u' ) / 1000 ),
61 $date->format( 'O' )
62 );
63 }
64
65 /**
66 * Encode to JSON in a way that is also backwards compatible
67 *
68 * @param mixed $data
69 * @param int $options (optional)
70 * @param int $depth (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 * Check if Stream is running on WordPress.com VIP
92 *
93 * @return bool
94 */
95 function wp_stream_is_vip() {
96 return function_exists( 'wpcom_vip_load_plugin' );
97 }
98
99 /**
100 * True if native WP Cron is enabled, otherwise false
101 *
102 * @return bool
103 */
104 function wp_stream_is_cron_enabled() {
105 return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true;
106 }
107