} ?> </ul> <?php } if (!empty($my_connects_record)) { ?> <p class="margin-top-40"><strong>My Connects (<?php echo number_format($my_connects_totalcount); ?> )</strong></p> <ul class="profile-more-photos"> <?php foreach ($my_connects_record as $mcKey => $mcValue) { $friend_full_name = $mcValue["first_name"] . " " . $mcValue["last_name"]; $facebookUserImage = getUserImage($mcValue["user_id"], $mcValue["user_facebook_id"], NULL, 70, 70); echo '<li><a href="' . getPublicProfileUrl($mcValue["username"]) . '" title="' . $friend_full_name . '"><img src="' . $facebookUserImage . '" alt="image" class="img-circle lazy my-connects-img" data-original="' . $facebookUserImage . '"/></a></li>'; } ?> </ul> <?php } ?> </div> </div> <div class="col-lg-8"> <div class="margin-bottom-20"> <div class="btn-group"> <a href="<?php
include_once "../../common/database.php"; include_once "../../common/image.php"; include_once "../../common/handleresponse.php"; if ($_SERVER["REQUEST_METHOD"] == "GET") { $uuid = $_GET['key']; if (Validation::includeBlank($uuid)) { HandleResponse::badRequest("Parameters are blank"); } else { // Retrieve image data and analysis and show $conn = null; try { $db = new DBConnection(); $conn = $db->getConnection(); mysqli_query($conn, "set autocommit = 0"); mysqli_query($conn, "begin"); $image = getUserImage($conn, $uuid); mysqli_query($conn, "commit"); if ($image != null && ImageUtil::isSupport($image)) { header("Content-Type: " . ImageUtil::contentType($image)); echo $image; } else { // default image header("Content-Type: " . 'image/png'); $im = imagecreatefrompng("../../resources/defaultuser.png"); imagepng($im); imagedestroy($im); } } catch (Exception $e) { mysqli_query($conn, "rollback"); HandleResponse::badRequest($e->getMessage()); }
/** * Gets user image (goes out to gravitar / facebook) * * @param bool $hard_refresh * @return object */ public function getImage($hard_refresh = false) { global $f3, $db, $logger; // If an image is already set then use that if (!$hard_refresh) { if (isset($this->image) && $this->image) { return $this->image; } } // No email or id? Nothing we can do here if (!$this->email && !$this->id) { return false; } // If is a facebook account, we'll hard refresh the image if ($hard_refresh && $this->facebook_id) { $session = new FacebookSession(getFacebookAccessToken()); try { // Get information about fb user $me = (new FacebookRequest($session, 'GET', '/me?fields=picture.height(200)'))->execute()->getGraphObject(GraphUser::className())->asArray(); if (@$me['picture']) { $sql = "UPDATE user "; $sql .= "SET image = ? "; $sql .= "WHERE id = ?;"; $query = $db->prepare($sql); $sql_params = array($me['picture']->data->url, $this->id); $query->execute($sql_params); if (!$query->execute($sql_params)) { $logger->write(sprintf('Couldnt update facebook photo for user ID %s', $this->id)); } } // The Graph API returned an error } catch (FacebookRequestException $e) { echo $e->getMessage(); // Some other error occurred } catch (\Exception $e) { echo $e->getMessage(); } } // Next we'll check the database for an image, $sql = "SELECT image FROM user WHERE "; if ($this->email) { $sql .= 'email = ?'; $sql_params = array($this->email); } else { $sql .= 'id = ?'; $sql_params = array($this->id); } $query = $db->prepare($sql); $query->execute($sql_params); if ($image = $query->fetchColumn()) { return $image; } // As a last resort we'll reach out to gravatar return getUserImage($this->email); }
function updateUserImage($user_id, $fileContents, $objDataHelper) { try { if (strlen(trim($user_id)) <= 0) { throw new Exception("profile_function.inc.php: updateUserImage : Missing Parameter user_id.", 141); } if (strlen(trim($fileContents)) <= 0) { throw new Exception("profile_function.inc.php: updateUserImage : Missing Parameter file contents.", 141); } if (!isset($objDataHelper)) { throw new Exception("profile_function.inc.php: updateUserImage : Datahlper not set.", 141); } $arrUserImage = getUserImage($user_id, $objDataHelper); if (count($arrUserImage) == 0) { $insertQuery = "Insert into user_images (user_id , image ) VALUES ('" . $user_id . "' , '" . $fileContents . "');"; $objDataHelper->putRecords("QR", $insertQuery); return true; } else { $updateQuery = "Update user_images set image='" . $fileContents . "' where user_id = '" . $user_id . "'"; $objDataHelper->putRecords("QR", $updateQuery); return true; } return false; } catch (Exception $e) { throw new Exception("profile.inc.php : updateUserImage : Could not find records : " . $e->getMessage(), 144); } }