Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions VKAPI/Handlers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ public function get(string $user_ids = "0", string $fields = "", int $offset = 0
$response[$i]->bdate = null;
}
break;
case 'personal':
$response[$i]->personal = (object) [
'political' => $usr->getPoliticalViews(),
'langs' => [], // FIXME: not implemented
'inspired_by' => $usr->getInspires(),
'people_main' => $usr->getMainInPeople(),
'life_main' => $usr->getMainInLife(),
'smoking' => $usr->getViewsOnSmoking(),
'alcohol' => $usr->getViewsOnAlcohol(),
];
break;
}
}

Expand Down
92 changes: 92 additions & 0 deletions Web/Models/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class User extends RowModel
public const NSFW_TOLERANT = 1;
public const NSFW_FULL_TOLERANT = 2;


public const PREFERENCES_COUNTS = [
'politViews' => 10,
'mainInLife' => 9,
'mainInPeople' => 7,
'viewsOnSubstances' => 6,
];

/* aggressive caching */
private $_avatarAlbum = null;
private $_avatarPhoto = false; // false - not resolved, null - no avatar
Expand Down Expand Up @@ -414,6 +422,36 @@ public function getPoliticalViews(): int
return $this->getRecord()->polit_views;
}

public function getWorldview(): string
{
return $this->getRecord()->worldview;
}

public function getMainInLife(): int
{
return $this->getRecord()->main_in_life;
}

public function getMainInPeople(): int
{
return $this->getRecord()->main_in_people;
}

public function getViewsOnSmoking(): int
{
return $this->getRecord()->views_on_smoking;
}

public function getViewsOnAlcohol(): int
{
return $this->getRecord()->views_on_alcohol;
}

public function getInspires(): string
{
return $this->getRecord()->inspires;
}

public function getMaritalStatus(): int
{
return $this->getRecord()->marital_status;
Expand Down Expand Up @@ -530,6 +568,60 @@ public function getAdditionalFields(bool $split = false): array
return $result;
}

public function getPersonalInfo()
{
$info = [];
if ($this->getPoliticalViews() > 0) {
$info[] = [
'label' => tr('politViews'),
'value' => tr('politViews_' . $this->getPoliticalViews()),
];
}
if ($this->getWorldview() != '') {
$info[] = [
'label' => tr('worldview'),
'value' => $this->getWorldview(),
];
}

if ($this->getMainInLife() > 0) {
$info[] = [
'label' => tr('mainInLife'),
'value' => tr('mainInLife_' . $this->getMainInLife()),
];
}

if ($this->getMainInPeople() > 0) {
$info[] = [
'label' => tr('mainInPeople'),
'value' => tr('mainInPeople_' . $this->getMainInPeople()),
];
}

if ($this->getViewsOnSmoking() > 0) {
$info[] = [
'label' => tr('viewsOnSmoking'),
'value' => tr('viewsOnSubstances_' . $this->getViewsOnSmoking()),
];
}

if ($this->getViewsOnAlcohol() > 0) {
$info[] = [
'label' => tr('viewsOnAlcohol'),
'value' => tr('viewsOnSubstances_' . $this->getViewsOnAlcohol()),
];
}

if ($this->getInspires() != '') {
$info[] = [
'label' => tr('inspires'),
'value' => $this->getInspires(),
];
}

return $info;
}

public function getNotificationOffset(): int
{
return $this->getRecord()->notification_offset;
Expand Down
51 changes: 35 additions & 16 deletions Web/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Nette\InvalidStateException;
use openvk\Web\Util\Sms;
use openvk\Web\Themes\Themepacks;
use openvk\Web\Models\Entities\{Photo, Post, EmailChangeVerification};
use openvk\Web\Models\Entities\{Photo, Post, EmailChangeVerification, User};
use openvk\Web\Models\Entities\Notifications\{CoinsTransferNotification, RatingUpNotification};
use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Videos, Notes, Vouchers, EmailChangeVerifications, Audios, Faves};
use openvk\Web\Models\Exceptions\InvalidUserNameException;
Expand Down Expand Up @@ -195,11 +195,20 @@ public function renderEdit(): void
$this->notFound();
}



$act = in_array($this->queryParam("act"), [
"main", "contacts", "interests", "avatar", "backdrop", "additional", "personal",
]) ? $this->queryParam("act")
: "main";

$this->template->mode = $act;

$user = $this->users->get($id);
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$this->willExecuteWriteAction($_GET['act'] === "status");

