[geeklog-cvs] geeklog: If plugin upload is disabled, tell the user why.
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sat Mar 5 13:15:48 EST 2011
changeset 8143:5e855016cbc6
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/5e855016cbc6
user: Rouslan Placella <rouslan at placella.com>
date: Sat Mar 05 18:14:50 2011 +0000
description:
If plugin upload is disabled, tell the user why.
diffstat:
language/english.php | 5 ++
public_html/admin/plugins.php | 73 +++++++++++++++++++++++++++---------------
2 files changed, 51 insertions(+), 27 deletions(-)
diffs (130 lines):
diff -r 68e31072e1e3 -r 5e855016cbc6 language/english.php
--- a/language/english.php Fri Mar 04 17:10:52 2011 -0500
+++ b/language/english.php Sat Mar 05 18:14:50 2011 +0000
@@ -1109,6 +1109,11 @@
62 => 'Click to Install this Plugin',
63 => 'This Plugin Cannot be Installed',
64 => 'This Plugin Cannot be Enabled',
+ 65 => 'The plugin upload function has been disabled due to the following errors:',
+ 66 => 'File uploads are disabled in your PHP configuration.',
+ 67 => 'The directory "%s" is not writable.',
+ 68 => 'You do not have the required permissions to install plugins.',
+ 69 => 'You do not have the required permissions to upload plugins.',
// to match the PHP error constants,
// http://www.php.net/manual/en/features.file-upload.errors.php
diff -r 68e31072e1e3 -r 5e855016cbc6 public_html/admin/plugins.php
--- a/public_html/admin/plugins.php Fri Mar 04 17:10:52 2011 -0500
+++ b/public_html/admin/plugins.php Sat Mar 05 18:14:50 2011 +0000
@@ -149,8 +149,8 @@
. '/functions.inc')) {
$plg_templates->set_var('pi_enabled', $LANG32[21]);
} else {
- $plg_templates->set_var('pi_enabled', '<div class="status_red">' . $LANG32[54] . '</div>');
- }
+ $plg_templates->set_var('pi_enabled', '<div class="status_red">' . $LANG32[54] . '</div>');
+ }
}
$plg_templates->set_var('back', $LANG32[60]);
$plg_templates->set_var('gltoken', SEC_createToken());
@@ -608,26 +608,39 @@
/**
* Check if uploads are possible
*
-* @return boolean true: uploads possible; false: not possible
+* @return array a list of errors or an empty array, if there weren't any.
*
*/
function plugin_upload_enabled()
{
- global $_CONF;
+ global $_CONF, $LANG32;
$path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'],
strlen($_CONF['site_url']) + 1) . '/';
// If 'file_uploads' is enabled in php.ini
// and the plugin directories are writable by the web server.
- $upload_enabled = (ini_get('file_uploads')
- && is_writable($_CONF['path'] . 'plugins/')
- && is_writable($_CONF['path_html'])
- && is_writable($path_admin . 'plugins/'))
- ? true
- : false;
+ $errors = array();
+ if (!ini_get('file_uploads')) {
+ $errors[] = $LANG32[66];
+ }
+ if (!is_writable($_CONF['path'] . 'plugins/')) {
+ $errors[] = sprintf($LANG32[67], $_CONF['path'] . 'plugins/');
+ }
+ if (!is_writable($_CONF['path_html'])) {
+ $errors[] = sprintf($LANG32[67], $_CONF['path_html']);
+ }
+ if (!is_writable($path_admin . 'plugins/')) {
+ $errors[] = sprintf($LANG32[67], $path_admin . 'plugins/');
+ }
+ if (!SEC_hasRights('plugin.install')) {
+ $errors[] = $LANG32[68];
+ }
+ if (!SEC_hasRights('plugin.upload')) {
+ $errors[] = $LANG32[69];
+ }
- return $upload_enabled;
+ return $errors;
}
/**
@@ -646,17 +659,26 @@
$retval .= COM_startBlock($LANG32[39], '',
COM_getBlockTemplate('_admin_block', 'header'));
- // Show the upload form
- $retval .= '<p>' . $LANG32[40] . '</p>' . LB
- . '<form name="plugins_upload" action="' . $_CONF['site_admin_url'] . '/plugins.php" method="post" enctype="multipart/form-data">' . LB
- . '<div>' . $LANG28[29] . ': '
- . '<input type="file" dir="ltr" name="plugin" size="40"' . XHTML
- . '> ' . LB
- . '<input type="submit" name="upload" value="' . $LANG32[41] . '"'
- . XHTML . '>' . LB
- . '<input type="hidden" name="' . CSRF_TOKEN . '" value="' . $token
- . '"' . XHTML . '>' . '</div>' . LB . '</form>' . LB;
-
+ // Check if all the requirements needed to upload a plugin are met
+ $errors = plugin_upload_enabled();
+ if (count($errors) == 0) {
+ // Show the upload form
+ $retval .= '<p>' . $LANG32[40] . '</p>' . LB
+ . '<form name="plugins_upload" action="' . $_CONF['site_admin_url']
+ . '/plugins.php" method="post" enctype="multipart/form-data">' . LB
+ . '<div>' . $LANG28[29] . ': '
+ . '<input type="file" dir="ltr" name="plugin" size="40"' . XHTML . '> ' . LB
+ . '<input type="submit" name="upload" value="' . $LANG32[41] . '"' . XHTML . '>' . LB
+ . '<input type="hidden" name="' . CSRF_TOKEN . '" value="' . $token . '"' . XHTML . '>'
+ . '</div>' . LB . '</form>' . LB;
+ } else {
+ // Show the errors
+ $retval .= '<p>' . $LANG32[65] . '</p>' . LB . '<div><ul>' . LB;
+ foreach ($errors as $key => $value) {
+ $retval .= "<li>$value</li>";
+ }
+ $retval .= '</ul></div>' . LB;
+ }
$retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
return $retval;
@@ -918,11 +940,8 @@
$retval .= show_newplugins($token);
}
- // If the web server will allow the user to upload a plugin
- if (plugin_upload_enabled() &&
- SEC_hasRights('plugin.install,plugin.upload')) {
- $retval .= plugin_show_uploadform($token);
- }
+ // Show the upload form or an error message
+ $retval .= plugin_show_uploadform($token);
$retval .= COM_siteFooter();
More information about the geeklog-cvs
mailing list