-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 28adcf6
Showing
8 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
js/src export-ignore | ||
.git* export-ignore | ||
|
||
js/dist/*.js -diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Clark Winkelmann | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Default Image Alt Text | ||
|
||
[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/clarkwinkelmann/flarum-ext-default-image-alt/blob/master/LICENSE.md) [![Latest Stable Version](https://img.shields.io/packagist/v/clarkwinkelmann/flarum-ext-default-image-alt.svg)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-default-image-alt) [![Total Downloads](https://img.shields.io/packagist/dt/clarkwinkelmann/flarum-ext-default-image-alt.svg)](https://packagist.org/packages/clarkwinkelmann/flarum-ext-default-image-alt) [![Donate](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/clarkwinkelmann) | ||
|
||
This extension sets a default alt text to images that were inserted in a post without any alt text. | ||
|
||
It affects all TextFormatter syntaxes that use the internal `IMG` tag, so `![](https://example.com/image.jpg)`, `[img]https://example.com/image.jpg[/img]` and AutoImage. | ||
|
||
The main use case of this extension is improving accessibility but help texts are also very useful to see whether the post contains broken images. | ||
|
||
The default alt text will not be visible in previews, only in the final output. | ||
|
||
The default text is not stored in the post XML, so all existing posts are immediately updated, including when the translation or language is modified. | ||
|
||
The alt text is different for posts with a known author. | ||
A second alt text is used for posts with deleted author and other contexts where the Flarum formatter is used. | ||
|
||
The Linguist extension can be used to change the text. | ||
|
||
## Installation | ||
|
||
composer require clarkwinkelmann/flarum-ext-default-image-alt | ||
|
||
## Support | ||
|
||
This extension is under **minimal maintenance**. | ||
|
||
It was developed for a client and released as open-source for the benefit of the community. | ||
I might publish simple bugfixes or compatibility updates for free. | ||
|
||
You can [contact me](https://clarkwinkelmann.com/flarum) to sponsor additional features or updates. | ||
|
||
Support is offered on a "best effort" basis through the Flarum community thread. | ||
|
||
## Links | ||
|
||
- [GitHub](https://github.com/clarkwinkelmann/flarum-ext-default-image-alt) | ||
- [Packagist](https://packagist.org/packages/clarkwinkelmann/flarum-ext-default-image-alt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "clarkwinkelmann/flarum-ext-default-image-alt", | ||
"description": "Sets an alt text to post images when missing", | ||
"keywords": [ | ||
"flarum", | ||
"image", | ||
"alt" | ||
], | ||
"type": "flarum-extension", | ||
"license": "MIT", | ||
"require": { | ||
"flarum/core": "^1.0" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Clark Winkelmann", | ||
"homepage": "https://clarkwinkelmann.com/", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"source": "https://github.com/clarkwinkelmann/flarum-ext-default-image-alt" | ||
}, | ||
"extra": { | ||
"flarum-extension": { | ||
"title": "Default Image Alt Text", | ||
"category": "feature", | ||
"icon": { | ||
"name": "fas fa-info", | ||
"backgroundColor": "#684ba6", | ||
"color": "#fff" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace ClarkWinkelmann\NoEmailNotifications; | ||
|
||
use Flarum\Extend; | ||
use Flarum\Locale\Translator; | ||
use Flarum\Post\Post; | ||
use Illuminate\Support\Arr; | ||
use s9e\TextFormatter\Utils; | ||
|
||
return [ | ||
new Extend\Locales(__DIR__ . '/locale'), | ||
|
||
(new Extend\Formatter()) | ||
->render(function ($renderer, $context, $xml) { | ||
return Utils::replaceAttributes($xml, 'IMG', function (array $attributes) use ($context): array { | ||
// If there's already an alt text, skip our code | ||
if (Arr::get($attributes, 'alt')) { | ||
return $attributes; | ||
} | ||
|
||
/** | ||
* @var $translator Translator | ||
*/ | ||
$translator = resolve(Translator::class); | ||
|
||
$key = 'clarkwinkelmann-default-image-alt.api.alt-text-generic'; | ||
$params = []; | ||
|
||
if ($context instanceof Post && $context->user) { | ||
$key = 'clarkwinkelmann-default-image-alt.api.alt-text-author'; | ||
$params['username'] = $context->user->display_name; | ||
} | ||
|
||
$attributes['alt'] = $translator->trans($key, $params); | ||
|
||
return $attributes; | ||
}); | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
clarkwinkelmann-default-image-alt: | ||
api: | ||
alt-text-generic: Image in user-generated content | ||
alt-text-author: Image uploaded by {username} |