Original post : TheOracle (thanks to him)
Original idea & Final debug : me
With this mod, 4images admins can choose to disable download and e-card until the user rates the picture.
works with lightbox too.
>> 04 files to edit from 4images root:
[change]
lightbox.php[change]
includes/functions.php[change]
lang/<your_language>/admin.php[change]
admin/settings.php >> 01 new file to download (db update):
install_rvotes.phpFirst, backup your files.------ Installation ------ STEP 1:open
lightbox.phpfind
if (function_exists("gzcompress") && function_exists("crc32")) {
if (!empty($user_info['lightbox_image_ids'])) {
$download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
}
else {
$download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
}
}
replace by:
if (function_exists("gzcompress") && function_exists("crc32")) {
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
$one_not_rated = "";
$rated_images = array();
// search all pics rated by user
$sql = "SELECT image_id
FROM ".VOTED_TABLE."
WHERE user_id =".$user_info['user_id'];
$result = $site_db->query($sql);
while($row = $site_db->fetch_array($result)) {
$rated_images[] = $row['image_id']; // put the result in an array
}
$array_lightbox_image_ids = explode(" ", $user_info['lightbox_image_ids']); // put lightboxed pics in an array
foreach ($array_lightbox_image_ids as $element) {
if (!in_array ($element, $rated_images)) { // if current lightboxed pics in not found in rated pics by user
$one_not_rated = 1;
}
}
if (!empty($user_info['lightbox_image_ids']) && !$one_not_rated) { // !$one_not_rated : means all pics in lightbox have been rated
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
$download_button = "<a href=\"".$site_sess->url(ROOT_PATH."download.php?action=lightbox")."\"><img src=\"".get_gallery_image("download_zip.gif")."\" border=\"0\" alt=\"\" /></a>";
}
else {
$download_button = "<img src=\"".get_gallery_image("download_zip_off.gif")."\" border=\"0\" alt=\"\" />";
}
}
STEP 2.1:open
includes/functions.phpfind:
if (!check_permission("auth_download", $image_row['cat_id'])) {
replace by:
if (!check_permission("auth_download", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use
STEP 2.2:find:
if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) {
replace by:
if (!check_permission("auth_sendpostcard", $image_row['cat_id']) || ($user_info['user_level'] != ADMIN && !check_user_rate($image_row['image_id'],$image_row['cat_id']) && $config['details_vote_download_restriction_options'] == 1)) { //---[Mod] Restrict users to use
STEP 2.3:find (2 times in this file):
"lang_new" => $lang['new'],
add after (2 times in this file):
"lang_not_voted" => $lang['not_voted'], //---[ [Mod] Restrict users to use e-card and download if they have not voted first]
STEP 2.4:find
"image_votes" => $image_row['image_votes'],
add after:
"image_rated" => check_user_rate($image_row['image_id'], $image_row['cat_id']), //---[ [Mod] Restrict users to use e-card and download if they have not voted first]
STEP 2.5:find:
function rate_form($id, $rate_suffix = "", $rating = ""){
add before:
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function check_user_rate($id, $cat_id) {
global $user_info, $site_db;
if (check_permission("auth_vote", $cat_id)) {
$sql = "SELECT vote
FROM ".VOTED_TABLE."
WHERE image_id =".$id." AND user_id =".$user_info['user_id'];
$row = $site_db->query_firstrow($sql);
}
return (isset($row['vote']))? 1 : 0 ;
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
STEP 3open
lang/<your_language>/admin.phpFind last section that starts with
$setting_group[##] =
Where
## is a number. Add one (1) to that number and remember it: you will need in STEP 4.2.
(if you got a fresh 4images installation, that number is number 7, you should remember number 8 (7+1=8))
At the end,
before closing
?> insert:
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
/*-- Setting-Group ## --*/
$setting_group[##]="Rating before download and sending e-card";
$setting['details_vote_download_restriction_options'] = "Activate restrictions for download and e-card from the details page ?<br /><span class=\"smalltext\"><b>The users must rate the picture</b> to download it or send it by e-card (Note: The administrator account will not be affected by this restriction.)</span>";
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace
## with the right number from your code.
STEP 4.1:open
admin/settings.phpfind:
// end of functions
and add before:
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
function show_details_vote_download_restriction_options($setting_name, $setting_value) {
global $details_vote_download_restriction_optionlist;
echo "<select name=\"setting_item[".$setting_name."]\">";
foreach ($details_vote_download_restriction_optionlist as $key => $val) {
echo "<input type=\"radio\" name=\"setting_item[".$setting_name."]\" value=\"$key\"";
if ($setting_value == $key) {
echo " checked=\"checked\"";
}
echo "> ".$val."<br />";
}
echo "</select>";
}
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
STEP 4.2:find:
show_form_footer($lang['save_changes'], "", 2);
and add
before:
//-------------------------------------------[ [Mod] Restrict users to use e-card and download if they have not voted first]
show_table_separator($setting_group[##], 2, "#setting_group_##");
show_setting_row("details_vote_download_restriction_options", "radio");
//-------------------------------------------[/[Mod] Restrict users to use e-card and download if they have not voted first]
Replace
## with the right number from your code, the same number you put in STEP 3.
STEP 5.1Download, extract, save and execute the following/attached file in your 4images root to make a database update.
Note with this installer you can also remove the database modifications for this MOD
------ End of Installation ------ Now, go to your ACP general setting to enable/desable the restriction.