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)); } // try to upload $file if (ftp_fput($conn_id, get_file_name($filePath), $pageToBeDeployedHandle, FTP_ASCII)) { $successArray[] = "http://www.iwanttolol.com/" . $datarow[CSV_URL_INDEX]; } else { $errorArray[] = "FTP error: {$thePage}"; } // Close reference to file fclose($pageToBeDeployedHandle); } } else { $errorArray[] = "No content (" . strlen($theContent) . "): {$thePage}"; error_log("No content: {$thePage}. Content: \n" . $theContent, 0); }
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); } }
function ftp_to_deployment_site($localFile, $remoteDir = REMOTE_DOC_ROOT_PATH) { // set up basic connection $conn_id = ftp_connect(FTP_SERVER); // login with username and password $login_result = ftp_login($conn_id, FTP_USERNAME, FTP_PASSWORD); $pageToBeDeployedHandle = fopen($localFile, 'r') or die("can't open file"); // change to proper dir if (!ftp_chdir($conn_id, $remoteDir)) { build_directory_structure_ftp($conn_id, $remoteDir); ftp_chdir($conn_id, $remoteDir); error_log("Built dir for ftp_to_deployment_site: " . $remoteDir, 0); } // try to upload $file if (!ftp_fput($conn_id, get_file_name($localFile), $pageToBeDeployedHandle, FTP_ASCII)) { echo "There was a problem while uploading {$localFileName}\n"; error_log("There was a problem while uploading {$localFileName}", 0); } // Close reference to file fclose($pageToBeDeployedHandle); // close the connection and the file handler ftp_close($conn_id); }