PluginProbe
Stream – Activity Log & Audit Trail / 3.6.1
Stream – Activity Log & Audit Trail v3.6.1
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 | classes/class-db.php +37 -25 3.2.23.6.1 View file →
@@ -1,10 +1,19 @@
1 1 <?php
2 +/**
3 + * Manage DB connections using a provided DB driver.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - DB
12 + */
4 13 class DB {
5 14 /**
6 - * Hold the Driver class
15 + * Holds the driver instance
7 16 *
8 17 * @var DB_Driver
9 18 */
10 19 public $driver;
@@ -27,9 +36,9 @@
27 36
28 37 /**
29 38 * Insert a record
30 39 *
31 - * @param array $record
40 + * @param array $record New record.
32 41 *
33 42 * @return int
34 43 */
35 44 public function insert( $record ) {
@@ -45,13 +54,16 @@
45 54 * @return array
46 55 */
47 56 $record = apply_filters( 'wp_stream_record_array', $record );
48 57
49 - array_walk( $record, function( &$value, &$key ) {
50 - if ( ! is_array( $value ) ) {
51 - $value = strip_tags( $value );
58 + array_walk(
59 + $record,
60 + function( &$value, &$key ) {
61 + if ( ! is_array( $value ) ) {
62 + $value = wp_strip_all_tags( $value );
63 + }
52 64 }
53 - });
65 + );
54 66
55 67 if ( empty( $record ) ) {
56 68 return false;
57 69 }
@@ -93,14 +105,14 @@
93 105 *
94 106 * @see assemble_records
95 107 * @since 1.0.4
96 108 *
97 - * @param string $column
109 + * @param string $column Table column to pull data from.
98 110 *
99 111 * @return array
100 112 */
101 113 public function existing_records( $column ) {
102 - // Sanitize column
114 + // Sanitize column.
103 115 $allowed_columns = array( 'ID', 'site_id', 'blog_id', 'object_id', 'user_id', 'user_role', 'created', 'summary', 'connector', 'context', 'action', 'ip' );
104 116 if ( ! in_array( $column, $allowed_columns, true ) ) {
105 117 return array();
106 118 }
@@ -127,39 +139,39 @@
127 139
128 140 /**
129 141 * Get stream records
130 142 *
131 - * @param array Query args
143 + * @param array $args Arguments to filter result by.
132 144 *
133 145 * @return array Stream Records
134 146 */
135 147 public function get_records( $args ) {
136 148 $defaults = array(
137 - // Search param
149 + // Search param.
138 150 'search' => null,
139 151 'search_field' => 'summary',
140 152 'record_after' => null, // Deprecated, use date_after instead
141 - // Date-based filters
142 - 'date' => null, // Ex: 2015-07-01
143 - 'date_from' => null, // Ex: 2015-07-01
144 - 'date_to' => null, // Ex: 2015-07-01
145 - 'date_after' => null, // Ex: 2015-07-01T15:19:21+00:00
146 - 'date_before' => null, // Ex: 2015-07-01T15:19:21+00:00
147 - // Record ID filters
153 + // Date-based filters.
154 + 'date' => null, // Ex: 2015-07-01.
155 + 'date_from' => null, // Ex: 2015-07-01.
156 + 'date_to' => null, // Ex: 2015-07-01.
157 + 'date_after' => null, // Ex: 2015-07-01T15:19:21+00:00.
158 + 'date_before' => null, // Ex: 2015-07-01T15:19:21+00:00.
159 + // Record ID filters.
148 160 'record' => null,
149 161 'record__in' => array(),
150 162 'record__not_in' => array(),
151 - // Pagination params
163 + // Pagination params.
152 164 'records_per_page' => get_option( 'posts_per_page', 20 ),
153 165 'paged' => 1,
154 - // Order
166 + // Order.
155 167 'order' => 'desc',
156 168 'orderby' => 'date',
157 - // Fields selection
169 + // Fields selection.
158 170 'fields' => array(),
159 171 );
160 172
161 - // Additional property fields
173 + // Additional property fields.
162 174 $properties = array(
163 175 'user_id' => null,
164 176 'user_role' => null,
165 177 'ip' => null,
@@ -177,9 +189,9 @@
177 189 * @return array Array of query properties
178 190 */
179 191 $properties = apply_filters( 'wp_stream_query_properties', $properties );
180 192
181 - // Add property fields to defaults, including their __in/__not_in variations
193 + // Add property fields to defaults, including their __in/__not_in variations.
182 194 foreach ( $properties as $property => $default ) {
183 195 if ( ! isset( $defaults[ $property ] ) ) {
184 196 $defaults[ $property ] = $default;
185 197 }
@@ -196,9 +208,9 @@
196 208 * @return array Array of query arguments
197 209 */
198 210 $args = apply_filters( 'wp_stream_query_args', $args );
199 211
200 - $result = (array) $this->driver->get_records( $args );
212 + $result = (array) $this->driver->get_records( $args );
201 213 $this->found_records_count = isset( $result['count'] ) ? $result['count'] : 0;
202 214
203 215 return empty( $result['items'] ) ? array() : $result['items'];
204 216 }
@@ -205,9 +217,9 @@
205 217
206 218 /**
207 219 * Helper function, backwards compatibility
208 220 *
209 - * @param array $args Query args
221 + * @param array $args Argument to filter result by.
210 222 *
211 223 * @return array Stream Records
212 224 */
213 225 public function query( $args ) {
@@ -216,9 +228,9 @@
216 228
217 229 /**
218 230 * Return the number of records found in last request
219 231 *
220 - * return int
232 + * @return int
221 233 */
222 234 public function get_found_records_count() {
223 235 return $this->found_records_count;
224 236 }