|
|
|
@ -22,37 +22,28 @@ $metaScripts = [
@@ -22,37 +22,28 @@ $metaScripts = [
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Init variables |
|
|
|
|
$fullName = false; |
|
|
|
|
$location = false; |
|
|
|
|
$url = false; |
|
|
|
|
$bitMessage = false; |
|
|
|
|
$tox = false; |
|
|
|
|
$bio = false; |
|
|
|
|
$avatar = false; |
|
|
|
|
$successMessage = false; |
|
|
|
|
|
|
|
|
|
$errorFullName = false; |
|
|
|
|
$errorLocation = false; |
|
|
|
|
$errorURL = false; |
|
|
|
|
$errorBitMessage = false; |
|
|
|
|
$errorTOX = false; |
|
|
|
|
$errorBio = false; |
|
|
|
|
/* |
|
|
|
|
* Process profile update request |
|
|
|
|
* |
|
|
|
|
* */ |
|
|
|
|
|
|
|
|
|
// Save profile details |
|
|
|
|
if (isset($_POST) && !empty($_POST)) { |
|
|
|
|
|
|
|
|
|
// Prepare request |
|
|
|
|
$fullName = isset($_POST['fullName']) ? Filter::string($_POST['fullName']) : ''; |
|
|
|
|
$location = isset($_POST['location']) ? Filter::string($_POST['location']) : ''; |
|
|
|
|
$url = isset($_POST['url']) ? Filter::string($_POST['url']) : ''; |
|
|
|
|
$bitMessage = isset($_POST['bitMessage']) ? Filter::string($_POST['bitMessage']) : ''; |
|
|
|
|
$tox = isset($_POST['tox']) ? Filter::string($_POST['tox']) : ''; |
|
|
|
|
$bio = isset($_POST['bio']) ? Filter::string($_POST['bio']) : ''; |
|
|
|
|
// Filter form data |
|
|
|
|
$fullName = isset($_POST['fullName']) ? Filter::fullName($_POST['fullName']) : ''; |
|
|
|
|
$location = isset($_POST['location']) ? Filter::location($_POST['location']) : ''; |
|
|
|
|
$url = isset($_POST['url']) ? Filter::url($_POST['url']) : ''; |
|
|
|
|
$bitMessage = isset($_POST['bitMessage']) ? Filter::bitMessage($_POST['bitMessage']) : ''; |
|
|
|
|
$tox = isset($_POST['tox']) ? Filter::tox($_POST['tox']) : ''; |
|
|
|
|
$bio = isset($_POST['bio']) ? Filter::bio($_POST['bio']) : ''; |
|
|
|
|
|
|
|
|
|
// Get current block number |
|
|
|
|
$blockId = $_modelBlock->getThisBlock(); |
|
|
|
|
|
|
|
|
|
// Avatar provided |
|
|
|
|
if (isset($_FILES['avatar']['tmp_name']) && file_exists($_FILES['avatar']['tmp_name']) && getimagesize($_FILES['avatar']['tmp_name'])) { |
|
|
|
|
if (isset($_FILES['avatar']['tmp_name']) && file_exists($_FILES['avatar']['tmp_name']) && @getimagesize($_FILES['avatar']['tmp_name'])) { |
|
|
|
|
|
|
|
|
|
// Prepare image |
|
|
|
|
$image = new Imagick(); |
|
|
|
@ -135,131 +126,23 @@ if (isset($_POST) && !empty($_POST)) {
@@ -135,131 +126,23 @@ if (isset($_POST) && !empty($_POST)) {
|
|
|
|
|
$url, |
|
|
|
|
$bitMessage, |
|
|
|
|
$tox); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update profile cache |
|
|
|
|
$_memcache->replace('api.user.profile.' . $_SESSION['userName'], |
|
|
|
|
[ |
|
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
|
'fullName' => $fullName, |
|
|
|
|
'location' => $location, |
|
|
|
|
'url' => $url, |
|
|
|
|
'bitMessage' => $bitMessage, |
|
|
|
|
'tox' => $tox, |
|
|
|
|
'bio' => $bio, |
|
|
|
|
], |
|
|
|
|
MEMCACHE_COMPRESS, |
|
|
|
|
MEMCACHE_DHT_PROFILE_TIMEOUT); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get avatar details |
|
|
|
|
if ($userAvatar = $_memcache->get('api.user.avatar.' . $_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
$avatar = $userAvatar; |
|
|
|
|
|
|
|
|
|
} else if ($avatarVersions = $_twister->getDHT($_SESSION['userName'], 'avatar', 's')) { |
|
|
|
|
|
|
|
|
|
// Add DHT version if not exists |
|
|
|
|
foreach ($avatarVersions as $avatarVersion) { |
|
|
|
|
|
|
|
|
|
if (!$_modelAvatar->versionExists($_SESSION['userId'], |
|
|
|
|
Filter::int($avatarVersion['p']['height']), |
|
|
|
|
Filter::int($avatarVersion['p']['seq']))) { |
|
|
|
|
|
|
|
|
|
$_modelAvatar->add( $_SESSION['userId'], |
|
|
|
|
Filter::int($avatarVersion['p']['height']), |
|
|
|
|
Filter::int($avatarVersion['p']['seq']), |
|
|
|
|
Filter::int($avatarVersion['p']['time']), |
|
|
|
|
Filter::string($avatarVersion['p']['v'])); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get latest version available |
|
|
|
|
if ($avatarInfo = $_modelAvatar->get($_SESSION['userId'])) { |
|
|
|
|
|
|
|
|
|
$avatar = $avatarInfo['data']; |
|
|
|
|
|
|
|
|
|
$_memcache->set('api.user.avatar.' . $_SESSION['userName'], $avatarInfo['data'], MEMCACHE_COMPRESS, MEMCACHE_DHT_AVATAR_TIMEOUT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Generate identity icon |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
$fileName = md5($_SESSION['userName']); |
|
|
|
|
$filePath = PROJECT_DIR . '/cache/image/' . $fileName . '.jpeg'; |
|
|
|
|
|
|
|
|
|
if (!file_exists($filePath)) { |
|
|
|
|
|
|
|
|
|
$icon = new Icon(); |
|
|
|
|
$image = $icon->generateImageResource($fileName, 42, 42, false); |
|
|
|
|
|
|
|
|
|
file_put_contents($filePath, $image); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$avatar = sprintf('data:image/jpeg;base64,%s', base64_encode(file_get_contents($filePath))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get profile details from cache |
|
|
|
|
if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
$fullName = $profile['fullName']; |
|
|
|
|
$location = $profile['location']; |
|
|
|
|
$url = $profile['url']; |
|
|
|
|
$bitMessage = $profile['bitMessage']; |
|
|
|
|
$tox = $profile['tox']; |
|
|
|
|
$bio = $profile['bio']; |
|
|
|
|
|
|
|
|
|
// Get profile details from DHT |
|
|
|
|
} else if ($userProfileVersions = $_twister->getDHT($_SESSION['userName'], 'profile', 's')) { |
|
|
|
|
|
|
|
|
|
// Add DHT version if not exists |
|
|
|
|
foreach ($userProfileVersions as $userProfileVersion) { |
|
|
|
|
|
|
|
|
|
if (!$_modelProfile->versionExists($_SESSION['userId'], |
|
|
|
|
Filter::int($userProfileVersion['p']['height']), |
|
|
|
|
Filter::int($userProfileVersion['p']['seq']))) { |
|
|
|
|
|
|
|
|
|
if (isset($userProfileVersion['p']['v'])) { |
|
|
|
|
|
|
|
|
|
$profile = $userProfileVersion['p']['v']; |
|
|
|
|
|
|
|
|
|
$_modelProfile->add($_SESSION['userId'], |
|
|
|
|
Filter::int($userProfileVersion['p']['height']), |
|
|
|
|
Filter::int($userProfileVersion['p']['seq']), |
|
|
|
|
Filter::int($userProfileVersion['p']['time']), |
|
|
|
|
|
|
|
|
|
isset($profile['fullname']) ? Filter::string($profile['fullname']) : '', |
|
|
|
|
isset($profile['bio']) ? Filter::string($profile['bio']) : '', |
|
|
|
|
isset($profile['location']) ? Filter::string($profile['location']) : '', |
|
|
|
|
isset($profile['url']) ? Filter::string($profile['url']) : '', |
|
|
|
|
isset($profile['bitmessage']) ? Filter::string($profile['bitmessage']) : '', |
|
|
|
|
isset($profile['tox']) ? Filter::string($profile['tox']) : ''); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get latest version available |
|
|
|
|
if ($profileInfo = $_modelProfile->get($_SESSION['userId'])) { |
|
|
|
|
|
|
|
|
|
$profile = [ |
|
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
|
'fullName' => $profileInfo['fullName'], |
|
|
|
|
'location' => $profileInfo['location'], |
|
|
|
|
'url' => $profileInfo['url'], |
|
|
|
|
'bitMessage' => $profileInfo['bitMessage'], |
|
|
|
|
'tox' => $profileInfo['tox'], |
|
|
|
|
'bio' => $profileInfo['bio'], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$fullName = $profile['fullName']; |
|
|
|
|
$location = $profile['location']; |
|
|
|
|
$url = $profile['url']; |
|
|
|
|
$bitMessage = $profile['bitMessage']; |
|
|
|
|
$tox = $profile['tox']; |
|
|
|
|
$bio = $profile['bio']; |
|
|
|
|
|
|
|
|
|
$_memcache->set('api.user.profile.' . $_SESSION['userName'], $profile, MEMCACHE_COMPRESS, MEMCACHE_DHT_PROFILE_TIMEOUT); |
|
|
|
|
// Update profile cache |
|
|
|
|
$_memcache->replace('api.user.profile.' . $_SESSION['userName'], |
|
|
|
|
[ |
|
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
|
'fullName' => $fullName, |
|
|
|
|
'location' => $location, |
|
|
|
|
'url' => $url, |
|
|
|
|
'bitMessage' => $bitMessage, |
|
|
|
|
'tox' => $tox, |
|
|
|
|
'bio' => Format::bio($bio), |
|
|
|
|
], |
|
|
|
|
MEMCACHE_COMPRESS, |
|
|
|
|
MEMCACHE_DHT_PROFILE_TIMEOUT); |
|
|
|
|
|
|
|
|
|
$successMessage = _('Profile successfully saved!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|