]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - admin/plugins.php
Update active plugin list if one is missing upon activation
[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 activation/deactivation of plugins\r
7 if( isset( $_GET['action'] ) ) {\r
8 \r
9         // Check nonce\r
10         if( !isset( $_GET['nonce'] ) or !yourls_verify_nonce( $_GET['nonce'], 'manage_plugins' ) )\r
11                 yourls_die( 'Unauthorized action or expired link', 'Error', 403 );\r
12 \r
13         // Check plugin file is valid\r
14         if( isset( $_GET['plugin'] ) && yourls_validate_plugin_file( YOURLS_PLUGINDIR.'/'.$_GET['plugin'].'/plugin.php') ) {\r
15                 \r
16                 global $ydb;\r
17                 // Activate / Deactive\r
18                 switch( $_GET['action'] ) {\r
19                         case 'activate':\r
20                                 $result = yourls_activate_plugin( $_GET['plugin'].'/plugin.php' );\r
21                                 if( $result === true )\r
22                                         yourls_redirect( yourls_admin_url( 'plugins.php?success=activated' ) );\r
23 \r
24                                 break;\r
25                 \r
26                         case 'deactivate':\r
27                                 $result = yourls_deactivate_plugin( $_GET['plugin'].'/plugin.php' );\r
28                                 if( $result === true )\r
29                                         yourls_redirect( yourls_admin_url( 'plugins.php?success=deactivated' ) );\r
30 \r
31                                 break;\r
32                                 \r
33                         default:\r
34                                 $result = 'Unsupported action';\r
35                                 break;\r
36                 }\r
37         } else {\r
38                 $result = 'No plugin specified, or not a valid plugin';\r
39         }\r
40         \r
41         yourls_add_notice( $result );\r
42 }\r
43 \r
44 // Handle message upon succesfull (de)activation\r
45 if( isset( $_GET['success'] ) ) {\r
46         if( $_GET['success'] == 'activated' OR $_GET['success'] == 'deactivated' ) {\r
47                 yourls_add_notice( 'Plugin '.$_GET['success'] );\r
48         }\r
49 }\r
50 \r
51 yourls_html_head( 'plugins' );\r
52 yourls_html_logo();\r
53 yourls_html_menu();\r
54 ?>\r
55 \r
56         <h2>Plugins</h2>\r
57         \r
58         <?php\r
59         $plugins = (array)yourls_get_plugins();\r
60         $count = count( $plugins );\r
61         $count_active = yourls_has_active_plugins();\r
62         ?>\r
63         \r
64         <p>You currently have <strong><?php echo $count.' '.yourls_plural( 'plugin', $count ); ?></strong> installed, and <strong><?php echo $count_active; ?></strong> activated.</p>\r
65 \r
66         <table id="tblUrl" class="tblSorter" cellpadding="0" cellspacing="1">\r
67         <thead>\r
68                 <tr>\r
69                         <th>Plugin Name</th>\r
70                         <th>Version</th>\r
71                         <th>Author</th>\r
72                         <th>Description</th>\r
73                         <th>Action</th>\r
74                 </tr>\r
75         </thead>\r
76         <tbody>\r
77         <?php\r
78         \r
79         $nonce = yourls_create_nonce( 'manage_plugins' );\r
80         \r
81         foreach( $plugins as $file=>$plugin ) {\r
82                 \r
83                 // default fields to read from the plugin header\r
84                 $fields = array(\r
85                         'name'       => 'Plugin Name',\r
86                         'uri'        => 'Plugin URI',\r
87                         'desc'       => 'Description',\r
88                         'version'    => 'Version',\r
89                         'author'     => 'Author',\r
90                         'author_uri' => 'Author URI'\r
91                 );\r
92                 \r
93                 // Loop through all default fields, get value if any and reset it\r
94                 foreach( $fields as $field=>$value ) {\r
95                         if( $plugin[ $value ] ) {\r
96                                 $data[ $field ] = $plugin[ $value ];\r
97                         } else {\r
98                                 $data[ $field ] = '(no info)';\r
99                         }\r
100                         unset( $plugin[$value] );\r
101                 }\r
102                 \r
103                 $plugindir = trim( dirname( $file ), '/' );\r
104                 $action = yourls_is_active_plugin( $file ) ?\r
105                         "<a href='?action=deactivate&plugin=$plugindir&nonce=$nonce'>Deactivate</a>" :\r
106                         "<a href='?action=activate&plugin=$plugindir&nonce=$nonce'>Activate</a>" ;\r
107         \r
108                 // Other "Fields: Value" in the header? Get them too\r
109                 if( $plugin ) {\r
110                         foreach( $plugin as $extra_field=>$extra_value ) {\r
111                                 $data['desc'] .= "<br/>\n<em>$extra_field</em>: $extra_value";\r
112                                 unset( $plugin[$extra_value] );\r
113                         }\r
114                 }\r
115                 \r
116                 $data['desc'] .= "<br/><small>plugin location: $file</small>";\r
117                 \r
118                 printf( "<tr><td><a href='%s'>%s</a></td><td>%s</td><td>%s</td><td><a href='%s'>%s</a></td><td>%s</td></tr>",\r
119                         $data['uri'], $data['name'], $data['version'], $data['desc'], $data['author_uri'], $data['author'], $action\r
120                         );\r
121                 \r
122         }\r
123         ?>\r
124         </tbody>\r
125         </table>\r
126         \r
127         <script type="text/javascript">\r
128         yourls_defaultsort = 0;\r
129         yourls_defaultorder = 0;\r
130         </script>\r
131         \r
132         <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
133 \r
134         \r
135 <?php yourls_html_footer(); ?>