Skip to content

Commit

Permalink
Merge pull request #28 from TomboFry/develop
Browse files Browse the repository at this point in the history
Release v1.0.1
  • Loading branch information
moonfloof authored Sep 17, 2019
2 parents e4fbb24 + 9ec1beb commit d59da0a
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 25 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.0.1 - 2019-09-17

### Added

* Dark mode for default theme (hint: there's an option in `index.php`)
* Media endpoint URL in HTML head section (in addition to micropub query)

### Fixed

* Uses current time if `published` value is an empty string on micropub API
* Properly escape values for meta tags in HTML head
* Prevent errors from occurring when trying to determine non-existent
Content-Type
* Wrap long words and links in default theme
* Save user configuration propertly if note and links are empty

### Changed

* Resize profile to always be square

## v1.0.0 Initial Release - 2019-09-14

No changes were made. It was the first release, after all!
21 changes: 17 additions & 4 deletions includes/api.include.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ function ml_api_method () {
* @return string
*/
function ml_api_content_type () {
$content_type = $_SERVER['CONTENT_TYPE'];
if (empty($content_type)) $content_type = $_SERVER['HTTP_CONTENT_TYPE'];
$content_type = '';

if (isset($_SERVER['CONTENT_TYPE'])) {
$content_type = $_SERVER['CONTENT_TYPE'];
}

if (empty($content_type) && isset($_SERVER['HTTP_CONTENT_TYPE'])) {
$content_type = $_SERVER['HTTP_CONTENT_TYPE'];
}

// Default to form data if no value was provided.
if (empty($content_type)) $content_type = HTTPContentType::FORM_DATA;

return $content_type;
}
Expand All @@ -43,7 +53,7 @@ function ml_api_content_type () {
function ml_api_post_decode () {
global $post;

if (ml_api_content_type() === 'application/json') {
if (ml_api_content_type() === HTTPContentType::JSON) {
$post = json_decode(file_get_contents('php://input'), true);
} else {
$post = $_POST;
Expand Down Expand Up @@ -81,6 +91,7 @@ function ml_api_post_json ($post, $key, $is_single = false) {
if (!is_array($post)) return null;
if (!isset($post[$key])) return null;
if (empty($post[$key])) return null;
if (!is_array($post[$key])) return $post[$key];

// A lot of microformats2 items are intentionally single element arrays.
// I'm not sure why, but if we know it's supposed to, parse it here.
Expand Down Expand Up @@ -110,10 +121,12 @@ function ml_api_get ($key) {
* @return null|string
*/
function ml_api_access_token () {
global $post;

// Don't allow user in without a valid bearer token
$bearer = ml_http_bearer();

if ($bearer === false) {
if ($bearer === false && $post !== null) {
$bearer = ml_api_post('access_token');
}

Expand Down
8 changes: 6 additions & 2 deletions includes/functions.include.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function ml_get_title () {
$str = '';

if ($showing === Show::POST || $showing === Show::PAGE) {
$str .= $posts['name'] !== ''
$str .= $posts['name'] !== '' && $posts['name'] !== null
? $posts['name']
: $posts['summary'];
$str .= Config::TITLE_SEPARATOR;
Expand Down Expand Up @@ -395,6 +395,9 @@ function ml_page_headers () {
$description = User::NOTE;
$image = ml_icon_url();
}

$description = htmlspecialchars($description, ENT_QUOTES);
$title = htmlspecialchars(ml_get_title(), ENT_QUOTES);
?>
<meta name='description' content='<?php echo $description; ?>' />
<meta name='generator' content='Microlight <?php echo MICROLIGHT; ?>' />
Expand All @@ -404,7 +407,7 @@ function ml_page_headers () {
<?php if (Config::OPEN_GRAPH === true): ?>
<meta name='twitter:card' content='summary' />
<meta property='og:url' content='<?php echo ml_canonical_permalink(); ?>' />
<meta property='og:title' content='<?php echo ml_get_title(); ?>' />
<meta property='og:title' content='<?php echo $title; ?>' />
<meta property='og:description' content='<?php echo $description; ?>' />
<meta property='og:image' content='<?php echo $image; ?>' />
<?php endif; ?>
Expand All @@ -415,6 +418,7 @@ function ml_page_headers () {

<title><?php echo ml_get_title(); ?></title>
<link rel='micropub' href='<?php echo ml_base_url() . 'micropub/index.php'; ?>' />
<link rel="micropub_media" href='<?php echo ml_base_url() . 'media/index.php'; ?>' />
<link rel='authorization_endpoint' href='<?php echo Config::INDIEAUTH_PROVIDER; ?>' />
<link rel='token_endpoint' href='<?php echo Config::INDIEAUTH_TOKEN_ENDPOINT; ?>' />
<link rel='icon' href='<?php echo $image; ?>' />
Expand Down
44 changes: 41 additions & 3 deletions includes/lib/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ abstract class ImageType extends BasicEnum {
const GIF = 'image/gif'; // jif
}

abstract class ImageResizeMethod extends BasicEnum {
const KEEP_ASPECT_RATIO = 0;
const SQUARE = 1;
}

class ImageResizer {
private $image;
private $type;
Expand All @@ -72,6 +77,7 @@ class ImageResizer {
private $width_src;
private $height_src;
private $filename;
private $resize_method;

private $filename_override;
private $mimetype_override;
Expand All @@ -81,9 +87,16 @@ class ImageResizer {
* @param array $file
* @param string $filename_override If set, the image will be forcibly saved here
* @param string $mimetype_override If set, the image will be forcibly saved with this type
* @param ImageResizeMethod $resize_method If set, the image will be resized differently
* @return ImageResizer
* @throws Exception
*/
function __construct ($file, $filename_override = null, $mimetype_override = null) {
function __construct (
$file,
$filename_override = null,
$mimetype_override = null,
$resize_method = ImageResizeMethod::KEEP_ASPECT_RATIO
) {
if ($file['error'] !== UPLOAD_ERR_OK) throw new UploadException($file);

if (empty($file['tmp_name'])) {
Expand All @@ -99,6 +112,13 @@ function __construct ($file, $filename_override = null, $mimetype_override = nul
throw new Exception('Image was not provided');
}

// Make sure resize method is an acceptable value
if (!ImageResizeMethod::isValidValue($resize_method)) {
throw new Exception('Invalid resize method');
}

$this->resize_method = $resize_method;

// Calculate new image size
if (!$this->dimensions($file)) {
throw new Exception('Image dimensions could not be determined');
Expand Down Expand Up @@ -224,11 +244,29 @@ private function load ($file) {
}

private function resize () {
// Determine resize coordinates
$scale = $this->width_src / $this->width;

$source_x = 0;
$source_y = 0;

if ($this->resize_method === ImageResizeMethod::SQUARE) {
if ($this->width_src > $this->height_src) {
$source_x = ceil(($this->width_src - $this->height_src) / 2.0);
$this->width_src = $this->height_src;
$this->width = $this->height;
} else if ($this->width_src < $this->height_src) {
$source_y = ceil(($this->height_src - $this->width_src) / 2.0);
$this->height_src = $this->width_src;
$this->height = $this->width;
}
}

$destination = imagecreatetruecolor($this->width, $this->height);
$success = imagecopyresampled(
$destination, // New image
$destination, // New image
$this->image, // Old image
0, 0, 0, 0, // Image origin coords
0, 0, $source_x, $source_y, // Image origin coords
$this->width, $this->height, // New image size
$this->width_src, $this->height_src // Old image size
);
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// This definition will prevent any files to be loaded outside of this file.
define('MICROLIGHT', 'v1.0.0');
define('MICROLIGHT', 'v1.0.1');

try {
// Load user details
Expand Down
20 changes: 12 additions & 8 deletions install.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// This definition will prevent any files to be loaded outside of this file.
define('MICROLIGHT', 'v1.0.0');
define('MICROLIGHT', 'v1.0.1');

session_start();
require_once('includes/config.php');
Expand Down Expand Up @@ -73,12 +73,10 @@ class User {
const EMAIL = \'' . $email .'\';
';

// Add note, if provided
if (!empty($note)) {
$note = quote($note);
$contents .= ' const NOTE = \'' . $note . '\';
// Always add note, even if it's empty.
$note = quote($note);
$contents .= ' const NOTE = \'' . $note . '\';
';
}

// Open identities section, even if there are no identities provided
$contents .= ' const IDENTITIES = [
Expand All @@ -96,7 +94,8 @@ class User {
';
}
} else {
$contents .= ' // [ \'name\' => \'\', \'url\' => \'\' ],';
$contents .= ' // [ \'name\' => \'\', \'url\' => \'\' ],
';
}

// Close identities section
Expand Down Expand Up @@ -148,7 +147,12 @@ class User {

// Attempt to upload/resize profile picture
if (isset($_FILES['photo'])) {
$image = new ImageResizer($_FILES['photo'], 'me', 'image/jpg');
$image = new ImageResizer(
$_FILES['photo'],
'me',
ImageType::JPG,
ImageResizeMethod::SQUARE
);
}

if (count($errors) === 0) {
Expand Down
2 changes: 1 addition & 1 deletion media/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('MICROLIGHT', 'v1.0.0');
define('MICROLIGHT', 'v1.0.1');

chdir('..');
require_once('includes/config.php');
Expand Down
9 changes: 8 additions & 1 deletion micropub/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('MICROLIGHT', 'v1.0.0');
define('MICROLIGHT', 'v1.0.1');

chdir('..');
require_once('includes/config.php');
Expand Down Expand Up @@ -41,6 +41,13 @@
case 'source':
ml_http_response(HTTPStatus::OK, query_source());
return;

default:
ml_http_error(
HTTPStatus::INVALID_REQUEST,
'Invalid q parameter. Pick one of "config", "syndicate-to", or "source"'
);
return;
}

case 'POST':
Expand Down
4 changes: 2 additions & 2 deletions micropub/post/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @return string|false Return the date in ISO8601 if valid, otherwise false
*/
function validate_date ($date) {
if ($date === null) {
if ($date === null || $date === '') {
// Use the current timestamp, if not provided.
return gmdate("c");
} else {
Expand Down Expand Up @@ -87,7 +87,7 @@ function generate_slug ($name, $summary) {
/**
* Determines the post type depending on whether other optional fields to POST
* were provided.
*
*
* @param PostEntry $entry
* @return array|false If a valid post type was detected, an array containing
* "type" and "url" keys, otherwise false.
Expand Down
Loading

0 comments on commit d59da0a

Please sign in to comment.