Exemplo n.º 1
0
    /**
     * Returns unix time for an article number.
     *
     * @param int    $post      The article number to get the time from.
     * @param array  $groupData Usenet group info from NNTP selectGroup method.
     *
     * @return int	Timestamp.
     */
    public function postdate($post, array $groupData)
    {
        // Set table names
        $groupID = $this->_groups->getIDByName($groupData['group']);
        $group = [];
        if ($groupID !== '') {
            $group = $this->_groups->getCBPTableNames($this->_tablePerGroup, $groupID);
        }
        $currentPost = $post;
        $attempts = $date = 0;
        do {
            // Try to get the article date locally first.
            if ($groupID !== '') {
                // Try to get locally.
                $local = $this->_pdo->queryOneRow(sprintf('
						SELECT c.date AS date
						FROM %s c
						INNER JOIN %s b ON(c.id=b.collection_id)
						INNER JOIN %s p ON(b.id=p.binaryid)
						WHERE p.number = %s
						%s LIMIT 1', $group['cname'], $group['bname'], $group['pname'], $currentPost, $this->_tablePerGroup === false ? sprintf('AND c.group_id = %d', $groupID) : ''));
                if ($local !== false) {
                    $date = $local['date'];
                    break;
                }
            }
            // If we could not find it locally, try usenet.
            $header = $this->_nntp->getXOVER($currentPost);
            if (!$this->_nntp->isError($header)) {
                // Check if the date is set.
                if (isset($header[0]['Date']) && strlen($header[0]['Date']) > 0) {
                    $date = $header[0]['Date'];
                    break;
                }
            }
            // Try to get a different article number.
            if (abs($currentPost - $groupData['first']) > abs($groupData['last'] - $currentPost)) {
                $tempPost = round($currentPost / (mt_rand(1005, 1012) / 1000), 0, PHP_ROUND_HALF_UP);
                if ($tempPost < $groupData['first']) {
                    $tempPost = $groupData['first'];
                }
            } else {
                $tempPost = round(mt_rand(1005, 1012) / 1000 * $currentPost, 0, PHP_ROUND_HALF_UP);
                if ($tempPost > $groupData['last']) {
                    $tempPost = $groupData['last'];
                }
            }
            // If we got the same article number as last time, give up.
            if ($tempPost === $currentPost) {
                break;
            }
            $currentPost = $tempPost;
            if ($this->_debug) {
                $this->_colorCLI->doEcho($this->_colorCLI->debug('Postdate retried ' . $attempts . " time(s)."));
            }
        } while ($attempts++ <= 20);
        // If we didn't get a date, set it to now.
        if (!$date) {
            $date = time();
        } else {
            $date = strtotime($date);
        }
        if ($this->_debug) {
            $this->_debugging->log(get_class(), __FUNCTION__, 'Article (' . $post . "'s) date is (" . $date . ') (' . $this->daysOld($date) . " days old)", Logger::LOG_INFO);
        }
        return $date;
    }
Exemplo n.º 2
0
<?php

// To troubleshoot what's actually on usenet.
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'indexer.php');
use nzedb\Binaries;
use nzedb\ColorCLI;
use nzedb\NNTP;
$cli = new ColorCLI();
if (!isset($argv[2]) || !is_numeric($argv[2])) {
    exit($cli->error("\nTest your nntp connection, get group information and postdate for specific article.\n\n" . "php {$argv['0']} alt.binaries.teevee 595751142    ...: To test nntp on alt.binaries.teevee with artivle 595751142.\n"));
}
$nntp = new NNTP();
if ($nntp->doConnect() !== true) {
    exit;
}
$first = $argv[2];
$group = $argv[1];
// Select a group.
$groupArr = $nntp->selectGroup($group);
print_r($groupArr);
// Insert actual local part numbers here.
$msg = $nntp->getXOVER($first . '-' . $first);
// Print out the array of headers.
print_r($msg);
// get postdate for an article
$binaries = new Binaries(['NNTP' => $nntp]);
$newdate = $binaries->postdate($first, $groupArr);
echo $cli->primary("The posted date for " . $group . ", article " . $first . " is " . date('Y-m-d H:i:s', $newdate));