if ($_GET['act'] === "main" || $_GET['act'] == null) {
if ($act === "main" || $act == null) {
try {
$user->setFirst_Name(empty($this->postParam("first_name")) ? $user->getFirstName() : $this->postParam("first_name"));
$user->setLast_Name(empty($this->postParam("last_name")) ? "" : $this->postParam("last_name"));
Expand Down Expand Up @@ -239,10 +248,6 @@ public function renderEdit(): void
}
}

if ($this->postParam("politViews") <= 9 && $this->postParam("politViews") >= 0) {
$user->setPolit_Views($this->postParam("politViews"));
}

if ($this->postParam("pronouns") <= 2 && $this->postParam("pronouns") >= 0) {
switch ($this->postParam("pronouns")) {
case '0':
Expand All @@ -269,7 +274,26 @@ public function renderEdit(): void
$this->flashFail("err", tr("error_segmentation"), "котлетки: Remote err!");
}
}
} elseif ($_GET['act'] === "contacts") {
} elseif ($act === "personal") {

if ($this->postParam("politViews") < User::PREFERENCES_COUNTS['politViews'] && $this->postParam("politViews") >= 0) {
$user->setPolit_Views($this->postParam("politViews"));
}
$user->setWorldview(mb_substr($this->postParam("worldview") ?? "", 0, 256));
if ($this->postParam("mainInLife") < User::PREFERENCES_COUNTS['mainInLife'] && $this->postParam("mainInLife") >= 0) {
$user->setMain_In_Life($this->postParam("mainInLife"));
}
if ($this->postParam("mainInPeople") < User::PREFERENCES_COUNTS['mainInPeople'] && $this->postParam("mainInPeople") >= 0) {
$user->setMain_In_People($this->postParam("mainInPeople"));
}
if ($this->postParam("viewsOnSmoking") < User::PREFERENCES_COUNTS['viewsOnSubstances'] && $this->postParam("viewsOnSmoking") >= 0) {
$user->setViews_On_Smoking($this->postParam("viewsOnSmoking"));
}
if ($this->postParam("viewsOnAlcohol") < User::PREFERENCES_COUNTS['viewsOnSubstances'] && $this->postParam("viewsOnAlcohol") >= 0) {
$user->setViews_On_Alcohol($this->postParam("viewsOnAlcohol"));
}
$user->setInspires(mb_substr($this->postParam("inspires") ?? "", 0, 256));
} elseif ($act === "contacts") {
if (empty($this->postParam("email_contact")) || Validator::i()->emailValid($this->postParam("email_contact"))) {
$user->setEmail_Contact(empty($this->postParam("email_contact")) ? null : $this->postParam("email_contact"));
} else {
Expand All @@ -296,7 +320,7 @@ public function renderEdit(): void
} else {
$user->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website);
}
} elseif ($_GET['act'] === "interests") {
} elseif ($act === "interests") {
$user->setInterests(empty($this->postParam("interests")) ? null : ovk_proc_strtr($this->postParam("interests"), 1000));
$user->setFav_Music(empty($this->postParam("fav_music")) ? null : ovk_proc_strtr($this->postParam("fav_music"), 1000));
$user->setFav_Films(empty($this->postParam("fav_films")) ? null : ovk_proc_strtr($this->postParam("fav_films"), 1000));
Expand Down Expand Up @@ -332,7 +356,7 @@ public function renderEdit(): void
$user->setBackDropPictures($pic1, $pic2);
$user->save();
$this->flashFail("succ", tr("backdrop_succ"), tr("backdrop_succ_desc"));
} elseif ($_GET['act'] === "status") {
} elseif ($act === "status") {
if (mb_strlen($this->postParam("status")) > 255) {
$statusLength = (string) mb_strlen($this->postParam("status"));
$this->flashFail("err", tr("error"), tr("error_status_too_long", $statusLength), null, true);
Expand All @@ -345,7 +369,7 @@ public function renderEdit(): void
$this->returnJson([
"success" => true,
]);
} elseif ($_GET['act'] === "additional") {
} elseif ($act === "additional") {
$maxAddFields = ovkGetQuirk("users.max-fields");
$items = [];

Expand Down Expand Up @@ -382,7 +406,7 @@ public function renderEdit(): void
}

try {
if ($_GET['act'] !== "additional") {
if ($act !== "additional") {
$user->save();
}
} catch (\PDOException $ex) {
Expand All @@ -396,11 +420,6 @@ public function renderEdit(): void
$this->flash("succ", tr("changes_saved"), tr("changes_saved_comment"));
}

$this->template->mode = in_array($this->queryParam("act"), [
"main", "contacts", "interests", "avatar", "backdrop", "additional",
]) ? $this->queryParam("act")
: "main";

$this->template->user = $user;
}

Expand Down
112 changes: 100 additions & 12 deletions Web/Presenters/templates/User/Edit.latte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{var $isAdditional = $mode === 'additional'}
{var $isAvatar = $mode === 'avatar'}
{var $isBackDrop = $mode === 'backdrop'}
{var $isPersonal = $mode === 'personal'}

<div n:if="$user->hasPendingNumberChange()" class="msg">
<b>Подтверждение номера телефона</b><br/>
Expand All @@ -35,12 +36,16 @@
<div n:attr="id => ($isAdditional ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isAdditional ? 'act_tab_a' : 'ki')" href="/edit?act=additional">{_additional}</a>
</div>
<div n:attr="id => ($isPersonal ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isPersonal ? 'act_tab_a' : 'ki')" href="/edit?act=personal">{_personal}</a>
</div>
<div n:attr="id => ($isAvatar ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isAvatar ? 'act_tab_a' : 'ki')" href="/edit?act=avatar">{_avatar}</a>
</div>
<div n:attr="id => ($isBackDrop ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isBackDrop ? 'act_tab_a' : 'ki')" href="/edit?act=backdrop">{_backdrop_short}</a>
</div>

</div>

<div class="container_gray">
Expand Down Expand Up @@ -129,18 +134,6 @@
n:attr="value => $user->getMaritalStatusUser() ? $user->getMaritalStatusUser()->getURL(true) : ''" />
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_politViews}: </span>
</td>
<td>
<select name="politViews">
<option n:foreach="range(0, 9) as $i" n:attr="selected => ($user->getPoliticalViews() == $i)" value="{$i}">
{tr("politViews_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_pronouns}: </span>
Expand Down Expand Up @@ -327,6 +320,101 @@
</table>
</form>

{elseif $isPersonal}

<h4>{_personal}</h4>
<form action="/edit?act=personal" method="POST" enctype="multipart/form-data">
<table cellspacing="7" cellpadding="0" width="60%" border="0" align="center">
<tbody>
<tr>
<td width="120" valign="top">
<span class="nobold">{_politViews}: </span>
</td>
<td>
<select name="politViews">
<option n:foreach="range(0, $user::PREFERENCES_COUNTS['politViews'] - 1) as $i" n:attr="selected => ($user->getPoliticalViews() == $i)" value="{$i}">
{tr("politViews_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_worldview}: </span>
</td>
<td>
<input type="text" name="worldview" value="{$user->getWorldview()}" maxlength="256" />
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_mainInLife}: </span>
</td>
<td>
<select name="mainInLife">
<option n:foreach="range(0, $user::PREFERENCES_COUNTS['mainInLife'] - 1) as $i" n:attr="selected => ($user->getMainInLife() == $i)" value="{$i}">
{tr("mainInLife_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_mainInPeople}: </span>
</td>
<td>
<select name="mainInPeople">
<option n:foreach="range(0, $user::PREFERENCES_COUNTS['mainInPeople'] - 1) as $i" n:attr="selected => ($user->getMainInPeople() == $i)" value="{$i}">
{tr("mainInPeople_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_viewsOnSmoking}: </span>
</td>
<td>
<select name="viewsOnSmoking">
<option n:foreach="range(0, $user::PREFERENCES_COUNTS['viewsOnSubstances'] - 1) as $i" n:attr="selected => ($user->getViewsOnSmoking() == $i)" value="{$i}">
{tr("viewsOnSubstances_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_viewsOnAlcohol}: </span>
</td>
<td>
<select name="viewsOnAlcohol">
<option n:foreach="range(0, $user::PREFERENCES_COUNTS['viewsOnSubstances'] - 1) as $i" n:attr="selected => ($user->getViewsOnAlcohol() == $i)" value="{$i}">
{tr("viewsOnSubstances_" . $i)}
</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_inspires}: </span>
</td>
<td>
<input type="text" name="inspires" value="{$user->getInspires()}" maxlength="256" />
</td>
</tr>
<tr>
<td>

</td>
<td>
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" value="{_save}" class="button" />
</td>
</tr>
</tbody>
</table>
</form>

{elseif $isAvatar}

<h4>{_profile_picture}</h4>
Expand Down
Loading
Loading