From aeef4960a1191d62c4cbdd6cc0e67d1c19ae9b84 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 11 May 2021 08:10:25 -0400 Subject: [PATCH 1/4] Make birthday time comparison 32-bit safe in Protocol\DFRN - Address https://github.com/friendica/friendica/issues/10168#issuecomment-838221234 --- src/Protocol/DFRN.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index df974729b..d20b8949b 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1441,19 +1441,19 @@ class DFRN /** * Fetch the author data from head or entry items * - * @param object $xpath XPath object - * @param object $context In which context should the data be searched - * @param array $importer Record of the importer user mixed with contact of the content - * @param string $element Element name from which the data is fetched - * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well - * @param string $xml optional, default empty + * @param \DOMXPath $xpath XPath object + * @param \DOMNode $context In which context should the data be searched + * @param array $importer Record of the importer user mixed with contact of the content + * @param string $element Element name from which the data is fetched + * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well + * @param string $xml optional, default empty * * @return array Relevant data of the author * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException * @todo Find good type-hints for all parameter */ - private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") + private static function fetchauthor(\DOMXPath $xpath, \DOMNode $context, $importer, $element, $onlyfetch, $xml = "") { $author = []; $author["name"] = XML::getFirstNodeValue($xpath, $element."/atom:name/text()", $context); @@ -1609,12 +1609,14 @@ class DFRN } // "dfrn:birthday" contains the birthday converted to UTC - $birthday = XML::getFirstNodeValue($xpath, $element . "/poco:birthday/text()", $context); - - if (strtotime($birthday) > time()) { - $bd_timestamp = strtotime($birthday); - - $poco["bdyear"] = date("Y", $bd_timestamp); + $birthday = XML::getFirstNodeValue($xpath, $element . "/dfrn:birthday/text()", $context); + try { + $birthday_date = new \DateTime($birthday); + if ($birthday_date > new \DateTime()) { + $poco["bdyear"] = $birthday_date->format("Y"); + } + } catch (\Exception $e) { + // Invalid birthday } // "poco:birthday" is the birthday in the format "yyyy-mm-dd" From c642062aa02338182446e94267c429fa4a5eccf1 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 13 May 2021 18:47:12 +0200 Subject: [PATCH 2/4] Enable PHP linting per Drone --- .drone.yml | 32 +++++++++++++++++++++++++++++++- .github/workflows/lint.yml | 17 ----------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.drone.yml b/.drone.yml index 53be71e31..74dacfca4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,4 +11,34 @@ steps: - name: Check default image: friendicaci/transifex commands: - - /check-messages.sh \ No newline at end of file + - /check-messages.sh +--- +kind: pipeline +type: docker +name: php7.3-lint + +steps: + - name: Test + image: php:7.3 + commands: + - ./bin/composer.phar run lint +--- +kind: pipeline +type: docker +name: php7.4-lint + +steps: + - name: Test + image: php:7.4 + commands: + - ./bin/composer.phar run lint +--- +kind: pipeline +type: docker +name: php8.0-lint + +steps: + - name: Test + image: php:8.0 + commands: + - ./bin/composer.phar run lint diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 72f53c901..8612ee740 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,23 +2,6 @@ name: Lint on: pull_request jobs: - php-linters: - name: php${{ matrix.php-versions }} lint - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: ['7.3', '7.4', '8.0'] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up php${{ matrix.php-versions }} - uses: shivammathur/setup-php@master - with: - php-version: ${{ matrix.php-versions }} - coverage: none - - name: Lint - run: bin/composer.phar run lint - php-cs-fixer: name: php-cs check runs-on: ubuntu-latest From 52a5232487079b09c7a0c8fb6a1a548f3267db08 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 13 May 2021 19:44:38 +0200 Subject: [PATCH 3/4] Enable PHP-CS Check per Drone --- .drone.yml | 24 ++++++++++++++++++++++++ .github/workflows/lint.yml | 25 ------------------------- 2 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.drone.yml b/.drone.yml index 74dacfca4..4f1fbae36 100644 --- a/.drone.yml +++ b/.drone.yml @@ -42,3 +42,27 @@ steps: image: php:8.0 commands: - ./bin/composer.phar run lint +--- +kind: pipeline +type: docker +name: php-cs check + +steps: + - name: Install dependencies + image: composer + commands: + - ./bin/composer.phar run cs:install + when: + event: + include: + - pull_request + + - name: Run coding standards check + image: friendicaci/php-cs + commands: + - export CHANGED_FILES="$(git diff --name-status ${DRONE_COMMIT_BEFORE}..${DRONE_COMMIT_AFTER} | grep ^A | cut -f2)" + - /check-php-cs.sh + when: + event: + include: + - pull_request diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 8612ee740..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Lint -on: pull_request - -jobs: - php-cs-fixer: - name: php-cs check - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Get changed files - id: changes - uses: jitterbit/get-changed-files@v1 - - name: Set up php - uses: shivammathur/setup-php@master - with: - php-version: 7.2 - coverage: none - - name: Install dependencies - run: bin/composer.phar run cs:install - - name: Run coding standards check - run: | - if ! echo "${{ steps.changes.outputs.added }}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${{ steps.changes.outputs.added }}"); else EXTRA_ARGS=''; fi - bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --diff --diff-format=udiff --dry-run --stop-on-violation --using-cache=no ${EXTRA_ARGS} - shell: bash \ No newline at end of file From 3e00fcd1ca28be2bbac4972c2ec5ac6cd1b51782 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 13 May 2021 22:31:37 +0200 Subject: [PATCH 4/4] Optimize PHP-CS check --- .drone.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4f1fbae36..257fe23d7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -47,22 +47,17 @@ kind: pipeline type: docker name: php-cs check +trigger: + event: + - pull_request + steps: - name: Install dependencies image: composer commands: - ./bin/composer.phar run cs:install - when: - event: - include: - - pull_request - - name: Run coding standards check image: friendicaci/php-cs commands: - export CHANGED_FILES="$(git diff --name-status ${DRONE_COMMIT_BEFORE}..${DRONE_COMMIT_AFTER} | grep ^A | cut -f2)" - /check-php-cs.sh - when: - event: - include: - - pull_request