What I have so far is user based bandwith monitoring that will not care about tumbnails being shown only the full pictures includign the once that you see in the slideshow are monitored.
Ok, the files that need to be modified are:
lang/<your language>.php
usermgr.php
delete.php
displayimage.php
include/init.inc.php
include/slideshow.inc.php
On top of that the database needs a change... (we will add a table)
Ok lets start with the language file(s) this will not be noticed by anyone for obvious reasons I will only show how to
change the english language file.
Look for:
'user_occupation' => 'User occupation',
'latest_upload' => 'Recent uploads', //cpg1.3.0
Replace with:
'user_occupation' => 'User occupation',
'user_bandwidth' => 'User bandwidth limit (in Mb)',
'latest_upload' => 'Recent uploads', //cpg1.3.0
Look for:
$lang_error = 'Error';
Replace with:
$lang_error = 'Error';
$lang_bandwidth_limit = 'Bandwidth limit reached';
Look for:
$lang_errors = array(
'access_denied' => 'You don\'t have permission to access this page.',
Replace with:
$lang_errors = array(
'bandwidth_limit' => 'You have exceeded your bandwidth limit of [limit]Mb',
'access_denied' => 'You don\'t have permission to access this page.',
Look for:
'Cookies settings',
array('Name of the cookie used by the script (when using bbs integration, make sure it differs from the bbs\'s cookie
name)', 'cookie_name', 0),
array('Path of the cookie used by the script', 'cookie_path', 0),
'Miscellaneous settings',
array('Enable debug mode', 'debug_mode', 9), //cpg1.3.0
array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0
Replace with:
'Cookies settings',
array('Name of the cookie used by the script (when using bbs integration, make sure it differs from the bbs\'s cookie
name)', 'cookie_name', 0),
array('Path of the cookie used by the script', 'cookie_path', 0),
'Bandwidth monitoring',
array('Monitor bandwidth per user', 'monitor_bandwidth', 1),
'Miscellaneous settings',
array('Enable debug mode', 'debug_mode', 9), //cpg1.3.0
array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0
Ok, now that should be it.... as far as the language file goes.
Then we will do the table creation in the database which again should not be noticed by our dear users.
DROP TABLE IF EXISTS `cpg133_bandwidth`;
CREATE TABLE IF NOT EXISTS `cpg133_bandwidth` (
`user_id` int(11) NOT NULL default '0',
`bandwidth` bigint(20) NOT NULL default '0',
`download` bigint(20) NOT NULL default '0',
PRIMARY KEY (`user_id`)
) TYPE=MyISAM;
Then we need to make sure all our users are in there plus an extra which is the unknown user (iow logged in)
INSERT INTO `cpg133_bandwidth` VALUES (0, 0, 0);
INSERT INTO `cpg133_bandwidth` VALUES (select user_id, 0, 0 from `cpg133_users`);
Now we need to add a configuration field to the admin screen so we can en/disable bandwidth checking
The following SQL code will do that:
INSERT INTO `cpg133_config` VALUES ('monitor_bandwidth', '0');
Now we need to make sure we can access the bandwidth table and add some custom error message to do this we edit init.inc.php
Look for:
$CONFIG['TABLE_ECARDS'] = $CONFIG['TABLE_PREFIX']."ecards";
$CONFIG['TABLE_TEMPDATA'] = $CONFIG['TABLE_PREFIX']."temp_data";
Replace with:
$CONFIG['TABLE_ECARDS'] = $CONFIG['TABLE_PREFIX']."ecards";
$CONFIG['TABLE_TEMPDATA'] = $CONFIG['TABLE_PREFIX']."temp_data";
$CONFIG['TABLE_BANDWIDTH'] = $CONFIG['TABLE_PREFIX']."bandwidth";
Look for:
define('CRITICAL_ERROR', 3);
Replace with:
define('CRITICAL_ERROR', 3);
define('BANDWIDTH_LIMIT', 4);
Ok, so now we have a table and we have the language files changed lets make sure that new users get added with their own
personal bandwidth limit.
So now then usermgr.php
Look for:
case 'new_user' :
db_query("INSERT INTO {$CONFIG['TABLE_USERS']}(user_regdate, user_active) VALUES (NOW(), 'YES')");
$user_id = mysql_insert_id();
Replace with:
case 'new_user' :
db_query("INSERT INTO {$CONFIG['TABLE_USERS']}(user_regdate, user_active) VALUES (NOW(), 'YES')");
$user_id = mysql_insert_id();
db_query("INSERT INTO {$CONFIG['TABLE_BANDWIDTH']}(user_id, bandwidth, download) VALUES ($user_id, 0, 0)");
Look for:
function update_user($user_id)
{
global $CONFIG, $PHP_SELF, $HTTP_POST_VARS;
global $lang_usermgr_php, $lang_register_php;
$user_name = addslashes(trim($HTTP_POST_VARS['user_name']));
$user_password = addslashes(trim($HTTP_POST_VARS['user_password']));
$user_email = addslashes(trim($HTTP_POST_VARS['user_email']));
$user_location = addslashes($HTTP_POST_VARS['user_location']);
$user_interests = addslashes($HTTP_POST_VARS['user_interests']);
$user_website = addslashes($HTTP_POST_VARS['user_website']);
$user_occupation = addslashes($HTTP_POST_VARS['user_occupation']);
$user_active = $HTTP_POST_VARS['user_active'];
$user_group = $HTTP_POST_VARS['user_group'];
$group_list = isset($HTTP_POST_VARS['group_list']) ? $HTTP_POST_VARS['group_list'] : '';
Replace with:
function update_user($user_id)
{
global $CONFIG, $PHP_SELF, $HTTP_POST_VARS;
global $lang_usermgr_php, $lang_register_php;
$user_name = addslashes(trim($HTTP_POST_VARS['user_name']));
$user_password = addslashes(trim($HTTP_POST_VARS['user_password']));
$user_email = addslashes(trim($HTTP_POST_VARS['user_email']));
$user_location = addslashes($HTTP_POST_VARS['user_location']);
$user_interests = addslashes($HTTP_POST_VARS['user_interests']);
$user_website = addslashes($HTTP_POST_VARS['user_website']);
$user_occupation = addslashes($HTTP_POST_VARS['user_occupation']);
$user_active = $HTTP_POST_VARS['user_active'];
$user_group = $HTTP_POST_VARS['user_group'];
$user_bandwidth = $HTTP_POST_VARS['bandwidth'];
$group_list = isset($HTTP_POST_VARS['group_list']) ? $HTTP_POST_VARS['group_list'] : '';
Look for:
$sql_update = "UPDATE {$CONFIG['TABLE_USERS']} " . "SET " . "user_name = '$user_name', " . "user_email
= '$user_email', " . "user_active = '$user_active', " . "user_group = '$user_group', " . "user_location
= '$user_location', " . "user_interests = '$user_interests', " . "user_website = '$user_website', " .
"user_occupation= '$user_occupation', " . "user_group_list = '$user_group_list'";
if (strlen($user_password)) $sql_update .= ", user_password = '$user_password'";
$sql_update .= " WHERE user_id = '$user_id'";
db_query($sql_update);
}
Replace with:
$sql_update = "UPDATE {$CONFIG['TABLE_USERS']} " . "SET " . "user_name = '$user_name', " . "user_email
= '$user_email', " . "user_active = '$user_active', " . "user_group = '$user_group', " . "user_location
= '$user_location', " . "user_interests = '$user_interests', " . "user_website = '$user_website', " .
"user_occupation= '$user_occupation', " . "user_group_list = '$user_group_list'";
if (strlen($user_password)) $sql_update .= ", user_password = '$user_password'";
$sql_update .= " WHERE user_id = '$user_id'";
db_query($sql_update);
$sql_update = "UPDATE {$CONFIG['TABLE_BANDWIDTH']} SET bandwidth = '" . round(($user_bandwidth*1024)*1024) .
"' WHERE user_id = '$user_id'";
db_query($sql_update);
}
Look for:
function edit_user($user_id)
{
global $CONFIG, $PHP_SELF;
global $lang_usermgr_php, $lang_yes, $lang_no;
$form_data = array(
array('input', 'user_name', $lang_usermgr_php['name'], 25),
array('password', 'user_password', $lang_usermgr_php['password'], 25),
array('yesno', 'user_active', $lang_usermgr_php['user_active']),
array('group_list', 'user_group', $lang_usermgr_php['user_group']),
array('input', 'user_email', $lang_usermgr_php['user_email'], 255),
array('input', 'user_location', $lang_usermgr_php['user_location'], 255),
array('input', 'user_interests', $lang_usermgr_php['user_interests'], 255),
array('input', 'user_website', $lang_usermgr_php['user_web_site'], 255),
array('input', 'user_occupation', $lang_usermgr_php['user_occupation'], 255),
);
$sql = "SELECT * FROM {$CONFIG['TABLE_USERS']} WHERE user_id = '$user_id'";
Replace with:
function edit_user($user_id)
{
global $CONFIG, $PHP_SELF;
global $lang_usermgr_php, $lang_yes, $lang_no;
$form_data = array(
array('input', 'user_name', $lang_usermgr_php['name'], 25),
array('password', 'user_password', $lang_usermgr_php['password'], 25),
array('yesno', 'user_active', $lang_usermgr_php['user_active']),
array('group_list', 'user_group', $lang_usermgr_php['user_group']),
array('input', 'user_email', $lang_usermgr_php['user_email'], 255),
array('input', 'user_location', $lang_usermgr_php['user_location'], 255),
array('input', 'user_interests', $lang_usermgr_php['user_interests'], 255),
array('input', 'user_website', $lang_usermgr_php['user_web_site'], 255),
array('input', 'user_occupation', $lang_usermgr_php['user_occupation'], 255),
array('input', 'bandwidth', $lang_usermgr_php['user_bandwidth'], 255),
);
$sql = "SELECT * FROM {$CONFIG['TABLE_USERS']} as tu, {$CONFIG['TABLE_BANDWIDTH']} as tb WHERE tu.user_id =
'$user_id' AND tb.user_id = tu.user_id";
Look for:
foreach ($form_data as $element) switch ($element[0]) {
case 'input' :
$user_data[$element[1]] = $user_data[$element[1]];
echo <<<EOT
Replace with:
foreach ($form_data as $element) switch ($element[0]) {
case 'input' :
if ( $element[1] == 'bandwidth' ) { $user_data[$element[1]] = ($user_data[$element[1]]/1024)/1024; }
echo <<<EOT
And we can add users with their bandwith limit set, now we need to make sure that if we remove them we clean up this
users info in the bandwith table as well.
So now for delete.php
Look for:
db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET owner_id = '0' WHERE owner_id = '$user_id'");
Replace with:
db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET owner_id = '0' WHERE owner_id = '$user_id'");
// BANDWIDTH MONITORING
db_query("DELETE FROM {$CONFIG['TABLE_BANDWIDTH']} WHERE user_id = '$user_id'");
// BANDWIDTH MONITORING