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