Beispiel #1
0
/**
* Extract the site title and description from HTML tags
*/
function lxExtractSiteInfo()
{
    global $json, $DB, $C;
    require_once "{$GLOBALS['BASE_DIR']}/includes/htmlparser.class.php";
    $link = array('site_url' => $_REQUEST['url'], 'allow_redirect' => TRUE, 'recip_url' => null);
    $result = ScanLink($link);
    if ($result['site_url']['working']) {
        $parser = new PageParser();
        $parser->parse($result['site_url']['html']);
        $title = mb_convert_encoding($parser->title, 'ISO-8859-1', mb_detect_encoding($parser->title, 'auto'));
        $description = mb_convert_encoding($parser->description, 'ISO-8859-1', mb_detect_encoding($parser->description, 'auto'));
        $keywords = mb_convert_encoding($parser->keywords, 'ISO-8859-1', mb_detect_encoding($parser->keywords, 'auto'));
        echo $json->encode(array('status' => JSON_SUCCESS, 'title' => html_entity_decode(trim($title)), 'description' => html_entity_decode(trim($description)), 'keywords' => trim(FormatKeywords(html_entity_decode($keywords)))));
    } else {
        echo $json->encode(array('status' => JSON_FAILURE));
    }
}
Beispiel #2
0
function lxEditLink()
{
    global $DB, $C, $L, $t;
    $v = new Validator();
    // Make sure user is allowed to edit this link
    $link = $DB->Row('SELECT * FROM lx_links JOIN lx_link_fields USING (link_id) WHERE lx_links.link_id=?', array($_REQUEST['link_id']));
    if ($_REQUEST['noaccount']) {
        if (!empty($link['username']) || $link['site_url'] != $_REQUEST['login_site_url'] || $link['password'] != sha1($_REQUEST['login_password']) || $link['email'] != $_REQUEST['login_email']) {
            $t->assign('error', $L['LINK_EDIT_REFUSED']);
            $t->display('error-nice.tpl');
            return;
        }
    } else {
        $account = ValidUserLogin();
        if (!$account || $account['username'] != $link['username']) {
            $t->assign('error', $L['LINK_EDIT_REFUSED']);
            $t->display('error-nice.tpl');
            return;
        }
    }
    $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, 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=? AND link_id!=?', array($_REQUEST['site_url'], $link['link_id']))) {
        $v->SetError($L['DUPLICATE_URL']);
    }
    // Validation of user defined fields
    $fields =& GetUserLinkFields();
    foreach ($fields as $field) {
        if ($field['on_edit']) {
            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']);
            }
        }
    }
    $_REQUEST['allow_redirect'] = $link['allow_redirect'];
    $_REQUEST['recip_required'] = $link['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']));
    }
    if (!$v->Validate()) {
        $errors = join('<br />', $v->GetErrors());
        lxShEdit($errors);
        return;
    }
    if ($C['approve_link_edits']) {
        $_REQUEST['submit_ip'] = $_SERVER['REMOTE_ADDR'];
        $DB->Update('UPDATE lx_links SET is_edited=1,edit_data=? WHERE link_id=?', array(base64_encode(serialize($_REQUEST)), $link['link_id']));
    } else {
        // Update password, if necessary
        $password = $link['password'];
        if ($_REQUEST['noaccount'] && !empty($_REQUEST['password'])) {
            $password = sha1($_REQUEST['password']);
        }
        // Update link data
        $DB->Update('UPDATE lx_links SET ' . 'site_url=?, ' . 'recip_url=?, ' . 'title=?, ' . 'description=?, ' . 'name=?, ' . 'email=?, ' . 'submit_ip=?, ' . 'keywords=?, ' . 'date_modified=?, ' . 'password=?, ' . 'has_recip=? ' . 'WHERE link_id=?', array($_REQUEST['site_url'], $_REQUEST['recip_url'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['name'], $_REQUEST['email'], $_SERVER['REMOTE_ADDR'], $_REQUEST['keywords'], MYSQL_NOW, $password, $scan_result['has_recip'], $link['link_id']));
        // Update user defined fields
        UserDefinedUpdate('lx_link_fields', 'lx_link_field_defs', 'link_id', $_REQUEST['link_id'], $_REQUEST, FALSE);
    }
    // Get category information
    $categories = array();
    $result = $DB->Query('SELECT * FROM lx_categories JOIN lx_link_cats USING (category_id) WHERE link_id=?', array($link['link_id']));
    while ($category = $DB->NextRow($result)) {
        $category['path_parts'] = unserialize($category['path_parts']);
        $categories[] = $category;
    }
    $DB->Free($result);
    // Show confirmation page
    $t->assign_by_ref('categories', $categories);
    $t->assign_by_ref('user_fields', $fields);
    $t->assign_by_ref('link', $_REQUEST);
    $t->display('submit-edited.tpl');
    flush();
    // Send e-mail to appropriate administrators
    $result = $DB->Query('SELECT * FROM lx_administrators');
    while ($admin = $DB->NextRow($result)) {
        if ($admin['notifications'] & E_LINK_EDIT) {
            SendMail($admin['email'], 'email-admin-link-edit.tpl', $t);
        }
    }
    $DB->Free($result);
}
Beispiel #3
0
function lxEditLink()
{
    global $DB, $C;
    VerifyPrivileges(P_LINK_MODIFY);
    // See if URL already exists
    $url_exists = $DB->Count('SELECT COUNT(*) FROM lx_links WHERE site_url=? AND link_id!=?', array($_REQUEST['site_url'], $_REQUEST['link_id']));
    $validator = new Validator();
    $validator->Register($_REQUEST['email'], V_EMAIL, 'The email address is not properly formatted');
    $validator->Register($_REQUEST['site_url'], V_URL, 'The site URL is not properly formatted');
    $validator->Register($_REQUEST['category_id'], V_EMPTY, 'Please select at least one category for this link');
    $validator->Register($url_exists, V_ZERO, 'This URL is already in the database');
    $validator->Register($_REQUEST['date_added'], V_DATETIME, 'The Date Added field is not properly formatted');
    // Handle improperly formatted expire dates
    if (!empty($_REQUEST['expires'])) {
        $validator->Register($_REQUEST['expires'], V_DATETIME, 'The expiration date is not properly formatted');
    }
    if (!empty($_REQUEST['date_modified'])) {
        $validator->Register($_REQUEST['date_modified'], V_DATETIME, 'The Date Modified field is not properly formatted');
    }
    // Make sure account exists
    if ($_REQUEST['username']) {
        $account = $DB->Row('SELECT * FROM lx_users WHERE username=?', array($_REQUEST['username']));
        $validator->Register($account, V_NOT_FALSE, "No user account exists with the username '{$_REQUEST['username']}'");
    }
    if (!$validator->Validate()) {
        $GLOBALS['errstr'] = join('<br />', $validator->GetErrors());
        lxShEditLink();
        return;
    }
    $link = $DB->Row('SELECT * FROM lx_links WHERE link_id=?', array($_REQUEST['link_id']));
    // Calculate average rating
    $rating_avg = null;
    if ($_REQUEST['ratings'] > 0) {
        $rating_avg = $_REQUEST['rating_total'] / $_REQUEST['ratings'];
    }
    // Encrypt the password
    if (!empty($_REQUEST['password'])) {
        $_REQUEST['password'] = sha1($_REQUEST['password']);
    } else {
        $_REQUEST['password'] = $link['password'];
    }
    if (empty($_REQUEST['expires'])) {
        $_REQUEST['expires'] = DEF_EXPIRES;
    }
    // Scan the link to see if it has a recip
    $scan_result = ScanLink($_REQUEST);
    $has_recip = $scan_result['has_recip'];
    NullIfEmpty($_REQUEST['date_modified']);
    // Update regular fields
    $DB->Update('UPDATE lx_links SET ' . 'site_url=?, ' . 'recip_url=?, ' . 'title=?, ' . 'description=?, ' . 'status=?, ' . 'type=?, ' . 'expires=?, ' . 'name=?, ' . 'email=?, ' . 'submit_ip=?, ' . 'keywords=?, ' . 'clicks=?, ' . 'screenshot=?, ' . 'ratings=?, ' . 'rating_total=?, ' . 'rating_avg=?, ' . 'weight=?, ' . 'date_added=?, ' . 'date_modified=?, ' . 'recip_required=?, ' . 'allow_redirect=?, ' . 'icons=?, ' . 'admin_comments=?, ' . 'username=?, ' . 'password=?, ' . 'has_recip=? ' . 'WHERE link_id=?', array($_REQUEST['site_url'], $_REQUEST['recip_url'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['status'], $_REQUEST['type'], $_REQUEST['expires'], $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['submit_ip'], $_REQUEST['keywords'], $_REQUEST['clicks'], '', $_REQUEST['ratings'], $_REQUEST['rating_total'], $rating_avg, $_REQUEST['weight'], $_REQUEST['date_added'], $_REQUEST['date_modified'], intval($_REQUEST['recip_required']), intval($_REQUEST['allow_redirect']), $_REQUEST['icons'], $_REQUEST['admin_comments'], $_REQUEST['username'], $_REQUEST['password'], $has_recip, $_REQUEST['link_id']));
    // Get current categories this link is located in so the link count can be updated
    $old_categories = array();
    $result = $DB->Query('SELECT * FROM lx_link_cats WHERE link_id=?', array($_REQUEST['link_id']));
    while ($old_category = $DB->NextRow($result)) {
        $old_categories[] = $old_category['category_id'];
    }
    $DB->Free($result);
    // Update category data
    $DB->Update('DELETE FROM lx_link_cats WHERE link_id=?', array($_REQUEST['link_id']));
    foreach (explode(',', $_REQUEST['category_id']) as $category_id) {
        $sorter = $DB->Count('SELECT MAX(sorter) FROM lx_link_cats WHERE category_id=?', array($category_id));
        $DB->Update('INSERT INTO lx_link_cats VALUES (?,?,?)', array($_REQUEST['link_id'], $category_id, $sorter));
        UpdateLinkCount($category_id);
    }
    // Update the link count for the old categories this link was located in
    foreach ($old_categories as $old_category) {
        UpdateLinkCount($old_category);
    }
    // Update user defined fields
    UserDefinedUpdate('lx_link_fields', 'lx_link_field_defs', 'link_id', $_REQUEST['link_id'], $_REQUEST);
    // If username was supplied, update link count
    if ($_REQUEST['username'] != $link['username']) {
        if (!empty($link['username'])) {
            UpdateAccountLinkCount($link['username']);
        }
        if (!empty($_REQUEST['username'])) {
            UpdateAccountLinkCount($_REQUEST['username']);
        }
    }
    // Clear cache
    ClearLinkDetailsCache($_REQUEST['link_id']);
    $GLOBALS['message'] = 'Link has been successfully updated';
    $GLOBALS['added'] = true;
    lxShEditLink();
}
Beispiel #4
0
$total_links = $DB->NumRows($result);
while ($link = $DB->NextRow($result)) {
    $updates = array('placeholders' => array(), 'binds' => array());
    $exception = 0x0;
    $current_link++;
    // Exit if stopped (pid set to 0)
    $pid = $DB->Count('SELECT pid FROM lx_scanner_configs WHERE config_id=?', array($config_id));
    if ($pid == 0) {
        break;
    }
    // Update scanner status
    $DB->Update('UPDATE lx_scanner_configs SET current_status=?,status_updated=? WHERE config_id=?', array("Scanning link {$current_link} of {$total_links}", time(), $config_id));
    // Mark last scan time of the link
    $DB->Update('UPDATE lx_links SET date_scanned=? WHERE link_id=?', array(MYSQL_NOW, $link['link_id']));
    // Scan the link
    $scan_result =& ScanLink($link);
    // Bad URL
    if (!$scan_result['site_url']['working']) {
        // Bad status code
        if (!empty($scan_result['site_url']['status'])) {
            if (preg_match('~^3\\d\\d~', $scan_result['site_url']['status'])) {
                $exception = $exceptions['forward'];
            } else {
                $exception = $exceptions['broken'];
            }
        } else {
            $exception = $exceptions['connect'];
        }
    } else {
        // No reciprocal link found
        if ($link['recip_required'] && !$scan_result['site_url']['has_recip'] && !$scan_result['recip_url']['has_recip']) {