From 996108289c17796018e7afe7953526430e59d057 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:13:05 +0300 Subject: [PATCH] add fav games --- VKAPI/Handlers/Account.php | 2 +- VKAPI/Handlers/Users.php | 15 ++++++++++++++- Web/Models/Entities/User.php | 8 ++++++++ Web/Presenters/UserPresenter.php | 15 ++++++++------- Web/Presenters/templates/User/Edit.xml | 8 ++++++++ Web/Presenters/templates/User/View.xml | 4 ++++ Web/static/js/al_wall.js | 3 ++- install/sqls/00053-new-fields.sql | 1 + locales/en.strings | 1 + locales/ru.strings | 1 + 10 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 install/sqls/00053-new-fields.sql diff --git a/VKAPI/Handlers/Account.php b/VKAPI/Handlers/Account.php index c1f3ef23..3f25df35 100644 --- a/VKAPI/Handlers/Account.php +++ b/VKAPI/Handlers/Account.php @@ -269,7 +269,7 @@ final class Account extends VKAPIRequestHandler return 1; $entity = get_entity_by_id($owner_id); - if(!$entity || $entity->isDeleted()) + if(!$entity) return 0; if(!$entity->isBlacklistedBy($this->getUser())) diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index 7dc68f3b..bbb78a55 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -12,8 +12,14 @@ final class Users extends VKAPIRequestHandler if($authuser == NULL) $authuser = $this->getUser(); $users = new UsersRepo; - if($user_ids == "0") + if($user_ids == "0") { + if(!$authuser) { + return []; + } + $user_ids = (string) $authuser->getId(); + } + $usrs = explode(',', $user_ids); $response = array(); @@ -198,6 +204,13 @@ final class Users extends VKAPIRequestHandler $response[$i]->quotes = $usr->getFavoriteQuote(); break; + case "games": + if(!$canView) { + break; + } + + $response[$i]->games = $usr->getFavoriteGames(); + break; case "email": if(!$canView) { break; diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 61ea120b..43290424 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -415,6 +415,11 @@ class User extends RowModel return $this->getRecord()->fav_quote; } + function getFavoriteGames(): ?string + { + return $this->getRecord()->fav_games; + } + function getCity(): ?string { return $this->getRecord()->city; @@ -1432,6 +1437,9 @@ class User extends RowModel $res->blacklisted = (int)$user->isBlacklistedBy($this); break; + case "games": + $res->games = $this->getFavoriteGames(); + break; } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index f238e381..556d5e8c 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -251,13 +251,14 @@ final class UserPresenter extends OpenVKPresenter else $user->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website); } elseif($_GET['act'] === "interests") { - $user->setInterests(empty($this->postParam("interests")) ? NULL : ovk_proc_strtr($this->postParam("interests"), 300)); - $user->setFav_Music(empty($this->postParam("fav_music")) ? NULL : ovk_proc_strtr($this->postParam("fav_music"), 300)); - $user->setFav_Films(empty($this->postParam("fav_films")) ? NULL : ovk_proc_strtr($this->postParam("fav_films"), 300)); - $user->setFav_Shows(empty($this->postParam("fav_shows")) ? NULL : ovk_proc_strtr($this->postParam("fav_shows"), 300)); - $user->setFav_Books(empty($this->postParam("fav_books")) ? NULL : ovk_proc_strtr($this->postParam("fav_books"), 300)); - $user->setFav_Quote(empty($this->postParam("fav_quote")) ? NULL : ovk_proc_strtr($this->postParam("fav_quote"), 300)); - $user->setAbout(empty($this->postParam("about")) ? NULL : ovk_proc_strtr($this->postParam("about"), 300)); + $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)); + $user->setFav_Shows(empty($this->postParam("fav_shows")) ? NULL : ovk_proc_strtr($this->postParam("fav_shows"), 1000)); + $user->setFav_Books(empty($this->postParam("fav_books")) ? NULL : ovk_proc_strtr($this->postParam("fav_books"), 1000)); + $user->setFav_Quote(empty($this->postParam("fav_quote")) ? NULL : ovk_proc_strtr($this->postParam("fav_quote"), 1000)); + $user->setFav_Games(empty($this->postParam("fav_games")) ? NULL : ovk_proc_strtr($this->postParam("fav_games"), 1000)); + $user->setAbout(empty($this->postParam("about")) ? NULL : ovk_proc_strtr($this->postParam("about"), 1000)); } elseif($_GET["act"] === "backdrop") { if($this->postParam("subact") === "remove") { $user->unsetBackDropPictures(); diff --git a/Web/Presenters/templates/User/Edit.xml b/Web/Presenters/templates/User/Edit.xml index 8bea7f0c..b0eea51f 100644 --- a/Web/Presenters/templates/User/Edit.xml +++ b/Web/Presenters/templates/User/Edit.xml @@ -294,6 +294,14 @@ + + + {_favorite_games}: + + + + + {_information_about}: diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index cbcb1f1f..98c12cb1 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -567,6 +567,10 @@ {_favorite_quotes}: {$user->getFavoriteQuote()} + + {_favorite_games}: + {$user->getFavoriteGames()} + {_information_about}: {$user->getDescription()} diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index a20b0d9d..58ba9437 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -924,7 +924,8 @@ u(document).on("click", "#editPost", async (e) => { const target = u(e.target) const post = target.closest("table") const content = post.find(".post-content") - const edit_place = post.find('.post-edit') + const edit_place_l = post.find('.post-edit') + const edit_place = u(edit_place_l.first()) const id = post.attr('data-id').split('_') let type = 'post' diff --git a/install/sqls/00053-new-fields.sql b/install/sqls/00053-new-fields.sql new file mode 100644 index 00000000..318cba71 --- /dev/null +++ b/install/sqls/00053-new-fields.sql @@ -0,0 +1 @@ +ALTER TABLE `profiles` ADD `fav_games` MEDIUMTEXT NULL DEFAULT NULL AFTER `fav_quote`; diff --git a/locales/en.strings b/locales/en.strings index ac328308..e7a3d1d6 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -152,6 +152,7 @@ "favorite_shows" = "Favorite TV-shows"; "favorite_books" = "Favorite books"; "favorite_quotes" = "Favorite quotes"; +"favorite_games" = "Favorite games"; "information_about" = "About"; "updated_at" = "Updated at $1"; diff --git a/locales/ru.strings b/locales/ru.strings index 3f036473..4dc068ff 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -136,6 +136,7 @@ "favorite_shows" = "Любимые ТВ-шоу"; "favorite_books" = "Любимые книги"; "favorite_quotes" = "Любимые цитаты"; +"favorite_games" = "Любимые игры"; "information_about" = "О себе"; "updated_at" = "Обновлено $1"; "user_banned" = "К сожалению, нам пришлось заблокировать страницу пользователя $1.";