get_error_message() ); error_log( $error_msg, 4 ); return $http_response; } else { $json = wp_remote_retrieve_body( $http_response ); $data = json_decode( $json, $assoc = true ); set_transient( $cachekey, $data, $cachetime ); } } return $data; } } /** * holds the community directory */ class FF_Directory { private $directory; function __construct( $ext_data_service = null ) { if ( is_null( $ext_data_service ) ) { $ed = new FF_Meta_Externaldata(); } else { $ed = $ext_data_service; } $data = $ed->get( FF_META_DEFAULT_DIR ); if ( is_wp_error( $data ) ) { $this->directory = array(); } else { $this->directory = $data; } } function get_url_by_city( $city ) { if ( array_key_exists( $city, $this->directory ) ) { return $this->directory[$city]; } else { return false; } } } /** * OO interface to handle a single community/city */ class FF_Community { public $name; public $street; public $zip; public $city; public $lon; public $lat; /** * Default constructor from metadata */ function __construct( $metadata ) { $loc = $metadata['location']; $this->name = ( isset( $loc['address'] ) && isset( $loc['address']['Name'] ) ) ? $loc['address']['Name'] : ''; $this->street = ( isset( $loc['address'] ) && isset( $loc['address']['Street'] ) ) ? $loc['address']['Street'] : ''; $this->zip = ( isset( $loc['address'] ) && isset( $loc['address']['Zipcode'] ) ) ? $loc['address']['Zipcode'] : ''; $this->city = isset( $loc['city'] ) ? $loc['city'] : ''; $this->lon = isset( $loc['lon'] ) ? $loc['lon'] : ''; $this->lat = isset( $loc['lat'] ) ? $loc['lat'] : ''; } /** * Alternative constructor from city name */ static function make_from_city( $city, $ext_data_service = null ) { if ( is_null( $ext_data_service ) ) { $ed = new FF_Meta_Externaldata(); } else { $ed = $ext_data_service; } $directory = new FF_Directory( $ed ); if ( false === ( $url = $directory->get_url_by_city( $city ) ) ) { return '\n"; } if ( false === ( $metadata = $ed->get( $url ) ) ) { return "\n"; } return new FF_Community( $metadata ); } function format_address() { if ( empty( $this->name ) || empty( $this->street ) || empty( $this->zip ) ) { return ''; } // TODO: style address + map as single box // TODO: once it is "ready" package openlayers.js into the plugin // ( cf. http://docs.openlayers.org/library/deploying.html ) // TODO: handle missing values ( i.e. only name & city ) return sprintf( '
%s
%s
%s %s
';
// Output -- rather ugly but the data is not uniform,
// some fields are URIs, some are usernames, ...
if ( ! empty( $contact['email'] ) ) {
$outstr .= sprintf(
'E-Mail: %s
',
$contact['email'], $contact['email']
);
}
if ( ! empty( $contact['ml'] ) ) {
$outstr .= sprintf(
'Mailingliste: %s
',
$contact['ml'], $contact['ml']
);
}
if ( ! empty( $contact['irc'] ) ) {
$outstr .= sprintf(
'IRC: %s
',
$contact['irc'], $contact['irc']
);
}
if ( ! empty( $contact['twitter'] ) ) {
// catch username instead of URI
if ( $contact['twitter'][0] === '@' ) {
$twitter_url = 'http://twitter.com/' . ltrim( $contact['twitter'], '@' );
$twitter_handle = $contact['twitter'];
} else {
$twitter_url = $contact['twitter'];
$twitter_handle = '@' . substr(
$contact['twitter'], strrpos( $contact['twitter'], '/' ) + 1
);
}
$outstr .= sprintf(
'Twitter: %s
',
$twitter_url, $twitter_handle
);
}
if ( ! empty( $contact['facebook'] ) ) {
$outstr .= sprintf(
'Facebook: %s
',
$contact['facebook'], $contact['facebook']
);
}
if ( ! empty( $contact['googleplus'] ) ) {
$outstr .= sprintf(
'G+: %s
',
$contact['googleplus'], $contact['googleplus']
);
}
if ( ! empty( $contact['jabber'] ) ) {
$outstr .= sprintf(
'XMPP: %s
',
$contact['jabber'], $contact['jabber']
);
}
$outstr .= '
This is the default city parameter.
'; } function options_page() { ?>