Issues (2756)

admin/plugins.php (20 issues)

1
<?php
2
define( 'YOURLS_ADMIN', true );
3
require_once( dirname( __DIR__ ).'/includes/load-yourls.php' );
4
yourls_maybe_require_auth();
5
6
// Handle plugin administration pages
7
if( isset( $_GET['page'] ) && !empty( $_GET['page'] ) ) {
8
	yourls_plugin_admin_page( $_GET['page'] );
9
    die();
10
}
11
12
// Handle activation/deactivation of plugins
13
if( isset( $_GET['action'] ) ) {
14
15
	// Check nonce
16
	yourls_verify_nonce( 'manage_plugins', $_REQUEST['nonce'] );
17
18
	// Check plugin file is valid
19
	if( isset( $_GET['plugin'] ) && yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$_GET['plugin'].'/plugin.php') ) {
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
20
21
		// Activate / Deactive
22
		switch( $_GET['action'] ) {
23
			case 'activate':
24
				$result = yourls_activate_plugin( $_GET['plugin'].'/plugin.php' );
25
				if( $result === true )
26
					yourls_redirect( yourls_admin_url( 'plugins.php?success=activated' ), 302 );
27
28
				break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 7 spaces, found 4
Loading history...
29
30
			case 'deactivate':
31
				$result = yourls_deactivate_plugin( $_GET['plugin'].'/plugin.php' );
32
				if( $result === true )
33
					yourls_redirect( yourls_admin_url( 'plugins.php?success=deactivated' ), 302 );
34
35
				break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 7 spaces, found 4
Loading history...
36
37
			default:
38
				$result = yourls__( 'Unsupported action' );
39
				break;
0 ignored issues
show
Case breaking statement indented incorrectly; expected 7 spaces, found 4
Loading history...
40
		}
41
	} else {
42
		$result = yourls__( 'No plugin specified, or not a valid plugin' );
43
	}
44
45
	yourls_add_notice( $result );
46
}
47
48
// Handle message upon succesfull (de)activation
49
if( isset( $_GET['success'] ) && ( ( $_GET['success'] == 'activated' ) OR ( $_GET['success'] == 'deactivated' ) ) ) {
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
This line exceeds maximum limit of 100 characters; contains 117 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
50
	if( $_GET['success'] == 'activated' ) {
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
51
		$message = yourls__( 'Plugin has been activated' );
52
	} elseif ( $_GET['success'] == 'deactivated' ) {
0 ignored issues
show
Operator == prohibited; use === instead
Loading history...
53
		$message = yourls__( 'Plugin has been deactivated' );
54
	}
55
	yourls_add_notice( $message );
56
}
57
58
yourls_html_head( 'plugins', yourls__( 'Manage Plugins' ) );
59
yourls_html_logo();
60
yourls_html_menu();
61
?>
62
63
	<main role="main">
64
	<h2><?php yourls_e( 'Plugins' ); ?></h2>
65
66
	<?php
67
	$plugins = (array)yourls_get_plugins();
68
	uasort( $plugins, 'yourls_plugins_sort_callback' );
69
70
	$count = count( $plugins );
71
	$plugins_count = sprintf( yourls_n( '%s plugin', '%s plugins', $count ), $count );
72
	$count_active = yourls_has_active_plugins();
73
	?>
74
75
	<p id="plugin_summary"><?php /* //translators: "you have '3 plugins' installed and '1' activated" */ yourls_se( 'You currently have <strong>%1$s</strong> installed, and <strong>%2$s</strong> activated', $plugins_count, $count_active ); ?></p>
0 ignored issues
show
Single line block comment not allowed; use inline ("// text") comment instead
Loading history...
This line exceeds maximum limit of 100 characters; contains 243 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
76
77
	<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">
78
	<thead>
79
		<tr>
80
			<th><?php yourls_e( 'Plugin Name' ); ?></th>
81
			<th><?php yourls_e( 'Version' ); ?></th>
82
			<th><?php yourls_e( 'Description' ); ?></th>
