Completed
Push — add/about-page ( e67633...c7df0d )
by
unknown
30:49 queued 23:48
created

Jetpack_About_Page::display_gravatars()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 63
rs 8.8072
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Disable direct access and execution.
4
 */
5
if ( ! defined( 'ABSPATH' ) ) {
6
	exit;
7
}
8
9
include_once( 'class.jetpack-admin-page.php' );
10
11
// Builds the landing page and its menu
12
class Jetpack_About_Page extends Jetpack_Admin_Page {
13
14
	// Show the settings page only when Jetpack is connected or in dev mode
15
	protected $dont_show_if_not_active = true;
16
17
	/**
18
	 * Add a submenu item to the Jetpack admin menu.
19
	 *
20
	 * @return string
21
	 */
22
	function get_page_hook() {
23
		// Add the main admin Jetpack menu
24
		return add_submenu_page(
25
			'jetpack',
26
			esc_html__( 'About Jetpack', 'jetpack' ),
27
			esc_html__( 'About Jetpack', 'jetpack' ),
28
			'jetpack_admin_page',
29
			'jetpack_about',
30
			array( $this, 'render' )
31
		);
32
	}
33
34
	function add_page_actions( $hook ) {}
35
	function page_admin_scripts() {
36
		wp_enqueue_style( 'plugin-install' );
37
		wp_enqueue_script( 'plugin-install' );
38
39
		wp_enqueue_style( 'thickbox' );
40
		wp_enqueue_script( 'thickbox' );
41
	}
42
43
	/**
44
	 * Load styles for static page.
45
	 */
46
	function additional_styles() {
47
		Jetpack_Admin_Page::load_wrapper_styles();
48
	}
49
50
	/**
51
	 * Render the page with a common top and bottom part, and page specific content
52
	 */
53
	function render() {
54
		Jetpack_Admin_Page::wrap_ui( array( $this, 'page_render' ), array( 'show-nav' => false ) );
55
	}
56
57
	/**
58
	 * Render the page content
59
	 */
60
	function page_render() {
61
		?>
62
		<div class="page-content configure">
63
			<div class="frame top">
64
				<div class="jetpack-about__link-back">
65
					<a href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack' ) ); ?>">
66
						<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></g></svg>
67
						<?php esc_html_e( 'Back to Jetpack Dashboard', 'jetpack' ); ?>
68
					</a>
69
				</div>
70
				<div class="jetpack-about__main">
71
					<div class="jetpack-about__logo">
72
						<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
73
							 viewBox="0 0 800 96" style="enable-background:new 0 0 800 96;" xml:space="preserve">
74
						<g>
75
							<path style="fill: #39c;" d="M292.922,78c-19.777,0-32.598-14.245-32.598-29.078V47.08c0-15.086,12.821-29.08,32.598-29.08
76
								c19.861,0,32.682,13.994,32.682,29.08v1.843C325.604,63.755,312.783,78,292.922,78z M315.044,47.245
77
								c0-10.808-7.877-20.447-22.122-20.447s-22.04,9.639-22.04,20.447v1.341c0,10.811,7.795,20.614,22.04,20.614
78
								s22.122-9.803,22.122-20.614V47.245z"/>
79
							<path d="M69.602,75.821l-7.374-13.826H29.463l-7.124,13.826H11.277l30.167-55.81h8.715l30.671,55.81H69.602z M45.552,30.906
80
								L33.401,54.369h24.72L45.552,30.906z"/>
81
							<path d="M128.427,78c-20.028,0-29.329-10.894-29.329-25.391V20.012h10.391v32.765c0,10.308,6.788,16.424,19.692,16.424
82
								c13.242,0,18.687-6.116,18.687-16.424V20.012h10.475v32.598C158.342,66.436,149.46,78,128.427,78z"/>
83
							<path d="M216.667,28.727v47.094h-10.475V28.727h-24.386v-8.715h59.245v8.715H216.667z"/>
84
							<path d="M418.955,75.821V31.659l-2.766,4.861l-23.379,39.301h-5.112L364.569,36.52l-2.765-4.861v44.162h-10.224v-55.81h14.497
85
								l22.038,38.296L390.713,63l2.599-4.692l21.786-38.296h14.331v55.81H418.955z"/>
86
							<path d="M508.619,75.821l-7.374-13.826H468.48l-7.123,13.826h-11.061l30.167-55.81h8.715l30.669,55.81H508.619z M484.569,30.906
87
								l-12.151,23.464h24.72L484.569,30.906z"/>
88
							<path d="M562.081,28.727v47.094h-10.474V28.727h-24.386v-8.715h59.245v8.715H562.081z"/>
89
							<path d="M638.924,28.727v47.094H628.45V28.727h-24.386v-8.715h59.245v8.715H638.924z"/>
90
							<path d="M689.118,75.821v-50.53c4.19,0,5.866-2.263,5.866-5.28h4.442v55.81H689.118z"/>
91
							<path d="M781.464,35.765c-5.028-4.609-12.402-8.967-22.374-8.967c-14.916,0-23.296,10.225-23.296,20.867v1.089
92
								c0,10.558,8.464,20.445,24.05,20.445c9.303,0,17.012-4.441,21.872-8.965L788,66.854C781.883,72.887,771.492,78,759.174,78
93
								c-21.118,0-33.939-13.743-33.939-28.828v-1.843c0-15.084,13.993-29.329,34.44-29.329c11.816,0,22.541,4.944,28.324,11.146
94
								L781.464,35.765z"/>
95
							<path d="M299.82,37.417c1.889,1.218,2.418,3.749,1.192,5.648l-9.553,14.797c-1.226,1.901-3.752,2.452-5.637,1.234l0,0
96
								c-1.886-1.22-2.421-3.745-1.192-5.647l9.553-14.797C295.41,36.753,297.935,36.201,299.82,37.417L299.82,37.417z"/>
97
						</g>
98
						</svg>
99
					</div>
100
					<div class="jetpack-about__content">
101
						<div class="jetpack-about__images">
102
							<div class="gravatars"><?php $this->display_gravatars(); ?></div>
103
							<a href="https://automattic.com/about/" target="_blank"><?php esc_html_e( 'Meet the team', 'jetpack' ); ?></a>
104
						</div>
105
106
						<div class="jetpack-about__text">
107
							<p>
108
								<?php esc_html_e( 'We are the people behind WordPress.com, WooCommerce, Jetpack, Simplenote, Longreads, VaultPress, Akismet, Gravatar, Crowdsignal, Cloudup, and more. We believe in making the web a better place.', 'jetpack' ); ?>
109
								<a href="https://automattic.com/" target="_blank">
110
									<?php esc_html_e( 'Learn more about us.', 'jetpack' ); ?>
111
								</a>
112
							</p>
113
							<p>
114
								<?php esc_html_e( 'We’re a distributed company with 864 Automatticians in 68 countries speaking 84 different languages. Our common goal is to democratize publishing so that anyone with a story can tell it, regardless of income, gender, politics, language, or where they live in the world.', 'jetpack' ); ?>
115
							</p>
116
							<p>
117
								<?php esc_html_e( 'We believe in Open Source and the vast majority of our work is available under the GPL.', 'jetpack' ); ?>
118
							</p>
119
							<p>
120
								<?php
121
									// Maybe use printf() because we'll want to escape the string but still allow for the link, so we can't use esc_html_e()
122
									echo wp_kses( __( 'We strive to live by the <a href="https://automattic.com/creed/" target="_blank">Automattic Creed</a>.', 'jetpack' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ); ?>
123
							</p>
124
							<p>
125
								<a href="https://automattic.com/jobs" target="_blank">
126
									<?php esc_html_e( 'Come work with us', 'jetpack' ); ?>
127
								</a>
128
							</p>
129
						</div>
130
					</div>
131
				</div>
132
133
				<div class="jetpack-about__colophon">
134
					<h3><?php esc_html_e( 'Popular WordPress services by Automattic', 'jetpack' ); ?></h3>
135
					<ul class="jetpack-about__services">
136
					<?php $this->display_plugins(); ?>
137
					</ul>
138
139
					<p class="more"><?php echo wp_kses( __( 'For even more of our WordPress plugins, please <a href="https://profiles.wordpress.org/automattic/" target="_blank">take a look at our WordPress.org profile</a>.', 'jetpack' ), array( 'a' => array( 'href' => array(), 'target' => array() ) ) ); ?></p>
140
				</div>
141
			</div>
142
		</div>
143
		<?php
144
	}
145
146
	function display_plugins() {
147
		$plugins_allowedtags = array(
148
			'a'       => array(
149
				'href'   => array(),
150
				'title'  => array(),
151
				'target' => array(),
152
			),
153
			'abbr'    => array( 'title' => array() ),
154
			'acronym' => array( 'title' => array() ),
155
			'code'    => array(),
156
			'pre'     => array(),
157
			'em'      => array(),
158
			'strong'  => array(),
159
			'ul'      => array(),
160
			'ol'      => array(),
161
			'li'      => array(),
162
			'p'       => array(),
163
			'br'      => array(),
164
		);
165
166
		// slugs for plugins we want to display
167
		$a8c_plugins = array(
168
			'akismet',
169
			'wp-super-cache',
170
			'vaultpress',
171
			'polldaddy',
172
		);
173
174
		// need this to access the plugins_api() function
175
		include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
176
177
		foreach ( $a8c_plugins as $slug ){
178
			$args = array(
179
				'slug'	=> $slug,
180
				'fields'	=> array(
181
					'added'						=> false,
182
					'author'						=> false,
183
					'author_profile'				=> false,
184
					'banners'					=> false,
185
					'contributors'				=> false,
186
					'donate_link'				=> false,
187
					'homepage'					=> false,
188
					'reviews'					=> false,
189
					'screenshots'				=> false,
190
					'support_threads'			=> false,
191
					'support_threads_resolved'	=> false,
192
					'sections'					=> false,
193
					'tags'						=> false,
194
					'versions'					=> false,
195
196
					'compatibility'				=> true,
197
					'downloaded'					=> true,
198
					'downloadlink'				=> true,
199
					'icons'						=> true,
200
					'last_updated'				=> true,
201
					'num_ratings'				=> true,
202
					'rating'						=> true,
203
					'requires'					=> true,
204
					'requires_php'				=> true,
205
					'short_description'			=> true,
206
					'tested'						=> true,
207
				),
208
			);
209
210
			// should probably add some error checking here too
211
			$api = plugins_api( 'plugin_information', $args );
212
			$plugins[] = $api;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$plugins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $plugins = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
213
		}
214
215
		foreach ( $plugins as $plugin ) {
0 ignored issues
show
Bug introduced by
The variable $plugins does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
216
			if ( is_object( $plugin ) ) {
217
				$plugin = (array) $plugin;
218
			}
219
220
			$title = wp_kses( $plugin['name'], $plugins_allowedtags );
221
			$version     = wp_kses( $plugin['version'], $plugins_allowedtags );
222
223
			$name = strip_tags( $title . ' ' . $version );
224
225
			// Remove any HTML from the description.
226
			$description = strip_tags( $plugin['short_description'] );
227
228
			$wp_version = get_bloginfo( 'version' );
229
230
			$compatible_php = ( empty( $plugin['requires_php'] ) || version_compare( phpversion(), $plugin['requires_php'], '>=' ) );
231
			$tested_wp      = ( empty( $plugin['tested'] ) || version_compare( $wp_version, $plugin['tested'], '<=' ) );
0 ignored issues
show
Unused Code introduced by
$tested_wp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
232
			$compatible_wp  = ( empty( $plugin['requires'] ) || version_compare( $wp_version, $plugin['requires'], '>=' ) );
233
234
			$action_links = array();
235
236
			// install button
237
			if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
238
				$status = install_plugin_install_status( $plugin );
239
				switch ( $status['status'] ) {
240
					case 'install':
241 View Code Duplication
						if ( $status['url'] ) {
242
							if ( $compatible_php && $compatible_wp ) {
243
								$action_links[] = sprintf(
244
									'<a class="install-now button" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
245
									esc_attr( $plugin['slug'] ),
246
									esc_url( $status['url'] ),
247
									/* translators: %s: plugin name and version */
248
									esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
249
									esc_attr( $name ),
250
									__( 'Install Now' )
251
								);
252
							} else {
253
								$action_links[] = sprintf(
254
									'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
255
									_x( 'Cannot Install', 'plugin' )
256
								);
257
							}
258
						}
259
						break;
260
261
					case 'update_available':
262 View Code Duplication
						if ( $status['url'] ) {
263
							$action_links[] = sprintf(
264
								'<a class="update-now button aria-button-if-js" data-plugin="%s" data-slug="%s" href="%s" aria-label="%s" data-name="%s">%s</a>',
265
								esc_attr( $status['file'] ),
266
								esc_attr( $plugin['slug'] ),
267
								esc_url( $status['url'] ),
268
								/* translators: %s: plugin name and version */
269
								esc_attr( sprintf( __( 'Update %s now' ), $name ) ),
270
								esc_attr( $name ),
271
								__( 'Update Now' )
272
							);
273
						}
274
						break;
275
276
					case 'latest_installed':
277
					case 'newer_installed':
278
						if ( is_plugin_active( $status['file'] ) ) {
279
							$action_links[] = sprintf(
280
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
281
								_x( 'Active', 'plugin' )
282
							);
283
						} elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
284
							$button_text = __( 'Activate' );
285
							/* translators: %s: plugin name */
286
							$button_label = _x( 'Activate %s', 'plugin' );
287
							$activate_url = add_query_arg(
288
								array(
289
									'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
290
									'action'   => 'activate',
291
									'plugin'   => $status['file'],
292
								),
293
								network_admin_url( 'plugins.php' )
294
							);
295
296
							if ( is_network_admin() ) {
297
								$button_text = __( 'Network Activate' );
298
								/* translators: %s: plugin name */
299
								$button_label = _x( 'Network Activate %s', 'plugin' );
300
								$activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
301
							}
302
303
							$action_links[] = sprintf(
304
								'<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>',
305
								esc_url( $activate_url ),
306
								esc_attr( sprintf( $button_label, $plugin['name'] ) ),
307
								$button_text
308
							);
309
						} else {
310
							$action_links[] = sprintf(
311
								'<button type="button" class="button button-disabled" disabled="disabled">%s</button>',
312
								_x( 'Installed', 'plugin' )
313
							);
314
						}
315
						break;
316
				}
317
			}
318
319
			$details_link = self_admin_url(
320
				'plugin-install.php?tab=plugin-information&amp;plugin=' . $plugin['slug'] .
321
				'&amp;TB_iframe=true&amp;width=600&amp;height=550'
322
			);
323
324
			if ( ! empty( $plugin['icons']['svg'] ) ) {
325
				$plugin_icon_url = $plugin['icons']['svg'];
326
			} elseif ( ! empty( $plugin['icons']['2x'] ) ) {
327
				$plugin_icon_url = $plugin['icons']['2x'];
328
			} elseif ( ! empty( $plugin['icons']['1x'] ) ) {
329
				$plugin_icon_url = $plugin['icons']['1x'];
330
			} else {
331
				$plugin_icon_url = $plugin['icons']['default'];
332
			}
333
?>
334
335
		<li class="jetpack-about__plugin plugin-card-<?php echo sanitize_html_class( $plugin['slug'] ); ?>">
336
			<?php
337
			if ( ! $compatible_php || ! $compatible_wp ) {
338
				echo '<div class="notice inline notice-error notice-alt"><p>';
339
				if ( ! $compatible_php && ! $compatible_wp ) {
340
					_e( 'This plugin doesn&#8217;t work with your versions of WordPress and PHP.' );
341
					if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
342
						printf(
343
							/* translators: 1: "Update WordPress" screen URL, 2: "Update PHP" page URL */
344
							' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
345
							self_admin_url( 'update-core.php' ),
346
							esc_url( wp_get_update_php_url() )
347
						);
348
						wp_update_php_annotation();
349
					} elseif ( current_user_can( 'update_core' ) ) {
350
						printf(
351
							/* translators: %s: "Update WordPress" screen URL */
352
							' ' . __( '<a href="%s">Please update WordPress</a>.' ),
353
							self_admin_url( 'update-core.php' )
354
						);
355 View Code Duplication
					} elseif ( current_user_can( 'update_php' ) ) {
356
						printf(
357
							/* translators: %s: "Update PHP" page URL */
358
							' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
359
							esc_url( wp_get_update_php_url() )
360
						);
361
						wp_update_php_annotation();
362
					}
363
				} elseif ( ! $compatible_wp ) {
364
					_e( 'This plugin doesn&#8217;t work with your version of WordPress.' );
365
					if ( current_user_can( 'update_core' ) ) {
366
						printf(
367
							/* translators: %s: "Update WordPress" screen URL */
368
							' ' . __( '<a href="%s">Please update WordPress</a>.' ),
369
							self_admin_url( 'update-core.php' )
370
						);
371
					}
372 View Code Duplication
				} elseif ( ! $compatible_php ) {
373
					_e( 'This plugin doesn&#8217;t work with your version of PHP.' );
374
					if ( current_user_can( 'update_php' ) ) {
375
						printf(
376
							/* translators: %s: "Update PHP" page URL */
377
							' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
378
							esc_url( wp_get_update_php_url() )
379
						);
380
						wp_update_php_annotation();
381
					}
382
				}
383
				echo '</p></div>';
384
			}
385
			?>
386
387
			<div class="plugin-card-top">
388
				<div class="name column-name">
389
					<h3>
390
						<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
391
						<?php echo $title; ?>
392
						<img src="<?php echo esc_attr( $plugin_icon_url ); ?>" class="plugin-icon" alt="">
393
						</a>
394
					</h3>
395
				</div>
396
				<div class="desc column-description">
397
					<p><?php echo $description; ?></p>
398
				</div>
399
400
				<div class="details-link">
401
					<a class="thickbox open-plugin-details-modal" href="<?php echo $details_link; ?>"><?php _e( 'More Details', 'jetpack' ); ?></a>
402
				</div>
403
			</div>
404
405
			<div class="plugin-card-bottom">
406
				<div class="action-links">
407
					<?php
408
					if ( $action_links ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $action_links of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
409
						echo '<ul class="plugin-action-buttons"><li>' . implode( '</li><li>', $action_links ) . '</li></ul>';
410
					}
411
					?>
412
				</div>
413
				<div class="vers column-rating">
414
					<?php
415
					wp_star_rating(
416
						array(
417
							'rating' => $plugin['rating'],
418
							'type'   => 'percent',
419
							'number' => $plugin['num_ratings'],
420
						)
421
					);
422
					?>
423
					<span class="num-ratings" aria-hidden="true">(<?php echo number_format_i18n( $plugin['num_ratings'] ); ?> <?php esc_html_e( 'ratings', 'jetpack' ); ?>)</span>
424
				</div>
425
				<div class="column-downloaded">
426
					<?php
427
					if ( $plugin['active_installs'] >= 1000000 ) {
428
						$active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
429
						$active_installs_text     = sprintf(
430
							_nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
431
							number_format_i18n( $active_installs_millions )
432
						);
433
					} elseif ( 0 == $plugin['active_installs'] ) {
434
						$active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
435
					} else {
436
						$active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
437
					}
438
					printf( __( '%s Active Installations' ), $active_installs_text );
439
					?>
440
				</div>
441
			</div>
442
		</li>
443
			<?php
444
445
		}
