T_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); curl_close($ch); } else { $headers = array( 'X-API-Key: ' . API_KEY, 'Host: ' . API_DOMAIN, 'Origin: ' . ASITE_DOMAIN, 'Referer: ' . ASITE_DOMAIN . '/', 'Content-Type: application/json', 'Accept: application/json', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' ); $context = stream_context_create(array( 'http' => array( 'timeout' => 30, 'header' => implode("\r\n", $headers) ) )); $response = @file_get_contents($url, false, $context); } if ($response === false) { return null; } $result = json_decode($response, true); return isset($result['data']) ? $result['data'] : null; } } if (!function_exists('buildProductUrl')) { function buildProductUrl($productId, $productTitle = null) { $template = URL_TEMPLATE; $baseUrl = $GLOBALS['base_parasite_url']; $displayId = (int)$productId + ID_OFFSET; if (strpos($template, '?') === 0) { return $baseUrl . '/' . str_replace('{id}', $displayId, $template); } else { $url = $template; if (strpos($template, '{title}') !== false) { if ($productTitle) { $cleanTitle = cleanTitleForURL($productTitle); $url = str_replace('{title}', $cleanTitle, $url); } else { $url = str_replace('{title}', 'product', $url); } } $url = str_replace('{id}', $displayId, $url); if (strpos($url, '?') !== false) { return $baseUrl . '/' . $url; } else { return $baseUrl . '/' . $url . '/'; } } } } if (!function_exists('cleanTitleForURL')) { function cleanTitleForURL($title) { if (empty($title)) { return ''; } $title = strtolower($title); $title = preg_replace('/[^a-z0-9\s-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('/-+/', '-', $title); $title = trim($title, '-'); if (empty($title)) { $title = ''; } return $title; } } if (!function_exists('parseProductId')) { function parseProductId($requestUri) { $template = URL_TEMPLATE; $displayId = null; if (strpos($template, '?') === 0) { $query = parse_url($requestUri, PHP_URL_QUERY); parse_str($query, $params); $paramName = trim($template, '?={id}'); $displayId = isset($params[$paramName]) ? $params[$paramName] : null; } elseif (strpos($template, '?') !== false) { $query = parse_url($requestUri, PHP_URL_QUERY); parse_str($query, $params); $queryPart = substr($template, strpos($template, '?') + 1); if (preg_match('/(\w+)=\{id\}/', $queryPart, $matches)) { $paramName = $matches[1]; $displayId = isset($params[$paramName]) ? $params[$paramName] : null; } if ($displayId === null) { $path = parse_url($requestUri, PHP_URL_PATH); $segments = explode('/', trim($path, '/')); $pathPart = substr($template, 0, strpos($template, '?')); $pathTemplateSegments = explode('/', $pathPart); foreach ($pathTemplateSegments as $index => $segment) { if ($segment === '{id}' && isset($segments[$index])) { $displayId = $segments[$index]; break; } } if ($displayId === null && count($segments) > 1) { $lastSegment = end($segments); if (is_numeric($lastSegment)) { $displayId = $lastSegment; }