2013-04-07 12:52:52 +02:00
< ? php
define ( 'YOURLS_ADMIN' , true );
2017-04-17 23:03:37 +02:00
require_once ( dirname ( __DIR__ ) . '/includes/load-yourls.php' );
2013-04-07 12:52:52 +02:00
yourls_maybe_require_auth ();
// Handle plugin administration pages
if ( isset ( $_GET [ 'page' ] ) && ! empty ( $_GET [ 'page' ] ) ) {
yourls_plugin_admin_page ( $_GET [ 'page' ] );
2015-05-11 10:28:17 +02:00
die ();
2013-04-07 12:52:52 +02:00
}
// Handle activation/deactivation of plugins
if ( isset ( $_GET [ 'action' ] ) ) {
// Check nonce
yourls_verify_nonce ( 'manage_plugins' , $_REQUEST [ 'nonce' ] );
// Check plugin file is valid
if ( isset ( $_GET [ 'plugin' ] ) && yourls_validate_plugin_file ( YOURLS_PLUGINDIR . '/' . $_GET [ 'plugin' ] . '/plugin.php' ) ) {
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
// Activate / Deactive
switch ( $_GET [ 'action' ] ) {
case 'activate' :
$result = yourls_activate_plugin ( $_GET [ 'plugin' ] . '/plugin.php' );
2022-03-20 20:54:03 +01:00
if ( $result === true ) {
yourls_redirect ( yourls_admin_url ( 'plugins.php?success=activated' ), 302 );
exit ();
}
2013-04-07 12:52:52 +02:00
break ;
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
case 'deactivate' :
$result = yourls_deactivate_plugin ( $_GET [ 'plugin' ] . '/plugin.php' );
2022-03-20 20:54:03 +01:00
if ( $result === true ) {
yourls_redirect ( yourls_admin_url ( 'plugins.php?success=deactivated' ), 302 );
exit ();
}
2013-04-07 12:52:52 +02:00
break ;
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
default :
$result = yourls__ ( 'Unsupported action' );
break ;
}
} else {
$result = yourls__ ( 'No plugin specified, or not a valid plugin' );
}
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
yourls_add_notice ( $result );
}
// Handle message upon succesfull (de)activation
if ( isset ( $_GET [ 'success' ] ) && ( ( $_GET [ 'success' ] == 'activated' ) OR ( $_GET [ 'success' ] == 'deactivated' ) ) ) {
if ( $_GET [ 'success' ] == 'activated' ) {
$message = yourls__ ( 'Plugin has been activated' );
} elseif ( $_GET [ 'success' ] == 'deactivated' ) {
$message = yourls__ ( 'Plugin has been deactivated' );
}
yourls_add_notice ( $message );
}
yourls_html_head ( 'plugins' , yourls__ ( 'Manage Plugins' ) );
yourls_html_logo ();
yourls_html_menu ();
?>
2015-06-26 12:18:15 +02:00
< main role = " main " >
2013-04-07 12:52:52 +02:00
< h2 >< ? php yourls_e ( 'Plugins' ); ?> </h2>
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< ? php
$plugins = ( array ) yourls_get_plugins ();
uasort ( $plugins , 'yourls_plugins_sort_callback' );
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
$count = count ( $plugins );
2013-04-11 20:54:47 +02:00
$plugins_count = sprintf ( yourls_n ( '%s plugin' , '%s plugins' , $count ), $count );
2013-04-07 12:52:52 +02:00
$count_active = yourls_has_active_plugins ();
?>
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< 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>
< table id = " main_table " class = " tblSorter " cellpadding = " 0 " cellspacing = " 1 " >
< thead >
< tr >
< th >< ? php yourls_e ( 'Plugin Name' ); ?> </th>
< th >< ? php yourls_e ( 'Version' ); ?> </th>
< th >< ? php yourls_e ( 'Description' ); ?> </th>
< th >< ? php yourls_e ( 'Author' ); ?> </th>
< th >< ? php yourls_e ( 'Action' ); ?> </th>
</ tr >
</ thead >
< tbody >
< ? php
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
$nonce = yourls_create_nonce ( 'manage_plugins' );
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
foreach ( $plugins as $file => $plugin ) {
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
// default fields to read from the plugin header
$fields = array (
'name' => 'Plugin Name' ,
'uri' => 'Plugin URI' ,
'desc' => 'Description' ,
'version' => 'Version' ,
'author' => 'Author' ,
'author_uri' => 'Author URI'
);
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
// Loop through all default fields, get value if any and reset it
foreach ( $fields as $field => $value ) {
if ( isset ( $plugin [ $value ] ) ) {
$data [ $field ] = $plugin [ $value ];
} else {
2020-04-20 14:50:19 +02:00
$data [ $field ] = yourls__ ( '(no info)' );
2013-04-07 12:52:52 +02:00
}
unset ( $plugin [ $value ] );
}
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
$plugindir = trim ( dirname ( $file ), '/' );
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
if ( yourls_is_active_plugin ( $file ) ) {
$class = 'active' ;
2020-04-08 15:26:42 +02:00
$action_url = yourls_nonce_url ( 'manage_plugins' , yourls_add_query_arg ( array ( 'action' => 'deactivate' , 'plugin' => $plugindir ), yourls_admin_url ( 'plugins.php' ) ) );
2013-04-07 12:52:52 +02:00
$action_anchor = yourls__ ( 'Deactivate' );
} else {
$class = 'inactive' ;
2020-04-08 15:26:42 +02:00
$action_url = yourls_nonce_url ( 'manage_plugins' , yourls_add_query_arg ( array ( 'action' => 'activate' , 'plugin' => $plugindir ), yourls_admin_url ( 'plugins.php' ) ) );
2013-04-07 12:52:52 +02:00
$action_anchor = yourls__ ( 'Activate' );
}
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
// Other "Fields: Value" in the header? Get them too
if ( $plugin ) {
foreach ( $plugin as $extra_field => $extra_value ) {
$data [ 'desc' ] .= " <br/> \n <em> $extra_field </em>: $extra_value " ;
unset ( $plugin [ $extra_value ] );
}
}
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
$data [ 'desc' ] .= '<br/><small>' . yourls_s ( 'plugin file location: %s' , $file ) . '</small>' ;
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
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> " ,
$class , $data [ 'uri' ], $data [ 'name' ], $data [ 'version' ], $data [ 'desc' ], $data [ 'author_uri' ], $data [ 'author' ], $action_url , $action_anchor
);
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
}
?>
</ tbody >
</ table >
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< script type = " text/javascript " >
yourls_defaultsort = 0 ;
yourls_defaultorder = 0 ;
< ? php if ( $count_active ) { ?>
$ ( '#plugin_summary' ) . append ( '<span id="toggle_plugins">filter</span>' );
2021-02-08 23:29:48 +01:00
$ ( '#toggle_plugins' ) . css ({ 'background' : 'transparent url("../images/filter.svg") top left no-repeat' , 'display' : 'inline-block' , 'text-indent' : '-9999px' , 'width' : '16px' , 'height' : '16px' , 'margin-left' : '3px' , 'cursor' : 'pointer' })
2013-04-07 12:52:52 +02:00
. attr ( 'title' , '<?php echo yourls_esc_attr__( ' Toggle active / inactive plugins ' ); ?>' )
. click ( function (){
$ ( '#main_table tr.inactive' ) . toggle ();
});
< ? php } ?>
</ script >
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< 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>
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< h3 >< ? php yourls_e ( 'More plugins' ); ?> </h3>
2020-04-08 15:26:42 +02:00
2020-04-08 15:34:46 +02:00
< p >< ? php yourls_e ( 'For more plugins, head to the official <a href="http://yourls.org/awesome">Plugin list</a>.' ); ?> </p>
2015-06-26 12:18:15 +02:00
</ main >
2020-04-08 15:26:42 +02:00
2013-04-07 12:52:52 +02:00
< ? php yourls_html_footer (); ?>