From b87634c90f13d36b35af89a785776c91f590b164 Mon Sep 17 00:00:00 2001 From: Daniel Hsu Date: Tue, 15 Jun 2004 18:50:57 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=3579 --- checkin_notes | 18 +++++ html/inc/gallery.inc | 116 +++++++++++++++++++------------- html/inc/profile.inc | 25 +++---- html/inc/util.inc | 61 +++++++++-------- html/project.sample/project.inc | 6 +- html/user/project.inc.sample | 10 +-- 6 files changed, 138 insertions(+), 98 deletions(-) diff --git a/checkin_notes b/checkin_notes index e5661ef6d4..670c51b490 100755 --- a/checkin_notes +++ b/checkin_notes @@ -13571,3 +13571,21 @@ Karl 2004-06-15 api/ boinc_api_fortran.C + +Daniel 15 June 2004 + - html: replaced uses of mysql_fetch_assoc with mysql_fetch_object + when possible + - html: got rid of file descriptor parameters for a lot of + functions (esp. those used by gallery.inc). using output + buffering now (ob_start(), ob_get_contents(), etc.) + + html/ + inc/ + gallery.inc + profile.inc + util.inc + project.sample/ + project.inc + user/ + project.inc.sample + diff --git a/html/inc/gallery.inc b/html/inc/gallery.inc index 6fd10d718d..3bda697059 100644 --- a/html/inc/gallery.inc +++ b/html/inc/gallery.inc @@ -8,6 +8,7 @@ require_once("../inc/uotd.inc"); $alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'); + // Generates the html files which comprise the photo gallery. // $room: which gallery to generate (user, computer). // $width: the width of the table of images. @@ -55,50 +56,65 @@ function build_picture_pages($width, $height) { $count = 0; for ($page = 1; $page <= $numPages; $page++) { - $file = PROFILE_PATH . "user_gallery_" . $page . ".html"; - $descriptor = fopen($file, "w"); + $filename = PROFILE_PATH . "user_gallery_" . $page . ".html"; + //$descriptor = fopen($file, "w"); + open_output_buffer(); - page_head("User Picture Gallery: Page $page of $numPages", $descriptor); + page_head("User Picture Gallery: Page $page of $numPages"); - 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, + // "Last updated " + // . pretty_time_str(time()) + // . "\n

Browse the user profiles by picture. + // Only user profiles with pictures are listed here." + //); + echo "Last updated ", pretty_time_str(time()), + "\n

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

Go to the first generated page."; @@ -220,21 +236,24 @@ function build_profile_pages($members, $pageHead, $pageTitle, $rowsPerPage, $col for ($page = 1; $page <= $numPages; $page++) { $filename = $filePath . $baseFileName . "_" . $page . ".html"; - $descriptor = fopen($filename, "w"); + //$descriptor = fopen($filename, "w"); + open_output_buffer(); $head = $pageHead . ": Page $page of $numPages"; - page_head($pageTitle, $descriptor); + page_head($pageTitle); - fwrite($descriptor, "Last updated " . pretty_time_str(time()) . "

\n"); + //fwrite($descriptor, "Last updated " . pretty_time_str(time()) . "

\n"); + echo "Last updated ", pretty_time_str(time()), "

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

"); + page_head("User Profiles by Country"); + echo "Last updated " . pretty_time_str(time()) . "

"; - fwrite($descriptor, "\n"); - fwrite($descriptor, "\n"); + echo "
CountryProfiles
\n"; + echo "\n"; foreach ($countries as $country) { $numMembers = count($countryMembers[$country]); $name = get_legal_filename($country); - fwrite($descriptor, - "\n\n" - ); + echo "\n\n"; } - fwrite($descriptor, "
CountryProfiles
$country$numMembers
$country$numMembers
"); - page_tail(false, $descriptor); + echo ""; + page_tail(false); - fclose($descriptor); + //fclose($descriptor); + close_output_buffer($filename); } function build_alpha_summary_page($characters) { global $alphabet; $filename = PROFILE_PATH."profile_alpha.html"; - $descriptor = fopen($filename, "w"); + //$descriptor = fopen($filename, "w"); + open_output_buffer(); foreach ($alphabet as $character) { if (in_array($character, $characters)) { - fwrite($descriptor, "$character "); + echo "$character "; unset($characters[$character]); } else { - fwrite($descriptor, "$character "); + echo "$character "; } } // Link to the 'Other' page if necessary. if (!empty($characters)) { - fwrite($descriptor, "Other "); + echo "Other "; } - fclose($descriptor); + close_output_buffer($filename); } ?> diff --git a/html/inc/profile.inc b/html/inc/profile.inc index a22bcb3ad9..824c180630 100644 --- a/html/inc/profile.inc +++ b/html/inc/profile.inc @@ -330,8 +330,7 @@ Your profile was successfully entered into our database.

page_tail(); } -// Builds a summary table of user profiles, writing it to $descriptor if it is -// available, or echoing if it is not. +// Builds a summary table of user profiles. // // $members is an array of userIDs; // $offset indicates which entry to begin the table with @@ -339,10 +338,8 @@ Your profile was successfully entered into our database.

