コード例 #1
0
ファイル: promote10.php プロジェクト: GallardoAlba/Meneame
function promote_from_subs($destination, $hours, $min_karma, $min_votes)
{
    global $db;
    echo "Promote to main: {$destination}\n";
    $res = $db->get_results("select sub_statuses.*, link_url, link_karma, link_votes from sub_statuses, subs, links where date > date_sub(now(), interval {$hours} hour) and status = 'published' and link_karma >= {$min_karma} and sub_statuses.id = origen and subs.id = sub_statuses.id and subs.created_from = {$destination} and not subs.private and not subs.nsfw and sub_statuses.id not in (select src from subs_copy where dst={$destination}) and {$destination} not in (select id from sub_statuses as t where t.link=sub_statuses.link) and link_id = sub_statuses.link and link_votes >= {$min_votes}");
    foreach ($res as $status) {
        // If there are more of the same sub in queue or published, multiply minimums
        $promoted = $db->get_var("select count(*) from sub_statuses where id = {$destination} and origen = {$status->id} and date > date_sub(now(), interval {$hours} hour)");
        echo "PROMOTED {$status->id} -> {$destination}: {$promoted}\n";
        if ($promoted > 0 && $status->link_karma < min(4, $promoted * 0.5 + 1) * $min_karma && $status->link_votes < min(4, $promoted * 0.5 + 1) * $min_votes) {
            echo "Already in main {$promoted}, doesn't have minimums, {$status->link_url}\n";
            continue;
        }
        $properties = SitesMgr::get_extended_properties($status->id);
        if (!empty($properties['no_link']) && empty($status->link_url)) {
            echo "NO LINK, {$status->id}\n";
            // continue;
        }
        if (!empty($status->link_url) && Link::duplicates($status->link_url, $destination)) {
            echo "Duplicated in destination, {$status->link_url}\n";
            continue;
        }
        $status->id = $destination;
        $status->status = 'queued';
        echo "--->\n";
        if (!DEBUG) {
            SitesMgr::store($status);
        }
    }
}