2024-07-05 15:03:35 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controllers\Api\Profile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
|
|
|
use App\Models\{User, Vote};
|
|
|
|
use App\Services\Upload as UploadPhoto;
|
|
|
|
|
|
|
|
class Update
|
|
|
|
{
|
|
|
|
private $photourl;
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
|
|
|
|
$postData = $_POST;
|
|
|
|
$dataArray = [];
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($postData as $key => $value) {
|
|
|
|
if (strpos($key, 'about') === 0) {
|
|
|
|
$paramKey = $key;
|
|
|
|
|
|
|
|
if (!isset($dataArray[$paramKey])) {
|
|
|
|
$dataArray[$paramKey] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strpos($key, 'OnMain') === false) {
|
2024-07-19 10:18:55 +03:00
|
|
|
$dataArray[$paramKey]['value'] = htmlentities($value);
|
2024-07-05 15:03:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = new \App\Models\User(Auth::userid());
|
|
|
|
$content = json_decode($user->i('content'), true);
|
|
|
|
$existingArray = array_replace_recursive($content, $dataArray);
|
|
|
|
|
|
|
|
$newJson = json_encode($existingArray, JSON_PRETTY_PRINT);
|
|
|
|
if (isset($_FILES['userphoto'])) {
|
2024-07-10 12:30:10 +03:00
|
|
|
$upload = new UploadPhoto($_FILES['userphoto'], '/cdn/img/');
|
2024-07-05 15:03:35 +03:00
|
|
|
if ($upload->getType() !== null) {
|
2024-07-10 12:30:10 +03:00
|
|
|
|
2024-07-05 15:03:35 +03:00
|
|
|
$this->photourl = $upload->getSrc();
|
|
|
|
} else {
|
2024-07-10 12:30:10 +03:00
|
|
|
|
2024-07-05 15:03:35 +03:00
|
|
|
$this->photourl = $user->i('photourl');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->photourl = $user->i('photourl');
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::query('UPDATE users SET content=:c, photourl=:ph WHERE id=:id', [':id' => Auth::userid(), ':c' => $newJson, ':ph'=>$this->photourl]);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|