Completed
Pull Request — master (#2278)
by ྅༻ Ǭɀħ
14:42
created

admin/plugins.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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') ) {
20
		
21
		global $ydb;
22
		// Activate / Deactive
23
		switch( $_GET['action'] ) {
24 View Code Duplication
			case 'activate':
25
				$result = yourls_activate_plugin( $_GET['plugin'].'/plugin.php' );
26
				if( $result === true )
27
					yourls_redirect( yourls_admin_url( 'plugins.php?success=activated' ), 302 );
28
29
				break;
30
		
31 View Code Duplication
			case 'deactivate':
32
				$result = yourls_deactivate_plugin( $_GET['plugin'].'/plugin.php' );
33
				if( $result === true )
34
					yourls_redirect( yourls_admin_url( 'plugins.php?success=deactivated' ), 302 );
35
36
				break;
37
				
38
			default:
39
				$result = yourls__( 'Unsupported action' );
40
				break;
41
		}
42
	} else {
43
		$result = yourls__( 'No plugin specified, or not a valid plugin' );
44
	}
45
	
46
	yourls_add_notice( $result );
47
}
48
49
// Handle message upon succesfull (de)activation
50
if( isset( $_GET['success'] ) && ( ( $_GET['success'] == 'activated' ) OR ( $_GET['success'] == 'deactivated' ) ) ) {
51
	if( $_GET['success'] == 'activated' ) {
52
		$message = yourls__( 'Plugin has been activated' );
53
	} elseif ( $_GET['success'] == 'deactivated' ) {
54
		$message = yourls__( 'Plugin has been deactivated' );
55
	}
56
	yourls_add_notice( $message );
57
}
58
59
yourls_html_head( 'plugins', yourls__( 'Manage Plugins' ) );
60
yourls_html_logo();
61
yourls_html_menu();
62
?>
63
64
	<main role="main">
65
	<h2><?php yourls_e( 'Plugins' ); ?></h2>
66
	
67
	<?php
68
	$plugins = (array)yourls_get_plugins();
69
	uasort( $plugins, 'yourls_plugins_sort_callback' );
70
	
71
	$count = count( $plugins );
72
	$plugins_count = sprintf( yourls_n( '%s plugin', '%s plugins', $count ), $count );
73
	$count_active = yourls_has_active_plugins();
74
	?>
75
	
76
	<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>
77
78
	<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">
79
	<thead>
80
		<tr>
81
			<th><?php yourls_e( 'Plugin Name' ); ?></th>
82
			<th><?php yourls_e( 'Version' ); ?></th>
83
			<th><?php yourls_e( 'Description' ); ?></th>
84
			<th><?php yourls_e( 'Author' ); ?></th>
85
			<th><?php yourls_e( 'Action' ); ?></th>
86
		</tr>
87
	</thead>
88
	<tbody>
89
	<?php
90
	
91
	$nonce = yourls_create_nonce( 'manage_plugins' );
92
	
93
	foreach( $plugins as $file=>$plugin ) {
94
		
95
		// default fields to read from the plugin header
96
		$fields = array(
97
			'name'       => 'Plugin Name',
98
			'uri'        => 'Plugin URI',
99
			'desc'       => 'Description',
100
			'version'    => 'Version',
101
			'author'     => 'Author',
102
			'author_uri' => 'Author URI'
103
		);
104
		
105
		// Loop through all default fields, get value if any and reset it
106
		foreach( $fields as $field=>$value ) {
107
			if( isset( $plugin[ $value ] ) ) {
108
				$data[ $field ] = $plugin[ $value ];
109
			} else {
110
				$data[ $field ] = '(no info)';
111
			}
112
			unset( $plugin[$value] );
113
		}
114
		
115
		$plugindir = trim( dirname( $file ), '/' );
116
		
117
		if( yourls_is_active_plugin( $file ) ) {
118
			$class = 'active';
119
			$action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ) ) );
0 ignored issues
show
yourls_add_query_arg(arr...plugin' => $plugindir)) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
			$action_anchor = yourls__( 'Deactivate' );
121
		} else {
122
			$class = 'inactive';
123
			$action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ) ) );
0 ignored issues
show
yourls_add_query_arg(arr...plugin' => $plugindir)) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
			$action_anchor = yourls__( 'Activate' );
125
		}
126
			
127
		// Other "Fields: Value" in the header? Get them too
128
		if( $plugin ) {
129
			foreach( $plugin as $extra_field=>$extra_value ) {
130
				$data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";
131
				unset( $plugin[$extra_value] );
132
			}
133
		}
134
		
135
		$data['desc'] .= '<br/><small>' . yourls_s( 'plugin file location: %s', $file) . '</small>';
136
		
137
		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>",
138
			$class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor
139
			);
140
		
141
	}
142
	?>
143
	</tbody>
144
	</table>
145
	
146
	<script type="text/javascript">
147
	yourls_defaultsort = 0;
148
	yourls_defaultorder = 0;
149
	<?php if ($count_active) { ?>
150
	$('#plugin_summary').append('<span id="toggle_plugins">filter</span>');
151
	$('#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'})
152
		.attr('title', '<?php echo yourls_esc_attr__( 'Toggle active/inactive plugins' ); ?>')
153
		.click(function(){
154
			$('#main_table tr.inactive').toggle();
155
		});
156
	<?php } ?>
157
	</script>
158
	
159
	<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>
160
	
161
	<h3><?php yourls_e( 'More plugins' ); ?></h3>
162
	
163
	<p><?php yourls_e( 'For more plugins, head to the official <a href="http://yourls.org/pluginlist">Plugin list</a>.' ); ?></p>
164
	</main>
165
	
166
<?php yourls_html_footer(); ?>
167