]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/plugins.php
Plugin management page: now properly sorted by name.
[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 = 'Unsupported action';\r
39                                 break;\r
40                 }\r
41         } else {\r
42                 $result = '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'] ) ) {\r
50         if( $_GET['success'] == 'activated' OR $_GET['success'] == 'deactivated' ) {\r
51                 yourls_add_notice( 'Plugin '.$_GET['success'] );\r
52         }\r
53 }\r
54 \r
55 yourls_html_head( 'plugins', 'Manage Plugins' );\r
56 yourls_html_logo();\r
57 yourls_html_menu();\r
58 ?>\r
59 \r
60         <h2>Plugins</h2>\r
61         \r
62         <?php\r
63         $plugins = (array)yourls_get_plugins();\r
64         uasort( $plugins, 'yourls_plugins_sort_callback' );\r
65         \r
66         $count = count( $plugins );\r
67         $count_active = yourls_has_active_plugins();\r
68         ?>\r
69         \r
70         <p id="plugin_summary">You currently have <strong><?php echo $count.' '.yourls_plural( 'plugin', $count ); ?></strong> installed, and <strong><?php echo $count_active; ?></strong> activated</p>\r
71 \r
72         <table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1">\r
73         <thead>\r
74                 <tr>\r
75                         <th>Plugin Name</th>\r
76                         <th>Version</th>\r
77                         <th>Description</th>\r
78                         <th>Author</th>\r
79                         <th>Action</th>\r
80                 </tr>\r
81         </thead>\r
82         <tbody>\r
83         <?php\r
84         \r
85         $nonce = yourls_create_nonce( 'manage_plugins' );\r
86         \r
87         foreach( $plugins as $file=>$plugin ) {\r
88                 \r
89                 // default fields to read from the plugin header\r
90                 $fields = array(\r
91                         'name'       => 'Plugin Name',\r
92                         'uri'        => 'Plugin URI',\r
93                         'desc'       => 'Description',\r
94                         'version'    => 'Version',\r
95                         'author'     => 'Author',\r
96                         'author_uri' => 'Author URI'\r
97                 );\r
98                 \r
99                 // Loop through all default fields, get value if any and reset it\r
100                 foreach( $fields as $field=>$value ) {\r
101                         if( isset( $plugin[ $value ] ) ) {\r
102                                 $data[ $field ] = $plugin[ $value ];\r
103                         } else {\r
104                                 $data[ $field ] = '(no info)';\r
105                         }\r
106                         unset( $plugin[$value] );\r
107                 }\r
108                 \r
109                 $plugindir = trim( dirname( $file ), '/' );\r
110                 \r
111                 if( yourls_is_active_plugin( $file ) ) {\r
112                         $class = 'active';\r
113                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'deactivate', 'plugin' => $plugindir ) ) );\r
114                         $action_anchor = 'Deactivate';\r
115                 } else {\r
116                         $class = 'inactive';\r
117                         $action_url = yourls_nonce_url( 'manage_plugins', yourls_add_query_arg( array('action' => 'activate', 'plugin' => $plugindir ) ) );\r
118                         $action_anchor = 'Activate';\r
119                 }\r
120                         \r
121                 // Other "Fields: Value" in the header? Get them too\r
122                 if( $plugin ) {\r
123                         foreach( $plugin as $extra_field=>$extra_value ) {\r
124                                 $data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";\r
125                                 unset( $plugin[$extra_value] );\r
126                         }\r
127                 }\r
128                 \r
129                 $data['desc'] .= "<br/><small>plugin file location: $file</small>";\r
130                 \r
131                 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
132                         $class, $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action_url, $action_anchor\r
133                         );\r
134                 \r
135         }\r
136         ?>\r
137         </tbody>\r
138         </table>\r
139         \r
140         <script type="text/javascript">\r
141         yourls_defaultsort = 0;\r
142         yourls_defaultorder = 0;\r
143         <?php if ($count_active) { ?>\r
144         $('#plugin_summary').append('<span id="toggle_plugins">filter</span>');\r
145         $('#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
146                 .attr('title', 'Toggle active/inactive plugins')\r
147                 .click(function(){\r
148                         $('#main_table tr.inactive').toggle();\r
149                 });\r
150         <?php } ?>\r
151         </script>\r
152         \r
153         <p>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
154         \r
155         <h3>More plugins</h3>\r
156         \r
157         <p>For more plugins, head to the official <a href="http://code.google.com/p/yourls/wiki/PluginList">Plugin list</a>.</p>\r
158 \r
159         \r
160 <?php yourls_html_footer(); ?>\r