PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-logging.php
give / includes Last commit date
admin 1 year ago api 3 years ago database 2 years ago deprecated 3 years ago donors 1 year ago emails 3 years ago forms 1 year ago frontend 6 years ago gateways 1 year ago libraries 2 years ago payments 1 year ago actions.php 5 years ago ajax-functions.php 2 years ago class-give-async-process.php 1 year ago class-give-background-updater.php 2 years ago class-give-cache-setting.php 2 years ago class-give-cache.php 3 years ago class-give-cli-commands.php 3 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 year ago class-give-logging.php 5 years ago class-give-readme-parser.php 4 years ago class-give-roles.php 6 years ago class-give-scripts.php 2 years ago class-give-session.php 5 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 4 years ago class-notices.php 2 years ago country-functions.php 1 year ago currencies-list.php 3 years ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 3 years ago formatting.php 1 year ago install.php 2 years ago login-register.php 2 years ago misc-functions.php 1 year ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 4 years ago user-functions.php 3 years ago
class-give-logging.php
315 lines
1 <?php
2
3 use Give\Log\Log;
4 use Give\Log\LogFactory;
5 use Give\Log\LogRepository;
6 use Give\Log\ValueObjects\LogType;
7 use Give\Log\Helpers\LogTypeHelper;
8 /**
9 * Class for logging events and errors
10 *
11 * @package Give
12 * @subpackage Classes/Give_Logging
13 * @copyright Copyright (c) 2016, GiveWP
14 * @license https://opensource.org/licenses/gpl-license GNU Public License
15 * @since 1.0
16 */
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Give_Logging Class
25 *
26 * A general use class for logging events and errors.
27 *
28 * @deprecated 2.10.0
29 * @use Log
30 * @see Log
31 *
32 * @since 1.0
33 */
34 class Give_Logging {
35 /**
36 * @var LogRepository
37 */
38 private $logRepository;
39
40 /**
41 * @var LogTypeHelper
42 */
43 private $logTypeHelper;
44
45 /**
46 * Class Constructor
47 *
48 * Set up the Give Logging Class.
49 *
50 * @since 1.0
51 * @access public
52 */
53 public function __construct() {
54 $this->logRepository = give( LogRepository::class );
55 $this->logTypeHelper = give( LogTypeHelper::class );
56 }
57
58 /**
59 * Create new log entry
60 *
61 * This is just a simple and fast way to log something. Use $this->insert_log()
62 * if you need to store custom meta data.
63 *
64 * @deprecated 2.10.0
65 * @use Log::LOG_TYPE( $message );
66 * @see Log
67 *
68 * @since 1.0
69 * @access public
70 *
71 * @param string $title Log entry title. Default is empty.
72 * @param string $message Log entry message. Default is empty.
73 * @param int $parent Log entry parent. Default is 0.
74 * @param string $type Log type. Default is empty string.
75 *
76 * @return int Log ID.
77 */
78 public function add( $title = '', $message = '', $parent = 0, $type = '' ) {
79 $log_data = [
80 'post_title' => $title,
81 'post_content' => $message,
82 'post_parent' => $parent,
83 'log_type' => $type,
84 ];
85
86 return $this->insert_log( $log_data );
87 }
88
89 /**
90 * Helper method used to map the fields from the old system to the new system
91 *
92 * @since 2.10.0
93 *
94 * @param array $logData
95 * @param array $logMeta
96 *
97 * @return array
98 */
99 private function getLogData( $logData, $logMeta ) {
100 $oldType = isset( $logData['log_type'] )
101 ? $logData['log_type']
102 : LogType::getDefault();
103
104 $data = $this->logTypeHelper->getDataFromType( $oldType );
105
106 $content = esc_html__( 'Something went wrong', 'give' );
107
108 if ( isset( $logData['log_content'] ) ) {
109 $content = $logData['log_content'];
110 } else {
111 if ( isset( $logData['post_title'] ) ) {
112 $content = $logData['post_title'];
113 }
114 }
115
116 return [
117 'type' => $data['type'],
118 'category' => $data['category'],
119 'message' => $content,
120 'context' => array_merge( $logData, $logMeta ),
121 ];
122 }
123
124 /**
125 * Get Logs
126 *
127 * Retrieves log items for a particular object ID.
128 *
129 * @deprecated 2.10.0
130 * @use LogRepository::getLogs();
131 * @see LogRepository
132 *
133 * @since 1.0
134 * @access public
135 *
136 * @param int $object_id Log object ID. Default is 0.
137 * @param string $type Log type. Default is empty string.
138 * @param int $paged Page number Default is null.
139 *
140 * @return array An array of the connected logs.
141 */
142 public function get_logs( $object_id = 0, $type = '', $paged = null ) {
143 if ( $object_id ) {
144 $log = $this->logRepository->getLog( $object_id );
145
146 return [
147 (object) [
148 'ID' => $log->getId(),
149 'log_date' => $log->getDate(),
150 'log_date_gmt' => '',
151 'log_content' => $log->getMessage(),
152 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
153 'log_type' => $log->getType(),
154 ],
155 ];
156 }
157
158 if ( ! empty( $type ) ) {
159 $data = [];
160 $logs = $this->logRepository->getLogsByType( $type );
161
162 foreach ( $logs as $log ) {
163 $data[] = (object) [
164 'ID' => $log->getId(),
165 'log_date' => $log->getDate(),
166 'log_date_gmt' => '',
167 'log_content' => $log->getMessage(),
168 'log_title' => $log->getCategory() . ' - ' . $log->getSource(),
169 'log_type' => $log->getType(),
170 ];
171 }
172
173 return $data;
174 }
175
176 return [];
177 }
178
179 /**
180 * Stores a log entry
181 *
182 * @deprecated 2.10.0
183 * @use Log::LOG_TYPE( $message );
184 * @see Log
185 *
186 * @since 1.0
187 * @access public
188 *
189 * @param array $log_data Log entry data.
190 * @param array $log_meta Log entry meta.
191 *
192 * @return int The ID of the newly created log item.
193 */
194 public function insert_log( $log_data = [], $log_meta = [] ) {
195 // Extract data from parameters
196 $data = $this->getLogData( $log_data, $log_meta );
197
198 $backtrace = debug_backtrace();
199
200 // Add more context
201 if (
202 isset( $backtrace[1] ) &&
203 ! array_diff( [ 'file', 'line', 'function', 'class' ], array_keys( $backtrace[1] ) )
204 ) {
205 $data['context']['file'] = $backtrace[1]['file'];
206 $data['context']['line'] = $backtrace[1]['line'];
207 $data['context']['function'] = $backtrace[1]['function'];
208 $data['context']['class'] = $backtrace[1]['class'];
209 }
210
211 try {
212 $log = LogFactory::makeFromArray( $data );
213 $log->save();
214
215 return $log->getId();
216 } catch ( Exception $exception ) {
217 error_log( $exception->getMessage() );
218 }
219 }
220
221 /**
222 * Update and existing log item
223 *
224 * @deprecated 2.10.0
225 * @use Log::LOG_TYPE( $message );
226 * @see Log
227 *
228 * @since 1.0
229 * @access public
230 *
231 * @param array $log_data Log entry data.
232 * @param array $log_meta Log entry meta.
233 *
234 * @return bool|null True if successful, false otherwise.
235 */
236 public function update_log( $log_data = [], $log_meta = [] ) {
237 return $this->insert_log( $log_data, $log_meta );
238 }
239
240 /**
241 * Retrieve all connected logs
242 *
243 * Used for retrieving logs related to particular items, such as a specific donation.
244 * For new table params check: Give_DB_Logs::get_column_defaults and Give_DB_Logs::get_sql#L262
245 *
246 * @deprecated 2.10.0
247 *
248 * @since 1.0
249 * @since 2.0 Added new table logic.
250 * @access public
251 *
252 * @param array $args Query arguments.
253 *
254 * @return array|false Array if logs were found, false otherwise.
255 */
256 public function get_connected_logs( $args = [] ) {
257 return false;
258 }
259
260 /**
261 * Retrieve Log Count
262 *
263 * Retrieves number of log entries connected to particular object ID.
264 *
265 * @deprecated 2.10.0
266 * @use LogRepository::getTotalCount()
267 * @see LogRepository
268 *
269 * @since 1.0
270 * @access public
271 *
272 * @param int $object_id Log object ID. Default is 0.
273 * @param string $type Log type. Default is empty string.
274 * @param array $meta_query Log meta query. Default is null.
275 * @param array $date_query Log data query. Default is null.
276 *
277 * @return int Log count.
278 */
279 public function get_log_count( $object_id = 0, $type = '', $meta_query = null, $date_query = null ) {
280 if ( $object_id ) {
281 return 0;
282 }
283
284 if ( ! empty( $type ) ) {
285 $logs = $this->logRepository->getLogsByType( $type );
286 return count( $logs );
287 }
288
289 return $this->logRepository->getTotalCount();
290 }
291
292 /**
293 * Delete Logs
294 *
295 * Remove log entries connected to particular object ID.
296 *
297 * @deprecated 2.10.0
298 * @use LogRepository::deleteLogs()
299 * @see LogRepository
300 *
301 * @since 1.0
302 * @access public
303 *
304 * @param int $object_id Log object ID. Default is 0.
305 * @param string $type Log type. Default is empty string.
306 * @param array $meta_query Log meta query. Default is null.
307 *
308 * @return void
309 */
310 public function delete_logs( $object_id = 0, $type = '', $meta_query = null ) {
311 $this->logRepository->deleteLogs();
312 }
313
314 }
315