83
			<th><?php yourls_e( 'Author' ); ?></th>
84
			<th><?php yourls_e( 'Action' ); ?></th>
85
		</tr>
86
	</thead>
87
	<tbody>
88
	<?php
89
90
	$nonce = yourls_create_nonce( 'manage_plugins' );
91
92
	foreach( $plugins as $file=>$plugin ) {
93
94
		// default fields to read from the plugin header
95
		$fields = array(
96
			'name'       => 'Plugin Name',
97
			'uri'        => 'Plugin URI',
98
			'desc'       => 'Description',
99
			'version'    => 'Version',
100
			'author'     => 'Author',
101
			'author_uri' => 'Author URI'
0 ignored issues
show
Each line in an array declaration must end in a comma
Loading history...
102
		);
0 ignored issues
show
The closing parenthesis does not seem to be aligned correctly; expected 12 space(s), but found 2.
Loading history...
103
104
		// Loop through all default fields, get value if any and reset it
105
		foreach( $fields as $field=>$value ) {
106
			if( isset( $plugin[ $value ] ) ) {
107
				$data[ $field ] = $plugin[ $value ];
108
			} else {
109
				$data[ $field ] = yourls__('(no info)');
110
			}
111
			unset( $plugin[$value] );
112
		}
113
114
		$plugindir = trim( dirname( $file ), '/' );
115
116
		if( yourls_is_active_plugin( $file ) ) {
117
			$class = 'active';
118
			$action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ), yourls_admin_url('plugins.php') ) );
119
			$action_anchor = yourls__( 'Deactivate' );
120
		} else {
121
			$class = 'inactive';
122
			$action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ), yourls_admin_url('plugins.php') ) );
123
			$action_anchor = yourls__( 'Activate' );
124
		}
125
126
		// Other "Fields: Value" in the header? Get them too
127
		if( $plugin ) {
128
			foreach( $plugin as $extra_field=>$extra_value ) {
129
				$data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $extra_field instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $extra_value instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
130
				unset( $plugin[$extra_value] );
131
			}
132
		}
133
134
		$data['desc'] .= '<br/><small>' . yourls_s( 'plugin file location: %s', $file) . '</small>';
135
136
		printf( "<tr class='plugin %s'><td class='plugin_name'><a href='%s'>%s</a></td><td class='plugin_version'>%s</td><td class='plugin_desc'>%s</td><td class='plugin_author'><a href='%s'>%s</a></td><td class='plugin_actions actions'><a href='%s'>%s</a></td></tr>",
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 262 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
137
			$class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
138
			);
139
140
	}
141
	?>
142
	</tbody>
143
	</table>
144
145
	<script type="text/javascript">
146
	yourls_defaultsort = 0;
147
	yourls_defaultorder = 0;
148
	<?php if ($count_active) { ?>
149
	$('#plugin_summary').append('<span id="toggle_plugins">filter</span>');
150
	$('#toggle_plugins').css({'background':'transparent url("../images/filter.gif") top left no-repeat','display':'inline-block','text-indent':'-9999px','width':'16px','height':'16px','margin-left':'3px','cursor':'pointer'})
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 221 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
151
		.attr('title', '<?php echo yourls_esc_attr__( 'Toggle active/inactive plugins' ); ?>')
152
		.click(function(){
153
			$('#main_table tr.inactive').toggle();
154
		});
155
	<?php } ?>
156
	</script>
157
158
	<p><?php yourls_e( 'If something goes wrong after you activate a plugin and you cannot use YOURLS or access this page, simply rename or delete its directory, or rename the plugin file to something different than <code>plugin.php</code>.' ); ?></p>
0 ignored issues
show
This line exceeds maximum limit of 100 characters; contains 248 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
159
160
	<h3><?php yourls_e( 'More plugins' ); ?></h3>
161
162
	<p><?php yourls_e( 'For more plugins, head to the official <a href="http://yourls.org/awesome">Plugin list</a>.' ); ?></p>
163
	</main>
164
165
<?php yourls_html_footer(); ?>
166