HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/mailpoet/lib/Util/DateConverter.php
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing

namespace MailPoet\Util;

if (!defined('ABSPATH')) exit;


use MailPoetVendor\Carbon\Carbon;

class DateConverter {
  /**
   * @return string|false
   */
  public function convertDateToDatetime(string $date, string $dateFormat) {
    $datetime = false;

    if ($dateFormat === 'datetime') {
      $datetime = $date;
    } elseif ($dateFormat === 'd/m/Y') {
      $datetime = str_replace('/', '-', $date);
    } else {
      $parsedDate = explode('/', $date);
      $parsedDateFormat = explode('/', $dateFormat);
      $yearPosition = array_search('YYYY', $parsedDateFormat);
      $monthPosition = array_search('MM', $parsedDateFormat);
      $dayPosition = array_search('DD', $parsedDateFormat);
      if (count($parsedDate) === 3) {
        // create date from any combination of month, day and year
        $parsedDate = [
          'year' => $parsedDate[$yearPosition],
          'month' => $parsedDate[$monthPosition],
          'day' => $parsedDate[$dayPosition],
        ];
      } else if (count($parsedDate) === 2) {
        // create date from any combination of month and year
        $parsedDate = [
          'year' => $parsedDate[$yearPosition],
          'month' => $parsedDate[$monthPosition],
          'day' => '01',
        ];
      } else if ($dateFormat === 'MM' && count($parsedDate) === 1) {
        // create date from month
        if ((int)$parsedDate[$monthPosition] === 0) {
          $datetime = '';
          $parsedDate = false;
        } else {
          $parsedDate = [
            'month' => $parsedDate[$monthPosition],
            'day' => '01',
            'year' => date('Y'),
          ];
        }
      } else if ($dateFormat === 'YYYY' && count($parsedDate) === 1) {
        // create date from year
        if ((int)$parsedDate[$yearPosition] === 0) {
          $datetime = '';
          $parsedDate = false;
        } else {
          $parsedDate = [
            'year' => $parsedDate[$yearPosition],
            'month' => '01',
            'day' => '01',
          ];
        }
      } else if ($dateFormat === 'DD' && count($parsedDate) === 1) {
        // create date from day
        if ((int)$parsedDate[$dayPosition] === 0) {
          $datetime = '';
          $parsedDate = false;
        } else {
          $parsedDate = [
            'year' => date('Y'),
            'month' => '01',
            'day' => $parsedDate[$dayPosition],
          ];
        }
      } else {
        $parsedDate = false;
      }
      if ($parsedDate) {
        $year = $parsedDate['year'];
        $month = $parsedDate['month'];
        $day = $parsedDate['day'];
        // if all date parts are set to 0, date value is empty
        if ((int)$year === 0 && (int)$month === 0 && (int)$day === 0) {
          $datetime = '';
        } else {
          if ((int)$year === 0) $year = date('Y');
          if ((int)$month === 0) $month = date('m');
          if ((int)$day === 0) $day = date('d');
          $datetime = sprintf(
            '%s-%s-%s 00:00:00',
            $year,
            $month,
            $day
          );
        }
      }
    }
    if ($datetime !== false && !empty($datetime)) {
      try {
        $datetime = Carbon::parse($datetime)->toDateTimeString();
      } catch (\Exception $e) {
        $datetime = false;
      }
    }
    return $datetime;
  }
}