Changeset 2679871
- Timestamp:
- 02/16/2022 01:23:41 PM (4 years ago)
- Location:
- blipper-widget/trunk
- Files:
-
- 3 edited
-
blipper-widget.php (modified) (27 diffs)
-
changelog.txt (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
blipper-widget/trunk/blipper-widget.php
r2428330 r2679871 11 11 * Plugin URI: http://pandammonium.org/wordpress-dev/blipper-widget/ 12 12 * Description: Display your latest blip in a widget. Requires a Blipfoto account (available free of charge). 13 * Version: 1.1. 113 * Version: 1.1.2 14 14 * Author: Caity Ross 15 15 * Author URI: http://pandammonium.org/ … … 48 48 use blipper_widget\blipper_widget_settings; 49 49 50 // -------------------------------------------------------------------------- // 51 52 define( 'BW_DEBUG', true ); 53 50 54 // --- Action hooks --------------------------------------------------------- // 51 55 … … 81 85 */ 82 86 function blipper_widget_exception( $e ) { 83 error_log( 'Error. ' . $e->getMessage() . '.' );84 echo '<p >An unexpected error has occurred. ' . $e->getMessage() . '. Sorry about that. Please check your settings or try again later.</p>';87 if ( BW_DEBUG ) { error_log( 'Blipper Widget: ' . $e->getMessage() . '.' ); } 88 echo '<p class="blipper-widget error">Blipper Widget: An unexpected error has occurred. ' . $e->getMessage() . '. Please check your settings or try again later.</p>'; 85 89 } 86 90 set_exception_handler('blipper_widget_exception'); … … 119 123 'display-date' => 'show', // 'hide' 120 124 'display-journal-title' => 'hide', // 'show' 125 'display-powered-by' => 'hide', // 'show' 121 126 'add-link-to-blip' => 'hide', // 'show' 122 'display-powered-by' => 'hide', // 'show'123 127 ), 124 128 ); … … 212 216 public function form( $settings ) { 213 217 214 error_log( 'Blipper_Widget::form( $settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ' )' );218 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::form( $settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ' )' ); } 215 219 $this->blipper_widget_display_form( $this->blipper_widget_get_display_values( $settings ) ); 216 220 … … 261 265 $settings['style-control'] = $style_control; 262 266 263 error_log( 'Blipper_Widget::update( $new_settings: ' . json_encode( $new_settings, JSON_PRETTY_PRINT ) . ' $old_settings: ' . json_encode( $old_settings, JSON_PRETTY_PRINT ) . ' )' );264 error_log( 'Actual settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) );267 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::update( $new_settings: ' . json_encode( $new_settings, JSON_PRETTY_PRINT ) . ' $old_settings: ' . json_encode( $old_settings, JSON_PRETTY_PRINT ) . ' )' ); } 268 if ( BW_DEBUG ) { error_log( 'Actual settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) ); } 265 269 266 270 return $settings; … … 280 284 public function blipper_widget_shortcode_blip_display( $atts, $content=null, $shortcode="", $print=false) { 281 285 282 error_log( "Blipper_Widget::blipper_widget_shortcode_blip_display( \$atts: " . json_encode( $atts, JSON_PRETTY_PRINT ) . "), \$content: '" . $content . "', \$shortcode: " . $shortcode . ")\n" );286 if ( BW_DEBUG ) { error_log( "Blipper_Widget::blipper_widget_shortcode_blip_display( \$atts: " . json_encode( $atts, JSON_PRETTY_PRINT ) . "), \$content: '" . $content . "', \$shortcode: " . $shortcode . ")\n" ); } 283 287 284 288 $settings = array_merge( $this->default_setting_values['shortcode'], $this->default_setting_values['common'] ); … … 286 290 $args = shortcode_atts( $settings, $atts, $shortcode ); 287 291 extract( $args ); 288 error_log( "Collated arguments: " . json_encode( $args, JSON_PRETTY_PRINT ) . "\n" );292 if ( BW_DEBUG ) { error_log( "Collated arguments: " . json_encode( $args, JSON_PRETTY_PRINT ) . "\n" ); } 289 293 290 294 $the_title = ''; … … 323 327 private function blipper_widget_validate( $new_settings, $old_settings, $setting_field ) { 324 328 325 error_log( "Blipper_Widget::blipper_widget_validate( $setting_field )" );326 error_log( "\tCurrent value: " . ( array_key_exists( $setting_field, $old_settings ) ? $old_settings[$setting_field] : "undefined" ) );327 error_log( "\tProposed value: " . ( array_key_exists( $setting_field, $new_settings ) ? $new_settings[$setting_field] : "undefined" ) );329 if ( BW_DEBUG ) { error_log( "Blipper_Widget::blipper_widget_validate( $setting_field )" ); } 330 if ( BW_DEBUG ) { error_log( "\tCurrent value: " . ( array_key_exists( $setting_field, $old_settings ) ? $old_settings[$setting_field] : "undefined" ) ); } 331 if ( BW_DEBUG ) { error_log( "\tProposed value: " . ( array_key_exists( $setting_field, $new_settings ) ? $new_settings[$setting_field] : "undefined" ) ); } 328 332 329 333 if ( array_key_exists( $setting_field, $old_settings ) && array_key_exists( $setting_field, $new_settings ) ) { 330 334 if ( $new_settings[$setting_field] === $old_settings[$setting_field] ) { 331 335 $settings = $old_settings[$setting_field]; 332 error_log( "\tValue unchanged\n" );336 if ( BW_DEBUG ) { error_log( "\tValue unchanged\n" ); } 333 337 return $settings; 334 338 } … … 367 371 } 368 372 369 error_log( "\tNew value: $settings\n" );373 if ( BW_DEBUG ) { error_log( "\tNew value: $settings\n" ); } 370 374 371 375 return $settings; … … 384 388 private function blipper_widget_get_display_values( $settings ) { 385 389 386 error_log( 'Blipper_Widget::blipper_widget_get_display_values (' . json_encode( $settings, JSON_PRETTY_PRINT ) . ')');390 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::blipper_widget_get_display_values (' . json_encode( $settings, JSON_PRETTY_PRINT ) . ')'); } 387 391 388 392 $new_settings = array(); … … 419 423 private function blipper_widget_get_display_value( $setting, $settings ) { 420 424 421 error_log( 'Blipper_Widget::blipper_widget_get_display_value (' . json_encode( $setting, JSON_PRETTY_PRINT ) . ', ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ')');425 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::blipper_widget_get_display_value (' . json_encode( $setting, JSON_PRETTY_PRINT ) . ', ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ')'); } 422 426 423 427 try { … … 432 436 } else { 433 437 throw new ErrorException( 'Invalid setting requested: <strong>' . $setting . '</strong>.' ); 434 error_log( 'Invalid setting requested:' . $setting );438 if ( BW_DEBUG ) { error_log( 'Invalid setting requested:' . $setting ); } 435 439 return ''; 436 440 } … … 555 559 } else { 556 560 $client_ok = true; 557 error_log( 'Blipper_Widget::blipper_widget_create_blipfoto_client( \$settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ' )' );558 error_log( 'Client: ' . json_encode( $this->client, JSON_PRETTY_PRINT ) );561 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::blipper_widget_create_blipfoto_client( \$settings: ' . json_encode( $settings, JSON_PRETTY_PRINT ) . ' )' ); } 562 if ( BW_DEBUG ) { error_log( 'Client: ' . json_encode( $this->client, JSON_PRETTY_PRINT ) ); } 559 563 } 560 564 … … 607 611 } 608 612 } else { 609 error_log( 'CLIENT IS NOT OK' );613 if ( BW_DEBUG ) { error_log( 'CLIENT IS NOT OK' ); } 610 614 } 611 615 return $client_ok; … … 1008 1012 1009 1013 } finally { 1010 error_log( "The completed blip:\n" . $the_blip );1014 if ( BW_DEBUG ) { error_log( "The completed blip:\n" . $the_blip ); } 1011 1015 } 1012 1016 … … 1036 1040 private function blipper_widget_get_styling( $element, $is_widget, $style_control, $settings ) { 1037 1041 1038 error_log( 'Blipper_Widget::blipper_widget_get_styling( ' . $element . ', ' . (int)$is_widget . ', ' . (int)$style_control . ' )' );1042 if ( BW_DEBUG ) { error_log( 'Blipper_Widget::blipper_widget_get_styling( ' . $element . ', ' . (int)$is_widget . ', ' . (int)$style_control . ' )' ); } 1039 1043 1040 1044 // If the blip is not to be displayed in a widget or if the widget is to be … … 1105 1109 private function blipper_widget_sanitise_html( $html ) { 1106 1110 1107 return wp_kses( $html, ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'b', 'em', 'div'] ); 1111 $allowed_html = array( 1112 'p' => array(), 1113 'h1' => array(), 1114 'h2' => array(), 1115 'h3' => array(), 1116 'h4' => array(), 1117 'h5' => array(), 1118 'h6' => array(), 1119 'i' => array(), 1120 'b' => array(), 1121 'em' => array(), 1122 'div' => array(), 1123 'br' => array(), 1124 'a' => array( 1125 'href' => array(), 1126 'title' => array(), 1127 ), 1128 ); 1129 error_log( "Dirty HTML: $html\nClean HTML: " . wp_kses( $html, $allowed_html ) ); 1130 return wp_kses( $html, $allowed_html ); 1108 1131 1109 1132 } … … 1120 1143 private function blipper_widget_sanitise_url( $url ) { 1121 1144 1122 error_log( "Blipper_Widget::blipper_widget_sanitise_url:\n$url ⟹\n" . esc_url( $url ) );1145 if ( BW_DEBUG ) { error_log( "Blipper_Widget::blipper_widget_sanitise_url:\n$url ⟹\n" . esc_url( $url ) ); } 1123 1146 1124 1147 return esc_url( $url ); … … 1157 1180 private function blipper_widget_display_form( $settings ) { 1158 1181 1159 error_log( "Blipper_Widget::blipper_widget_display_form( " . json_encode( $settings, JSON_PRETTY_PRINT ) . ')' );1182 if ( BW_DEBUG ) { error_log( "Blipper_Widget::blipper_widget_display_form( " . json_encode( $settings, JSON_PRETTY_PRINT ) . ')' ); } 1160 1183 1161 1184 $oauth_settings = $this->settings->blipper_widget_get_settings(); … … 1284 1307 </p> 1285 1308 1286 <?php error_log(1309 <?php if ( BW_DEBUG ) { error_log( 1287 1310 'NAME: ' . $this->get_field_name( 'style-control' ) 1288 1311 . ' ID: ' . $this->get_field_name( 'style-control' ) 1289 1312 . ' DEFAULT VALUE: ' . $this->default_setting_values['widget']['style-control'] 1290 . ' ACTUAL VALUE: ' . $settings['style-control'] ); 1313 . ' ACTUAL VALUE: ' . $settings['style-control'] ); } 1291 1314 ?> 1292 1315 … … 1521 1544 ) 1522 1545 : ( "No key, no value; adding default (common): " . $this->default_setting_values['common']['display-journal-title'] );