Commit 15f289a8 authored by Dries's avatar Dries

- Added file handling.  Work by Kjartan.
parent c1898456
...@@ -935,6 +935,7 @@ function drupal_page_footer() { ...@@ -935,6 +935,7 @@ function drupal_page_footer() {
include_once "includes/menu.inc"; include_once "includes/menu.inc";
include_once "includes/xmlrpc.inc"; include_once "includes/xmlrpc.inc";
include_once "includes/tablesort.inc"; include_once "includes/tablesort.inc";
include_once "includes/file.inc";
// set error handler: // set error handler:
set_error_handler("error_handler"); set_error_handler("error_handler");
......
This diff is collapsed.
...@@ -57,6 +57,10 @@ function profile_settings() { ...@@ -57,6 +57,10 @@ function profile_settings() {
_profile_init(); _profile_init();
} }
if (!file_check_directory(file_create_path(variable_get('profile_avatar_path', 'avatars')))) {
$error['profile_avatar_path'] = theme('error', t('Directory does not exist, or is not writable.'));
}
$profile_public_fields = variable_get("profile_public_fields", array()); $profile_public_fields = variable_get("profile_public_fields", array());
$profile_private_fields = variable_get("profile_private_fields", array()); $profile_private_fields = variable_get("profile_private_fields", array());
$profile_required_fields = variable_get("profile_required_fields", array()); $profile_required_fields = variable_get("profile_required_fields", array());
...@@ -74,7 +78,7 @@ function profile_settings() { ...@@ -74,7 +78,7 @@ function profile_settings() {
} }
$output .= theme("table", $header, $row); $output .= theme("table", $header, $row);
$output .= form_textfield(t("Avatar image path"), "profile_avatar_path", variable_get("profile_avatar_path", "misc/avatars/"), 30, 255, t("Path for avatar directory; it must be writable and visible from the web.")); $output .= form_textfield(t("Avatar image path"), "profile_avatar_path", variable_get("profile_avatar_path", "avatars"), 30, 255, t("Subdirectory in the directory '%dir' where avatars will be stored.", array('%dir' => variable_get('file_directory_path', 'files') . FILE_SEPARATOR)) . $error['profile_avatar_path']);
$output .= form_textfield(t("Avatar maximum dimensions"), "profile_avatar_dimensions", variable_get("profile_avatar_dimensions", "85x85"), 10, 10, t("Maximum dimensions for avatars.")); $output .= form_textfield(t("Avatar maximum dimensions"), "profile_avatar_dimensions", variable_get("profile_avatar_dimensions", "85x85"), 10, 10, t("Maximum dimensions for avatars."));
$output .= form_textfield(t("Avatar maximum file size"), "profile_avatar_file_size", variable_get("profile_avatar_file_size", "30"), 10, 10, t("Maximum file size for avatars, in kB.")); $output .= form_textfield(t("Avatar maximum file size"), "profile_avatar_file_size", variable_get("profile_avatar_file_size", "30"), 10, 10, t("Maximum file size for avatars, in kB."));
...@@ -133,11 +137,8 @@ function _profile_form($edit, $mode) { ...@@ -133,11 +137,8 @@ function _profile_form($edit, $mode) {
} }
if (in_array("avatar", $reg_fields)) { if (in_array("avatar", $reg_fields)) {
if ($edit["profile_avatar"] && $edit["uid"]) { if ($edit["profile_avatar"] && file_exists($edit["profile_avatar"])) {
$file = profile_avatar_path($edit["uid"], $edit["profile_avatar"]); $output .= form_item(t("Avatar"), '<img src="'. file_create_url($edit["profile_avatar"]) .'" alt="" title="" />');
if ($file) {
$output .= "<img src=\"$file\" alt=\"\" title=\"\" /><br />";
}
} }
$output .= form_file($profile_fields["avatar"][1], "profile_avatar", 64, $profile_fields["avatar"][2]); $output .= form_file($profile_fields["avatar"][1], "profile_avatar", 64, $profile_fields["avatar"][2]);
} }
...@@ -199,9 +200,8 @@ function _profile_user_view(&$user, $mode) { ...@@ -199,9 +200,8 @@ function _profile_user_view(&$user, $mode) {
case "": case "":
// special // special
if ($t == "profile_avatar") { if ($t == "profile_avatar") {
$file = profile_avatar_path($user->uid, $user->profile_avatar); if (file_exists($user->$t)) {
if (file_exists($file)) { $output .= form_item(t("Avatar"), '<img src="'. file_create_url($user->$t) .'" alt="" title="" />');
$output .= form_item(t("Avatar"), "<img src=\"$file\" alt=\"\" title=\"\" />");
} }
} }
...@@ -218,51 +218,44 @@ function _profile_user_view(&$user, $mode) { ...@@ -218,51 +218,44 @@ function _profile_user_view(&$user, $mode) {
return $output; return $output;
} }
function profile_file_download($file) {
if (strpos($file, variable_get("profile_avatar_path", "avatars")) === 0) {
return array("Content-type: $mime");
}
}
function _profile_validate_avatar(&$edit, $user) { function _profile_validate_avatar(&$edit, $user) {
// check that uploaded file is an image, with a maximum file size and maximum height/width // check that uploaded file is an image, with a maximum file size and maximum height/width
unset($edit["profile_avatar"]); unset($edit["profile_avatar"]);
if ($_FILES["edit"]["name"]["profile_avatar"] == "") { if (!$file = file_check_upload('profile_avatar')) {
$edit["profile_avatar"] = $user->profile_avatar; $edit["profile_avatar"] = $user->profile_avatar;
return ""; return;
} }
$image_file = $_FILES["edit"]["tmp_name"]["profile_avatar"]; $extension = strtolower(strrchr($file->name, "."));
if (is_uploaded_file($image_file)) { $size = getimagesize($file->path);
$extension = strtolower(strrchr($_FILES["edit"]["name"]["profile_avatar"], ".")); list($maxwidth, $maxheight) = explode("x", variable_get("profile_avatar_dimensions", "85x85"));
$size = getimagesize($image_file); if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array(".gif", ".jpg", ".png", ".jpeg")))) {
list($maxwidth, $maxheight) = explode("x", variable_get("profile_avatar_dimensions", "85x85")); $error = t("The uploaded file was not an image.");
if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array(".gif", ".jpg", ".png", ".jpeg")))) { }
$error = t("The uploaded file was not an image."); else if ($file->size > (variable_get("profile_avatar_file_size", "30") * 1000)) {
} $error = t("The uploaded image is too large; the maximum file size is %a kB.", array("%a" => variable_get("profile_avatar_file_size", "30")));
else if (filesize($image_file) > (variable_get("profile_avatar_file_size", "30") * 1000)) { }
$error = t("The uploaded image is too large; the maximum file size is %a kB.", array("%a" => variable_get("profile_avatar_file_size", "30"))); else if ($size[0] > $maxwidth || $size[1] > $maxheight) {
} $error = t("The uploaded image is too large; the maximum dimensions are %a pixels.", array("%a" => variable_get("profile_avatar_dimensions", "85x85")));
else if ($size[0] > $maxwidth || $size[1] > $maxheight) { }
$error = t("The uploaded image is too large; the maximum dimensions are %a pixels.", array("%a" => variable_get("profile_avatar_dimensions", "85x85"))); else if ($file = file_save_upload('profile_avatar', variable_get("profile_avatar_path", "avatars") . FILE_SEPARATOR .'avatar-'. $user->uid . $extension, 1)) {
} $edit["profile_avatar"] = $file->name;
else if (!is_dir(variable_get("profile_avatar_path", "misc/avatars/"))) { }
$error = t("Failed to upload the avatar image; the '%directory' directory doesn't exist.", array("%directory" => variable_get("profile_avatar_path", "misc/avatars/"))); else {
} $error = t("Failed to upload the avatar image; the '%directory' directory doesn't exist.", array("%directory" => variable_get("profile_avatar_path", "avatars")));
else if (!is_writeable(variable_get("profile_avatar_path", "misc/avatars/"))) {
$error = t("Failed to upload the avatar image; the webserver has no write permission to the '%directory' directory.", array("%directory" => variable_get("profile_avatar_path", "misc/avatars/")));
}
else if (!copy($image_file, variable_get("profile_avatar_path", "misc/avatars/").md5($user->uid).$extension)) {
$error = t("Failed to upload the avatar image; could not copy file '%filename' to directory '%directory'.", array("%filename" => $_FILES["edit"]["name"]["profile_avatar"], "%directory" => variable_get("profile_avatar_path", "misc/avatars/")));
}
else {
$edit["profile_avatar"] = $extension;
}
} }
return $error ? "$error<br />" : ""; return $error ? "$error<br />" : "";
} }
function profile_avatar_path($uid, $extension) {
return $extension ? variable_get("profile_avatar_path", "misc/avatars/") . md5($uid) . $extension : "";
}
function _profile_active_fields($mode) { function _profile_active_fields($mode) {
return variable_get("profile_". $mode ."_fields", array()); return variable_get("profile_". $mode ."_fields", array());
} }
......
...@@ -57,6 +57,10 @@ function profile_settings() { ...@@ -57,6 +57,10 @@ function profile_settings() {
_profile_init(); _profile_init();
} }
if (!file_check_directory(file_create_path(variable_get('profile_avatar_path', 'avatars')))) {
$error['profile_avatar_path'] = theme('error', t('Directory does not exist, or is not writable.'));
}
$profile_public_fields = variable_get("profile_public_fields", array()); $profile_public_fields = variable_get("profile_public_fields", array());
$profile_private_fields = variable_get("profile_private_fields", array()); $profile_private_fields = variable_get("profile_private_fields", array());
$profile_required_fields = variable_get("profile_required_fields", array()); $profile_required_fields = variable_get("profile_required_fields", array());
...@@ -74,7 +78,7 @@ function profile_settings() { ...@@ -74,7 +78,7 @@ function profile_settings() {
} }
$output .= theme("table", $header, $row); $output .= theme("table", $header, $row);
$output .= form_textfield(t("Avatar image path"), "profile_avatar_path", variable_get("profile_avatar_path", "misc/avatars/"), 30, 255, t("Path for avatar directory; it must be writable and visible from the web.")); $output .= form_textfield(t("Avatar image path"), "profile_avatar_path", variable_get("profile_avatar_path", "avatars"), 30, 255, t("Subdirectory in the directory '%dir' where avatars will be stored.", array('%dir' => variable_get('file_directory_path', 'files') . FILE_SEPARATOR)) . $error['profile_avatar_path']);
$output .= form_textfield(t("Avatar maximum dimensions"), "profile_avatar_dimensions", variable_get("profile_avatar_dimensions", "85x85"), 10, 10, t("Maximum dimensions for avatars.")); $output .= form_textfield(t("Avatar maximum dimensions"), "profile_avatar_dimensions", variable_get("profile_avatar_dimensions", "85x85"), 10, 10, t("Maximum dimensions for avatars."));
$output .= form_textfield(t("Avatar maximum file size"), "profile_avatar_file_size", variable_get("profile_avatar_file_size", "30"), 10, 10, t("Maximum file size for avatars, in kB.")); $output .= form_textfield(t("Avatar maximum file size"), "profile_avatar_file_size", variable_get("profile_avatar_file_size", "30"), 10, 10, t("Maximum file size for avatars, in kB."));
...@@ -133,11 +137,8 @@ function _profile_form($edit, $mode) { ...@@ -133,11 +137,8 @@ function _profile_form($edit, $mode) {
} }
if (in_array("avatar", $reg_fields)) { if (in_array("avatar", $reg_fields)) {
if ($edit["profile_avatar"] && $edit["uid"]) { if ($edit["profile_avatar"] && file_exists($edit["profile_avatar"])) {
$file = profile_avatar_path($edit["uid"], $edit["profile_avatar"]); $output .= form_item(t("Avatar"), '<img src="'. file_create_url($edit["profile_avatar"]) .'" alt="" title="" />');
if ($file) {
$output .= "<img src=\"$file\" alt=\"\" title=\"\" /><br />";
}
} }
$output .= form_file($profile_fields["avatar"][1], "profile_avatar", 64, $profile_fields["avatar"][2]); $output .= form_file($profile_fields["avatar"][1], "profile_avatar", 64, $profile_fields["avatar"][2]);
} }
...@@ -199,9 +200,8 @@ function _profile_user_view(&$user, $mode) { ...@@ -199,9 +200,8 @@ function _profile_user_view(&$user, $mode) {
case "": case "":
// special // special
if ($t == "profile_avatar") { if ($t == "profile_avatar") {
$file = profile_avatar_path($user->uid, $user->profile_avatar); if (file_exists($user->$t)) {
if (file_exists($file)) { $output .= form_item(t("Avatar"), '<img src="'. file_create_url($user->$t) .'" alt="" title="" />');
$output .= form_item(t("Avatar"), "<img src=\"$file\" alt=\"\" title=\"\" />");
} }
} }
...@@ -218,51 +218,44 @@ function _profile_user_view(&$user, $mode) { ...@@ -218,51 +218,44 @@ function _profile_user_view(&$user, $mode) {
return $output; return $output;
} }
function profile_file_download($file) {
if (strpos($file, variable_get("profile_avatar_path", "avatars")) === 0) {
return array("Content-type: $mime");
}
}
function _profile_validate_avatar(&$edit, $user) { function _profile_validate_avatar(&$edit, $user) {
// check that uploaded file is an image, with a maximum file size and maximum height/width // check that uploaded file is an image, with a maximum file size and maximum height/width
unset($edit["profile_avatar"]); unset($edit["profile_avatar"]);
if ($_FILES["edit"]["name"]["profile_avatar"] == "") { if (!$file = file_check_upload('profile_avatar')) {
$edit["profile_avatar"] = $user->profile_avatar; $edit["profile_avatar"] = $user->profile_avatar;
return ""; return;
} }
$image_file = $_FILES["edit"]["tmp_name"]["profile_avatar"]; $extension = strtolower(strrchr($file->name, "."));
if (is_uploaded_file($image_file)) { $size = getimagesize($file->path);
$extension = strtolower(strrchr($_FILES["edit"]["name"]["profile_avatar"], ".")); list($maxwidth, $maxheight) = explode("x", variable_get("profile_avatar_dimensions", "85x85"));
$size = getimagesize($image_file); if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array(".gif", ".jpg", ".png", ".jpeg")))) {
list($maxwidth, $maxheight) = explode("x", variable_get("profile_avatar_dimensions", "85x85")); $error = t("The uploaded file was not an image.");
if ((!in_array($size[2], array(1, 2, 3))) || (!in_array($extension, array(".gif", ".jpg", ".png", ".jpeg")))) { }
$error = t("The uploaded file was not an image."); else if ($file->size > (variable_get("profile_avatar_file_size", "30") * 1000)) {
} $error = t("The uploaded image is too large; the maximum file size is %a kB.", array("%a" => variable_get("profile_avatar_file_size", "30")));
else if (filesize($image_file) > (variable_get("profile_avatar_file_size", "30") * 1000)) { }
$error = t("The uploaded image is too large; the maximum file size is %a kB.", array("%a" => variable_get("profile_avatar_file_size", "30"))); else if ($size[0] > $maxwidth || $size[1] > $maxheight) {
} $error = t("The uploaded image is too large; the maximum dimensions are %a pixels.", array("%a" => variable_get("profile_avatar_dimensions", "85x85")));
else if ($size[0] > $maxwidth || $size[1] > $maxheight) { }
$error = t("The uploaded image is too large; the maximum dimensions are %a pixels.", array("%a" => variable_get("profile_avatar_dimensions", "85x85"))); else if ($file = file_save_upload('profile_avatar', variable_get("profile_avatar_path", "avatars") . FILE_SEPARATOR .'avatar-'. $user->uid . $extension, 1)) {
} $edit["profile_avatar"] = $file->name;
else if (!is_dir(variable_get("profile_avatar_path", "misc/avatars/"))) { }
$error = t("Failed to upload the avatar image; the '%directory' directory doesn't exist.", array("%directory" => variable_get("profile_avatar_path", "misc/avatars/"))); else {
} $error = t("Failed to upload the avatar image; the '%directory' directory doesn't exist.", array("%directory" => variable_get("profile_avatar_path", "avatars")));
else if (!is_writeable(variable_get("profile_avatar_path", "misc/avatars/"))) {
$error = t("Failed to upload the avatar image; the webserver has no write permission to the '%directory' directory.", array("%directory" => variable_get("profile_avatar_path", "misc/avatars/")));
}
else if (!copy($image_file, variable_get("profile_avatar_path", "misc/avatars/").md5($user->uid).$extension)) {
$error = t("Failed to upload the avatar image; could not copy file '%filename' to directory '%directory'.", array("%filename" => $_FILES["edit"]["name"]["profile_avatar"], "%directory" => variable_get("profile_avatar_path", "misc/avatars/")));
}
else {
$edit["profile_avatar"] = $extension;
}
} }
return $error ? "$error<br />" : ""; return $error ? "$error<br />" : "";
} }
function profile_avatar_path($uid, $extension) {
return $extension ? variable_get("profile_avatar_path", "misc/avatars/") . md5($uid) . $extension : "";
}
function _profile_active_fields($mode) { function _profile_active_fields($mode) {
return variable_get("profile_". $mode ."_fields", array()); return variable_get("profile_". $mode ."_fields", array());
} }
......
...@@ -35,8 +35,7 @@ function system_help($section = "admin/help#system") { ...@@ -35,8 +35,7 @@ function system_help($section = "admin/help#system") {
// Start of system_help_cache // Start of system_help_cache
$output .= "<p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached.</p>"; $output .= "<p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached.</p>";
// End of system_help_cache // End of system_help_cache
$output = t($output, array("%base_url" => $base_url, "%cron-link" => "<a href=\"$base_url/cron.php\ $output = t($output, array("%base_url" => $base_url, "%cron-link" => "<a href=\"$base_url/cron.php\">$base_url/cron.php</a>", "%lynx" => "<a href=\"http://lynx.browser.org\">lynx</a>", "%wget" => "<a href=\"http://www.gnu.org/software/wget/wget.html\">wget</a>" ));
\">$base_url/cron.php</a>", "%lynx" => "<a href=\"http://lynx.browser.org\">lynx</a>", "%wget" => "<a href=\"http://www.gnu.org/software/wget/wget.html\">wget</a>" ));
break; break;
case 'admin/system/modules#description': case 'admin/system/modules#description':
$output = t("Configuration system that lets administrators modify the workings of the site."); $output = t("Configuration system that lets administrators modify the workings of the site.");
...@@ -56,6 +55,7 @@ function system_perm() { ...@@ -56,6 +55,7 @@ function system_perm() {
function system_link($type) { function system_link($type) {
if ($type == "system") { if ($type == "system") {
menu("system/files", t("file download"), "file_download", 0, MENU_HIDE);
if (user_access("administer site configuration")) { if (user_access("administer site configuration")) {
menu("admin/system", t("configuration"), "system_admin", 3); menu("admin/system", t("configuration"), "system_admin", 3);
...@@ -126,6 +126,17 @@ function system_view_general() { ...@@ -126,6 +126,17 @@ function system_view_general() {
$output .= form_group(t("Cache settings"), $group); $output .= form_group(t("Cache settings"), $group);
// file system:
if (!file_check_directory(variable_get('file_directory_path', 'files'))) {
$error['file_directory_path'] = theme('error', t('Directory does not exist, or is not writable.'));
}
if (!file_check_directory(variable_get('file_directory_temp', ini_get('upload_tmp_dir')))) {
$error['file_directory_temp'] = theme('error', t('Directory does not exist, or is not writable.'));
}
$group = form_textfield(t('File system path'), 'file_directory_path', variable_get('file_directory_path', 'files'), 70, 255, t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.') . $error['file_directory_path']);
$group .= form_textfield(t('Temporary directory'), 'file_directory_temp', variable_get('file_directory_temp', (PHP_OS == 'WINNT' ? 'c:\\windows\\temp' : '/tmp')), 70, 255, t('Location where files can be saved temporarily. This directory should not be accessible from the web.') . $error['file_directory_temp']);
$group .= form_radios(t('Download method'), 'file_downloads', variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC), array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using http directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are be transferred by Drupal.')), t('This setting can be changed at any time, however, all download URLs will change and there may be unexpected problems so it is not recommended.'));
$output .= form_group(t('File system'), $group);
// submission settings: // submission settings:
$rate = array(-10000 => t("Disabled"), 1 => t("Maximum 1 every second"), 5 => t("Maximum 1 every 5 seconds"), 15 => t("Maximum 1 every 15 seconds"), 30 => t("Maximum 1 every 30 seconds"), 60 => t("Maximum 1 every minute"), 300 => t("Maximum 1 every 5 minutes"), 900 => t("Maximum 1 every 15 minutes"), 1800 => t("Maximum 1 every 30 minutes"), 3600 => t("Maximum 1 every hour"), 21600 => t("Maximum 1 every 6 hours"), 43200 => t("Maximum 1 every 12 hours")); $rate = array(-10000 => t("Disabled"), 1 => t("Maximum 1 every second"), 5 => t("Maximum 1 every 5 seconds"), 15 => t("Maximum 1 every 15 seconds"), 30 => t("Maximum 1 every 30 seconds"), 60 => t("Maximum 1 every minute"), 300 => t("Maximum 1 every 5 minutes"), 900 => t("Maximum 1 every 15 minutes"), 1800 => t("Maximum 1 every 30 minutes"), 3600 => t("Maximum 1 every hour"), 21600 => t("Maximum 1 every 6 hours"), 43200 => t("Maximum 1 every 12 hours"));
...@@ -254,32 +265,12 @@ function system_view($type, $arg = "") { ...@@ -254,32 +265,12 @@ function system_view($type, $arg = "") {
return form($form); return form($form);
} }
function system_dirscan($dir, $mask, $nomask = array(".", "..", "CVS")) {
$files = array();
if (is_dir($dir) && $handle = opendir($dir)) {
while ($file = readdir($handle)) {
if (!in_array($file, $nomask)) {
if (is_dir("$dir/$file")) {
$files = array_merge($files, system_dirscan("$dir/$file", $mask, $nomask));
}
elseif (ereg($mask, $file)) {
$name = basename($file);
$files["$dir/$file"]->filename = "$dir/$file";
$files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.'));
}
}
}
closedir($handle);
}
return $files;
}
function system_listing($type, $directory, $required = array()) { function system_listing($type, $directory, $required = array()) {
// Make sure we set $type correctly // Make sure we set $type correctly
$type = $type != 'theme' ? "module" : "theme"; $type = $type != 'theme' ? "module" : "theme";
// Find files in the directory. // Find files in the directory.
$files = system_dirscan($directory, "\.$type$"); $files = file_scan_directory($directory, "\.$type$");
// Extract current files from database. // Extract current files from database.
$result = db_query("SELECT filename, type, status, throttle FROM {system} WHERE type = '%s'", $type); $result = db_query("SELECT filename, type, status, throttle FROM {system} WHERE type = '%s'", $type);
......
...@@ -35,8 +35,7 @@ function system_help($section = "admin/help#system") { ...@@ -35,8 +35,7 @@ function system_help($section = "admin/help#system") {
// Start of system_help_cache // Start of system_help_cache
$output .= "<p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached.</p>"; $output .= "<p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached.</p>";
// End of system_help_cache // End of system_help_cache
$output = t($output, array("%base_url" => $base_url, "%cron-link" => "<a href=\"$base_url/cron.php\ $output = t($output, array("%base_url" => $base_url, "%cron-link" => "<a href=\"$base_url/cron.php\">$base_url/cron.php</a>", "%lynx" => "<a href=\"http://lynx.browser.org\">lynx</a>", "%wget" => "<a href=\"http://www.gnu.org/software/wget/wget.html\">wget</a>" ));
\">$base_url/cron.php</a>", "%lynx" => "<a href=\"http://lynx.browser.org\">lynx</a>", "%wget" => "<a href=\"http://www.gnu.org/software/wget/wget.html\">wget</a>" ));
break; break;
case 'admin/system/modules#description': case 'admin/system/modules#description':
$output = t("Configuration system that lets administrators modify the workings of the site."); $output = t("Configuration system that lets administrators modify the workings of the site.");
...@@ -56,6 +55,7 @@ function system_perm() { ...@@ -56,6 +55,7 @@ function system_perm() {
function system_link($type) { function system_link($type) {
if ($type == "system") { if ($type == "system") {
menu("system/files", t("file download"), "file_download", 0, MENU_HIDE);
if (user_access("administer site configuration")) { if (user_access("administer site configuration")) {
menu("admin/system", t("configuration"), "system_admin", 3); menu("admin/system", t("configuration"), "system_admin", 3);
...@@ -126,6 +126,17 @@ function system_view_general() { ...@@ -126,6 +126,17 @@ function system_view_general() {
$output .= form_group(t("Cache settings"), $group); $output .= form_group(t("Cache settings"), $group);
// file system:
if (!file_check_directory(variable_get('file_directory_path', 'files'))) {
$error['file_directory_path'] = theme('error', t('Directory does not exist, or is not writable.'));
}
if (!file_check_directory(variable_get('file_directory_temp', ini_get('upload_tmp_dir')))) {
$error['file_directory_temp'] = theme('error', t('Directory does not exist, or is not writable.'));
}
$group = form_textfield(t('File system path'), 'file_directory_path', variable_get('file_directory_path', 'files'), 70, 255, t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.') . $error['file_directory_path']);
$group .= form_textfield(t('Temporary directory'), 'file_directory_temp', variable_get('file_directory_temp', (PHP_OS == 'WINNT' ? 'c:\\windows\\temp' : '/tmp')), 70, 255, t('Location where files can be saved temporarily. This directory should not be accessible from the web.') . $error['file_directory_temp']);
$group .= form_radios(t('Download method'), 'file_downloads', variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC), array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using http directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are be transferred by Drupal.')), t('This setting can be changed at any time, however, all download URLs will change and there may be unexpected problems so it is not recommended.'));
$output .= form_group(t('File system'), $group);
// submission settings: // submission settings:
$rate = array(-10000 => t("Disabled"), 1 => t("Maximum 1 every second"), 5 => t("Maximum 1 every 5 seconds"), 15 => t("Maximum 1 every 15 seconds"), 30 => t("Maximum 1 every 30 seconds"), 60 => t("Maximum 1 every minute"), 300 => t("Maximum 1 every 5 minutes"), 900 => t("Maximum 1 every 15 minutes"), 1800 => t("Maximum 1 every 30 minutes"), 3600 => t("Maximum 1 every hour"), 21600 => t("Maximum 1 every 6 hours"), 43200 => t("Maximum 1 every 12 hours")); $rate = array(-10000 => t("Disabled"), 1 => t("Maximum 1 every second"), 5 => t("Maximum 1 every 5 seconds"), 15 => t("Maximum 1 every 15 seconds"), 30 => t("Maximum 1 every 30 seconds"), 60 => t("Maximum 1 every minute"), 300 => t("Maximum 1 every 5 minutes"), 900 => t("Maximum 1 every 15 minutes"), 1800 => t("Maximum 1 every 30 minutes"), 3600 => t("Maximum 1 every hour"), 21600 => t("Maximum 1 every 6 hours"), 43200 => t("Maximum 1 every 12 hours"));
...@@ -254,32 +265,12 @@ function system_view($type, $arg = "") { ...@@ -254,32 +265,12 @@ function system_view($type, $arg = "") {
return form($form); return form($form);
} }
function system_dirscan($dir, $mask, $nomask = array(".", "..", "CVS")) {
$files = array();
if (is_dir($dir) && $handle = opendir($dir)) {
while ($file = readdir($handle)) {
if (!in_array($file, $nomask)) {
if (is_dir("$dir/$file")) {
$files = array_merge($files, system_dirscan("$dir/$file", $mask, $nomask));
}
elseif (ereg($mask, $file)) {
$name = basename($file);
$files["$dir/$file"]->filename = "$dir/$file";
$files["$dir/$file"]->name = substr($name, 0, strrpos($name, '.'));
}
}
}
closedir($handle);
}
return $files;
}
function system_listing($type, $directory, $required = array()) { function system_listing($type, $directory, $required = array()) {
// Make sure we set $type correctly // Make sure we set $type correctly
$type = $type != 'theme' ? "module" : "theme"; $type = $type != 'theme' ? "module" : "theme";
// Find files in the directory. // Find files in the directory.
$files = system_dirscan($directory, "\.$type$"); $files = file_scan_directory($directory, "\.$type$");
// Extract current files from database. // Extract current files from database.
$result = db_query("SELECT filename, type, status, throttle FROM {system} WHERE type = '%s'", $type); $result = db_query("SELECT filename, type, status, throttle FROM {system} WHERE type = '%s'", $type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment