Beispiel #1
0
function _compo2_rate_recalc($params, $uid)
{
    $cid = $params["cid"];
    $ce = compo2_entry_load($params["cid"], $uid);
    $r = compo2_query("select * from c2_rate where cid = ? and to_uid = ?", array($cid, $uid));
    $data = array();
    foreach ($params["cats"] as $k) {
        $value = 0;
        $total = 0;
        $values = array();
        foreach ($r as $ve) {
            if ($ve["from_uid"] == $uid) {
                continue;
            }
            // no voting for self
            $dd = unserialize($ve["data"]);
            if (!strlen($dd[$k])) {
                continue;
            }
            $values[] = intval($dd[$k]);
        }
        sort($values);
        for ($i = 0; $i < $params["calc_droplow"]; $i++) {
            array_shift($values);
        }
        for ($i = 0; $i < $params["calc_drophigh"]; $i++) {
            array_pop($values);
        }
        foreach ($values as $v) {
            $value += $v;
            $total += 1;
        }
        $data[$k] = $total >= $params["calc_reqvote"] ? round($value / $total, 2) : "";
    }
    compo2_update("c2_entry", array("id" => $ce["id"], "results" => serialize($data)));
}
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_active_save($params, $uid = "", $is_admin = 0)
{
    if (!$uid) {
        $uid = $params["uid"];
    }
    $ce = compo2_entry_load($params["cid"], $uid);
    if (isset($params["locked"]) && !isset($ce["id"]) && !$is_admin) {
        echo "<p class='warning'>This competition is locked.  No new entries are being accepted.</p>";
        return;
    }
    /*	
    	if ( current_user_can('edit_others_posts') ) {
    		echo "Hey team. Just ignore this for now. Only you can see it. Thanks!<br /><br />";
    		var_dump( $_REQUEST );
    		echo "<br /><br />";
    		var_dump( $ce );
    	}
    */
    $active = true;
    $msg = "";
    if (!$_REQUEST["formdata"]) {
        $active = false;
        $msg .= "ERROR: Entry not updated. Bad formdata. Something is wrong.<br />";
    } else {
        $ce["title"] = compo2_strip($_REQUEST["title"]);
        if (!strlen(trim($ce["title"]))) {
            $active = false;
            $msg .= "Name is required.<br />";
        }
        if (isset($_REQUEST["etype"]) && $_REQUEST["etype"] !== "") {
            $ce["etype"] = $_REQUEST["etype"];
        }
        if ($params["init"] == 0) {
            $ce["is_judged"] = intval(strcmp($ce["etype"], "compo") == 0);
        } else {
            $ce["is_judged"] = 1;
            // now we judge all entries
        }
        if (!strlen($ce["etype"])) {
            $active = false;
            $msg .= "Submission Type is required.<br />";
        }
        $ce["notes"] = compo2_strip($_REQUEST["notes"]);
        $shots = unserialize($ce["shots"]);
        if ($shots == null) {
            $shots = array();
        }
        // For loop, because we're looking for File IDs of the same generated name (shot0, shot1, etc) //
        for ($i = 0; $i < 9; $i++) {
            $k = "shot{$i}";
            $fe = $_FILES[$k];
            // Reject empty filename (i.e. no change) //
            if (!trim($fe["tmp_name"])) {
                continue;
            }
            list($w, $h, $type) = getimagesize($fe["tmp_name"]);
            if (current_user_can('edit_others_posts')) {
                $msg .= "Debug: Shot " . ($i + 1) . ": [{$w},{$h},{$type}]<br />";
            }
            // Reject Bad Dimensions (0 or less, or bigger than 4k) //
            if (intval($w) <= 0 || intval($h) <= 0) {
                $msg .= "Problem with Screenshot " . ($i + 1) . "! [{$w},{$h},{$type}]<br />";
                continue;
            }
            if ($w > 4096 || $h > 2160) {
                $msg .= "Screenshot " . ($i + 1) . " is too big! Should be 4096x2160 or less. [{$w},{$h},{$type}]<br />";
                continue;
            }
            // Reject Bad File Size (greater than 8 MB) //
            $image_size = filesize($fe["tmp_name"]);
            if ($image_size > 8 * 1024 * 1024) {
                $msg .= "Screenshot " . ($i + 1) . " file is too large! Images should be 8 MB or less. [{$image_size}]<br />";
                continue;
            }
            $ext = array_pop(explode(".", $fe["name"]));
            // Reject File Formats //
            if (!in_array(strtolower($ext), array("png", "gif", "jpg", "jpeg"))) {
                $msg .= "Screenshot " . ($i + 1) . ": Invalid Type \"{$ext}\". Should be PNG, JPEG or GIF.<br />";
                continue;
            }
            $cid = $params["cid"];
            $ts = time();
            $fname = "{$cid}/{$uid}-{$k}-{$ts}.{$ext}";
            $dname = dirname(__FILE__) . "/../../compo2";
            @mkdir("{$dname}/{$cid}");
            $dest = "{$dname}/{$fname}";
            $old_file = $dname . '/' . $shots[$k];
            if (trim($shots[$k]) !== "" && file_exists($old_file)) {
                //unlink( $old_file ); // Delete One File //
                array_map('unlink', glob($old_file . "*"));
                // Delete all files with same base //
            }
            move_uploaded_file($fe["tmp_name"], $dest);
            $shots[$k] = $fname;
        }
        $ce["shots"] = serialize($shots);
        if (!count($shots)) {
            $active = false;
            $msg .= "You must include at least one screenshot.<br />";
        }
        foreach ($_REQUEST["links"] as $k => $le) {
            $_REQUEST["links"][$k] = array("title" => compo2_strip($le["title"]), "link" => compo2_strip($le["link"]));
        }
        $ce["links"] = serialize($_REQUEST["links"]);
        $ok = false;
        foreach ($_REQUEST["links"] as $le) {
            if (strlen(trim($le["title"])) && strlen(trim($le["link"]))) {
                $ok = true;
            }
        }
        if (!$ok) {
            $active = false;
            $msg .= "You must include at least one link.<br />";
        }
        if ($is_admin) {
            $ce["disabled"] = $_REQUEST["disabled"];
        }
        if ($ce["disabled"]) {
            $active = false;
            $msg .= "This Entry has been disabled.<br />";
        }
        //     $ce["data"] = serialize($_REQUEST["data"]);
        $ce["active"] = intval($active);
        $user = compo2_get_user($uid);
        $ce["get_user"] = serialize(array("display_name" => $user->display_name, "user_nicename" => $user->user_nicename, "user_email" => $user->user_email));
        // MK START //
        // Build Settings //
        $settings = [];
        // Opt-Outs //
        foreach ($params["divs"] as $div) {
            foreach ($params[$div . "_cats"] as $cat) {
                if (!isset($_REQUEST["OPTOUT"][$div][$cat])) {
                    $settings["OPTOUT"][$div][$cat] = 1;
                }
            }
        }
        // Parental Settings and other Settings //
        $settings["NSFW"] = isset($_REQUEST["SETTING"]["NSFW"]) ? 1 : 0;
        $settings["NSFL"] = isset($_REQUEST["SETTING"]["NSFL"]) ? 1 : 0;
        $settings["ANONYMOUS"] = isset($_REQUEST["SETTING"]["ANONYMOUS"]) ? 1 : 0;
        // Embedded Game Player //
        $embed_width = 800;
        $embed_height = 450;
        $embed_url = "";
        $embed_fullscreen = false;
        $embed_nocontrols = false;
        if (isset($_REQUEST["SETTING"]["EMBED"]["width"])) {
            $width = intval($_REQUEST["SETTING"]["EMBED"]["width"]);
            if ($width > 900) {
                $width = 900;
            }
            if ($width < 16) {
                $width = 16;
            }
            $embed_width = $width;
        }
        if (isset($_REQUEST["SETTING"]["EMBED"]["height"])) {
            $height = intval($_REQUEST["SETTING"]["EMBED"]["height"]);
            if ($height > 600) {
                $height = 600;
            }
            if ($height < 9) {
                $height = 9;
            }
            $embed_height = $height;
        }
        if (isset($_REQUEST["SETTING"]["EMBED"]["url"])) {
            $embed_url = esc_url($_REQUEST["SETTING"]["EMBED"]["url"]);
        }
        if (isset($_REQUEST["SETTING"]["EMBED"]["fullscreen"])) {
            $embed_fullscreen = intval($_REQUEST["SETTING"]["EMBED"]["fullscreen"]) ? true : false;
        }
        if (isset($_REQUEST["SETTING"]["EMBED"]["nocontrols"])) {
            $embed_nocontrols = intval($_REQUEST["SETTING"]["EMBED"]["nocontrols"]) ? true : false;
        }
        $settings["EMBED"]["width"] = $embed_width;
        $settings["EMBED"]["height"] = $embed_height;
        $settings["EMBED"]["url"] = $embed_url;
        $settings["EMBED"]["fullscreen"] = $embed_fullscreen;
        $settings["EMBED"]["nocontrols"] = $embed_nocontrols;
        $ce["settings"] = serialize($settings);
        $ce["stamp"] = date("Y-m-d H:i:s");
        // MK END //
        unset($ce["results"]);
        if (!$ce["id"]) {
            $ce["cid"] = $params["cid"];
            $ce["uid"] = $uid;
            $ce["ts"] = date("Y-m-d H:i:s");
            compo2_insert("c2_entry", $ce);
        } else {
            compo2_update("c2_entry", $ce);
        }
        echo "<h3>Entry Saved</h3>";
    }
    if (!$active) {
        $msg .= "<br />Entry is inactive due to errors. <a href='?action=edit'>Edit Entry</a>.";
    }
    if ($msg) {
        echo "<p class='error'>{$msg}</p>";
    }
    if (!$is_admin) {
        echo "<p><a href='?action=edit'>Edit Entry</a> | <a href='?action=default'>Browse entries</a> | <a href='?action=preview&uid={$params["uid"]}'>View Entry</a></p>";
    } else {
        echo "<p><a href='?action=default&admin=1'>Browse entries</a></p>";
    }
    //     header("Location: ?action=default"); die;
}
Beispiel #4
0
function _compo2_preview_show($params, $uid, $comments = true)
{
    $ce = compo2_entry_load($params["cid"], $uid);
    echo "<p>";
    echo "<a href='?action=preview'>Back to Browse Entries</a>";
    if (isset($params["uid"]) && $params["uid"]) {
        if (current_user_can('edit_others_posts')) {
            //			$ce = compo2_entry_load($params["cid"],intval($_REQUEST["uid"]));
            echo " | <strong><a href='?action=edit&uid=" . $ce["uid"] . "&admin=1'>ADMIN EDIT</a></strong>";
        }
        if (intval($params["uid"]) === intval($uid)) {
            // If the entry exists //
            if ($ce["id"]) {
                echo " | <a href='?action=edit'>Edit Entry</a>";
            }
        }
    }
    echo "</p>";
    if (!$ce["id"]) {
        echo "<p>Sorry, this person does not have an Entry.</p>";
        return;
    }
    $shots = unserialize($ce["shots"]);
    $settings = unserialize($ce["settings"]);
    $is_nsfw = $settings["NSFL"];
    $baseurl = get_bloginfo("url") . "/wp-content";
    $has_embed = isset($settings["EMBED"]["url"]) && $settings["EMBED"]["url"] !== "";
    if ($has_embed) {
        $url = $settings["EMBED"]["url"];
        $width = $settings["EMBED"]["width"];
        $height = $settings["EMBED"]["height"];
        $imagefile = array_values($shots)[0];
        $shot_url = c2_thumb($imagefile, 900, 500, false, true);
        $play_code = "<div id='embed' onclick='c2_play_game();' style='width:{$width}px;height:{$height}px'><img class='embed-icon' src='{$shot_url}'><div class='embed-overlay'></div><img class='embed-icon' src='/compo/wp-content/plugins/compo2/art/play.png' /></div>";
        ?>
		<script>
			function c2_toggle_fullscreen() {
				var elem = document.getElementById('embed');
					if (elem.requestFullscreen) {
						elem.requestFullscreen();
					} else if (elem.msRequestFullscreen) {
						elem.msRequestFullscreen();
					} else if (elem.mozRequestFullScreen) {
						elem.mozRequestFullScreen();
					} else if (elem.webkitRequestFullscreen) {
						elem.webkitRequestFullscreen();
				}
			}
			
			function c2_play_game() {
				var elm = document.getElementById('embed-frame');
				elm.innerHTML = "<?php 
        echo "<iframe id='embed' src='{$url}' width='{$width}' height='{$height}' frameborder='0' allowfullscreen></iframe>";
        ?>
";
			}
			
			function c2_exit_game() {
				var elm = document.getElementById('embed-frame');
				elm.innerHTML = "<?php 
        echo $play_code;
        ?>
";
				//"<div id='embed' onclick='c2_play_game();'><?php 
        echo "<img id='embed' src='{$shot_url}'>";
        ?>
</div>";
			}
		</script>
		<style>
			#embed {
				margin:10px auto;
				display:block;
				position:relative;
				text-align:center;
			}
			
			:-webkit-full-screen #embed {
				width: 100%;
				height: 100%;
			}
			#embed:-ms-fullscreen {
				position:absolute;
				left:0px;
				top:0px;
				width: 100%;
				height: 100%;
			}					
			
			.embed-overlay {
				position:absolute;
				background:url('/compo/wp-content/plugins/compo2/art/TiledBars.png');
				left:0;
				top:0;
				width:100%;
				height:100%;
			}
			.embed-icon {
				position:absolute;
				left:50%;
				top:50%;
				-ms-transform: translate(-50%,-50);
				-webkit-transform: translate(-50%,-50%);
				transform: translate(-50%,-50%);				
			}
			
			.embed-controls {
				text-align:center;
			}
			.embed-controls img {
				cursor:pointer;
				opacity:0.3;
			}
			.embed-controls img:hover {
				opacity:1.0;
			}
		</style>
