| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * Gets a specific external variable by name and optionally filters it. |
| 5 | 4 | * |
| 6 | 5 | * This is a polyfill function intended to be used in place of PHP's |
| @@ -5,10 +4,8 @@ | ||
| 5 | 4 | * |
| 6 | 5 | * This is a polyfill function intended to be used in place of PHP's |
| 7 | 6 | * filter_input() function, which can occasionally be unreliable. |
| 8 | 7 | * |
| 9 | - * @since 1.2.5 | |
| 10 | - * | |
| 11 | 8 | * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV. |
| 12 | 9 | * @param string $variable_name Name of a variable to get. |
| 13 | 10 | * @param int $filter The ID of the filter to apply. |
| 14 | 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. |
| @@ -15,9 +12,9 @@ | ||
| 15 | 12 | * |
| 16 | 13 | * @return Value of the requested variable on success, FALSE if the filter fails, or NULL if the $variable_name is not set. |
| 17 | 14 | */ |
| 18 | 15 | 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() ); | |
| 16 | + return call_user_func_array( array( '\WP_Stream\Filter_Input', 'super' ), func_get_args() ); | |
| 20 | 17 | } |
| 21 | 18 | |
| 22 | 19 | /** |
| 23 | 20 | * Filters a variable with a specified filter. |
| @@ -24,10 +21,8 @@ | ||
| 24 | 21 | * |
| 25 | 22 | * This is a polyfill function intended to be used in place of PHP's |
| 26 | 23 | * filter_var() function, which can occasionally be unreliable. |
| 27 | 24 | * |
| 28 | - * @since 1.2.5 | |
| 29 | - * | |
| 30 | 25 | * @param string $var Value to filter. |
| 31 | 26 | * @param int $filter The ID of the filter to apply. |
| 32 | 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. |
| 33 | 28 | * |
| @@ -33,38 +28,20 @@ | ||
| 33 | 28 | * |
| 34 | 29 | * @return Returns the filtered data, or FALSE if the filter fails. |
| 35 | 30 | */ |
| 36 | 31 | 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() ); | |
| 32 | + return call_user_func_array( array( '\WP_Stream\Filter_Input', 'filter' ), func_get_args() ); | |
| 38 | 33 | } |
| 39 | 34 | |
| 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 | 35 | /** |
| 59 | 36 | * Converts a time into an ISO 8601 extended formatted string. |
| 60 | 37 | * |
| 61 | - * @param int Seconds since unix epoc | |
| 62 | - * @param int Hour offset | |
| 38 | + * @param int|bool $time Seconds since unix epoc | |
| 39 | + * @param int $offset Hour offset | |
| 63 | 40 | * |
| 64 | 41 | * @return string an ISO 8601 extended formatted time |
| 65 | 42 | */ |
| 66 | -function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) { | |
| 43 | +function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) { | |
| 67 | 44 | if ( $time ) { |
| 68 | 45 | $microtime = (float) $time . '.0000'; |
| 69 | 46 | } else { |
| 70 | 47 | $microtime = microtime( true ); |
| @@ -84,47 +61,82 @@ | ||
| 84 | 61 | ); |
| 85 | 62 | } |
| 86 | 63 | |
| 87 | 64 | /** |
| 88 | - * Returns array of existing values for requested field. | |
| 89 | - * Used to fill search filters with only used items, instead of all items. | |
| 65 | + * Encode to JSON in a way that is also backwards compatible | |
| 90 | 66 | * |
| 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 | |
| 67 | + * @param mixed $data | |
| 68 | + * @param int $options (optional) | |
| 69 | + * @param int $depth (optional) | |
| 70 | + * | |
| 71 | + * @return string | |
| 95 | 72 | */ |
| 96 | -function wp_stream_existing_records( $field ) { | |
| 97 | - $values = WP_Stream::$db->get_distinct_field_values( $field ); | |
| 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 | + } | |
| 98 | 85 | |
| 99 | - if ( is_array( $values ) && ! empty( $values ) ) { | |
| 100 | - return array_combine( $values, $values ); | |
| 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 ); | |
| 101 | 99 | } else { |
| 102 | - $field = sprintf( 'stream_%s', $field ); | |
| 103 | - return isset( WP_Stream_Connectors::$term_labels[ $field ] ) ? WP_Stream_Connectors::$term_labels[ $field ] : array(); | |
| 100 | + $sites = array(); | |
| 101 | + foreach ( wp_get_sites( $args ) as $site ) { // @codingStandardsIgnoreLine Specifically for old version of WP first, in order to provide backward compatibility | |
| 102 | + $sites[] = WP_Site::get_instance( $site['blog_id'] ); | |
| 103 | + } | |
| 104 | 104 | } |
| 105 | + | |
| 106 | + return $sites; | |
| 105 | 107 | } |
| 106 | 108 | |
| 107 | 109 | /** |
| 108 | - * Determine the title of an object that a record is for. | |
| 110 | + * Check if Stream is running on WordPress.com VIP | |
| 109 | 111 | * |
| 110 | - * @since 2.1.0 | |
| 111 | - * @param object Record object | |
| 112 | - * @return mixed The title of the object as a string, otherwise false | |
| 112 | + * @return bool | |
| 113 | 113 | */ |
| 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 | - } | |
| 114 | +function wp_stream_is_vip() { | |
| 115 | + return function_exists( 'wpcom_vip_load_plugin' ); | |
| 116 | +} | |
| 118 | 117 | |
| 119 | - $output = false; | |
| 118 | +/** | |
| 119 | + * Check if the default front-end WP Cron is enabled. It doesn't | |
| 120 | + * mean that the Cron is disabled in general. | |
| 121 | + * | |
| 122 | + * @return bool | |
| 123 | + */ | |
| 124 | +function wp_stream_is_cron_enabled() { | |
| 125 | + return ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ? false : true; | |
| 126 | +} | |
| 120 | 127 | |
| 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; | |
| 128 | +/** | |
| 129 | + * Get the asset min suffix if defined. | |
| 130 | + * | |
| 131 | + * @return string | |
| 132 | + */ | |
| 133 | +function wp_stream_min_suffix() { | |
| 134 | + $min = ''; | |
| 135 | + $is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG; | |
| 136 | + | |
| 137 | + if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) { | |
| 138 | + $min = 'min.'; | |
| 127 | 139 | } |
| 128 | 140 | |
| 129 | - return $output; | |
| 141 | + return $min; | |
| 130 | 142 | } |