示例#1
0
function _compo2_admin_recalc($params)
{
    echo "<h3>Recaculating Results ...</h3>";
    $r = compo2_query("select uid from c2_entry where cid = ? and active = 1", array($params["cid"]));
    global $compo2;
    $compo2["log.enabled"] = false;
    foreach ($r as $ce) {
        $uid = $ce["uid"];
        _compo2_rate_recalc($params, $uid);
    }
    $compo2["log.enabled"] = true;
    echo "<p>Done.</p>";
    echo "<hr/>";
    _compo2_admin_resetcache($params);
    echo "<hr/>";
    _compo2_results_results($params);
}
示例#2
0
function compo2_theme_author($uid)
{
    $r1 = compo2_query("select * from wp_compo_rate where to_uid = ? group by cid order by cid desc", array($uid));
    $r2 = compo2_query("select * from c2_entry where uid = ? and active = 1 and disabled = 0 order by cid desc", array($uid));
    if (count($r1) == 0 && count($r2) == 0) {
        return;
    }
    $ue = compo2_get_user($uid);
    echo '<h2 class="pagetitle">Entries</h2>';
    echo "<div class='ld-post post' id='compo2'><div class='body'>\n";
    $cols = 4;
    $n = 0;
    $row = 0;
    echo "<table class='preview'>";
    // compo2
    foreach ($r2 as $e) {
        $pe = array_pop(compo2_query("select * from wp_posts where ID = ?", array($e["cid"])));
        if (stristr($pe["post_name"], "test") !== false) {
            continue;
        }
        // HACK: don't include test compo results.
        $_link = "../../{$pe["post_name"]}/?action=preview";
        if ($n % $cols == 0) {
            echo "<tr>";
            $row += 1;
        }
        $n += 1;
        $klass = "class='alt-" . (1 + $row % 2) . "'";
        echo "<td valign=bottom align=center {$klass}>";
        $link = "{$_link}&uid={$e["uid"]}";
        echo "<div>&nbsp;</div>";
        echo "<div><a href='{$link}'>";
        $shots = unserialize($e["shots"]);
        echo "<img src='" . compo2_thumb($shots["shot0"], 120, 90) . "'>";
        echo "<div class='title'><i>" . htmlentities($e["title"]) . "</i></div>";
        echo "</a></div>";
        echo "<div class='title' style='height:40px;'>" . htmlentities($pe["post_title"]) . "</div>";
    }
    // compo
    foreach ($r1 as $e) {
        $ce = get_category($e["cid"]);
        if (stristr($ce->name, "test") !== false) {
            continue;
        }
        // HACK: don't include test compo results.
        if (!strlen($ce->slug)) {
            continue;
        }
        // HACK: skip empty categories
        // TODO: with some smarts, search for their post tagged "final"
        // then find the first image, and use that as the thumb image.
        $_link = "../../category/{$ce->slug}/?";
        if ($n % $cols == 0) {
            echo "<tr>";
            $row += 1;
        }
        $n += 1;
        $klass = "class='alt-" . (1 + $row % 2) . "'";
        echo "<td valign=bottom align=center {$klass}>";
        $link = "{$_link}&author_name={$ue->user_nicename}";
        echo "<div>&nbsp;</div>";
        echo "<div><a href='{$link}'>";
        $e["title"] = $ce->name;
        //             $shots = unserialize($e["shots"]);
        //             echo "<img src='".compo2_thumb($shots["shot0"],120,90)."'>";
        echo "<div class='title' style='height:40px;'><i>" . htmlentities($e["title"]) . "</i></div>";
        echo "</a></div>";
        //             echo "<div class='title' style='height:40px;'>".htmlentities($ce->name)."</div>";
    }
    echo "</table>";
    echo "</div></div>";
}
示例#3
0
function compo2_install()
{
    global $compo2;
    $key = $compo2["version.key"];
    $cur = get_option($key);
    $version = 1;
    if ($cur < $version) {
        compo2_query("create table c2_rate (cid int, to_uid int, from_uid int, data blob)");
        update_option($key, $version);
    }
    $version = 2;
    if ($cur < $version) {
        compo2_query("alter table c2_rate add comments text");
        update_option($key, $version);
    }
    $version = 7;
    if ($cur < $version) {
        compo2_query("create table c2_entry (id int not null auto_increment primary key, cid int, uid int, notes text, links blob, data blob)");
        update_option($key, $version);
    }
    $version = 9;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add results blob");
        update_option($key, $version);
    }
    $version = 11;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add active int default 0");
        update_option($key, $version);
    }
    $version = 12;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add title varchar(255)");
        update_option($key, $version);
    }
    $version = 13;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add shots blob");
        update_option($key, $version);
    }
    $version = 19;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add disabled int default 0");
        update_option($key, $version);
    }
    $version = 20;
    if ($cur < $version) {
        compo2_query("create index idx_c2_entry_uid on c2_entry (uid)");
        compo2_query("create index idx_c2_entry_cid on c2_entry (cid)");
        compo2_query("create index idx_c2_rate_cid on c2_rate (cid)");
        compo2_query("create index idx_c2_rate_to_uid on c2_rate (to_uid)");
        compo2_query("create index idx_c2_rate_from_uid on c2_rate (from_uid)");
        update_option($key, $version);
    }
    $version = 21;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add rate_in int default 0");
        compo2_query("alter table c2_entry add rate_out int default 0");
        update_option($key, $version);
    }
    $version = 22;
    if ($cur < $version) {
        compo2_query("alter table c2_rate add ts datetime");
        compo2_query("alter table c2_entry add ts datetime");
        update_option($key, $version);
    }
    $version = 23;
    if ($cur < $version) {
        compo2_query("create table c2_comments (id int not null auto_increment primary key, cid int, to_uid int, from_uid int, content text, ts datetime)");
        compo2_query("create index idx_c2_comments_cid on c2_comments (cid)");
        compo2_query("create index idx_c2_comments_to_uid on c2_comments (to_uid)");
        update_option($key, $version);
    }
    $version = 24;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add rules_ok int default 1");
        update_option($key, $version);
    }
    $version = 25;
    if ($cur < $version) {
        compo2_query("alter table c2_entry change rules_ok is_judged int");
        compo2_query("alter table c2_entry add etype varchar(32)");
        compo2_query("update c2_entry set etype = 'compo' where is_judged = 1");
        compo2_query("update c2_entry set etype = 'gamejam' where is_judged = 0");
        update_option($key, $version);
    }
    $version = 28;
    if ($cur < $version) {
        compo2_query("alter table c2_entry add get_user blob");
        update_option($key, $version);
    }
    $version = 30;
    if ($cur < $version) {
        $r = compo2_query("select id,uid from c2_entry");
        foreach ($r as $ce) {
            $user = compo2_get_user($ce["uid"]);
            compo2_query("update c2_entry set get_user = ? where id = ?", array(serialize(array("display_name" => $user->display_name, "user_nicename" => $user->user_nicename, "user_email" => $user->user_email)), $ce["id"]));
        }
        update_option($key, $version);
    }
    $version = 31;
    if ($cur < $version) {
        compo2_query("alter table c2_comments add get_user blob");
        update_option($key, $version);
    }
    $version = 33;
    if ($cur < $version) {
        $r = compo2_query("select id,from_uid from c2_comments where get_user is null");
        foreach ($r as $ce) {
            $user = compo2_get_user($ce["from_uid"]);
            compo2_query("update c2_comments set get_user = ? where id = ?", array(serialize(array("display_name" => $user->display_name, "user_nicename" => $user->user_nicename, "user_email" => $user->user_email)), $ce["id"]));
        }
        update_option($key, $version);
    }
    $version = 34;
    if ($cur < $version) {
        compo2_query("create table c2_cache (id varchar(32) primary key, cid int, name varchar(64), data longblob, ts datetime)");
        compo2_query("create index idx_c2_cache_cid on c2_cache (cid)");
        compo2_query("create index idx_c2_cache_name on c2_cache (name)");
        update_option($key, $version);
    }
    $version = 35;
    if ($cur < $version) {
        compo2_query("create index idx_c2_cache_ts on c2_cache (ts)");
        update_option($key, $version);
    }
    // Added int 'love', default 0 //
    // Added index 'cid_love' //
    // Added blob 'flags' //
}
示例#4
0
function _compo2_rate_recalc($params, $uid)
{
    $cid = $params["cid"];
    $ce = compo2_entry_load($params["cid"], $uid);
    $r = compo2_query("select * from c2_rate where cid = ? and to_uid = ?", array($cid, $uid));
    $data = array();
    foreach ($params["cats"] as $k) {
        $value = 0;
        $total = 0;
        $values = array();
        foreach ($r as $ve) {
            if ($ve["from_uid"] == $uid) {
                continue;
            }
            // no voting for self
            $dd = unserialize($ve["data"]);
            if (!strlen($dd[$k])) {
                continue;
            }
            $values[] = intval($dd[$k]);
        }
        sort($values);
        for ($i = 0; $i < $params["calc_droplow"]; $i++) {
            array_shift($values);
        }
        for ($i = 0; $i < $params["calc_drophigh"]; $i++) {
            array_pop($values);
        }
        foreach ($values as $v) {
            $value += $v;
            $total += 1;
        }
        $data[$k] = $total >= $params["calc_reqvote"] ? round($value / $total, 2) : "";
    }
    compo2_update("c2_entry", array("id" => $ce["id"], "results" => serialize($data)));
}
示例#5
0
function _compo2_mike_cron($params)
{
    echo "Hey...<br/>\n";
    if (current_user_can('delete_users')) {
        $compo_id = $params['cid'];
        $my_user_id = $params['uid'];
        //print_r($params);
        echo "Recalculating Coolness and Votes...";
        echo "<br />\n";
        echo "<br />\n";
        $entries = compo2_query("select uid from c2_entry where cid = ?", array($compo_id));
        //		print_r( $entries );
        foreach ($entries as $entry) {
            _compo2_rate_io_calc($params, $entry['uid']);
            echo $entry['uid'] . ", ";
        }
        echo "<br />\n";
        echo "<br />\n";
        echo "Done.<br />\n";
    }
    return "";
}
示例#6
0
function compo2_update($table, $e, $key = "id")
{
    $r = $id = $e[$key];
    $sets = array();
    foreach ($e as $k => $v) {
        $sets[] = $k . " = ?";
    }
    $sets_ = implode(",", $sets);
    $values = array_values($e);
    $values[] = $id;
    return compo2_query("update {$table} set {$sets_} where {$key} = ?", $values);
}
示例#7
0
function _compo2_get_results($params)
{
    //     if (($cres=compo2_cache_read($params["cid"],$ckey="get_results"))!==false) { return unserialize($cres); }
    global $compo2;
    $compo2["log.enabled"] = false;
    $tm = microtime(true);
    $r = compo2_query("select * from c2_entry where cid = ? and active = 1", array($params["cid"]));
    $total = 0;
    foreach ($r as $k => $ce) {
        $r[$k]["results"] = unserialize($ce["results"]);
        $r[$k]["user"] = unserialize($ce["get_user"]);
        $r[$k]["values"] = array();
        $r[$k]["places"] = array();
        $total += intval($ce["is_judged"] != 0);
    }
    // HACK: add in Coolness
    $cat = $params["cats"][] = "Coolness";
    foreach ($r as $k => $ce) {
        //         $r[$k]["results"][$cat] = round(100*$ce["rate_out"]/(max($total,2)-1));
        $r[$k]["results"][$cat] = compo2_calc_coolness($ce["rate_out"], $total);
    }
    foreach ($params["cats"] as $cat) {
        foreach ($r as $k => $ce) {
            $r[$k]["v"] = $ce["results"][$cat];
        }
        $r = _compo2_results_sort2($r);
        //         usort($r,"_compo2_results_sort");
        $myurl = get_bloginfo("url") . "/wp-content/plugins/compo2/images";
        $n = 0;
        $t = 1;
        $p = -1;
        foreach ($r as $k => $ce) {
            if ($cat != "Coolness" && !$ce["is_judged"]) {
                continue;
            }
            $v = $ce["v"];
            if ($v != $p) {
                $n = $t;
            }
            $p = $v;
            $t += 1;
            $vv = compo2_number_format($v);
            // HACK: for coolness
            if ($cat == "Coolness") {
                if ($v >= 50) {
                    $n = 3;
                }
                if ($v >= 75) {
                    $n = 2;
                }
                if ($v >= 100) {
                    $n = 1;
                }
                $vv = intval($v) . "%";
            }
            $r[$k]["values"][$cat] = $vv;
            $r[$k]["places"][$cat] = strcmp($vv, "-") != 0 ? $n : 0;
        }
    }
    foreach ($r as $k => $ce) {
        if (($cres = compo2_cache_read($params["cid"], $ukey = "get_results:{$ce["uid"]}")) == false) {
            compo2_cache_write($params["cid"], $ukey, serialize($ce));
        }
    }
    //     compo2_cache_write($params["cid"],$ckey,serialize($r));
    $compo2["log.enabled"] = true;
    compo2_log("_compo2_get_results", microtime(true) - $tm);
    return $r;
}
示例#8
0
function _compo2_preview_comments($params, $uid, $form = true)
{
    if ($form) {
        if ($params["uid"]) {
            $comments = trim(compo2_strip($_REQUEST["comments"]));
            if (strlen($comments)) {
                $user = compo2_get_user($params["uid"]);
                compo2_insert("c2_comments", array("cid" => $params["cid"], "to_uid" => $uid, "from_uid" => $params["uid"], "ts" => date("Y-m-d H:i:s"), "content" => $comments, "get_user" => serialize(array("display_name" => $user->display_name, "user_nicename" => $user->user_nicename, "user_email" => $user->user_email))));
                header("Location: ?action=preview&uid={$uid}");
                die;
            }
        }
    }
    $r = compo2_query("select * from c2_comments where cid = ? and to_uid = ? order by ts asc", array($params["cid"], $uid));
    echo "<h2>Comments</h2>";
    $pe = array();
    foreach ($r as $e) {
        if (strlen(trim($e["content"]))) {
            // get rid of double posts.
            if (strcmp($e["from_uid"], $pe["from_uid"]) == 0 && strcmp($e["content"], $pe["content"]) == 0) {
                continue;
            }
            $pe = $e;
            $user = unserialize($e["get_user"]);
            echo "<div class = 'comment'>";
            echo get_gravatar($user["user_email"], 48, 'mm', 'g', true, array("align" => "right", "class" => "gravatar"));
            $cuid = intval($e["from_uid"]);
            echo "<div><strong><a href=\"?action=preview&uid={$cuid}\">{$user["display_name"]}</a> says ...</strong></div>";
            echo "<div><small>" . date("M j, Y @ g:ia", strtotime($e["ts"])) . "</small></div>";
            echo "<p>" . str_replace("\n", "<br/>", htmlentities(trim($e["content"]))) . "</p>";
            echo "</div>";
        }
    }
    if ($form) {
        if ($params["uid"]) {
            echo "<form method='post' action='?action=preview&uid={$uid}'>";
            echo "<textarea name='comments' rows=4 cols=60></textarea>";
            echo "<p><input type='submit' value='Submit Comment'></p>";
        } else {
            echo "<p>You must sign in to comment.</p>";
        }
    }
}