Esempio n. 1
0
function compo_trophy_sidebar()
{
    // CACHE ///////////////////////////////////////////////////////////////
    if (($cres = compo2_cache_read(0, $ckey = "compo_trophy_sidebar", 5 * 60)) !== false) {
        echo $cres;
        return;
    }
    ob_start();
    ////////////////////////////////////////////////////////////////////////
    global $compo;
    $table = $compo["trophy.table"];
    $topurl = get_bloginfo("url");
    $r = compo_query("select * from {$table} order by time desc limit 12");
    echo '<div class="trophylist">';
    foreach ($r as $e) {
        echo '<div class="cell"><div class="inner">';
        $auth = get_userdata($e["to_uid"]);
        echo "<div class='name'><a href='{$topurl}/author/{$auth->user_nicename}/'>{$auth->display_name}</a></div>";
        compo_trophy_show($e);
        echo "</div></div>";
    }
    echo "</div>";
    // CACHE ///////////////////////////////////////////////////////////////
    $cres = ob_get_contents();
    ob_end_clean();
    compo2_cache_write(0, $ckey, $cres);
    echo $cres;
    ////////////////////////////////////////////////////////////////////////
}
Esempio n. 2
0
function compo2_cache_end()
{
    if (function_exists("compo2_fcache_end")) {
        return compo2_fcache_end();
    }
    $user = wp_get_current_user();
    $uid = $user->ID;
    if ($uid) {
        echo "<p>[cache: unable to cache, user logged in]</p>";
        return;
    }
    if (count($_POST)) {
        echo "<p>[cache: unable to cache, POST data submitted]</p>";
        return;
    }
    $ckey = substr(md5($_SERVER["REQUEST_URI"]), 0, 30);
    // truncated because of 32 char limit of ckey
    $cres = ob_get_contents();
    compo2_cache_write("0", $ckey, $cres);
    ob_end_clean();
    echo $cres;
    echo "<p>[cache: storing page]</p>";
    // 1 in 1000 hits, auto clear out all 1-hour old cache data in the "0" cache
    if (rand() % 1000 == 0) {
        $ts = 60 * 60;
        compo2_query("delete from c2_cache where cid = ? and ts < ?", array("0", date("Y-m-d H:i:s", time() - $ts)));
    }
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
function _compo_vote_results($pid)
{
    // CACHE ///////////////////////////////////////////////////////////////
    if (($cres = compo2_cache_read(0, $ckey = "compo_vote_results:{$pid}", 3 * 60)) !== false) {
        if (!isset($_REQUEST["admin"])) {
            echo $cres;
            return;
        }
    }
    ob_start();
    ////////////////////////////////////////////////////////////////////////
    global $compo;
    /*    
        $r = compo_query("select * from {$compo['vote.table']} where pid = ? and uid = ? order by value desc",array($pid,0));
        
        $r2 = compo_query("select count(*) c, name,value , concat(name,'|',value) as n_v from {$compo['vote.table']} where pid = ? and uid != 0 group by n_v",array($pid));
        $data = array(); foreach ($r2 as $e) { $data[$e["name"]][$e["value"]] = $e["c"]; }
    */
    $data = null;
    if (function_exists('apcu_fetch')) {
        if (!isset($_GET["admin"])) {
            $data = apcu_fetch('c1_vote_result_' . $pid);
        }
    }
    if (!$data) {
        $data = [];
        $fields_query = compo_query("SELECT DISTINCT name FROM {$compo['vote.table']} WHERE pid = ?", array($pid));
        $fields = [];
        foreach ($fields_query as $field) {
            $fields[] = $field['name'];
        }
        foreach ($fields as $field) {
            $data[] = array_pop(compo_query("\n\t\t\t\tSELECT name,\n\t\t\t\t\tSUM(value) AS result,\n\t\t\t\t\tSUM(CASE WHEN value = -1 then 1 end) as downvote,\n\t\t\t\t\tSUM(CASE WHEN value = 0 then 1 end) as novote,\n\t\t\t\t\tSUM(CASE WHEN value = 1 then 1 end) as upvote,\n\t\t\t\t\tCOUNT(value) AS total\n\t\t\t\tFROM {$compo['vote.table']} \n\t\t\t\tWHERE pid = ? AND uid != 0 AND name = ?", array($pid, $field)));
        }
        usort($data, function ($a, $b) {
            return $b['result'] - $a['result'];
        });
        if (function_exists('apcu_store')) {
            apcu_store('c1_vote_result_' . $pid, $data);
        }
    }
    //print_r( $data );
    echo "<table>";
    echo "<tr><th><th><th><th>&nbsp;&nbsp;&nbsp;&nbsp;<th align=center>+1<th align=center>0<th align=center>-1<th align=center>Total Votes";
    $n = 1;
    foreach ($data as $e) {
        echo "<tr>";
        echo "<th>{$n}.";
        $n++;
        echo "<td>" . compo_vote_google($e['name']);
        echo "<th align=right>" . htmlentities($e['result']) . "";
        echo "<td>";
        echo "<td>" . $e['upvote'];
        echo "<td>" . $e['novote'];
        echo "<td>" . $e['downvote'];
        echo "<td align=right>" . $e['total'];
    }
    echo "</table>";
    //    $e = array_pop(compo_query("
    //    	SELECT sum(value) as v
    //    	FROM {$compo['vote.table']}
    //    	WHERE pid = ? AND uid != 0",// AND name = ?",
    //    	array($pid,$name)));
    /*   
        echo "<table>";
        echo "<tr><th><th><th><th align=center>+1<th align=center>0<th align=center>-1";
        $n=1;
        foreach ($r as $e) {
            echo "<tr>";
            echo "<th>{$n}.";$n++;
            echo "<td>".compo_vote_google($e["name"]);
            $v = $e["value"];
            if ($v>0) { $v="+$v"; }
    //         echo "<th>(".htmlentities($v).")";
            echo "<th>".htmlentities($v)."";
            echo "<td>".$data[$e["name"]]["1"];
            echo "<td>".$data[$e["name"]]["0"];
            echo "<td>".$data[$e["name"]]["-1"];
        }
        echo "</table>";
    */
    // CACHE ///////////////////////////////////////////////////////////////
    $cres = ob_get_contents();
    ob_end_clean();
    compo2_cache_write(0, $ckey, $cres);
    echo $cres;
    ////////////////////////////////////////////////////////////////////////
}