function content_public_files_form
Search API
7.x content.module | content_public_files_form() |
6.x content.module | content_public_files_form() |
This screen lets the user upload/manage/delete "public files" stored at custom/files/content_uploads/public_uploads/
1 string reference to 'content_public_files_form'
- content_menu in modules/
content/ content.module
File
- modules/
content/ content.module, line 297
Code
function content_public_files_form() {
fp_add_css(fp_get_module_path('content') . '/css/content.css');
$form = array();
fp_set_title('');
// Did we receive a request to delete a file?
if (isset($_GET ['del']) && is_numeric($_GET ['del'])) {
$del_fid = intval($_GET ['del']);
$del_file = content_get_uploaded_file($del_fid);
// Make sure the file is a "public" file.
if (intval($del_file ['attributes']) === CONTENT_PUBLIC_FILE) {
// Double-check the user has access to delete
if (user_has_permission('admin_public_files')) {
// Okay, unlink the file.
$temp = unlink(fp_get_files_path() . '/content_uploads/public_uploads/' . $del_file ['filename']);
if ($temp == FALSE) {
fp_add_message(t("Unable to delete file. Possible server permissions issue, or file not found."), 'error');
}
else {
// We did delete from file system, so delete from content_files table as well.
db_query("DELETE FROM content_files WHERE fid = ?", array($del_fid));
fp_add_message(t("File deleted successfully."));
}
}
} // if public file
// Use fp_goto() to avoid issue with user hitting "refresh"
fp_goto("admin-tools/content/files");
} // trying to delete file
$form ["#attributes"] = array("enctype" => 'multipart/form-data'); // allow the form itself to submit files.
$form ['mark_top'] = array(
'value' => '<p>' . t("This form allows you to upload files which are publicly accessible (without needing to log in) through the web.
For example, you may wish to upload image files, css, etc, for use in other settings.
<br><br>
<strong>Note:</strong> These files will not be encrypted, and will be publicly available. Do not upload sensitive
information, like student records or any personally-identifying details.") . "</p><hr>",
);
$form ['upload_file'] = array(
'type' => 'file',
'label' => t("Upload file:"),
'description' => t("Allowed file extensions: %ext", array('%ext' => strtolower(variable_get("public_files_allowed_extensions", "css, txt, pdf, doc, docx, csv, xls, xlsx, ppt, pptx, rtf, odt, jpg, jpeg, png, gif, zip, 7z")))),
);
$overwrite_val = FALSE;
if (isset($_SESSION ['public_file_form_overwrite_val'])) {
$overwrite_val = (bool) $_SESSION ['public_file_form_overwrite_val'];
}
$form ['overwrite'] = array(
'type' => 'checkbox',
'label' => t('Keep original filename and overwrite existing file by the same name?'),
'value' => $overwrite_val,
'prefix' => t("<strong>Important:</strong> By default, files are given randomized names when uploaded, so as not to overwrite an existing file with the same name.
<br>If you would prefer to overwrite files with the same name, check the box below:"),
);
$form ['upload_btn'] = array(
'type' => 'submit',
'value' => t("Upload"),
);
$form ['mark_below_upload'] = array(
'value' => "<hr>",
);
///////////////////////////////////////////////////////////
$html = "";
$table_headers = array();
$table_headers [] = array("label" => "Actions");
$table_headers [] = array("label" => "FID", "field" => "fid");
$table_headers [] = array("label" => "Filename", "field" => "original_filename");
$table_headers [] = array("label" => "Link");
$table_headers [] = array("label" => "Uploaded", "field" => "posted");
// Set our initial sort, if none is already set.
theme_table_header_sortable_set_initial_sort("posted", 'DESC');
$html .= "<table class='public-files-table' cellspacing='0' cellpadding='4'>";
// Draw our our table headers, with links....
$html .= theme_table_header_sortable($table_headers);
// Get our order by clause based on selected table header, if any.
$order_by = theme_table_header_sortable_order_by($table_headers);
$res = pager_query("SELECT * FROM content_files WHERE `attributes` = ?
$order_by", array(CONTENT_PUBLIC_FILE), 10, 0);
while ($cur = db_fetch_object($res)) {
$pol = (@$pol == "even") ? "odd" : "even";
$posted = format_date(convert_time($cur->posted), "short");
$abs = base_url() . "/custom/files/content_uploads/public_uploads/$cur->filename";
$rel = base_path() . "/custom/files/content_uploads/public_uploads/$cur->filename";
$absolute_link = "<a href='$abs' title='Link to file' class='abs-link' target='_blank'><i class='fa fa-link'></i></a>";
$del_link = fp_get_js_confirm_link("Are you sure you want to delete this file?\\n\\nThis action cannot be undone.", "window.location=\"" . fp_url("admin-tools/content/files", "del=$cur->fid") . "\";", "<i class='fa fa-remove' title='" . t("Delete?") . "'></i>", "delete-link");
$html .= "<tr class='row-$pol'>
<td valign='top'>$del_link</td>
<td valign='top'>$cur->fid</td>
<td valign='top'>$cur->original_filename</td>
<td valign='top'>$absolute_link</td>
<td valign='top'>$posted</td>
</tr>
";
} // while
$html .= "</table>";
$html .= theme_pager();
$form ['mark_files_table'] = array(
'value' => $html,
);
return $form;
}