<?php
/* generate the code within an iframe
 * ex: https://growingbolder.com/wp-content/plugins/bolderplayer/bolder_jw5_iframe_get.php?id=911984
 * ex: https://growingbolder.com/wp-content/plugins/boldernetdata/bolder_jw5_iframe_get.php?id=3022113&ads=no
 * 
 */

#give me access to everything that is wordpress environment! bitch!
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');

global $wp_query;
global $post;

#was an ID passed in?
$id = $_GET['id'];
if(!$id) die('Error 2-16-9-a: No Post ID found.');


// is this a bmguid request?
if (strlen($id) == 24) {
	// this maybe a bmguid request. 
	// is there an asset with this id?
	$args = array(
		'post_type'  => 'bmgasset',
		'meta_query' => array(
			array(
				'key'     => 'bmguid',
				'value'   => $id,
				'compare' => '=',
			),
		),
	);
	$the_query = new WP_Query( $args );
	if ( $the_query->have_posts() ) {
		while ( $the_query->have_posts() ) {
			$fpost = $the_query->the_post();
			$id = $fpost->ID;
		}
	}
}

// this is not a bmguid request. 
// attempt to look up the single post by id
$post = get_post($id);


// does this ID relate to an actual post in our database?
if(!$post) die('Error 2-16-9-b: No Post found for ID-'.$id);

// return HTML for for iframe
require_once('bolder_jw5_iframe.php');
