mirror of
https://github.com/openvk/openvk
synced 2024-11-14 19:19:14 +03:00
add share button 4 vids&photos, improv wall.repost
This commit is contained in:
parent
890961e63d
commit
73325a3acb
7 changed files with 54 additions and 239 deletions
|
@ -1,156 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\ServiceAPI;
|
||||
|
||||
use openvk\Web\Models\Entities\{User, Post};
|
||||
use openvk\Web\Models\Repositories\{Videos, Comments, Clubs};
|
||||
use Chandler\MVC\Routing\Router;
|
||||
|
||||
class Video implements Handler
|
||||
{
|
||||
protected $user;
|
||||
protected $videos;
|
||||
protected $comments;
|
||||
protected $groups;
|
||||
|
||||
function __construct(?User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->videos = new Videos;
|
||||
$this->comments = new Comments;
|
||||
$this->groups = new Clubs;
|
||||
}
|
||||
|
||||
function getVideo(int $id, callable $resolve, callable $reject)
|
||||
{
|
||||
$video = $this->videos->get($id);
|
||||
|
||||
if(!$video || $video->isDeleted()) {
|
||||
$reject(2, "Video does not exists");
|
||||
}
|
||||
|
||||
if(method_exists($video, "canBeViewedBy") && !$video->canBeViewedBy($this->user)) {
|
||||
$reject(4, "Access to video denied");
|
||||
}
|
||||
|
||||
if(!$video->getOwner()->getPrivacyPermission('videos.read', $this->user)) {
|
||||
$reject(8, "Access to video denied: this user chose to hide his videos");
|
||||
}
|
||||
|
||||
$prevVideo = NULL;
|
||||
$nextVideo = NULL;
|
||||
$lastVideo = $this->videos->getLastVideo($video->getOwner());
|
||||
|
||||
if($video->getVirtualId() - 1 != 0) {
|
||||
for($i = $video->getVirtualId(); $i != 0; $i--) {
|
||||
$maybeVideo = (new Videos)->getByOwnerAndVID($video->getOwner()->getId(), $i);
|
||||
|
||||
if(!is_null($maybeVideo) && !$maybeVideo->isDeleted() && $maybeVideo->getId() != $video->getId()) {
|
||||
if(method_exists($maybeVideo, "canBeViewedBy") && !$maybeVideo->canBeViewedBy($this->user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$prevVideo = $maybeVideo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_null($lastVideo) || $lastVideo->getId() == $video->getId()) {
|
||||
$nextVideo = NULL;
|
||||
} else {
|
||||
for($i = $video->getVirtualId(); $i <= $lastVideo->getVirtualId(); $i++) {
|
||||
$maybeVideo = (new Videos)->getByOwnerAndVID($video->getOwner()->getId(), $i);
|
||||
|
||||
if(!is_null($maybeVideo) && !$maybeVideo->isDeleted() && $maybeVideo->getId() != $video->getId()) {
|
||||
if(method_exists($maybeVideo, "canBeViewedBy") && !$maybeVideo->canBeViewedBy($this->user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$nextVideo = $maybeVideo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res = [
|
||||
"id" => $video->getId(),
|
||||
"title" => $video->getName(),
|
||||
"owner" => $video->getOwner()->getId(),
|
||||
"commentsCount" => $video->getCommentsCount(),
|
||||
"description" => $video->getDescription(),
|
||||
"type" => $video->getType(),
|
||||
"name" => $video->getOwner()->getCanonicalName(),
|
||||
"pretty_id" => $video->getPrettyId(),
|
||||
"virtual_id" => $video->getVirtualId(),
|
||||
"published" => (string)$video->getPublicationTime(),
|
||||
"likes" => $video->getLikesCount(),
|
||||
"has_like" => $video->hasLikeFrom($this->user),
|
||||
"author" => $video->getOwner()->getCanonicalName(),
|
||||
"canBeEdited" => $video->getOwner()->getId() == $this->user->getId(),
|
||||
"isProcessing" => $video->getType() == 0 && $video->getURL() == "/assets/packages/static/openvk/video/rendering.mp4",
|
||||
"prevVideo" => !is_null($prevVideo) ? $prevVideo->getId() : null,
|
||||
"nextVideo" => !is_null($nextVideo) ? $nextVideo->getId() : null,
|
||||
];
|
||||
|
||||
if($video->getType() == 1) {
|
||||
$res["embed"] = $video->getVideoDriver()->getEmbed();
|
||||
} else {
|
||||
$res["url"] = $video->getURL();
|
||||
}
|
||||
|
||||
$resolve($res);
|
||||
}
|
||||
|
||||
function shareVideo(int $owner, int $vid, int $type, string $message, int $club, bool $signed, bool $asGroup, callable $resolve, callable $reject)
|
||||
{
|
||||
$video = $this->videos->getByOwnerAndVID($owner, $vid);
|
||||
|
||||
if(!$video || $video->isDeleted()) {
|
||||
$reject(16, "Video does not exists");
|
||||
}
|
||||
|
||||
if(method_exists($video, "canBeViewedBy") && !$video->canBeViewedBy($this->user)) {
|
||||
$reject(32, "Access to video denied");
|
||||
}
|
||||
|
||||
if(!$video->getOwner()->getPrivacyPermission('videos.read', $this->user)) {
|
||||
$reject(8, "Access to video denied: this user chose to hide his videos");
|
||||
}
|
||||
|
||||
$flags = 0;
|
||||
|
||||
$nPost = new Post;
|
||||
$nPost->setOwner($this->user->getId());
|
||||
|
||||
if($type == 0) {
|
||||
$nPost->setWall($this->user->getId());
|
||||
} else {
|
||||
$club = $this->groups->get($club);
|
||||
|
||||
if(!$club || $club->isDeleted() || !$club->canBeModifiedBy($this->user)) {
|
||||
$reject(64, "Can't do repost to this club");
|
||||
}
|
||||
|
||||
if($asGroup)
|
||||
$flags |= 0b10000000;
|
||||
|
||||
if($signed)
|
||||
$flags |= 0b01000000;
|
||||
|
||||
$nPost->setWall($club->getId() * -1);
|
||||
}
|
||||
|
||||
$nPost->setContent($message);
|
||||
$nPost->setFlags($flags);
|
||||
$nPost->save();
|
||||
|
||||
$nPost->attach($video);
|
||||
|
||||
$res = [
|
||||
"id" => $nPost->getId(),
|
||||
"pretty_id" => $nPost->getPrettyId(),
|
||||
];
|
||||
|
||||
$resolve($res);
|
||||
}
|
||||
}
|
|
@ -80,67 +80,4 @@ class Wall implements Handler
|
|||
|
||||
$resolve($post->getId());
|
||||
}
|
||||
|
||||
function getMyNotes(callable $resolve, callable $reject)
|
||||
{
|
||||
$count = $this->notes->getUserNotesCount($this->user);
|
||||
$myNotes = $this->notes->getUserNotes($this->user, 1, $count);
|
||||
|
||||
$arr = [
|
||||
"count" => $count,
|
||||
"closed" => $this->user->getPrivacySetting("notes.read"),
|
||||
"items" => [],
|
||||
];
|
||||
|
||||
foreach($myNotes as $note) {
|
||||
$arr["items"][] = [
|
||||
"id" => $note->getId(),
|
||||
"name" => ovk_proc_strtr($note->getName(), 30),
|
||||
#"preview" => $note->getPreview()
|
||||
];
|
||||
}
|
||||
|
||||
$resolve($arr);
|
||||
}
|
||||
|
||||
function getVideos(int $page = 1, callable $resolve, callable $reject)
|
||||
{
|
||||
$videos = $this->videos->getByUser($this->user, $page, 8);
|
||||
$count = $this->videos->getUserVideosCount($this->user);
|
||||
|
||||
$arr = [
|
||||
"count" => $count,
|
||||
"items" => [],
|
||||
];
|
||||
|
||||
foreach($videos as $video) {
|
||||
$res = json_decode(json_encode($video->toVkApiStruct($this->user)), true);
|
||||
$res["video"]["author_name"] = $video->getOwner()->getCanonicalName();
|
||||
|
||||
$arr["items"][] = $res;
|
||||
}
|
||||
|
||||
$resolve($arr);
|
||||
}
|
||||
|
||||
function searchVideos(int $page = 1, string $query, callable $resolve, callable $reject)
|
||||
{
|
||||
$dbc = $this->videos->find($query);
|
||||
$videos = $dbc->page($page, 8);
|
||||
$count = $dbc->size();
|
||||
|
||||
$arr = [
|
||||
"count" => $count,
|
||||
"items" => [],
|
||||
];
|
||||
|
||||
foreach($videos as $video) {
|
||||
$res = json_decode(json_encode($video->toVkApiStruct($this->user)), true);
|
||||
$res["video"]["author_name"] = $video->getOwner()->getCanonicalName();
|
||||
|
||||
$arr["items"][] = $res;
|
||||
}
|
||||
|
||||
$resolve($arr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -606,9 +606,9 @@ final class Wall extends VKAPIRequestHandler
|
|||
$this->willExecuteWriteAction();
|
||||
|
||||
$postArray;
|
||||
if(preg_match('/wall((?:-?)[0-9]+)_([0-9]+)/', $object, $postArray) == 0)
|
||||
if(preg_match('/(wall|video|photo)((?:-?)[0-9]+)_([0-9]+)/', $object, $postArray) == 0)
|
||||
$this->fail(100, "One of the parameters specified was missing or invalid: object is incorrect");
|
||||
|
||||
|
||||
$parsed_attachments = parseAttachments($attachments, ['photo', 'video', 'note', 'audio']);
|
||||
$final_attachments = [];
|
||||
foreach($parsed_attachments as $attachment) {
|
||||
|
@ -618,11 +618,22 @@ final class Wall extends VKAPIRequestHandler
|
|||
}
|
||||
}
|
||||
|
||||
$post = (new PostsRepo)->getPostById((int) $postArray[1], (int) $postArray[2]);
|
||||
if(!$post || $post->isDeleted()) $this->fail(100, "One of the parameters specified was missing or invalid");
|
||||
|
||||
if(!$post->canBeViewedBy($this->getUser()))
|
||||
$this->fail(15, "Access denied");
|
||||
$repost_entity = NULL;
|
||||
$repost_type = $postArray[1];
|
||||
switch($repost_type) {
|
||||
default:
|
||||
case 'wall':
|
||||
$repost_entity = (new PostsRepo)->getPostById((int) $postArray[2], (int) $postArray[3]);
|
||||
break;
|
||||
case 'photo':
|
||||
$repost_entity = (new PhotosRepo)->getByOwnerAndVID((int) $postArray[2], (int) $postArray[3]);
|
||||
break;
|
||||
case 'video':
|
||||
$repost_entity = (new VideosRepo)->getByOwnerAndVID((int) $postArray[2], (int) $postArray[3]);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$repost_entity || $repost_entity->isDeleted() || !$repost_entity->canBeViewedBy($this->getUser())) $this->fail(100, "One of the parameters specified was missing or invalid");
|
||||
|
||||
$nPost = new Post;
|
||||
$nPost->setOwner($this->user->getId());
|
||||
|
@ -652,21 +663,26 @@ final class Wall extends VKAPIRequestHandler
|
|||
$nPost->setApi_Source_Name($this->getPlatform());
|
||||
$nPost->save();
|
||||
|
||||
$nPost->attach($post);
|
||||
$nPost->attach($repost_entity);
|
||||
|
||||
foreach($parsed_attachments as $attachment) {
|
||||
$nPost->attach($attachment);
|
||||
}
|
||||
|
||||
if($post->getOwner(false)->getId() !== $this->user->getId() && !($post->getOwner() instanceof Club))
|
||||
(new RepostNotification($post->getOwner(false), $post, $this->user))->emit();
|
||||
if($repost_type == 'wall' && $repost_entity->getOwner(false)->getId() !== $this->user->getId() && !($repost_entity->getOwner() instanceof Club))
|
||||
(new RepostNotification($repost_entity->getOwner(false), $repost_entity, $this->user))->emit();
|
||||
|
||||
$repost_count = 1;
|
||||
if($repost_type == 'wall') {
|
||||
$repost_count = $repost_entity->getRepostCount();
|
||||
}
|
||||
|
||||
return (object) [
|
||||
"success" => 1, // 👍
|
||||
"post_id" => $nPost->getVirtualId(),
|
||||
"pretty_id" => $nPost->getPrettyId(),
|
||||
"reposts_count" => $post->getRepostCount(),
|
||||
"likes_count" => $post->getLikesCount()
|
||||
"reposts_count" => $repost_count,
|
||||
"likes_count" => $repost_entity->getLikesCount()
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,13 @@ final class VideosPresenter extends OpenVKPresenter
|
|||
if(!is_null($this->user)) {
|
||||
$video->toggleLike($this->user->identity);
|
||||
}
|
||||
|
||||
$this->returnJson(["success" => true]);
|
||||
|
||||
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$this->returnJson([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->redirect("$_SERVER[HTTP_REFERER]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@
|
|||
</div>
|
||||
<a href="{$photo->getURL()}" class="profile_link" target="_blank" style="display:block;width:96%;">{_"open_original"}</a>
|
||||
<a n:if="isset($thisUser) && $thisUser->getId() != $photo->getOwner()->getId()" class="profile_link" style="display:block;width:96%;" href="javascript:reportPhoto({$photo->getId()})">{_report}</a>
|
||||
<a onclick="javascript:repost({$photo->getPrettyId()}, 'photo')" class="profile_link" style="display:block;width:96%;">
|
||||
{_share}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -75,6 +75,9 @@
|
|||
<a id='_videoDelete' href="/video{$video->getPrettyId()}/remove" class="profile_link" style="display:block;width:96%;">
|
||||
{_delete}
|
||||
</a>
|
||||
<a onclick="javascript:repost({$video->getPrettyId()}, 'video')" class="profile_link" style="display:block;width:96%;">
|
||||
{_share}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -154,9 +154,9 @@ async function OpenMiniature(e, photo, post, photo_id, type = "post") {
|
|||
const parser = new DOMParser
|
||||
const body = parser.parseFromString(photo_text, "text/html")
|
||||
const details = body.querySelector('.ovk-photo-details')
|
||||
json.body[photo_id].cached = details.innerHTML ?? ''
|
||||
json.body[photo_id].cached = details ? details.innerHTML : ''
|
||||
if(photo_id == currentImageid) {
|
||||
photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = details.innerHTML ?? '';
|
||||
photo_viewer.getNode().find(".ovk-photo-details").last().innerHTML = details ? details.innerHTML : ''
|
||||
}
|
||||
|
||||
photo_viewer.getNode().find(".ovk-photo-details .bsdn").nodes.forEach(bsdnInitElement)
|
||||
|
@ -1321,6 +1321,9 @@ async function repost(id, repost_type = 'post') {
|
|||
case 'post':
|
||||
params.object = `wall${id}`
|
||||
break
|
||||
case 'photo':
|
||||
params.object = `photo${id}`
|
||||
break
|
||||
case 'video':
|
||||
params.object = `video${id}`
|
||||
break
|
||||
|
@ -1345,10 +1348,13 @@ async function repost(id, repost_type = 'post') {
|
|||
|
||||
try {
|
||||
res = await window.OVKAPI.call('wall.repost', params)
|
||||
if(repostsCount.length > 0) {
|
||||
repostsCount.html(previousVal + 1)
|
||||
} else {
|
||||
u('#reposts' + id).nodes[0].insertAdjacentHTML('beforeend', `(<b id='repostsCount${id}'>1</b>)`)
|
||||
|
||||
if(u('#reposts' + id).length > 0) {
|
||||
if(repostsCount.length > 0) {
|
||||
repostsCount.html(previousVal + 1)
|
||||
} else {
|
||||
u('#reposts' + id).nodes[0].insertAdjacentHTML('beforeend', `(<b id='repostsCount${id}'>1</b>)`)
|
||||
}
|
||||
}
|
||||
|
||||
NewNotification(tr('information_-1'), tr('shared_succ'), null, () => {window.location.assign(`/wall${res.pretty_id}`)});
|
||||
|
|
Loading…
Reference in a new issue