function depublish($site_id) { // send back to queue links with too many negatives global $db, $globals; $days = 4; echo "STARTING depublish for {$site_id}\n"; $site_info = SitesMgr::get_info($site_id); $links = $db->get_col("select SQL_NO_CACHE link_id as id from links, sub_statuses where id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and date < date_sub(now(), interval 14 minute) and link = link_id and link_negatives > link_votes / 5"); if ($links) { $votes_clicks = $db->get_col("select SQL_NO_CACHE link_votes/counter from links, sub_statuses, link_clicks where sub_statuses.id = {$site_id} and status = 'published' and date > date_sub(now(), interval {$days} day) and link = link_id and link_clicks.id = link"); sort($votes_clicks); foreach ($links as $link) { $l = Link::from_db($link); $vc = $l->votes / $l->clicks; $prob = cdf($votes_clicks, $vc); // Count only those votes with karma > 6 to avoid abuses with new accounts with new accounts $negatives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_date > date_sub(now(), interval 24 hour) and vote_value < 0 and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_negative_karma']); $positives = (int) $db->get_var("select SQL_NO_CACHE sum(user_karma) from votes, users where vote_type='links' and vote_link_id={$l->id} and vote_date > from_unixtime({$l->date}) and vote_value > 0 and vote_date > date_sub(now(), interval 24 hour) and vote_user_id > 0 and user_id = vote_user_id and user_karma > " . $globals['depublish_positive_karma']); echo "Candidate {$l->uri}\n karma: {$l->sub_karma} ({$l->karma}) negative karma: {$negatives} positive karma: {$positives}\n"; // Adjust positives to the probability of votes/clicks $c = 1 + (1 - $prob) * 0.5; $positives = $positives * $c; echo " probability: {$prob} New positives: {$positives} ({$c})\n"; if ($negatives > 10 && $negatives > $c * $l->sub_karma / 6 && $l->negatives > $c * $l->votes / 6 && $l->negatives > 5 && ($negatives > $positives || $negatives > $c * $l->sub_karma / 2 && $negatives > $positives / 2)) { echo "Queued again: {$l->id} negative karma: {$negatives} positive karma: {$positives}\n"; $karma_old = $l->sub_karma; $karma_new = intval($l->sub_karma / $globals['depublish_karma_divisor']); $l->status = 'queued'; $l->sub_karma = $l->karma = $karma_new; $db->query("update links set link_status='queued', link_date = link_sent_date, link_karma={$karma_new} where link_id = {$l->id}"); SitesMgr::deploy($l); // Add an annotation to show it in the logs $l->karma_old = $karma_old; $l->karma = $karma_new; $l->annotation = _('Retirada de portada'); $l->save_annotation('link-karma'); Log::insert('link_depublished', $l->id, $l->author); if (!$site_info->sub) { // Add the discard to log/event $user = new User($l->author); if ($user->read) { echo "{$user->username}: {$user->karma}\n"; $user->add_karma(-$globals['instant_karma_per_depublished'], _('Retirada de portada')); } // Increase karma to users that voted negative $ids = $db->get_col("select vote_user_id from votes where vote_type = 'links' and vote_link_id = {$l->id} and vote_user_id > 0 and vote_value < 0"); foreach ($ids as $id) { $u = new User($id); if ($u->read) { // Avoid abuse of users voting negative just to get more karma $voted = $db->get_var("select count(*) from logs where log_type = 'user_depublished_vote' and log_user_id = {$id} and log_date > date_sub(now(), interval 48 hour)"); if ($voted < 5) { $u->add_karma(0.2, _('Negativo a retirada de portada')); Log::insert('user_depublished_vote', $l->id, $id); } } } } /*********** * TODO: call for every site (as in promote) if ($globals['twitter_token'] || $globals['jaiku_user']) { if ($globals['url_shortener']) { $short_url = $l->get_short_permalink(); } else { $short_url = fon_gs($l->get_permalink()); } $text = _('Retirada de portada') . ': ' . $l->title; if ($globals['twitter_user'] && $globals['twitter_token']) { twitter_post($text, $short_url); } if ($globals['jaiku_user'] && $globals['jaiku_key']) { jaiku_post($text, $short_url); } } *******/ } } } }
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}"); } }
function store_basic($really_basic = false) { global $db, $current_user, $globals; if (!$this->date) { $this->date = $globals['now']; } $link_author = $this->author; $link_blog = $this->blog; $link_status = $db->escape($this->status); $link_anonymous = $this->anonymous; $link_karma = $this->karma; $link_votes_avg = $this->votes_avg; $link_randkey = $this->randkey; $link_date = $this->date; $link_sent_date = $this->sent_date; $link_published_date = $this->published_date; $link_content_type = $db->escape($this->content_type); $db->transaction(); if ($this->id === 0) { $this->ip = $globals['user_ip']; $link_ip = $db->escape($this->ip); $this->ip_int = $globals['user_ip_int']; $r = $db->query("INSERT INTO links (link_author, link_blog, link_status, link_randkey, link_date, link_sent_date, link_published_date, link_karma, link_anonymous, link_votes_avg, link_content_type, link_ip_int, link_ip) VALUES ({$link_author}, {$link_blog}, '{$link_status}', {$link_randkey}, FROM_UNIXTIME({$link_date}), FROM_UNIXTIME({$link_sent_date}), FROM_UNIXTIME({$link_published_date}), {$link_karma}, {$link_anonymous}, {$link_votes_avg}, '{$link_content_type}', {$this->ip_int}, '{$link_ip}')"); $this->id = $db->insert_id; } else { // update $r = $db->query("UPDATE links set link_author={$link_author}, link_blog={$link_blog}, link_status='{$link_status}', link_randkey={$link_randkey}, link_date=FROM_UNIXTIME({$link_date}), link_sent_date=FROM_UNIXTIME({$link_sent_date}), link_published_date=FROM_UNIXTIME({$link_published_date}), link_karma={$link_karma}, link_votes_avg={$link_votes_avg}, link_content_type='{$link_content_type}' WHERE link_id={$this->id}"); } if (!$r || !SitesMgr::deploy($this)) { // Deploy changes to other sub sites syslog(LOG_INFO, "failed insert of update in store_basic: {$this->id}"); $db->rollback(); return false; } if (!$really_basic) { if ($this->votes == 1 && $this->negatives == 0 && $this->status == 'queued') { // This is a new link, add it to the events, it an additional control // just in case the user dind't do the last submit phase and voted later Log::conditional_insert('link_new', $this->id, $this->author); } $this->update_votes(); $this->update_comments(); } $db->commit(); return true; }
<?php // This script is to add the statuses values of previous links for multisite support // It must be run for every subsite you have created include '../config.php'; $links = $db->object_iterator("SELECT link_id as id, link_status as status, link_karma as karma, link_category as category, UNIX_TIMESTAMP(link_date) as date, UNIX_TIMESTAMP(link_sent_date) as sent_date, UNIX_TIMESTAMP(link_published_date) as published_date FROM links order by link_id desc", "Link"); if ($links) { $c = 0; $db->transaction(); foreach ($links as $link) { if ($c % 1000 == 0) { echo "{$link->id}, {$link->category}\n"; $db->commit(); usleep(100000); $db->transaction(); } SitesMgr::deploy($link, true); // Force to copy to all receivers $c++; } $db->commit(); }
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; }