mirror of
https://github.com/openvk/openvk
synced 2024-12-22 08:31:18 +03:00
feat(wall): add new route /{type}/{id}/likes
This commit is contained in:
parent
14110c409a
commit
cf0b4be3fb
8 changed files with 114 additions and 60 deletions
|
@ -28,6 +28,11 @@ class Comment extends Post
|
|||
return $entity;
|
||||
}
|
||||
|
||||
function getPageURL(): string
|
||||
{
|
||||
return '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* May return fake owner (group), if flags are [1, (*)]
|
||||
*
|
||||
|
|
|
@ -336,6 +336,11 @@ class Post extends Postable
|
|||
{
|
||||
return $this->getRecord()->suggested;
|
||||
}
|
||||
|
||||
function getPageURL(): string
|
||||
{
|
||||
return "/wall".$this->getPrettyId();
|
||||
}
|
||||
|
||||
function toNotifApiStruct()
|
||||
{
|
||||
|
|
|
@ -309,6 +309,11 @@ class Video extends Media
|
|||
);
|
||||
}
|
||||
|
||||
function getPageURL(): string
|
||||
{
|
||||
return "/video".$this->getPrettyId();
|
||||
}
|
||||
|
||||
function canBeViewedBy(?User $user = NULL): bool
|
||||
{
|
||||
if($this->isDeleted() || $this->getOwner()->isDeleted()) {
|
||||
|
|
|
@ -549,66 +549,6 @@ final class WallPresenter extends OpenVKPresenter
|
|||
$this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment"));
|
||||
}
|
||||
|
||||
function renderEdit()
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] !== "POST")
|
||||
$this->redirect("/id0");
|
||||
|
||||
if($this->postParam("type") == "post")
|
||||
$post = $this->posts->get((int)$this->postParam("postid"));
|
||||
else
|
||||
$post = (new Comments)->get((int)$this->postParam("postid"));
|
||||
|
||||
if(!$post || $post->isDeleted())
|
||||
$this->returnJson(["error" => "Invalid post"]);
|
||||
|
||||
if(!$post->canBeEditedBy($this->user->identity))
|
||||
$this->returnJson(["error" => "Access denied"]);
|
||||
|
||||
$attachmentsCount = sizeof(iterator_to_array($post->getChildren()));
|
||||
|
||||
if(empty($this->postParam("newContent")) && $attachmentsCount < 1)
|
||||
$this->returnJson(["error" => "Empty post"]);
|
||||
|
||||
$post->setEdited(time());
|
||||
|
||||
try {
|
||||
$post->setContent($this->postParam("newContent"));
|
||||
} catch(\LengthException $e) {
|
||||
$this->returnJson(["error" => $e->getMessage()]);
|
||||
}
|
||||
|
||||
if($this->postParam("type") === "post") {
|
||||
$post->setNsfw($this->postParam("nsfw") == "true");
|
||||
$flags = 0;
|
||||
|
||||
if($post->getTargetWall() < 0 && $post->getWallOwner()->canBeModifiedBy($this->user->identity)) {
|
||||
if($this->postParam("fromgroup") == "true") {
|
||||
$flags |= 0b10000000;
|
||||
$post->setFlags($flags);
|
||||
} else
|
||||
$post->setFlags($flags);
|
||||
}
|
||||
}
|
||||
|
||||
$post->save(true);
|
||||
|
||||
$this->returnJson(["error" => "no",
|
||||
"new_content" => $post->getText(),
|
||||
"new_edited" => (string)$post->getEditTime(),
|
||||
"nsfw" => $this->postParam("type") === "post" ? (int)$post->isExplicit() : 0,
|
||||
"from_group" => $this->postParam("type") === "post" && $post->getTargetWall() < 0 ?
|
||||
((int)$post->isPostedOnBehalfOfGroup()) : "false",
|
||||
"new_text" => $post->getText(false),
|
||||
"author" => [
|
||||
"name" => $post->getOwner()->getCanonicalName(),
|
||||
"avatar" => $post->getOwner()->getAvatarUrl()
|
||||
]]);
|
||||
}
|
||||
|
||||
function renderAccept() {
|
||||
$this->assertUserLoggedIn();
|
||||
$this->willExecuteWriteAction(true);
|
||||
|
@ -697,4 +637,44 @@ final class WallPresenter extends OpenVKPresenter
|
|||
"new_count" => (new Posts)->getSuggestedPostsCount($post->getWallOwner()->getId())
|
||||
]);
|
||||
}
|
||||
|
||||
function renderLikers(string $type, int $owner_id, int $item_id)
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
||||
$item = NULL;
|
||||
$display_name = $type;
|
||||
switch($type) {
|
||||
default:
|
||||
$this->notFound();
|
||||
break;
|
||||
case 'wall':
|
||||
$item = $this->posts->getPostById($owner_id, $item_id);
|
||||
$display_name = 'post';
|
||||
break;
|
||||
case 'comment':
|
||||
$item = (new \openvk\Web\Models\Repositories\Comments)->get($item_id);
|
||||
break;
|
||||
case 'photo':
|
||||
$item = (new \openvk\Web\Models\Repositories\Photos)->getByOwnerAndVID($owner_id, $item_id);
|
||||
break;
|
||||
case 'video':
|
||||
$item = (new \openvk\Web\Models\Repositories\Videos)->getByOwnerAndVID($owner_id, $item_id);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$item || $item->isDeleted() || !$item->canBeViewedBy($this->user->identity))
|
||||
$this->notFound();
|
||||
|
||||
$page = (int)($this->queryParam('p') ?? 1);
|
||||
$count = $item->getLikesCount();
|
||||
$likers = iterator_to_array($item->getLikers($page, OPENVK_DEFAULT_PER_PAGE));
|
||||
|
||||
$this->template->item = $item;
|
||||
$this->template->type = $display_name;
|
||||
$this->template->iterator = $likers;
|
||||
$this->template->count = $count;
|
||||
$this->template->page = $page;
|
||||
$this->template->perPage = OPENVK_DEFAULT_PER_PAGE;
|
||||
}
|
||||
}
|
||||
|
|
51
Web/Presenters/templates/Wall/Likers.xml
Normal file
51
Web/Presenters/templates/Wall/Likers.xml
Normal file
|
@ -0,0 +1,51 @@
|
|||
{extends "../@listView.xml"}
|
||||
|
||||
{block title}
|
||||
{_likers_list}
|
||||
{/block}
|
||||
|
||||
{block header}
|
||||
<a href='{$item->getPageURL()}'>{tr($type)}</a> »
|
||||
{_likers_list}
|
||||
{/block}
|
||||
|
||||
{block tabs}
|
||||
<div class="tab" id="activetabs">
|
||||
<a id="act_tab_a" href="#">{_liked_verb}</a>
|
||||
</div>
|
||||
{/block}
|
||||
|
||||
{block link|strip|stripHtml}
|
||||
{$x->getURL()}
|
||||
{/block}
|
||||
|
||||
{block preview}
|
||||
<img src="{$x->getAvatarUrl('tiny')}" width="75" loading=lazy />
|
||||
{/block}
|
||||
|
||||
{block name}
|
||||
{$x->getCanonicalName()}
|
||||
<img n:if="$x->isVerified()"
|
||||
class="name-checkmark"
|
||||
src="/assets/packages/static/openvk/img/checkmark.png"
|
||||
/>
|
||||
{/block}
|
||||
|
||||
{block description}
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="120" valign="top"><span class="nobold">{_pronouns}: </span></td>
|
||||
<td>{$x->isFemale() ? tr("female") : ($x->isNeutral() ? tr("neutral") : tr("male"))}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="120" valign="top"><span class="nobold">{_relationship}:</span></td>
|
||||
<td>{$x->getLocalizedMaritalStatus()}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="120" valign="top"><span class="nobold">{_registration_date}: </span></td>
|
||||
<td>{$x->getRegistrationTime()}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{/block}
|
|
@ -143,6 +143,8 @@ routes:
|
|||
handler: "Wall->accept"
|
||||
- url: "/wall/decline"
|
||||
handler: "Wall->decline"
|
||||
- url: "/{text}/{num}_{num}/likes"
|
||||
handler: "Wall->likers"
|
||||
- url: "/blob_{text}/{?path}.{text}"
|
||||
handler: "Blob->file"
|
||||
placeholders:
|
||||
|
|
|
@ -272,6 +272,9 @@
|
|||
"show_more" = "Show more";
|
||||
"has_repost" = "Has repost";
|
||||
|
||||
"likers_list" = "Likers list";
|
||||
"liked_verb" = "Liked by";
|
||||
|
||||
/* Friends */
|
||||
|
||||
"friends" = "Friends";
|
||||
|
|
|
@ -251,6 +251,9 @@
|
|||
"show_more" = "Показать больше";
|
||||
"has_repost" = "Содержит репост";
|
||||
|
||||
"likers_list" = "Список лайкнувших";
|
||||
"liked_verb" = "Понравилось";
|
||||
|
||||
/* Friends */
|
||||
|
||||
"friends" = "Друзья";
|
||||
|
|
Loading…
Reference in a new issue