PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 2.17.1
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v2.17.1
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / class-cff-error-reporter.php
custom-facebook-feed Last commit date
admin 5 years ago blocks 6 years ago css 5 years ago fonts 5 years ago img 5 years ago inc 5 years ago js 5 years ago languages 6 years ago templates 6 years ago README.txt 5 years ago changelog.txt 6 years ago class-cff-education.php 6 years ago class-cff-error-reporter.php 6 years ago class-cff-sitehealth.php 6 years ago custom-facebook-feed-admin.php 5 years ago custom-facebook-feed.php 5 years ago email.php 6 years ago gpl-2.0.txt 13 years ago
class-cff-error-reporter.php
444 lines
1 <?php
2 /**
3 * Class CFF_Error_Reporter
4 *
5 * Set as a global object to record and report errors
6 *
7 * @since
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 die( '-1' );
12 }
13
14 class CFF_Error_Reporter
15 {
16 /**
17 * @var array
18 */
19 var $errors;
20
21 /**
22 * @var array
23 */
24 var $frontend_error;
25
26 var $reporter_key;
27
28 /**
29 * CFF_Error_Reporter constructor.
30 */
31 public function __construct() {
32 $this->reporter_key = 'cff_error_reporter';
33 $this->errors = get_option( $this->reporter_key, array() );
34 $this->frontend_error = '';
35 add_action( 'cff_feed_issue_email', array( $this, 'maybe_trigger_report_email_send' ) );
36 add_action( 'wp_ajax_cff_dismiss_critical_notice', array( $this, 'dismiss_critical_notice' ) );
37 add_action( 'wp_footer', array( $this, 'critical_error_notice' ), 300 );
38 add_action( 'admin_notices', array( $this, 'admin_error_notices' ) );
39 }
40
41 /**
42 * @return array
43 *
44 * @since 2.0/4.0
45 */
46 public function get_errors() {
47 return $this->errors;
48 }
49
50 /**
51 * @param $type
52 * @param $message_array
53 *
54 * @since 2.0/4.0
55 */
56 public function add_error( $type, $args ) {
57 if ( $type === 'accesstoken' ) {
58 $accesstoken_error_exists = false;
59 if ( isset( $this->errors['accesstoken'] ) ) {
60 foreach ($this->errors['accesstoken'] as $accesstoken ) {
61 if ( $args['accesstoken'] === $accesstoken['accesstoken'] ) {
62 $accesstoken_error_exists = true;
63 }
64 }
65 }
66
67 if ( !$accesstoken_error_exists ) {
68 $this->errors['accesstoken'][] = array(
69 'accesstoken' => $args['accesstoken'],
70 'post_id' => $args['post_id'],
71 'errorno' => $args['errorno']
72 );
73 }
74
75 } else {
76 $this->errors[ $type ] = array(
77 'accesstoken' => $args['accesstoken'],
78 'public_message' => $args['public_message'],
79 'admin_message' => $args['admin_message'],
80 'frontend_directions' => $args['frontend_directions'],
81 'backend_directions' => $args['backend_directions'],
82 'post_id' => $args['post_id'],
83 'errorno' => $args['errorno']
84 );
85 }
86
87 update_option( $this->reporter_key, $this->errors, false );
88 }
89
90 /**
91 * @param $type
92 *
93 * @since 2.0/4.0
94 */
95 public function remove_error( $type ) {
96 $errors = $this->errors;
97
98 if ( isset( $errors[ $type ] ) ) {
99 unset( $errors[ $type ] );
100 }
101
102 if ( empty( $errors ) ) {
103 delete_option( $this->reporter_key );
104 $this->errors = array();
105 } else {
106 update_option( $this->reporter_key, $errors, false );
107 $this->errors = $errors;
108 }
109 }
110
111 public function remove_all_errors() {
112 delete_option( $this->reporter_key );
113 $this->errors = array();
114 }
115
116 /**
117 * @param $type
118 * @param $message
119 *
120 * @since 2.0/5.0
121 */
122 public function add_frontend_error( $message, $directions ) {
123 $this->frontend_error = $message . $directions;
124 }
125
126 public function remove_frontend_error() {
127 $this->frontend_error = '';
128 }
129
130 /**
131 * @return string
132 *
133 * @since 2.0/5.0
134 */
135 public function get_frontend_error() {
136 return $this->frontend_error;
137 }
138
139 public function get_critical_errors() {
140 $errors = $this->get_errors();
141
142 return $errors;
143 }
144
145 public function are_critical_errors() {
146 $are_errors = false;
147
148 $errors = $this->get_errors();
149
150 foreach ( $errors as $error ) {
151 $are_errors = true;
152 }
153
154 return $are_errors;
155 }
156
157
158 /**
159 * Load the critical notice for logged in users.
160 */
161 function critical_error_notice() {
162 // Don't do anything for guests.
163 if ( ! is_user_logged_in() ) {
164 return;
165 }
166
167 // Only show this to users who are not tracked.
168 if ( ! current_user_can( 'edit_posts' ) ) {
169 return;
170 }
171
172 if ( ! $this->are_critical_errors() ) {
173 return;
174 }
175
176
177 // Don't show if already dismissed.
178 if ( get_option( 'cff_dismiss_critical_notice', false ) ) {
179 return;
180 }
181
182 $options = get_option('cff_style_settings');
183 if ( isset( $options['disable_admin_notice'] ) && $options['disable_admin_notice'] === 'on' ) {
184 return;
185 }
186
187 ?>
188 <div class="cff-critical-notice cff-critical-notice-hide">
189 <div class="cff-critical-notice-icon">
190 <img src="<?php echo CFF_PLUGIN_URL . 'img/cff-icon.png'; ?>" width="45" alt="Custom Facebook Feed icon" />
191 </div>
192 <div class="cff-critical-notice-text">
193 <h3><?php esc_html_e( 'Custom Facebook Feed Critical Issue', 'custom-facebook-feed' ); ?></h3>
194 <p>
195 <?php
196 $doc_url = admin_url() . 'admin.php?page=cff-top';
197 // Translators: %s is the link to the article where more details about critical are listed.
198 printf( esc_html__( 'An issue is preventing your Custom Facebook Feeds from updating. %1$sResolve this issue%2$s.', 'custom-facebook-feed' ), '<a href="' . esc_url( $doc_url ) . '" target="_blank">', '</a>' );
199 ?>
200 </p>
201 </div>
202 <div class="cff-critical-notice-close">&times;</div>
203 </div>
204 <style type="text/css">
205 .cff-critical-notice {
206 position: fixed;
207 bottom: 20px;
208 right: 15px;
209 font-family: Arial, Helvetica, "Trebuchet MS", sans-serif;
210 background: #fff;
211 box-shadow: 0 0 10px 0 #dedede;
212 padding: 10px 10px;
213 display: flex;
214 align-items: center;
215 justify-content: center;
216 width: 325px;
217 max-width: calc( 100% - 30px );
218 border-radius: 6px;
219 transition: bottom 700ms ease;
220 z-index: 10000;
221 }
222
223 .cff-critical-notice h3 {
224 font-size: 13px;
225 color: #222;
226 font-weight: 700;
227 margin: 0 0 4px;
228 padding: 0;
229 line-height: 1;
230 border: none;
231 }
232
233 .cff-critical-notice p {
234 font-size: 12px;
235 color: #7f7f7f;
236 font-weight: 400;
237 margin: 0;
238 padding: 0;
239 line-height: 1.2;
240 border: none;
241 }
242
243 .cff-critical-notice p a {
244 color: #7f7f7f;
245 font-size: 12px;
246 line-height: 1.2;
247 margin: 0;
248 padding: 0;
249 text-decoration: underline;
250 font-weight: 400;
251 }
252
253 .cff-critical-notice p a:hover {
254 color: #666;
255 }
256
257 .cff-critical-notice-icon img {
258 height: auto;
259 display: block;
260 margin: 0;
261 }
262
263 .cff-critical-notice-icon {
264 padding: 0;
265 border-radius: 4px;
266 flex-grow: 0;
267 flex-shrink: 0;
268 margin-right: 12px;
269 overflow: hidden;
270 }
271
272 .cff-critical-notice-close {
273 padding: 10px;
274 margin: -12px -9px 0 0;
275 border: none;
276 box-shadow: none;
277 border-radius: 0;
278 color: #7f7f7f;
279 background: transparent;
280 line-height: 1;
281 align-self: flex-start;
282 cursor: pointer;
283 font-weight: 400;
284 }
285 .cff-critical-notice-close:hover,
286 .cff-critical-notice-close:focus{
287 color: #111;
288 }
289
290 .cff-critical-notice.cff-critical-notice-hide {
291 bottom: -200px;
292 }
293 </style>
294 <?php
295
296 if ( ! wp_script_is( 'jquery', 'queue' ) ) {
297 wp_enqueue_script( 'jquery' );
298 }
299 ?>
300 <script>
301 if ( 'undefined' !== typeof jQuery ) {
302 jQuery( document ).ready( function ( $ ) {
303 /* Don't show the notice if we don't have a way to hide it (no js, no jQuery). */
304 $( document.querySelector( '.cff-critical-notice' ) ).removeClass( 'cff-critical-notice-hide' );
305 $( document.querySelector( '.cff-critical-notice-close' ) ).on( 'click', function ( e ) {
306 e.preventDefault();
307 $( this ).closest( '.cff-critical-notice' ).addClass( 'cff-critical-notice-hide' );
308 $.ajax( {
309 url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
310 method: 'POST',
311 data: {
312 action: 'cff_dismiss_critical_notice',
313 nonce: '<?php echo esc_js( wp_create_nonce( 'cff-critical-notice' ) ); ?>',
314 }
315 } );
316 } );
317 } );
318 }
319 </script>
320 <?php
321 }
322
323 /**
324 * Ajax handler to hide the critical notice.
325 */
326 public function dismiss_critical_notice() {
327
328 check_ajax_referer( 'cff-critical-notice', 'nonce' );
329
330 update_option( 'cff_dismiss_critical_notice', 1, false );
331
332 wp_die();
333
334 }
335
336 public function send_report_email() {
337 $options = get_option( 'cff_style_settings', array() );
338
339 $to_string = ! empty( $options['email_notification_addresses'] ) ? str_replace( ' ', '', $options['email_notification_addresses'] ) : get_option( 'admin_email', '' );
340
341 $to_array_raw = explode( ',', $to_string );
342 $to_array = array();
343
344 foreach ( $to_array_raw as $email ) {
345 if ( is_email( $email ) ) {
346 $to_array[] = $email;
347 }
348 }
349
350 if ( empty( $to_array ) ) {
351 return false;
352 }
353 $from_name = esc_html( wp_specialchars_decode( get_bloginfo( 'name' ) ) );
354 $email_from = $from_name . ' <' . get_option( 'admin_email', $to_array[0] ) . '>';
355 $header_from = "From: " . $email_from;
356
357 $headers = array( 'Content-Type: text/html; charset=utf-8', $header_from );
358
359 $header_image = CFF_PLUGIN_URL . 'img/balloon-120.png';
360 $title = __( 'Custom Facebook Feed Report for ' . home_url() );
361 $link = admin_url( 'admin.php?page=cff-top');
362 //&tab=customize-advanced
363 $footer_link = admin_url('admin.php?page=cff-style&tab=misc&flag=emails');
364 $bold = __( 'There\'s an Issue with a Facebook Feed on Your Website', 'custom-facebook-feed' );
365 $details = '<p>' . __( 'A Custom Facebook Feed on your website is currently unable to connect to Facebook to retrieve new posts. Don\'t worry, your feed is still being displayed using a cached version, but is no longer able to display new posts.', 'custom-facebook-feed' ) . '</p>';
366 $details .= '<p>' . sprintf( __( 'This is caused by an issue with your Facebook account connecting to the Facebook API. For information on the exact issue and directions on how to resolve it, please visit the %sCustom Facebook Feed settings page%s on your website.', 'custom-facebook-feed' ), '<a href="' . esc_url( $link ) . '">', '</a>' ). '</p>';
367 $message_content = '<h6 style="padding:0;word-wrap:normal;font-family:\'Helvetica Neue\',Helvetica,Arial,sans-serif;font-weight:bold;line-height:130%;font-size: 16px;color:#444444;text-align:inherit;margin:0 0 20px 0;Margin:0 0 20px 0;">' . $bold . '</h6>' . $details;
368 include_once CFF_PLUGIN_DIR . 'class-cff-education.php';
369 $educator = new CFF_Education();
370 $dyk_message = $educator->dyk_display();
371 ob_start();
372 include CFF_PLUGIN_DIR . 'email.php';
373 $email_body = ob_get_contents();
374 ob_get_clean();
375 $sent = wp_mail( $to_array, $title, $email_body, $headers );
376
377 return $sent;
378 }
379
380 public function maybe_trigger_report_email_send() {
381 if ( ! $this->are_critical_errors() ) {
382 return;
383 }
384 $options = get_option('cff_style_settings');
385
386 if ( isset( $options['enable_email_report'] ) && empty( $options['enable_email_report'] ) ) {
387 return;
388 }
389
390 $this->send_report_email();
391 }
392
393 public function admin_error_notices() {
394 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'cff-top', 'cff-style' )) ) {
395
396 $errors = $this->get_critical_errors();
397 if ( $this->are_critical_errors() && ! empty( $errors ) ) :
398 if ( isset( $errors['wp_remote_get'] ) ) {
399 $error = $errors['wp_remote_get'];
400 $error_message = $error['admin_message'];
401 $button = $error['backend_directions'];
402 $post_id = $error['post_id'];
403 $directions = '<p class="cff-error-directions">';
404 $directions .= $button;
405 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
406 $directions .= '</p>';
407 } elseif ( isset( $errors['api'] ) ) {
408 $error = $errors['api'];
409 $error_message = $error['admin_message'];
410 $button = $error['backend_directions'];
411 $post_id = $error['post_id'];
412 $directions = '<p class="cff-error-directions">';
413 $directions .= $button;
414 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
415 $directions .= '</p>';
416 } else {
417 $error = $errors['accesstoken'];
418
419 $tokens = array();
420 $post_id = false;
421 foreach ( $error as $token ) {
422 $tokens[] = $token['accesstoken'];
423 $post_id = $token['post_id'];
424 }
425 $error_message = sprintf( __( 'The access token %s is invalid or has expired.', 'custom-facebook-feed' ), implode( $tokens, ', ' ) );
426 $directions = '<p class="cff-error-directions">';
427 $directions .= '<button class="button button-primary cff-reconnect">' . __( 'Reconnect Your Account', 'custom-facebook-feed' ) . '</button>';
428 $directions .= '<button data-url="'.get_the_permalink( $post_id ).'" class="cff-clear-errors-visit-page cff-space-left button button-secondary">' . __( 'View Feed and Retry', 'custom-facebook-feed' ) . '</button>';
429 $directions .= '</p>';
430 }
431 ?>
432 <div class="notice notice-warning is-dismissible cff-admin-notice">
433 <p><strong><?php echo esc_html__( 'Custom Facebook Feed is encountering an error and your feeds may not be updating due to the following reasons:', 'custom-facebook-feed') ; ?></strong></p>
434
435 <?php echo $error_message; ?>
436
437 <?php echo $directions; ?>
438 </div>
439 <?php endif;
440 }
441
442 }
443
444 }