function _compo2_rate_list($params) { @($q = $_REQUEST["q"]); if (isset($params['ratedivs']) && trim($params['ratedivs']) !== "") { $ratedivs = explode(";", $params['ratedivs']); } else { $ratedivs = ["compo", "open"]; } $ratedivs_out = implode(",", array_map('add_quotes', $ratedivs)); $ecnt = array_pop(compo2_query("select count(*) cnt from c2_entry where cid = ? AND active = 1 AND is_judged = 1 AND etype IN ({$ratedivs_out})", array($params["cid"]))); //$ecnt = array_pop(compo2_query("select count(*) cnt from c2_entry where cid = ? AND active = 1 AND is_judged = 1",array($params["cid"]))); $cnt = $ecnt["cnt"]; if (!strlen($q)) { $_r = compo2_query("select etype,shots,title,uid,cid,rate_in,rate_out,get_user,settings from c2_entry where cid = ? AND active = 1 AND is_judged = 1 AND etype IN ({$ratedivs_out})", array($params["cid"])); //$_r = compo2_query("select etype,shots,title,uid,cid,rate_in,rate_out,get_user from c2_entry where cid = ? AND active = 1 AND is_judged = 1",array($params["cid"])); } else { $_r = compo2_query("select etype,shots,title,uid,cid,rate_in,rate_out,get_user,settings from c2_entry where (title like ? OR notes like ? OR links like ? OR get_user like ?) AND cid = ? AND active = 1 AND is_judged = 1 AND etype IN ({$ratedivs_out})", array("%{$q}%", "%{$q}%", "%{$q}%", "%{$q}%", $params["cid"])); //$_r = compo2_query("select etype,shots,title,uid,cid,rate_in,rate_out,get_user from c2_entry where (title like ? OR notes like ? OR links like ? OR get_user like ?) AND cid = ? AND active = 1 AND is_judged = 1",array("%$q%","%$q%","%$q%","%$q%",$params["cid"])); $_REQUEST["more"] = 1; } $r_rate = array(); foreach (compo2_query("select * from c2_rate where cid = ? and from_uid = ?", array($params["cid"], $params["uid"])) as $ve) { $r_rate[$ve["to_uid"]] = $ve; } $sortby = isset($_REQUEST["sortby"]) ? $_REQUEST["sortby"] : "default"; $r_rated = array(); $r_unrated = array(); $total = count($_r); foreach ($_r as $k => $ce) { $ce["rate_c"] = compo2_calc_coolness($ce["rate_out"], $cnt); if (isset($r_rate[$ce["uid"]])) { $ue = unserialize($ce["get_user"]); $key = strtolower($ue["display_name"]); $r_rated[$key] = $ce; } else { $ce['settings'] = unserialize($ce['settings']); $ce["legal_cats"] = 8; if (isset($ce['settings']['OPTOUT'])) { if (isset($ce['settings']['OPTOUT'][$ce['etype']])) { foreach ($ce['settings']['OPTOUT'][$ce['etype']] as $lcat) { if ($lcat > 0) { $ce["legal_cats"]--; } } } } // echo "<!-- FEEB: "; // print_r( $ce ); // echo "\nCats: " . $ce["legal_cats"]; // echo "-->\n"; $ce["rate_d"] = $ce["rate_in"] + 50 - sqrt(min(100, $ce["rate_out"])) * 50 / 10; if ($sortby == "ratings") { $v = $ce["rate_in"]; } elseif ($sortby == "coolness") { $v = -$ce["rate_out"]; } else { $v = $ce["rate_d"]; } if ($ce["legal_cats"] == 0) { continue; } $key = sprintf("%05d|%s", 10000 + $v, $ce["uid"]); $r_unrated[$key] = $ce; } } ksort($r_rated); ksort($r_unrated); echo "<h3>Rate Entries (" . count($_r) . ")</h3>"; if (isset($_REQUEST["dump"])) { echo "<h3>dump-only includes entries you haven't rated</h3>"; echo "<table><tr><th><th>D<th>R<th>C"; foreach ($r_unrated as $e) { $ue = unserialize($e["get_user"]); echo "<tr><th>"; echo $ue["display_name"]; $rate_in = intval($e["rate_in"]); $rate_out = intval($e["rate_out"]); $rate_d = intval($e["rate_d"]); echo "<td>{$rate_d}<td>{$rate_in}<td>{$rate_out}"; } echo "</table>"; } ob_start(); echo "<p>"; // if (!strlen($_REQUEST["more"])) { // echo "<a href='?more=1&q=".urlencode($q)."'>Show all entries</a> | "; // } // echo "<a href='?sortby=rate_in&q=".urlencode($q)."'>Sort by least ratings</a> | "; // echo "<a href='?sortby=rate_out'>Sort by most coolness</a>"; // echo "</p><p>"; echo "<a href='?action=preview'>Browse Entries</a> | "; echo "<a href='?action=edit'>Edit Entry</a> | "; echo "<a href='?action=preview&uid={$params["uid"]}'>View Entry</a>"; echo "</p>"; $links = ob_get_contents(); ob_end_clean(); echo $links; echo "<form style='text-align:left;margin:10px;'>"; // echo "<input type='hidden' name='action' value=''>"; echo "<input type='hidden' name='sortby' value=\"" . htmlentities($sortby) . "\">"; echo "<input type='text' name='q' value=\"" . htmlentities($q) . "\">"; echo " <input type='submit' value='Search'>"; echo "</form>"; echo "<p><h3>Play another game!</h3></p>"; echo "<p>Sort by: "; $qq = urlencode($q); echo "<a href='?sortby=default&q={$qq}'>Default (both)</a> | "; echo "<a href='?sortby=ratings&q={$qq}'>Least Ratings</a> | "; echo "<a href='?sortby=coolness&q={$qq}'>Most Coolness</a>"; echo "</p>"; $_link = "?action=preview"; $r = array_slice($r_unrated, 0, 18 + 12, true); $myurl = get_bloginfo("url") . "/wp-content/plugins/compo2"; $cols = 6; $n = 0; $row = 0; echo "<table class='preview'>"; foreach ($r as $e) { 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><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>"; $ue = unserialize($e["get_user"]); echo $ue["display_name"]; echo "</a></div>"; // if ($e["disabled"]) { echo "<div><i>disabled</i></div>"; } // else { if (!$e["active"]) { echo "<div><i>inactive</i></div>"; } } echo "<div style='color:#fff; margin: 3px; padding: 2px; background:#000; text-align:center; font-weight:bold;'>"; echo htmlentities($params["{$e["etype"]}_title"]); echo "</div>"; echo "<div style='font-size:10px;text-align:center;font-style:italic'><i>"; // $img = "inone.gif"; // $v = $e["rate_c"]; // if ($v >= 50) { $img = "ibronze.gif"; } // if ($v >= 75) { $img = "isilver.gif"; } // if ($v >= 100) { $img = "igold.gif"; } // echo "<img align=left src='$myurl/images/$img' title='$v% Coolness' style='padding:0px;margin:0px;border:0px;'>"; $rate_in = intval($e["rate_in"]); $rate_out = intval($e["rate_out"]); $rate_d = intval($e["rate_d"]); $legal_cats = intval($e["legal_cats"]); echo "(D:{$rate_d}=R:{$rate_in}-C:{$rate_out})" . $legal_cats; echo "</div>"; } echo "</table>"; echo "<p style='font-size:8px;'>"; echo "D = Default = R - C, except not quite that simple<br/>"; echo "R = Ratings = how many ratings this Entry has received.<br/>"; echo "C = Coolness = how many entries this user has rated<br/>"; echo "L = Loser = someone who games the coolness ranking. It's the honor system, people. Everyone might think you are cool, but in your heart of hearts, you will know that you are a <i>loser</i>.</p>"; $n = htmlentities(count($r_rated)); echo "<p><h3>Previously rated entries ({$n})</h3></p>"; // echo "<p>Rate 25+ entries to earn a Coolness medal!</p>"; $r = $r_rated; echo "<table>"; echo "<tr><th><th><th>"; foreach ($params["cats"] as $k) { echo "<th>" . substr($k, 0, 3); } echo "<th>Txt"; $myurl = get_bloginfo("url") . "/wp-content/plugins/compo2"; foreach ($r as $key => $ce) { $ve = $r_rate[$ce["uid"]]; $ue = unserialize($ce["get_user"]); echo "<tr>"; echo "<td valign=center>"; /* $img = "inone.gif"; $v = $ce["rate_c"]; if ($v >= 50) { $img = "ibronze.gif"; } if ($v >= 75) { $img = "isilver.gif"; } if ($v >= 100) { $img = "igold.gif"; } echo "<img src='$myurl/images/$img' title='$v% Coolness'>";*/ echo "<td valign=center align=center>"; $shots = unserialize($ce["shots"]); echo "<img src='" . compo2_thumb($shots["shot0"], 60, 45) . "' style='margin:5px;border:1px solid #000;'>"; echo "<td valign=center>"; echo "<a href='?action=preview&uid={$ce["uid"]}'>"; echo "<div style='width:125px;height:20px;overflow:hidden;'><i>" . htmlentities($ce["title"]) . "</i></div>"; $name = $ue["display_name"]; if (!strlen($name)) { $name = "?"; } echo htmlentities($name); if ($ce["rate_in"]) { echo " ({$ce["rate_in"]})"; } echo "</a>"; $data = unserialize($ve["data"]); foreach ($params["cats"] as $k) { echo "<td align=center valign=center>" . (strlen($data[$k]) ? intval($data[$k]) : "-"); } echo "<td align=center valign=center>" . (strlen($ve["comments"]) ? "x" : "-"); } echo "</table>"; echo $links; }
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; }