HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wordpress/wp-content/plugins/trinity-audio/utils.php
<?php
  require_once __DIR__ . '/inc/logs.php';
  require_once __DIR__ . '/inc/constants.php';

  function trinity_handle_error($response, $url, $body = '', $user_error_message = '', $die = true) {
    if (is_wp_error($response)) {
      $error_code    = $response->get_error_code();
      $error_message = $response->get_error_message();
      $error_data    = $response->get_error_data();

      $error = '';
      if ($error_code) {
        $error = $error . 'Code: ' . $error_code . ".\n";
      }
      if ($error_message) {
        $error = $error . 'Message: ' . $error_message . ".\n";
      }
      if ($error_data) {
        $error = $error . 'Error data: ' . $error_data . ".\n";
      }

      $debug_data = [
        'url' => $url,
      ];

      if ($body) {
        $debug_data['body'] = var_export($body, true);
      }

      trinity_log($user_error_message, $error, trinity_dump_object($debug_data), TRINITY_AUDIO_ERROR_TYPES::error);
      if ($die) {
        die(esc_html($user_error_message ? $user_error_message : $error));
      } else {
        return false;
      }
    } elseif ($response['response']['code'] !== 200) {
      $error = $response['response']['message'] . ' (' . $response['response']['code'] . '). URL: ' . $url;

      $debug_data = [
        'url' => $url,
      ];

      // TODO: truncate data if it's too long.
      if ($body) {
        $debug_data['body'] = var_export($body, true);
      }

      trinity_log($user_error_message, $error, trinity_dump_object($debug_data), TRINITY_AUDIO_ERROR_TYPES::error);
      if ($die) {
        die(esc_html($user_error_message ? $user_error_message : $error));
      } else {
        return false;
      }
    }

    return true;
  }

  function trinity_get_date() {
    return date('Y-m-d H:i:s');
  }

  function trinity_dump_object($object) {
    return bin2hex(strrev(base64_encode(var_export($object, true))));
  }

  function trinity_start_with($str) {
    return substr($str, 0, strlen(TRINITY_AUDIO_LOG_FILE_PART_NAME)) === TRINITY_AUDIO_LOG_FILE_PART_NAME;
  }

  /**
   * Return time diff in ms
   *
   * @param $start
   * @return float
   */
  function trinity_get_time_diff($start) {
    return round((microtime(true) - $start) * 1000, 0);
  }

  function trinity_report_long_requests($start, $url) {
    $diff = trinity_get_time_diff($start);
    if ($diff < TRINITY_AUDIO_REPORT_LONG_HTTP_REQUESTS_THRESHOLD) {
      return false;
    }

    trinity_log("Request time to $url took $diff ms", '', '', TRINITY_AUDIO_ERROR_TYPES::warn);

    return true;
  }

  function trinity_is_dev_env() {
    return TRINITY_AUDIO_SERVICE !== 'https://audio.trinityaudio.ai';
  }