Пример #1
0
<div id="page">


<div id="header">
	<div id="headerimg">
		<h1><a href="<?php 
echo get_option('home');
?>
/"><?php 
/* bloginfo('name'); */
echo str_repeat("&nbsp;", 40);
?>
</a></h1>
		<div class="description"><?php 
bloginfo('description');
?>
</div>
	</div>
</div>
<hr />

<div id='compo-status'><?php 
global $wpdb;
$e = array_pop(compo_query("select * from {$wpdb->posts} where post_name = ? and post_type =?", array("status", "page")));
echo str_replace("\n", "<br>", $e["post_content"]);
?>
</div>

<hr />

Пример #2
0
function compo_calc($cid, $uid)
{
    global $compo;
    $r = compo_query("select * from {$compo["rate.table"]} where cid = ? and to_uid = ? and from_uid != 0", array($cid, $uid));
    $total = array();
    $count = array();
    foreach ($r as $ee) {
        $e = unserialize($ee["data"]);
        foreach ($e as $k => $v) {
            if (!strlen($v)) {
                continue;
            }
            $total[$k] += $v;
            $count[$k] += 1;
        }
    }
    $e = $total;
    foreach ($total as $k => $v) {
        if ($count[$k] < 5) {
            $e[$k] = "";
            // no score for you!
            continue;
        }
        $e[$k] = floatval($v) / floatval($count[$k]);
    }
    compo_query("delete from {$compo["rate.table"]} where cid = ? and from_uid = ? and to_uid = ?", array($cid, 0, $uid));
    compo_query("insert into {$compo["rate.table"]} (cid,from_uid,to_uid,data) values (?,?,?,?)", array($cid, 0, $uid, serialize($e)));
}
Пример #3
0
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)));
    }
}
Пример #4
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;
    ////////////////////////////////////////////////////////////////////////
}
Пример #5
0
function _compo_vote_form($pid, $opts)
{
    global $compo;
    $cur = wp_get_current_user();
    $uid = $cur->ID;
    if (!$uid) {
        /*		$data = null;
        		
        		if ( function_exists('apcu_fetch') ) {
        			if ( !isset($_GET["admin"]) ) {
        				$data = apcu_fetch( 'c1_vote_themelist_' . $pid );
        			}
        		}
        		
        		if ( !$data ) {
        			$fields_query = compo_query("SELECT DISTINCT name FROM {$compo['vote.table']} WHERE pid = ?",array($pid));
        			$data = [];
        			foreach( $fields_query as $field ) {
        				$data[] = $field['name'];
        			}
        
        			if ( function_exists('apcu_store') ) {
        				apcu_store( 'c1_vote_themelist_' . $pid, $data); // Store (no expiration) //
        			}
        		}
        */
        echo "<p>You must sign in to vote.</p>";
        $n = 1;
        echo "<table class='table'>";
        foreach ($opts as $k => $name) {
            // Pull the themes from the args //
            //foreach ($data as $name) {
            $key = "vote_{$k}";
            echo "<tr>";
            echo "<th>{$n}.";
            $n++;
            echo "<td class='{$key}' align=left>" . compo_vote_google($name);
        }
        echo "</table>";
        echo "<p>You must sign in to vote.</p>";
        return;
    }
    $data = compo_query("select * from {$compo['vote.table']} where pid = ? and uid = ?", array($pid, $uid));
    $r = array();
    foreach ($data as $e) {
        $r[$e["name"]] = $e["value"];
    }
    echo "<style>.s,.us { cursor:pointer; } .us { opacity: 0.15; -moz-opacity: 0.15; filter: alpha(opacity=15); }</style>";
    //     echo "<p>$pid $uid</p>";
    $topurl = get_bloginfo("url");
    echo "<script type='text/javascript' src='{$topurl}/wp-content/plugins/compo/vote.js'></script>";
    echo "<form class='vote' method='post'>";
    //echo "<input type='submit' value='Vote!'>";
    echo "<input type='hidden' name='compo_vote_action' value=1>";
    echo "<table class='table'>";
    foreach ($opts as $k => $name) {
        $key = "vote_{$k}";
        $v = $r[$name];
        echo "<tr>";
        echo "<td><nobr>";
        compo_vote_fakeajax($key, $v);
        echo "</nobr>";
        echo "<td class='{$key}' align=left>" . compo_vote_google($name);
    }
    echo "</table>";
    //     $total = count($opts);
    //     echo "<script type='text/javascript'>initvote($total);</script>";
    echo "<br />";
    echo "<input class='button' type='submit' value='Vote!'>";
    echo "</form>";
}