Changed post permalink handling
This commit is contained in:
parent
46e47f6f39
commit
37ff4705a6
12 changed files with 23 additions and 52 deletions
|
@ -4,8 +4,8 @@ dbLocation = "./data/db.sqlite"
|
||||||
dbUser = "test"
|
dbUser = "test"
|
||||||
dbPass = "test"
|
dbPass = "test"
|
||||||
cachePath = "./cache/"
|
cachePath = "./cache/"
|
||||||
filesPath = "./data/files/"
|
|
||||||
logsPath = "./data/logs/{yyyy}-{mm}.log"
|
logsPath = "./data/logs/{yyyy}-{mm}.log"
|
||||||
|
filesPath = "./public_html/files/"
|
||||||
mediaPath = "./public_html/media/"
|
mediaPath = "./public_html/media/"
|
||||||
thumbnailsPath = "./public_html/thumbs/"
|
thumbnailsPath = "./public_html/thumbs/"
|
||||||
avatarsPath = "./public_html/avatars/"
|
avatarsPath = "./public_html/avatars/"
|
||||||
|
@ -104,17 +104,6 @@ viewPost.sketchy=registered
|
||||||
viewPost.unsafe=registered
|
viewPost.unsafe=registered
|
||||||
viewPost.hidden=moderator
|
viewPost.hidden=moderator
|
||||||
|
|
||||||
;privilege to download post file, e.g. example.com/8ca21cb48aaf6ba5d361e6bebebc8cfe/retrieve
|
|
||||||
;note that the hash cannot be guessed with basic url manipulation. giving
|
|
||||||
;anonymous access in this case is reasonable - it allows privileged users to
|
|
||||||
;share permalinks with unprivileged folks, also it allows to properly feature
|
|
||||||
;posts otherwise unavailable to unregistered people.
|
|
||||||
downloadPost=anonymous
|
|
||||||
downloadPost.safe=anonymous
|
|
||||||
downloadPost.sketchy=anonymous
|
|
||||||
downloadPost.unsafe=anonymous
|
|
||||||
downloadPost.hidden=moderator
|
|
||||||
|
|
||||||
retrievePost=anonymous
|
retrievePost=anonymous
|
||||||
favoritePost=registered
|
favoritePost=registered
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ RewriteCond %{DOCUMENT_ROOT}/thumbs/$1.thumb -f
|
||||||
RewriteRule ^/?post/(.*)/thumb/?$ /thumbs/$1.thumb
|
RewriteRule ^/?post/(.*)/thumb/?$ /thumbs/$1.thumb
|
||||||
RewriteRule ^/?thumbs/(.*).thumb - [L,T=image/jpeg]
|
RewriteRule ^/?thumbs/(.*).thumb - [L,T=image/jpeg]
|
||||||
|
|
||||||
|
RewriteCond %{DOCUMENT_ROOT}/files/$1 -f
|
||||||
|
RewriteRule ^/?post/(.*)/retrieve/?$ /files/$1
|
||||||
|
RewriteRule ^/?files/(.*) - [L]
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteRule ^.*$ /dispatch.php
|
RewriteRule ^.*$ /dispatch.php
|
||||||
|
|
|
@ -36,20 +36,12 @@ class GetPostContentJob extends AbstractJob
|
||||||
|
|
||||||
public function getRequiredMainPrivilege()
|
public function getRequiredMainPrivilege()
|
||||||
{
|
{
|
||||||
return Privilege::DownloadPost;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequiredSubPrivileges()
|
public function getRequiredSubPrivileges()
|
||||||
{
|
{
|
||||||
$post = $this->postRetriever->retrieve();
|
return null;
|
||||||
$privileges = [];
|
|
||||||
|
|
||||||
if ($post->isHidden())
|
|
||||||
$privileges []= 'hidden';
|
|
||||||
|
|
||||||
$privileges []= $post->getSafety()->toString();
|
|
||||||
|
|
||||||
return $privileges;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isAuthenticationRequired()
|
public function isAuthenticationRequired()
|
||||||
|
|
|
@ -320,6 +320,7 @@ class PostController extends AbstractController
|
||||||
|
|
||||||
public function fileView($name)
|
public function fileView($name)
|
||||||
{
|
{
|
||||||
|
die;
|
||||||
$ret = Api::run(new GetPostContentJob(), [JobArgs::ARG_POST_NAME => $name]);
|
$ret = Api::run(new GetPostContentJob(), [JobArgs::ARG_POST_NAME => $name]);
|
||||||
|
|
||||||
$options = new FileRendererOptions();
|
$options = new FileRendererOptions();
|
||||||
|
|
|
@ -3,7 +3,6 @@ class Privilege extends AbstractEnum implements IEnum
|
||||||
{
|
{
|
||||||
const ListPosts = 'listPosts';
|
const ListPosts = 'listPosts';
|
||||||
const ViewPost = 'viewPost';
|
const ViewPost = 'viewPost';
|
||||||
const DownloadPost = 'downloadPost';
|
|
||||||
const RetrievePost = 'retrievePost';
|
const RetrievePost = 'retrievePost';
|
||||||
const FavoritePost = 'favoritePost';
|
const FavoritePost = 'favoritePost';
|
||||||
const HidePost = 'hidePost';
|
const HidePost = 'hidePost';
|
||||||
|
|
|
@ -360,6 +360,11 @@ final class PostEntity extends AbstractEntity implements IValidatable, ISerializ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getContentUrl()
|
||||||
|
{
|
||||||
|
return Core::getRouter()->linkTo(['PostController', 'fileView'], ['name' => $this->getName()]);
|
||||||
|
}
|
||||||
|
|
||||||
public function getThumbnailUrl()
|
public function getThumbnailUrl()
|
||||||
{
|
{
|
||||||
return Core::getRouter()->linkTo(['PostController', 'thumbnailView'], ['name' => $this->getName()]);
|
return Core::getRouter()->linkTo(['PostController', 'thumbnailView'], ['name' => $this->getName()]);
|
||||||
|
|
|
@ -63,9 +63,9 @@ class Router extends \Chibi\Routing\Router
|
||||||
$this->get('/{source}/{query}/{additionalInfo}/{page}', ['PostController', 'listView'], $postValidation);
|
$this->get('/{source}/{query}/{additionalInfo}/{page}', ['PostController', 'listView'], $postValidation);
|
||||||
$this->post('/{source}-redirect', ['PostController', 'listRedirectAction'], $postValidation);
|
$this->post('/{source}-redirect', ['PostController', 'listRedirectAction'], $postValidation);
|
||||||
|
|
||||||
$this->get('/post/{name}/retrieve', ['PostController', 'fileView'], $postValidation);
|
|
||||||
$this->get('/post/{identifier}', ['PostController', 'genericView'], $postValidation);
|
$this->get('/post/{identifier}', ['PostController', 'genericView'], $postValidation);
|
||||||
$this->get('/post/{identifier}/search={query}', ['PostController', 'genericView'], $postValidation);
|
$this->get('/post/{identifier}/search={query}', ['PostController', 'genericView'], $postValidation);
|
||||||
|
$this->get('/post/{name}/retrieve', ['PostController', 'fileView'], $postValidation);
|
||||||
$this->get('/post/{name}/thumb', ['PostController', 'thumbnailView'], $postValidation);
|
$this->get('/post/{name}/thumb', ['PostController', 'thumbnailView'], $postValidation);
|
||||||
|
|
||||||
$this->any('/post/{identifier}/toggle-tag/{tag}/{enable}', ['PostController', 'toggleTagAction'], $postValidation);
|
$this->any('/post/{identifier}/toggle-tag/{tag}/{enable}', ['PostController', 'toggleTagAction'], $postValidation);
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
$this->assets->setPageThumbnail(Core::getRouter()->linkTo(
|
|
||||||
['PostController', 'thumbnailView'],
|
|
||||||
['name' => $this->context->transport->post->getName()]));
|
|
||||||
$post = $this->context->transport->post;
|
$post = $this->context->transport->post;
|
||||||
|
$this->assets->setPageThumbnail($post->getThumbnailUrl());
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if ($post->getType()->toInteger() == PostType::Image): ?>
|
<?php if ($post->getType()->toInteger() == PostType::Image): ?>
|
||||||
|
|
||||||
<img alt="<?= $post->getName() ?>"
|
<img alt="<?= $post->getName() ?>" src="<?= $post->getContentUrl() ?>"/>
|
||||||
src="<?= Core::getRouter()->linkTo(
|
|
||||||
['PostController', 'fileView'],
|
|
||||||
['name' => $post->getName()]) ?>"/>
|
|
||||||
|
|
||||||
<?php elseif ($post->getType()->toInteger() == PostType::Flash): ?>
|
<?php elseif ($post->getType()->toInteger() == PostType::Flash): ?>
|
||||||
|
|
||||||
|
@ -18,14 +13,10 @@ $post = $this->context->transport->post;
|
||||||
type="<?= $post->getMimeType() ?>"
|
type="<?= $post->getMimeType() ?>"
|
||||||
width="<?= $post->getImageWidth() ?>"
|
width="<?= $post->getImageWidth() ?>"
|
||||||
height="<?= $post->getImageHeight() ?>"
|
height="<?= $post->getImageHeight() ?>"
|
||||||
data="<?= Core::getRouter()->linkTo(
|
data="<?= $post->getContentUrl() ?>">
|
||||||
['PostController', 'fileView'],
|
|
||||||
['name' => $post->getName()]) ?>">
|
|
||||||
|
|
||||||
<param name="wmode" value="opaque"/>
|
<param name="wmode" value="opaque"/>
|
||||||
<param name="movie" value="<?= Core::getRouter()->linkTo(
|
<param name="movie" value="<?= $post->getContentUrl() ?>"/>
|
||||||
['PostController', 'fileView'],
|
|
||||||
['name' => $post->getName()]) ?>"/>
|
|
||||||
|
|
||||||
</object>
|
</object>
|
||||||
|
|
||||||
|
@ -39,9 +30,7 @@ $post = $this->context->transport->post;
|
||||||
<video controls>
|
<video controls>
|
||||||
<source
|
<source
|
||||||
type="<?= $post->getMimeType() ?>"
|
type="<?= $post->getMimeType() ?>"
|
||||||
src="<?= Core::getRouter()->linkTo(
|
src="<?= $post->getContentUrl() ?>"/>
|
||||||
['PostController', 'fileView'],
|
|
||||||
['name' => $post->getName()]) ?>">
|
|
||||||
|
|
||||||
Your browser doesn't support HTML5 <video> tag.
|
Your browser doesn't support HTML5 <video> tag.
|
||||||
</video>
|
</video>
|
||||||
|
|
|
@ -199,9 +199,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
<div class="unit hl-options">
|
<div class="unit hl-options">
|
||||||
<?php if ($post->getType()->toInteger() != PostType::Youtube): ?>
|
<?php if ($post->getType()->toInteger() != PostType::Youtube): ?>
|
||||||
<div class="hl-option">
|
<div class="hl-option">
|
||||||
<a title="Download" href="<?= Core::getRouter()->linkTo(
|
<a title="Download" href="<?= $post->getContentUrl() ?>">
|
||||||
['PostController', 'fileView'],
|
|
||||||
['name' => $post->getName()]) ?>">
|
|
||||||
<i class="icon-dl"></i>
|
<i class="icon-dl"></i>
|
||||||
<span>
|
<span>
|
||||||
<?php
|
<?php
|
||||||
|
|
|
@ -120,10 +120,8 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
$job->setArgument(JobArgs::ARG_POST_ID, $post->getId());
|
$job->setArgument(JobArgs::ARG_POST_ID, $post->getId());
|
||||||
$job->setArgument(JobArgs::ARG_POST_NAME, $post->getName());
|
$job->setArgument(JobArgs::ARG_POST_NAME, $post->getName());
|
||||||
$job->prepare();
|
$job->prepare();
|
||||||
$this->assert->areEqual(Privilege::DownloadPost, $job->getRequiredMainPrivilege());
|
$this->assert->isNull($job->getRequiredMainPrivilege());
|
||||||
$sub = $job->getRequiredSubPrivileges();
|
$this->assert->isNull($job->getRequiredSubPrivileges());
|
||||||
natcasesort($sub);
|
|
||||||
$this->assert->areEquivalent(['hidden', 'safe'], $sub);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDynamicPostThumbnailPrivileges()
|
public function testDynamicPostThumbnailPrivileges()
|
||||||
|
@ -131,6 +129,7 @@ class ApiPrivilegeTest extends AbstractFullApiTest
|
||||||
$job = new GetPostThumbnailJob();
|
$job = new GetPostThumbnailJob();
|
||||||
$this->testedJobs []= $job;
|
$this->testedJobs []= $job;
|
||||||
$this->assert->isNull($job->getRequiredMainPrivilege());
|
$this->assert->isNull($job->getRequiredMainPrivilege());
|
||||||
|
$this->assert->isNull($job->getRequiredSubPrivileges());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDynamicUserPrivileges()
|
public function testDynamicUserPrivileges()
|
||||||
|
|
|
@ -3,7 +3,6 @@ class GetPostContentJobTest extends AbstractTest
|
||||||
{
|
{
|
||||||
public function testPostRetrieval()
|
public function testPostRetrieval()
|
||||||
{
|
{
|
||||||
$this->grantAccess('downloadPost');
|
|
||||||
$post = $this->postMocker->mockSingle();
|
$post = $this->postMocker->mockSingle();
|
||||||
|
|
||||||
$output = $this->assert->doesNotThrow(function() use ($post)
|
$output = $this->assert->doesNotThrow(function() use ($post)
|
||||||
|
@ -24,8 +23,6 @@ class GetPostContentJobTest extends AbstractTest
|
||||||
|
|
||||||
public function testIdFail()
|
public function testIdFail()
|
||||||
{
|
{
|
||||||
$this->grantAccess('downloadPost');
|
|
||||||
|
|
||||||
$this->assert->throws(function()
|
$this->assert->throws(function()
|
||||||
{
|
{
|
||||||
Api::run(
|
Api::run(
|
||||||
|
@ -38,8 +35,6 @@ class GetPostContentJobTest extends AbstractTest
|
||||||
|
|
||||||
public function testInvalidName()
|
public function testInvalidName()
|
||||||
{
|
{
|
||||||
$this->grantAccess('downloadPost');
|
|
||||||
|
|
||||||
$this->assert->throws(function()
|
$this->assert->throws(function()
|
||||||
{
|
{
|
||||||
Api::run(
|
Api::run(
|
||||||
|
|
Loading…
Reference in a new issue