diff --git a/include/event.php b/include/event.php index c49c9220f..9172e3ecc 100644 --- a/include/event.php +++ b/include/event.php @@ -38,9 +38,9 @@ function format_event_html($ev, $simple = false) { ); if ($simple) { - $o = "
" . BBCode::convert($ev['desc']) . "
"; + $o .= "" . BBCode::convert($ev['desc'], false, $simple) . "
"; $o .= "" . $event_start . "
"; @@ -49,7 +49,7 @@ function format_event_html($ev, $simple = false) { } if (strlen($ev['location'])) { - $o .= "" . BBCode::convert($ev['location']) . "
"; + $o .= "" . BBCode::convert($ev['location'], false, $simple) . "
"; } return $o; @@ -57,7 +57,7 @@ function format_event_html($ev, $simple = false) { $o = '' . Map::byLocation($match[1]) . '
', $match[0]); + function ($match) use ($simple_html) { + return str_replace($match[0], '' . Map::byLocation($match[1], $simple_html) . '
', $match[0]); }, $text ); @@ -1614,14 +1614,14 @@ class BBCode if (strpos($text, '[map=') !== false) { $text = preg_replace_callback( "/\[map=(.*?)\]/ism", - function ($match) { - return str_replace($match[0], '' . Map::byCoordinates(str_replace('/', ' ', $match[1])) . '
', $match[0]); + function ($match) use ($simple_html) { + return str_replace($match[0], '' . Map::byCoordinates(str_replace('/', ' ', $match[1]), $simple_html) . '
', $match[0]); }, $text ); } if (strpos($text, '[map]') !== false) { - $text = preg_replace("/\[map\]/", '', $text); + $text = preg_replace("/\[map\]/", '', $text); } // Check for headers diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 9da41b1b3..cc4b23083 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -29,6 +29,7 @@ use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; +use Friendica\Util\Map; use dba; use SimpleXMLElement; @@ -3618,10 +3619,18 @@ class Diaspora $eventdata['description'] = html_entity_decode(bb2diaspora($event['desc'])); } if ($event['location']) { + $event['location'] = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $event['location']); + $coord = Map::getCoordinates($event['location']); + $location = []; $location["address"] = html_entity_decode(bb2diaspora($event['location'])); - $location["lat"] = 0; - $location["lng"] = 0; + if (!empty($coord['lat']) && !empty($coord['lon'])) { + $location["lat"] = $coord['lat']; + $location["lng"] = $coord['lon']; + } else { + $location["lat"] = 0; + $location["lng"] = 0; + } $eventdata['location'] = $location; } @@ -3715,7 +3724,13 @@ class Diaspora if (count($event)) { $message['event'] = $event; - /// @todo Once Diaspora supports it, we will remove the body + if (!empty($event['location']['address']) && + !empty($event['location']['lat']) && + !empty($event['location']['lng'])) { + $message['location'] = $event['location']; + } + + /// @todo Once Diaspora supports it, we will remove the body and the location hack above // $message['text'] = ''; } } diff --git a/src/Util/Map.php b/src/Util/Map.php index e736ca719..d3ac02166 100644 --- a/src/Util/Map.php +++ b/src/Util/Map.php @@ -10,17 +10,23 @@ use Friendica\Core\Addon; * Leaflet Map related functions */ class Map { - public static function byCoordinates($coord) { + public static function byCoordinates($coord, $html_mode = 0) { $coord = trim($coord); $coord = str_replace([',','/',' '],[' ',' ',' '],$coord); - $arr = ['lat' => trim(substr($coord,0,strpos($coord,' '))), 'lon' => trim(substr($coord,strpos($coord,' ')+1)), 'html' => '']; + $arr = ['lat' => trim(substr($coord,0,strpos($coord,' '))), 'lon' => trim(substr($coord,strpos($coord,' ')+1)), 'mode' => $html_mode, 'html' => '']; Addon::callHooks('generate_map',$arr); return ($arr['html']) ? $arr['html'] : $coord; } - public static function byLocation($location) { - $arr = ['location' => $location, 'html' => '']; + public static function byLocation($location, $html_mode = 0) { + $arr = ['location' => $location, 'mode' => $html_mode, 'html' => '']; Addon::callHooks('generate_named_map',$arr); return ($arr['html']) ? $arr['html'] : $location; } + + public static function getCoordinates($location) { + $arr = ['location' => $location, 'lat' => false, 'lon' => false]; + Addon::callHooks('Map::getCoordinates', $arr); + return $arr; + } }