diff --git a/ServiceAPI/Video.php b/ServiceAPI/Video.php
deleted file mode 100644
index d0eb4ee8..00000000
--- a/ServiceAPI/Video.php
+++ /dev/null
@@ -1,156 +0,0 @@
-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);
- }
-}
diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php
index c7a8362c..ed7251ac 100644
--- a/ServiceAPI/Wall.php
+++ b/ServiceAPI/Wall.php
@@ -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);
- }
}
diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php
index c2c73293..5b6b8d9f 100644
--- a/VKAPI/Handlers/Wall.php
+++ b/VKAPI/Handlers/Wall.php
@@ -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()
];
}
diff --git a/Web/Presenters/VideosPresenter.php b/Web/Presenters/VideosPresenter.php
index 49ed1b43..dbf4efea 100644
--- a/Web/Presenters/VideosPresenter.php
+++ b/Web/Presenters/VideosPresenter.php
@@ -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]");
}
}
diff --git a/Web/Presenters/templates/Photos/Photo.xml b/Web/Presenters/templates/Photos/Photo.xml
index 8f857581..590d6830 100644
--- a/Web/Presenters/templates/Photos/Photo.xml
+++ b/Web/Presenters/templates/Photos/Photo.xml
@@ -65,6 +65,9 @@
{_"open_original"}
{_report}
+
+ {_share}
+
diff --git a/Web/Presenters/templates/Videos/View.xml b/Web/Presenters/templates/Videos/View.xml
index c215cc92..845ca9b1 100644
--- a/Web/Presenters/templates/Videos/View.xml
+++ b/Web/Presenters/templates/Videos/View.xml
@@ -75,6 +75,9 @@
{_delete}
+
+ {_share}
+
diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js
index d2cd417f..1ca0fe6c 100644
--- a/Web/static/js/al_wall.js
+++ b/Web/static/js/al_wall.js
@@ -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', `(1)`)
+
+ if(u('#reposts' + id).length > 0) {
+ if(repostsCount.length > 0) {
+ repostsCount.html(previousVal + 1)
+ } else {
+ u('#reposts' + id).nodes[0].insertAdjacentHTML('beforeend', `(1)`)
+ }
}
NewNotification(tr('information_-1'), tr('shared_succ'), null, () => {window.location.assign(`/wall${res.pretty_id}`)});