function buildListPage($listPageObject) { global $errorArray; global $successArray; global $templateHtml; global $statusFile; global $pageBeforeContent; global $pageAfterContent; global $conn_id; global $listCounter; global $numListPages; $errorSize = count($errorArray); fwrite($statusFile, "<strong>(" . ($listCounter + 1) . "/{$numListPages}) Memory Used:" . memory_get_usage() . "</strong> " . $listPageObject->url . ":<br>"); fwrite($statusFile, " " . $listPageObject->toString() . "<br>"); //Open handle to page if (!file_exists(DOC_ROOT_PATH . "{$listPageObject->url}")) { build_directory_structure($listPageObject->url); } $pageToBeDeployedHandle = fopen(DOC_ROOT_PATH . $listPageObject->url, 'w') or die("can't open file"); //Insert title into head section $updatedPageBeforeContent = str_replace("#head-additional-styles-and-scripts#", "<title>{$listPageObject->listingName} Vacation and Resort Listing</title>", $pageBeforeContent); // Add the remote path where the installation is located $updatedPageBeforeContent = str_replace("#remote-install-path#", REMOTE_INSTALL_PATH, $updatedPageBeforeContent); // Replace the agency code $updatedPageBeforeContent = str_replace("#agency-code#", AGENCY_CODE, $updatedPageBeforeContent); //Insert country code and empty hotel code for search $updatedPageBeforeContent = str_replace("#country-code-upper##hotel-code-upper#", "", $updatedPageBeforeContent); if (property_exists($listPageObject, "countryCode")) { $updatedPageBeforeContent = str_replace("#country-code-upper#", $listPageObject->countryCode, $updatedPageBeforeContent); $updatedPageBeforeContent = str_replace("#dest-region#", "", $updatedPageBeforeContent); } else { // Chain pages we aren't sure of country or hotel, so just filter by destination region $updatedPageBeforeContent = str_replace("#country-code-upper#", "", $updatedPageBeforeContent); $updatedPageBeforeContent = str_replace("#hotel-code-upper#", "", $updatedPageBeforeContent); $updatedPageBeforeContent = str_replace("#dest-region#", DEST_REGION_FILTER, $updatedPageBeforeContent); } $updatedPageBeforeContent = str_replace("#meta-keywords#", $listPageObject->listingName . ", " . $listPageObject->listingName . " hotel, " . $listPageObject->listingName . " resort, " . $listPageObject->listingName . " all inclusive", $updatedPageBeforeContent); $updatedPageBeforeContent = str_replace("#meta-description#", PRETTY_SITE_NAME . " provides All-inclusive vacations to " . $listPageObject->listingName . ". Great prices, personal service, and can price match (then beat) any other offer.", $updatedPageBeforeContent); //Write html before the content fwrite($pageToBeDeployedHandle, $updatedPageBeforeContent); //Check to see if we should treat as a hotel chain object or standard hotel object if (strcmp(get_class($listPageObject), "ChainListPageObject") != 0) { foreach ($listPageObject->hotelCodes as $childHotel) { $hotelListObject = get_hotel_info($listPageObject->countryCode, $childHotel); if (!empty($hotelListObject->hotelName)) { $listOutput = $hotelListObject->formattedOutput(); fwrite($statusFile, " " . $hotelListObject->hotelName . "<br>"); //Write html for current hotel fwrite($pageToBeDeployedHandle, $listOutput); } else { $errorArray[$hotelListObject->countryCode . $hotelListObject->hotelCode] = "countryCode:{$hotelListObject->countryCode}, hotelCode:{$hotelListObject->hotelCode}"; } if (kill_build()) { fwrite($statusFile, "<br>BUILD KILLED!!!<br>"); $errorArray[] = "Build Killed!"; break; } } } else { foreach ($listPageObject->hotels as $hotelListObject) { if (!empty($hotelListObject->hotelName)) { $listOutput = $hotelListObject->formattedOutput(); fwrite($statusFile, " " . $hotelListObject->hotelName . "<br>"); //Write html for current hotel fwrite($pageToBeDeployedHandle, $listOutput); } else { $errorArray[$hotelListObject->countryCode . $hotelListObject->hotelCode] = "countryCode:{$hotelListObject->countryCode}, hotelCode:{$hotelListObject->hotelCode}"; } if (kill_build()) { fwrite($statusFile, "<br>BUILD KILLED!!!<br>"); $errorArray[] = "Build Killed!"; break; } } } fwrite($statusFile, "<br>"); $pageAfterContent = str_replace("#pretty-site-name#", PRETTY_SITE_NAME, $pageAfterContent); //Write html after the content fwrite($pageToBeDeployedHandle, $pageAfterContent); chmod(DOC_ROOT_PATH . "{$listPageObject->url}", 0777); // Close reference to file fclose($pageToBeDeployedHandle); if (FTP_ENABLED) { $pageToBeDeployedHandle = fopen(DOC_ROOT_PATH . $listPageObject->url, 'r') or die("can't open file"); // change to proper dir build_directory_structure_ftp($conn_id, get_file_dir($listPageObject->url)); ftp_chdir($conn_id, REMOTE_DOC_ROOT_PATH . get_file_dir($listPageObject->url)); // try to upload $file and check if all the hotels in list were successfully added (errors start == errors end) if (ftp_fput($conn_id, get_file_name($listPageObject->url), $pageToBeDeployedHandle, FTP_ASCII) && $errorSize == count($errorArray)) { $successArray[] = "http://" . SITE_DOMAIN . $listPageObject->url; } else { if ($errorSize == count($errorArray)) { // If the error count is equal then it is FTP error, else has been logged above $errorArray[] = "FTP error: {$listPageObject->url}"; } } // Close reference to file fclose($pageToBeDeployedHandle); } }
$priceDisplayHTML = str_replace("#three-day-price-output#", $threeDayPrice, $priceDisplayHTML); $priceDisplayHTML = str_replace("#seven-day-price-output#", $sevenDayPrice, $priceDisplayHTML); $priceDisplayHTML = str_replace("#trip-start#", $tripStart, $priceDisplayHTML); $pageToBeDeployed = str_replace("<!--#price-info#-->", $priceDisplayHTML, $pageToBeDeployed); } } } //Add the country listing breadcrumb //TODO figure out a solution to point back to listings for adults only or however they got to the detail page. // probably don't generate a different detail page for each category $listingUrl = create_listing_url($datarow, ""); $listingBreadcrumb = "<a href='" . $listingUrl . "'><h2 style='text-decoration:underline'>« Return to All Inclsuive Hotels in " . $datarow[CSV_CITY_OR_STATE_INDEX] . " " . $datarow[CSV_COUNTRY_INDEX] . "</h2></a>"; $pageToBeDeployed = str_replace("<!--#country-listing-breadcrumb#-->", $listingBreadcrumb, $pageToBeDeployed); $filePath = $datarow[CSV_URL_INDEX]; if (!file_exists(DOC_ROOT_PATH . "{$filePath}")) { build_directory_structure($filePath); if (FTP_ENABLED) { build_directory_structure_ftp($conn_id, get_file_dir($filePath)); } } $pageToBeDeployedHandle = fopen(DOC_ROOT_PATH . $datarow[CSV_URL_INDEX], 'w') or die("can't open file"); fwrite($pageToBeDeployedHandle, $pageToBeDeployed); chmod(DOC_ROOT_PATH . $datarow[CSV_URL_INDEX], 0777); // Close reference to file fclose($pageToBeDeployedHandle); if (FTP_ENABLED) { $pageToBeDeployedHandle = fopen(DOC_ROOT_PATH . $datarow[CSV_URL_INDEX], 'r') or die("can't open file"); // change to proper dir if (!@ftp_chdir($conn_id, REMOTE_DOC_ROOT_PATH . get_file_dir($filePath))) { build_directory_structure_ftp($conn_id, get_file_dir($filePath)); ftp_chdir($conn_id, REMOTE_DOC_ROOT_PATH . get_file_dir($filePath));