function compo_rate($cid, $uid) { $user = wp_get_current_user(); $k = "compo-{$cid}-state"; $v = get_option($k); if ($v == "") { return; } if ($v == "rate") { if (!compo_can_rate($cid, $user->ID)) { compo_trophy($uid); return; } compo_rate_rate($cid, $uid); compo_show_comments($cid, $uid); /* $topurl = get_bloginfo("url"); $auth = get_userdata($uid); $name = $auth->user_nicename; echo "<p><a href='$topurl/author/$name/'>See {$name}'s trophies!</a></p>"; */ } elseif ($v == "results") { // compo_rate_results($cid,$uid); compo_trophy($uid); compo_show_details($cid, $uid); compo_show_comments($cid, $uid); // echo "<p>TODO: compo_rate.results</p>"; } }
function x_my_get_buttons() { // check if we're on a "final" post page .. $my_final = 0; $tags = get_the_tags(); if (!$tags) { return; } foreach ($tags as $e) { if ($e->slug == "final") { $my_final = 1; } } $my_auth = get_the_author_meta('user_nicename'); $uid = get_the_author_meta('ID'); $cat = array_pop(get_the_category()); $my_cat = $cat->slug; // print_r($cat); $cid = $cat->cat_ID; // echo "$my_auth : $my_cat : $is_final"; $my_link = get_option('home') . "/?category_name=" . urlencode($my_cat) . "&author_name=" . urlencode($my_auth); $state = get_option("compo-{$cid}-state"); if (!$my_final) { return; } ob_start(); if ($state == "rate") { if (!is_user_logged_in()) { return; } $cuid = wp_get_current_user()->ID; if ($cuid == $uid) { return; } if (compo_can_rate($cid, $cuid)) { echo "<p style='text-align:left;clear:both;'><form method=post action='{$my_link}'><input type='submit' value='Vote on this Entry'></form></p>"; } } if ($state == "results") { echo "<p style='text-align:left;clear:both;'><form method=post action='{$my_link}'><input type='submit' value='View voting results for this entry'></form></p>"; } $my_buttons = ob_get_contents(); ob_end_clean(); return $my_buttons; }
function compo_results($cid) { global $compo; $cid = intval($cid); $cat = get_category($cid); $state = get_option("compo-{$cid}-state"); if ($state == "") { return; } $users = compo_get_finalists($cid); $topurl = get_bloginfo("url"); $cats = get_option("compo-{$cid}-cats"); /* $user = wp_get_current_user(); print_r($user);*/ $user = wp_get_current_user(); if (isset($_REQUEST["compo_recalc"]) && $user->user_level == 10) { foreach ($users as $uid) { compo_calc($cid, $uid); } echo "<p>Recalculated results...</p>"; } if ($state == "active") { $user = wp_get_current_user(); echo "<h3>Compo Active</h3>"; /* echo "<p>"; echo "Your entry wi foreach (explode(",",$cats) as $k) { echo ucfirst($k)." "; } echo "</p>";*/ echo "<p>"; foreach ($users as $final_id) { $auth = get_userdata($final_id); echo "<a href='{$topurl}/?category_name={$cat->slug}&author_name={$auth->user_nicename}'>{$auth->display_name}</a> "; } echo "</p>"; } elseif ($state == "rate") { $r = compo_query("select to_uid post_author,count(*) cnt from {$compo["rate.table"]} where cid = ? and from_uid != 0 and to_uid in (" . implode(",", $users) . ") group by to_uid order by cnt desc", array($cid)); /* // sort by cnt $data = array(); foreach ($users as $final_id) { $data[$final_id] = "0|$final_id"; } foreach ($r as $e) { $data[$e["post_author"]] = "{$e["cnt"]}|{$e["post_author"]}"; } sort($data); */ // sort by random (but diff rand per user) $data = array(); $user = wp_get_current_user(); foreach ($users as $final_id) { $key = md5("{$user->ID}|{$final_id}"); $cnt = 0; $data[$key] = "{$cnt}|{$final_id}"; } foreach ($r as $e) { $final_id = $e["post_author"]; $cnt = $e["cnt"]; $key = md5("{$user->ID}|{$final_id}"); $data[$key] = "{$cnt}|{$final_id}"; } ksort($data); $user = wp_get_current_user(); if (!compo_can_rate($cid, $user->ID)) { return; } echo "<h3>Your Ratings</h3>"; echo "<p><table>"; echo "<tr><td><th>C"; foreach (explode(",", $cats) as $k) { echo "<th>" . ucfirst(substr($k, 0, 3)); } // foreach ($r as $e) { $total = 0; foreach ($data as $dd) { list($cnt, $final_id) = explode("|", $dd); echo "<tr>"; // $auth = get_userdata($e["post_author"]); $auth = get_userdata($final_id); echo "<td><a href='{$topurl}/?category_name={$cat->slug}&author_name={$auth->user_nicename}'>{$auth->display_name}</a> ({$cnt})"; $r = compo_query("select * from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, $user->ID, $auth->ID)); echo "<td>"; if (strlen($r[0]["comment"])) { echo "X"; } $re = count($r) ? unserialize($r[0]["data"]) : array(); foreach (explode(",", $cats) as $k) { $v = isset($re[$k]) ? $re[$k] : ""; echo "<td align=center>{$v}"; } $total += 1; if ($total > 20 && !isset($_REQUEST["compo_results_all"])) { break; } } echo "</table></p>"; if (!isset($_REQUEST["compo_results_all"])) { echo "<p><form ><input type='hidden' name='compo_results_all' value='1'><input type='submit' value='Show all Entries'></form></p>"; } } elseif ($state == "results") { // $r = compo_query($sql,array($cid)); $vdata = array(); $cdata = array(); $total = 0; foreach ($users as $final_id) { $auth = get_userdata($final_id); $rr = compo_query("select * from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, 0, $auth->ID)); if (!count($rr)) { continue; } $re = count($rr) ? unserialize($rr[0]["data"]) : array(); // $e["auth"] = $auth; foreach (explode(",", $cats) as $k) { $v = isset($re[$k]) ? $re[$k] : ""; $v = compo_number_format($v, 2); if ($v != "") { $vdata[$k][] = $v; $cdata[$k][] = "{$v}:{$auth->user_nicename}:{$auth->display_name}"; } $e[$k] = $v; } $total += 1; // $data[] = $e; } foreach ($cdata as $k => $lst) { rsort($cdata[$k]); } foreach ($vdata as $k => $lst) { rsort($vdata[$k]); } echo "<h3>Final Results</h3>"; $limit = isset($_REQUEST["compo_limit"]) ? $_REQUEST["compo_limit"] : 0; if (!$limit) { echo "<p><a href='?compo_limit={$total}'>Show full results</a></p>"; } // echo "<p><a href='?compo_page=who_voted_prize'>See who did the most voting</a></p>"; _compo_show_results($cid, $cats, $cdata, $vdata, max(5, min($total, $limit))); } }