summaryrefslogtreecommitdiff
path: root/lib/helpers.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/helpers.php')
-rw-r--r--lib/helpers.php33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/helpers.php b/lib/helpers.php
index 4d6ca3c..2102ee1 100644
--- a/lib/helpers.php
+++ b/lib/helpers.php
@@ -120,8 +120,8 @@ function micropub_media_post_for_user(&$user, $file) {
$r = micropub_post($user->micropub_media_endpoint, [], $user->micropub_access_token, $file, true, 'file');
// Check the response and look for a "Location" header containing the URL
- if($r['response'] && preg_match('/Location: (.+)/', $r['response'], $match)) {
- $r['location'] = trim($match[1]);
+ if($r['headers'] && $r['headers']['Location']) {
+ $r['location'] = $r['headers']['Location'];
} else {
$r['location'] = false;
}
@@ -269,6 +269,7 @@ function parse_headers($headers) {
function get_micropub_config(&$user, $query=[]) {
$targets = [];
+ $channels = [];
$r = micropub_get($user->micropub_endpoint, $query, $user->micropub_access_token);
if($r['data'] && is_array($r['data']) && array_key_exists('syndicate-to', $r['data'])) {
@@ -295,8 +296,13 @@ function get_micropub_config(&$user, $query=[]) {
}
}
+ if($r['data'] && is_array($r['data']) && array_key_exists('channels', $r['data']) && is_array($r['data']['channels'])) {
+ $channels = $r['data']['channels'];
+ }
+
// Reset the values so they can be overwritten
$user->syndication_targets = '';
+ $user->channels = '';
$user->supported_post_types = '';
$user->supported_visibility = '';
$user->micropub_media_endpoint = '';
@@ -304,6 +310,9 @@ function get_micropub_config(&$user, $query=[]) {
if(count($targets))
$user->syndication_targets = json_encode($targets);
+ if(count($channels))
+ $user->channels = json_encode($channels);
+
$media_endpoint = false;
$supported_post_types = false;
if($r['data'] && is_array($r['data'])) {
@@ -325,6 +334,7 @@ function get_micropub_config(&$user, $query=[]) {
return [
'targets' => $targets,
+ 'channels' => $channels,
'response' => $r
];
}
@@ -360,7 +370,12 @@ function get_micropub_source(&$user, $url, $properties) {
}
function static_map($latitude, $longitude, $height=180, $width=700, $zoom=14) {
- return 'https://atlas.p3k.io/map/img?marker[]=lat:' . $latitude . ';lng:' . $longitude . ';icon:small-blue-cutout&basemap=gray&width=' . $width . '&height=' . $height . '&zoom=' . $zoom;
+ $params = [
+ 'h' => $height,
+ 'w' => $width,
+ 'z' => $zoom,
+ ];
+ return '/map-img?lat='.$latitude.'&lng='.$longitude.'&'.http_build_query($params);
}
function relative_time($date) {
@@ -407,8 +422,8 @@ function validate_photo(&$file) {
}
// You should also check filesize here.
- if ($file['size'] > 4000000) {
- throw new RuntimeException('Exceeded filesize limit.');
+ if ($file['size'] > 12000000) {
+ throw new RuntimeException('Exceeded Quill filesize limit.');
}
// DO NOT TRUST $file['mime'] VALUE !!
@@ -438,6 +453,11 @@ function correct_photo_rotation($filename) {
if(class_exists('IMagick')) {
try {
$image = new IMagick($filename);
+
+ // Don't try to convert animated images
+ if($image->getImageIterations() == 1)
+ return;
+
$orientation = $image->getImageOrientation();
switch($orientation) {
case IMagick::ORIENTATION_BOTTOMRIGHT:
@@ -449,6 +469,9 @@ function correct_photo_rotation($filename) {
case IMagick::ORIENTATION_LEFTBOTTOM:
$image->rotateImage(new ImagickPixel('#00000000'), -90);
break;
+ default:
+ // Don't overwrite if no orientation header was returned
+ return;
}
$image->setImageOrientation(IMagick::ORIENTATION_TOPLEFT);
$image->writeImage($filename);