[insert_php]

get_header();

define(‘EVENTS_PAGE_NAME’, ‘Events’);
define(‘EVENTUPON_API_URL’, “https://api.meetup.com/2/open_events.xml”);
define(‘EVENTUPON_API_KEY’, “b7175506853e16b4c5213293d3b5e”);

function get_site_event_range(){
$zipcode = get_option(‘zipcode’);
$events_range = get_option(‘events_range’);
if(!empty($zipcode) && !empty($events_range)){
return $zipcode . “:” . $events_range;
}elseif(!empty($zipcode) && empty($events_range)){
return $zipcode;
}
return false;
}
function get_site_state(){
$state = get_option(‘state’);
if(!empty($state)){
return $state;
}
return false;
}

function paragraph_excerpt($text, $limit = 300) {
if ( ” != $text ) {
$text = strip_tags( $text );
$text = strip_shortcodes( $text );
$text = trim( $text );

if(strlen($text)>$limit){
$text = substr($text, 0, ($limit-3));
$last_space = strrpos($text, ‘ ‘);
$text = substr($text, 0, $last_space) . ‘…’;
}
$text = $text;
}
return $text;
}

function get_request_object(){
$request_obj = new stdClass();

$protocol = ‘http’;
if (isset($_SERVER[“HTTPS”]) && $_SERVER[“HTTPS”] == “on”) {$protocol .= “s”;}
$protocol .= ‘://’;
$site_url = $protocol . $_SERVER[‘SERVER_NAME’];
$request_uri = $_SERVER[‘REQUEST_URI’];
$request = explode(‘?’, $request_uri);
$request_vars = array();
$page_url = ”;
$query_url = ”;

if(isset($request[0])){
$page_url = $request[0];
}
if(isset($request[1])){
$query_url = $request[1];
$request = explode(‘&’, $request[1]);
foreach($request as $r){
$var = explode(‘=’, $r);
if(count($var)>1){
$request_vars[$var[0]] = $var[1];
}
}
}

$request_obj->protocol = $protocol;
$request_obj->site_url = $site_url;
$request_obj->page_url = $page_url;
$request_obj->request_uri = $request_uri;
$request_obj->request_vars = $request_vars;
$request_obj->current_url = $site_url . $request_uri;

return $request_obj;
}

function get_domain(){
$server_name= $_SERVER[‘SERVER_NAME’];
if(!$_SERVER[‘SERVER_NAME’]){return;}

$domain = ”;
$pos_last = strrpos($server_name, ‘.’);
$pos_med = strrpos($server_name, ‘.’, -1*$pos_last);

if($pos_med>0){
$domain = substr($server_name, $pos_med+1);
}else{
$domain = $server_name;
}
return $domain;
}

function eventupon_get($limit = 5, $query = null){
$myfile = fopen(“testfile.txt”, “w”);
$txt = “John Doe\n”;
fwrite($myfile, $txt);
fclose($myfile);
$args = array();
if(isset($query) && is_array($query)){
$args = array_merge($args, $query);
}
if($limit){
$args = array_merge($args, array(“count” => $limit) );
}

$events_data = eventupon_get_events($args);
if($events_data){
return $events_data;
}

}

function eventupon_get_events($args = null){
$event_obj = new stdClass();
$events = array();
$method = ‘event_calendar.list’;
$radius = 10;
$options_query = ‘country=us&state=WV&city=Berkeley%20Springs’;
$query = “https://api.meetup.com/2/open_events.xml” . ‘?’. $options_query . ‘&key=’ . “b7175506853e16b4c5213293d3b5e” . ‘&radius=’ . $radius ;
$today = date(‘Y-m-d’);
$events_data = @simplexml_load_file($query);
if($events_data === false){die(‘test’);
echo ”

fail to load feed

“;
}else{
if(!empty($events_data) && isset($events_data)){
if($events_data->items->item){
// sort events chronologically
//key needs to be unique, Identical start dates get overwritten -JF
$event_count=1;
$items = array();
foreach($events_data->items->item as $item){
if(isset($item->photo_url) && (“”.$item->photo_url != ”)){
$item->thumbnail = ‘' . $item->name . '‘;
}else{
if(strpos($item->event_url,’eventbrite.com’)!==false){
$item->thumbnail = ‘' . $item->name . '‘;
}elseif(strpos($item->event_url,’eventful.com’)!==false){
$item->thumbnail = ‘' . $item->name . '‘;
}elseif(strpos($item->event_url,’meetup.com’)!==false){
$item->thumbnail = ‘' . $item->name . '‘;
}else{
$item->thumbnail = ‘' . $item->name . '‘;
}
}

$item->title = $item->name;
$body = paragraph_excerpt($item->description, 270);
if(strlen($body)>0){
$item->description = $body;
}
if(“”.$item->group->name != ‘evdb’){
$item->host_name = $item->group->name;
}

$events[] = $item;
}
}
if(count($events)>0){
$event_obj->events = $events;
}
return $event_obj;
}
return false;
}
}

function eventupon_show_events($limit = null, $title = ‘Events’){
$query = array();
$day_picked = ”;

if( isset($_REQUEST[‘events_day’]) ){
$req_date = explode(“-“, strip_tags($_REQUEST[‘events_day’]));
foreach($req_date as $date){
$date = intval($date);
}
if(count($req_date>2)){

$before_date = strtotime($req_date[0] . ‘-‘ . $req_date[1] . ‘-‘ . $req_date[2] ) + (60*60*24);
$before_date = date(‘Y-m-j’, $before_date);
$query = array_merge($query, array(
‘after_date’ => $req_date[0] . ‘-‘ . $req_date[1] . ‘-‘ . $req_date[2],
‘before_date’ => $before_date
));
$day_picked = strftime(“%B %e, %Y”, strtotime($req_date[0] . ‘-‘ . $req_date[1] . ‘-‘ . $req_date[2]));
}
} elseif(isset($_REQUEST[‘events_after’]) && isset($_REQUEST[‘events_before’])){
$query = array_merge($query, array(
‘after_date’ => strip_tags($_REQUEST[‘events_after’]),
‘before_date’ => strip_tags($_REQUEST[‘events_before’])
));
}

if ( isset($_GET) && isset($_GET[‘host_name’]) && is_string($_GET[‘host_name’]) ){
$query = array_merge($query, array(‘host_name’ => strip_tags($_GET[‘host_name’])));
}

if ( isset($_GET) && isset($_GET[‘event_tags’]) && is_string($_GET[‘event_tags’]) ){
$query = array_merge($query, array(‘event_tags’ => strip_tags($_GET[‘event_tags’])));
}

if(isset($_REQUEST[‘events_page’])){
$query = array_merge($query, array(‘page’ => strip_tags($_REQUEST[‘events_page’])));
}

$eventupon_data = eventupon_get($limit, $query);

if($eventupon_data){

$eb_events_to_loop = $eventupon_data->events;
echo ”

“;
echo “

“;

echo ”

“;
if($eb_events_to_loop){
foreach($eb_events_to_loop as $eventupon_item){
echo “

“;
echo ”

“;
if(isset($eventupon_item->photo_url) && !empty($eventupon_item->photo_url)){
echo “photo_url[0].”\” alt=\”\” />
“;
}
echo “

“;
echo ”

“;
error_log($eventupon_item);error_log(“Error message\n”.$eventupon_item, 3, “myphplog.log”);
echo “

“;
echo ”

“;
echo ”

event_url.”\” target=\”_blank\”>”.$eventupon_item->title.”

“;

if(!empty($eventupon_item->start) || !empty($eventupon_item->end)){
$date_format=”F j, Y”;

if(isset($eventupon_item->start) && !empty($eventupon_item->start)){
//convert provided time format
$start_parts = explode(” “,$eventupon_item->start);
if(isset($start_parts) && !empty($start_parts)){ $start_date_parts = explode(“-“,$start_parts[0]); }
if(isset($start_date_parts) && !empty($start_date_parts)){ $start_date = mktime(0, 0, 0, $start_date_parts[1], $start_date_parts[2], $start_date_parts[0]); }
if(isset($start_parts) && !empty($start_parts) && is_array($start_parts) && !empty($start_parts[1]) && !empty($start_parts[2])){ $start_time = $start_parts[1].” “.$start_parts[2]; }
}else{
$start_parts=””;
$start_date_parts=””;
}
if(isset($eventupon_item->end) && !empty($eventupon_item->end)){
//convert provided time format
$end_parts = explode(” “,$eventupon_item->end);
if(isset($end_parts) && !empty($end_parts)){ $end_date_parts = explode(“-“,$end_parts[0]); }
if(isset($end_date_parts) && !empty($end_date_parts)){ $end_date = mktime(0, 0, 0, $end_date_parts[1], $end_date_parts[2], $end_date_parts[0]); }
if(isset($end_parts) && !empty($end_parts) && !empty($end_parts[1]) && !empty($end_parts[2])){ $end_time = $end_parts[1].” “.$end_parts[2]; }
}else{
$end_parts=””;
$end_date_parts=””;
}
echo ”

“;
if(!empty($eventupon_item->start) && !empty($start_time)){
echo date($date_format,$start_date).” “.$start_time;
}else{
echo date($date_format,$start_date);
}
if(!empty($eventupon_item->end)){

if(!empty($eventupon_item->start)){
echo ” — “;
}
if(!isset($end_time)){ $end_time=””; }
echo date($date_format,$end_date).” “.$end_time;
}
echo ”

“;
}
if(isset($eventupon_item->location_name) && !empty($eventupon_item->location_name)){
echo ”

at “.$eventupon_item->location_name.”

“;
}
if(isset($eventupon_item->description) && !empty($eventupon_item->description)){
echo wpautop(wptexturize(paragraph_excerpt($eventupon_item->description)));
}
if(isset($eventupon_item->description) && !empty($eventupon_item->description)){
echo ”

Hosted by “.$eventupon_item->host_name.”

“;
}
echo ”

“;
echo ”

“;

$start_parts = “”;
$end_parts = “”;

//convert provided time format
$start_parts = “”;
$start_date_parts = “”;
$start_date = “”;
$start_time = “”;

$end_parts = “”;
$end_date_parts = “”;
$end_date = “”;
$end_time = “”;

}
echo ”

“;
echo ”

“;
echo “

“;
echo ”

“;
}else{
}
echo ”

“;
}
}

if ( have_posts() ) {
[/insert_php]

[insert_php] the_title();[/insert_php]

[insert_php]
}
[/insert_php]

[insert_php]
$postr = get_post(get_the_id());
$slugr = $postr->post_name;
eventupon_show_events(10, $slugr);
[/insert_php]


[insert_php] get_sidebar();[/insert_php]

[insert_php]
//get_template_part(‘sidebars/pov_events_sidebar’);
[/insert_php]

[insert_php]
get_footer();
[/insert_php]