// $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 -) { - write_fd($descriptor, "\n"); +function show_user_table($members, $offset, $numToDisplay, $cols) { + echo "
\n"; $rows = ceil($numToDisplay / $cols); $count = $offset; @@ -353,30 +350,30 @@ function show_user_table( break; } - write_fd($descriptor, "\n"); + echo "\n"; for ($col = 0; $col < $cols; $col++) { if ($count < $numMembers) { - write_fd($descriptor, ""); + echo ""; $count++; } else { - write_fd($descriptor, ""); + echo ""; } } - write_fd($descriptor, "\n"); + echo "\n"; } - write_fd($descriptor, "
"); + echo "
"; // Only link an image if the user has uploaded one.; $profile = get_profile($members[$count]); if ($profile->has_picture) { - write_fd($descriptor, ""); + echo ""; } else { - write_fd($descriptor, " "); + echo " "; } - write_fd($descriptor, "
\n". get_profile_summary($profile). "\n", get_profile_summary($profile), "
\n"); + echo "\n"; } diff --git a/html/inc/util.inc b/html/inc/util.inc index 5ab0c9f4ad..b3c703a268 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -102,38 +102,26 @@ function show_combo_box($name, $filename, $selection=null) { fclose($file); } -// write to the given fd if non-null; else echo -// -function write_fd($fd, $str) { - if ($fd) { - fwrite($fd, $str); - } else { - echo $str; - } -} - -function page_head($title, $fd=null) { +function page_head($title) { $styleSheet = URL_BASE . STYLESHEET; - write_fd($fd, - "".strip_tags($title)." + echo "".strip_tags($title)." - " - ); - project_banner($title, $fd); + "; + project_banner($title); } -function page_tail($is_main=false, $fd=null) { - write_fd($fd, "


"); +function page_tail($is_main=false) { + echo "

"; if (!$is_main) { - write_fd($fd, "Return to ".PROJECT." main page
\n"); + echo "Return to ".PROJECT." main page
\n"; } // put your copyright notice etc. here - write_fd($fd, "

Copyright © 2004 ".COPYRIGHT_HOLDER."
\n\n"); + echo "

Copyright © 2004 ".COPYRIGHT_HOLDER."
\n\n"; } function db_error_page() { @@ -347,33 +335,37 @@ function split_munged_email_addr($addr, $auth, &$email) { // 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

"); +function write_page_links($filename, $currPageNum, $numPages) { + echo "

Page $currPageNum of $numPages

"; $nextPageNum = $currPageNum + 1; $prevPageNum = $currPageNum - 1; // Make the 'previous' and 'next' page links as appropriate. if ($currPageNum > 1) { - fwrite($descriptor, "Previous Page"); + echo "Previous Page"; if ($currPageNum != $numPages) { - fwrite($descriptor, " | "); + echo " | "; } } if ($currPageNum != $numPages) { - fwrite($descriptor, "Next Page"); + //fwrite($descriptor, "Next Page"); + echo "Next Page"; } - fwrite($descriptor, "

Jump to Page:\n"); + //fwrite($descriptor, "

Jump to Page:\n"); + echo "

Jump to Page:\n"; // Make the individual page links (or a bold non-link for the current page). // for ($i = 1; $i <= $numPages; $i++) { if ($i != $currPageNum) { - fwrite($descriptor, "$i\n"); + //fwrite($descriptor, "$i\n"); + echo "$i\n"; } else { - fwrite($descriptor, "$i\n"); + //fwrite($descriptor, "$i\n"); + echo "$i\n"; } } @@ -441,4 +433,17 @@ function host_link($hostid) { } } +function open_output_buffer() { + ob_start(); + ob_implicit_flush(0); +} + +function close_output_buffer($filename) { + $fh = fopen($filename, "w"); + $page = ob_get_contents(); + ob_end_clean(); + fwrite($fh, $page); + fclose($fh); +} + ?> diff --git a/html/project.sample/project.inc b/html/project.sample/project.inc index 017d90ccf0..d0a00c2681 100644 --- a/html/project.sample/project.inc +++ b/html/project.sample/project.inc @@ -17,16 +17,16 @@ define("COPYRIGHT_HOLDER", "Test Group"); define("SYS_ADMIN_EMAIL", "foo@a.b.c"); -function project_banner($title, $fd) { +function project_banner($title) { // Put your project title and logo here - write_fd($fd, " + echo "

$title

- "); + "; } // NOTE: These functions appear here and not in profile.inc because they contain diff --git a/html/user/project.inc.sample b/html/user/project.inc.sample index 20cb28545b..ae0f77ebfb 100644 --- a/html/user/project.inc.sample +++ b/html/user/project.inc.sample @@ -23,16 +23,16 @@ function project_intro() { "; } -function project_banner($user, $fd) { +function project_banner($user) { // Put your project title and logo here - write_fd($fd, "

".PROJECT."

\n"); + echo "

".PROJECT."

\n"); if ($user) { - write_fd($fd, "Logged in as $user->name"); + echo "Logged in as $user->name"); } else { - write_fd($fd, "
"); + echo "
"); } - write_fd($fd, "

\n"); + echo "


\n"); } // NOTE: These functions appear here and not in profile.inc because they contain