Exemple #1
0
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
require_once "../inc/util.inc";
require_once "../inc/boinc_db.inc";
if (DISABLE_PROFILES) {
    error_page("Profiles are disabled");
}
check_get_args(array("userid", "vote"));
$userid = get_int('userid');
$vote = get_str('vote');
$logged_in_user = get_logged_in_user();
if ($vote != "recommend" && $vote != "reject") {
    error_page(tra("Invalid vote type:") . " " . htmlentities($vote));
}
BoincProfile::update_aux("{$vote}={$vote}+1 WHERE userid = {$userid}");
page_head(tra("Vote Recorded"));
start_table_noborder();
row1(tra("Thank you"));
if ($vote == "recommend") {
    rowify(tra("Your recommendation has been recorded."));
} else {
    rowify(tra("Your vote to reject this profile has been recorded."));
}
end_table();
echo "<br><a href=\"view_profile.php?userid=", $userid, "\">" . tra("Return to profile.") . "</a>";
page_tail();
function process_create_profile($user, $profile)
{
    global $config;
    $response1 = post_str('response1', true);
    $response2 = post_str('response2', true);
    $language = post_str('language', true);
    $privatekey = parse_config($config, "<recaptcha_private_key>");
    if ($privatekey) {
        $recaptcha = new ReCaptcha($privatekey);
        $resp = $recaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
        if (!$resp->success) {
            $profile->response1 = $response1;
            $profile->response2 = $response2;
            show_profile_form($profile, tra("Your ReCaptcha response was not correct.  Please try again."));
            return;
        }
    }
    if (!akismet_check($user, $response1)) {
        $profile->response1 = $response1;
        $profile->response2 = $response2;
        show_profile_form($profile, tra("Your first response was flagged as spam by the Akismet anti-spam system.  Please modify your text and try again."));
        return;
    }
    if (!akismet_check($user, $response2)) {
        $profile->response1 = $response1;
        $profile->response2 = $response2;
        show_profile_form($profile, tra("Your second response was flagged as spam by the Akismet anti-spam system.  Please modify your text and try again."));
        return;
    }
    if (isset($_POST['delete_pic'])) {
        $delete_pic = $_POST['delete_pic'];
    } else {
        $delete_pic = "off";
    }
    if (strlen($response1) == 0 && strlen($response2) == 0 && $delete_pic != "on" && !is_uploaded_file($_FILES['picture']['tmp_name'])) {
        error_page(tra("Your profile submission was empty."));
        exit;
    }
    if ($delete_pic == "on") {
        delete_user_pictures($profile->userid);
        $profile->has_picture = false;
        $profile->verification = 0;
    }
    $profile ? $has_picture = $profile->has_picture : ($has_picture = false);
    if (is_uploaded_file($_FILES['picture']['tmp_name'])) {
        $has_picture = true;
        if ($profile) {
            $profile->verification = 0;
        }
        // echo "<br>Name: " . $_FILES['picture']['name'];
        // echo "<br>Type: " . $_FILES['picture']['type'];
        // echo "<br>Size: " . $_FILES['picture']['size'];
        // echo "<br>Temp name: " . $_FILES['picture']['tmp_name'];
        $images = getImages($_FILES['picture']['tmp_name']);
        // Write the original image file to disk.
        // TODO: define a constant for image quality.
        ImageJPEG($images[0], IMAGE_PATH . $user->id . '.jpg');
        ImageJPEG($images[1], IMAGE_PATH . $user->id . '_sm.jpg');
    }
    $response1 = sanitize_html($response1);
    $response2 = sanitize_html($response2);
    $has_picture = $has_picture ? 1 : 0;
    if ($profile) {
        $query = " response1 = '" . BoincDb::escape_string($response1) . "'," . " response2 = '" . BoincDb::escape_string($response2) . "'," . " language = '" . BoincDb::escape_string($language) . "'," . " has_picture = {$has_picture}," . " verification = {$profile->verification}" . " WHERE userid = {$user->id}";
        $result = BoincProfile::update_aux($query);
        if (!$result) {
            error_page(tra("Could not update the profile: database error"));
        }
    } else {
        $query = 'SET ' . " userid={$user->id}," . " language = '" . BoincDb::escape_string($language) . "'," . " response1 = '" . BoincDb::escape_string($response1) . "'," . " response2 = '" . BoincDb::escape_string($response2) . "'," . " has_picture = {$has_picture}," . " recommend=0, " . " reject=0, " . " posts=0, " . " uotd_time=0, " . " verification=0";
        $result = BoincProfile::insert($query);
        if (!$result) {
            error_page(tra("Could not create the profile: database error"));
        }
    }
    $user->update("has_profile=1");
    page_head(tra("Profile saved"));
    echo tra("Congratulations! Your profile was successfully entered into our database.") . "<br><br>" . "<a href=\"view_profile.php?userid=" . $user->id . "\">" . tra("View your profile") . "</a><br>";
    page_tail();
}
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
// script to repair the "has_picture" field of profiles
ini_set("memory_limit", "1023M");
$cli_only = true;
require_once "../inc/util_ops.inc";
BoincDb::get();
$profiles = BoincProfile::enum("");
foreach ($profiles as $p) {
    $id = $p->userid;
    $path = "../user_profile/images/{$id}.jpg";
    $smpath = "../user_profile/images/" . $id . "_sm.jpg";
    $has_pic = file_exists($path);
    $has_pic_sm = file_exists($smpath);
    if ($p->has_picture) {
        if (!$has_pic || !$has_pic_sm) {
            echo "{$id} {$p->has_picture} {$has_pic} {$has_pic_sm}\n";
            BoincProfile::update_aux("has_picture=0 where userid={$id}");
        }
    } else {
        if ($has_pic && $has_pic_sm) {
            echo "{$id} {$p->has_picture} {$has_pic} {$has_pic_sm}\n";
            BoincProfile::update_aux("has_picture=1 where userid={$id}");
        }
    }
}