/**
 * Enter description here...
 *
 */
function handlePostTrackback($uri, $date)
{
    global $PIVOTX;
    $message = "";
    // Using our integrated Trackback Spam Killer
    killtrackbackspam();
    // Initialise the IP blocklist.
    $blocklist = new IPBlock();
    // checking if IP address of trackbacking site is blocked
    if ($blocklist->isBlocked($_SERVER['REMOTE_ADDR'])) {
        debug("Blocked user from " . $_SERVER['REMOTE_ADDR'] . " tried to trackback");
        respondExit("Your IP-address has been blocked, so you are not" . " allowed to leave trackbacks on this site. We know IP-adresses can easily be faked," . " but it helps.", 1);
    }
    // Get the entry from the DB..
    $entry = $PIVOTX['db']->read_entry($uri, $date);
    // Exit if non-existing ID supplied
    if (empty($entry['code'])) {
        respondExit('Entry not found', 1);
    }
    // Keep original excerpt for spam checks ...
    $orig_excerpt = $_POST['excerpt'];
    // Strip out HTML from input and convert to utf-8.
    $_POST['blog_name'] = i18n_str_to_utf8(strip_tags($_POST['blog_name']));
    $_POST['title'] = i18n_str_to_utf8(strip_tags($_POST['title']));
    $_POST['url'] = strip_tags($_POST['url']);
    if ($PIVOTX['config']->get('allow_html_in_comments') == 1) {
        $_POST['excerpt'] = stripTagsAttributes($_POST['excerpt'], "*");
    } else {
        $_POST['excerpt'] = stripTagsAttributes($_POST['excerpt'], "<b><em><i><strong>");
    }
    $_POST['excerpt'] = i18n_str_to_utf8($_POST['excerpt']);
    $my_trackback = array('entry_uid' => intval($entry['code']), 'name' => $_POST['blog_name'], 'title' => $_POST['title'], 'url' => trim($_POST['url']), 'ip' => $_SERVER['REMOTE_ADDR'], 'date' => formatDate("", "%year%-%month%-%day%-%hour24%-%minute%"), 'excerpt' => trimText($_POST['excerpt'], 255, false, true, false));
    // Exit if no URL is given - need to know URL to foreign entry that
    // trackbacked us.
    if (empty($my_trackback['url'])) {
        respondExit('No URL (url) parameter given', 1);
    }
    //here we do a check to prevent double entries...
    $duplicate = FALSE;
    if (isset($entry['trackbacks']) && count($entry['trackbacks']) > 0) {
        foreach ($entry['trackbacks'] as $loop_trackback) {
            $diff = 1 / (min(strlen($loop_trackback['excerpt']), 200) / (levenshtein(substr($loop_trackback['excerpt'], 0, 200), substr($my_trackback['excerpt'], 0, 200)) + 1));
            if ($diff < 0.25 && $loop_trackback['ip'] == $my_trackback['ip']) {
                $duplicate = TRUE;
                break;
            }
        }
    }
    if (!$duplicate) {
        // update the current entry
        $entry['trackbacks'][] = $my_trackback;
        $post = TRUE;
    } else {
        $message = 'Your trackback has not been stored, because it seems to be a duplicate';
        $post = FALSE;
    }
    if ($PIVOTX['config']->get('maxhrefs') > 0) {
        $low_excerpt = strtolower(trackbackFormat($orig_excerpt));
        if (substr_count($low_excerpt, "href=") > $PIVOTX['config']->get('maxhrefs')) {
            $message = 'The maximum number of hyperlinks was exceeded. Are you spamming us?';
            $post = FALSE;
        }
    }
    if ($post) {
        $PIVOTX['db']->set_entry($entry);
        $PIVOTX['db']->save_entry(FALSE);
        // do not update the index.
        // Remove the compiled/parsed pages from the cache.
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->clear_cache();
        }
        // send mail..
        sendMailTrackback($my_trackback);
        debug("A trackback from '" . $my_trackback['name'] . "' added.");
        //update the 'last trackbacks' file
        if (isset($my_trackback)) {
            generateLastTrackbacks($my_trackback);
        }
        // Clean the simple cache..
        $PIVOTX['cache']->clear();
        // Remove the compiled/parsed pages from the cache.
        if ($PIVOTX['config']->get('smarty_cache')) {
            $PIVOTX['template']->clear_cache();
        }
        // After messing about with the trackbacks, clear the cache.
        $PIVOTX['cache']->cache['entries'] = array();
        respondExit();
    } else {
        respondExit($message, 1);
    }
}
Example #2
0
    $low_trackback = strtolower(trackback_format($my_trackback['excerpt']));
    if (substr_count($low_trackback, "href=") > 2) {
        $message = lang('trackback', 'too_many_hrefs');
        unset($Pivot_Vars['post']);
    }
}
if (isset($Pivot_Vars['post'])) {
    $db->set_entry($entry);
    // send mail..
    send_mail_tb();
    // switch to weblog's language (it might be changed in the meantime)
    LoadWeblogLanguage($Weblogs[$Current_weblog]['language']);
    debug("trackback from '" . $Pivot_Vars['piv_name'] . "' added.");
    $db->save_entry(FALSE);
    // do not update the index.
    //update the 'last trackbacks' file
    if (isset($my_trackback)) {
        generate_last_trackbacks($my_trackback);
    }
    // remove it from cache, to make sure the latest one is used.
    $db->unread_entry($entry['code']);
    // regenerate entry, frontpage and archive..
    generate_pages($Pivot_Vars['tb_id'], TRUE, TRUE, TRUE, FALSE, FALSE);
    add_hook("trackback", "post");
    execute_hook("trackback", "post", $Pivot_Vars, $entry);
    respondExit();
} else {
    add_hook("trackback", "post");
    execute_hook("trackback", "post", $Pivot_Vars, "");
    respondExit($message, 1);
}