nativegallery-weryskok/app/Controllers/Api/Profile/Update.php

58 lines
1.6 KiB
PHP
Raw Normal View History

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) {
$dataArray[$paramKey]['value'] = strip_tags($value, ['br']);
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]);
}
}