Skip to content

Commit

Permalink
Finish 5.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Aug 7, 2020
2 parents 9f8a041 + a6a41fe commit cca8793
Show file tree
Hide file tree
Showing 17 changed files with 248 additions and 39 deletions.
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@
- Δ Changed
- − Removed

## [next] -

- [Full commit-log](https://github.com/Schlaefer/Saito/compare/5.7.1...<next>)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/<next>/saito-release-master-<next>.zip)

## [5.7.1] -

- [Full commit-log](https://github.com/Schlaefer/Saito/compare/5.7.0...5.7.1)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/5.7.1/saito-release-master-5.7.1.zip)

### Changes

- + Adds .webp images to allowed upload mime-types #372
- + Adds required PHP extensions to readme.md
- ✓ Fixes Thread Collpase user setting not working in 5.x #371
- ✓ Fixes URL with paranthesis pair omits closing on autolink #373
- ✓ Fixes delete category and move existing posts
- ✓ Fixes missing l10n de merge thread
- ✓ Fixes text-field to submit-button alignment on simple search
- ✓ Fixes spoiler tags are not revealed reliably
- ✓ Fixes image compression is to aggressive #374

## [5.7.0] - 2020-03-25

- [Full commit-log](https://github.com/Schlaefer/Saito/compare/5.6.0...5.7.0)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/saito-release-master-5.7.0.zip)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/5.7.0/saito-release-master-5.7.0.zip)

### Changes

Expand Down Expand Up @@ -49,7 +71,7 @@ The plugin Local in "plugins/local" allows extending the forum in a CakePHP fash
## [5.6.0] - 2020-01-03

- [Full commit-log](https://github.com/Schlaefer/Saito/compare/5.5.0...5.6.0)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/saito-release-master-5.6.0.zip)
- [Download release-zip](https://github.com/Schlaefer/Saito/releases/download/5.6.0/saito-release-master-5.6.0.zip)

### Changes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A lot of optimization went into serving long existing, small- to mid-sized commu

## Requirements

- PHP 7.2+
- PHP 7.2+ (extensions: gd, exif, intl, mbstring, pdo, simplexml)
- Database (MySQL/MariaDB tested, [others untested](https://book.cakephp.org/3.0/en/orm/database-basics.html#supported-databases)).

## Get Started
Expand Down
9 changes: 9 additions & 0 deletions config/saito_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@
* Max file size
*/
->setDefaultMaxFileSize('8MB')
/**
* Threshold file size (and rough target) for resizing images (jpeg/png)
*/
->setDefaultMaxResize('650kB')
/**
* Image quality factor when resizing images (integer between 0 and 100)
*/
->setImageCompressionQuality(92)
/**
* Allowed mime/types
*/
Expand All @@ -123,6 +131,7 @@
->addType('image/jpeg', '19MB')
->addType('image/png', '19MB')
->addType('image/svg+xml')
->addType('image/webp')
->addType('text/plain')
->addType('video/mp4')
->addType('video/webm');
Expand Down
2 changes: 1 addition & 1 deletion plugins/Admin/src/Controller/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function delete($id)
/* get categories for target <select> */
$targetCategories = $this->CurrentUser->getCategories()->getAll(
'read',
'list'
'select'
);
unset($targetCategories[$id]);

Expand Down
1 change: 1 addition & 0 deletions plugins/Admin/src/Template/Categories/delete.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'targetCategory',
[
'label' => __d('admin', 'cat.del.mbd.l'),
'options' => $targetCategories,
'type' => 'select',
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ public function testDeleteDelete()
$this->assertEquals($expected, $after['all']);
}

/**
* Test showing of delete form
*
* @return void
*/
public function testDeleteGetForm(): void
{
$this->_loginUser(1);
$source = 2;
$target = 4;

$this->get('/admin/categories/delete/2');

$targetCategories = $this->viewVariable('targetCategories');
$this->assertCount(4, $targetCategories);
$this->assertArraySubset([4 => 'Offtopic', 5 => 'Trash'], $targetCategories);
}

/**
* delete category and merge postings into other category
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,15 @@ protected function _parse($content, $attributes, \JBBCode\ElementNode $node)
STR_PAD_BOTH
);

$json = json_encode(['string' => $content]);
$id = 'spoiler_' . rand(0, 9999999999999);
// Escape HTML-special chars to prevent injection
$spoilerContent = htmlentities($content);
// Encode content for JS usage
$spoilerContent = json_encode($spoilerContent);

$out = <<<EOF
<div class="richtext-spoiler" style="display: inline;">
<script>
window.$id = $json;
</script>
<a href="#" class="richtext-spoiler-link"
onclick='this.parentNode.innerHTML = window.$id.string; delete window.$id; return false;'
onclick='this.parentNode.innerHTML = $spoilerContent; return false;'
>
$title
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,34 @@ protected function atUserLink(string $string): string
protected function autolink(string $string): string
{
$replace = function (array $matches): string {
// don't link locally
/// don't link locally
if (strpos($matches['element'], 'file://') !== false) {
return $matches['element'];
}

// exclude punctuation at end of sentence from URLs
/// exclude punctuation at end of sentence from URLs
$ignoredEndChars = implode('|', [',', '\?', ',', '\.', '\)', '!']);
preg_match(
'/(?P<element>.*?)(?P<suffix>' . $ignoredEndChars . ')?$/',
$matches['element'],
$m
);
// keep ['element'] and ['suffix'] and include ['prefix']; (array) for phpstan

/// exclude ignored end chars if paired in URL foo.com/bar_(baz)
if (!empty($m['suffix'])) {
$ignoredIfNotPaired = [
['open' => '(', 'close' => ')'],
];
foreach ($ignoredIfNotPaired as $pair) {
$isUnpaired = substr_count($m['element'], $pair['open']) > substr_count($m['element'], $pair['close']);
if ($isUnpaired) {
$m['element'] .= $m['suffix'];
unset($m['suffix']);
}
}
}

/// keep ['element'] and ['suffix'] and include ['prefix']; (array) for phpstan
$matches = (array)($m + $matches);

if (strpos($matches['element'], '://') === false) {
Expand Down
37 changes: 33 additions & 4 deletions plugins/BbcodeParser/tests/TestCase/Lib/BbcodeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ public function testSpoiler()
'style' => 'display: inline;',
],
],
['script' => true],
'preg:/(.*?)"string":" te &quot;&#039; xt"(.*?)(?=<)/',
'/script',
[
'a' => [
'href' => '#',
'class' => 'richtext-spoiler-link',
'onclick',
'onclick' => 'preg:/.*" te &amp;quot;&amp;#039; xt".*/',
],
],
'preg:/.*▇ Spoiler ▇.*?(?=<)/',
Expand Down Expand Up @@ -650,6 +647,38 @@ public function testLinkAutoUrlWithinParentheses()
];
$result = $this->_Parser->parse($input);
$this->assertHtml($expected, $result);

$input = 'some (www.example.com/foo_(bar)) text';
$expected = [
'some (',
'a' => [
'class' => 'richtext-link truncate',
'href' => 'http://www.example.com/foo_(bar)',
'rel' => 'external',
'target' => '_blank',
],
'http://www.example.com/foo_(bar)',
'/a',
') text',
];
$result = $this->_Parser->parse($input);
$this->assertHtml($expected, $result);

$input = 'some www.example.com/foo_(bar) text';
$expected = [
'some ',
'a' => [
'class' => 'richtext-link truncate',
'href' => 'http://www.example.com/foo_(bar)',
'rel' => 'external',
'target' => '_blank',
],
'http://www.example.com/foo_(bar)',
'/a',
' text',
];
$result = $this->_Parser->parse($input);
$this->assertHtml($expected, $result);
}

public function testLinkAutoSurroundingChars()
Expand Down
71 changes: 67 additions & 4 deletions plugins/ImageUploader/src/Lib/UploaderConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,80 @@ class UploaderConfig
/** @var array allowed mime types */
private $types = [];

/** @var int Default target size for resizing a type in bytes */
private $defaultResize = 450000;
/** @var int Threshold (and rough target) for resizing images in bytes */
private $defaultResize = 650000;

/** @var int Jpeg compression factor between 0 and 100 */
private $jpegCompression = 92;

/**
* Set image compression quality
*
* @param int $quality Integer between 0 and 100
* @throws \InvalidArgumentException if quality isn't valid.
* @return self
*/
public function setImageCompressionQuality(int $quality): self
{
if ($quality < 0 || $quality > 100) {
throw new \InvalidArgumentException(
"Image compression quality must be between 0 and 100.",
1596204082
);
}
$this->setJpegCompressionFactor($quality);

return $this;
}

/**
* Set JPEG compression quality
*
* @param int $compression Number between 0 and 100
* @return self
* @throws \InvalidArgumentException if compression factor isn't valid.
*/
protected function setJpegCompressionFactor(int $compression): self
{
if ($compression < 0 || $compression > 100) {
throw new \InvalidArgumentException(
"Jpeg compression factor must be between 0 and 100.",
1596187723
);
}
$this->jpegCompression = $compression;

return $this;
}

/**
* Get Jpeg compression factor
*
* @return int
*/
public function getJpegCompressionFactor(): int
{
return $this->jpegCompression;
}

/**
* Set default max file size when resizing a type
*
* @param int $size Size in bytes
* @param string|int $size Size in bytes as int or string e.g. "3MB"
* @return self
* @throws \InvalidArgumentException if size isn't valid.
*/
public function setDefaultMaxResize(int $size): self
public function setDefaultMaxResize($size): self
{
if (is_string($size)) {
$size = (int)Text::parseFileSize($size, $this->defaultResize);
}
if (!is_int($size)) {
throw new \InvalidArgumentException(
'Default max resize isn\'t a number.',
1596199482
);
}
$this->defaultResize = $size;

return $this;
Expand Down
Loading

0 comments on commit cca8793

Please sign in to comment.