PluginProbe
Stream – Activity Log & Audit Trail / 3.9.0
Stream – Activity Log & Audit Trail v3.9.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
← All changes | includes/functions.php +83 -63 2.0.23.9.0 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Defines common functionality used throughout the plugin.
4 + *
5 + * @package WP_Stream
6 + */
2 7
3 8 /**
4 9 * Gets a specific external variable by name and optionally filters it.
5 10 *
@@ -5,10 +10,8 @@
5 10 *
6 11 * This is a polyfill function intended to be used in place of PHP's
7 12 * filter_input() function, which can occasionally be unreliable.
8 13 *
9 - * @since 1.2.5
10 - *
11 14 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
12 15 * @param string $variable_name Name of a variable to get.
13 16 * @param int $filter The ID of the filter to apply.
14 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.
@@ -15,9 +18,9 @@
15 18 *
16 19 * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set.
17 20 */
18 21 function wp_stream_filter_input( $type, $variable_name, $filter = null, $options = array() ) {
19 - return call_user_func_array( array( 'WP_Stream_Filter_Input', 'super' ), func_get_args() );
22 + return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() );
20 23 }
21 24
22 25 /**
23 26 * Filters a variable with a specified filter.
@@ -24,10 +27,8 @@
24 27 *
25 28 * This is a polyfill function intended to be used in place of PHP's
26 29 * filter_var() function, which can occasionally be unreliable.
27 30 *
28 - * @since 1.2.5
29 - *
30 31 * @param string $var Value to filter.
31 32 * @param int $filter The ID of the filter to apply.
32 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.
33 34 *
@@ -33,38 +34,20 @@
33 34 *
34 35 * @return Returns the filtered data, or FALSE if the filter fails.
35 36 */
36 37 function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
37 - return call_user_func_array( array( 'WP_Stream_Filter_Input', 'filter' ), func_get_args() );
38 + return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() );
38 39 }
39 40
40 -function wp_stream_query( $args = array() ) {
41 - return WP_Stream_Query::instance()->query( $args );
42 -}
43 -
44 -function wp_stream_get_meta( $record, $meta_key = '', $single = false ) {
45 - if ( isset( $record->stream_meta->$meta_key ) ) {
46 - $record_meta = $record->stream_meta->$meta_key;
47 - } else {
48 - return '';
49 - }
50 -
51 - if ( $single ) {
52 - return $record_meta;
53 - } else {
54 - return array( $record_meta );
55 - }
56 -}
57 -
58 41 /**
59 42 * Converts a time into an ISO 8601 extended formatted string.
60 43 *
61 - * @param int Seconds since unix epoc
62 - * @param int Hour offset
44 + * @param int|bool $time Seconds since unix epoch.
45 + * @param int $offset Timezone offset.
63 46 *
64 47 * @return string an ISO 8601 extended formatted time
65 48 */
66 -function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
49 +function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
67 50 if ( $time ) {
68 51 $microtime = (float) $time . '.0000';
69 52 } else {
70 53 $microtime = microtime( true );
@@ -70,61 +53,98 @@
70 53 $microtime = microtime( true );
71 54 }
72 55
73 56 $micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
74 - $offset_string = sprintf( 'Etc/GMT%s%s', $offset < 0 ? '+' : '-', abs( $offset ) );
57 + $offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
75 58
76 59 $timezone = new DateTimeZone( $offset_string );
77 - $date = new DateTime( date( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
60 + $date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
78 61
79 - return sprintf(
80 - '%s%03d%s',
81 - $date->format( 'Y-m-d\TH:i:s.' ),
82 - floor( $date->format( 'u' ) / 1000 ),
83 - $date->format( 'O' )
84 - );
62 + return $date->format( 'Y-m-d\TH:i:sO' );
85 63 }
86 64
87 65 /**
88 - * Returns array of existing values for requested field.
89 - * Used to fill search filters with only used items, instead of all items.
66 + * Encode to JSON in a way that is also backwards compatible
90 67 *
91 - * @see assemble_records
92 - * @since 1.0.4
93 - * @param string Requested field (i.e., 'context')
94 - * @return array Array of items to be output to select dropdowns
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
95 73 */
96 -function wp_stream_existing_records( $field ) {
97 - $values = WP_Stream::$db->get_distinct_field_values( $field );
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 + }
98 86
99 - if ( is_array( $values ) && ! empty( $values ) ) {
100 - return array_combine( $values, $values );
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 );
101 107 } else {
102 - $field = sprintf( 'stream_%s', $field );
103 - return isset( WP_Stream_Connectors::$term_labels[ $field ] ) ? WP_Stream_Connectors::$term_labels[ $field ] : array();
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 + }
104 112 }
113 +
114 + return $sites;
105 115 }
106 116
107 117 /**
108 - * Determine the title of an object that a record is for.
118 + * Check if Stream is running on WordPress.com VIP
109 119 *
110 - * @since 2.1.0
111 - * @param object Record object
112 - * @return mixed The title of the object as a string, otherwise false
120 + * @return bool
113 121 */
114 -function wp_stream_get_object_title( $record ) {
115 - if ( ! is_object( $record ) || ! isset( $record->object_id ) || empty( $record->object_id ) ) {
116 - return false;
117 - }
122 +function wp_stream_is_vip() {
123 + return function_exists( 'wpcom_vip_load_plugin' );
124 +}
118 125
119 - $output = false;
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 +}
120 135
121 - if ( isset( $record->stream_meta->post_title ) && ! empty( $record->stream_meta->post_title ) ) {
122 - $output = (string) $record->stream_meta->post_title;
123 - } elseif ( isset( $record->stream_meta->display_name ) && ! empty( $record->stream_meta->display_name ) ) {
124 - $output = (string) $record->stream_meta->display_name;
125 - } elseif ( isset( $record->stream_meta->name ) && ! empty( $record->stream_meta->name ) ) {
126 - $output = (string) $record->stream_meta->name;
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.';
127 147 }
128 148
129 - return $output;
149 + return $min;
130 150 }