コード例 #1
0
ファイル: submit.php プロジェクト: Cyberspace-Networks/TGPX
function txAddGallery()
{
    global $DB, $C, $L, $t, $domain;
    // Set some default values
    $defaults = array('weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => $_SERVER['REMOTE_ADDR'], 'sponsor_id' => null, 'type' => 'submitted', 'format' => $C['allow_format'] ? $_REQUEST['format'] : FMT_PICTURES, 'status' => 'pending', 'previous_status' => null, 'date_scanned' => MYSQL_NOW, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'allow_scan' => 1, 'allow_preview' => 1, 'has_preview' => 0, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => $domain['tags']);
    $_REQUEST = array_merge($_REQUEST, $defaults);
    $v = new Validator();
    // Verify and grab partner account
    $partner = null;
    if (!IsEmptyString($_REQUEST['username']) || !IsEmptyString($_REQUEST['password'])) {
        $partner = $DB->Row('SELECT * FROM `tx_partners` WHERE `username`=? AND `password`=?', array($_REQUEST['username'], sha1($_REQUEST['password'])));
        if (!$partner) {
            $v->SetError($L['INVALID_LOGIN']);
        } else {
            // Setup the correct weight value for this account
            $_REQUEST['weight'] = $partner['weight'];
            $_REQUEST['partner'] = $partner['username'];
            $_REQUEST['email'] = $partner['email'];
            $_REQUEST['nickname'] = $partner['name'];
            if (!empty($partner['categories'])) {
                $partner['categories'] = unserialize($partner['categories']);
            }
            // Nickname not required for partner accounts
            if ($C['require_nickname']) {
                $v->Register($_REQUEST['nickname'], V_EMPTY, $L['NO_PARTNER_NICKNAME']);
            }
            // Check if the partner account is active and valid to submit
            if ($partner['status'] == 'suspended') {
                $v->SetError($L['ACCOUNT_SUSPENDED']);
            } else {
                if ($partner['status'] != 'active') {
                    $v->SetError($L['ACCOUNT_PENDING']);
                }
            }
            // Check active dates
            if (!IsEmptyString($partner['date_end']) && !IsEmptyString($partner['date_start'])) {
                $now = strtotime(MYSQL_NOW);
                $end = strtotime($partner['date_end']);
                $start = strtotime($partner['date_start']);
                if ($now < $start || $now > $end) {
                    $start_time = date("{$C['date_format']} {$C['time_format']}", $start);
                    $end_time = date("{$C['date_format']} {$C['time_format']}", $end);
                    $v->SetError(sprintf($L['ACCOUNT_EXPIRED'], $start_time, $end_time));
                }
            }
            if ($partner['domains']) {
                $partner['domains'] = unserialize($partner['domains']);
                if ($domain) {
                    if (!$partner['domains_as_exclude'] && !in_array($domain['domain_id'], $partner['domains']) || $partner['domains_as_exclude'] && in_array($domain['domain_id'], $partner['domains'])) {
                        $v->SetError($L['BAD_PARTNER_DOMAIN']);
                    }
                }
            }
        }
    }
    // See if only accepting submissions from partners
    if (!$partner && $C['submit_status'] == 'partner') {
        $v->SetError($L['PARTNERS_ONLY']);
    }
    // Do partner account validation
    if (!$v->Validate()) {
        return $v->ValidationError('txShGallerySubmit', TRUE);
    }
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['gallery_url'], V_URL, sprintf($L['INVALID_URL'], $L['GALLERY_URL']));
    if ($C['require_keywords']) {
        $v->Register($_REQUEST['keywords'], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $L['KEYWORDS']));
    }
    if ($C['require_nickname']) {
        $v->Register($_REQUEST['nickname'], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $L['NAME']));
    }
    if ($C['require_description']) {
        $v->Register($_REQUEST['description'], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $L['DESCRIPTION']));
    }
    // Check description length if required or provided
    if ($C['require_description'] || !IsEmptyString($_REQUEST['description'])) {
        $v->Register($_REQUEST['description'], V_LENGTH, sprintf($L['DESCRIPTION_LENGTH'], $C['min_desc_length'], $C['max_desc_length']), "{$C['min_desc_length']},{$C['max_desc_length']}");
    }
    // Format keywords and check number
    $_REQUEST['keywords'] = FormatSpaceSeparated($_REQUEST['keywords']);
    $keywords = explode(' ', $_REQUEST['keywords']);
    $v->Register(count($keywords), V_LESS_EQ, sprintf($L['MAXIMUM_KEYWORDS'], $C['max_keywords']), $C['max_keywords']);
    // Validation of user defined fields
    $fields =& GetUserGalleryFields();
    foreach ($fields as $field) {
        if ($field['on_submit']) {
            if ($field['required']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $field['label']));
            }
            if (!IsEmptyString($_REQUEST[$field['name']]) && $field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Check the global number of submissions
    if (!$partner && $C['max_submissions'] != -1) {
        $todays_submissions = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE type=? AND (partner=? OR partner IS NULL) AND `date_added` BETWEEN ? AND ?', array('submitted', '', MYSQL_CURDATE . ' 00:00:00', MYSQL_CURDATE . ' 23:59:59'));
        if ($todays_submissions >= $C['max_submissions']) {
            $t->display($domain['template_prefix'] . 'submit-full-global.tpl');
            return;
        }
    }
    // Check the number of submitted galleries
    if ($partner) {
        if ($partner['per_day'] != -1) {
            $amount = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `partner`=? AND `type`=? AND `date_added` BETWEEN ? AND ?', array($partner['username'], 'submitted', MYSQL_CURDATE . ' 00:00:00', MYSQL_CURDATE . ' 23:59:59'));
            if ($amount >= $partner['per_day']) {
                $v->SetError($L['SUBMIT_LIMIT_REACHED']);
            }
        }
    } else {
        if ($C['submissions_per_person'] != -1) {
            $amount = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE (`submit_ip`=? OR `email`=? OR `gallery_url`=?) AND `type`=? AND `date_added` BETWEEN ? AND ?', array($_SERVER['REMOTE_ADDR'], $_REQUEST['email'], LevelUpUrl($_REQUEST['gallery_url']), 'submitted', MYSQL_CURDATE . ' 00:00:00', MYSQL_CURDATE . ' 23:59:59'));
            if ($amount >= $C['submissions_per_person']) {
                $v->SetError($L['SUBMIT_LIMIT_REACHED']);
            }
        }
    }
    // Check for valid category if allowing multiple categories to be selected
    $category = null;
    if ($C['allow_multiple_cats']) {
        if (is_array($_REQUEST['category_id'])) {
            $_REQUEST['category_id'] = array_unique($_REQUEST['category_id']);
            if (count($_REQUEST['category_id']) > $C['max_categories']) {
                $v->SetError(sprintf($L['EXCESSIVE_CATEGORIES'], $C['max_categories']));
            } else {
                $category_names = array();
                $category_tags = array();
                $_REQUEST['submitted_categories'] = join(',', $_REQUEST['category_id']);
                // Check that all categories are valid
                foreach ($_REQUEST['category_id'] as $category_id) {
                    $temp_category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=? AND `hidden`=0', array($category_id));
                    if (!$temp_category) {
                        $v->SetError($L['INVALID_CATEGORY']);
                    } else {
                        // Set primary category
                        if ($category == null) {
                            $category = $temp_category;
                        }
                        // Check category submission limit
                        if ($temp_category['per_day'] != -1) {
                            $category_submissions = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE type=? AND MATCH(`categories`) AGAINST(? IN BOOLEAN MODE) AND `date_added` BETWEEN ? AND ?', array('submitted', $temp_category['tag'], MYSQL_CURDATE . ' 00:00:00', MYSQL_CURDATE . ' 23:59:59'));
                            if ($category_submissions >= $temp_category['per_day']) {
                                $v->SetError(sprintf($L['CATEGORY_FULL'], htmlspecialchars($temp_category['name'])));
                            }
                        }
                        // Check if partner is allowed to submit to this category
                        if ($partner['categories']) {
                            if (!$partner['categories_as_exclude'] && !in_array($temp_category['category_id'], $partner['categories']) || $partner['categories_as_exclude'] && in_array($temp_category['category_id'], $partner['categories'])) {
                                $v->SetError(sprintf($L['BAD_PARTNER_CATEGORY'], $category['name']));
                            }
                        }
                        $category_names[] = $temp_category['name'];
                        $category_tags[] = $temp_category['tag'];
                    }
                }
                $_REQUEST['category'] = join(', ', $category_names);
                $category['tag'] = join(' ', $category_tags);
            }
        } else {
            $v->SetError($L['INVALID_CATEGORY']);
        }
    } else {
        if (is_array($_REQUEST['category_id'])) {
            $_REQUEST['category_id'] = $_REQUEST['category_id'][0];
        }
        $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=? AND `hidden`=0', array($_REQUEST['category_id']));
        if (!$category) {
            $v->SetError($L['INVALID_CATEGORY']);
        } else {
            // Check category submission limit
            if ($category['per_day'] != -1) {
                $category_submissions = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE type=? AND MATCH(`categories`) AGAINST(? IN BOOLEAN MODE) AND `date_added` BETWEEN ? AND ?', array('submitted', $category['tag'], MYSQL_CURDATE . ' 00:00:00', MYSQL_CURDATE . ' 23:59:59'));
                if ($category_submissions >= $category['per_day']) {
                    $v->SetError(sprintf($L['CATEGORY_FULL'], htmlspecialchars($category['name'])));
                }
            }
            // Check if partner is allowed to submit to this category
            if ($partner['categories']) {
                if (!$partner['categories_as_exclude'] && !in_array($_REQUEST['category_id'], $partner['categories']) || $partner['categories_as_exclude'] && in_array($_REQUEST['category_id'], $partner['categories'])) {
                    $v->SetError(sprintf($L['BAD_PARTNER_CATEGORY'], $category['name']));
                }
            }
            $_REQUEST['category'] = $category['name'];
        }
    }
    // Verify captcha code
    if (!$partner && $C['gallery_captcha'] || $partner && $C['gallery_captcha_partner']) {
        VerifyCaptcha($v);
    }
    // Check for duplicate gallery URL
    if (!$C['allow_duplicates'] && $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `gallery_url`=?', array($_REQUEST['gallery_url']))) {
        $v->SetError($L['DUPLICATE_URL']);
    }
    // Do preliminary validation before gallery scan
    if (!$v->Validate()) {
        return $v->ValidationError('txShGallerySubmit', TRUE);
    }
    // Check if whitelisted
    $whitelisted = MergeWhitelistOptions(CheckWhitelist($_REQUEST), $partner);
    // Scan gallery
    $scan =& ScanGallery($_REQUEST, $category, $whitelisted);
    $_REQUEST['scan'] = $scan;
    // Make sure the gallery URL is working
    if (!$scan['success']) {
        $v->SetError(sprintf($L['BROKEN_URL'], $L['GALLERY_URL'], $scan['errstr']));
        return $v->ValidationError('txShGallerySubmit', TRUE);
    }
    // Check if gallery content is hosted on same server
    if ($C['require_content_on_server'] && !$scan['server_match']) {
        $v->SetError($L['CONTENT_NOT_ON_SERVER']);
    }
    // Check for a reciprocal link
    if ($C['require_recip'] && !$whitelisted['allow_norecip'] && !$scan['has_recip']) {
        $v->SetError($L['NO_RECIP_FOUND']);
    }
    // Give weight boost to galleries with a reciprocal link
    if ($scan['has_recip'] && $C['give_recip_boost']) {
        $_REQUEST['weight']++;
    }
    // Check for 2257 code
    if ($C['require_2257'] && !$scan['has_2257']) {
        $v->SetError($L['NO_2257_FOUND']);
    }
    // Check for existing gallery with the same hash
    if (!$C['allow_same_hash']) {
        $amount = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `page_hash`=?', array($scan['page_hash']));
    }
    // Override the number of thumbnails
    if (!$C['allow_num_thumbs']) {
        $_REQUEST['thumbnails'] = $scan['thumbnails'];
    }
    // Check blacklist
    $blacklisted = FALSE;
    if (!$whitelisted['allow_blacklist']) {
        $_REQUEST['html'] = $scan['html'];
        $_REQUEST['headers'] = $scan['headers'];
        $blacklisted = CheckBlacklistGallery($_REQUEST);
        if ($blacklisted !== FALSE) {
            // Handle blacklist transparently
            if ($C['use_transparent_blacklist']) {
                $_REQUEST['gallery_id'] = $DB->Count('SELECT MAX(gallery_id) FROM `tx_galleries`') + 1;
                $t->assign_by_ref('gallery', $_REQUEST);
                $t->display($domain['template_prefix'] . 'submit-complete.tpl');
                return;
            } else {
                $v->SetError(sprintf($blacklisted[0]['reason'] ? $L['BLACKLISTED_REASON'] : $L['BLACKLISTED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
            }
        }
    }
    // Check number of links on the gallery
    if ($C['max_links'] != -1 && $scan['links'] > $C['max_links']) {
        $v->SetError(sprintf($L['EXCESSIVE_LINKS'], $C['max_links']));
    }
    // Get information about what is allowed for this category and format
    if ($C['allow_format']) {
        $scan['format'] = $_REQUEST['format'];
    }
    $format = GetCategoryFormat($scan['format'], $category);
    $_REQUEST['category_format'] = $format;
    // See if category allows this format
    if (!$format['allowed']) {
        $v->SetError(sprintf($L['INVALID_FORMAT'], $format['format_lang']));
    }
    // Check number of thumbnails
    if ($_REQUEST['thumbnails'] < $format['minimum'] || $_REQUEST['thumbnails'] > $format['maximum']) {
        $v->SetError(sprintf($L['BAD_THUMB_COUNT'], $format['minimum'], $format['maximum']));
    }
    // Clear keywords if not allowed
    if (!$C['allow_keywords']) {
        $_REQUEST['keywords'] = null;
    }
    // Clear preview thumbnail if only allowing partners to submit
    // OR
    // if this category and format does not allow preview thumbs
    if ($C['allow_preview_partner'] && !$partner || !$format['preview_allowed']) {
        $_REQUEST['preview'] = null;
    }
    // Handle the preview thumbnail if it was uploaded or to be automatically selected
    $preview = HandlePreviewThumb($v, $format, LoadAnnotation($format['annotation'], $category['name']));
    // Check size of gallery content
    if ($C['check_content_size']) {
        foreach ($scan['thumbs'] as $thumb) {
            $head = new Http();
            if ($head->Head($thumb['content'], FALSE, $scan['end_url'])) {
                if (!empty($head->response_headers['content-length']) && $head->response_headers['content-length'] < $format['file_size']) {
                    $v->SetError(sprintf($L['SMALL_CONTENT'], $format['file_size'] / 1024));
                    break;
                }
            }
        }
    }
    // Check download speed
    if ($C['check_download_speed'] && $scan['speed_download'] < $C['min_download_speed']) {
        $v->SetError(sprintf($L['SLOW_DOWNLOAD'], $scan['speed_download'], $C['min_download_speed']));
    }
    // Do final validation after gallery scan
    if (!$v->Validate()) {
        return $v->ValidationError('txShGallerySubmit', TRUE);
    }
    // Determine gallery status
    $autoapprove_general = empty($partner) && !$C['require_confirm'] && ($C['allow_autoapprove'] || $whitelisted['allow_autoapprove']);
    $autoapprove_partner = !empty($partner) && ($partner['allow_noconfirm'] || !$C['require_confirm']) && $whitelisted['allow_autoapprove'];
    if ($_REQUEST['preview'] == 'crop') {
        $_REQUEST['status'] = 'submitting';
    } else {
        if ($autoapprove_general || $autoapprove_partner) {
            $_REQUEST['status'] = 'approved';
            $_REQUEST['date_approved'] = MYSQL_NOW;
            $_REQUEST['administrator'] = 'AUTO';
        } else {
            if (empty($partner) && $C['require_confirm'] || !empty($partner) && !$partner['allow_noconfirm'] && $C['require_confirm']) {
                $_REQUEST['status'] = 'unconfirmed';
                $_REQUEST['confirm_id'] = md5(uniqid(rand(), true));
            }
        }
    }
    // Add gallery data to the database
    $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $_REQUEST['gallery_url'], $_REQUEST['description'], $_REQUEST['keywords'], $_REQUEST['thumbnails'], $_REQUEST['email'], $_REQUEST['nickname'], $_REQUEST['weight'], $_REQUEST['clicks'], $_REQUEST['submit_ip'], $_REQUEST['gallery_ip'], $_REQUEST['sponsor_id'], $_REQUEST['type'], $scan['format'], $_REQUEST['status'], $_REQUEST['previous_status'], $_REQUEST['date_scanned'], $_REQUEST['date_added'], $_REQUEST['date_approved'], $_REQUEST['date_scheduled'], $_REQUEST['date_displayed'], $_REQUEST['date_deletion'], $_REQUEST['partner'], $_REQUEST['administrator'], $_REQUEST['admin_comments'], $scan['page_hash'], $scan['has_recip'], $_REQUEST['has_preview'], $_REQUEST['allow_scan'], $_REQUEST['allow_preview'], $_REQUEST['times_selected'], $_REQUEST['used_counter'], $_REQUEST['build_counter'], $_REQUEST['tags'], MIXED_CATEGORY . " " . $category['tag']));
    $_REQUEST['gallery_id'] = $DB->InsertID();
    // Insert user defined database fields
    $query_data = CreateUserInsert('tx_gallery_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // If partner account has icons, assign those to this gallery
    if ($partner) {
        $icons =& $DB->FetchAll('SELECT * FROM `tx_partner_icons` WHERE `username`=?', array($partner['username']));
        foreach ($icons as $icon) {
            $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($_REQUEST['gallery_id'], $icon['icon_id']));
        }
    }
    // Log e-mail address
    if ($C['log_emails']) {
        $DB->Update('REPLACE INTO `tx_email_log` VALUES (?)', array($_REQUEST['email']));
    }
    // Show thumbnail cropping interface
    if ($_REQUEST['preview'] == 'crop' && $_REQUEST['thumbnails'] > 0) {
        txShCrop();
    } else {
        // Add preview thumbnail to database and rename
        $preview = AddPreview($_REQUEST['gallery_id'], $format['preview_size'], $preview);
        $_REQUEST['preview_url'] = $preview['url'];
        // Assign gallery data to the template
        $t->assign_by_ref('gallery', $_REQUEST);
        $t->assign_by_ref('user_fields', $fields);
        // Handle confirmation
        if ($_REQUEST['status'] == 'unconfirmed') {
            SendMail($_REQUEST['email'], $domain['template_prefix'] . 'email-gallery-confirm.tpl', $t);
            $DB->Update('INSERT INTO `tx_gallery_confirms` VALUES (?,?,?)', array($_REQUEST['gallery_id'], $_REQUEST['confirm_id'], MYSQL_NOW));
        }
        // Update number of submitted galleries if partner account
        if ($partner) {
            $DB->Update('UPDATE `tx_partners` SET `submitted`=`submitted`+1,`date_last_submit`=? WHERE `username`=?', array(MYSQL_NOW, $partner['username']));
        }
        // Update the date of last submission for this category
        $DB->Update('UPDATE `tx_categories` SET `date_last_submit`=? WHERE `category_id`=?', array(MYSQL_NOW, $category['category_id']));
        $t->display($domain['template_prefix'] . 'submit-complete.tpl');
    }
}
コード例 #2
0
ファイル: accounts.php プロジェクト: hackingman/ToplistX
function tlxAccountAdd()
{
    global $C, $DB, $L, $IMAGE_EXTENSIONS, $t;
    unset($_REQUEST['banner_url_local']);
    // Get domain
    $parsed_url = parse_url($_REQUEST['site_url']);
    $_REQUEST['domain'] = preg_replace('~^www\\.~', '', $parsed_url['host']);
    $v = new Validator();
    // Get selected category (if any) and set variables
    if (isset($_REQUEST['category_id'])) {
        $category = $DB->Row('SELECT * FROM `tlx_categories` WHERE `category_id`=? AND `hidden`=0', array($_REQUEST['category_id']));
        if ($category) {
            $C['min_desc_length'] = $category['desc_min_length'];
            $C['max_desc_length'] = $category['desc_max_length'];
            $C['min_title_length'] = $category['title_min_length'];
            $C['max_title_length'] = $category['title_max_length'];
            $C['banner_max_width'] = $category['banner_max_width'];
            $C['banner_max_height'] = $category['banner_max_height'];
            $C['banner_max_bytes'] = $category['banner_max_bytes'];
            $C['allow_redirect'] = $category['allow_redirect'];
        } else {
            $v->SetError($L['INVALID_CATEGORY']);
        }
    }
    // See if username is taken
    if ($DB->Count('SELECT COUNT(*) FROM `tlx_accounts` WHERE `username`=?', array($_REQUEST['username'])) > 0) {
        $v->SetError($L['USERNAME_TAKEN']);
    }
    // Check for duplicate account information
    if ($DB->Count('SELECT COUNT(*) FROM `tlx_accounts` WHERE `site_url`=? OR `email`=? OR `domain`=?', array($_REQUEST['site_url'], $_REQUEST['email'], $_REQUEST['domain'])) > 0) {
        $v->SetError($L['EXISTING_ACCOUNT']);
    }
    $v->Register($_REQUEST['username'], V_LENGTH, $L['USERNAME_LENGTH'], '4,32');
    $v->Register($_REQUEST['username'], V_ALPHANUM, $L['INVALID_USERNAME']);
    $v->Register($_REQUEST['password'], V_LENGTH, $L['PASSWORD_LENGTH'], '4,9999');
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['site_url'], V_URL, sprintf($L['INVALID_URL'], $L['SITE_URL']));
    $v->Register($_REQUEST['password'], V_NOT_EQUALS, $L['USERNAME_IS_PASSWORD'], $_REQUEST['username']);
    $v->Register($_REQUEST['password'], V_EQUALS, $L['PASSWORDS_DONT_MATCH'], $_REQUEST['confirm_password']);
    if (!IsEmptyString($_REQUEST['banner_url'])) {
        $v->Register($_REQUEST['banner_url'], V_URL, sprintf($L['INVALID_URL'], $L['BANNER_URL']));
    }
    // Format keywords and check number
    if ($C['allow_keywords']) {
        $_REQUEST['keywords'] = FormatSpaceSeparated($_REQUEST['keywords']);
        $keywords = explode(' ', $_REQUEST['keywords']);
        $v->Register(count($keywords), V_LESS_EQ, sprintf($L['MAXIMUM_KEYWORDS'], $C['max_keywords']), $C['max_keywords']);
    } else {
        $_REQUEST['keywords'] = null;
    }
    // Verify captcha code
    if ($C['account_add_captcha']) {
        VerifyCaptcha($v);
    }
    // Initial validation
    if (!$v->Validate()) {
        return $v->ValidationError('tlxShAccountAdd', TRUE);
    }
    // Check if the site URL is working
    $http = new Http();
    if ($http->Get($_REQUEST['site_url'], $C['allow_redirect'])) {
        $_REQUEST['html'] = $http->body;
        $_REQUEST['headers'] = $http->raw_response_headers;
    } else {
        $v->SetError(sprintf($L['BROKEN_URL'], $_REQUEST['site_url'], $http->errstr));
    }
    // Check the blacklist
    $blacklisted = CheckBlacklistAccount($_REQUEST);
    if ($blacklisted !== FALSE) {
        $v->SetError(sprintf($blacklisted[0]['reason'] ? $L['BLACKLISTED_REASON'] : $L['BLACKLISTED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
    }
    // Check site title and description length
    $v->Register($_REQUEST['title'], V_LENGTH, sprintf($L['TITLE_LENGTH'], $C['min_title_length'], $C['max_title_length']), "{$C['min_title_length']},{$C['max_title_length']}");
    $v->Register($_REQUEST['description'], V_LENGTH, sprintf($L['DESCRIPTION_LENGTH'], $C['min_desc_length'], $C['max_desc_length']), "{$C['min_desc_length']},{$C['max_desc_length']}");
    // Validation of user defined fields
    $fields =& GetUserAccountFields();
    foreach ($fields as $field) {
        if ($field['on_create']) {
            if ($field['required_create']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $field['label']));
            }
            if (!IsEmptyString($_REQUEST[$field['name']]) && $field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Download banner to check size
    $banner_file = null;
    if (!IsEmptyString($_REQUEST['banner_url']) && ($C['download_banners'] || $C['host_banners'])) {
        $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];
                if (filesize($banner_file) > $C['banner_max_bytes']) {
                    $v->SetError(sprintf($L['BAD_BANNER_BYTES'], $C['banner_max_bytes']));
                }
                if ($C['host_banners']) {
                    if (isset($IMAGE_EXTENSIONS[$banner_info[2]])) {
                        $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 {
                        $v->SetError($L['BAD_BANNER_IMAGE']);
                    }
                } else {
                    @unlink($banner_file);
                    $banner_file = null;
                }
            } else {
                $v->SetError($L['BAD_BANNER_IMAGE']);
            }
        } else {
            $v->SetError(sprintf($L['BROKEN_URL'], $_REQUEST['banner_url'], $http->errstr));
        }
    }
    // Check banner dimensions
    if ($_REQUEST['banner_width'] > $C['banner_max_width'] || $_REQUEST['banner_height'] > $C['banner_max_height']) {
        $v->SetError(sprintf($L['BAD_BANNER_SIZE'], $C['banner_max_width'], $C['banner_max_height']));
    }
    // Force banner dimensions
    if ($C['banner_force_size']) {
        $_REQUEST['banner_width'] = $C['banner_max_width'];
        $_REQUEST['banner_height'] = $C['banner_max_height'];
    }
    if (!$v->Validate()) {
        if (!empty($banner_file)) {
            @unlink($banner_file);
        }
        return $v->ValidationError('tlxShAccountAdd', TRUE);
    }
    $_REQUEST['status'] = STATUS_ACTIVE;
    $email_template = 'email-account-added.tpl';
    if ($C['confirm_accounts']) {
        $_REQUEST['status'] = STATUS_UNCONFIRMED;
        $email_template = 'email-account-confirm.tpl';
        $confirm_id = md5(uniqid(rand(), true));
        $t->assign('confirm_url', "{$C['install_url']}/accounts.php?r=confirm&id={$confirm_id}");
        $DB->Update('INSERT INTO `tlx_account_confirms` VALUES (?,?,?)', array($_REQUEST['username'], $confirm_id, MYSQL_NOW));
    } else {
        if ($C['review_new_accounts']) {
            $_REQUEST['status'] = STATUS_PENDING;
            $email_template = 'email-account-pending.tpl';
        }
    }
    // Add account information
    $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'], MYSQL_NOW, $_REQUEST['status'] == STATUS_ACTIVE ? MYSQL_NOW : null, MYSQL_NOW, sha1($_REQUEST['password']), $C['return_percent'], $_REQUEST['status'], 0, 0, 0, $_REQUEST['category_id'], null, null, 0, 0, 0, null, null));
    // Create stats tracking data
    $stats_data = array_merge(array($_REQUEST['username']), array_fill(0, 127, 0));
    $DB->Update('INSERT INTO `tlx_account_hourly_stats` VALUES (' . CreateBindList($stats_data) . ')', $stats_data);
    // Insert user defined database fields
    $query_data = CreateUserInsert('tlx_account_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tlx_account_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // Assign template values
    $_REQUEST['category'] = $category['name'];
    $t->assign_by_ref('account', $_REQUEST);
    $t->assign_by_ref('user_fields', $fields);
    $t->assign('tracking_url', $C['tracking_mode'] == 'unique_link' ? "{$C['in_url']}?id={$_REQUEST['username']}" : $C['in_url']);
    // Send e-mail to account submitter
    if ($C['confirm_accounts'] || $C['email_new_accounts']) {
        SendMail($_REQUEST['email'], $email_template, $t);
    }
    // Send e-mail to administrators
    $administrators =& $DB->FetchAll('SELECT * FROM `tlx_administrators`');
    foreach ($administrators as $administrator) {
        if ($administrator['notifications'] & E_ACCOUNT_ADDED) {
            SendMail($administrator['email'], 'email-admin-account-added.tpl', $t);
        }
    }
    // Display confirmation page
    $t->display('accounts-added.tpl');
}
コード例 #3
0
ファイル: account.php プロジェクト: hackingman/LinkX
function lxCreateAccount()
{
    global $DB, $C, $t, $L;
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['username'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['USERNAME']}");
    $v->Register($_REQUEST['password'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['PASSWORD']}");
    $v->Register($_REQUEST['username'], V_ALPHANUM, $L['INVALID_USERNAME']);
    $v->Register($_REQUEST['username'], V_LENGTH, $L['USERNAME_LENGTH'], '3,32');
    $v->Register($_REQUEST['password'], V_EQUALS, $L['NO_PASSWORD_MATCH'], $_REQUEST['confirm_password']);
    $v->Register($_REQUEST['password'], V_LENGTH, $L['PASSWORD_LENGTH'], '4,9999');
    $v->Register($_REQUEST['name'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['NAME']}");
    // Validation of user defined fields
    $fields =& GetUserAccountFields();
    foreach ($fields as $field) {
        if ($field['on_create']) {
            if ($field['required']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$field['label']}");
            }
            if ($field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Username exists?
    if ($DB->Count('SELECT COUNT(*) FROM lx_users WHERE username=?', array($_REQUEST['username']))) {
        $v->SetError($L['DUPLICATE_USER']);
    }
    // E-mail exists?
    if ($DB->Count('SELECT COUNT(*) FROM lx_users WHERE email=?', array($_REQUEST['email']))) {
        $v->SetError($L['DUPLICATE_EMAIL']);
    }
    // Verify captcha code
    if ($C['account_captcha']) {
        VerifyCaptcha($v);
    }
    // Check dsbl.org for spam submissions
    if ($C['dsbl_account'] && CheckDsbl($_SERVER['REMOTE_ADDR'])) {
        $v->SetError($L['DSBL_MATCHED']);
    }
    // Check blacklist
    $blacklisted = CheckBlacklistAccount($_REQUEST);
    if ($blacklisted !== FALSE) {
        $v->SetError(sprintf($L['BLACKLIST_MATCHED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
    }
    if (!$v->Validate()) {
        $errors = join('<br />', $v->GetErrors());
        lxShRegister($errors);
        return;
    }
    $status = 'active';
    $confirm_id = '';
    // Confirm accounts by e-mail
    if ($C['confirm_accounts']) {
        $status = 'unconfirmed';
    } else {
        if ($C['approve_accounts']) {
            $status = 'pending';
        }
    }
    // Add pre-defined data
    $DB->Update('INSERT INTO lx_users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', array($_REQUEST['username'], sha1($_REQUEST['password']), $_REQUEST['name'], $_REQUEST['email'], MYSQL_NOW, null, $status, '', 0, 0, $C['recip_required'], $C['allow_redirect'], $C['link_weight']));
    // Add user defined fields
    $query_data = CreateUserInsert('lx_user_fields', $_REQUEST);
    $DB->Update('INSERT INTO lx_user_fields VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // Setup template values
    $t->assign_by_ref('user_fields', $fields);
    $t->assign_by_ref('account', $_REQUEST);
    $t->assign('status', $status);
    // Send e-mail message
    if ($status == 'unconfirmed') {
        $confirm_id = sha1(uniqid(rand(), TRUE));
        $DB->Update('INSERT INTO lx_user_confirms VALUES (?,?,?)', array($_REQUEST['username'], $confirm_id, time()));
        $t->assign('confirm_id', $confirm_id);
        SendMail($_REQUEST['email'], 'email-account-confirm.tpl', $t);
    } else {
        if ($C['email_accounts']) {
            SendMail($_REQUEST['email'], 'email-account-added.tpl', $t);
        }
    }
    // Display confirmation page
    $t->display('account-created.tpl');
}
コード例 #4
0
function ConvertData()
{
    global $C, $DB, $from_shell;
    $errors = array();
    if (!is_dir($_REQUEST['directory'])) {
        $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server";
        return DisplayMain($errors);
    }
    if (!is_file("{$_REQUEST['directory']}/tgpr.pl")) {
        $errors[] = "The tgpr.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory";
        return DisplayMain($errors);
    }
    if (!is_readable("{$_REQUEST['directory']}/tgpr.pl")) {
        $errors[] = "The tgpr.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading";
        return DisplayMain($errors);
    }
    // Check version
    $version_file_contents = file_get_contents("{$_REQUEST['directory']}/tgpr.pl");
    if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) {
        list($a, $b, $c) = explode('.', $matches[1]);
        if ($b < 2 || strpos($c, '-SS') === FALSE) {
            $errors[] = "Your TGP Rotator installation is outdated; please upgrade to the very latest snapshot release (1.2.1-SS)";
            return DisplayMain($errors);
        }
    } else {
        $errors[] = "Unable to extract version information from tgpr.pl; your version of TGP Rotator is likely too old";
        return DisplayMain($errors);
    }
    // Extract MySQL information
    $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables");
    if ($mysql_file_contents === FALSE) {
        $errors[] = "Unable to read contents of the variables file";
        return DisplayMain($errors);
    }
    $vars = array();
    if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $vars[$match[1]] = $match[2];
        }
    }
    if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) {
        $errors[] = "Unable to extract MySQL database information from the variables file";
        return DisplayMain($errors);
    }
    if (!is_writable("{$GLOBALS['BASE_DIR']}/annotations")) {
        $errors[] = "Change the permissions on the TGPX annotations directory to 777";
        return DisplayMain($errors);
    }
    if ($C['preview_dir'] == $vars['THUMB_DIR']) {
        $errors[] = "The TGPX Thumbnail URL cannot be the same as the TGP Rotator Thumbnail URL";
        return DisplayMain($errors);
    }
    $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']);
    $CONVERTDB->Connect();
    $CONVERTDB->Update('SET wait_timeout=86400');
    $columns = $CONVERTDB->GetColumns('tr_Galleries');
    if (!in_array('Thumbnail_URL', $columns)) {
        $errors[] = "Your TGP Rotator installation is outdated; please upgrade to the latest snapshot release";
        return DisplayMain($errors);
    }
    if (!$from_shell) {
        echo "<pre>";
    }
    // Copy annotations
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying annotation font files and images...\n");
    echo "Copying annotation font files and images...\n";
    flush();
    $annotations =& DirRead($vars['ANNOTATION_DIR'], '^[^.]');
    foreach ($annotations as $annotation) {
        @copy("{$vars['ANNOTATION_DIR']}/{$annotation}", "{$GLOBALS['BASE_DIR']}/annotations/{$annotation}");
    }
    // Copy thumbnail previews
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n");
    echo "Copying thumbnail preview images...\n";
    flush();
    $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$');
    foreach ($thumbs as $thumb) {
        @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}");
        @chmod("{$C['preview_dir']}/t_{$thumb}", 0666);
    }
    //
    // Dump annotations
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting annotation settings...\n");
    echo "Converting annotation settings...\n";
    flush();
    $annotations = array();
    $DB->Update('DELETE FROM `tx_annotations`');
    $result = $CONVERTDB->Query('SELECT * FROM `tr_Annotations`');
    while ($annotation = $CONVERTDB->NextRow($result)) {
        $DB->Update('INSERT INTO `tx_annotations` VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $annotation['Identifier'], strtolower($annotation['Type']), $annotation['String'], 0, $annotation['Font_File'], $annotation['Size'], $annotation['Color'], $annotation['Shadow'], $annotation['Image_File'], $annotation['Transparency'], $annotation['Location']));
        $annotations[$annotation['Unique_ID']] = $DB->InsertID();
    }
    $CONVERTDB->Free($result);
    //
    // Dump categories
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n");
    echo "Converting categories...\n";
    flush();
    $categories = array();
    $category_ids = array();
    $DB->Update('DELETE FROM `tx_categories`');
    $result = $CONVERTDB->Query('SELECT * FROM `tr_Categories`');
    while ($category = $CONVERTDB->NextRow($result)) {
        $tag = CreateCategoryTag($category['Name']);
        $categories[$category['Name']] = $tag;
        $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, empty($category['Pictures']) ? 0 : 1, $category['Pictures'], 10, 30, 12288, "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Pictures']], empty($category['Movies']) ? 0 : 1, $category['Movies'], 5, 30, 102400, "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Movies']], -1, 0, null, null, null));
        $category_ids[$category['Name']] = $DB->InsertID();
    }
    $CONVERTDB->Free($result);
    //
    // Dump sponsors
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting sponsors...\n");
    echo "Converting sponsors...\n";
    flush();
    $counter = 1;
    $sponsors = array();
    $DB->Update('DELETE FROM `tx_sponsors`');
    $result = $CONVERTDB->Query('SELECT DISTINCT `Sponsor` FROM `tr_Galleries` WHERE `Sponsor`!=?', array(''));
    while ($sponsor = $CONVERTDB->NextRow($result)) {
        $sponsors[$sponsor['Sponsor']] = $counter;
        $DB->Update("INSERT INTO `tx_sponsors` VALUES (?,?,?)", array($counter++, $sponsor['Sponsor'], null));
    }
    $CONVERTDB->Free($result);
    //
    // Dump gallery data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n");
    echo "Converting gallery data...\n";
    flush();
    $DB->Update('DELETE FROM `tx_galleries`');
    $DB->Update('DELETE FROM `tx_gallery_fields`');
    $DB->Update('DELETE FROM `tx_gallery_icons`');
    $DB->Update('DELETE FROM `tx_gallery_previews`');
    $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0');
    $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0');
    $result = $CONVERTDB->Query('SELECT * FROM `tr_Galleries` ORDER BY `Gallery_ID`');
    $preview_sizes = array();
    while ($gallery = $CONVERTDB->NextRow($result)) {
        $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], $gallery['Keywords'], $gallery['Thumbnails'], $C['from_email'], null, $gallery['Weight'], $gallery['Clicks'], $_SERVER['REMOTE_ADDR'], null, !empty($gallery['Sponsor']) ? $sponsors[$gallery['Sponsor']] : null, 'permanent', strtolower($gallery['Type']), $gallery['Status'] == 'Pending' ? 'approved' : strtolower($gallery['Status']), $gallery['Status'] == 'Disabled' ? 'approved' : null, date(DF_DATETIME, TimeWithTz($gallery['Added'])), date(DF_DATETIME, TimeWithTz($gallery['Added'])), date(DF_DATETIME, TimeWithTz($gallery['Added'])), empty($gallery['Scheduled_Date']) ? null : "{$gallery['Scheduled_Date']} 00:00:00", empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", null, null, 'TGPR Convert', '', null, 0, empty($gallery['Thumbnail_URL']) ? 0 : 1, $gallery['Allow_Scan'], $gallery['Allow_Thumb'], $gallery['Times_Selected'], $gallery['Used_Counter'], $gallery['Build_Counter'], null, MIXED_CATEGORY . " " . $categories[$gallery['Category']]));
        $gallery_id = $DB->InsertID();
        $gallery_info = array('gallery_id' => $gallery_id);
        $insert = CreateUserInsert('tx_gallery_fields', $gallery_info);
        $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $gallery['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id]));
            }
        }
        if (!empty($gallery['Thumbnail_URL'])) {
            $dimensions = '';
            if (!empty($gallery['Thumb_Width']) && !empty($gallery['Thumb_Height'])) {
                $dimensions = "{$gallery['Thumb_Width']}x{$gallery['Thumb_Height']}";
                $preview_sizes[$dimensions] = TRUE;
            }
            $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions));
            $preview_id = $DB->InsertID();
            if (preg_match('~^' . preg_quote($vars['THUMB_URL']) . '~i', $gallery['Thumbnail_URL'])) {
                $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg";
                $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id));
                @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg");
            }
        }
    }
    $CONVERTDB->Free($result);
    // Update the stored thumbnail preview sizes
    $sizes = unserialize(GetValue('preview_sizes'));
    if (!is_array($sizes)) {
        $sizes = array();
    }
    $sizes = array_merge($sizes, array_keys($preview_sizes));
    StoreValue('preview_sizes', serialize(array_unique($sizes)));
    //
    // Dump TGP page data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n");
    echo "Converting TGP pages...\n";
    flush();
    $build_order = 1;
    $DB->Update('DELETE FROM `tx_pages`');
    $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0');
    $result = $CONVERTDB->Query('SELECT * FROM `tr_Pages` ORDER BY `Build_Order`');
    while ($page = $CONVERTDB->NextRow($result)) {
        $template = file_get_contents("{$_REQUEST['directory']}/data/pages/{$page['Page_ID']}");
        $template = ConvertTemplate($template);
        $compiled = '';
        $page['Directory'] = preg_replace('~/$~', '', $page['Directory']);
        $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, "{$page['Directory']}/{$page['Filename']}", $page['Page_URL'], $page['Category'] == 'Mixed' ? null : $category_ids[$page['Category']], $build_order++, 0, null, $template, $compiled));
    }
    $CONVERTDB->Free($result);
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!");
    echo "\nData conversion complete!\n";
    if (!$from_shell) {
        echo "</pre>";
    }
}
コード例 #5
0
function ConvertData()
{
    global $C, $DB, $from_shell;
    $errors = array();
    if (!is_dir($_REQUEST['directory'])) {
        $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server";
        return DisplayMain($errors);
    }
    if (!is_file("{$_REQUEST['directory']}/ags.pl")) {
        $errors[] = "The ags.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory";
        return DisplayMain($errors);
    }
    if (!is_readable("{$_REQUEST['directory']}/ags.pl")) {
        $errors[] = "The ags.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading";
        return DisplayMain($errors);
    }
    // Check version
    $version_file_contents = file_get_contents("{$_REQUEST['directory']}/ags.pl");
    if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) {
        if ($matches[1] != '3.6.2-SS') {
            $errors[] = "Your AutoGallery SQL installation is outdated ({$matches[1]}); please upgrade to version 3.6.2-SS";
            return DisplayMain($errors);
        }
    } else {
        $errors[] = "Unable to extract version information from ags.pl; your version of AutoGallery SQL is likely too old";
        return DisplayMain($errors);
    }
    // Extract MySQL information
    $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables");
    if ($mysql_file_contents === FALSE) {
        $errors[] = "Unable to read contents of the variables file";
        return DisplayMain($errors);
    }
    $vars = array();
    if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $vars[$match[1]] = $match[2];
        }
    }
    if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) {
        $errors[] = "Unable to extract MySQL database information from the variables file";
        return DisplayMain($errors);
    }
    if (!is_writable("{$GLOBALS['BASE_DIR']}/annotations")) {
        $errors[] = "Change the permissions on the TGPX annotations directory to 777";
        return DisplayMain($errors);
    }
    if (!is_writable($C['font_dir'])) {
        $errors[] = "Change the permissions on the TGPX fonts directory to 777";
        return DisplayMain($errors);
    }
    if ($C['preview_dir'] == $vars['THUMB_DIR']) {
        $errors[] = "The TGPX Thumbnail URL cannot be the same as the AutoGallery SQL Thumbnail URL";
        return DisplayMain($errors);
    }
    $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']);
    $CONVERTDB->Connect();
    $CONVERTDB->Update('SET wait_timeout=86400');
    if (!$from_shell) {
        echo "<pre>";
    }
    // Copy fonts for validation codes
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying font files for verification codes...\n");
    echo "Copying font files for verification codes...\n";
    flush();
    $fonts =& DirRead($vars['FONT_DIR'], '^[^.]');
    foreach ($fonts as $font) {
        @copy("{$vars['FONT_DIR']}/{$font}", "{$C['font_dir']}/{$font}");
    }
    // Copy annotations
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying annotation font files and images...\n");
    echo "Copying annotation font files and images...\n";
    flush();
    $annotations =& DirRead($vars['ANNOTATION_DIR'], '^[^.]');
    foreach ($annotations as $annotation) {
        @copy("{$vars['ANNOTATION_DIR']}/{$annotation}", "{$GLOBALS['BASE_DIR']}/annotations/{$annotation}");
    }
    // Copy thumbnail previews
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n");
    echo "Copying thumbnail preview images...\n";
    flush();
    $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$');
    foreach ($thumbs as $thumb) {
        @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}");
        @chmod("{$C['preview_dir']}/t_{$thumb}", 0666);
    }
    //
    // Dump e-mail log
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting e-mail log...\n");
    echo "Converting e-mail log...\n";
    flush();
    $emails = file("{$_REQUEST['directory']}/data/emails");
    $DB->Update('DELETE FROM `tx_email_log`');
    foreach ($emails as $email) {
        $email = trim($email);
        if (empty($email)) {
            continue;
        }
        $DB->Update('REPLACE INTO `tx_email_log` VALUES (?)', array($email));
    }
    //
    // Dump blacklist
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting blacklist...\n");
    echo "Converting blacklist...\n";
    flush();
    $DB->Update('DELETE FROM `tx_blacklist`');
    $types = array('submit_ip' => 'submitip', 'email' => 'email', 'url' => 'domain', 'domain_ip' => 'domainip', 'word' => 'word', 'html' => 'html', 'headers' => 'headers', 'dns' => 'dns');
    foreach ($types as $new_type => $old_type) {
        if (is_file("{$_REQUEST['directory']}/data/blacklist/{$old_type}")) {
            $blist_items = file("{$_REQUEST['directory']}/data/blacklist/{$old_type}");
            foreach ($blist_items as $html) {
                $html = trim($html);
                if (empty($html)) {
                    continue;
                }
                $regex = 0;
                if (strpos($html, '*') !== FALSE) {
                    $regex = 1;
                    $html = preg_quote($html);
                    $html = str_replace('\\*', '.*?', $html);
                }
                $DB->Update('INSERT INTO `tx_blacklist` VALUES (?,?,?,?,?)', array(null, $new_type, $regex, $html, ''));
            }
        }
    }
    //
    // Dump whitelist
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting whitelist...\n");
    echo "Converting whitelist...\n";
    flush();
    $DB->Update('DELETE FROM `tx_whitelist`');
    $wlist_items = file("{$_REQUEST['directory']}/data/blacklist/whitelist");
    foreach ($wlist_items as $html) {
        $html = trim($html);
        if (empty($html)) {
            continue;
        }
        $regex = 0;
        if (strpos($html, '*') !== FALSE) {
            $regex = 1;
            $html = preg_quote($html);
            $html = str_replace('\\*', '.*?', $html);
        }
        $DB->Update('INSERT INTO `tx_whitelist` VALUES (?,?,?,?,?,?,?,?,?,?)', array(null, 'url', $regex, $html, '', 1, 0, 0, 0, 0));
    }
    //
    // Dump reciprocal links
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting reciprocal link settings...\n");
    echo "Converting reciprocal link settings...\n";
    flush();
    $DB->Update('DELETE FROM `tx_reciprocals`');
    IniParse("{$_REQUEST['directory']}/data/generalrecips", TRUE, $recips);
    IniParse("{$_REQUEST['directory']}/data/trustedrecips", TRUE, $recips);
    foreach ($recips as $identifier => $html) {
        $regex = 0;
        if (strpos($html, '*') !== FALSE) {
            $regex = 1;
            $html = preg_quote($html);
            $html = str_replace('\\*', '.*?', $html);
        }
        $DB->Update('INSERT INTO `tx_reciprocals` VALUES (?,?,?,?)', array(null, $identifier, $html, $regex));
    }
    //
    // Dump 2257 code
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting 2257 search code...\n");
    echo "Converting 2257 search code...\n";
    flush();
    $counter = 1;
    $c2257s = file("{$_REQUEST['directory']}/data/2257");
    $DB->Update('DELETE FROM `tx_2257`');
    foreach ($c2257s as $html) {
        $html = trim($html);
        if (empty($html)) {
            continue;
        }
        $regex = 0;
        if (strpos($html, '*') !== FALSE) {
            $regex = 1;
            $html = preg_quote($html);
            $html = str_replace('\\*', '.*?', $html);
        }
        $DB->Update('INSERT INTO `tx_2257` VALUES (?,?,?,?)', array(null, "AGS Converted #{$counter}", $html, $regex));
        $counter++;
    }
    //
    // Dump icons
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting icons...\n");
    echo "Converting icons...\n";
    flush();
    $icons = array();
    $DB->Update('DELETE FROM `tx_icons`');
    IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini);
    foreach ($icons_ini as $identifier => $html) {
        $identifier = trim($identifier);
        $html = trim($html);
        if (empty($identifier) || empty($html)) {
            continue;
        }
        $DB->Update('INSERT INTO `tx_icons` VALUES (?,?,?)', array(null, $identifier, $html));
        $icons[$identifier] = $DB->InsertID();
    }
    //
    // Dump annotations
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting annotation settings...\n");
    echo "Converting annotation settings...\n";
    flush();
    $annotations = array();
    $DB->Update('DELETE FROM `tx_annotations`');
    $result = $CONVERTDB->Query('SELECT * FROM `ags_Annotations`');
    while ($annotation = $CONVERTDB->NextRow($result)) {
        $DB->Update('INSERT INTO `tx_annotations` VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $annotation['Identifier'], strtolower($annotation['Type']), $annotation['String'], 0, $annotation['Font_File'], $annotation['Size'], $annotation['Color'], $annotation['Shadow'], $annotation['Image_File'], $annotation['Transparency'], $annotation['Location']));
        $annotations[$annotation['Unique_ID']] = $DB->InsertID();
    }
    $CONVERTDB->Free($result);
    //
    // Dump categories
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n");
    echo "Converting categories...\n";
    flush();
    $categories = array();
    $category_ids = array();
    $DB->Update('DELETE FROM `tx_categories`');
    $result = $CONVERTDB->Query('SELECT * FROM `ags_Categories`');
    while ($category = $CONVERTDB->NextRow($result)) {
        $tag = CreateCategoryTag($category['Name']);
        $categories[$category['Name']] = $tag;
        $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, empty($category['Ext_Pictures']) ? 0 : 1, $category['Ext_Pictures'], $category['Min_Pictures'], $category['Max_Pictures'], $category['Size_Pictures'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Pictures']], empty($category['Ext_Movies']) ? 0 : 1, $category['Ext_Movies'], $category['Min_Movies'], $category['Max_Movies'], $category['Size_Movies'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Movies']], $category['Per_Day'], $category['Hidden'], null, null, null));
        $category_ids[$category['Name']] = $DB->InsertID();
    }
    $CONVERTDB->Free($result);
    //
    // Dump sponsors
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting sponsors...\n");
    echo "Converting sponsors...\n";
    flush();
    $counter = 1;
    $sponsors = array();
    $DB->Update('DELETE FROM `tx_sponsors`');
    $result = $CONVERTDB->Query('SELECT DISTINCT `Sponsor` FROM `ags_Galleries` WHERE `Sponsor`!=?', array(''));
    while ($sponsor = $CONVERTDB->NextRow($result)) {
        $sponsors[$sponsor['Sponsor']] = $counter;
        $DB->Update("INSERT INTO `tx_sponsors` VALUES (?,?,?)", array($counter++, $sponsor['Sponsor'], null));
    }
    $CONVERTDB->Free($result);
    //
    // Dump gallery data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n");
    echo "Converting gallery data...\n";
    flush();
    $DB->Update('DELETE FROM `tx_galleries`');
    $DB->Update('DELETE FROM `tx_gallery_fields`');
    $DB->Update('DELETE FROM `tx_gallery_icons`');
    $DB->Update('DELETE FROM `tx_gallery_previews`');
    $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0');
    $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0');
    $result = $CONVERTDB->Query('SELECT * FROM `ags_Galleries` ORDER BY `Gallery_ID`');
    $preview_sizes = array();
    while ($gallery = $CONVERTDB->NextRow($result)) {
        $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], $gallery['Keywords'], $gallery['Thumbnails'], $gallery['Email'], $gallery['Nickname'], $gallery['Weight'], $gallery['Clicks'], $gallery['Submit_IP'], $gallery['Gallery_IP'], !empty($gallery['Sponsor']) ? $sponsors[$gallery['Sponsor']] : null, strtolower($gallery['Type']), strtolower($gallery['Format']), strtolower($gallery['Status']), $gallery['Status'] == 'Disabled' ? 'approved' : null, date(DF_DATETIME, TimeWithTz($gallery['Added_Stamp'])), date(DF_DATETIME, TimeWithTz($gallery['Added_Stamp'])), empty($gallery['Approve_Stamp']) ? null : date(DF_DATETIME, TimeWithTz($gallery['Approve_Stamp'])), empty($gallery['Scheduled_Date']) ? null : "{$gallery['Scheduled_Date']} 00:00:00", empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", empty($gallery['Delete_Date']) ? null : "{$gallery['Delete_Date']} 00:00:00", $gallery['Account_ID'], $gallery['Moderator'], $gallery['Comments'], null, $gallery['Has_Recip'], empty($gallery['Thumbnail_URL']) ? 0 : 1, $gallery['Allow_Scan'], $gallery['Allow_Thumb'], $gallery['Times_Selected'], $gallery['Used_Counter'], $gallery['Build_Counter'], null, MIXED_CATEGORY . " " . $categories[$gallery['Category']]));
        $gallery_id = $DB->InsertID();
        $gallery_info = array('gallery_id' => $gallery_id);
        $insert = CreateUserInsert('tx_gallery_fields', $gallery_info);
        $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $gallery['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id]));
            }
        }
        if (!empty($gallery['Thumbnail_URL'])) {
            $dimensions = '';
            if (!empty($gallery['Thumb_Width']) && !empty($gallery['Thumb_Height'])) {
                $dimensions = "{$gallery['Thumb_Width']}x{$gallery['Thumb_Height']}";
                $preview_sizes[$dimensions] = TRUE;
            }
            $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions));
            $preview_id = $DB->InsertID();
            if (preg_match('~^' . preg_quote($vars['THUMB_URL']) . '~i', $gallery['Thumbnail_URL'])) {
                $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg";
                $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id));
                @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg");
            }
        }
    }
    $CONVERTDB->Free($result);
    //
    // Dump partner data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting partner accounts...\n");
    echo "Converting partner accounts...\n";
    flush();
    $DB->Update('DELETE FROM `tx_partners`');
    $DB->Update('DELETE FROM `tx_partner_fields`');
    $DB->Update('DELETE FROM `tx_partner_icons`');
    $DB->Update('DELETE FROM `tx_partner_confirms`');
    $result = $CONVERTDB->Query('SELECT * FROM `ags_Accounts`');
    while ($partner = $CONVERTDB->NextRow($result)) {
        $DB->Update('INSERT INTO `tx_partners` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($partner['Account_ID'], sha1($partner['Password']), '', $partner['Email'], null, MYSQL_NOW, $partner['Submitted'] > 0 ? MYSQL_NOW : null, empty($partner['Start_Date']) ? null : "{$partner['Start_Date']} 00:00:00", empty($partner['End_Date']) ? null : "{$partner['End_Date']} 23:59:59", $partner['Allowed'], round($partner['Weight']), null, 0, null, 0, $partner['Submitted'], $partner['Removed'], 'active', null, null, 0, $partner['Check_Recip'] ? 0 : 1, $partner['Auto_Approve'], $partner['Confirm'] ? 0 : 1, $partner['Check_Black'] ? 0 : 1));
        $partner_info = array('username' => $partner['Account_ID']);
        $insert = CreateUserInsert('tx_partner_fields', $partner_info);
        $DB->Update('INSERT INTO `tx_partner_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $partner['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tx_partner_icons` VALUES (?,?)', array($partner['Account_ID'], $icons[$icon_id]));
            }
        }
    }
    $CONVERTDB->Free($result);
    // Update the stored thumbnail preview sizes
    $sizes = unserialize(GetValue('preview_sizes'));
    if (!is_array($sizes)) {
        $sizes = array();
    }
    $sizes = array_merge($sizes, array_keys($preview_sizes));
    StoreValue('preview_sizes', serialize(array_unique($sizes)));
    //
    // Dump TGP page data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n");
    echo "Converting TGP pages...\n";
    flush();
    $build_order = 1;
    $docroot_url = parse_url($vars['CGI_URL']);
    $DB->Update('DELETE FROM `tx_pages`');
    $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0');
    $result = $CONVERTDB->Query('SELECT * FROM `ags_Pages` ORDER BY `Build_Order`');
    while ($page = $CONVERTDB->NextRow($result)) {
        $template = file_get_contents("{$_REQUEST['directory']}/data/html/{$page['Page_ID']}");
        $template = ConvertTemplate($template);
        $compiled = '';
        $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, "{$vars['DOCUMENT_ROOT']}/{$page['Filename']}", "http://{$docroot_url['host']}/{$page['Filename']}", $page['Category'] == 'Mixed' ? null : $category_ids[$page['Category']], $build_order++, 0, null, $template, $compiled));
    }
    $CONVERTDB->Free($result);
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!");
    echo "\nData conversion complete!\n";
    if (!$from_shell) {
        echo "</pre>";
    }
}
コード例 #6
0
ファイル: index.php プロジェクト: hackingman/LinkX
function lxAddUser()
{
    global $DB, $C;
    VerifyPrivileges(P_USER_ADD);
    $user_count = $DB->Count('SELECT COUNT(*) FROM lx_users WHERE username=?', array($_REQUEST['username']));
    $mail_count = $DB->Count('SELECT COUNT(*) FROM lx_users WHERE email=?', array($_REQUEST['email']));
    $validator = new Validator();
    $validator->Register($_REQUEST['username'], V_LENGTH, 'The username must be between 3 and 32 characters in length', array('min' => 3, 'max' => 32));
    $validator->Register($_REQUEST['username'], V_ALPHANUM, 'The username can only contain letters and numbers');
    $validator->Register($_REQUEST['password'], V_LENGTH, 'The password must contain at least 4 characters', array('min' => 4, 'max' => 999));
    $validator->Register($_REQUEST['email'], V_EMAIL, 'The e-mail address is not properly formatted');
    $validator->Register($user_count, V_ZERO, 'A user account already exists with that username');
    $validator->Register($mail_count, V_ZERO, 'A user account already exists with that e-mail address');
    $validator->Register($_REQUEST['weight'], V_NUMERIC, 'The weight value must be numeric');
    $validator->Register($_REQUEST['date_added'], V_DATETIME, 'The Date Added field is not properly formatted');
    if (!empty($_REQUEST['date_modified'])) {
        $validator->Register($_REQUEST['date_modified'], V_DATETIME, 'The Date Modified field is not properly formatted');
    }
    if (!$validator->Validate()) {
        $GLOBALS['errstr'] = join('<br />', $validator->GetErrors());
        lxShAddUser();
        return;
    }
    NullIfEmpty($_REQUEST['date_modified']);
    // Add account data to the database
    $DB->Update('INSERT INTO lx_users VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', array($_REQUEST['username'], sha1($_REQUEST['password']), $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['date_added'], $_REQUEST['date_modified'], $_REQUEST['status'], '', NULL, 0, intval($_REQUEST['recip_required']), intval($_REQUEST['allow_redirect']), $_REQUEST['weight']));
    // Add user defined fields
    $query_data = CreateUserInsert('lx_user_fields', $_REQUEST);
    $DB->Update('INSERT INTO lx_user_fields VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    $GLOBALS['message'] = 'New user account successfully added';
    $GLOBALS['added'] = true;
    UnsetArray($_REQUEST);
    lxShAddUser();
}
コード例 #7
0
ファイル: submit.php プロジェクト: hackingman/LinkX
function lxAddLink()
{
    global $DB, $C, $L, $t;
    $account = ValidUserLogin();
    // Requiring user account to submit links
    if ($C['user_for_links'] && !$account) {
        $t->display('submit-info.tpl');
        return;
    }
    if ($account) {
        $_REQUEST['email'] = $account['email'];
        $_REQUEST['name'] = $account['name'];
    }
    $_REQUEST['c'] = $_REQUEST['category_id'];
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['site_url'], V_URL, "{$L['INVALID_URL']}: {$L['SITE_URL']}");
    $v->Register($_REQUEST['title'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['TITLE']}");
    $v->Register($_REQUEST['description'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['DESCRIPTION']}");
    $v->Register($_REQUEST['keywords'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['KEYWORDS']}");
    $v->Register($_REQUEST['name'], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$L['NAME']}");
    $v->Register($_REQUEST['description'], V_LENGTH, sprintf($L['DESCRIPTION_LENGTH'], $C['min_desc_length'], $C['max_desc_length']), "{$C['min_desc_length']},{$C['max_desc_length']}");
    $v->Register($_REQUEST['title'], V_LENGTH, sprintf($L['TITLE_LENGTH'], $C['min_title_length'], $C['max_title_length']), "{$C['min_title_length']},{$C['max_title_length']}");
    // Format keywords and check number
    $_REQUEST['keywords'] = FormatKeywords($_REQUEST['keywords']);
    $keywords = explode(' ', $_REQUEST['keywords']);
    $v->Register(count($keywords), V_LESS_EQ, sprintf($L['MAXIMUM_KEYWORDS'], $C['max_keywords']), $C['max_keywords']);
    if (!empty($_REQUEST['password'])) {
        $v->Register($_REQUEST['password'], V_EQUALS, $L['NO_PASSWORD_MATCH'], $_REQUEST['confirm_password']);
    }
    // See if URL already exists
    if ($DB->Count('SELECT COUNT(*) FROM lx_links WHERE site_url=?', array($_REQUEST['site_url']))) {
        $v->SetError($L['DUPLICATE_URL']);
    }
    // Validation of user defined fields
    $fields =& GetUserLinkFields();
    foreach ($fields as $field) {
        if ($field['on_submit']) {
            if ($field['required']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, "{$L['REQUIRED_FIELD']}: {$field['label']}");
            }
            if ($field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Verify captcha code
    if ($C['link_captcha']) {
        VerifyCaptcha($v);
    }
    $_REQUEST['allow_redirect'] = $account ? $account['allow_redirect'] : $C['allow_redirect'];
    $_REQUEST['recip_required'] = $account ? $account['recip_required'] : $C['recip_required'];
    // Scan link
    $scan_result =& ScanLink($_REQUEST);
    // Make sure site URL is working
    if (!$scan_result['site_url']['working']) {
        $v->SetError(sprintf($L['BROKEN_URL'], $L['SITE_URL'], $scan_result['site_url']['error']));
    }
    // Setup HTML code for blacklist check
    $_REQUEST['html'] = $scan_result['site_url']['html'];
    if (!empty($_REQUEST['recip_url'])) {
        $_REQUEST['html'] .= ' ' . $scan_result['recip_url']['html'];
        // Make sure recip URL is working
        if (!$scan_result['recip_url']['working']) {
            $v->SetError(sprintf($L['BROKEN_URL'], $L['RECIP_URL'], $scan_result['recip_url']['error']));
        }
    }
    // Verify recip link was found
    if ($_REQUEST['recip_required'] && !$scan_result['has_recip']) {
        $v->SetError($L['NO_RECIP_FOUND']);
    }
    // Check blacklist
    $blacklisted = CheckBlacklistLink($_REQUEST);
    if ($blacklisted !== FALSE) {
        $v->SetError(sprintf($L['BLACKLIST_MATCHED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
    }
    // Check dsbl.org for spam submissions
    if ($C['dsbl_link'] && CheckDsbl($_SERVER['REMOTE_ADDR'])) {
        $v->SetError($L['DSBL_MATCHED']);
    }
    // Get category information
    $category = $DB->Row('SELECT * FROM lx_categories WHERE category_id=?', array($_REQUEST['category_id']));
    if (!$category || $category['hidden']) {
        $v->SetError($L['INVALID_CATEGORY']);
    } else {
        if ($category['status'] == 'locked') {
            $v->SetError($L['CATEGORY_LOCKED']);
        }
    }
    $category['path_parts'] = unserialize($category['path_parts']);
    if (!$v->Validate()) {
        $errors = join('<br />', $v->GetErrors());
        lxShSubmit($errors);
        return;
    }
    // Setup link status
    $status = 'active';
    if ($C['confirm_links'] && !$account) {
        $status = 'unconfirmed';
    } else {
        if ($category['status'] == 'approval') {
            $status = 'pending';
        }
    }
    // Setup username and password values
    $username = '';
    $password = '';
    if ($account) {
        $username = $account['username'];
    } else {
        if ($_REQUEST['password']) {
            $password = sha1($_REQUEST['password']);
        }
    }
    $weight = $account ? $account['weight'] : $C['link_weight'];
    // Insert link data
    $DB->Update('INSERT INTO lx_links VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $_REQUEST['site_url'], $_REQUEST['recip_url'], $_REQUEST['title'], $_REQUEST['description'], $status, 'regular', DEF_EXPIRES, $_REQUEST['name'], $_REQUEST['email'], $_SERVER['REMOTE_ADDR'], $_REQUEST['keywords'], 0, 0, null, 0, 0, 0, $weight, MYSQL_NOW, 0, MYSQL_NOW, $_REQUEST['recip_required'], $_REQUEST['allow_redirect'], '', '', $username, $password, $scan_result['has_recip'], 0, ''));
    $link_id = $DB->InsertID();
    $sorter = $DB->Count('SELECT MAX(sorter) FROM lx_link_cats WHERE category_id=?', array($_REQUEST['category_id']));
    $_REQUEST['link_id'] = $link_id;
    $_REQUEST['status'] = $status;
    // Insert category data
    $DB->Update('INSERT INTO lx_link_cats VALUES (?,?,?)', array($link_id, $_REQUEST['category_id'], $sorter));
    // Insert user defined fields
    $query_data = CreateUserInsert('lx_link_fields', $_REQUEST);
    $DB->Update('INSERT INTO lx_link_fields VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // Update category link count
    if ($status == 'active') {
        $DB->Update('UPDATE lx_categories SET links=links+1 WHERE category_id=?', array($_REQUEST['category_id']));
    }
    // Update account link count
    if ($account) {
        $DB->Update('UPDATE lx_users SET num_links=num_links+1 WHERE username=?', array($account['username']));
    }
    // Show confirmation page
    $t->assign_by_ref('category', $category);
    $t->assign_by_ref('user_fields', $fields);
    $t->assign_by_ref('link', $_REQUEST);
    $t->assign('status', $status);
    // Send e-mail message
    if ($status == 'unconfirmed') {
        $confirm_id = sha1(uniqid(rand(), TRUE));
        $DB->Update('INSERT INTO lx_link_confirms VALUES (?,?,?)', array($link_id, $confirm_id, time()));
        $t->assign('confirm_id', $confirm_id);
        SendMail($_REQUEST['email'], 'email-link-confirm.tpl', $t);
    } else {
        if ($C['email_links']) {
            SendMail($_REQUEST['email'], 'email-link-added.tpl', $t);
        }
    }
    $t->display('submit-added.tpl');
    flush();
    // Send e-mail to appropriate administrators
    if ($status != 'unconfirmed') {
        $result = $DB->Query('SELECT * FROM lx_administrators');
        while ($admin = $DB->NextRow($result)) {
            if ($admin['notifications'] & E_LINK_ADD) {
                SendMail($admin['email'], 'email-admin-link-add.tpl', $t);
            }
        }
        $DB->Free($result);
    }
}
コード例 #8
0
function ConvertData()
{
    global $C, $DB, $from_shell;
    $errors = array();
    if (!is_dir($_REQUEST['directory'])) {
        $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server";
        return DisplayMain($errors);
    }
    if (!is_file("{$_REQUEST['directory']}/agp.pl")) {
        $errors[] = "The agp.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory; make sure you have version 3.0.0 or newer installed";
        return DisplayMain($errors);
    }
    if (!is_readable("{$_REQUEST['directory']}/agp.pl")) {
        $errors[] = "The agp.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading";
        return DisplayMain($errors);
    }
    // Check version
    $version_file_contents = file_get_contents("{$_REQUEST['directory']}/agp.pl");
    if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) {
        list($a, $b, $c) = explode('.', $matches[1]);
        $c = str_replace('-SS', '', $c);
        if ($a < 3) {
            $errors[] = "Your AutoGallery Pro installation is outdated ({$matches[1]}); please upgrade to version 3.0.0+";
            return DisplayMain($errors);
        }
    } else {
        $errors[] = "Unable to extract version information from agp.pl; your version of AutoGallery Pro is likely too old";
        return DisplayMain($errors);
    }
    // Extract variables
    $var_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables");
    if ($var_file_contents === FALSE) {
        $errors[] = "Unable to read contents of the variables file";
        return DisplayMain($errors);
    }
    $vars = array();
    if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $var_file_contents, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $vars[$match[1]] = $match[2];
        }
    }
    if (!isset($vars['ADMIN_EMAIL'])) {
        $errors[] = "Unable to extract variable data from the AutoGallery Pro variables file";
        return DisplayMain($errors);
    }
    if (!is_writable($C['font_dir'])) {
        $errors[] = "Change the permissions on the TGPX fonts directory to 777";
        return DisplayMain($errors);
    }
    if ($C['preview_dir'] == $vars['THUMB_DIR']) {
        $errors[] = "The TGPX Thumbnail URL cannot be the same as the AutoGallery Pro Thumbnail URL";
        return DisplayMain($errors);
    }
    if (!$from_shell) {
        echo "<pre>";
    }
    // Copy fonts for validation codes
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying font files for verification codes...\n");
    echo "Copying font files for verification codes...\n";
    flush();
    $fonts =& DirRead($vars['FONT_DIR'], '^[^.]');
    foreach ($fonts as $font) {
        @copy("{$vars['FONT_DIR']}/{$font}", "{$C['font_dir']}/{$font}");
    }
    // Copy thumbnail previews
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n");
    echo "Copying thumbnail preview images...\n";
    flush();
    $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$');
    foreach ($thumbs as $thumb) {
        @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}");
        @chmod("{$C['preview_dir']}/t_{$thumb}", 0666);
    }
    //
    // Dump e-mail log
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting e-mail log...\n");
    echo "Converting e-mail log...\n";
    flush();
    $emails = file("{$_REQUEST['directory']}/data/emails");
    $DB->Update('DELETE FROM `tx_email_log`');
    foreach ($emails as $email) {
        $email = trim($email);
        if (empty($email)) {
            continue;
        }
        $DB->Update('REPLACE INTO `tx_email_log` VALUES (?)', array($email));
    }
    //
    // Dump blacklist
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting blacklist...\n");
    echo "Converting blacklist...\n";
    flush();
    $DB->Update('DELETE FROM `tx_blacklist`');
    $types = array('submit_ip' => 'submitip', 'email' => 'email', 'url' => 'domain', 'domain_ip' => 'domainip', 'word' => 'word', 'html' => 'html', 'dns' => 'dns');
    foreach ($types as $new_type => $old_type) {
        $blist_items = file("{$_REQUEST['directory']}/data/blacklist/{$old_type}");
        foreach ($blist_items as $html) {
            $html = trim($html);
            if (empty($html)) {
                continue;
            }
            $regex = 0;
            if (strpos($html, '*') !== FALSE) {
                $regex = 1;
                $html = preg_quote($html);
                $html = str_replace('\\*', '.*?', $html);
            }
            $DB->Update('INSERT INTO `tx_blacklist` VALUES (?,?,?,?,?)', array(null, $new_type, $regex, $html, ''));
        }
    }
    //
    // Dump whitelist
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting whitelist...\n");
    echo "Converting whitelist...\n";
    flush();
    $DB->Update('DELETE FROM `tx_whitelist`');
    $wlist_items = file("{$_REQUEST['directory']}/data/blacklist/whitelist");
    foreach ($wlist_items as $html) {
        $html = trim($html);
        if (empty($html)) {
            continue;
        }
        $regex = 0;
        if (strpos($html, '*') !== FALSE) {
            $regex = 1;
            $html = preg_quote($html);
            $html = str_replace('\\*', '.*?', $html);
        }
        $DB->Update('INSERT INTO `tx_whitelist` VALUES (?,?,?,?,?,?,?,?,?,?)', array(null, 'url', $regex, $html, '', 1, 0, 0, 0, 0));
    }
    //
    // Dump reciprocal links
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting reciprocal link settings...\n");
    echo "Converting reciprocal link settings...\n";
    flush();
    $DB->Update('DELETE FROM `tx_reciprocals`');
    IniParse("{$_REQUEST['directory']}/data/generalrecips", TRUE, $recips);
    IniParse("{$_REQUEST['directory']}/data/trustedrecips", TRUE, $recips);
    foreach ($recips as $identifier => $html) {
        $regex = 0;
        if (strpos($html, '*') !== FALSE) {
            $regex = 1;
            $html = preg_quote($html);
            $html = str_replace('\\*', '.*?', $html);
        }
        $DB->Update('INSERT INTO `tx_reciprocals` VALUES (?,?,?,?)', array(null, $identifier, trim($html), $regex));
    }
    //
    // Dump icons
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting icons...\n");
    echo "Converting icons...\n";
    flush();
    $icons = array();
    $DB->Update('DELETE FROM `tx_icons`');
    IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini);
    foreach ($icons_ini as $identifier => $html) {
        $identifier = trim($identifier);
        $html = trim($html);
        if (empty($identifier) || empty($html)) {
            continue;
        }
        $DB->Update('INSERT INTO `tx_icons` VALUES (?,?,?)', array(null, $identifier, trim($html)));
        $icons[$identifier] = $DB->InsertID();
    }
    //
    // Dump categories
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n");
    echo "Converting categories...\n";
    flush();
    $cat_format = array('Name', 'Type', 'Ext_Pictures', 'Ext_Movies', 'Min_Pictures', 'Min_Movies', 'Max_Pictures', 'Max_Movies', 'Size_Pictures', 'Size_Movies');
    $categories = array();
    $category_ids = array();
    $DB->Update('DELETE FROM `tx_categories`');
    $lines = file("{$_REQUEST['directory']}/data/dbs/categories");
    foreach ($lines as $line) {
        $line = trim($line);
        if (empty($line)) {
            continue;
        }
        $category = explode('|', $line);
        foreach ($cat_format as $index => $key) {
            $category[$key] = $category[$index];
        }
        $tag = CreateCategoryTag($category['Name']);
        $categories[$category['Name']] = $tag;
        $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, $category['Type'] != 'Movies' ? 1 : 0, $category['Ext_Pictures'], $category['Min_Pictures'], $category['Max_Pictures'], $category['Size_Pictures'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, null, $category['Type'] != 'Pictures' ? 1 : 0, $category['Ext_Movies'], $category['Min_Movies'], $category['Max_Movies'], $category['Size_Movies'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, null, -1, 0, null, null, null));
        $category_ids[$category['Name']] = $DB->InsertID();
    }
    //
    // Dump gallery data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n");
    echo "Converting gallery data...\n";
    flush();
    $DB->Update('DELETE FROM `tx_galleries`');
    $DB->Update('DELETE FROM `tx_gallery_fields`');
    $DB->Update('DELETE FROM `tx_gallery_icons`');
    $DB->Update('DELETE FROM `tx_gallery_previews`');
    $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0');
    $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0');
    $gal_format = array('Gallery_ID', 'Email', 'Gallery_URL', 'Description', 'Thumbnails', 'Category', 'Nickname', 'Submit_Date', 'Approve_Date', 'Display_Date', 'Display_Stamp', 'Confirm_ID', 'Account_ID', 'CPanel_ID', 'Submit_IP', 'Gallery_IP', 'Scanned', 'Links', 'Has_Recip', 'Page_Bytes', 'Icons');
    $gal_dbs = array('unconfirmed' => 'unconfirmed', 'pending' => 'pending', 'approved' => 'used', 'archived' => 'used');
    foreach (array_keys($categories) as $cat_name) {
        $gal_dbs[preg_replace('~[^a-z0-9]~i', '', strtolower($cat_name))] = 'used';
    }
    foreach ($gal_dbs as $db => $status) {
        $db_file = "{$_REQUEST['directory']}/data/dbs/{$db}";
        if (is_file($db_file)) {
            $lines = file($db_file);
            foreach ($lines as $line) {
                $line = trim($line);
                if (empty($line)) {
                    continue;
                }
                $gallery = explode('|', $line);
                foreach ($gal_format as $index => $key) {
                    $gallery[$key] = $gallery[$index];
                }
                if (!preg_match('!^http(s)?://[\\w-]+\\.[\\w-]+(\\S+)?$!i', $gallery['Gallery_URL'])) {
                    continue;
                }
                $has_thumb = is_file("{$vars['THUMB_DIR']}/{$gallery['Gallery_ID']}.jpg");
                $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], null, $gallery['Thumbnails'], $gallery['Email'], $gallery['Nickname'], $C['gallery_weight'], 0, $gallery['Submit_IP'], $gallery['Gallery_IP'], null, 'submitted', FMT_PICTURES, $status, null, "{$gallery['Submit_Date']} 12:00:00", "{$gallery['Submit_Date']} 12:00:00", empty($gallery['Approve_Date']) ? null : "{$gallery['Approve_Date']} 12:00:00", null, empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", null, $gallery['Account_ID'], $gallery['CPanel_ID'], null, null, $gallery['Has_Recip'], $has_thumb ? 1 : 0, 1, 1, 0, 0, 0, null, MIXED_CATEGORY . " " . $categories[$gallery['Category']]));
                $gallery_id = $DB->InsertID();
                $gallery_info = array('gallery_id' => $gallery_id);
                $insert = CreateUserInsert('tx_gallery_fields', $gallery_info);
                $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
                foreach (explode(',', $gallery['Icons']) as $icon_id) {
                    if (isset($icons[$icon_id])) {
                        $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id]));
                    }
                }
                if (!empty($has_thumb)) {
                    $dimensions = $vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT'];
                    $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions));
                    $preview_id = $DB->InsertID();
                    $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg";
                    $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id));
                    @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg");
                }
            }
        }
    }
    //
    // Convert permanent gallery data
    $perm_format = array('Permanent_ID', 'Gallery_URL', 'Category', 'Thumbnails', 'Description', 'Nickname', 'Location', 'Thumbnail_URL', 'Start_Date', 'Expire_Date');
    $lines = file("{$_REQUEST['directory']}/data/dbs/permanent");
    foreach ($lines as $line) {
        $line = trim($line);
        if (empty($line)) {
            continue;
        }
        $gallery = explode('|', $line);
        foreach ($perm_format as $index => $key) {
            $gallery[$key] = $gallery[$index];
        }
        if (!preg_match('!^http(s)?://[\\w-]+\\.[\\w-]+(\\S+)?$!i', $gallery['Gallery_URL'])) {
            continue;
        }
        $has_thumb = is_file("{$vars['THUMB_DIR']}/p{$gallery['Permanent_ID']}.jpg");
        $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], null, $gallery['Thumbnails'], $C['from_email'], $gallery['Nickname'], $C['gallery_weight'], 0, $_SERVER['REMOTE_ADDR'], null, null, 'permanent', FMT_PICTURES, 'approved', null, MYSQL_NOW, MYSQL_NOW, MYSQL_NOW, null, null, null, null, 'AGP Import', null, null, 0, $has_thumb ? 1 : 0, 1, 1, 0, 0, 0, null, MIXED_CATEGORY . " " . $categories[$gallery['Category']]));
        $gallery_id = $DB->InsertID();
        $gallery_info = array('gallery_id' => $gallery_id);
        $insert = CreateUserInsert('tx_gallery_fields', $gallery_info);
        $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $gallery['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id]));
            }
        }
        if (!empty($has_thumb)) {
            $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT']));
            $preview_id = $DB->InsertID();
            $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg";
            $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id));
            @rename("{$C['preview_dir']}/t_p{$gallery['Permanent_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg");
        }
    }
    //
    // Dump partner data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting partner accounts...\n");
    echo "Converting partner accounts...\n";
    flush();
    $DB->Update('DELETE FROM `tx_partners`');
    $DB->Update('DELETE FROM `tx_partner_fields`');
    $DB->Update('DELETE FROM `tx_partner_icons`');
    $DB->Update('DELETE FROM `tx_partner_confirms`');
    $acct_format = array('Account_ID', 'Password', 'Email', 'Allowed', 'Auto_Approve', 'Recip', 'Blacklist', 'HTML', 'Icons');
    $lines = file("{$_REQUEST['directory']}/data/dbs/accounts");
    foreach ($lines as $line) {
        $line = trim($line);
        if (empty($line)) {
            continue;
        }
        $partner = explode('|', $line);
        foreach ($acct_format as $index => $key) {
            $partner[$key] = $partner[$index];
        }
        $DB->Update('INSERT INTO `tx_partners` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($partner['Account_ID'], sha1($partner['Password']), '', $partner['Email'], null, MYSQL_NOW, null, null, null, $partner['Allowed'], $C['gallery_weight'], null, 0, null, 0, 0, 0, 'active', null, null, 0, $partner['Recip'] ? 0 : 1, $partner['Auto_Approve'], 1, $partner['Blacklist'] ? 0 : 1));
        $partner_info = array('username' => $partner['Account_ID']);
        $insert = CreateUserInsert('tx_partner_fields', $partner_info);
        $DB->Update('INSERT INTO `tx_partner_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $partner['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tx_partner_icons` VALUES (?,?)', array($partner['Account_ID'], $icons[$icon_id]));
            }
        }
    }
    // Update the stored thumbnail preview sizes
    UpdateThumbSizes($vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT']);
    //
    // Dump TGP page data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n");
    echo "Converting TGP pages...\n";
    flush();
    $build_order = 1;
    $DB->Update('DELETE FROM `tx_pages`');
    $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0');
    $pages = GetPageList($vars, $categories);
    foreach ($pages as $page) {
        $template = file_get_contents($page['template']);
        $template = trim(ConvertTemplate($template, $page['arch']));
        $compiled = '';
        $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, $page['file'], $page['url'], $page['category'] == 'Mixed' ? null : $category_ids[$page['category']], $build_order++, 0, null, $template, $compiled));
    }
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!");
    echo "\nData conversion complete!\n";
    if (!$from_shell) {
        echo "</pre>";
    }
}
コード例 #9
0
ファイル: partner.php プロジェクト: Cyberspace-Networks/TGPX
function txPartnerRequestAdd()
{
    global $C, $DB, $L, $t, $domain;
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['name'], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $L['YOUR_NAME']));
    $v->Register($_REQUEST['username'], V_REGEX, $L['INVALID_USERNAME'], '~^[a-z0-9_]+~i');
    $v->Register($_REQUEST['username'], V_LENGTH, sprintf($L['USERNAME_LENGTH'], 3, 32), '3,32');
    // Validation of user defined fields
    $fields =& GetUserPartnerFields();
    foreach ($fields as $field) {
        if ($field['on_request']) {
            if ($field['required_request']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $field['label']));
            }
            if (!IsEmptyString($_REQUEST[$field['name']]) && $field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Check captcha code
    if ($C['request_captcha']) {
        VerifyCaptcha($v);
    }
    // Check if this username exists
    if ($DB->Count('SELECT COUNT(*) FROM `tx_partners` WHERE `username`=?', array($_REQUEST['username']))) {
        $v->SetError($L['USERNAME_TAKEN']);
    }
    // Check if this e-mail address already exists
    if ($DB->Count('SELECT COUNT(*) FROM `tx_partners` WHERE `email`=?', array($_REQUEST['email']))) {
        $v->SetError($L['EXISTING_REQUEST']);
    }
    // Check blacklist
    $blacklisted = CheckBlacklistPartner($_REQUEST);
    if ($blacklisted !== FALSE) {
        $v->SetError(sprintf($blacklisted[0]['reason'] ? $L['BLACKLISTED_REASON'] : $L['BLACKLISTED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
    }
    if (!$v->Validate()) {
        return $v->ValidationError('txShPartnerRequest', TRUE);
    }
    // Insert partner data
    $DB->Update('INSERT INTO `tx_partners` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($_REQUEST['username'], sha1(RandomPassword()), $_REQUEST['name'], $_REQUEST['email'], $_SERVER['REMOTE_ADDR'], MYSQL_NOW, null, null, null, $C['submissions_per_person'], $C['gallery_weight'], null, 0, null, 0, 0, 0, 'pending', null, null, 0, 0, 0, 1, 0));
    // Insert user-defined fields
    $query_data = CreateUserInsert('tx_partner_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tx_partner_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    $t->assign_by_ref('request', $_REQUEST);
    $t->assign_by_ref('user_fields', $fields);
    $t->display($domain['template_prefix'] . 'partner-request-complete.tpl');
    // See if we need to e-mail any administrators
    $requests_waiting = $DB->Count('SELECT COUNT(*) FROM `tx_partners` WHERE `status`=?', array('pending'));
    $t->assign('requests_waiting', $requests_waiting);
    $administrators =& $DB->FetchAll('SELECT * FROM `tx_administrators`');
    foreach ($administrators as $administrator) {
        if ($administrator['requests_waiting'] > 0) {
            if ($administrator['notifications'] & E_PARTNER_REQUEST && $requests_waiting % $administrator['requests_waiting'] == 0) {
                SendMail($administrator['email'], 'email-admin-requests.tpl', $t);
            }
        }
    }
}
コード例 #10
0
ファイル: arphp-convert.php プロジェクト: hackingman/ToplistX
function ConvertData()
{
    global $C, $DB, $from_shell;
    $errors = array();
    if (!is_dir($_REQUEST['directory'])) {
        $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server";
        return DisplayMain($errors);
    }
    if (!is_file("{$_REQUEST['directory']}/arphp.php")) {
        $errors[] = "The arphp.php file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory";
        return DisplayMain($errors);
    }
    if (!is_readable("{$_REQUEST['directory']}/arphp.php")) {
        $errors[] = "The arphp.php file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading";
        return DisplayMain($errors);
    }
    // Check version
    $version_file_contents = file_get_contents("{$_REQUEST['directory']}/common.php");
    if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) {
        list($a, $b, $c) = explode('.', $matches[1]);
        if ($a < 3) {
            $errors[] = "Your AutoRank PHP installation is outdated; please upgrade to the 3.0.x series";
            return DisplayMain($errors);
        }
    } else {
        $errors[] = "Unable to extract version information from arphp.php; your version of AutoRank PHP is likely too old";
        return DisplayMain($errors);
    }
    // Extract variables
    $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables");
    if ($mysql_file_contents === FALSE) {
        $errors[] = "Unable to read contents of the variables file";
        return DisplayMain($errors);
    }
    $vars = array();
    if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $vars[$match[1]] = $match[2];
        }
    }
    if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) {
        $errors[] = "Unable to extract MySQL database information from the variables file";
        return DisplayMain($errors);
    }
    $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']);
    $CONVERTDB->Connect();
    $CONVERTDB->Update('SET `wait_timeout`=86400');
    if (!$from_shell) {
        echo "<pre>";
    }
    //
    // Copy banners
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying member account banners...\n");
    echo "Copying member account banners...\n";
    flush();
    $banners =& DirRead($vars['BANNER_DIR'], '\\.(png|jpg|gif|bmp)$');
    foreach ($banners as $banner) {
        @copy("{$vars['BANNER_DIR']}/{$banner}", "{$C['banner_dir']}/{$banner}");
        @chmod("{$C['banner_dir']}/{$banner}", 0666);
    }
    //
    // Dump categories
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n");
    echo "Converting categories...\n";
    flush();
    $categories = array();
    $category_ids = array();
    $DB->Update('DELETE FROM `tlx_categories`');
    $DB->Update('ALTER TABLE `tlx_categories` AUTO_INCREMENT=0');
    foreach (explode(',', $vars['CATEGORIES']) as $category) {
        $DB->Update('INSERT INTO `tlx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category, 0, $vars['FORWARD_URL'], null, $vars['BANNER_WIDTH'], $vars['BANNER_HEIGHT'], $vars['BANNER_SIZE'], intval($vars['O_FORCE_DIMS']), intval($vars['O_CHECK_DIMS']), intval($vars['O_SERVE_BANNERS']), 1, 1, $vars['MAX_TITLE'], 1, $vars['MAX_DESC'], intval($vars['O_REQ_RECIP'])));
        $category_ids[$category] = $DB->InsertID();
    }
    //
    // Import icons
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account icons...\n");
    echo "Converting account icons...\n";
    flush();
    $DB->Update('DELETE FROM `tlx_icons`');
    $DB->Update('ALTER TABLE `tlx_icons` AUTO_INCREMENT=0');
    IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini);
    $icons = array();
    foreach ($icons_ini as $key => $value) {
        $DB->Update('INSERT INTO `tlx_icons` VALUES (?,?,?)', array(null, $key, trim($value)));
        $icons[$key] = $DB->InsertID();
    }
    //
    // Import user defined fields
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting user defined database fields...\n");
    echo "Converting user defined database fields...\n";
    flush();
    $DB->Update('DELETE FROM `tlx_account_field_defs`');
    $DB->Update('ALTER TABLE `tlx_account_field_defs` AUTO_INCREMENT=0');
    $DB->Update('DROP TABLE IF EXISTS `tlx_account_fields`');
    $DB->Update('CREATE TABLE `tlx_account_fields` (`username` CHAR(32) NOT NULL PRIMARY KEY)');
    for ($i = 1; $i <= 3; $i++) {
        if (!IsEmptyString($vars["NAME_FIELD_{$i}"])) {
            $DB->Update('INSERT INTO `tlx_account_field_defs` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, "user_field_{$i}", $vars["NAME_FIELD_{$i}"], FT_TEXT, null, null, 0, null, null, 1, intval($vars["O_REQ_FIELD_{$i}"]), 1, intval($vars["O_REQ_FIELD_{$i}"])));
            $DB->Update("ALTER TABLE `tlx_account_fields` ADD COLUMN # TEXT", array("user_field_{$i}"));
        }
    }
    //
    // Dump account data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account data...\n");
    echo "Converting account data...\n";
    flush();
    $DB->Update('DELETE FROM `tlx_accounts`');
    $DB->Update('DELETE FROM `tlx_account_hourly_stats`');
    $DB->Update('DELETE FROM `tlx_account_daily_stats`');
    $DB->Update('DELETE FROM `tlx_account_country_stats`');
    $DB->Update('DELETE FROM `tlx_account_referrer_stats`');
    $DB->Update('DELETE FROM `tlx_account_icons`');
    $DB->Update('DELETE FROM `tlx_account_comments`');
    $DB->Update('DELETE FROM `tlx_account_ranks`');
    $result = $CONVERTDB->Query('SELECT * FROM `arphp_Accounts`');
    while ($account = $CONVERTDB->NextRow($result)) {
        $parsed_url = parse_url($account['Site_URL']);
        $account['Domain'] = preg_replace('~^www\\.~i', '', $parsed_url['host']);
        $account['Banner_URL'] = str_replace($vars['BANNER_URL'], $C['banner_url'], $account['Banner_URL']);
        $DB->Update('INSERT INTO `tlx_accounts` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($account['Username'], $account['Email'], $account['Site_URL'], $account['Domain'], $account['Banner_URL'], $account['Banner_URL'], $account['Banner_Height'], $account['Banner_Width'], $account['Title'], $account['Description'], null, date(DF_DATETIME, $account['Signup']), date(DF_DATETIME, $account['Signup']), null, sha1($account['Password']), $C['return_percent'], STATUS_ACTIVE, intval($account['Locked']), intval($account['Suspended']), 0, $category_ids[$account['Category']], 0, 0, $account['Num_Ratings'], $account['Rating_Total'], $account['Inactive'], null, $account['Comments']));
        $stats = array_merge(array($account['Username']), array_fill(0, 127, 0));
        $DB->Update('INSERT INTO `tlx_account_hourly_stats` VALUES (' . CreateBindList($stats) . ')', $stats);
        $account_info = array('username' => $account['Username'], 'user_field_1' => $account['Field_1'], 'user_field_2' => $account['Field_2'], 'user_field_3' => $account['Field_3']);
        $insert = CreateUserInsert('tlx_account_fields', $account_info);
        $DB->Update('INSERT INTO `tlx_account_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']);
        foreach (explode(',', $account['Icons']) as $icon_id) {
            if (isset($icons[$icon_id])) {
                $DB->Update('INSERT INTO `tlx_account_icons` VALUES (?,?)', array($account['Username'], $icons[$icon_id]));
            }
        }
    }
    $CONVERTDB->Free($result);
    //
    // Dump account comments
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account comments...\n");
    echo "Converting account comments...\n";
    flush();
    $DB->Update('DELETE FROM `tlx_account_comments`');
    $result = $CONVERTDB->Query('SELECT * FROM `arphp_Comments`');
    while ($comment = $CONVERTDB->NextRow($result)) {
        $DB->Update('INSERT INTO `tlx_account_comments` VALUES (?,?,?,?,?,?,?,?)', array(null, $comment['Username'], date(DF_DATETIME, $comment['Timestamp']), $comment['IP'], $comment['Name'], $comment['Email'], strtolower($comment['Status']), $comment['Comment']));
    }
    $CONVERTDB->Free($result);
    //
    // Dump ranking page data
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting ranking pages...\n");
    echo "Converting ranking pages...\n";
    flush();
    $build_order = 1;
    $DB->Update('DELETE FROM `tlx_pages`');
    $DB->Update('ALTER TABLE `tlx_pages` AUTO_INCREMENT=0');
    $result = $CONVERTDB->Query('SELECT * FROM `arphp_Pages`');
    while ($page = $CONVERTDB->NextRow($result)) {
        $template = file_get_contents("{$_REQUEST['directory']}/data/pages/{$page['Identifier']}");
        $template = ConvertTemplate($template);
        $compiled = '';
        $DB->Update('INSERT INTO `tlx_pages` VALUES (?,?,?,?,?,?,?)', array(null, "tlx_pages/{$page['Identifier']}.html", $page['category'] == 'Mixed' ? null : $category_ids[$page['category']], $build_order++, null, $template, $compiled));
    }
    $CONVERTDB->Free($result);
    FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!");
    echo "\nData conversion complete!\n";
    if (!$from_shell) {
        echo "</pre>";
    }
    $CONVERTDB->Disconnect();
}
コード例 #11
0
function ImportFromRss($feed)
{
    global $DB, $C;
    $settings = unserialize($feed['settings']);
    $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=?', array($settings['category']));
    $columns = $DB->GetColumns('tx_gallery_fields');
    $imported = 0;
    $defaults = array('gallery_url' => null, 'description' => null, 'keywords' => null, 'thumbnails' => 0, 'email' => $C['from_email'], 'nickname' => null, 'weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => GetIpFromUrl($feed['feed_url']), 'gallery_ip' => '', 'sponsor_id' => !empty($feed['sponsor_id']) ? $feed['sponsor_id'] : null, 'type' => $settings['type'], 'format' => $settings['format'], 'status' => $settings['status'], 'previous_status' => null, 'date_scanned' => null, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'partner' => null, 'administrator' => $_SERVER['REMOTE_USER'], 'admin_comments' => null, 'page_hash' => null, 'has_recip' => 0, 'has_preview' => 0, 'allow_scan' => 1, 'allow_preview' => 1, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => null, 'categories' => MIXED_CATEGORY . " " . $category['tag'], 'preview_url' => null, 'dimensions' => null);
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $http = new Http();
    if ($http->Get($feed['feed_url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($rss = $parser->Parse($http->body)) !== FALSE) {
            foreach ($rss['items'] as $item) {
                $gallery = array();
                $gallery['gallery_url'] = html_entity_decode($item[$settings['gallery_url_from']]);
                $gallery['description'] = html_entity_decode($item[$settings['description_from']]);
                if (!empty($settings['date_added_from'])) {
                    if (($timestamp = strtotime($item[$settings['date_added_from']])) !== FALSE) {
                        $gallery['date_added'] = date(DF_DATETIME, $timestamp);
                    }
                }
                if (!empty($settings['preview_from'])) {
                    if (!is_array($item[$settings['preview_from']])) {
                        $item[$settings['preview_from']] = array($item[$settings['preview_from']]);
                    }
                    foreach ($item[$settings['preview_from']] as $item_value) {
                        if (preg_match('~(http://[^>< ]+\\.(jpg|png))~i', $item_value, $matches)) {
                            $gallery['preview_url'] = $matches[1];
                            break;
                        }
                    }
                }
                // Remove HTML tags and trim the description
                $gallery['description'] = trim(strip_tags($gallery['description']));
                // Merge with the defaults
                $gallery = array_merge($defaults, $gallery);
                // Skip over duplicate or empty URLs
                if ($DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `gallery_url`=?', array($gallery['gallery_url'])) || IsEmptyString($gallery['gallery_url'])) {
                    continue;
                }
                $imported++;
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $gallery['has_preview'] = 1;
                }
                // Add regular fields
                $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $gallery['gallery_url'], $gallery['description'], $gallery['keywords'], $gallery['thumbnails'], $gallery['email'], $gallery['nickname'], $gallery['weight'], $gallery['clicks'], $gallery['submit_ip'], $gallery['gallery_ip'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['previous_status'], $gallery['date_scanned'], $gallery['date_added'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_displayed'], $gallery['date_deletion'], $gallery['partner'], $gallery['administrator'], $gallery['admin_comments'], $gallery['page_hash'], $gallery['has_recip'], $gallery['has_preview'], $gallery['allow_scan'], $gallery['allow_preview'], $gallery['times_selected'], $gallery['used_counter'], $gallery['build_counter'], $gallery['tags'], $gallery['categories']));
                $gallery['gallery_id'] = $DB->InsertID();
                // Add user defined fields
                $query_data = CreateUserInsert('tx_gallery_fields', $gallery, $columns);
                $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery['gallery_id'], $gallery['preview_url'], $gallery['dimensions']));
                }
            }
        }
        $DB->Update('UPDATE `tx_rss_feeds` SET `date_last_import`=? WHERE `feed_id`=?', array(MYSQL_NOW, $feed['feed_id']));
    } else {
        return "Could not access the RSS feed: " . $http->errstr;
    }
    return $imported;
}
コード例 #12
0
ファイル: index.php プロジェクト: hackingman/TGPX
function txGalleryAdd()
{
    global $DB, $C;
    VerifyPrivileges(P_GALLERY_ADD);
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, 'The E-mail Address is not properly formatted');
    $v->Register($_REQUEST['gallery_url'], V_URL, 'The Gallery URL is not properly formatted');
    $v->Register($_REQUEST['date_scheduled'], V_DATETIME, 'The Scheduled Date is not properly formatted');
    $v->Register($_REQUEST['date_deletion'], V_DATETIME, 'The Delete Date is not properly formatted');
    if ($_REQUEST['status'] == 'used' || $_REQUEST['status'] == 'holding') {
        $v->Register($_REQUEST['date_displayed'], V_EMPTY, 'The Displayed Date must be filled in');
        $v->Register($_REQUEST['date_displayed'], V_DATETIME, 'The Displayed Date is not properly formatted');
    }
    if (!IsEmptyString($_REQUEST['partner'])) {
        $partner = $DB->Row('SELECT * FROM `tx_partners` WHERE `username`=?', array($_REQUEST['partner']));
        if (!$partner) {
            $v->SetError('The Partner username you entered does not match an existing partner account');
        }
    }
    // Check tags for proper format
    if (!IsEmptyString($_REQUEST['tags'])) {
        $_REQUEST['tags'] = FormatSpaceSeparated($_REQUEST['tags']);
        foreach (explode(' ', $_REQUEST['tags']) as $tag) {
            if (strlen($tag) < 4 || !preg_match('~^[a-z0-9_]+$~i', $tag)) {
                $v->SetError('All tags must be at least 4 characters in length and contain only letters, numbers, and underscores');
                break;
            }
        }
    }
    if (!$v->Validate()) {
        return $v->ValidationError('txShGalleryAdd');
    }
    // Get the primary category (first one selected)
    $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=?', array($_REQUEST['categories'][0]));
    // Check if whitelisted
    $whitelisted = MergeWhitelistOptions(CheckWhitelist($_REQUEST), $partner);
    // Scan gallery
    $scan =& ScanGallery($_REQUEST, $category, $whitelisted);
    // If approved, set date approved
    $date_approved = null;
    if ($_REQUEST['status'] == 'approved') {
        $date_approved = MYSQL_NOW;
        $DB->Update('UPDATE `tx_administrators` SET `approved`=`approved`+1 WHERE `username`=?', array($_SERVER['REMOTE_USER']));
    }
    NullIfEmpty($_REQUEST['date_scheduled']);
    NullIfEmpty($_REQUEST['date_displayed']);
    NullIfEmpty($_REQUEST['date_deletion']);
    // Add gallery data to the database
    $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $_REQUEST['gallery_url'], $_REQUEST['description'], FormatSpaceSeparated($_REQUEST['keywords']), IsEmptyString($_REQUEST['thumbnails']) ? $scan['thumbnails'] : $_REQUEST['thumbnails'], $_REQUEST['email'], $_REQUEST['nickname'], $_REQUEST['weight'], $_REQUEST['clicks'], $_REQUEST['submit_ip'], $scan['gallery_ip'], $_REQUEST['sponsor_id'], $_REQUEST['type'], IsEmptyString($_REQUEST['format']) ? $scan['format'] : $_REQUEST['format'], $_REQUEST['status'], null, MYSQL_NOW, MYSQL_NOW, $date_approved, $_REQUEST['date_scheduled'], $_REQUEST['date_displayed'], $_REQUEST['date_deletion'], $_REQUEST['partner'], $_SERVER['REMOTE_USER'], $_REQUEST['admin_comments'], $scan['page_hash'], 0, intval($scan['has_recip']), intval($_REQUEST['allow_scan']), intval($_REQUEST['allow_preview']), 0, 1, 1, FormatSpaceSeparated($_REQUEST['tags']), CategoryTagsFromIds($_REQUEST['categories'])));
    // Add user defined fields
    $_REQUEST['gallery_id'] = $DB->InsertID();
    $query_data = CreateUserInsert('tx_gallery_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tx_gallery_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 `tx_gallery_icons` VALUES (?,?)', array($_REQUEST['gallery_id'], $icon_id));
        }
    }
    // Update partner submit count, if applicable
    if (isset($_REQUEST['partner'])) {
        $DB->Update('UPDATE `tx_partners` SET `submitted`=`submitted`+1 WHERE `username`=?', array($_REQUEST['partner']));
    }
    // Warn that the gallery URL is not working
    if (!$scan['success']) {
        $GLOBALS['warn'][] = 'The gallery URL does not seem to be working: ' . $scan['errstr'];
    }
    // Warn that the gallery has no thumbs
    if ($scan['thumbnails'] < 1) {
        $GLOBALS['warn'][] = 'No thumbnails could be found on the gallery';
    }
    $GLOBALS['message'] = 'New gallery successfully added';
    $GLOBALS['added'] = true;
    UnsetArray($_REQUEST);
    txShGalleryAdd();
}
コード例 #13
0
ファイル: index.php プロジェクト: hackingman/ToplistX
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();
}