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}"); } }
static function duplicates($url) { global $db; $trimmed = $db->escape(preg_replace('/\\/$/', '', $url)); $list = "'{$trimmed}', '{$trimmed}/'"; if (preg_match('/^http.{0,1}:\\/\\/www\\./', $trimmed)) { $link_alternative = preg_replace('/^(http.{0,1}):\\/\\/www\\./', '$1://', $trimmed); } else { $link_alternative = preg_replace('/^(http.{0,1}):\\/\\//', '$1://www.', $trimmed); } $list .= ", '{$link_alternative}', '{$link_alternative}/'"; /* Alternative to http and https */ if (preg_match('/^http:/', $url)) { $list2 = preg_replace('/http:\\/\\//', 'https://', $list); } else { $list2 = preg_replace('/https:\\/\\//', 'http://', $list); } $list .= ", {$list2}"; $site_id = SitesMgr::my_id(); $filter_by_site_sql = "(sub_statuses.id = {$site_id} "; $site_parent = SitesMgr::my_parent(); if ($site_parent > 0 && $site_parent != $site_id) { $filter_by_site_sql .= " OR sub_statuses.id = {$site_parent} "; } $site_children = SitesMgr::get_children($site_id); // array if (is_array($site_children) && count($site_children) > 0) { $filter_by_site_sql .= " OR sub_statuses.id in (" . implode(',', $site_children) . ")"; } $filter_by_site_sql .= ")"; // If it was abuse o autodiscarded allow other to send it again $found = $db->get_var("SELECT link_id FROM links, sub_statuses WHERE link_url in ({$list}) AND link_status not in ('abuse') AND link_votes > 0 AND sub_statuses.link = link_id AND {$filter_by_site_sql} ORDER by link_id asc limit 1"); return $found; }