"; // Build an array of IDs of all users with pictures in their profiles. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $userIds[] = $row[0]; } mysql_free_result($result); if (count($userIds) > 0) { // Randomize the ordering of users. shuffle($userIds); } $numPages = ceil(count($userIds)/($width * $height)); // Make sure that a page is generated even when no profiles with pictures // exist in order to avoid 404 errors from the profile_menu page. if ($numPages == 0) { $numPages = 1; } //echo "Generating $numPages pages.
"; $count = 0; for ($page = 1; $page <= $numPages; $page++) { $file = PROFILE_PATH . "user_gallery_" . $page . ".html"; $descriptor = fopen($file, "w"); page_head("User Picture Gallery: Page $page of $numPages", $descriptor); fwrite($descriptor, "Last updated " . pretty_time_str(time()) . "\n

Browse the user profiles by picture. Only user profiles with pictures are listed here." ); fwrite($descriptor, "\n"); for ($row = 0; $row < $height; $row++) { fwrite($descriptor, ""); for ($col = 0; $col < $width; $col++) { if ($count < $numIds) { fwrite($descriptor, "" ); $count++; } } fwrite($descriptor, "\n"); if ($count == $numIds) { break; } } fwrite($descriptor, "
\n"); // Previous and Next links write_page_links("user_gallery", $page, $numPages, $descriptor); page_tail(false, $descriptor); fclose($descriptor); } //echo "

Go to the first generated page."; } // Creates pages grouping user profiles by country. Filenames are of the // format "profile_country__.html" // Also creates a summary page listing all countries which have profiled // members, the number of such members, and links to the created pages for // each country. function build_country_pages() { $query = "select * from profile"; $result = mysql_query($query); $numIds = 0; // Build a multi-dimensional array of countries, // each element of which contains an array // of the userids who belong to those countries. // Format: array[country][index] = userid. while ($profile = mysql_fetch_object($result)) { $user = lookup_user_id($profile->userid); if ($user->country) { $countryMembers[$user->country][] = $user->id; $numIds++; } else { $countryMembers['Other'][] = $user->id; } } mysql_free_result($result); //echo "$numIds users have profiles AND non-null country entries.
"; $countries = array_keys($countryMembers); sort($countries); // Build the pages. // TODO: Define a constant for the desired number of rows per page. foreach ($countries as $country) { $baseFileName = "profile_country_" . get_legal_filename($country); $filePath = PROFILE_PATH; build_profile_pages( $countryMembers[$country], "User Profiles from $country", $country, 5, 2, $filePath, $baseFileName, "../html/" ); } // Build the summary page linking to the individual country pages. build_country_summary_page($countryMembers); //echo "
View Summary Page"; //echo "

Done"; } // Creates pages grouping users by the first letter of their names. function build_alpha_pages() { global $alphabet; $query = "select * from profile"; $result = mysql_query($query); $numIds = 0; while ($profile = mysql_fetch_object($result)) { $user = lookup_user_id($profile->userid); if ($user->name) { $name = ltrim($user->name); $members[strtoupper($name[0])][] = $user->id; $numIds++; } } mysql_free_result($result); //echo "$numIds users have profiles AND non-null country entries.
"; $letters = array_keys($members); foreach ($letters as $letter) { // NOTE: Array indexing is case sensitive. $filePath = PROFILE_PATH; if (in_array($letter, $alphabet)) { build_profile_pages( $members[$letter], "User Profiles - Names beginning with $letter", "Names beginning with $letter", 5, 2, $filePath, "profile_$letter" ); } else { build_profile_pages( $members[$letter], "User Profiles - Names beginning with other characters", "Names beginning with other characters", 5, 2, $filePath, "profile_other" ); } } build_alpha_summary_page($letters); } // A generalized function to produce some number of pages summarizing a // set of user profiles. function build_profile_pages($members, $pageHead, $pageTitle, $rowsPerPage, $colsPerPage, $filePath, $baseFileName) { $numMembers = count($members); $numPerPage = $rowsPerPage * $colsPerPage; $numPages = ceil(count($members) / $numPerPage); $count = 0; for ($page = 1; $page <= $numPages; $page++) { $filename = $filePath . $baseFileName . "_" . $page . ".html"; $descriptor = fopen($filename, "w"); $head = $pageHead . ": Page $page of $numPages"; page_head($pageTitle, $descriptor); fwrite($descriptor, "Last updated " . pretty_time_str(time()) . "

\n"); $offset = (($page-1) * $rowsPerPage * $colsPerPage); show_user_table($members, $offset, $numPerPage, $colsPerPage, $descriptor); write_page_links($baseFileName, $page, $numPages, $descriptor); page_tail(false, $descriptor); fclose($descriptor); } } function build_country_summary_page($countryMembers) { $countries = array_keys($countryMembers); $filename = PROFILE_PATH . "profile_country.html"; $descriptor = fopen($filename, "w"); page_head("User Profiles by Country", $descriptor); fwrite($descriptor, "Last updated " . pretty_time_str(time()) . "

"); fwrite($descriptor, "\n"); fwrite($descriptor, "\n"); foreach ($countries as $country) { $numMembers = count($countryMembers[$country]); $name = get_legal_filename($country); fwrite($descriptor, "\n\n" ); } fwrite($descriptor, "
CountryProfiles
$country$numMembers
"); page_tail(false, $descriptor); fclose($descriptor); } function build_alpha_summary_page($characters) { global $alphabet; $filename = PROFILE_PATH."profile_alpha.html"; $descriptor = fopen($filename, "w"); foreach ($alphabet as $character) { if (in_array($character, $characters)) { fwrite($descriptor, "$character "); unset($characters[$character]); } else { fwrite($descriptor, "$character "); } } // Link to the 'Other' page if necessary. if (!empty($characters)) { fwrite($descriptor, "Other "); } fclose($descriptor); } ?>