--------- [ Introduction ] ------------ This mod will show "Terms and Conditions" message instead of image on the image details page untill the visitor accept them.
- Administrator can set terms per category and per individual image. Per image settings have higher priority then per category, meaning if both category and image set terms, only image terms will be used, and accepting image terms will not affect category terms.
- Administrator can set who must accept terms: only guests or everyone
- Cookies are supported
U can see it in action:
here terms are set for the image only
and
here terms are set for category (members only)
--------- [ Installation ] ------------ NOTE:
This mod require
[MOD] Dropdown options for custom database fields mod to be installed.
Changed files:
global.php
details.php
categories.php
includes/functions.php
includes/constants.php
includes/db_field_definitions.php
lang/<yourlanguage>/main.php
admin/categories.php
templates/<yourtemplate>/details.html
templates/<yourtemplate>/categories.html New template:
templates/<yourtemplate>/terms.html
Step 1 Open
global.phpFor 4images v1.7Find:
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images
replace with:
$sql = "SELECT c.cat_id, c.cat_name, c.cat_description, c.cat_parent_id, c.cat_hits, c.cat_order, c.auth_viewcat, c.auth_viewimage, c.auth_download, c.auth_upload, c.auth_directupload, c.auth_vote, c.auth_sendpostcard, c.auth_readcomment, c.auth_postcomment, COUNT(i.image_id) AS new_images, c.terms, c.terms_msg
(there only added
, c.terms, c.terms_msg at the end of that line)
For 4images v1.7.1Find:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace with:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, terms, terms_msg
(there only added
, terms, terms_msg at the end of that line)
Step 2 Open
details.php Find:
show_image($image_row, $mode, 0, 1);
Insert
above:
//-----------------------------------------------------
//--- Image Terms -------------------------------------
//-----------------------------------------------------
if ($action == "terms") {
terms_add($cat_id, (($image_row['terms']) ? $image_id : ""));
}
$terms = 0;
if (!terms_check($cat_id, (($image_row['terms']) ? $image_row : "")) && $action != "terms")
{
if ($image_row['terms'])
{
$terms_agreement = ($lang['terms_agreement'][$image_row['terms_msg']]) ? $lang['terms_agreement'][$image_row['terms_msg']] : $lang['terms_agreement'][0];
}
else
{
$terms_agreement = ($lang['terms_agreement'][$cat_cache[$cat_id]['terms_msg']]) ? $lang['terms_agreement'][$cat_cache[$cat_id]['terms_msg']] : $lang['terms_agreement'][0];
}
$site_template->register_vars(array(
"url_home" => $site_sess->url(ROOT_PATH."index.php"),
"lang_terms" => $lang['terms'],
"mode" => $mode,
"lang_terms_agreement" => $terms_agreement,
"lang_agree" => $lang['agree'],
"lang_agree_not" => $lang['agree_not']
));
$terms = $site_template->parse_template("terms");
}
$site_template->register_vars(array(
"show_terms" => $terms,
"no_terms" => ($terms) ? 0 : 1
));
//--- End Image Terms -------------------------------------
Step 3 Open
includes/functions.php At the end,
above closing
?> insert:
//-----------------------------------------------------
//--- Image Terms -------------------------------------
//-----------------------------------------------------
function terms_check($id, $image = array())
{
global $HTTP_COOKIE_VARS, $site_sess, $user_info, $cat_cache;
if ($user_info['user_level'] == ADMIN || (!empty($image) && (($image['terms'] == 1 && $user_info['user_level'] > GUEST) || ($image['terms'] == 2 && $user_info['user_level'] > USER))) || (empty($image) && empty($cat_cache[$id]['terms']) || ($cat_cache[$id]['terms'] && (($cat_cache[$id]['terms'] == 1 && $user_info['user_level'] > GUEST) || ($cat_cache[$id]['terms'] == 2 && $user_info['user_level'] > USER)))))
{
return true;
}
$name = "terms";
if (!empty($image))
{
$id = $image['image_id'];
$name .= "img";
}
if (TERMS_COOKIES)
{
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
$cookie_name .= $name.$user_info['user_id'];
$split_list = isset($HTTP_COOKIE_VARS[$cookie_name]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name])) : array();
$terms = in_array($id, $split_list);
}
if (!isset($site_sess->session_info[$name]))
{
$site_sess->session_info[$name] = $site_sess->get_session_var($name);
}
$split_list = array();
if (!empty($site_sess->session_info[$name]))
{
$split_list = explode(" ", $site_sess->session_info[$name]);
}
return ((TERMS_COOKIES && $terms) || in_array($id, $split_list));
}
function terms_add($id, $image = "")
{
global $HTTP_COOKIE_VARS, $site_sess, $user_info, $cat_cache;
$name = "terms";
if ($image)
{
$id = $image;
$name .= "img";
}
if (TERMS_COOKIES)
{
$cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
$cookie_name .= $name.$user_info['user_id'];
$split_list = isset($HTTP_COOKIE_VARS[$cookie_name]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name])) : array();
if (!in_array($id, $split_list)) {
$cookie_termsid[] = $id;
setcookie($cookie_name, serialize($cookie_termsid), time() + TERMS_COOKIES_EXPIRE, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
}
}
if (!isset($site_sess->session_info[$name]))
{
$site_sess->session_info[$name] = $site_sess->get_session_var($name);
}
$split_list = array();
if (!empty($site_sess->session_info[$name]))
{
$split_list = explode(" ", $site_sess->session_info[$name]);
}
if (!in_array($id, $split_list))
{
$site_sess->session_info[$name] .= " ".$id;
$site_sess->session_info[$name] = trim($site_sess->session_info[$name]);
$site_sess->set_session_var($name, $site_sess->session_info[$name]);
}
}
//--- End Image Terms -------------------------------------
Step 4 Open
includes/constants.php At the end,
above closing
?> insert:
// Terms and conditions
define('TERMS_COOKIES', 0); //use cookies? if not only session will be used (every time browser is closed a new session will be started)
define('TERMS_COOKIES_EXPIRE', 60*60*24*1); //60 seconds * 60 minutes * 24 hours * 1 day (read the comments )
Step 5Open
includes/db_field_definitions.php At the end,
above ?> insert:
$additional_image_fields['terms'] = array($lang['terms'], "dropdown", 0, $lang['terms_array'], 1);
$additional_image_fields['terms_msg'] = array($lang['terms_msg'], "dropdown", 0, $lang['terms_agreement'], 1);
Step 6 Open
lang/<yourlanguage>/main.php At the end,
above closing
?> insert:
//-----------------------------------------------------
//--- Image Terms -------------------------------------
//-----------------------------------------------------
$lang['terms'] = "Terms and Conditions";
$lang['terms_msg'] = "Terms and Conditions message";
$lang['terms_agreement'] = array(
"Terms and conditions blah blah<b>testa</b><br>asdfasdf",
"Another terms and conditions blah blah blah"
);
$lang['terms_array'] = array("Disable", "Guests", "Everyone");
Step 7 Open
admin/categories.php Find:
function show_access_select($title = "", $type, $status) {
Insert
above:
function show_terms_select($title = "", $type, $status, $array) {
global $HTTP_POST_VARS;
if (isset($HTTP_POST_VARS[$type])) {
$status = $HTTP_POST_VARS[$type];
}
echo "<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td><p class=\"rowtitle\">".$title."</p></td>\n";
echo "<td>\n<select name=\"".$type."\">\n";
foreach ($array as $key => $val) {
echo "<option value=\"".$key."\"";
if ($status == $key) {
echo " selected=\"selected\"";
}
echo ">".$val."</option>\n";
}
echo "</select>\n</td>\n</tr>\n";
}
Step 7.1 Find
two times:
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
Insert
below each:
$terms = $HTTP_POST_VARS['terms'];
$terms_msg = $HTTP_POST_VARS['terms_msg'];
Step 7.2 Find:
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment)
Replace it with:
(cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, terms, terms_msg)
(please note, that there only added
, terms, terms_msg at the end of the line. If u have different line, just add those two words manualy)
Step 7.3 Two line
below, find:
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment)";
Replace it with:
('$cat_name', '$cat_description', $cat_parent_id, $cat_order, $auth_viewcat, $auth_viewimage, $auth_download, $auth_upload, $auth_directupload, $auth_vote, $auth_sendpostcard, $auth_readcomment, $auth_postcomment, '$terms', '$terms_msg')";
(same deal here, only
, $terms, $terms_msg was added to the end of the line)
Step 7.4Find:
show_form_footer($lang['add'], $lang['reset'], 2);
Insert
above:
show_table_separator($lang['terms'], 2);
show_terms_select($lang['terms'], 'terms', $row['terms'], $lang['terms_array']);
show_terms_select($lang['terms_msg'], 'terms_msg', $row['terms_msg'], $lang['terms_agreement']);
Step 7.5
Find:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
Replace it with:
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, terms = '$terms', terms_msg = '$terms_msg'
(And again
, terms = '$terms', terms_msg = '$terms_msg' was added to the end of the line)
Step 7.6Find:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace it with:
$sql = "SELECT cat_name, cat_description, cat_parent_id, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, terms, terms_msg
(
, terms, terms_msg was added to the end of the line)
Step 7. 7Find:
show_form_footer($lang['save_changes'], $lang['reset'], 2, $lang['back']);
Insert
above:
(4images v1.7 - 1.7.1) show_table_separator($lang['terms'], 2);
show_terms_select($lang['terms'], 'terms', $result['terms'], $lang['terms_array']);
show_terms_select($lang['terms_msg'], 'terms_msg', $result['terms_msg'], $lang['terms_agreement']);
(4images v1.7.2+) show_table_separator($lang['terms'], 2);
show_terms_select($lang['terms'], 'terms', $cat_row['terms'], $lang['terms_array']);
show_terms_select($lang['terms_msg'], 'terms_msg', $cat_row['terms_msg'], $lang['terms_agreement']);
Step 7.8 Find:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment
Replace it with:
$sql = "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, terms, terms_msg
(
, terms, terms_msg was added to the end of the line)
Step 8 Open
templates/<yourtemplate>/details.html Find
{image} tag.
Replace it with:
{if show_terms}<b>{show_terms}<br /></b>{endif show_terms}
{if no_terms}
{image}
{endif no_terms}
Let me explain what it does. The
{show_terms} tag will show the "Terms and Condition" message, u should add it in between
{if show_terms} and
{endif show_terms} tags, if u want u can add between those tags whatever u want to display along with the terms.
Put whatever u dont want to show when terms are present, between
{if no_terms} and
{endif no_terms} tags, make sure that
{show_terms} tag is outside of
no_terms tags.
Step 9 Create a new template:
templates/<yourtemplate>/terms.html With this code:
<table border="0" cellpadding="0" cellspacing="0" width="400" class="bordercolor" align="center">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td valign="top" class="head1">{lang_terms}</td>
</tr>
<tr>
<td class="row2">{lang_terms_agreement}</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellspacing="1" cellpadding="1" width="400" align="center">
<tr>
<form method="post" action="{self}">
<td align="right" width="50%">
<input type="hidden" name="action" value="terms" />
{if mode}
<input type="hidden" name="mode" value="{mode}" />
{endif mode}
<input type="submit" value="{lang_agree}" class="button" />
</td>
</form>
<form method="post" action="{url_home}">
<td align="left" width="50%">
<input type="submit" value="{lang_agree_not}" class="button" />
</td>
</form>
</tr>
</table>
Step 10 In your favorite MySQL manager (phpmyadmin or such) execute this query:
ALTER TABLE `4images_images` ADD `terms` TINYINT( 1 ) NOT NULL, ADD `terms_msg` SMALLINT( 6 ) NOT NULL;
ALTER TABLE `4images_images_temp` ADD `terms` TINYINT( 1 ) NOT NULL, ADD `terms_msg` SMALLINT( 6 ) NOT NULL;
ALTER TABLE `4images_categories` ADD `terms` TINYINT( 1 ) NOT NULL, ADD `terms_msg` SMALLINT( 6 ) NOT NULL;
In few words:
in phpmyadmin select your database (if its not selected already), click on "SQL" icon on top and paste the query above to the text box, click "Go" button.
The alternative is to download
this installer.
Step 11 If u haven't install
[MOD] Dropdown options for custom database fields, then do so, its required.
Step 12 (added 30-03-2005)
Open
categories.phpFind:
//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
Insert
above:
//-----------------------------------------------------
//--- Image Terms -------------------------------------
//-----------------------------------------------------
if ($action == "terms") {
terms_add($cat_id);
}
$terms = 0;
if (!terms_check($cat_id) && $action != "terms")
{
$terms_agreement = ($lang['terms_agreement'][$cat_cache[$cat_id]['terms_msg']]) ? $lang['terms_agreement'][$cat_cache[$cat_id]['terms_msg']] : $lang['terms_agreement'][0];
$site_template->register_vars(array(
"url_home" => $site_sess->url(ROOT_PATH."index.php"),
"mode" => $mode,
"lang_terms" => $lang['terms'],
"lang_terms_agreement" => $terms_agreement,
"lang_agree" => $lang['agree'],
"lang_agree_not" => $lang['agree_not']
));
$terms = $site_template->parse_template("terms");
}
$site_template->register_vars(array(
"show_terms" => $terms,
"no_terms" => ($terms) ? 0 : 1
));
//--- End Image Terms -------------------------------------
Step 13Open
templates/<yourtemplate>/categories.htmlFind
{thumbnails} tag
Replace it with:
{if show_terms}
{show_terms}
{endif show_terms}
{if no_terms}
{thumbnails}
{endif no_terms}
Adjust it to your layout
Now in ACP (Admin Control Panel) under "Edit images" and "Edit categories" u should see new options.
------- [ Version history ] ---------- 1.2.1 (18-04-05) (more info
here)
- Fixed a bug in
Step 21.2 (30-03-05) (more info
here)
- Added terms to the category page
1.1 (26-08-04)
- Fixed "decline" button. (details.php)
1.0 (25-08-04)
- First release