diff --git a/html/user/gallery.inc b/html/user/gallery.inc index 6ca74005a0..45fce4dd19 100755 --- a/html/user/gallery.inc +++ b/html/user/gallery.inc @@ -79,6 +79,12 @@ function build_picture_pages($width, $height) { 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"; @@ -107,6 +113,8 @@ function build_country_pages() { $countries = array_keys($countryMembers); // Build the pages. + // TODO: Define a constant for the desired number of rows per page. + foreach ($countries as $country) { build_country_page($country, &$countryMembers[$country], 5); } @@ -120,6 +128,10 @@ function build_country_pages() { } +// Helper function for build_country_page. Creates as many pages as +// are neccessary to list all user profiles for country $name, given +// $rows rows per page. Member IDs are passed in the array $members. + function build_country_page($name, $members, $rows) { $countryName = $name; @@ -141,46 +153,15 @@ function build_country_page($name, $members, $rows) { $filename = PROFILE_PATH . "profile_country_" . $name . "_" . $page . ".html"; $descriptor = fopen($filename, "w"); - // TODO: Page header. - //fwrite($descriptor, "\n"); page_head("User Profiles from $countryName: Page $page of $numPages", null, $descriptor); fwrite($descriptor, "

$countryName

\n"); fwrite($descriptor, "Last updated " . gmdate("r") . " UTC

\n"); - fwrite($descriptor, "\n"); + + $offset = (($page-1) * $rows * 2); + $numPerPage = ($rows * 2); - for ($row = 0; $row < $rows; $row++) { - if ($count >= $numMembers) { - break; - } - - fwrite($descriptor, "\n"); - - // Formatting is a table with two columns of user summaries. - for ($col = 0; $col < 2; $col++) { - if ($count < $numMembers) { - fwrite($descriptor, ""); - $count++; - } - else { - // Empty entry. - fwrite($descriptor, ""); - } - } - fwrite($descriptor, "\n"); - } - fwrite($descriptor, "
"); - - // Only link an image if one exists. - if (file_exists(IMAGE_PATH . $members[$count] . '_sm.jpg')) { - fwrite($descriptor, ""); - } else { - fwrite($descriptor, " "); - } - - fwrite($descriptor, "
"); - fwrite($descriptor, get_profile_summary($members[$count])); - fwrite($descriptor, "
\n"); + show_user_table($members, $offset, $numPerPage, 2, $descriptor); $tempFileName = "profile_country_" . $name; write_page_links($tempFileName, $page, $numPages, $descriptor); @@ -191,11 +172,109 @@ function build_country_page($name, $members, $rows) { } +// Builds a summary table of user profiles, writing it to $descriptor if it is +// available, or echoing if it is not. +// +// $members is an array of userIDs; +// $offset indicates which entry to begin the table with +// $numToDisplay indicates how many profiles to display in this table +// $cols indicates how many profile summaries should be written per row +// $descriptor is an optional file descriptor to write the table to. + +function show_user_table($members, $offset, $numToDisplay, $cols, $descriptor=null) { + + // TODO: Would be nice if we could open a stream to stdout to avoid + // all the redundant $descriptor checks. Once the server is running + // PHP 5+, might want to try switching over to fprintf(...). + + if ($descriptor) { + fwrite($descriptor, "\n"); + } else { + echo "
"; + } + + $rows = ceil($numToDisplay / $cols); + $count = $offset; + $numMembers = count($members); + + for ($row = 0; $row < $rows; $row++) { + if ($count >= $numMembers) { + break; + } + + if ($descriptor) { + fwrite($descriptor, "\n"); + } else { + echo ""; + } + + // Formatting is a table with two columns of user summaries. + for ($col = 0; $col < $cols; $col++) { + if ($count < $numMembers) { + if ($descriptor) { + fwrite($descriptor, ""); + } else { + echo ""; + } + + $count++; + } + else { + // Empty entry + if ($descriptor) { + fwrite($descriptor, ""); + } else { + echo ""; + } + } + } + if ($descriptor) { + fwrite($descriptor, "\n"); + } else { + echo ""; + } + } + if ($descriptor) { + fwrite($descriptor, "
"); + } else { + echo "
"; + } + + // Only link an image if one exists. + if (file_exists(IMAGE_PATH . $members[$count] . '_sm.jpg')) { + if ($descriptor) { + fwrite($descriptor, ""); + } else { + echo ""; + } + + } else { + if ($descriptor) { + fwrite($descriptor, " "); + } else { + echo " "; + } + } + if ($descriptor) { + fwrite($descriptor, "
"); + fwrite($descriptor, get_profile_summary($members[$count])); + fwrite($descriptor, "\n", get_profile_summary($members[$count]), "
\n"); + } else { + echo ""; + } +} + +// Generates a legal filename from a parameter string. + function get_legal_filename($name) { $name = ereg_replace(',', '', $name); return ereg_replace(' ', '_', $name); } +// Generates a string containing: +// 1) the name of the user with ID == $userid, with a link to a view of their profile; +// 2) the first MAX_DESC_LENGTH characters from the response1 field of said user's profile. + function get_profile_summary($userid) { $result = mysql_query("SELECT * FROM profile WHERE userid = $userid"); $result2 = mysql_query("SELECT name FROM user WHERE id = $userid"); @@ -224,6 +303,9 @@ function get_profile_summary($userid) { return $summary; } +// Generates a standard set of links between associated multi-page documents. All linked +// files must be of the form "$filename_.html". + function write_page_links($filename, $currPageNum, $numPages, $descriptor) { fwrite($descriptor, "

Page $currPageNum of $numPages

");