Brightkite Location Plugin
The file {$_user} is not writable. Please ensure that your Brighkite Location plugin folder is writable, or create the file manually and apply appropriate write permissions.");
return;
}
}
$headers = "GET /people/{$user}/objects.rss HTTP/1.0\r\n";
$headers .= "Host: brightkite.com\r\n";
$headers .= "Connection: Close\r\n\r\n";
$socket = @fsockopen("brightkite.com", 80, $errno, $errstr, 30);
if(!$socket) {
if($critical) echo 'Brightkite Location Plugin
Unable to reach to the Brightkite servers. Try again later.
';
return false;
} else {
@fwrite($socket, $headers);
$data = ''; while (!feof($socket)) $data .= @fgets($socket, 128);
@fclose($socket);
$data = trim(substr($data, strpos($data, "\r\n\r\n")));
if(!$data) {
if($critical) echo 'Brightkite Location Plugin
There was an error retrieving your feed. Brightkite may be down for maintenance. Please try again shortly.
';
return false;
}
if(!function_exists('xmlize')) include("{$path}xml.php");
if(!function_exists('xmlize')) echo 'Brightkite Location Plugin
Unable to load XML processing library.
';
$xml = xmlize($data);
if(!$xml || !isset($xml['rss']['#']['channel'][0]['#']['item'][0]['#']['title'])) {
if($critical) echo 'Brightkite Location Plugin
Brightkite returned an unexpected message. Please check your username and try again.
';
return false;
} unset($data);
$event = $xml['rss']['#']['channel'][0]['#']['item'][0]['#'];
$data['link'] = $event['link'][0]['#'];
$data['lat'] = $event['geo:lat'][0]['#'];
$data['long'] = $event['geo:long'][0]['#'];
if(isset($event['bk:placeAddress'][0]['#'])) {
$data['place'] = $event['bk:placeAddress'][0]['#'];
if(substr($data['place'], -4) == ' USA') {
// Strip out zip if in the United States.
$data['place'] = trim(substr($data['place'], 0, -4));
if(substr($data['place'], -1) == ',' && is_numeric(substr($data['place'], -6, 5))) {
$data['place'] = trim(substr($data['place'], 0, -7));
}
}
}
if($event['bk:eventType'][0]['#'] == 'photo' && isset($event['media:thumbnail'])) {
$photo = $event['media:thumbnail'][0]['@'];
$data['description'] = '
';
if($event['bk:photoCaption'][0]['#']) $data['description'] .= '
' . htmlentities($event['bk:photoCaption'][0]['#']);
} else {
$data['description'] = htmlentities($event['description'][0]['#']);
}
unset($xml);
$socket = @fopen("{$path}{$_user}", 'w');
if(!$socket) {
echo("Brightkite Location Plugin
The file {$_user} is not writable. Please ensure that your Brighkite Location plugin folder is writable, or create the file manually and apply appropriate write permissions.");
return;
}
@fwrite($socket, '<' . '?php $bkRenderDate = \'' . time() . '\'; $bkRenderData = \'' . addslashes(serialize($data)) . '\'; ?' . '>');
@fclose($socket);
return $data;
}
}
function bkWordpressHeaders() {
if(strpos(__FILE__, '\\wp-content')) {
$path['css'] = substr(__FILE__, strpos(__FILE__, '\\wp-content'));
$path['css'] = substr($path['css'], 0, strrpos($path['css'], '\\'));
} else {
$path['css'] = substr(__FILE__, strpos(__FILE__, '/wp-content'));
$path['css'] = substr($path['css'], 0, strrpos($path['css'], '/'));
}
echo "\t" . '' . "\n";
}
function bkRenderLocation($user, $api_key, $settings = array()) {
$_user = sprintf("%u", crc32(md5($user . get_bloginfo('wpurl')))) . '.cache';
if(strpos(__FILE__, '\\wp-content')) {
$path['physical'] = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '\\'));
$path['physical'] .= substr(__FILE__, strpos(__FILE__, '\\wp-content'));
$path['physical'] = substr($path['physical'], 0, strrpos($path['physical'], '\\')) . '/';
$path['css'] = substr(__FILE__, strpos(__FILE__, '\\wp-content'));
$path['css'] = substr($path['css'], 0, strrpos($path['css'], '\\'));
} else {
$path['physical'] = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], '/'));
$path['physical'] .= substr(__FILE__, strpos(__FILE__, '/wp-content'));
$path['physical'] = substr($path['physical'], 0, strrpos($path['physical'], '/')) . '/';
$path['css'] = substr(__FILE__, strpos(__FILE__, '/wp-content'));
$path['css'] = substr($path['css'], 0, strrpos($path['css'], '/'));
}
if(!$path['physical']) { echo '
Brightkite Location Plugin
Unable to determine physical location.
'; return; }
if(!$path['css']) { echo 'Brightkite Location Plugin
Unable to determine stylesheet location.
'; return; }
$path['css'] = str_replace('\\', '/', $path['css']) . '/style.css';
$data = null;
$bkRenderDate = null;
//if(!file_exists("{$path['physical']}{$_user}")) {
$data = bkUpdateFeed($user, $path['physical'], true);
//} else {
// include("{$path['physical']}{$_user}");
// if(!isset($bkRenderDate) || $bkRenderDate == null || (time() - $bkRenderDate > 600)) $data = bkUpdateFeed($user, $path['physical']);
// if(!$data) $data = unserialize(stripslashes($bkRenderData));
//}
if($data) {
if(!isset($settings['map_width'])) $settings['map_width'] = 223;
if(!isset($settings['map_height'])) $settings['map_height'] = 134;
if(!isset($settings['map_zoom'])) $settings['map_zoom'] = 14;
if(!isset($settings['map_beacon_color'])) $settings['map_beacon_color'] = 'red';
if(!isset($settings['map_beacon_size'])) $settings['map_beacon_size'] = 'mid';
if(!isset($settings['map_provider'])) $settings['map_provider'] = 'static';
if($settings['map_provider'] != 'static' && $settings['map_provider'] != 'dynamic') $settings['map_provider'] = 'static';
if($settings['map_provider'] == 'static') {
if(!isset($settings['map_style'])) $settings['map_style'] = 'roadmap';
if($settings['map_style'] != 'roadmap' && $settings['map_style'] != 'mobile') $settings['map_style'] = 'roadmap';
echo '
';
} elseif($settings['map_provider'] == 'dynamic') {
if(!isset($settings['map_style'])) $settings['map_style'] = 'terrain';
if($settings['map_style'] != 'terrain' && $settings['map_style'] != 'roadmap' && $settings['map_style'] != 'satellite' && $settings['map_style'] != 'hybrid') $settings['map_style'] = 'terrain';
if($settings['map_style'] == 'terrain') $settings['map_style'] = 'G_PHYSICAL_MAP';
elseif($settings['map_style'] == 'roadmap') $settings['map_style'] = 'G_NORMAL_MAP';
elseif($settings['map_style'] == 'satellite') $settings['map_style'] = 'G_SATELLITE_MAP';
elseif($settings['map_style'] == 'hybrid') $settings['map_style'] = 'G_HYBRID_MAP';
echo '';
echo '';
echo '';
}
echo '' . $data['place'] . '
';
if(!strpos($data['description'], 'checked in @')) echo '' . $data['description'] . '
';
} else {
echo("Brightkite Location Plugin
Your feed could not be retrieved at this time. Try again shortly.");
}
}
add_action('wp_head', 'bkWordpressHeaders');
?>