diff --git a/ServiceAPI/Photos.php b/ServiceAPI/Photos.php
new file mode 100644
index 00000000..16d602f2
--- /dev/null
+++ b/ServiceAPI/Photos.php
@@ -0,0 +1,92 @@
+user = $user;
+ $this->photos = new PhotosRepo;
+ }
+
+ function getPhotos(int $page = 1, int $album = 0, callable $resolve, callable $reject)
+ {
+ if($album == 0) {
+ $photos = $this->photos->getEveryUserPhoto($this->user, $page, 24);
+ $count = $this->photos->getUserPhotosCount($this->user);
+ } else {
+ $album = (new Albums)->get($album);
+
+ if(!$album || $album->isDeleted())
+ $reject(55, "Invalid .");
+
+ if($album->getOwner() instanceof User) {
+ if($album->getOwner()->getId() != $this->user->getId())
+ $reject(555, "Access to album denied");
+ } else {
+ if(!$album->getOwner()->canBeModifiedBy($this->user))
+ $reject(555, "Access to album denied");
+ }
+
+ $photos = $album->getPhotos($page, 24);
+ $count = $album->size();
+ }
+
+ $arr = [
+ "count" => $count,
+ "items" => [],
+ ];
+
+ foreach($photos as $photo) {
+ $res = json_decode(json_encode($photo->toVkApiStruct()), true);
+
+ $arr["items"][] = $res;
+ }
+
+ $resolve($arr);
+ }
+
+ function getAlbums(int $club, callable $resolve, callable $reject)
+ {
+ $albumsRepo = (new Albums);
+
+ $count = $albumsRepo->getUserAlbumsCount($this->user);
+ $albums = $albumsRepo->getUserAlbums($this->user, 1, $count);
+
+ $arr = [
+ "count" => $count,
+ "items" => [],
+ ];
+
+ foreach($albums as $album) {
+ $res = ["id" => $album->getId(), "name" => $album->getName()];
+
+ $arr["items"][] = $res;
+ }
+
+ if($club > 0) {
+ $cluber = (new Clubs)->get($club);
+
+ if(!$cluber || !$cluber->canBeModifiedBy($this->user))
+ $reject(1337, "Invalid (club), or you can't modify him");
+
+ $clubCount = (new Albums)->getClubAlbumsCount($cluber);
+ $clubAlbums = (new Albums)->getClubAlbums($cluber, 1, $clubCount);
+
+ foreach($clubAlbums as $albumr) {
+ $res = ["id" => $albumr->getId(), "name" => $albumr->getName()];
+
+ $arr["items"][] = $res;
+ }
+
+ $arr["count"] = $arr["count"] + $clubCount;
+ }
+
+ $resolve($arr);
+ }
+}
diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php
index d64a2763..37b06dda 100644
--- a/Web/Models/Entities/Comment.php
+++ b/Web/Models/Entities/Comment.php
@@ -11,7 +11,7 @@ class Comment extends Post
function getPrettyId(): string
{
- return $this->getRecord()->id;
+ return (string)$this->getRecord()->id;
}
function getVirtualId(): int
diff --git a/Web/Models/Repositories/Photos.php b/Web/Models/Repositories/Photos.php
index 88c7e804..0698c914 100644
--- a/Web/Models/Repositories/Photos.php
+++ b/Web/Models/Repositories/Photos.php
@@ -33,14 +33,26 @@ class Photos
return new Photo($photo);
}
- function getEveryUserPhoto(User $user): \Traversable
+ function getEveryUserPhoto(User $user, int $page = 1, ?int $perPage = NULL): \Traversable
{
+ $perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
$photos = $this->photos->where([
- "owner" => $user->getId()
- ]);
+ "owner" => $user->getId(),
+ "deleted" => 0
+ ])->order("id DESC");
- foreach($photos as $photo) {
+ foreach($photos->page($page, $perPage) as $photo) {
yield new Photo($photo);
}
}
+
+ function getUserPhotosCount(User $user)
+ {
+ $photos = $this->photos->where([
+ "owner" => $user->getId(),
+ "deleted" => 0
+ ]);
+
+ return sizeof($photos);
+ }
}
diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php
index b68c7d11..e005af86 100644
--- a/Web/Presenters/CommentPresenter.php
+++ b/Web/Presenters/CommentPresenter.php
@@ -2,7 +2,7 @@
namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\{Comment, Notifications\MentionNotification, Photo, Video, User, Topic, Post};
use openvk\Web\Models\Entities\Notifications\CommentNotification;
-use openvk\Web\Models\Repositories\{Comments, Clubs, Videos};
+use openvk\Web\Models\Repositories\{Comments, Clubs, Videos, Photos};
final class CommentPresenter extends OpenVKPresenter
{
@@ -54,9 +54,6 @@ final class CommentPresenter extends OpenVKPresenter
if ($entity instanceof Post && $entity->getWallOwner()->isBanned())
$this->flashFail("err", tr("error"), tr("forbidden"));
- if($_FILES["_vid_attachment"] && OPENVK_ROOT_CONF['openvk']['preferences']['videos']['disableUploading'])
- $this->flashFail("err", tr("error"), tr("video_uploads_disabled"));
-
$flags = 0;
if($this->postParam("as_group") === "on" && !is_null($club) && $club->canBeModifiedBy($this->user->identity))
$flags |= 0b10000000;
@@ -70,18 +67,22 @@ final class CommentPresenter extends OpenVKPresenter
}
}
- # TODO move to trait
- try {
- $photo = NULL;
- if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
- $album = NULL;
- if($wall > 0 && $wall === $this->user->id)
- $album = (new Albums)->getUserWallAlbum($wallOwner);
-
- $photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album);
+ $photos = [];
+ if(!empty($this->postParam("photos"))) {
+ $un = rtrim($this->postParam("photos"), ",");
+ $arr = explode(",", $un);
+
+ if(sizeof($arr) < 11) {
+ foreach($arr as $dat) {
+ $ids = explode("_", $dat);
+ $photo = (new Photos)->getByOwnerAndVID((int)$ids[0], (int)$ids[1]);
+
+ if(!$photo || $photo->isDeleted())
+ continue;
+
+ $photos[] = $photo;
+ }
}
- } catch(ISE $ex) {
- $this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_file_too_big"));
}
$videos = [];
@@ -103,7 +104,7 @@ final class CommentPresenter extends OpenVKPresenter
}
}
- if(empty($this->postParam("text")) && !$photo && !$video)
+ if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) < 1)
$this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_empty"));
try {
@@ -119,8 +120,8 @@ final class CommentPresenter extends OpenVKPresenter
$this->flashFail("err", tr("error_when_publishing_comment"), tr("error_comment_too_big"));
}
- if(!is_null($photo))
- $comment->attach($photo);
+ foreach($photos as $photo)
+ $comment->attach($photo);
if(sizeof($videos) > 0)
foreach($videos as $vid)
diff --git a/Web/Presenters/InternalAPIPresenter.php b/Web/Presenters/InternalAPIPresenter.php
index efcb0179..e2e6b50e 100644
--- a/Web/Presenters/InternalAPIPresenter.php
+++ b/Web/Presenters/InternalAPIPresenter.php
@@ -1,6 +1,6 @@
getPostById(intval($id[0]), intval($id[1]));
+
+ if($this->postParam("parentType", false) == "post") {
+ $post = (new Posts)->getPostById($owner_id, $post_id);
+ } else {
+ $post = (new Comments)->get($post_id);
+ }
+
if(is_null($post)) {
$this->returnJson([
diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php
index bef984b7..0a8b87e4 100644
--- a/Web/Presenters/PhotosPresenter.php
+++ b/Web/Presenters/PhotosPresenter.php
@@ -222,15 +222,20 @@ final class PhotosPresenter extends OpenVKPresenter
{
$this->assertUserLoggedIn();
$this->willExecuteWriteAction(true);
-
- if(is_null($this->queryParam("album")))
- $this->flashFail("err", tr("error"), tr("error_adding_to_deleted"), 500, true);
-
- [$owner, $id] = explode("_", $this->queryParam("album"));
- $album = $this->albums->get((int) $id);
+
+ if(is_null($this->queryParam("album"))) {
+ $album = $this->albums->getUserWallAlbum($this->user->identity);
+ } else {
+ [$owner, $id] = explode("_", $this->queryParam("album"));
+ $album = $this->albums->get((int) $id);
+ }
+
if(!$album)
$this->flashFail("err", tr("error"), tr("error_adding_to_deleted"), 500, true);
- if(is_null($this->user) || !$album->canBeModifiedBy($this->user->identity))
+
+ # Для быстрой загрузки фоток из пикера фотографий нужен альбом, но юзер не может загружать фото
+ # в системные альбомы, так что так.
+ if(is_null($this->user) || !is_null($this->queryParam("album")) && !$album->canBeModifiedBy($this->user->identity))
$this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied"), 500, true);
if($_SERVER["REQUEST_METHOD"] === "POST") {
@@ -261,6 +266,9 @@ final class PhotosPresenter extends OpenVKPresenter
$this->flashFail("err", tr("no_photo"), tr("select_file"), 500, true);
$photos = [];
+ if((int)$this->postParam("count") > 10)
+ $this->flashFail("err", tr("no_photo"), "ты еблан", 500, true);
+
for($i = 0; $i < $this->postParam("count"); $i++) {
try {
$photo = new Photo;
diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php
index 4635a6f4..2f9d611d 100644
--- a/Web/Presenters/WallPresenter.php
+++ b/Web/Presenters/WallPresenter.php
@@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Exceptions\TooMuchOptionsException;
use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User};
use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification};
-use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos, Comments};
+use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Videos, Comments, Photos};
use Chandler\Database\DatabaseConnection;
use Nette\InvalidStateException as ISE;
use Bhaktaraz\RSSGenerator\Item;
@@ -249,35 +249,23 @@ final class WallPresenter extends OpenVKPresenter
if($this->postParam("force_sign") === "on")
$flags |= 0b01000000;
- try {
- $photos = [];
- $video = NULL;
- /* if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
- $album = NULL;
- if(!$anon && $wall > 0 && $wall === $this->user->id)
- $album = (new Albums)->getUserWallAlbum($wallOwner);
-
- $photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album, $anon);
- } */
+ $photos = [];
- $album = NULL;
- if(!$anon && $wall > 0 && $wall === $this->user->id)
- $album = (new Albums)->getUserWallAlbum($wallOwner);
+ if(!empty($this->postParam("photos"))) {
+ $un = rtrim($this->postParam("photos"), ",");
+ $arr = explode(",", $un);
- foreach($_FILES as $fileId => $file) {
- bdump([$fileId, $file, $file["error"] !== UPLOAD_ERR_OK, strncmp($fileId, "attachPic", 9) !== 0]);
- if($file["error"] !== UPLOAD_ERR_OK || strncmp($fileId, "attachPic", 9) !== 0)
- continue;
-
- $photos[] = Photo::fastMake($this->user->id, $this->postParam("text"), $file, $album, $anon);
+ if(sizeof($arr) < 11) {
+ foreach($arr as $dat) {
+ $ids = explode("_", $dat);
+ $photo = (new Photos)->getByOwnerAndVID((int)$ids[0], (int)$ids[1]);
+
+ if(!$photo || $photo->isDeleted())
+ continue;
+
+ $photos[] = $photo;
+ }
}
-
- /*if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK)
- $video = Video::fastMake($this->user->id, $_FILES["_vid_attachment"]["name"], $this->postParam("text"), $_FILES["_vid_attachment"], $anon);*/
- } catch(\DomainException $ex) {
- $this->flashFail("err", tr("failed_to_publish_post"), tr("media_file_corrupted"));
- } catch(ISE $ex) {
- $this->flashFail("err", tr("failed_to_publish_post"), tr("media_file_corrupted_or_too_large"));
}
try {
@@ -324,7 +312,7 @@ final class WallPresenter extends OpenVKPresenter
}
}
- if(empty($this->postParam("text")) && !$photos && sizeof($videos) < 1 && !$poll && !$note)
+ if(empty($this->postParam("text")) && sizeof($photos) < 1 && sizeof($videos) < 1 && !$poll && !$note)
$this->flashFail("err", tr("failed_to_publish_post"), tr("post_is_empty_or_too_big"));
try {
diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml
index 94d12034..a46be837 100644
--- a/Web/Presenters/templates/components/attachment.xml
+++ b/Web/Presenters/templates/components/attachment.xml
@@ -1,7 +1,7 @@
{if $attachment instanceof \openvk\Web\Models\Entities\Photo}
{if !$attachment->isDeleted()}
{var $link = "/photo" . ($attachment->isAnonymous() ? ("s/" . base_convert((string) $attachment->getId(), 10, 32)) : $attachment->getPrettyId())}
-
+
{else}
diff --git a/Web/Presenters/templates/components/comment.xml b/Web/Presenters/templates/components/comment.xml
index 9be7d838..1ba7ada3 100644
--- a/Web/Presenters/templates/components/comment.xml
+++ b/Web/Presenters/templates/components/comment.xml
@@ -24,7 +24,7 @@