|
|
@ -22,13 +22,13 @@ $metaScripts = [ |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// Init variables |
|
|
|
// Init variables |
|
|
|
$seq = false; |
|
|
|
|
|
|
|
$fullName = false; |
|
|
|
$fullName = false; |
|
|
|
$location = false; |
|
|
|
$location = false; |
|
|
|
$url = false; |
|
|
|
$url = false; |
|
|
|
$bitMessage = false; |
|
|
|
$bitMessage = false; |
|
|
|
$tox = false; |
|
|
|
$tox = false; |
|
|
|
$bio = false; |
|
|
|
$bio = false; |
|
|
|
|
|
|
|
$avatar = false; |
|
|
|
|
|
|
|
|
|
|
|
$errorFullName = false; |
|
|
|
$errorFullName = false; |
|
|
|
$errorLocation = false; |
|
|
|
$errorLocation = false; |
|
|
@ -41,7 +41,6 @@ $errorBio = false; |
|
|
|
if (isset($_POST) && !empty($_POST)) { |
|
|
|
if (isset($_POST) && !empty($_POST)) { |
|
|
|
|
|
|
|
|
|
|
|
// Prepare request |
|
|
|
// Prepare request |
|
|
|
$seq = isset($_POST['seq']) ? $_POST['seq'] : 0; |
|
|
|
|
|
|
|
$fullName = isset($_POST['fullName']) ? $_POST['fullName'] : ''; |
|
|
|
$fullName = isset($_POST['fullName']) ? $_POST['fullName'] : ''; |
|
|
|
$location = isset($_POST['location']) ? $_POST['location'] : ''; |
|
|
|
$location = isset($_POST['location']) ? $_POST['location'] : ''; |
|
|
|
$url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
|
|
$url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
|
@ -49,35 +48,76 @@ if (isset($_POST) && !empty($_POST)) { |
|
|
|
$tox = isset($_POST['tox']) ? $_POST['tox'] : ''; |
|
|
|
$tox = isset($_POST['tox']) ? $_POST['tox'] : ''; |
|
|
|
$bio = isset($_POST['bio']) ? $_POST['bio'] : ''; |
|
|
|
$bio = isset($_POST['bio']) ? $_POST['bio'] : ''; |
|
|
|
|
|
|
|
|
|
|
|
// Increase revision number |
|
|
|
|
|
|
|
$seq++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get current block number |
|
|
|
// Get current block number |
|
|
|
$blockId = $_modelBlock->getThisBlock(); |
|
|
|
$blockId = $_modelBlock->getThisBlock(); |
|
|
|
|
|
|
|
|
|
|
|
// Save revision to DHT |
|
|
|
// Avatar provided |
|
|
|
$userProfileVersions = $_twister->putDHT( $_SESSION['userName'], |
|
|
|
if (isset($_FILES['avatar']['tmp_name']) && getimagesize($_FILES['avatar']['tmp_name'])) { |
|
|
|
'profile', |
|
|
|
|
|
|
|
's', |
|
|
|
// Prepare image |
|
|
|
[ |
|
|
|
$image = new Imagick(); |
|
|
|
'fullname' => $fullName, |
|
|
|
|
|
|
|
'location' => $location, |
|
|
|
$image->readImage($_FILES['avatar']['tmp_name']); |
|
|
|
'url' => $url, |
|
|
|
$image->resizeImage(64, 64, 1, false); |
|
|
|
'bitmessage' => $bitMessage, |
|
|
|
$image->setImageFormat('jpeg'); |
|
|
|
'tox' => $tox, |
|
|
|
$image->setCompressionQuality(100); |
|
|
|
'bio' => $bio, |
|
|
|
|
|
|
|
], |
|
|
|
// Encode base 64 |
|
|
|
$_SESSION['userName'], |
|
|
|
$avatar = 'data:image/jpeg;base64,' . base64_encode($image->getImageBlob()); |
|
|
|
$seq); |
|
|
|
|
|
|
|
|
|
|
|
// Get avatar revision |
|
|
|
// Save revision to DB |
|
|
|
$avatarSeq = $_modelAvatar->getMaxSeq($_SESSION['userId']) + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save avatar revision to DHT |
|
|
|
|
|
|
|
$_twister->putDHT($_SESSION['userName'], |
|
|
|
|
|
|
|
'avatar', |
|
|
|
|
|
|
|
's', |
|
|
|
|
|
|
|
$avatar, |
|
|
|
|
|
|
|
$_SESSION['userName'], |
|
|
|
|
|
|
|
$avatarSeq); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save avatar revision to DB |
|
|
|
|
|
|
|
if (!$_modelAvatar->versionExists($_SESSION['userId'], |
|
|
|
|
|
|
|
$blockId, |
|
|
|
|
|
|
|
$avatarSeq)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$_modelAvatar->add( $_SESSION['userId'], |
|
|
|
|
|
|
|
$blockId, |
|
|
|
|
|
|
|
$avatarSeq, |
|
|
|
|
|
|
|
time(), |
|
|
|
|
|
|
|
$avatar); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update avatar cache |
|
|
|
|
|
|
|
$_memcache->set('api.user.avatar.' . $_SESSION['userName'], $avatar, MEMCACHE_COMPRESS, MEMCACHE_DHT_AVATAR_TIMEOUT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get profile revision |
|
|
|
|
|
|
|
$profileSeq = $_modelProfile->getMaxSeq($_SESSION['userId']) + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save profile revision to DHT |
|
|
|
|
|
|
|
$_twister->putDHT($_SESSION['userName'], |
|
|
|
|
|
|
|
'profile', |
|
|
|
|
|
|
|
's', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'fullname' => $fullName, |
|
|
|
|
|
|
|
'location' => $location, |
|
|
|
|
|
|
|
'url' => $url, |
|
|
|
|
|
|
|
'bitmessage' => $bitMessage, |
|
|
|
|
|
|
|
'tox' => $tox, |
|
|
|
|
|
|
|
'bio' => $bio, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
$_SESSION['userName'], |
|
|
|
|
|
|
|
$profileSeq); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save profile revision to DB |
|
|
|
if (!$_modelProfile->versionExists($_SESSION['userId'], |
|
|
|
if (!$_modelProfile->versionExists($_SESSION['userId'], |
|
|
|
$blockId, |
|
|
|
$blockId, |
|
|
|
$seq)) { |
|
|
|
$profileSeq)) { |
|
|
|
|
|
|
|
|
|
|
|
$_modelProfile->add($_SESSION['userId'], |
|
|
|
$_modelProfile->add($_SESSION['userId'], |
|
|
|
$blockId, |
|
|
|
$blockId, |
|
|
|
$seq, |
|
|
|
$profileSeq, |
|
|
|
time(), |
|
|
|
time(), |
|
|
|
$fullName, |
|
|
|
$fullName, |
|
|
|
$bio, |
|
|
|
$bio, |
|
|
@ -87,10 +127,10 @@ if (isset($_POST) && !empty($_POST)) { |
|
|
|
$tox); |
|
|
|
$tox); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update profile cache |
|
|
|
$_memcache->replace('api.user.profile.' . $_SESSION['userName'], |
|
|
|
$_memcache->replace('api.user.profile.' . $_SESSION['userName'], |
|
|
|
[ |
|
|
|
[ |
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
'seq' => $seq, |
|
|
|
|
|
|
|
'fullName' => $fullName, |
|
|
|
'fullName' => $fullName, |
|
|
|
'location' => $location, |
|
|
|
'location' => $location, |
|
|
|
'url' => $url, |
|
|
|
'url' => $url, |
|
|
@ -103,10 +143,56 @@ if (isset($_POST) && !empty($_POST)) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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'], |
|
|
|
|
|
|
|
$avatarVersion['p']['height'], |
|
|
|
|
|
|
|
$avatarVersion['p']['seq'])) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$_modelAvatar->add( $_SESSION['userId'], |
|
|
|
|
|
|
|
$avatarVersion['p']['height'], |
|
|
|
|
|
|
|
$avatarVersion['p']['seq'], |
|
|
|
|
|
|
|
$avatarVersion['p']['time'], |
|
|
|
|
|
|
|
$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 |
|
|
|
// Get profile details |
|
|
|
if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
|
|
$seq = $profile['seq']; |
|
|
|
|
|
|
|
$fullName = $profile['fullName']; |
|
|
|
$fullName = $profile['fullName']; |
|
|
|
$location = $profile['location']; |
|
|
|
$location = $profile['location']; |
|
|
|
$url = $profile['url']; |
|
|
|
$url = $profile['url']; |
|
|
@ -116,30 +202,26 @@ if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
|
|
} else if ($userProfileVersions = $_twister->getDHT($_SESSION['userName'], 'profile', 's')) { |
|
|
|
} else if ($userProfileVersions = $_twister->getDHT($_SESSION['userName'], 'profile', 's')) { |
|
|
|
|
|
|
|
|
|
|
|
// Check user exists |
|
|
|
// Add DHT version if not exists |
|
|
|
if ($userId = $_modelUser->getUserId($_SESSION['userName'])) { |
|
|
|
foreach ($userProfileVersions as $userProfileVersion) { |
|
|
|
|
|
|
|
|
|
|
|
// Add DHT version if not exists |
|
|
|
|
|
|
|
foreach ($userProfileVersions as $userProfileVersion) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$_modelProfile->versionExists($userId, |
|
|
|
if (!$_modelProfile->versionExists($_SESSION['userId'], |
|
|
|
$userProfileVersion['p']['height'], |
|
|
|
$userProfileVersion['p']['height'], |
|
|
|
$userProfileVersion['p']['seq'])) { |
|
|
|
$userProfileVersion['p']['seq'])) { |
|
|
|
|
|
|
|
|
|
|
|
$profile = $userProfileVersion['p']['v']; |
|
|
|
$profile = $userProfileVersion['p']['v']; |
|
|
|
|
|
|
|
|
|
|
|
$_modelProfile->add($userId, |
|
|
|
$_modelProfile->add($_SESSION['userId'], |
|
|
|
$userProfileVersion['p']['height'], |
|
|
|
$userProfileVersion['p']['height'], |
|
|
|
$userProfileVersion['p']['seq'], |
|
|
|
$userProfileVersion['p']['seq'], |
|
|
|
$userProfileVersion['p']['time'], |
|
|
|
$userProfileVersion['p']['time'], |
|
|
|
|
|
|
|
|
|
|
|
isset($profile['fullname']) ? $profile['fullname'] : '', |
|
|
|
isset($profile['fullname']) ? $profile['fullname'] : '', |
|
|
|
isset($profile['bio']) ? $profile['bio'] : '', |
|
|
|
isset($profile['bio']) ? $profile['bio'] : '', |
|
|
|
isset($profile['location']) ? $profile['location'] : '', |
|
|
|
isset($profile['location']) ? $profile['location'] : '', |
|
|
|
isset($profile['url']) ? $profile['url'] : '', |
|
|
|
isset($profile['url']) ? $profile['url'] : '', |
|
|
|
isset($profile['bitmessage']) ? $profile['bitmessage'] : '', |
|
|
|
isset($profile['bitmessage']) ? $profile['bitmessage'] : '', |
|
|
|
isset($profile['tox']) ? $profile['tox'] : ''); |
|
|
|
isset($profile['tox']) ? $profile['tox'] : ''); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,7 +230,6 @@ if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
|
|
|
|
|
|
|
|
$profile = [ |
|
|
|
$profile = [ |
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
'userName' => $_SESSION['userName'], |
|
|
|
'seq' => $profileInfo['seq'], |
|
|
|
|
|
|
|
'fullName' => $profileInfo['fullName'], |
|
|
|
'fullName' => $profileInfo['fullName'], |
|
|
|
'location' => $profileInfo['location'], |
|
|
|
'location' => $profileInfo['location'], |
|
|
|
'url' => $profileInfo['url'], |
|
|
|
'url' => $profileInfo['url'], |
|
|
@ -157,7 +238,6 @@ if ($profile = $_memcache->get('api.user.profile.' . $_SESSION['userName'])) { |
|
|
|
'bio' => $profileInfo['bio'], |
|
|
|
'bio' => $profileInfo['bio'], |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$seq = $profile['seq']; |
|
|
|
|
|
|
|
$fullName = $profile['fullName']; |
|
|
|
$fullName = $profile['fullName']; |
|
|
|
$location = $profile['location']; |
|
|
|
$location = $profile['location']; |
|
|
|
$url = $profile['url']; |
|
|
|
$url = $profile['url']; |
|
|
|