446
447
	}
448
449
	function display_gravatars() {
450
		// just placeholders for now, ideally we nab these from a8c servers
451
		$gravatars = array(
452
			'https://2.gravatar.com/avatar/5ef318426c941cbef6db5342c1356231',
453
			'https://0.gravatar.com/avatar/07adca4279691873f594d48dd7c657e1',
454
			'https://2.gravatar.com/avatar/b0b357b291ac72bc7da81b4d74430fe6',
455
			'https://1.gravatar.com/avatar/ab1f64abf81653d5a60d78a86a26bec1',
456
			'https://2.gravatar.com/avatar/eecc887dff6e1e42103590c76f215d87',
457
			'https://0.gravatar.com/avatar/987da1e668e6eb5cde64b52a477764ec',
458
			'https://1.gravatar.com/avatar/4ac90c7bc18ab89a243e6ca93bda983a',
459
			'https://1.gravatar.com/avatar/4d346581a3340e32cf93703c9ce46bd4',
460
			'https://1.gravatar.com/avatar/78c17142720e599ad7919c541124749e',
461
			'https://0.gravatar.com/avatar/9f376366854d750124dffe057dda99c9',
462
			'https://1.gravatar.com/avatar/1a33e7a69df4f675fcd799edca088ac2',
463
			'https://0.gravatar.com/avatar/30cf08c478da339285e39b5e8feb6a3f',
464
			'https://1.gravatar.com/avatar/d212b7b6c54f0ccb2c848d23440b33ba',
465
			'https://0.gravatar.com/avatar/c0ccdd53794779bcc07fcae7b79c4d80',
466
			'https://2.gravatar.com/avatar/8e6e7e85e416fd569d0f821f6fbc4c2f',
467
			'https://2.gravatar.com/avatar/ebdbd8f65be345e43b11e4487e9fc445',
468
			'https://2.gravatar.com/avatar/22bd03ace6f176bfe0c593650bcf45d8',
469
			'https://0.gravatar.com/avatar/00542b20e199a94a9c5da3b773996296',
470
			'https://0.gravatar.com/avatar/3cc1bb1db348a73c6db9aa806df16c36',
471
			'https://0.gravatar.com/avatar/fe9a6432e7e9d541ce8fe9574b1637ca',
472
			'https://2.gravatar.com/avatar/b7359fc511ec1e733b749cf93a1108a8',
473
			'https://1.gravatar.com/avatar/19045a8e6cd135276b62fdd7c5a8e6c2',
474
			'https://2.gravatar.com/avatar/82879e72da41bc26a7724a276cf14fe0',
475
			'https://1.gravatar.com/avatar/76701f9a6394b36ce9236beb22b87beb',
476
			'https://2.gravatar.com/avatar/5915fd742d0c26f6a584f9d21f991b9c',
477
			'https://1.gravatar.com/avatar/198723e26f9350d9bbe8d4f35a8b0bb7',
478
			'https://1.gravatar.com/avatar/709977fc8f4496966d454a01eab615f6',
479
			'https://0.gravatar.com/avatar/6cf147a5459184fdd93a2328d03ebcb4',
480
			'https://1.gravatar.com/avatar/40266b37e9174a660f33bb21b809d751',
481
			'https://0.gravatar.com/avatar/f1568367297d076f566ef695d5304300',
482
			'https://0.gravatar.com/avatar/970fe9a9c489b4c343b186b0c6b017ad',
483
			'https://2.gravatar.com/avatar/e6389004daf6cd236a6fd5a82069b426',
484
			'https://1.gravatar.com/avatar/a12ebf4391c6b20fe4cab62e60a8db0d',
485
			'https://2.gravatar.com/avatar/b0be4235dbf38547a7c26ef8ec94934b',
486
			'https://1.gravatar.com/avatar/190cf13c9cd358521085af13615382d5',
487
			'https://0.gravatar.com/avatar/f2ad3d5d58caa9fdf62303e6bc56d09b',
488
			'https://0.gravatar.com/avatar/caaa4d366031d73ddbd0ea5e4c725ad5',
489
			'https://0.gravatar.com/avatar/00e1dd94340133b9daf6e291fb766266',
490
			'https://1.gravatar.com/avatar/d9f75324595bf8eb19a6b7b13eb9db0b',
491
			'https://0.gravatar.com/avatar/664e5a9a9a4e9f17390932951c4085f1',
492
			'https://2.gravatar.com/avatar/e813016d247963553f447125e406851b',
493
			'https://2.gravatar.com/avatar/2c5af1e485742ba78010f073d5933750',
494
			'https://1.gravatar.com/avatar/1747354c1a3d3b4edb2a7f247d94cfb0',
495
			'https://2.gravatar.com/avatar/84403426e6221e7ae534afcecc30f576',
496
			'https://0.gravatar.com/avatar/ca021af91df7c161d5586fdd6a46834d',
497
			'https://1.gravatar.com/avatar/a4d9571e63c4acfb7cf9f3656e3ab1e8',
498
			'https://2.gravatar.com/avatar/ef0040d706cbc048d83e41b9e34a56b8',
499
			'https://0.gravatar.com/avatar/39d69f56617c472f02a9b3b16067d390',
500
		);
501
502
		$random = array_rand( $gravatars, 16 );
503
504
		foreach ( $random as $key ) {
505
			$url =
0 ignored issues
show
Unused Code introduced by
$url is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
506
			$output .= '<li><img src="' . $gravatars[$key] . '"></li>' . "\n";
0 ignored issues
show
Bug introduced by
The variable $output does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
507
		}
508
509
		echo '<ul>' . $output . '</ul>';
510
511
	}
512
513
}
514