function _compo2_admin($params) { $user = $params["user"]; if ($user->user_level < 7) { compo2_error("admin"); } $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "preview"; if ($action == "default") { $action = "preview"; } if ($action == "edit") { return _compo2_active_form($params, $_REQUEST["uid"], 1); } elseif ($action == "save") { return _compo2_active_save($params, $_REQUEST["uid"], 1); } elseif ($action == "preview") { return _compo2_preview($params, "?admin=1&action=edit"); } elseif ($action == "ratelist") { return _compo2_rate_list($params); } elseif ($action == "results") { return _compo2_results_results($params); } elseif ($action == "top") { return _compo2_results_top($params); } elseif ($action == "recalc") { return _compo2_admin_recalc($params); } elseif ($action == "resetcache") { return _compo2_admin_resetcache($params); } elseif ($action == "get_user") { return _compo2_admin_get_user($params); } elseif ($action == "cron") { return _compo2_mike_cron($params); } }
function compo2_query($sql, $params = array()) { $tm = microtime(true); global $wpdb; $parts = explode("?", $sql); $sql = array_shift($parts); foreach ($parts as $v) { $sql .= "'" . $wpdb->escape(array_shift($params)) . "'"; $sql .= $v; } // echo "<p>compo2 - Debug: ".htmlentities($sql)."</p>"; $r = $wpdb->get_results($sql, ARRAY_A); if ($r === false) { compo2_error("compo2 - Error in query: {$sql}"); } compo2_log("compo2_query", microtime(true) - $tm, $sql); if (!$r) { return array(); } return $r; }
function _compo2_rate_submit($params) { // print_r($_REQUEST); die; $uid = intval($_REQUEST["uid"]); $ce = compo2_entry_load($params["cid"], $uid); if (!$ce["id"]) { compo2_error("Invalid Entry: uid={$uid}"); } if ($uid == $params["uid"]) { compo2_error("You can't vote on your own Entry!"); } $data = array(); $total = 0; foreach ($_REQUEST["data"] as $k => $v) { // $data[$k] = strlen($v)?intval($v):""; // worked for old method $data[$k] = intval($v) ? intval($v) : ""; // works for new javascript starry $total += $data[$k]; } $comments = trim(compo2_strip($_REQUEST["comments"])); // $comments2 = trim(compo2_strip($_REQUEST["comments2"])); // if ( strlen($comments2) > 0 ) { // $comments = $comments2; // } $e = array("cid" => $params["cid"], "to_uid" => $ce["uid"], "from_uid" => $params["uid"], "data" => serialize($data), "ts" => date("Y-m-d H:i:s")); $total += strlen($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)))); } $r = compo2_query("select * from c2_comments where cid = ? and to_uid = ? and from_uid = ?", array("cid" => $params["cid"], "to_uid" => $uid, "from_uid" => $params["uid"])); $e["comments"] = intval(count($r) != 0); if ($total) { compo2_query("delete from c2_rate where cid = ? and to_uid = ? and from_uid = ?", array($params["cid"], $ce["uid"], $params["uid"])); compo2_insert("c2_rate", $e); } _compo2_rate_recalc($params, $ce["uid"]); _compo2_rate_io_calc($params, $ce["uid"]); _compo2_rate_io_calc($params, $params["uid"]); header("Location: ?action=default"); die; }
function compo2_main($params) { global $compo2; $tm = microtime(true); /* old parsing $parts = explode(":",html_entity_decode($m[1])); $state = $parts[0]; $jcat = $parts[1]; $opts = $parts[2]; $opts = explode(";",str_replace(" ","",$opts)); */ /** Params ** @cats List of judging categories: "Innovation;Fun;Production" @jcat Wordpress Journal category @state State of compo (active,rate,results,closed) */ /* MK $params = xmlhack_attrs2array($m[1]); */ @($params["init"] = intval($params["init"])); if ($params["init"] == 0) { $params["divs"] = "compo"; if (isset($params["gamejam"])) { $params["divs"] .= ";gamejam"; } $params["compo_cats"] = $params["cats"]; $params["compo_title"] = "Competition"; $params["compo_summary"] = "My entry follows all the rules and I want it to be judged."; $params["compo_link"] = "#"; $params["gamejam_title"] = "Game Jam"; $params["gamejam_summary"] = "My entry doesn't follow the rules or I don't want it to be judged."; } if (!isset($params["opendivs"])) { $params["opendivs"] = $params["divs"]; } $params["divs"] = explode(";", str_replace(" ", "", $params["divs"])); $params["opendivs"] = explode(";", str_replace(" ", "", $params["opendivs"])); if ($params["locked"]) { $params["opendivs"] = array(); } $cats = array(); foreach ($params["divs"] as $div) { if (isset($params["{$div}_cats"])) { $params["{$div}_cats"] = explode(";", str_replace(" ", "", $params["{$div}_cats"])); foreach ($params["{$div}_cats"] as $v) { if (!in_array($v, $cats)) { $cats[] = $v; } } } } $params["cats"] = $cats; if (!isset($params["topcat"])) { $params["topcat"] = "Overall"; } foreach (array("calc_droplow" => 0, "calc_drophigh" => 0, "calc_reqvote" => 5) as $k => $v) { $params[$k] = isset($params[$k]) ? intval($params[$k]) : $v; } // some other auto-calculated stuff // @cat Contenst id (taken from page ID) $params["cid"] = intval($GLOBALS["post"]->ID); // @uid User ID // @user WP-User object $user = wp_get_current_user(); $uid = $user->ID; $params["uid"] = $uid; $params["user"] = $user; // @has_entry True if the current user has an entry in this compo $ce = compo2_entry_load($params["cid"], $uid); $params["has_entry"] = $ce["id"] != 0; // State is changed to admin if ?admin=1 is in the URL if ($_REQUEST["admin"]) { $params["state"] = "admin"; } // State is changed to misc, if we're accessing a misc_ page $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "default"; if (in_array($action, array("misc_links"))) { $params["state"] = "misc"; } // If we're in debug mode, display our params // if (strlen($_REQUEST["debug"])) { echo "<pre>";print_r($params);echo "</pre>"; } $nsfw = "<div id='compo-nsfw' class='hidden' onclick='c2_addclass( document.getElementById(\"compo-nsfw\"), \"hidden\"); c2_removeclass( document.getElementById(\"compo-body\"), \"hidden\");'><h2>WARNING!</h2><p>This entry may contain subject matter that you or those around you may find offensive. You have been warned.</p><h2>I understand. Let me see it.</h2></div><script>if ( window[\"compo_game_nsfw\"] ) { c2_addclass( document.getElementById(\"compo-body\"), \"hidden\"); c2_removeclass( document.getElementById(\"compo-nsfw\"), \"hidden\"); }</script>"; // dispatch according to the current state ob_start(); $state = $params["state"]; if ($state == "active") { _compo2_active($params); } elseif ($state == "rate") { echo "<div id='compo-body'>"; _compo2_rate($params); echo "</div>" . $nsfw; } elseif ($state == "results") { _compo2_results($params); } elseif ($state == "admin") { _compo2_admin($params); } elseif ($state == "misc") { _compo2_misc($params); } elseif ($state == "closed") { _compo2_closed($params); } else { compo2_error("compo2 - Invalid state: {$state}"); } if ($user->user_level >= 7) { echo "<p><a href='?admin=1'>Enter admin mode</a></p>"; } $r = ob_get_contents(); ob_end_clean(); // output the content compo2_log("_compo2_main", microtime(true) - $tm); /* // The red logging display at the bottom of all Compo2 pages // if (1 && $user->user_level >= 7) { ob_start(); $log = $compo2["log"]; usort($log,"_compo2_log_sort"); echo "<table border=1>"; echo "<tr><th>ms<th>fnc<th>hits<th>msg"; foreach ($log as $e) { echo "<tr>"; echo "<td align=right>".intval($e["tm"]*1000); echo "<td>".htmlentities($e["fnc"]); echo "<td align=right>".htmlentities($e["hits"]); echo "<td>".htmlentities($e["msg"]); } echo "</table>"; $rlog = ob_get_contents(); ob_end_clean(); $r .= "<div class='error'>$rlog</div>"; $v = get_option($compo2["version.key"]); $r .= "<p>compo2: $v</p>"; } */ return "<div id='compo2'>{$r}</div>"; }