Beispiel #1
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>";
}
Beispiel #2
0
function _compo2_results_top($params)
{
    $NUM_RESULTS = 100;
    $cat = $_REQUEST["cat"];
    $params["cats"][] = "Coolness";
    if (!in_array($cat, $params["cats"])) {
        $cat = $params["topcat"];
    }
    // HACK: why overall? who knows!
    // show user their link options here ..
    echo "<p>";
    echo "<a href='./'>Back to results</a> | ";
    echo "<a href='?action=preview'>Browse all Entries</a> | ";
    $ce = compo2_entry_load($params["cid"], $params["uid"]);
    if ($ce["id"]) {
        echo "<a href='?action=edit'>Edit your entry</a> | ";
    }
    if ($ce["id"]) {
        echo "<a href='?action=preview&uid=" . urlencode($ce["uid"]) . "'>View your entry</a> |";
    }
    echo "</p>";
    // CACHING ///////////////
    unset($_REQUEST["more"]);
    if (($cres = compo2_cache_read($params["cid"], $ckey = "results_top:{$cat}")) !== false) {
        echo $cres;
        return;
    }
    ob_start();
    //     $r = _compo2_get_top($params);
    $r = _compo2_get_results($params);
    // also, this now ignores the nice counting of trophes done earlier ..
    $_cat = $cat;
    // backup for later
    /*
    if (strlen($cat)) {
        foreach ($r as $k=>$e) {
            $r[$k]["v"] = -$e["places"][$cat];
        }
        usort($r,"_compo2_results_sort");
    }
    */
    foreach ($r as $k => $ce) {
        $r[$k]["v"] = -$ce["places"][$cat];
        $r[$k]["place"] = $ce["places"][$cat];
        $r[$k]["value"] = $ce["values"][$cat];
    }
    $r = _compo2_results_sort2($r);
    //     usort($r,"_compo2_results_sort");
    echo "<h3>Top Entries - " . htmlentities($cat) . "</h3>";
    $myurl = get_bloginfo("url") . "/wp-content/plugins/compo2/images";
    $t = 1;
    $ties = array();
    foreach ($r as $e) {
        $n = intval($e["places"][$_cat]);
        @($ties[$n] += 1);
    }
    $last = -1;
    echo "<table class='results-top'>";
    $row = 0;
    foreach ($r as $e) {
        //         $ce = $e["info"];
        $ce = $e;
        $shots = unserialize($ce["shots"]);
        $fname = array_shift($shots);
        $link = "?action=preview&uid={$ce["uid"]}";
        //         $n = intval($e["places"][$_cat]);
        $n = $e["place"];
        if ($n == 0) {
            continue;
        }
        // get rid of un-judged items
        if ($last != -1 && $last != $n) {
            break;
        }
        // allow several last-places to show up
        $klass = "class='alt-" . (1 + $row++ % 2) . "'";
        echo "<tr>";
        echo "<td valign=top align=center {$klass}><b>{$n}.</b>";
        if ($ties[$n] > 1) {
            echo "<br/><i>TIE</i>";
        }
        echo "<td align=center valign=top {$klass}>";
        echo "<a href='{$link}'><img src='" . compo2_thumb($fname, 160, 160) . "' class='screenshot'></a>";
        echo "<td valign=top {$klass}>";
        echo "<div><a href='{$link}'><b>" . htmlentities($ce["title"]) . "</b> - " . htmlentities($ce["user"]["display_name"]) . "</a></div>";
        echo "<p>";
        _compo2_preview_show_links($ce);
        echo "</p>";
        echo "<div class='notes'>" . str_replace("\n", "<br/>", htmlentities(substr($ce["notes"], 0, 140))) . " ...</div>";
        echo "<td valign=top {$klass}>";
        asort($e["places"]);
        foreach ($e["places"] as $cat => $nn) {
            if ($nn <= $NUM_RESULTS && $nn != 0) {
                $img = "inone.gif";
                echo "<div><nobr>";
                if ($nn <= 3) {
                    $map = array("1" => "igold.gif", "2" => "isilver.gif", "3" => "ibronze.gif");
                    $img = $map[$nn];
                    echo "<img src='{$myurl}/{$img}' align=absmiddle> - {$cat}";
                } else {
                    echo "#{$nn} - {$cat}";
                }
                echo "</nobr></div>";
            }
        }
        if ($t >= $NUM_RESULTS && !strlen($_REQUEST["more"])) {
            $last = $n;
        }
        $t += 1;
        //         echo "<tr><td>&nbsp;";
    }
    echo "</table>";
    $cres = ob_get_contents();
    ob_end_clean();
    compo2_cache_write($params["cid"], $ckey, $cres);
    echo $cres;
}
Beispiel #3
0
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;
}
Beispiel #4
0
function _compo2_preview($params, $_link = "?action=preview")
{
    if (isset($_REQUEST["uid"])) {
        _compo2_preview_show($params, intval($_REQUEST["uid"]));
        _compo2_show_comments($params["cid"], intval($_REQUEST["uid"]));
        return;
    }
    $cats = array("" => "All Entries");
    foreach ($params["divs"] as $div) {
        $cats[$div] = "{$params["{$div}_title"]} Entries";
    }
    if (isset($params["uid"])) {
        $ce = compo2_entry_load($params["cid"], $params["uid"]);
        if (isset($ce["id"])) {
            echo "<p><a href='?action=edit'>Edit Entry</a> | <a href='?action=preview&uid={$ce["uid"]}'>View Entry</a></p>";
        }
    }
    $etype = $_REQUEST["etype"];
    @($q = $_REQUEST["q"]);
    $limit = 24;
    $start = 0;
    if (isset($_REQUEST["start"])) {
        $start = intval($_REQUEST["start"]);
    }
    $start = intval($start);
    $limit = intval($limit);
    if (($cres = compo2_cache_read($params["cid"], $ckey = "_compo2_preview:{$etype}:{$q}:{$start}", 5 * 60)) !== false) {
        echo $cres;
        return;
    }
    ob_start();
    if (!strlen($q)) {
        $cnte = array_pop(compo2_query("select count(*) _cnt from c2_entry where etype like ? and cid = ? " . (!($params["state"] == "admin") ? " and active=1" : ""), array("%{$etype}%", $params["cid"])));
    } else {
        $cnte = array_pop(compo2_query("select count(*) _cnt from c2_entry where (title like ? OR notes like ? OR links like ? OR get_user like ?) and  etype like ? and cid = ? " . (!($params["state"] == "admin") ? " and active=1" : ""), array("%{$q}%", "%{$q}%", "%{$q}%", "%{$q}%", "%{$etype}%", $params["cid"])));
    }
    $cnt = $cnte["_cnt"];
    $sh = date("Y-m-d") . "|";
    // shuffle the entries every day .. seems a good compromise between having a user's search order get messed up if they are going through a bunch of entries, and having the same entries on the 1st page all the time.
    if (!strlen($q)) {
        $r = compo2_query("select *, md5(concat(?,id)) sh from c2_entry where etype like ? and cid = ? " . (!($params["state"] == "admin") ? " and active=1" : "") . " order by sh limit {$start},{$limit}", array($sh, "%{$etype}%", $params["cid"]));
    } else {
        $r = compo2_query("select *, md5(concat(?,id)) sh from c2_entry where (title like ? OR notes like ? OR links like ? OR get_user like ?) and etype like ? and cid = ? " . (!($params["state"] == "admin") ? " and active=1" : "") . " order by sh limit {$start},{$limit}", array($sh, "%{$q}%", "%{$q}%", "%{$q}%", "%{$q}%", "%{$etype}%", $params["cid"]));
    }
    usort($r, "_compo2_preview_sort");
    echo "<h2>" . htmlentities($cats[$etype]) . " ({$cnt})</h2>";
    if (isset($params[$etype . "_desc"])) {
        echo "<div>";
        echo $params[$etype . "_desc"];
        echo "</div>";
    }
    ob_start();
    echo "<p>";
    $pre = "";
    if (count($params["divs"]) > 1) {
        foreach ($cats as $kk => $vv) {
            echo "{$pre}<a href='?action=preview&etype={$kk}'>{$vv}</a>";
            $pre = " | ";
        }
    }
    echo "</p>";
    $links = ob_get_contents();
    ob_end_clean();
    echo $links;
    echo "<form style='text-align:left;margin:0px;'>";
    echo "<input type='hidden' name='action' value='preview'>";
    echo "<input type='text' name='q' value='" . htmlentities($q) . "'>";
    echo " <input type='submit' value='Search'>";
    echo "</form>";
    if (!$cnt) {
        echo "<p>No entries found.</p>";
    } else {
        ob_start();
        echo "<p>";
        if ($start > 0) {
            $i = max(0, $start - $limit);
            echo "<a href='?action=preview&q=" . urlencode($q) . "&etype=" . urlencode($etype) . "&start={$i}'>Previous</a> ";
        }
        echo " [ ";
        $n = 1;
        for ($i = 0; $i < $cnt; $i += $limit) {
            if ($i == $start) {
                echo "<b>{$n}</b> ";
            } else {
                echo "<a href='?action=preview&q=" . urlencode($q) . "&etype=" . urlencode($etype) . "&start={$i}'>{$n}</a> ";
            }
            $n += 1;
        }
        echo " ] ";
        if ($start < $cnt - $limit) {
            $i = $start + $limit;
            echo "<a href='?action=preview&q=" . urlencode($q) . "&etype=" . urlencode($etype) . "&start={$i}'>Next</a> ";
        }
        echo "</p>";
        $paging = ob_get_contents();
        ob_end_clean();
        echo $paging;
        $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 "</table>";
        echo $paging;
    }
    echo $links;
    $cres = ob_get_contents();
    ob_end_clean();
    compo2_cache_write($params["cid"], $ckey, $cres);
    echo $cres;
}