<?php 
        echo "<div id='embed-view'>";
        echo "<div id='embed-frame'>";
        echo $play_code;
        echo "</div>";
        echo "<div class='embed-controls'>";
        if ($settings["EMBED"]["fullscreen"]) {
            echo "<img src='{$baseurl}/plugins/compo2/art/Maximize.png' onclick='c2_toggle_fullscreen();'>";
        }
        echo "<img src='{$baseurl}/plugins/compo2/art/Power.png' onclick='if (confirm(\"Are you sure you want to Shutdown the game? All progress will be lost!\")) { c2_exit_game(); }'>";
        echo "</div>";
        echo "</div>";
    }
    echo "\n\t\t<style>\n\t\t\t#shotview {\n\t\t\t\ttext-align:center;\n\t\t\t\tmargin-bottom:10px;\n\t\t\t}\n\t\t\t#shotview img {\n\t\t\t\tmax-width:900px;\n\t\t\t}\n\t\t</style>\n\t";
    // Screenshot Viewer //
    echo "<div id='shotview' class='" . ($has_embed ? "hidden" : "") . "'>";
    $imagefile = array_values($shots)[0];
    $link = $baseurl . '/compo2/' . $imagefile;
    $preview = c2_thumb($imagefile, 900, 500, false, true);
    echo "<a id='shotview_link' href='{$link}' target='_blank'><img id='shotview_img' src='{$preview}'></a>";
    echo "</div>";
    // Game Name and Developer //
    echo "<div style='overflow:auto;'>";
    echo "<div style='float:right;'>";
    $user = unserialize($ce["get_user"]);
    echo get_avatar($user['user_email'], '56');
    echo "</div>";
    echo "<h2 style='font-size:28px'>" . htmlentities($ce["title"]) . "</h2>";
    echo "by <a href=\"../author/{$user['user_nicename']}/\" target='_blank'><strong>{$user['display_name']}</strong></a>";
    $div = $ce["etype"];
    echo " - <i>{$params["{$div}_title"]} Entry</i>";
    echo "</div>";
    ?>
	<style>
		.shot-nav {
			text-align:center;
			width:940px;
			left:-20px;
			position:relative;
			margin-top:10px;
		}
		
		.shot-nav .sn-item {
			display:inline-block;
			opacity:0.4;
			padding:3px;
			position:relative;
		}
		.shot-nav .sn-item:hover {
			opacity:1.0;
		}

		.shot-nav .sn-item .sn-img {
			border-radius:7px;
			cursor:pointer;
		}
		
		.shot-nav .sn-item .sn-overlay {
			border-radius:7px;
			position:absolute;
			background:url('/compo/wp-content/plugins/compo2/art/TiledBars.png');
			left:0;
			top:0;
			width:100%;
			height:100%;
		}
		
		.shot-nav .sn-item .sn-icon {
			position:absolute;
			left:50%;
			top:50%;
			-ms-transform: translate(-50%,-50);
			-webkit-transform: translate(-50%,-50%);
			transform: translate(-50%,-50%);
		}
		
		.shot-nav .sn-selected {
			opacity:0.8;
			border:3px solid #000;
			background:#000;
			border-radius:10px;
			padding:0;
		}
		
		.links {
			margin:0;
		}
		
		.links ul {
			list-style:none;
			margin:0;
		}
		.links ul li:before {
			content:'';
		}
		
		#compo-nsfw {
			cursor:pointer;
			background:#900;
			border-radius:10px;
			padding:20px;
			color:#FF0;
			text-align:center;
		}
		
		#compo-nsfw h2 {
			text-align:center;
			font-size:40px;
			color:#F80;
		}
		
	</style>
	
	<script>
		function c2_addclass( el, className ) {
			if ( el ) {
				if (el.classList)
					el.classList.add(className);
				else
					el.className += ' ' + className;
			}
		}
		function c2_removeclass( el, className ) {
			if ( el ) {
				if (el.classList)
					el.classList.remove(className);
				else
					el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
			}
		}

		// Global Variable //
		window.c2_ShotIndex = 0;
		
		function c2_show_embed() {
			c2_removeclass( document.getElementById('embed-view'), 'hidden');
		}
		function c2_hide_embed() {
			c2_addclass( document.getElementById('embed-view'), 'hidden');
		}
		
		function c2_show_image( _img, _link ) {
			c2_removeclass( document.getElementById('shotview'), 'hidden');
			document.getElementById('shotview_img').setAttribute('src', _img);
			document.getElementById('shotview_link').setAttribute('href', _link);
		}
		function c2_hide_image() {
			c2_addclass( document.getElementById('shotview'), 'hidden');
		}
		
		function c2_highlight_nav( id ) {
			c2_removeclass( document.getElementById('shot-nav-'+window.c2_ShotIndex), 'sn-selected');
			c2_addclass( document.getElementById('shot-nav-'+id), 'sn-selected');
			
			window.c2_ShotIndex = id;		
		}

		function c2_select_embed( id ) {
			c2_hide_image();
			
			c2_highlight_nav(id);
			
			c2_show_embed();
		}
		function c2_select_image( id, _img, _link ) {
			c2_hide_embed();
		
			c2_highlight_nav(id);

			c2_show_image( _img, _link );
		}
	</script>

