Exemple #1
0
require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
require_once "{$GLOBALS['BASE_DIR']}/includes/validator.class.php";
SetupRequest();
$t = new Template();
$t->assign_by_ref('config', $C);
$DB = new DB($C['db_hostname'], $C['db_username'], $C['db_password'], $C['db_name']);
$DB->Connect();
if ($C['accounts_status'] == 'closed') {
    $t->display('accounts-closed.tpl');
    $DB->Disconnect();
    return;
}
if (isset($functions[$_REQUEST['r']]) && function_exists($functions[$_REQUEST['r']])) {
    call_user_func($functions[$_REQUEST['r']]);
} else {
    tlxShAccountAdd();
}
$DB->Disconnect();
function tlxAccountLogout()
{
    global $C, $DB, $L, $t;
    if (isset($_COOKIE['toplistxaccount'])) {
        parse_str($_COOKIE['toplistxaccount'], $cookie);
        $DB->Update('DELETE FROM `tlx_account_logins` WHERE `username`=? AND `session`=?', array($cookie['username'], $cookie['session']));
    }
    setcookie('toplistxaccount', '', time() - 3600, '/', $C['cookie_domain']);
    $t->assign('logged_out', TRUE);
    tlxShAccountLogin();
}
function tlxShAccountLogin($errors = null)
{
Exemple #2
0
function tlxAccountAdd()
{
    global $DB, $C, $IMAGE_EXTENSIONS;
    VerifyPrivileges(P_ACCOUNT_ADD);
    $_REQUEST['return_percent'] /= 100;
    // Get domain
    $parsed_url = parse_url($_REQUEST['site_url']);
    $_REQUEST['domain'] = preg_replace('~^www\\.~', '', $parsed_url['host']);
    $v = new Validator();
    $v->Register($_REQUEST['username'], V_LENGTH, 'The account username must be between 4 and 32 characters', '4,32');
    $v->Register($_REQUEST['username'], V_ALPHANUM, 'The account username may only contain English letters and numbers');
    $v->Register($_REQUEST['password'], V_LENGTH, 'The account password must be at least 4 characters', '4,9999');
    $v->Register($_REQUEST['email'], V_EMAIL, 'The E-mail Address is not properly formatted');
    $v->Register($_REQUEST['site_url'], V_URL, 'The Site URL is not properly formatted');
    $v->Register($_REQUEST['date_added'], V_DATETIME, 'The Date Added value is not properly formatted');
    if (!IsEmptyString($_REQUEST['banner_url'])) {
        $v->Register($_REQUEST['banner_url'], V_URL, sprintf($L['INVALID_URL'], $L['BANNER_URL']));
    }
    if (!$v->Validate()) {
        return $v->ValidationError('tlxShAccountAdd');
    }
    // Handling of banner_url_local
    if ($_REQUEST['download_banner']) {
        $http = new Http();
        if ($http->Get($_REQUEST['banner_url'], TRUE, $_REQUEST['site_url'])) {
            $banner_file = SafeFilename("{$C['banner_dir']}/{$_REQUEST['username']}.jpg", FALSE);
            FileWrite($banner_file, $http->body);
            $banner_info = @getimagesize($banner_file);
            if ($banner_info !== FALSE) {
                $_REQUEST['banner_width'] = $banner_info[0];
                $_REQUEST['banner_height'] = $banner_info[1];
                $banner_ext = strtolower($IMAGE_EXTENSIONS[$banner_info[2]]);
                if ($banner_ext != 'jpg') {
                    $new_file = preg_replace('~\\.jpg$~', ".{$banner_ext}", $banner_file);
                    rename($banner_file, $new_file);
                    $banner_file = $new_file;
                }
                $_REQUEST['banner_url_local'] = "{$C['banner_url']}/{$_REQUEST['username']}.{$banner_ext}";
            } else {
                @unlink($banner_file);
                $banner_file = null;
            }
        }
    }
    NullIfEmpty($_REQUEST['banner_url_local']);
    NullIfEmpty($_REQUEST['admin_comments']);
    // Add account data to the database
    $DB->Update('INSERT INTO `tlx_accounts` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($_REQUEST['username'], $_REQUEST['email'], $_REQUEST['site_url'], $_REQUEST['domain'], $_REQUEST['banner_url'], $_REQUEST['banner_url_local'], $_REQUEST['banner_height'], $_REQUEST['banner_width'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['keywords'], $_REQUEST['date_added'], $_REQUEST['status'] == STATUS_ACTIVE ? MYSQL_NOW : null, null, sha1($_REQUEST['password']), $_REQUEST['return_percent'], $_REQUEST['status'], intval($_REQUEST['locked']), intval($_REQUEST['disabled']), 0, $_REQUEST['category_id'], null, null, intval($_REQUEST['ratings']), intval($_REQUEST['ratings_total']), 0, null, $_REQUEST['admin_comments']));
    // Add click stats to the database
    $stats = array($_REQUEST['username']);
    $totals = array('raw_in_total' => 0, 'unique_in_total' => 0, 'raw_out_total' => 0, 'unique_out_total' => 0, 'clicks_total' => 0);
    foreach (range(0, 23) as $hour) {
        $stats[] = $_REQUEST["raw_in_{$hour}"];
        $stats[] = $_REQUEST["unique_in_{$hour}"];
        $stats[] = $_REQUEST["raw_out_{$hour}"];
        $stats[] = $_REQUEST["unique_out_{$hour}"];
        $stats[] = $_REQUEST["clicks_{$hour}"];
        $totals['raw_in_total'] += $_REQUEST["raw_in_{$hour}"];
        $totals['unique_in_total'] += $_REQUEST["unique_in_{$hour}"];
        $totals['raw_out_total'] += $_REQUEST["raw_out_{$hour}"];
        $totals['unique_out_total'] += $_REQUEST["unique_out_{$hour}"];
        $totals['clicks_total'] += $_REQUEST["clicks_{$hour}"];
    }
    array_push($stats, $totals['raw_in_total'], $totals['unique_in_total'], $totals['raw_out_total'], $totals['unique_out_total'], $totals['clicks_total'], 0, 0);
    $DB->Update('INSERT INTO `tlx_account_hourly_stats` VALUES (' . CreateBindList($stats) . ')', $stats);
    // Add user defined fields
    $query_data = CreateUserInsert('tlx_account_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tlx_account_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // Add icons
    if (is_array($_REQUEST['icons'])) {
        foreach ($_REQUEST['icons'] as $icon_id) {
            $DB->Update('INSERT INTO `tlx_account_icons` VALUES (?,?)', array($_REQUEST['username'], $icon_id));
        }
    }
    $GLOBALS['message'] = 'New account successfully added';
    $GLOBALS['added'] = true;
    UnsetArray($_REQUEST);
    tlxShAccountAdd();
}