25
« on: February 08, 2007, 02:59:46 AM »
Hi.
I want a modification that limits the views of images to 20 to all unregistred users.
I'm trying to adapt an other mod of this forum but I'm not a PHP guru... so I would need you to help me.
// Step 1
In root dir create : install_user_limits.php.
Insert :
[code]
<?php
session_start();
define('ROOT_PATH', './');
include(ROOT_PATH.'config.php');
include(ROOT_PATH.'global.php');
include(ROOT_PATH.'includes/constants.php');
require(ROOT_PATH.'includes/sessions.php');
if (!isset($_SESSION[‘count’]))
{
$_SESSION[‘count’]=0;
}
$error_log = array();
$error_msg = "";
if ($action == "modinstall") {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
<link rel="stylesheet" href="admin/cpstyle.css">
<title>4images Installer</title>
</head>
<body leftmargin="20" topmargin="20" marginwidth="20" marginheight="20" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="500" align="center">
<tr><td class="tableborder"><img src="admin/images/logo_installer.gif" width="500" height="45"><br />
<table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr class="tablerow2"><td><b>User Upload Limits MOD</b> (by Silly Little Lamer)</td></tr>
<tr class="tablefooter"><td align="center"> </td></tr>
</table>
<table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr class="tablerow"><td colspan="2" align="right"></td></tr>
<tr class="tablerow2"><td colspan="2"><br /><blockquote>
<?php
    $sql = "INSERT INTO ".SETTINGS_TABLE."
            (".get_user_table_field("", "setting_name").get_user_table_field(", ", "setting_value").")
            VALUES
            ('default_upload_limit', $default_limit".$additional_value_sql.")";
         if (!$site_db->query($sql)) {
         $error_log[] = $sql;
}
$fldname = "user_limit";
    $sql = "ALTER TABLE ".USERS_TABLE."
    ADD $fldname SMALLINT(3) DEFAULT $default_limit NOT NULL";
         if (!$site_db->query($sql)) {
         $error_log[] = $sql;
         }
    if (empty($error_log)) { echo "<h4>Database update success!</h4>"; }
?>
</blockquote></td></tr>
<tr class="tablefooter"><td colspan="2"> </td></tr>
</table>
</td>
</tr>
</table>
</table>
<p align="center"> Powered by <b>4images</b> <?php echo SCRIPT_VERSION ?><br />Copyright © 2002 <a href=" " target="_blank"> </a>
</body>
</html>
<?php
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
<link rel="stylesheet" href="admin/cpstyle.css">
<title>4images Installer</title>
</head>
<body leftmargin="20" topmargin="20" marginwidth="20" marginheight="20" bgcolor="#FFFFFF">
<form action="install_user_limits.php" name="form" method="post">
<table cellpadding="0" cellspacing="0" border="0" width="500" align="center">
<tr><td class="tableborder"><img src="admin/images/logo_installer.gif" width="500" height="45"><br />
<table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr class="tablerow2"><td><b>User Upload Limits MOD</b> (by Silly Little Lamer)</td></tr>
<tr class="tablefooter"><td align="center"> </td></tr>
</table>
<table cellpadding="3" cellspacing="1" border="0" width="100%">
<tr class="tablerow"><td colspan="2" align="right"></td></tr>
<tr class="tablerow2"><td colspan="2"><center>
This script will modify your 4images database, so please<br><b>
<font color="#FF0000">ALWAYS BACKUP YOUR DATABASE BEFORE RUNNING THIS MOD!</b></font><br><br>
Please check out all fields shown below.<br>
If they do not correspond to your settings, please<br><b>DO NOT START INSTALLER</b>!
</center></td></tr>
<tr class="tableheader"><td colspan="2"><b><span class="tableheader">Database configuration</span></b></td></tr>
<tr class="tablerow"><td>Database server type</td><td><?php echo $db_servertype; ?></td></tr>
<tr class="tablerow2"><td>Database server hostname</td><td><?php echo stripslashes($db_host); ?></td></tr>
<tr class="tablerow"><td>Database name</td><td><?php echo stripslashes($db_name); ?></td></tr>
<tr class="tablerow2"><td>Prefix for tables in database</td><td><?php echo stripslashes($table_prefix); ?></td></tr>
<tr class="tableheader"><td colspan="2"><span class="tableheader">Limit settings</span></td></tr>
<tr class="tablerow"><td>Default upload limit (number of images) to be assigned for all new and existing users.
This could be changed in 4images Control Panel later.</td><td><input type="text" name="default_limit" value="5"></td></tr>
<input type="hidden" name="action" value="modinstall">
<tr class="tablefooter"><td colspan="2"><center><input type="submit" value="Start modify database" class="button" name="submit"></center></td></tr>
</table>
</td>
</tr>
</table>
</form>
<p align="center"> Powered by <b>4images</b> <?php echo SCRIPT_VERSION ?><br />Copyright © 2002 <a href="http://www.4homepages.de" target="_blank">4homepages.de</a>
</body>
</html>
// Step 2
In member.php,
find :
if ($action == "uploadform") {
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
show_error_page($lang['no_permission']);
exit;
}
replace to :
//-----------------------------------------------------
// --- Check User Limits ------------------------------
//-----------------------------------------------------
$user_id = $user_info['user_id'];
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
if ($cat_id && isset($cat_cache[$cat_id])) {
$clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
}
$clickstream .= $lang['file_upload_error']."</span>";
$site_template->register_vars(array(
"clickstream" => $clickstream,
"lang_no_limits" => $lang['no_limits'],
"lang_no_limits_text" => $lang['no_limits_text'],
"lang_already_loaded" => $lang['already_loaded'],
"lang_show_my_images" => $lang['show_my_images'],
"url_show_user_images" => $site_sess->url(ROOT_PATH."search.php?search_user=".$user_info['user_name'])
));
function check_daily_picture_limit($user_id) {
global $site_db, $site_template;
$sql = "SELECT user_limit FROM ".USERS_TABLE." WHERE user_id = $user_id";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$upload_limit = ($row['user_limit']);
$site_template->register_vars("upload_limit", $upload_limit);
$limit_cutoff = time() - 60 * 60 * 24;
$sql = "SELECT COUNT(*) AS num_rows_all
FROM ".IMAGES_TABLE."
WHERE image_active = 1 AND user_id=$user_id AND image_date > $limit_cutoff";
$row = $site_db->query_firstrow($sql);
$images_per_user = $row['num_rows_all'];
$site_template->register_vars("images_per_user", $images_per_user);
if($images_per_user >= $upload_limit) {
return false;
} else {
return true;
}
}
function check_picture_limit($user_id) {
global $site_db, $site_template;
$sql = "SELECT user_limit FROM ".USERS_TABLE." WHERE user_id = $user_id";
$result = $site_db->query($sql);
$row = $site_db->fetch_array($result);
$upload_limit = ($row['user_limit']);
$site_template->register_vars("upload_limit", $upload_limit);
$sql = "SELECT image_id FROM ".IMAGES_TABLE." WHERE user_id=$user_id";
$result = $site_db->query($sql);
$images_per_user = $site_db->get_numrows($result);
// $sql = "SELECT image_id FROM ".IMAGES_TEMP_TABLE." WHERE user_id=$user_id";
// $result = $site_db->query($sql);
// $tmp_images_per_user = $site_db->get_numrows($result);
// $images_per_user = $tmp_images_per_user + $images_per_user;
// Uncomment above four lines if you also want to check uploaded but not yet validated images against the user limit
$site_template->register_vars("images_per_user", $images_per_user);
if($images_per_user >= $upload_limit) {
return false;
} else {
return true;
}
}
if ($action == "uploadform") {
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
show_error_page($lang['no_permission']);
exit;
}
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_picture_limit($user_id))) {
// if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_daily_picture_limit($user_id))) {
//
// Depending on your requirements, you can either check against global or daily limit. For global check leave it as it is now.
// For daily limit comment first line and uncomment second one.
//
$site_template->print_template($site_template->parse_template("over_limit"));
include(ROOT_PATH.'includes/page_footer.php');
exit;
}
// Step 3
In register.php ,
find :
$sql = "INSERT INTO ".USERS_TABLE."
(".get_user_table_field("", "user_id").get_user_table_field(", ", "user_level").get_user_table_field(", ", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_showemail").get_user_table_field(", ", "user_allowemails").get_user_table_field(", ", "user_invisible").get_user_table_field(", ", "user_joindate").get_user_table_field(", ", "user_activationkey").get_user_table_field(", ", "user_lastaction").get_user_table_field(", ", "user_lastvisit").get_user_table_field(", ", "user_comments").get_user_table_field(", ", "user_homepage").get_user_table_field(", ", "user_icq").$additional_field_sql.")
VALUES
($user_id, $user_level, '$user_name', '".md5($user_password)."', '$user_email', $user_showemail, $user_allowemails, $user_invisible, $current_time, '$activationkey', $current_time, $current_time, 0, '$user_homepage', '$user_icq'".$additional_value_sql.")";
replace to :
$user_limit= $config['default_upload_limit'];
$sql = "INSERT INTO ".USERS_TABLE."
(".get_user_table_field("", "user_id").get_user_table_field(", ", "user_level").get_user_table_field(", ", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_showemail").get_user_table_field(", ", "user_allowemails").get_user_table_field(", ", "user_invisible").get_user_table_field(", ", "user_joindate").get_user_table_field(", ", "user_activationkey").get_user_table_field(", ", "user_lastaction").get_user_table_field(", ", "user_lastvisit").get_user_table_field(", ", "user_comments").get_user_table_field(", ", "user_homepage").get_user_table_field(", ", "user_icq").(", ").('user_limit').$additional_field_sql.")
VALUES
($user_id, $user_level, '$user_name', '".md5($user_password)."', '$user_email', $user_showemail, $user_allowemails, $user_invisible, $current_time, '$activationkey', $current_time, $current_time, 0, '$user_homepage', '$user_icq', $user_limit".$additional_value_sql.")";
// Step 4
In admin/users.php,
find :
$user_icq = (intval(trim($HTTP_POST_VARS['user_icq']))) ? intval(trim($HTTP_POST_VARS['user_icq'])) : "";
Insert bellow :
$user_limit = intval($HTTP_POST_VARS['user_limit']);
Then, find :
$sql = "UPDATE ".USERS_TABLE."
SET ".get_user_table_field("", "user_level")." = $user_level, ".get_user_table_field("", "user_name")." = '$user_name',$passinsert ".get_user_table_field("", "user_email")." = '$user_email', ".get_user_table_field("", "user_showemail")." = $user_showemail, ".get_user_table_field("", "user_allowemails")." = $user_allowemails, ".get_user_table_field("", "user_invisible")." = $user_invisible, ".get_user_table_field("", "user_joindate")." = $user_joindate, ".get_user_table_field("", "user_lastaction")." = $user_lastaction, ".get_user_table_field("", "user_homepage")." = '$user_homepage', ".get_user_table_field("", "user_icq")." = '$user_icq'".$additional_sql."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
replace to :
[code]
$sql = "UPDATE ".USERS_TABLE."
SET ".get_user_table_field("", "user_level")." = $user_level, ".get_user_table_field("", "user_name")." = '$user_name',$passinsert ".get_user_table_field("", "user_email")." = '$user_email', ".get_user_table_field("", "user_showemail")." = $user_showemail, ".get_user_table_field("", "user_allowemails")." = $user_allowemails, ".get_user_table_field("", "user_invisible")." = $user_invisible, ".get_user_table_field("", "user_joindate")." = $user_joindate, ".get_user_table_field("", "user_lastaction")." = $user_lastaction, ".get_user_table_field("", "user_homepage")." = '$user_homepage', ".get_user_table_field("", "user_icq")." = '$user_icq', user_limit='".$user_limit."'".$additional_sql."
WHERE ".get_user_table_field("", "user_id")." = $user_id";
Then, find :
$sql = "INSERT INTO ".USERS_TABLE."
(".get_user_table_field("", "user_id").get_user_table_field(", ", "user_level").get_user_table_field(", ", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_showemail").get_user_table_field(", ", "user_allowemails").get_user_table_field(", ", "user_invisible").get_user_table_field(", ", "user_joindate").get_user_table_field(", ", "user_activationkey").get_user_table_field(", ", "user_lastaction").get_user_table_field(", ", "user_lastvisit").get_user_table_field(", ", "user_comments").get_user_table_field(", ", "user_homepage").get_user_table_field(", ", "user_icq").$additional_field_sql.")
VALUES
($user_id, $user_level, '$user_name', '$user_password', '$user_email', $user_showemail, $user_allowemails, $user_invisible, $current_time, '$activationkey', $current_time, $current_time, 0, '$user_homepage', '$user_icq'".$additional_value_sql.")";
replace to :
$sql = "INSERT INTO ".USERS_TABLE."
(".get_user_table_field("", "user_id").get_user_table_field(", ", "user_level").get_user_table_field(", ", "user_name").get_user_table_field(", ", "user_password").get_user_table_field(", ", "user_email").get_user_table_field(", ", "user_showemail").get_user_table_field(", ", "user_allowemails").get_user_table_field(", ", "user_invisible").get_user_table_field(", ", "user_joindate").get_user_table_field(", ", "user_activationkey").get_user_table_field(", ", "user_lastaction").get_user_table_field(", ", "user_lastvisit").get_user_table_field(", ", "user_comments").get_user_table_field(", ", "user_homepage").get_user_table_field(", ", "user_icq").(", user_limit").$additional_field_sql.")
VALUES
($user_id, $user_level, '$user_name', '$user_password', '$user_email', $user_showemail, $user_allowemails, $user_invisible, $current_time, '$activationkey', $current_time, $current_time, 0, '$user_homepage', '$user_icq', $user_limit".$additional_value_sql.")";
Then, find :
show_input_row($lang['field_icq'], "user_icq", $user_row['user_icq'], $textinput_size);
Insert above :
show_input_row($lang['field_limit'], "user_limit", $user_row['user_limit']);
// Step 4
In admin/settings.php,
find :
show_setting_row("max_media_size");
Insert above :
Code:
show_setting_row("default_upload_limit");
// Step 5
In lang/english/admin.php,
find :
$setting['max_media_size'] = "Max. image size in KB";
inserir to baixo :
$setting['default_upload_limit'] = "Maximum number of images to upload<br /><span class=\"smalltext\">This value will be assigned to all new users as a default limit.</span>";
Then, find :
$lang['field_usergroup_name'] = "Name of User Group";
add below :
$lang['field_limit'] = "Maximum number of images to upload";
// Step 5
In lang/english/main.php,
find :
//-----------------------------------------------------
//--- Admin Links -------------------------------------
//-----------------------------------------------------
Insert above :
//-----------------------------------------------------
//--- Over Limits -------------------------------------
//-----------------------------------------------------
$lang['show_my_images'] = "You have uploaded {images_per_user} images to this site. Show all images uploaded by you?";
$lang['already_loaded'] = "<span class=\"smalltext\"><b>For your information:</b> you have uploaded <b>{images_per_user}</b> images out of <b>{upload_limit}</b> allowed for you.</span>";
$lang['no_limits'] = "Limit exceeded";
$lang['no_limits_text'] = "You have the limit of {upload_limit} images to upload to this site, and unfortunately you have reached this limit already.
You are not allowed to upload new images, but you still have the possibility to delete one or more of the images,
already uploaded by you. After that you will be able to upoad images here again.<br /><br />
If you feel, that it's absolutely neccessary for you to upload more images, please contact the <a href=\"mailto:{site_email}\">
Site Administrator.</a> Probably, your limits would be reconsidered...";
// Step 6
In templates/<your_template> create: over_limit.html.
Inserir :
{header}
<table width="640" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table width="640" border="0" cellspacing="0" cellpadding="0" class="tablehead">
<tr>
<td colspan="4"><img src="{template_url}/images/header_top.gif" width="640" height="6" alt="" /></td>
</tr>
<tr>
<td width="6"><img src="{template_url}/images/header_left.gif" width="6" height="60" alt="" /></td>
<td width="405"><img src="{template_url}/images/header_logo.gif" width="405" height="60" alt="" /></td>
<td width="225" align="right">
<form method="post" action="{url_search}">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td>
<input type="text" name="search_keywords" size="15" class="searchinput" />
</td>
<td>
<input type="submit" value="{lang_search}" class="button" name="submit" />
</td>
</tr>
<tr valign="top">
<td colspan="2"><a href="{url_search}" class="smalltext">{lang_advanced_search}</a></td>
</tr>
</table>
</form>
</td>
<td align="right" width="6"><img src="{template_url}/images/header_right.gif" width="6" height="60" alt="" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="bordercolor">
<table width="640" border="0" cellspacing="1" cellpadding="0">
<tr>
<td class="tablebgcolor">
<table width="638" border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="23" class="navbar">
<table width="636" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="{template_url}/images/spacer.gif" width="4" height="4" alt="" />{clickstream}</td>
<td align="right"><a href="{url_new_images}"><b>{lang_new_images}</b></a> </td>
</tr>
</table>
</td>
</tr>
</table>
<table width="638" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" valign="top" class="row2">
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2" height="20"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_registered_user}</td>
</tr>
<tr>
<td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td align="center" class="row1">{user_box} </td>
</tr>
<tr>
<td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
</table>
{if random_image}
<table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head2" height="20"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_random_image}</td>
</tr>
<tr>
<td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td align="center" class="row1">
<br />
{random_image}
<br />
<br />
</td>
</tr>
<tr>
<td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
</table>
{endif random_image}
</td>
<td width="1" class="bordercolor" valign="top"><img src="{template_url}/images/spacer.gif" width="1" height="1" alt="" /></td>
<td width="18" valign="top"><img src="{template_url}/images/spacer.gif" width="18" height="18" alt="" /></td>
<td width="450" valign="top"><br />
<b class="title">{lang_no_limits}</b>
<hr size="1" />
<p>{lang_no_limits_text}</p>
<$php if ($_SESSION[‘count’]!=5)
{$>
<a href="{url_show_user_images}">{lang_show_my_images}</a>
$_SESSION[‘count’]++
<$php }$>
<br /><br /><br />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>{category_dropdown_form}</td>
<td align="right">{setperpage_dropdown_form}</td>
</tr>
</table>
<p> </p>
</td>
<td width="20" valign="top"><img src="{template_url}/images/spacer.gif" width="19" height="19" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="640" border="0" cellspacing="0" cellpadding="0" class="tablebottom">
<tr>
<td width="6"><img src="{template_url}/images/footer_left.gif" width="6" height="19" alt="" /></td>
<td width="405"> </td>
<td width="225"> </td>
<td width="6"><img src="{template_url}/images/footer_right.gif" width="6" height="19" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
{footer}
[/code][/code]