Skip to content

Commit

Permalink
Merge branch 'SimpleMachines:release-3.0' into crowdinUpate
Browse files Browse the repository at this point in the history
  • Loading branch information
jdarwood007 authored Feb 6, 2024
2 parents 6ed2643 + bcea434 commit 40dc2ff
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 33 deletions.
114 changes: 114 additions & 0 deletions .github/phpcs/SMFClosingTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* This file is modified from original CS fixer source code.
*
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2024 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0
*/
declare(strict_types=1);

namespace SMF\Fixer\Whitespace;

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
use PhpCsFixer\Fixer\Whitespace;
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Tokens;
use PhpCsFixer\Tokenizer\Token;

/**
* Ensure line endings match SMF standards.
*
* @author Jeremy Darwood <[email protected]>
*/
final class closing_tag_fixer extends AbstractFixer implements WhitespacesAwareFixerInterface
{
public function getName(): string
{
return 'SMF/closing_tag_fixer';
}

public function getDefinition(): FixerDefinitionInterface
{
return new FixerDefinition(
'A PHP file must end with a closing tag.',
[
new CodeSample("<?php\n\$a = 1;"),
new CodeSample("<?php\n\$a = 1;\n?>"),
new CodeSample("<?php\n\if (true){}"),
new CodeSample("<?php\n\if (true){}\n\n?>"),
]
);
}

public function getPriority(): int
{
return -110;
}

public function isCandidate(Tokens $tokens): bool
{
$count = $tokens->count();

// No tokens, not a canidate.
if ($count == 0) {
return false;
}

// Last character is a white space, needs fixed.
if ($tokens[$count - 1]->isGivenKind(T_WHITESPACE)) {
return true;
}

// We have closing bracket then closing barcket, single white space and then closing tag.
if ($tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->isGivenKind(T_WHITESPACE) && $tokens[$count - 3]->getContent() !== ';') {
return true;
}

// We have a closing bracket, and then closing tag, no white space.
if ($tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->getContent() === '}') {
return true;
}

return false;
}

protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$count = $tokens->count();

// Last character is a white space. Adds a closing tag.
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_WHITESPACE)) {
$tokens[$count - 1] = new Token([
T_WHITESPACE,
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding() . '?' . '>'
]);
}

// We have closing bracket then closing barcket, single white space and then closing tag. Add one more return.
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->isGivenKind(T_WHITESPACE) && $tokens[$count - 3]->getContent() !== ';') {
$tokens[$count - 2] = new Token([
T_WHITESPACE,
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding()
]);
}

// We have a closing bracket, and then closing tag, no white space, add returns.
// There is no ID/Name for closing curely bracket or semi-colon.
if ($count > 0 && $tokens[$count - 1]->isGivenKind(T_CLOSE_TAG) && $tokens[$count - 2]->getContent() === '}') {

$tokens[$count - 1] = new Token([
T_WHITESPACE,
$this->whitespacesConfig->getLineEnding() . $this->whitespacesConfig->getLineEnding() . '?' . '>'
]);
}
}
}
31 changes: 31 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
push:
branches:
- release-2.1
pull_request:

name: PHP Check
jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42

- name: Get extra arguments for PHP-CS-Fixer
id: phpcs-intersection
run: |
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
echo "$EXTRA_ARGS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
5 changes: 1 addition & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ jobs:

- run: php -v

- run: composer lint

- name: Checking for sign off (GPG also accepted)
run: php ./vendor/simplemachines/build-tools/check-signed-off.php

- name: Checking file integrity
run: |
php ./vendor/simplemachines/build-tools/check-eof.php
php ./vendor/simplemachines/build-tools/check-smf-license.php
php ./vendor/simplemachines/build-tools/check-smf-languages.php
php ./vendor/simplemachines/build-tools/check-smf-index.php
Expand All @@ -44,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ 8.0, 8.1 ]
php: [ 8.0, 8.1, 8.2, 8.3 ]

name: PHP ${{ matrix.php }} Syntax Check
steps:
Expand Down
9 changes: 8 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*
* @version 3.0 Alpha 1
*/

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
// Don't touch libraries.
Expand All @@ -29,10 +28,18 @@
// Skip anything being ignored in .gitignore.
->ignoreVCSIgnored(true);

require_once('.github/phpcs/SMFClosingTag.php');

