Exemplo n.º 1
0
function publish($link)
{
    global $globals, $db;
    //return;
    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->query("update links set link_status='published', link_date=now(), link_votes_avg={$link->votes_avg} where link_id={$link->id}");
    SitesMgr::deploy($link);
    // Increase user's karma
    $user = new User($link->author);
    if ($user->read) {
        $user->add_karma($globals['instant_karma_per_published'], _('noticia publicada'));
    }
    // Add the publish event/log
    Log::insert('link_publish', $link->id, $link->author);
    $link->annotation .= _('publicación') . "<br/>";
    $link->save_annotation('link-karma');
    // Publish to all sub sites: this and children who import the link category
    $my_id = SitesMgr::my_id();
    // Get all sites that are "children" and try to post links
    // And that "import" the link->category
    $sites = array_intersect(SitesMgr::get_children($my_id), SitesMgr::get_receivers($link->category));
    // Add my own
    $sites[] = $my_id;
    foreach ($sites as $s) {
        $server_name = SitesMgr::get_info($s)->server_name;
        syslog(LOG_INFO, "Meneame, calling: " . dirname(__FILE__) . "/post_link.php {$server_name} {$link->id}");
        passthru(dirname(__FILE__) . "/post_link.php {$server_name} {$link->id}");
    }
}
Exemplo 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) {