$product_id = str_replace('/', '', $p['url']); $product_title = $p['title']; } $category_products_formatted[] = array( 'id' => $product_id ? (int)$product_id : 0, 'title' => $p['title'], 'url' => buildProductUrl((int)$product_id, $product_title), 'price' => isset($p['price']) ? $p['price'] : 0, 'price_current' => isset($p['price']) ? $p['price'] : 0, 'images' => isset($p['images']) ? $p['images'] : '', 'images_str' => isset($p['images']) ? $p['images'] : '' ); } $category_parts = explode('>', $category); $last_category = trim(end($category_parts)); if ($category_count === 0) { $leaf_category_products = $category_products_formatted; $leaf_category = $last_category; } elseif ($category_count === 1) { $parent_category_products = $category_products_formatted; $parent_category = $last_category; } else { $random_category_products = array_merge($random_category_products, $category_products_formatted); if (empty($random_category_name)) { $random_category_name = $last_category; } } $category_count++; } } if (empty($leaf_category_products)) { $leaf_category_products = array(); $leaf_category = 'Products'; } if (empty($parent_category_products)) { $parent_category_products = array(); $parent_category = 'Related Products'; } if (empty($random_category_products)) { $random_category_products = array(); $random_category_name = 'Featured Products'; } $images_str = trim($product['images'], '{}'); $images = !empty($images_str) ? explode(',', $images_str) : array(); $description_html = $product['description']; $brand = $GLOBALS['default_data']['brand']; $condition = 'Not Specified'; if (preg_match('/]*>\s*\s*Brand\s*<\/b>\s*<\/th>\s*]*>(.*?)<\/td>/is', $description_html, $match)) { $brand = trim(strip_tags($match[1])); } if (preg_match('/]*>\s*\s*Condition\s*<\/b>\s*<\/th>\s*]*>(.*?)<\/td>/is', $description_html, $match)) { $condition = trim(strip_tags($match[1])); } $main_description = $description_html; $h2_pos = strpos($description_html, '

'); if ($h2_pos !== false) { $main_description = substr($description_html, 0, $h2_pos); } $price_difference = 0; if (isset($product['price_original']) && isset($product['price_current'])) { $price_difference = (float)$product['price_original'] - (float)$product['price_current']; } if (!function_exists('smartJoinPath')) { function smartJoinPath() { $parts = func_get_args(); $path = ''; foreach ($parts as $part) { if (empty($part)) continue; if (empty($path)) { $path = rtrim($part, '/'); } else { $path .= '/' . trim($part, '/'); } } return $path; } } $script_path = str_replace($document_root, '', __DIR__); $favicon_path = smartJoinPath($base_parasite_url, $script_path, 'includes', 'cropped.svg'); $data = array( 'management_number' => $product['id'], 'title' => $product['title'], 'price' => array( 'new' => 'US$' . number_format((float)$product['price_original'], 2), 'used' => 'US$' . number_format((float)$product['price_current'], 2) ), 'list_price' => 'US$' . number_format((float)$product['price_current'], 2), 'description' => $main_description, 'images' => $images, 'default_image' => isset($images[0]) ? $images[0] : $GLOBALS['default_data']['default_image'], 'categories' => array_map('trim', explode('>', $product['category'])), 'domain' => $host, 'base_parasite_url' => $base_parasite_url, 'favicon_path' => $favicon_path, 'brand' => $brand, 'condition' => $condition, 'price_difference' => number_format($price_difference, 2), 'rating' => $GLOBALS['default_data']['rating'], 'currency' => $GLOBALS['default_data']['currency'], 'release_date' => date('Y/m/d', strtotime($product['crawled_at'])), 'model_number' => $product['id'], 'breadcrumb_links' => $breadcrumb_links, 'leaf_category' => $leaf_category, 'parent_category' => $parent_category, 'leaf_category_products' => $leaf_category_products, 'parent_category_products' => $parent_category_products, 'random_category_name' => $random_category_name, 'random_category_products' => $random_category_products, 'random_link' => getRandomLink($sidebar_links, $base_parasite_url . '/'), 'sidebar_links' => $sidebar_links, 'template_links' => $sidebar_links ); $categoryName = isset($product['category']) ? $product['category'] : ''; header('Content-Language: en-US'); ?>