]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/plugins.php
l10n optimization: less strings, better strings
[Github/YOURLS.git] / admin / plugins.php
1 <?php\r
2 define( 'YOURLS_ADMIN', true );\r
3 require_once( dirname( dirname( __FILE__ ) ).'/includes/load-yourls.php' );\r
4 yourls_maybe_require_auth();\r
5 \r
6 // Handle plugin administration pages\r
7 if( isset( $_GET['page'] ) && !empty( $_GET['page'] ) ) {\r
8         yourls_plugin_admin_page( $_GET['page'] );\r
9 }\r
10 \r
11 // Handle activation/deactivation of plugins\r
12 if( isset( $_GET['action'] ) ) {\r
13 \r
14         // Check nonce\r
15         yourls_verify_nonce( 'manage_plugins', $_REQUEST['nonce'] );\r
16 \r
17         // Check plugin file is valid\r
18         if( isset( $_GET['plugin'] ) && yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$_GET['plugin'].'/plugin.php') ) {\r
19                 \r
20                 global $ydb;\r
21                 // Activate / Deactive\r
22                 switch( $_GET['action'] ) {\r
23                         case 'activate':\r
24                                 $result = yourls_activate_plugin( $_GET['plugin'].'/plugin.php' );\r
25                                 if( $result === true )\r
26                                         yourls_redirect( yourls_admin_url( 'plugins.php?success=activated' ), 302 );\r
27 \r
28                                 break;\r
29                 \r
30                         case 'deactivate':\r
31                                 $result = yourls_deactivate_plugin( $_GET['plugin'].'/plugin.php' );\r
32                                 if( $result === true )\r
33                                         yourls_redirect( yourls_admin_url( 'plugins.php?success=deactivated' ), 302 );\r
34 \r
35                                 break;\r
36                                 \r
37                         default:\r
38                                 $result = yourls__( 'Unsupported action' );\r
39                                 break;\r
40                 }\r
41         } else {\r
42                 $result = yourls__( 'No plugin specified, or not a valid plugin' );\r
43         }\r
44         \r
45         yourls_add_notice( $result );\r
46 }\r
47 \r
48 // Handle message upon succesfull (de)activation\r
49 if( isset( $_GET['success'] ) && ( ( $_GET['success'] == 'activated' ) OR ( $_GET['success'] == 'deactivated' ) ) ) {\r
50         if( $_GET['success'] == 'activated' ) {\r
51                 $message = yourls__( 'Plugin has been activated' );\r
52         } elseif ( $_GET['success'] == 'deactivated' ) {\r
53                 $message = yourls__( 'Plugin has been deactivated' );\r
54         }\r
55         yourls_add_notice( $message );\r
56 }\r
57 \r
58 yourls_html_head( 'plugins', yourls__( 'Manage Plugins' ) );\r
59 yourls_html_logo();\r
60 yourls_html_menu();\r
61 ?>\r
62 \r
63         <h2><?php yourls_e( 'Plugins' ); ?></h2>\r
64         \r
65         <?php\r
66         $plugins = (array)yourls_get_plugins();\r
67         uasort( $plugins, 'yourls_plugins_sort_callback' );\r
68         \r
69         $count = count( $plugins );\r
70     $plugins_count = sprintf( yourls_n( '%s plugin', '%s plugins', $count ), $count );\r
71         $count_active = yourls_has_active_plugins();\r
72         ?>\r
73         \r
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>\r
75 \r
76         <table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">\r
77         <thead>\r
78                 <tr>\r
79                         <th><?php yourls_e( 'Plugin Name' ); ?></th>\r
80                         <th><?php yourls_e( 'Version' ); ?></th>\r
81                         <th><?php yourls_e( 'Description' ); ?></th>\r
82                         <th><?php yourls_e( 'Author' ); ?></th>\r
83                         <th><?php yourls_e( 'Action' ); ?></th>\r
84                 </tr>\r
85         </thead>\r
86         <tbody>\r
87         <?php\r
88         \r
89         $nonce = yourls_create_nonce( 'manage_plugins' );\r
90         \r
91         foreach( $plugins as $file=>$plugin ) {\r
92                 \r
93                 // default fields to read from the plugin header\r
94                 $fields = array(\r
95                         'name'       => 'Plugin Name',\r
96                         'uri'        => 'Plugin URI',\r
97                         'desc'       => 'Description',\r
98                         'version'    => 'Version',\r
99                         'author'     => 'Author',\r
100                         'author_uri' => 'Author URI'\r
101                 );\r
102                 \r
103                 // Loop through all default fields, get value if any and reset it\r
104                 foreach( $fields as $field=>$value ) {\r
105                         if( isset( $plugin[ $value ] ) ) {\r
106                                 $data[ $field ] = $plugin[ $value ];\r
107                         } else {\r
108                                 $data[ $field ] = '(no info)';\r
109                         }\r
110                         unset( $plugin[$value] );\r
111                 }\r
112                 \r
113                 $plugindir = trim( dirname( $file ), '/' );\r
114                 \r
115                 if( yourls_is_active_plugin( $file ) ) {\r
116                         $class = 'active';\r
117                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ) ) );\r
118                         $action_anchor = yourls__( 'Deactivate' );\r
119                 } else {\r
120                         $class = 'inactive';\r
121                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ) ) );\r
122                         $action_anchor = yourls__( 'Activate' );\r
123                 }\r
124                         \r
125                 // Other "Fields: Value" in the header? Get them too\r
126                 if( $plugin ) {\r
127                         foreach( $plugin as $extra_field=>$extra_value ) {\r
128                                 $data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";\r
129                                 unset( $plugin[$extra_value] );\r
130                         }\r
131                 }\r
132                 \r
133                 $data['desc'] .= '<br/><small>' . yourls_s( 'plugin file location: %s', $file) . '</small>';\r
134                 \r
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>",\r
136                         $class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor\r
137                         );\r
138                 \r
139         }\r
140         ?>\r
141         </tbody>\r
142         </table>\r
143         \r
144         <script type="text/javascript">\r
145         yourls_defaultsort = 0;\r
146         yourls_defaultorder = 0;\r
147         <?php if ($count_active) { ?>\r
148         $('#plugin_summary').append('<span id="toggle_plugins">filter</span>');\r
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'})\r
150                 .attr('title', '<?php echo yourls_esc_attr__( 'Toggle active/inactive plugins' ); ?>')\r
151                 .click(function(){\r
152                         $('#main_table tr.inactive').toggle();\r
153                 });\r
154         <?php } ?>\r
155         </script>\r
156         \r
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>\r
158         \r
159         <h3><?php yourls_e( 'More plugins' ); ?></h3>\r
160         \r
161         <p><?php yourls_e( 'For more plugins, head to the official <a href="http://yourls.org/pluginlist">Plugin list</a>.' ); ?></p>\r
162 \r
163         \r
164 <?php yourls_html_footer(); ?>\r