Hi!
With this Modification can you allow User to edit their own images and thumbnails.
1.) search in admin/setting.php:
show_setting_row("user_edit_image", "radio");
insert below:
show_setting_row("user_edit_imagethumb", "radio");
2.) search in lang/your lang/admin.php:
(deutsch)
$setting['user_edit_image'] = "Dürfen User Ihre eigenen Bilder bearbeiten";
and replace:
$setting['user_edit_image'] = "Dürfen User Ihre eigenen Bildbeschreibungen und Schlüsselwörter bearbeiten";
$setting['user_edit_imagethumb'] = "Dürfen User Ihre eigenen Bilder bearbeiten";
(english)
$setting['user_edit_image'] = "Allow users to edit their own image descriptions and keywords";
$setting['user_edit_imagethumb'] = "Allow users to edit their own images";
3.) search member.php:
if ($action == "updateimage") {
/*
*
* all content
*
*/
$sendprocess = 1;
}
}
and replace:
if ($action == "updateimage") {
$image_id = (isset($HTTP_POST_VARS['image_id'])) ? intval($HTTP_POST_VARS['image_id']) : intval($HTTP_GET_VARS['image_id']);
if (!$image_id || ($config['user_edit_image'] != 1 && $user_info['user_level'] != ADMIN)) {
show_error_page($lang['no_permission']);
}
$sql = "SELECT image_id, cat_id, user_id, image_name
FROM ".IMAGES_TABLE."
WHERE image_id = $image_id";
$image_row = $site_db->query_firstrow($sql);
if (!$image_row || $image_row['user_id'] <= USER_AWAITING || ($user_info['user_id'] != $image_row['user_id'] && $user_info['user_level'] != ADMIN)) {
show_error_page($lang['no_permission']);
exit;
}
$txt_clickstream = get_category_path($image_row['cat_id'], 1).$config['category_separator']."<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id)."\" class=\"clickstream\">".format_text($image_row['image_name'], 2)."</a>".$config['category_separator'];
$txt_clickstream .= $lang['image_edit'];
$error = 0;
$image_name = un_htmlspecialchars(trim($HTTP_POST_VARS['image_name']));
$image_description = un_htmlspecialchars(trim($HTTP_POST_VARS['image_description']));
$image_keywords = un_htmlspecialchars(trim($HTTP_POST_VARS['image_keywords']));
$image_keywords = preg_replace("/[\n\r]/is", ",", $image_keywords);
$image_keywords_arr = explode(',', $image_keywords);
array_walk($image_keywords_arr, 'trim_value');
$image_keywords = implode(',', array_unique(array_filter($image_keywords_arr)));
if ($config['user_edit_imagethumb']){
$remote_media_file = format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['remote_media_file'])));
$remote_thumb_file = format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['remote_thumb_file'])));
$old_file_name = un_htmlspecialchars(trim($HTTP_POST_VARS['old_file_name']));
$old_thumb_file_name = un_htmlspecialchars(trim($HTTP_POST_VARS['old_thumb_file_name']));
$image_download_url = (isset($HTTP_POST_VARS['image_download_url'])) ? format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['image_download_url']))) : "";
$delete_thumb_file = (isset($HTTP_POST_VARS['delete_thumb_file']) && $HTTP_POST_VARS['delete_thumb_file'] == 1) ? 1 : 0;
$cat_id = intval($HTTP_POST_VARS['cat_id']);
$old_cat_id = intval($HTTP_POST_VARS['old_cat_id']);
$direct_upload = (check_permission("auth_directupload", $cat_id)) ? 1 : 0;
$upload_cat = ($direct_upload) ? $cat_id : 0;
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
show_error_page($lang['no_permission']);
exit;
}
}
if ($image_name == "") {
$error = 1;
$field_error = preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "", $lang['image_name']), $lang['field_required']);
$msg .= (($msg != "") ? "<br />" : "").$field_error;
}
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error = 1;
$field_error = preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "", $val[0]), $lang['field_required']);
$msg .= (($msg != "") ? "<br />" : "").$field_error;
}
}
}
if (!$error) {
$uploaderror = 0;
if ($config['user_edit_imagethumb']){
$uploaderror = 0;
// Start Upload
include(ROOT_PATH.'includes/upload.php');
$site_upload = new Upload();
if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
unset($HTTP_POST_VARS['remote_media_file']);
@rename(MEDIA_PATH."/".$old_cat_id."/".$old_file_name, MEDIA_PATH."/".$old_cat_id."/".$old_file_name.".bak");
$new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
if (!$new_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
@rename(MEDIA_PATH."/".$old_cat_id."/".$old_file_name.".bak", MEDIA_PATH."/".$old_cat_id."/".$old_file_name);
$uploaderror = 1;
}
else {
unlink(MEDIA_PATH."/".$old_cat_id."/".$old_file_name.".bak");
}
}
elseif ((empty($HTTP_POST_FILES['media_file']['tmp_name']) || $HTTP_POST_FILES['media_file']['tmp_name'] == "none") && $remote_media_file != "" && (check_remote_media($remote_media_file) || check_local_media($remote_media_file))) {
$new_name = $remote_media_file;
if (file_exists(MEDIA_PATH."/".$old_cat_id."/".$old_file_name) && is_file(MEDIA_PATH."/".$old_cat_id."/".$old_file_name)) {
unlink(MEDIA_PATH."/".$old_cat_id."/".$old_file_name);
}
}
else {
if ($cat_id != $old_cat_id && !empty($old_file_name)) {
$new_name = copy_media($old_file_name, $old_cat_id, $cat_id);
}
else {
$new_name = $old_file_name;
}
}
if ($delete_thumb_file == 1) {
if (!empty($old_thumb_file_name) && file_exists(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name)) {
unlink(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name);
}
$new_thumb_name = "";
unset($HTTP_POST_VARS['remote_thumb_file']);
}
elseif (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$error) {
unset($HTTP_POST_VARS['remote_thumb_file']);
@rename(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name, THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name.".bak");
$new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $cat_id, get_basefile($new_name));
if (!$new_thumb_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
@rename(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name.".bak", THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name);
@unlink(MEDIA_PATH."/".$old_cat_id."/".$new_name);
$uploaderror = 1;
}
}
elseif ((empty($HTTP_POST_FILES['thumb_file']['tmp_name']) || $HTTP_POST_FILES['thumb_file']['tmp_name'] == "none") && $remote_thumb_file != "" && (check_remote_thumb($remote_thumb_file) || check_local_thumb($remote_thumb_file))) {
$new_thumb_name = $remote_thumb_file;
if (file_exists(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name) && is_file(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name)) {
unlink(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name);
}
}
else {
if ($cat_id != $old_cat_id && !empty($old_thumb_file_name)) {
$new_thumb_name = copy_thumbnail($new_name, $old_thumb_file_name, $old_cat_id, $cat_id);
}
else {
$new_thumb_name = $old_thumb_file_name;
}
}
if ($config['auto_thumbnail'] == 1 && !empty($new_name) && !$uploaderror && !$new_thumb_name && ((empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none"))) {
if ($direct_upload) {
if (is_remote($new_name)) {
$src = $new_name;
$thumb = create_unique_filename(THUMB_PATH."/".$cat_id, filterFileName($new_name));
} else {
$src = MEDIA_PATH."/".$cat_id."/".$new_name;
$thumb = $new_name;
}
$dest = THUMB_PATH."/".$cat_id."/".$thumb;
}
else {
if (is_remote($new_name)) {
$src = $new_name;
$thumb = create_unique_filename(THUMB_TEMP_PATH, filterFileName($new_name));
} else {
$src = MEDIA_TEMP_PATH."/".$new_name;
$thumb = $new_name;
}
$dest = THUMB_TEMP_PATH."/".$thumb;
}
$do_create = 0;
if ($image_info = @getimagesize($src)) {
if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
$do_create = 1;
}
}
if ($do_create) {
require(ROOT_PATH.'includes/image_utils.php');
$convert_options = init_convert_options();
if (!$convert_options['convert_error']) {
$dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
$resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
$quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;
if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
$new_thumb_name = $thumb;
}
}
}
}
}
} //error
if (!$uploaderror) {
$additional_sql = "";
if (isset($HTTP_POST_VARS['image_allow_comments'])) {
$additional_sql .= ", image_allow_comments = ".intval($HTTP_POST_VARS['image_allow_comments']);
}
if (!empty($additional_image_fields)) {
$table_fields = $site_db->get_table_fields(IMAGES_TABLE);
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && isset($table_fields[$key])) {
$additional_sql .= ", $key = '".un_htmlspecialchars(trim($HTTP_POST_VARS[$key]))."'";
}
}
}
$sql = ($config['user_edit_imagethumb']) ? ", image_media_file = '$new_name', image_thumb_file = '$new_thumb_name', image_download_url = '$image_download_url'":"";
$sql = "UPDATE ".IMAGES_TABLE."
SET image_name = '$image_name', image_description = '$image_description', image_keywords = '$image_keywords' $sql ".$additional_sql."
WHERE image_id = $image_id";
$result = $site_db->query($sql);
@unlink(MEDIA_PATH."/".$old_cat_id."/".$old_file_name.".bak");
@unlink(THUMB_PATH."/".$old_cat_id."/".$old_thumb_file_name.".bak");
if ($result) {
include(ROOT_PATH.'includes/search_utils.php');
$search_words = array();
foreach ($search_match_fields as $image_column => $match_column) {
if (isset($HTTP_POST_VARS[$image_column])) {
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
}
}
remove_searchwords($image_id);
add_searchwords($image_id, $search_words);
$msg = $lang['image_edit_success'];
$action = "editimage";
}
else {
$msg = $lang['image_edit_error'];
}
}
else {
$action = "editimage";
$sendprocess = 1;
}
}
3.1) search in section "if ($action == "editimage") {"
$sql = "SELECT image_id, cat_id, user_id, image_name, image_description, image_keywords, image_allow_comments".$additional_sql."
and replace:
$sql = "SELECT image_id, cat_id, user_id, image_name, image_description, image_keywords, image_allow_comments, image_media_file, image_thumb_file".$additional_sql."
3.2) search:
$site_template->register_vars(array(
"image_id" => $image_id,
and replace:
if($config['user_edit_imagethumb']){
show_image($image_row, $mode, 0, 1);
$old_file_name = $image_row['image_media_file'];
$old_thumb_file_name = $image_row['image_thumb_file'];
$site_template->register_vars(array(
"old_file_name" => format_text($old_file_name, 2),
"old_thumb_file_name" => format_text($old_thumb_file_name, 2),
"thumbnail_preview" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'],0,0),
"lang_image_delete" => $lang['image_delete'],
"lang_media_file" => $lang['media_file'],
"lang_thumb_file" => $lang['thumb_file'],
"lang_allowed_file_types" => $lang['allowed_mediatypes_desc'],
"allowed_media_types" => str_replace(",",", ",$config['allowed_mediatypes']),
"allowed_thumb_types" => "jpg, gif, png",
"lang_max_filesize" => $lang['max_filesize'],
"lang_max_imagewidth" => $lang['max_imagewidth'],
"lang_max_imageheight" => $lang['max_imageheight']
));
}
$site_template->register_vars(array(
"edit_imagethumb" => ($config['user_edit_imagethumb']) ? 1:0,
"image_id" => $image_id,
4.) search in your template/member_editimage.html:
<form method="post" action="{url_member}" onsubmit="uploadbutton.disabled=true;">
<input type="hidden" name="action" value="updateimage" />
<input type="hidden" name="image_id" value="{image_id}" />
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td valign="top" class="head1">
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr>
<td colspan="2" valign="top" class="head1">{lang_edit_image}</td>
</tr>
and replace:
<form method="post" action="{url_member}" enctype="multipart/form-data" onsubmit="uploadbutton.disabled=true;">
<input type="hidden" name="action" value="updateimage" />
<input type="hidden" name="image_id" value="{image_id}" />
{if edit_imagethumb}
<input type="hidden" name="old_file_name" value="{old_file_name}" />
<input type="hidden" name="old_thumb_file_name" value="{old_thumb_file_name}" />
<input type="hidden" name="cat_id" value="{cat_id}" />
<input type="hidden" name="old_cat_id" value="{cat_id}" />
{endif edit_imagethumb}
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td valign="top" class="head1">
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr>
<td colspan="2" valign="top" class="head1">{lang_edit_image}</td>
</tr>
{if edit_imagethumb}
<tr>
<td class="row2" valign="top"><b>{lang_image_name}</b>({old_file_name})</td>
<td class="row2">{image}</td>
</tr>
<tr>
<td class="row2"><b>Upload:</b></td>
<td class="row2"><input type="file" name="media_file" class="input"></td>
</tr>
<tr>
<td class="row2"><b>URL:</b></td>
<td class="row2"><input type="text" name="remote_media_file" size="30" value="{remote_media_file}" class="input" /><br />
<span class="smalltext"><b>{lang_allowed_file_types}</b> {allowed_media_types}</span>
</td>
</tr>
<tr>
<td class="row1" valign="top"><b>{lang_thumb_file}</b><br>({old_thumb_file_name})</td>
<td class="row1" align="left">{thumbnail_preview} {lang_image_delete}<input align="left" type="checkbox" name="delete_thumb_file" value="1"></td>
</tr>
<tr>
<td class="row1"><b>Upload:</b></td>
<td class="row1"><input type="file" name="thumb_file" class="input"></td>
</tr>
<tr>
<td class="row1"><b>URL:</b></td>
<td class="row1">
<input type="text" name="remote_thumb_file" size="30" value="{remote_thumb_file}" class="input" /><br />
<span class="smalltext"><b>{lang_allowed_file_types}</b> {allowed_thumb_types}</span>
</td>
</tr>
{endif edit_imagethumb}
In "ACP/General/Setting/Session and User Settings":
Allow users to edit their own images : set to "ON"
Allow users to edit their own image descriptions and keywords : set to "ON"
mfg Andi