Esempio n. 1
0
function publish($site, $link)
{
    global $globals, $db;
    $site_info = SitesMgr::get_info($site);
    if (DEBUG) {
        return;
    }
    // Calculate votes average
    // it's used to calculate and check future averages
    $votes_avg = (double) $db->get_var("select SQL_NO_CACHE avg(vote_value) from votes, users where vote_type='links' AND vote_link_id={$link->id} and vote_user_id > 0 and vote_value > 0 and vote_user_id = user_id and user_level !='disabled'");
    if ($votes_avg < $globals['users_karma_avg']) {
        $link->votes_avg = max($votes_avg, $globals['users_karma_avg'] * 0.97);
    } else {
        $link->votes_avg = $votes_avg;
    }
    $link->status = 'published';
    $link->date = $link->published_date = time();
    $db->transaction();
    $db->query("update links set link_status='published', link_date=now(), link_votes_avg={$link->votes_avg} where link_id={$link->id}");
    SitesMgr::deploy($link);
    $db->commit();
    // Increase user's karma
    $user = new User($link->author);
    if ($site_info->sub) {
        $karma_bonus = $globals['instant_karma_per_published'] / 10;
        // currently these published don't receive extra karma
        $log = false;
    } else {
        $karma_bonus = $globals['instant_karma_per_published'];
        $log = _('noticia publicada');
    }
    if ($user->read) {
        $user->add_karma($karma_bonus, $log);
    }
    // Add the publish event/log
    Log::insert('link_publish', $link->id, $link->author);
    $link->annotation .= _('publicación') . "<br/>";
    $link->save_annotation('link-karma');
    // read twitter and facebok configuration from subs' extended info
    if (!$site_info->sub || $site_info->visible) {
        // Only post if it's not a sub or it's visible (dmnm in mnm, f.e.)
        syslog(LOG_INFO, "Meneame, calling: " . dirname(__FILE__) . "/post_link.php {$site_info->name} {$link->id}");
        passthru(dirname(__FILE__) . "/post_link.php {$site_info->name} {$link->id} published");
    }
    // Publish the links of the source subs
    if ($site_info->meta && ($senders = SitesMgr::get_senders($site))) {
        if (in_array($link->sub_id, $senders) && $link->sub_status_origen == 'queued') {
            syslog(LOG_INFO, "Meneame, publishing for sender {$link->sub_name} ({$link->sub_id})");
            // "Simulate" the other site, needed for deploy
            SitesMgr::__init($link->sub_id);
            publish($link->sub_id, $link);
            SitesMgr::__init($site);
            // Back to the original site
        }
    }
    return;
}
Esempio n. 2
0
$time = intval($time_f);
$dbtime = date("YmdHis", intval($time));
$last_timestamp = $time_f;
if (!empty($_REQUEST['site_id']) && $_REQUEST['site_id'] > 0) {
    $globals['site_id'] = intval($_REQUEST['site_id']);
}
if (!empty($_REQUEST['items']) && intval($_REQUEST['items']) > 0) {
    $max_items = intval($_REQUEST['items']);
}
if ($max_items < 1 || $max_items > 100) {
    $max_items = 100;
    // Avoid abuse
}
// Get the logs by sub, if it's a sub
if ($globals['submnm']) {
    $subs = array_merge(array(SitesMgr::my_id()), SitesMgr::get_senders(), SitesMgr::get_receivers());
    $globals['subs'] = $subs = implode(',', $subs);
    $site_filter = "and log_sub in ({$subs})";
} else {
    $site_filter = '';
}
if (empty($_REQUEST['novote']) || empty($_REQUEST['noproblem'])) {
    get_votes($dbtime);
}
$logs = $db->get_results("select UNIX_TIMESTAMP(log_date) as time, log_type, log_ref_id, log_user_id from logs where log_type != 'login_failed' and log_date > {$dbtime} {$site_filter} order by log_date desc limit {$max_items}");
if ($logs) {
    foreach ($logs as $log) {
        if ($current_user->user_id > 0) {
            if (!empty($_REQUEST['friends']) && $log->log_user_id != $current_user->user_id) {
                // Check the user is a friend
                if (User::friend_exists($current_user->user_id, $log->log_user_id) <= 0) {