← Back
Editing: helpers.php
<?php if (!defined('ABSPATH')) { exit; } /** * The request host as the /collect route accepts it: lowercase, no port, no trailing dot, * at least one dot and not an IP address. Returns '' when the host can't be sent. */ function cal_aiv_request_host() { $host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : ''; $host = strtolower(trim($host)); $host = preg_replace('/:\d+$/', '', $host); $host = rtrim($host, '.'); if ($host === '' || strlen($host) > 253 || strpos($host, '.') === false) { return ''; } foreach (explode('.', $host) as $label) { if (!preg_match('/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/', $label)) { return ''; } } // The endpoint rejects IPs in any spelling, including a numeric or hex last label. $labels = explode('.', $host); $last = end($labels); // preg_match, not ctype_digit: the ctype extension is optional and WordPress has no polyfill. if (preg_match('/^\d+$/', $last) || preg_match('/^0x[0-9a-f]*$/', $last)) { return ''; } return $host; } // Old saves used intval(), so a typo like -12345 can be stored; absint() would turn it into another publisher. function cal_aiv_publisher_id() { $id = (int) get_option('cal_publisherId'); return $id > 0 ? $id : 0; } // Control characters removed only: sanitize_text_field() would delete %XX sequences from URLs. function cal_aiv_server_value($key) { if (!isset($_SERVER[$key])) { return null; } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitised by the control-character strip. $value = trim(preg_replace('/[\x00-\x1F\x7F]/', '', wp_unslash($_SERVER[$key]))); return $value === '' ? null : $value; } function cal_aiv_format_datetime($mysql_datetime) { if (!$mysql_datetime) { return 'Never'; } $timestamp = strtotime($mysql_datetime); if ($timestamp === false) { return 'Never'; } // last_fetch is site-local time, which date_i18n expects; wp_date (WP 5.3+) would shift it by the UTC offset. return date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $timestamp); }
Save File
Cancel