diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index 78417a56..ecda93f6 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -44,11 +44,12 @@ class Photo extends Media DB::i()->getContext()->table("album_relations")->where("media", $this->getRecord()->id)->delete(); } - static function fastMake(int $owner, string $description = "", array $file, ?Album $album = NULL): Photo + static function fastMake(int $owner, string $description = "", array $file, ?Album $album = NULL, bool $anon = false): Photo { $photo = new static; $photo->setOwner($owner); $photo->setDescription(iconv_substr($description, 0, 36) . "..."); + $photo->setAnonymous($anon); $photo->setCreated(time()); $photo->setFile($file); $photo->save(); diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 17c096fa..7d0cc486 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -36,14 +36,14 @@ class Post extends Postable * * @param bool $honourFlags - check flags */ - function getOwner(bool $honourFlags = true): RowModel + function getOwner(bool $honourFlags = true, bool $real = false): RowModel { if($honourFlags && ( ($this->getRecord()->flags & 0b10000000) > 0 )) { if($this->getRecord()->wall < 0) return (new Clubs)->get(abs($this->getRecord()->wall)); } - return parent::getOwner(); + return parent::getOwner($real); } function getPrettyId(): string diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 26670e94..b5749819 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -29,9 +29,12 @@ abstract class Postable extends Attachable return DB::i()->getContext()->table($this->tableName); } - function getOwner(): RowModel + function getOwner(bool $real = false): RowModel { $oid = (int) $this->getRecord()->owner; + if(!$real && $this->isAnonymous()) + $oid = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["account"]; + if($oid > 0) return (new Users)->get($oid); else @@ -96,6 +99,11 @@ abstract class Postable extends Attachable yield (new Users)->get($like->origin); } + function isAnonymous(): bool + { + return (bool) $this->getRecord()->anonymous; + } + function toggleLike(User $user): bool { $searchData = [ diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index 492dafed..17500e8d 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -122,12 +122,13 @@ class Video extends Media $this->save(); } - static function fastMake(int $owner, string $description = "", array $file, bool $unlisted = true): Video + static function fastMake(int $owner, string $description = "", array $file, bool $unlisted = true, bool $anon = false): Video { $video = new Video; $video->setOwner($owner); $video->setName("Unnamed Video.ogv"); $video->setDescription(ovk_proc_strtr($description, 300)); + $video->setAnonymous($anon); $video->setCreated(time()); $video->setFile($file); $video->setUnlisted($unlisted); diff --git a/Web/Presenters/PhotosPresenter.php b/Web/Presenters/PhotosPresenter.php index 15438bdd..cefe69ac 100644 --- a/Web/Presenters/PhotosPresenter.php +++ b/Web/Presenters/PhotosPresenter.php @@ -159,6 +159,17 @@ final class PhotosPresenter extends OpenVKPresenter $this->template->comments = iterator_to_array($photo->getComments($this->template->cPage)); } + function renderAbsolutePhoto(string $id): void + { + $id = (int) base_convert($id, 32, 10); + $photo = $this->photos->get($id); + if(!$photo || $photo->isDeleted()) + $this->notFound(); + + $this->template->_template = "Photos/Photo.xml"; + $this->renderPhoto($photo->getOwner(true)->getId(), $photo->getVirtualId()); + } + function renderEditPhoto(int $ownerId, int $photoId): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 51734a3d..325b84a2 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -188,6 +188,8 @@ final class WallPresenter extends OpenVKPresenter if(false) $this->flashFail("err", "Не удалось опубликовать пост", "Пост слишком большой."); + $anon = OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"] && $this->postParam("anon") === "on"; + $flags = 0; if($this->postParam("as_group") === "on") $flags |= 0b10000000; @@ -199,14 +201,14 @@ final class WallPresenter extends OpenVKPresenter $video = NULL; if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) { $album = NULL; - if($wall > 0 && $wall === $this->user->id) + 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); + $photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"], $album, $anon); } if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) { - $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"]); + $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"], $anon); } } catch(\DomainException $ex) { $this->flashFail("err", "Не удалось опубликовать пост", "Файл медиаконтента повреждён."); @@ -222,6 +224,7 @@ final class WallPresenter extends OpenVKPresenter $post->setWall($wall); $post->setCreated(time()); $post->setContent($this->postParam("text")); + $post->setAnonymous($anon); $post->setFlags($flags); $post->setNsfw($this->postParam("nsfw") === "on"); $post->save(); diff --git a/Web/Presenters/templates/components/attachment.xml b/Web/Presenters/templates/components/attachment.xml index 35f1901a..9e9271f2 100644 --- a/Web/Presenters/templates/components/attachment.xml +++ b/Web/Presenters/templates/components/attachment.xml @@ -1,6 +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/textArea.xml b/Web/Presenters/templates/components/textArea.xml index 814077f3..2033d393 100644 --- a/Web/Presenters/templates/components/textArea.xml +++ b/Web/Presenters/templates/components/textArea.xml @@ -9,12 +9,17 @@ Вложение: (unknown)