mirror of
https://github.com/tchapi/davis.git
synced 2025-01-17 04:48:16 +01:00
feat: use OSM images for maps, remove Mapbox entirely
This commit is contained in:
parent
e4d3f8163a
commit
a8ac74ff4b
5
.env
5
.env
@ -68,8 +68,3 @@ INVITE_FROM_ADDRESS=no-reply@example.org
|
||||
# USE ABSOLUTE PATHS for better predictability
|
||||
TMP_DIR='/tmp'
|
||||
PUBLIC_DIR='/public'
|
||||
|
||||
# Used to show a nice map on event invitation mails.
|
||||
# Can be null (and the map won't show)
|
||||
# See https://docs.mapbox.com/api/overview/#access-tokens-and-token-scopes
|
||||
MAPBOX_API_KEY=null
|
@ -98,12 +98,6 @@ TMP_DIR='/tmp'
|
||||
PUBLIC_DIR='/public'
|
||||
```
|
||||
|
||||
g. The Mapbox API key so invitation emails display a nice little static map when the event has geolocation data in it
|
||||
|
||||
```
|
||||
MAPBOX_API_KEY=pk.XXXXXXXX
|
||||
```
|
||||
|
||||
### Specific environment variables for IMAP and LDAP authentication methods
|
||||
|
||||
In case you use the `IMAP` auth type, you must specify the auth url (_the "mailbox" url_) in `IMAP_AUTH_URL`. See https://www.php.net/manual/en/function.imap-open.php for more details.
|
||||
|
@ -8,6 +8,7 @@
|
||||
"ext-ctype": "*",
|
||||
"ext-iconv": "*",
|
||||
"composer-runtime-api": "^2",
|
||||
"dantsu/php-osm-static-api": "^0.3.0",
|
||||
"doctrine/annotations": "^1.0",
|
||||
"doctrine/doctrine-bundle": "^2.4",
|
||||
"doctrine/doctrine-migrations-bundle": "^3.1",
|
||||
|
1393
composer.lock
generated
1393
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,6 @@ services:
|
||||
$authRealm: "%env(AUTH_REALM)%"
|
||||
$publicDir: "%env(PUBLIC_DIR)%"
|
||||
$tmpDir: "%env(TMP_DIR)%"
|
||||
$mapboxApiKey: "%env(MAPBOX_API_KEY)%"
|
||||
|
||||
App\Security\LoginFormAuthenticator:
|
||||
arguments:
|
||||
|
@ -25,5 +25,3 @@ MAIL_HOST=smtp.myprovider.com
|
||||
MAIL_PORT=587
|
||||
MAIL_USERNAME=userdav
|
||||
MAIL_PASSWORD=test
|
||||
|
||||
MAPBOX_API_KEY=null
|
||||
|
@ -49,7 +49,6 @@ services:
|
||||
- TMP_DIR=${TMP_DIR}
|
||||
- PUBLIC_DIR=${PUBLIC_DIR}
|
||||
- INVITE_FROM_ADDRESS=${INVITE_FROM_ADDRESS}
|
||||
- MAPBOX_API_KEY=${MAPBOX_API_KEY}
|
||||
depends_on:
|
||||
- mysql
|
||||
volumes:
|
||||
|
@ -119,7 +119,7 @@ class DAVController extends AbstractController
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, ?string $inviteAddress = null, ?string $authMethod = null, ?string $authRealm = null, ?string $publicDir = null, ?string $tmpDir = null, ?string $mapboxApiKey = null)
|
||||
public function __construct(MailerInterface $mailer, BasicAuth $basicAuthBackend, IMAPAuth $IMAPAuthBackend, LDAPAuth $LDAPAuthBackend, UrlGeneratorInterface $router, EntityManagerInterface $entityManager, LoggerInterface $logger, bool $calDAVEnabled = true, bool $cardDAVEnabled = true, bool $webDAVEnabled = false, ?string $inviteAddress = null, ?string $authMethod = null, ?string $authRealm = null, ?string $publicDir = null, ?string $tmpDir = null)
|
||||
{
|
||||
$this->calDAVEnabled = $calDAVEnabled;
|
||||
$this->cardDAVEnabled = $cardDAVEnabled;
|
||||
@ -141,8 +141,6 @@ class DAVController extends AbstractController
|
||||
$this->IMAPAuthBackend = $IMAPAuthBackend;
|
||||
$this->LDAPAuthBackend = $LDAPAuthBackend;
|
||||
|
||||
$this->mapboxApiKey = $mapboxApiKey;
|
||||
|
||||
$this->initServer();
|
||||
$this->initExceptionListener();
|
||||
}
|
||||
@ -242,7 +240,7 @@ class DAVController extends AbstractController
|
||||
$this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin());
|
||||
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
|
||||
if ($this->inviteAddress) {
|
||||
$this->server->addPlugin(new DavisIMipPlugin($this->mailer, $this->inviteAddress, $this->mapboxApiKey));
|
||||
$this->server->addPlugin(new DavisIMipPlugin($this->mailer, $this->inviteAddress, $this->publicDir));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use DantSu\OpenStreetMapStaticAPI\LatLng;
|
||||
use DantSu\OpenStreetMapStaticAPI\Markers;
|
||||
use DantSu\OpenStreetMapStaticAPI\OpenStreetMap;
|
||||
use Sabre\CalDAV\Schedule\IMipPlugin as SabreBaseIMipPlugin;
|
||||
use Sabre\DAV;
|
||||
use Sabre\VObject\ITip;
|
||||
@ -29,23 +32,22 @@ final class DavisIMipPlugin extends SabreBaseIMipPlugin
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $mapboxApiKey;
|
||||
protected $publicDir;
|
||||
|
||||
/**
|
||||
* Creates the email handler.
|
||||
*
|
||||
* @param string $senderEmail. The 'senderEmail' is the email that shows up
|
||||
* in the 'From:' address. This should
|
||||
* generally be some kind of no-reply email
|
||||
* address you own.
|
||||
* @param string $mapboxApiKey. The key to display the Mapbox static tile
|
||||
* in the invitation email.
|
||||
* @param string $senderEmail. The 'senderEmail' is the email that shows up
|
||||
* in the 'From:' address. This should
|
||||
* generally be some kind of no-reply email
|
||||
* address you own.
|
||||
* @param string $publicDir. The directory where public images are stored.
|
||||
*/
|
||||
public function __construct(MailerInterface $mailer, string $senderEmail, ?string $mapboxApiKey = null)
|
||||
public function __construct(MailerInterface $mailer, string $senderEmail, string $publicDir)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
$this->senderEmail = $senderEmail;
|
||||
$this->mapboxApiKey = $mapboxApiKey;
|
||||
$this->publicDir = $publicDir;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,8 +167,7 @@ final class DavisIMipPlugin extends SabreBaseIMipPlugin
|
||||
$url = $notEmpty('URL', false);
|
||||
$description = $notEmpty('DESCRIPTION', false);
|
||||
$location = $notEmpty('LOCATION', false);
|
||||
$locationImagePath = null;
|
||||
$locationImageContentId = false;
|
||||
$locationImageDataAsBase64 = false;
|
||||
$locationLink = false;
|
||||
|
||||
if (isset($itip->message->VEVENT->{'X-APPLE-STRUCTURED-LOCATION'})) {
|
||||
@ -176,24 +177,24 @@ final class DavisIMipPlugin extends SabreBaseIMipPlugin
|
||||
$coordinates
|
||||
);
|
||||
if (0 !== $match) {
|
||||
if ($this->mapboxApiKey) {
|
||||
$zoom = 16;
|
||||
$width = 500;
|
||||
$height = 220;
|
||||
$locationImagePath = 'https://api.mapbox.com/styles/v1'.
|
||||
'/mapbox/streets-v11/static'.
|
||||
'/pin-m-star+285A98'.
|
||||
'('.$coordinates['longitude'].
|
||||
','.$coordinates['latitude'].
|
||||
')'.
|
||||
'/'.$coordinates['longitude'].
|
||||
','.$coordinates['latitude'].
|
||||
','.$zoom.
|
||||
'/'.$width.'x'.$height.
|
||||
'?access_token='.$this->mapboxApiKey;
|
||||
}
|
||||
$zoom = 16;
|
||||
$width = 500;
|
||||
$height = 220;
|
||||
|
||||
$latLng = new LatLng($coordinates['latitude'], $coordinates['longitude']);
|
||||
|
||||
// https://github.com/DantSu/php-osm-static-api
|
||||
$locationImageDataAsBase64 = (new OpenStreetMap($latLng, $zoom, $width, $height))
|
||||
->addMarkers(
|
||||
(new Markers($this->publicDir.'/images/marker.png'))
|
||||
->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)
|
||||
->addMarker(new LatLng($coordinates['latitude'], $coordinates['longitude']))
|
||||
)
|
||||
->getImage()
|
||||
->getBase64PNG();
|
||||
|
||||
$locationLink =
|
||||
'http://www.openstreetmap.org'.
|
||||
'https://www.openstreetmap.org'.
|
||||
'/?mlat='.$coordinates['latitude'].
|
||||
'&mlon='.$coordinates['longitude'].
|
||||
'#map='.$zoom.
|
||||
@ -214,11 +215,6 @@ final class DavisIMipPlugin extends SabreBaseIMipPlugin
|
||||
->addTextHeader('X-Auto-Response-Suppress', 'OOF, DR, RN, NRN, AutoReply');
|
||||
}
|
||||
|
||||
if (null !== $locationImagePath) {
|
||||
$locationImageContentId = 'event_map';
|
||||
$message->embedFromPath($locationImagePath, $locationImageContentId, 'image/png');
|
||||
}
|
||||
|
||||
// Now that we have everything, we can set the message body
|
||||
$message->htmlTemplate('mails/scheduling.html.twig')
|
||||
->textTemplate('mails/scheduling.txt.twig')
|
||||
@ -230,7 +226,7 @@ final class DavisIMipPlugin extends SabreBaseIMipPlugin
|
||||
'allDay' => $allDay,
|
||||
'attendees' => $attendees,
|
||||
'location' => $location,
|
||||
'locationImageContentId' => $locationImageContentId,
|
||||
'locationImageDataAsBase64' => $locationImageDataAsBase64,
|
||||
'locationLink' => $locationLink,
|
||||
'url' => $url,
|
||||
'description' => $description,
|
||||
|
24
symfony.lock
24
symfony.lock
@ -1,7 +1,4 @@
|
||||
{
|
||||
"composer/package-versions-deprecated": {
|
||||
"version": "1.11.99"
|
||||
},
|
||||
"composer/pcre": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
@ -11,6 +8,12 @@
|
||||
"composer/xdebug-handler": {
|
||||
"version": "1.4.3"
|
||||
},
|
||||
"dantsu/php-image-editor": {
|
||||
"version": "1.1.1"
|
||||
},
|
||||
"dantsu/php-osm-static-api": {
|
||||
"version": "0.3.0"
|
||||
},
|
||||
"doctrine/annotations": {
|
||||
"version": "1.0",
|
||||
"recipe": {
|
||||
@ -126,21 +129,12 @@
|
||||
"nikic/php-parser": {
|
||||
"version": "v4.9.1"
|
||||
},
|
||||
"ocramius/package-versions": {
|
||||
"version": "1.5.1"
|
||||
},
|
||||
"ocramius/proxy-manager": {
|
||||
"version": "2.2.3"
|
||||
},
|
||||
"phar-io/manifest": {
|
||||
"version": "2.0.1"
|
||||
},
|
||||
"phar-io/version": {
|
||||
"version": "3.1.0"
|
||||
},
|
||||
"php": {
|
||||
"version": "7.3.12"
|
||||
},
|
||||
"php-cs-fixer/diff": {
|
||||
"version": "v1.3.0"
|
||||
},
|
||||
@ -646,11 +640,5 @@
|
||||
},
|
||||
"webmozart/assert": {
|
||||
"version": "1.9.1"
|
||||
},
|
||||
"zendframework/zend-code": {
|
||||
"version": "3.4.1"
|
||||
},
|
||||
"zendframework/zend-eventmanager": {
|
||||
"version": "3.2.1"
|
||||
}
|
||||
}
|
||||
|
@ -97,11 +97,11 @@
|
||||
<td>{{ location }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if locationImageContentId %}
|
||||
{% if locationImageDataAsBase64 %}
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<a href="{{ locationLink }}" title="Navigate on this map">
|
||||
<img src="cid:{{ locationImageContentId }}" width="100%"/>
|
||||
<img src="data:image/png;base64,{{ locationImageDataAsBase64 }}" width="100%"/>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
x
Reference in New Issue
Block a user