2 define( 'YOURLS_ADMIN', true );
3 require_once( dirname( __DIR__ ).'/includes/load-yourls.php' );
4 yourls_maybe_require_auth();
6 // Handle plugin administration pages
7 if( isset( $_GET['page'] ) && !empty( $_GET['page'] ) ) {
8 yourls_plugin_admin_page( $_GET['page'] );
12 // Handle activation/deactivation of plugins
13 if( isset( $_GET['action'] ) ) {
16 yourls_verify_nonce( 'manage_plugins', $_REQUEST['nonce'] );
18 // Check plugin file is valid
19 if( isset( $_GET['plugin'] ) && yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$_GET['plugin'].'/plugin.php') ) {
22 // Activate / Deactive
23 switch( $_GET['action'] ) {
25 $result = yourls_activate_plugin( $_GET['plugin'].'/plugin.php' );
26 if( $result === true )
27 yourls_redirect( yourls_admin_url( 'plugins.php?success=activated' ), 302 );
32 $result = yourls_deactivate_plugin( $_GET['plugin'].'/plugin.php' );
33 if( $result === true )
34 yourls_redirect( yourls_admin_url( 'plugins.php?success=deactivated' ), 302 );
39 $result = yourls__( 'Unsupported action' );
43 $result = yourls__( 'No plugin specified, or not a valid plugin' );
46 yourls_add_notice( $result );
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' );
56 yourls_add_notice( $message );
59 yourls_html_head( 'plugins', yourls__( 'Manage Plugins' ) );
65 <h2><?php yourls_e( 'Plugins' ); ?></h2>
68 $plugins = (array)yourls_get_plugins();
69 uasort( $plugins, 'yourls_plugins_sort_callback' );
71 $count = count( $plugins );
72 $plugins_count = sprintf( yourls_n( '%s plugin', '%s plugins', $count ), $count );
73 $count_active = yourls_has_active_plugins();
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>
78 <table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">
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>
91 $nonce = yourls_create_nonce( 'manage_plugins' );
93 foreach( $plugins as $file=>$plugin ) {
95 // default fields to read from the plugin header
97 'name' => 'Plugin Name',
98 'uri' => 'Plugin URI',
99 'desc' => 'Description',
100 'version' => 'Version',
101 'author' => 'Author',
102 'author_uri' => 'Author URI'
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 ];
110 $data[ $field ] = '(no info)';
112 unset( $plugin[$value] );
115 $plugindir = trim( dirname( $file ), '/' );
117 if( yourls_is_active_plugin( $file ) ) {
119 $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ) ) );
120 $action_anchor = yourls__( 'Deactivate' );
123 $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ) ) );
124 $action_anchor = yourls__( 'Activate' );
127 // Other "Fields: Value" in the header? Get them too
129 foreach( $plugin as $extra_field=>$extra_value ) {
130 $data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";
131 unset( $plugin[$extra_value] );
135 $data['desc'] .= '<br/><small>' . yourls_s( 'plugin file location: %s', $file) . '</small>';
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
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' ); ?>')
154 $('#main_table tr.inactive').toggle();
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>
161 <h3><?php yourls_e( 'More plugins' ); ?></h3>
163 <p><?php yourls_e( 'For more plugins, head to the official <a href="http://yourls.org/pluginlist">Plugin list</a>.' ); ?></p>
166 <?php yourls_html_footer(); ?>