]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/plugins.php
Get die() ouf of yourls_plugin_admin_page()
[Github/YOURLS.git] / admin / plugins.php
1 <?php
2 define( 'YOURLS_ADMIN', true );
3 require_once( dirname( dirname( __FILE__ ) ).'/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                         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                         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         <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>
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'
102                 );
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 ] = '(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 ) ) );
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 ) ) );
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";
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>",
137                         $class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor
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'})
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>
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/pluginlist">Plugin list</a>.' ); ?></p>
163
164         
165 <?php yourls_html_footer(); ?>