]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/plugins.php
Should fix PNS bookmarklet
[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 }
10
11 // Handle activation/deactivation of plugins
12 if( isset( $_GET['action'] ) ) {
13
14         // Check nonce
15         yourls_verify_nonce( 'manage_plugins', $_REQUEST['nonce'] );
16
17         // Check plugin file is valid
18         if( isset( $_GET['plugin'] ) && yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$_GET['plugin'].'/plugin.php') ) {
19                 
20                 global $ydb;
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;
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;
36                                 
37                         default:
38                                 $result = yourls__( 'Unsupported action' );
39                                 break;
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' ) ) ) {
50         if( $_GET['success'] == 'activated' ) {
51                 $message = yourls__( 'Plugin has been activated' );
52         } elseif ( $_GET['success'] == 'deactivated' ) {
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         <h2><?php yourls_e( 'Plugins' ); ?></h2>
64         
65         <?php
66         $plugins = (array)yourls_get_plugins();
67         uasort( $plugins, 'yourls_plugins_sort_callback' );
68         
69         $count = count( $plugins );
70         $plugins_count = sprintf( yourls_n( '%s plugin', '%s plugins', $count ), $count );
71         $count_active = yourls_has_active_plugins();
72         ?>
73         
74         <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>
75
76         <table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">
77         <thead>
78                 <tr>
79                         <th><?php yourls_e( 'Plugin Name' ); ?></th>
80                         <th><?php yourls_e( 'Version' ); ?></th>
81                         <th><?php yourls_e( 'Description' ); ?></th>
82                         <th><?php yourls_e( 'Author' ); ?></th>
83                         <th><?php yourls_e( 'Action' ); ?></th>
84                 </tr>
85         </thead>
86         <tbody>
87         <?php
88         
89         $nonce = yourls_create_nonce( 'manage_plugins' );
90         
91         foreach( $plugins as $file=>$plugin ) {
92                 
93                 // default fields to read from the plugin header
94                 $fields = array(
95                         'name'       => 'Plugin Name',
96                         'uri'        => 'Plugin URI',
97                         'desc'       => 'Description',
98                         'version'    => 'Version',
99                         'author'     => 'Author',
100                         'author_uri' => 'Author URI'
101                 );
102                 
103                 // Loop through all default fields, get value if any and reset it
104                 foreach( $fields as $field=>$value ) {
105                         if( isset( $plugin[ $value ] ) ) {
106                                 $data[ $field ] = $plugin[ $value ];
107                         } else {
108                                 $data[ $field ] = '(no info)';
109                         }
110                         unset( $plugin[$value] );
111                 }
112                 
113                 $plugindir = trim( dirname( $file ), '/' );
114                 
115                 if( yourls_is_active_plugin( $file ) ) {
116                         $class = 'active';
117                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ) ) );
118                         $action_anchor = yourls__( 'Deactivate' );
119                 } else {
120                         $class = 'inactive';
121                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ) ) );
122                         $action_anchor = yourls__( 'Activate' );
123                 }
124                         
125                 // Other "Fields: Value" in the header? Get them too
126                 if( $plugin ) {
127                         foreach( $plugin as $extra_field=>$extra_value ) {
128                                 $data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";
129                                 unset( $plugin[$extra_value] );
130                         }
131                 }
132                 
133                 $data['desc'] .= '<br/><small>' . yourls_s( 'plugin file location: %s', $file) . '</small>';
134                 
135                 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>",
136                         $class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor
137                         );
138                 
139         }
140         ?>
141         </tbody>
142         </table>
143         
144         <script type="text/javascript">
145         yourls_defaultsort = 0;
146         yourls_defaultorder = 0;
147         <?php if ($count_active) { ?>
148         $('#plugin_summary').append('<span id="toggle_plugins">filter</span>');
149         $('#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'})
150                 .attr('title', '<?php echo yourls_esc_attr__( 'Toggle active/inactive plugins' ); ?>')
151                 .click(function(){
152                         $('#main_table tr.inactive').toggle();
153                 });
154         <?php } ?>
155         </script>
156         
157         <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>
158         
159         <h3><?php yourls_e( 'More plugins' ); ?></h3>
160         
161         <p><?php yourls_e( 'For more plugins, head to the official <a href="http://yourls.org/pluginlist">Plugin list</a>.' ); ?></p>
162
163         
164 <?php yourls_html_footer(); ?>