Fix: Events on Diaspora now should look fine

This commit is contained in:
Michael 2018-03-20 06:32:17 +00:00
parent 9c5f2ad0fc
commit f4ba5d9799
4 changed files with 40 additions and 19 deletions

View File

@ -38,9 +38,9 @@ function format_event_html($ev, $simple = false) {
); );
if ($simple) { if ($simple) {
$o = "<h3>" . BBCode::convert($ev['summary']) . "</h3>"; $o = "<h3>" . BBCode::convert($ev['summary'], false, $simple) . "</h3>";
$o .= "<p>" . BBCode::convert($ev['desc']) . "</p>"; $o .= "<p>" . BBCode::convert($ev['desc'], false, $simple) . "</p>";
$o .= "<h4>" . L10n::t('Starts:') . "</h4><p>" . $event_start . "</p>"; $o .= "<h4>" . L10n::t('Starts:') . "</h4><p>" . $event_start . "</p>";
@ -49,7 +49,7 @@ function format_event_html($ev, $simple = false) {
} }
if (strlen($ev['location'])) { if (strlen($ev['location'])) {
$o .= "<h4>" . L10n::t('Location:') . "</h4><p>" . BBCode::convert($ev['location']) . "</p>"; $o .= "<h4>" . L10n::t('Location:') . "</h4><p>" . BBCode::convert($ev['location'], false, $simple) . "</p>";
} }
return $o; return $o;
@ -57,7 +57,7 @@ function format_event_html($ev, $simple = false) {
$o = '<div class="vevent">' . "\r\n"; $o = '<div class="vevent">' . "\r\n";
$o .= '<div class="summary event-summary">' . BBCode::convert($ev['summary']) . '</div>' . "\r\n"; $o .= '<div class="summary event-summary">' . BBCode::convert($ev['summary'], false, $simple) . '</div>' . "\r\n";
$o .= '<div class="event-start"><span class="event-label">' . L10n::t('Starts:') . '</span>&nbsp;<span class="dtstart" title="' $o .= '<div class="event-start"><span class="event-label">' . L10n::t('Starts:') . '</span>&nbsp;<span class="dtstart" title="'
. DateTimeFormat::utc($ev['start'], (($ev['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s' )) . DateTimeFormat::utc($ev['start'], (($ev['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s' ))
@ -71,16 +71,16 @@ function format_event_html($ev, $simple = false) {
. '</span></div>' . "\r\n"; . '</span></div>' . "\r\n";
} }
$o .= '<div class="description event-description">' . BBCode::convert($ev['desc']) . '</div>' . "\r\n"; $o .= '<div class="description event-description">' . BBCode::convert($ev['desc'], false, $simple) . '</div>' . "\r\n";
if (strlen($ev['location'])) { if (strlen($ev['location'])) {
$o .= '<div class="event-location"><span class="event-label">' . L10n::t('Location:') . '</span>&nbsp;<span class="location">' $o .= '<div class="event-location"><span class="event-label">' . L10n::t('Location:') . '</span>&nbsp;<span class="location">'
. BBCode::convert($ev['location']) . BBCode::convert($ev['location'], false, $simple)
. '</span></div>' . "\r\n"; . '</span></div>' . "\r\n";
// Include a map of the location if the [map] BBCode is used. // Include a map of the location if the [map] BBCode is used.
if (strpos($ev['location'], "[map") !== false) { if (strpos($ev['location'], "[map") !== false) {
$map = Map::byLocation($ev['location']); $map = Map::byLocation($ev['location'], $simple);
if ($map !== $ev['location']) { if ($map !== $ev['location']) {
$o.= $map; $o.= $map;
} }

View File

@ -1605,8 +1605,8 @@ class BBCode
if (strpos($text, '[/map]') !== false) { if (strpos($text, '[/map]') !== false) {
$text = preg_replace_callback( $text = preg_replace_callback(
"/\[map\](.*?)\[\/map\]/ism", "/\[map\](.*?)\[\/map\]/ism",
function ($match) { function ($match) use ($simple_html) {
return str_replace($match[0], '<p class="map">' . Map::byLocation($match[1]) . '</p>', $match[0]); return str_replace($match[0], '<p class="map">' . Map::byLocation($match[1], $simple_html) . '</p>', $match[0]);
}, },
$text $text
); );
@ -1614,14 +1614,14 @@ class BBCode
if (strpos($text, '[map=') !== false) { if (strpos($text, '[map=') !== false) {
$text = preg_replace_callback( $text = preg_replace_callback(
"/\[map=(.*?)\]/ism", "/\[map=(.*?)\]/ism",
function ($match) { function ($match) use ($simple_html) {
return str_replace($match[0], '<p class="map">' . Map::byCoordinates(str_replace('/', ' ', $match[1])) . '</p>', $match[0]); return str_replace($match[0], '<p class="map">' . Map::byCoordinates(str_replace('/', ' ', $match[1]), $simple_html) . '</p>', $match[0]);
}, },
$text $text
); );
} }
if (strpos($text, '[map]') !== false) { if (strpos($text, '[map]') !== false) {
$text = preg_replace("/\[map\]/", '<div class="map"></div>', $text); $text = preg_replace("/\[map\]/", '<p class="map"></p>', $text);
} }
// Check for headers // Check for headers

View File

@ -29,6 +29,7 @@ use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use Friendica\Util\Map;
use dba; use dba;
use SimpleXMLElement; use SimpleXMLElement;
@ -3618,10 +3619,18 @@ class Diaspora
$eventdata['description'] = html_entity_decode(bb2diaspora($event['desc'])); $eventdata['description'] = html_entity_decode(bb2diaspora($event['desc']));
} }
if ($event['location']) { if ($event['location']) {
$event['location'] = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $event['location']);
$coord = Map::getCoordinates($event['location']);
$location = []; $location = [];
$location["address"] = html_entity_decode(bb2diaspora($event['location'])); $location["address"] = html_entity_decode(bb2diaspora($event['location']));
$location["lat"] = 0; if (!empty($coord['lat']) && !empty($coord['lon'])) {
$location["lng"] = 0; $location["lat"] = $coord['lat'];
$location["lng"] = $coord['lon'];
} else {
$location["lat"] = 0;
$location["lng"] = 0;
}
$eventdata['location'] = $location; $eventdata['location'] = $location;
} }
@ -3715,7 +3724,13 @@ class Diaspora
if (count($event)) { if (count($event)) {
$message['event'] = $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'] = ''; // $message['text'] = '';
} }
} }

View File

@ -10,17 +10,23 @@ use Friendica\Core\Addon;
* Leaflet Map related functions * Leaflet Map related functions
*/ */
class Map { class Map {
public static function byCoordinates($coord) { public static function byCoordinates($coord, $html_mode = 0) {
$coord = trim($coord); $coord = trim($coord);
$coord = str_replace([',','/',' '],[' ',' ',' '],$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); Addon::callHooks('generate_map',$arr);
return ($arr['html']) ? $arr['html'] : $coord; return ($arr['html']) ? $arr['html'] : $coord;
} }
public static function byLocation($location) { public static function byLocation($location, $html_mode = 0) {
$arr = ['location' => $location, 'html' => '']; $arr = ['location' => $location, 'mode' => $html_mode, 'html' => ''];
Addon::callHooks('generate_named_map',$arr); Addon::callHooks('generate_named_map',$arr);
return ($arr['html']) ? $arr['html'] : $location; 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;
}
} }