mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
Add option to post anonymously
This commit is contained in:
parent
762368c89c
commit
0a7bc786b5
11 changed files with 53 additions and 11 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{if $attachment instanceof \openvk\Web\Models\Entities\Photo}
|
||||
{if !$attachment->isDeleted()}
|
||||
<a href="/photo{$attachment->getPrettyId()}">
|
||||
{var link = "/photo" . ($attachment->isAnonymous() ? ("s/" . base_convert((string) $attachment->getId(), 10, 32)) : $attachment->getPrettyId())}
|
||||
<a href="{$link}">
|
||||
<img class="media" src="{$attachment->getURL()}" alt="{$attachment->getDescription()}" />
|
||||
</a>
|
||||
{else}
|
||||
|
|
|
@ -9,12 +9,17 @@
|
|||
Вложение: <span>(unknown)</span>
|
||||
</div>
|
||||
<div n:if="$postOpts ?? true" class="post-opts">
|
||||
{var anonEnabled = OPENVK_ROOT_CONF['openvk']['preferences']['wall']['anonymousPosting']['enable']}
|
||||
|
||||
{if !is_null($thisUser) && !is_null($club ?? NULL) && $owner < 0}
|
||||
{if $club->canBeModifiedBy($thisUser)}
|
||||
<script>
|
||||
function onWallAsGroupClick(el) {
|
||||
_display = el.checked ? "block" : "none";
|
||||
document.querySelector("#forceSignOpt").style.display = _display;
|
||||
document.querySelector("#forceSignOpt").style.display = el.checked ? "block" : "none";
|
||||
|
||||
{if $anonEnabled}
|
||||
document.querySelector("#octoberAnonOpt").style.display = el.checked ? "none" : "block";
|
||||
{/if}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -27,6 +32,10 @@
|
|||
{/if}
|
||||
{/if}
|
||||
|
||||
<label n:if="$anonEnabled" id="octoberAnonOpt">
|
||||
<input type="checkbox" name="anon" /> Анонимно
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="nsfw" /> {_"contains_nsfw"}
|
||||
</label>
|
||||
|
|
|
@ -119,6 +119,8 @@ routes:
|
|||
handler: "Photos->uploadPhoto"
|
||||
- url: "/photo{num}_{num}"
|
||||
handler: "Photos->photo"
|
||||
- url: "/photos/{text}"
|
||||
handler: "Photos->absolutePhoto"
|
||||
- url: "/photo{num}_{num}/edit"
|
||||
handler: "Photos->editPhoto"
|
||||
- url: "/photo{num}_{num}/delete"
|
||||
|
|
3
install/sqls/00011-anonymous-posting.sql
Normal file
3
install/sqls/00011-anonymous-posting.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE `posts` ADD `anonymous` BOOLEAN NOT NULL DEFAULT FALSE AFTER `pinned`;
|
||||
ALTER TABLE `videos` ADD `anonymous` BOOLEAN NOT NULL DEFAULT FALSE AFTER `unlisted`;
|
||||
ALTER TABLE `photos` ADD `anonymous` BOOLEAN NOT NULL DEFAULT FALSE AFTER `hash`;
|
|
@ -34,6 +34,9 @@ openvk:
|
|||
messages:
|
||||
strict: false
|
||||
wall:
|
||||
anonymousPosting:
|
||||
enable: true
|
||||
account: 2
|
||||
postSizes:
|
||||
maxSize: 60000
|
||||
processingLimit: 3000
|
||||
|
|
Loading…
Reference in a new issue