| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Disable direct access/execution to/of the widget code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | if ( ! defined( 'ABSPATH' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | if ( ! class_exists( 'Jetpack_Flickr_Widget' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	 * Flickr Widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	 * Display your recent Flickr photos. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	class Jetpack_Flickr_Widget extends WP_Widget { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 		 * Constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 19 |  | View Code Duplication | 		function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 			parent::__construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 				'flickr', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 				/** This filter is documented in modules/widgets/facebook-likebox.php */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 				apply_filters( 'jetpack_widget_name', esc_html__( 'Flickr', 'jetpack' ) ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 				array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 					'description' => esc_html__( 'Display your recent Flickr photos.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 					'customize_selective_refresh' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 				array() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		 * Enqueue style. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		function enqueue_style() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			wp_enqueue_style( 'flickr-widget-style', plugins_url( 'flickr/style.css', __FILE__ ), array(), '20170405' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		 * Return an associative array of default values. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		 * These values are used in new widgets. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		 * @return array Default values for the widget options. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		public function defaults() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 				'title'             => esc_html__( 'Flickr Photos', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 				'items'             => 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 				'flickr_image_size' => 'thumbnail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				'flickr_rss_url'    => '' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		 * Front-end display of the widget. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		 * @param array $args     Widget arguments. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		 * @param array $instance Saved values from database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		public function widget( $args, $instance ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			$instance = wp_parse_args( $instance, $this->defaults() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			$image_size_string = 'small' == $instance['flickr_image_size'] ? '_m.jpg' : '_t.jpg'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			$rss_url = ( ! isset( $instance['flickr_rss_url'] ) || empty( $instance['flickr_rss_url'] ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 				? 'https://api.flickr.com/services/feeds/photos_interesting.gne?format=rss_200' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 				: htmlspecialchars_decode( $instance['flickr_rss_url'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			// We want to use the HTTPS version so the URLs in the API response are also HTTPS and we avoid mixed-content warnings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			$rss_url = preg_replace( '!^http://api.flickr.com/!i', 'https://api.flickr.com/', $rss_url ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			$rss = fetch_feed( $rss_url ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			$photos = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			if ( ! is_wp_error( $rss ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 				foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 					if ( $enclosure = $photo->get_enclosure() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 						$src = str_replace( '_s.jpg', $image_size_string, $enclosure->get_thumbnail() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 					} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 						$src = preg_match( '/src="(.*?)"/i', $photo->get_description(), $p ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 						$src = str_replace( '_m.jpg', $image_size_string, $p[1] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 					$photos .= '<a href="' . esc_url( $photo->get_permalink(), array( 'http', 'https' ) ) . '">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 					$photos .= '<img src="' . esc_url( $src, array( 'http', 'https' ) ) . '" '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 					$photos .= 'alt="' . esc_attr( $photo->get_title() ) . '" '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 					$photos .= 'border="0" '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 					$photos .= 'title="' . esc_attr( $photo->get_title() ) . '" '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 					$photos .= ' /></a><br /><br />'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 				if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 					$photos = Jetpack_Photon::filter_the_content( $photos ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				$flickr_home = $rss->get_link(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			echo $args['before_widget']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 			if ( empty( $photos ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 				if ( current_user_can( 'edit_theme_options' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 					printf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 						'<p>%1$s<br />%2$s</p>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 						esc_html__( 'There are no photos to display. Make sure your Flickr feed URL is correct, and that your pictures are publicly accessible.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 						esc_html__( '(Only admins can see this message)', 'jetpack' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 					); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 				echo $args['before_title'] . esc_html( $instance['title'] ) . $args['after_title']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 				require( dirname( __FILE__ ) . '/flickr/widget.php' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			echo $args['after_widget']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 			/** This action is already documented in modules/widgets/gravatar-profile.php */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 			do_action( 'jetpack_stats_extra', 'widget_view', 'flickr' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		 * Back-end widget form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		 * @param array $instance Previously saved values from database. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 125 |  |  | 		 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  | 		public function form( $instance ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  | 			$instance = wp_parse_args( $instance, $this->defaults() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  | 			require( dirname( __FILE__ ) . '/flickr/form.php' ); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		 * Sanitize widget form values as they are saved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		 * @param  array $new_instance Values just sent to be saved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		 * @param  array $old_instance Previously saved values from database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		 * @return array Updated safe values to be saved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		public function update( $new_instance, $old_instance ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 			$instance = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			$defaults = $this->defaults(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 			if ( isset( $new_instance['title'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 				$instance['title'] = wp_kses( $new_instance['title'], array() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 			if ( isset( $new_instance['items'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 				$instance['items'] = intval( $new_instance['items'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			if ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 				isset( $new_instance['flickr_image_size'] ) && | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 				in_array( $new_instance['flickr_image_size'], array( 'thumbnail', 'small' ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 			) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 				$instance['flickr_image_size'] = $new_instance['flickr_image_size']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 				$instance['flickr_image_size'] = 'thumbnail'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 			if ( isset( $new_instance['flickr_rss_url'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 				$instance['flickr_rss_url'] = esc_url( $new_instance['flickr_rss_url'], array( 'http', 'https' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 				if ( strlen( $instance['flickr_rss_url'] ) < 10 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 					$instance['flickr_rss_url'] = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 			return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 	// Register Jetpack_Flickr_Widget widget. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 	function jetpack_register_flickr_widget() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 		register_widget( 'Jetpack_Flickr_Widget' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	add_action( 'widgets_init', 'jetpack_register_flickr_widget' ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 176 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 177 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.