Author Topic: [MOD] - Restrict users to use e-card and download if they have not voted first.  (Read 64789 times)

0 Members and 1 Guest are viewing this topic.

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Quote
well, I will publish this MOD again but for the moment I do not have time yet to reconstitute it.

Can you write the code from this Mod, please???

Or everyone???
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
it would be really cool if a rmoderator could move this message at the beginning of the topic  8)
because it's a Re-publishing  :)

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.php


First, backup your files.

------ Installation ------


STEP 1:

open lightbox.php
find
Code: [Select]
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:
Code: [Select]
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.php
find:
Code: [Select]
if (!check_permission("auth_download", $image_row['cat_id'])) {

replace by:
Code: [Select]
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:
Code: [Select]
if (!check_permission("auth_sendpostcard", $image_row['cat_id'])) {

replace by:
Code: [Select]
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):
Code: [Select]
"lang_new" => $lang['new'],

add after (2 times in this file):
Code: [Select]
"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
Code: [Select]
"image_votes" => $image_row['image_votes'],

add after:
Code: [Select]
"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:
Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){

add before:
Code: [Select]
//-------------------------------------------[ [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 3
open lang/<your_language>/admin.php

Find last section that starts with
Quote
$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:
Code: [Select]
//-------------------------------------------[ [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.php

find:
Code: [Select]
// end of functions
and add before:
Code: [Select]
//-------------------------------------------[ [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:
Code: [Select]
  show_form_footer($lang['save_changes'], "", 2);

and add before:
Code: [Select]
//-------------------------------------------[ [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.1

Download, 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  :wink:

------ End of Installation ------

Now, go to your ACP general setting to enable/desable the restriction. 8)
ch€ri{Bi}²


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
it would be really cool if a rmoderator could move this message at the beginning of the topic  8)
because it's a Re-publishing  :)
Done
Thank you for posting it.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Hello,

thanks for republishing this mod. I have one problem. i can´t find

Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){
in my funkctions.php. I have the Version 1.7

Can anyone help me?
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Hello,

thanks for republishing this mod. I have one problem. i can´t find

Code: [Select]
function rate_form($id, $rate_suffix = "", $rating = ""){

it does not matter the place where you puts the code  :wink:
the text to find was an example   :arrow:  in order to prevent that the modification affects an existing function !
write the code at the end of your functions.php file, before the ?>.
ch€ri{Bi}²


Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Thanks, the Mod is working fine....
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Hi,

is there a way User must give a vote for the pic before he can put it into the lightbox???
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
yes it's possible but... need to add some other conditions...

 :idea: let me explain how this mod works in lightbox :

all the users are able to send picture in lightbox but they can not download  the (zipped) pictures  if there is at least one picture still not rated ...
in others words, a user can use lightbox as he want... but the only way to download all the pictures in lightbox is to rate all the pictures present in the lightbox  :wink:

and this is why i asked for this : if a user forgot to rate a picture, he can do it directly on thumbs in lightbox  8)
ch€ri{Bi}²


Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Hi,

is there a way to disable the function for the own images????
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Hi,

is there a way to disable the function for the own images????
not with this method...TheOracle introduced simple download button hiding method, yet, if you type manualy in the address bar the url to download lightbox, you'll be able to avoid this restrictions. If this restrctions were made directly in download.php intead, then it would be possible modify it to disable restrictions for own images...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
nice MOD,

Did it, but now i am not able to save the settings in the ACP (meaning, its always in "no" and cannot activate it)
i had skiped the 1st part (the lightbox.php) cause i have a previous mod (multiple lightboxes) and don't care about the donwload, just the "send ecard" function...


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Probably missed step 5.1
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
:( i had done this step, did it again, no change, still i cannot save the changes

edit: i have skiped Step 1, is it the reason? (i do not want this funtion on download button) - also have the multi lightbox mod

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Its a bug in Step 4.1
The code should be:
Code: [Select]
//-------------------------------------------[ [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, $config;
 $setting_value = $config[$setting_name];
 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]
Note, this is only a visual bug, the settings are being updated just fine ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
 :cry: still no change (practically and visually)