return (new PhpCsFixer\Config())
->registerCustomFixers([
new \SMF\Fixer\Whitespace\closing_tag_fixer(),
])
->setRules([
'@PSR12' => true,

// A custom fixer for us to apply our line endings.
'SMF/closing_tag_fixer' => true,

// PSR12 overrides.
'no_closing_tag' => false,
'no_break_comment' => false, // A bit buggy with comments.
Expand Down
20 changes: 10 additions & 10 deletions Sources/Actions/Admin/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,19 +1176,19 @@ public function modifyUser(): void
Utils::$context['sub'] = [
'id' => 0,
'start' => [
'year' => (int) Time::strftime('%Y', $row['start_time']),
'month' => (int) Time::strftime('%m', $row['start_time']),
'day' => (int) Time::strftime('%d', $row['start_time']),
'hour' => (int) Time::strftime('%H', $row['start_time']),
'min' => (int) Time::strftime('%M', $row['start_time']) < 10 ? '0' . (int) Time::strftime('%M', $row['start_time']) : (int) Time::strftime('%M', $row['start_time']),
'year' => (int) Time::strftime('%Y', (int) $row['start_time']),
'month' => (int) Time::strftime('%m', (int) $row['start_time']),
'day' => (int) Time::strftime('%d', (int) $row['start_time']),
'hour' => (int) Time::strftime('%H', (int) $row['start_time']),
'min' => (int) Time::strftime('%M', (int) $row['start_time']),
'last_day' => 0,
],
'end' => [
'year' => (int) Time::strftime('%Y', $row['end_time']),
'month' => (int) Time::strftime('%m', $row['end_time']),
'day' => (int) Time::strftime('%d', $row['end_time']),
'hour' => (int) Time::strftime('%H', $row['end_time']),
'min' => (int) Time::strftime('%M', $row['end_time']) < 10 ? '0' . (int) Time::strftime('%M', $row['end_time']) : (int) Time::strftime('%M', $row['end_time']),
'year' => (int) Time::strftime('%Y', (int) $row['end_time']),
'month' => (int) Time::strftime('%m', (int) $row['end_time']),
'day' => (int) Time::strftime('%d', (int) $row['end_time']),
'hour' => (int) Time::strftime('%H', (int) $row['end_time']),
'min' => (int) Time::strftime('%M', (int) $row['end_time']),
'last_day' => 0,
],
'status' => $row['status'],
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function edit(): void
'disabled' => $row['disabled'],
'offset' => $row['time_offset'],
'regularity' => $row['time_regularity'],
'offset_formatted' => date('H:i', $row['time_offset']),
'offset_formatted' => date('H:i', (int) $row['time_offset']),
'unit' => $row['time_unit'],
];
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Actions/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,22 +322,22 @@ public function execute(): void
// Give credit to any graphic library's, software library's, plugins etc
Utils::$context['credits_software_graphics'] = [
'graphics' => [
'<a href="http://p.yusukekamiyamane.com/">Fugue Icons</a> | © 2012 Yusuke Kamiyamane | These icons are licensed under a Creative Commons Attribution 3.0 License',
'<a href="https://techbase.kde.org/Projects/Oxygen/Licensing#Use_on_Websites">Oxygen Icons</a> | These icons are licensed under <a href="http://www.gnu.org/copyleft/lesser.html">GNU LGPLv3</a>',
'<a href="https://p.yusukekamiyamane.com/">Fugue Icons</a> | © 2012 Yusuke Kamiyamane | These icons are licensed under a Creative Commons Attribution 3.0 License',
'<a href="https://techbase.kde.org/Projects/Oxygen/Licensing#Use_on_Websites">Oxygen Icons</a> | These icons are licensed under <a href="https://www.gnu.org/licenses/lgpl-3.0.html">GNU LGPLv3</a>',
],
'software' => [
'<a href="https://jquery.org/">JQuery</a> | © John Resig | Licensed under <a href="https://github.com/jquery/jquery/blob/master/LICENSE.txt">The MIT License (MIT)</a>',
'<a href="https://briancherne.github.io/jquery-hoverIntent/">hoverIntent</a> | © Brian Cherne | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://www.sceditor.com/">SCEditor</a> | © Sam Clarke | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="http://wayfarerweb.com/jquery/plugins/animadrag/">animaDrag</a> | © Abel Mohler | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/mzubala/jquery-custom-scrollbar">jQuery Custom Scrollbar</a> | © Maciej Zubala | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="http://slippry.com/">jQuery Responsive Slider</a> | © booncon ROCKETS | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/code-of-kpp/jquery-animadrag/blob/master/animadrag.js">animaDrag</a> | © Abel Mohler | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/mzubala/jquery-custom-scrollbar">jQuery Custom Scrollbar</a> | © Maciej Zubala | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://slippry.com/">jQuery Responsive Slider</a> | © booncon ROCKETS | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/ichord/At.js">At.js</a> | © [email protected] | Licensed under <a href="https://github.com/ichord/At.js/blob/master/LICENSE-MIT">The MIT License (MIT)</a>',
'<a href="https://github.com/ttsvetko/HTML5-Desktop-Notifications">HTML5 Desktop Notifications</a> | © Tsvetan Tsvetkov | Licensed under <a href="https://github.com/ttsvetko/HTML5-Desktop-Notifications/blob/master/License.txt">The Apache License Version 2.0</a>',
'<a href="https://github.com/enygma/gauth">GAuth Code Generator/Validator</a> | © Chris Cornutt | Licensed under <a href="https://github.com/enygma/gauth/blob/master/LICENSE">The MIT License (MIT)</a>',
'<a href="https://github.com/enyo/dropzone">Dropzone.js</a> | © Matias Meno | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/matthiasmullie/minify">Minify</a> | © Matthias Mullie | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/true/php-punycode">PHP-Punycode</a> | © True B.V. | Licensed under <a href="http://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/enyo/dropzone">Dropzone.js</a> | © Matias Meno | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/matthiasmullie/minify">Minify</a> | © Matthias Mullie | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
'<a href="https://github.com/true/php-punycode">PHP-Punycode</a> | © True B.V. | Licensed under <a href="https://en.wikipedia.org/wiki/MIT_License">The MIT License (MIT)</a>',
],
'fonts' => [
'<a href="https://fontlibrary.org/en/font/anonymous-pro"> Anonymous Pro</a> | © 2009 | This font is licensed under the SIL Open Font License, Version 1.1',
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/TopicRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function execute(): void
}

// Can we be in here?
User::$me->isAllowedTo('move_any', Config::$modSettings['recycle_board']);
User::$me->isAllowedTo('move_any', [Config::$modSettings['recycle_board']]);

$unfound_messages = [];
$topics_to_restore = [];
Expand Down Expand Up @@ -215,7 +215,7 @@ public function execute(): void
}

// Ok we got here so me move them from here to there.
Topic::move($row['id_topic'], $row['id_previous_board']);
Topic::move([$row['id_topic']], (int) $row['id_previous_board']);

// Lets see if the board that we are returning to has post count enabled.
$request2 = Db::$db->query(
Expand Down
10 changes: 5 additions & 5 deletions Sources/Actions/TopicSplit.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,11 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st
while ($row = Db::$db->fetch_assoc($request)) {
// Get the right first and last message dependent on approved state...
if (empty($split1_first_msg) || $row['myid_first_msg'] < $split1_first_msg) {
$split1_first_msg = $row['myid_first_msg'];
$split1_first_msg = (int) $row['myid_first_msg'];
}

if (empty($split1_last_msg) || $row['approved']) {
$split1_last_msg = $row['myid_last_msg'];
$split1_last_msg = (int) $row['myid_last_msg'];
}

// Get the counts correct...
Expand Down Expand Up @@ -715,11 +715,11 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st
while ($row = Db::$db->fetch_assoc($request)) {
// As before get the right first and last message dependent on approved state...
if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) {
$split2_first_msg = $row['myid_first_msg'];
$split2_first_msg = (int) $row['myid_first_msg'];
}

if (empty($split2_last_msg) || $row['approved']) {
$split2_last_msg = $row['myid_last_msg'];
$split2_last_msg = (int) $row['myid_last_msg'];
}

// Then do the counts again...
Expand Down Expand Up @@ -935,7 +935,7 @@ public static function splitTopic(int $split1_ID_TOPIC, array $splitMessages, st

// Housekeeping.
Logging::updateStats('topic');
Msg::updateLastMessages($id_board);
Msg::updateLastMessages([$id_board]);

Logging::logAction('split', ['topic' => $split1_ID_TOPIC, 'new_topic' => $split2_ID_TOPIC, 'board' => $id_board]);

Expand Down
4 changes: 2 additions & 2 deletions Sources/Msg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,9 @@ public static function remove(int $message, bool $decreasePostCount = true): boo

// And now to update the last message of each board we messed with.
if ($recycle) {
Msg::updateLastMessages([$row['id_board'], Config::$modSettings['recycle_board']]);
self::updateLastMessages([$row['id_board'], Config::$modSettings['recycle_board']]);
} else {
Msg::updateLastMessages($row['id_board']);
self::updateLastMessages([$row['id_board']]);
}

// Close any moderation reports for this message.
Expand Down

0 comments on commit 40dc2ff

Please sign in to comment.