<?php 
    //echo "NSFW Test:".(($is_nsfw=='1')?"YES":"nope");
    //<script>window.compo_game_nsfw = true;</script>
    if ($is_nsfw == '1') {
        echo "<script>window.compo_game_nsfw = true;</script>";
    }
    // Screenshots //
    echo "<div class='shot-nav'><span>";
    $idx = 0;
    if ($has_embed) {
        $imagefile = array_values($shots)[0];
        $link = $baseurl . '/compo2"/' . $imagefile;
        $thumb = c2_thumb($imagefile, 180, 140);
        $selected = $idx === 0 ? "sn-selected" : "";
        //		echo "<div class='sn-item {$selected}' id='shot-nav-{$idx}'><a href='' target='_blank'><img src='{$thumb}' width='180' height='140'></a></div>";
        echo "<div class='sn-item {$selected}' id='shot-nav-{$idx}' onclick='c2_select_embed({$idx});'>\n\t\t\t<img class='sn-img' src='{$thumb}' width='180' height='140'>\n\t\t\t<div class='sn-overlay'></div>\n\t\t\t<img class='sn-icon' id='embed-mode' src='/compo/wp-content/plugins/compo2/art/play-sm.png' />\n\t\t</div>";
        $idx++;
    }
    foreach ($shots as $imagefile) {
        if ($idx === 5) {
            break;
        }
        $link = $baseurl . '/compo2/' . $imagefile;
        $thumb = c2_thumb($imagefile, 180, 140);
        $preview = c2_thumb($imagefile, 900, 500, false, true);
        $selected = $idx === 0 ? "sn-selected" : "";
        //		echo "<div class='sn-item {$selected}' id='shot-nav-{$idx}'><a href='{$link}' target='_blank'><img src='{$thumb}' width='180' height='140'></a></div>";
        echo "<div class='sn-item {$selected}' id='shot-nav-{$idx}'><img class='sn-img' src='{$thumb}' width='180' height='140' onclick='c2_select_image({$idx},\"{$preview}\",\"{$link}\");'></div>";
        $idx++;
    }
    echo "</span></div>";
    // Description //
    echo "<p>" . str_replace("\n", "<br/>", htmlentities($ce["notes"])) . "</p>";
    // Links and Downloads //
    echo "<h2>Downloads and Links</h2>";
    echo "<div class='links'>";
    _compo2_preview_show_links($ce);
    echo "</div>";
    echo "<br />";
    echo '<meta name="twitter:card" content="summary" />';
    echo '<meta name="twitter:site" content="@ludumdare" />';
    $twitter = get_the_author_meta('twitter', (string) $uid);
    //get_the_author_meta('twitter', $user["ID"]);
    if ($twitter != null && $twitter != '') {
        echo '<meta name="twitter:creator" content="@' . $twitter . '" />';
    }
    echo '<meta name="twitter:title" content="' . substr(htmlentities($ce["title"]), 0, 70) . '" />';
    echo '<meta name="twitter:description" content="' . substr(htmlentities($ce["notes"]), 0, 200) . '" />';
    if ($firstshot != null && $firstshot != '') {
        echo '<meta name="twitter:image" content="' . get_bloginfo("url") . '/wp-content/compo2/' . htmlentities($firstshot) . '" />';
    }
    echo '<script>';
    echo 'var Elm = document.getElementsByTagName("title")[0];';
    echo 'Elm.innerHTML = "' . htmlentities($ce["title"]) . ' by ' . $user["display_name"] . ' | " + Elm.innerHTML;';
    echo '</script>';
    // Rating Results //
    if ($params["state"] == "results" || $params["state"] == "admin") {
        if (!isset($params["{$div}_judged"]) || $params["{$div}_judged"] !== "0") {
            _compo2_results_ratings($params, $uid);
        }
    }
    // Comments ?? //
    if ($comments) {
        _compo2_preview_comments($params, $uid, true);
    }
}
Beispiel #5
0
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>";
}