This commit is contained in:
flash 2020-10-16 19:24:40 +00:00
parent 2f71fa5e62
commit 2e222021b9
5 changed files with 73 additions and 15 deletions

View file

@ -107,7 +107,7 @@ function ytknsEditorPreview(zoneInfo) {
var formElement = document.createElement('form'); var formElement = document.createElement('form');
formElement.action = '/zones/_preview'; formElement.action = '/zones/_preview';
formElement.method = 'post'; formElement.method = 'post';
formElement.target = '_blank'; formElement.target = ytknsEditorSBS ? 'preview' : '_blank';
formElement.style.display = 'none'; formElement.style.display = 'none';
var elements = ytknsZoneInfoSerialise(zoneInfo, function(name, value) { var elements = ytknsZoneInfoSerialise(zoneInfo, function(name, value) {
@ -154,7 +154,8 @@ var ytknsZoneInfo = null,
ytknsEditorElemMainContainer = null, ytknsEditorElemMainContainer = null,
ytknsEditorEffects = [], ytknsEditorEffects = [],
ytknsEditorIgnoreHashChange = false, ytknsEditorIgnoreHashChange = false,
ytknsEditorCleanExit = true; ytknsEditorCleanExit = true,
ytknsEditorSBS = false;
function ytknsEditorChangeHash(hash) { function ytknsEditorChangeHash(hash) {
ytknsEditorIgnoreHashChange = true; ytknsEditorIgnoreHashChange = true;
@ -877,6 +878,9 @@ function ytknsEditorMainSetContainer(child, title) {
ytknsEditorElemMainContainer.innerHTML = ''; ytknsEditorElemMainContainer.innerHTML = '';
ytknsEditorElemMainContainer.appendChild(child); ytknsEditorElemMainContainer.appendChild(child);
if(ytknsEditorSBS)
ytknsEditorPreview(ytknsZoneInfo);
} }
function ytknsEditorMainClone() { function ytknsEditorMainClone() {
return { return {
@ -1025,7 +1029,7 @@ function ytknsEditorHashChange(ev) {
ytknsEditorIgnoreHashChange = false; ytknsEditorIgnoreHashChange = false;
} }
function ytknsEditorMain(container, zoneId, editorToken, uploadToken) { function ytknsEditorMain(container, zoneId, editorToken, uploadToken, sideBySide) {
if(navigator.userAgent.match(/mobile/gi) && !confirm("The editor is not designed to be used on phones whatsoever.\r\nHit OK to continue anyway or cancel to whereever you came from.")) { if(navigator.userAgent.match(/mobile/gi) && !confirm("The editor is not designed to be used on phones whatsoever.\r\nHit OK to continue anyway or cancel to whereever you came from.")) {
history.go(-1); history.go(-1);
return; return;
@ -1035,6 +1039,7 @@ function ytknsEditorMain(container, zoneId, editorToken, uploadToken) {
window.onbeforeunload = ytknsEditorBeforeUnload; window.onbeforeunload = ytknsEditorBeforeUnload;
ytknsEditorToken = editorToken; ytknsEditorToken = editorToken;
ytknsEditorUploadToken = uploadToken; ytknsEditorUploadToken = uploadToken;
ytknsEditorSBS = sideBySide;
container.innerHTML = ''; container.innerHTML = '';
container.classList.add('ye'); container.classList.add('ye');

View file

@ -41,6 +41,7 @@ function html_header(array $vars = []): string {
['text' => 'Home', 'link' => page_url('/')], ['text' => 'Home', 'link' => page_url('/')],
['text' => 'Create a Zone', 'link' => page_url('/zones/create')], ['text' => 'Create a Zone', 'link' => page_url('/zones/create')],
['text' => 'Zones', 'link' => page_url('/zones')], ['text' => 'Zones', 'link' => page_url('/zones')],
['text' => 'Random', 'link' => page_url('/zones/random')],
]); ]);
$userMenu = []; $userMenu = [];
@ -313,6 +314,12 @@ if($reqPath === '/zones') {
return; return;
} }
if($reqPath === '/zones/random') {
$zoneInfo = Zone::byRandom();
header('Location: ' . $zoneInfo->getUrl());
return;
}
if($reqPath === '/zones/create') { if($reqPath === '/zones/create') {
if(!UserSession::hasInstance()) { if(!UserSession::hasInstance()) {
http_response_code(403); http_response_code(403);
@ -501,6 +508,14 @@ if(preg_match('#^/zones/([0-9]+)/delete$#', $reqPath, $matches)) {
return; return;
} }
if(preg_match('#^/zones/([0-9]+)/sbs$#', $reqPath, $matches)) {
echo '<!doctype html>';
echo '<meta charset="utf-8"/><title>YTKNS Side By Side Editor</title>';
echo '<iframe name="preview" style="position: absolute; top: 0; left: 0; bottom: 0; height: 100%; width: 70%; border-width: 0;"></iframe>';
echo '<iframe name="editor" src="/zones/' . $matches[1] . '" style="position: absolute; top: 0; right: 0; bottom: 0; height: 100%; width: 30%; border-width: 0;"></iframe>';
return;
}
if(preg_match('#^/zones/([0-9]+)$#', $reqPath, $matches)) { if(preg_match('#^/zones/([0-9]+)$#', $reqPath, $matches)) {
if(!UserSession::hasInstance()) { if(!UserSession::hasInstance()) {
http_response_code(403); http_response_code(403);
@ -523,15 +538,24 @@ if(preg_match('#^/zones/([0-9]+)$#', $reqPath, $matches)) {
return; return;
} }
$isSBS = !empty($_GET['sbs']);
$cssHash = hash_file('sha256', YTKNS_PUB . '/assets/editor.css'); $cssHash = hash_file('sha256', YTKNS_PUB . '/assets/editor.css');
$jsHash = hash_file('sha256', YTKNS_PUB . '/assets/editor.js'); $jsHash = hash_file('sha256', YTKNS_PUB . '/assets/editor.js');
echo html_header([ if($isSBS) {
'title' => 'Editing Zone - YTKNS', echo '<!doctype html>';
'styles' => [ echo '<link href="/assets/style.css" type="text/css" rel="stylesheet"/>';
page_url('/assets/editor.css', ['v' => $cssHash]), echo '<link href="/assets/editor.css?v=' . $cssHash . '" type="text/css" rel="stylesheet"/>';
], echo '<style>.ye { height: 100%; width: 100%; } .ye-sidebar { min-width: 200px; }</style>';
]); } else {
echo html_header([
'title' => 'Editing Zone - YTKNS',
'styles' => [
page_url('/assets/editor.css', ['v' => $cssHash]),
],
]);
}
Template::render('zones/edit', [ Template::render('zones/edit', [
'edit_id' => $zoneInfo->getId(), 'edit_id' => $zoneInfo->getId(),
'edit_token' => UserSession::instance()->getSmallToken(10), 'edit_token' => UserSession::instance()->getSmallToken(10),
@ -539,11 +563,24 @@ if(preg_match('#^/zones/([0-9]+)$#', $reqPath, $matches)) {
'edit_js_ver' => substr($jsHash, 0, 16), 'edit_js_ver' => substr($jsHash, 0, 16),
'upload_token' => UserSession::instance()->getSmallToken(6), 'upload_token' => UserSession::instance()->getSmallToken(6),
]); ]);
echo html_footer([
'scripts' => [ if($isSBS) {
page_url('/assets/editor.js', ['v' => $jsHash]), echo '<script type="text/javascript" charset="utf-8" src="/assets/editor.js?v=' . $jsHash . '"></script>';
], } else {
]); echo <<<HTML
<script>
window.addEventListener('DOMContentLoaded', function() {
if(window.location !== window.parent.location)
location.assign(location.toString() + '?sbs=1');
});
</script>
HTML;
echo html_footer([
'scripts' => [
page_url('/assets/editor.js', ['v' => $jsHash]),
],
]);
}
return; return;
} }

View file

@ -6,6 +6,7 @@ use YTKNS\HtmlTag;
use YTKNS\HtmlText; use YTKNS\HtmlText;
use YTKNS\PageBuilder; use YTKNS\PageBuilder;
use YTKNS\PageEffectInterface; use YTKNS\PageEffectInterface;
use YTKNS\PageEffectException;
use YTKNS\Upload; use YTKNS\Upload;
use YTKNS\UploadNotFoundException; use YTKNS\UploadNotFoundException;

View file

@ -190,6 +190,19 @@ final class Zone {
return $zone; return $zone;
} }
public static function byRandom(): self {
$getZone = DB::prepare('
SELECT `zone_id`, `user_id`, `zone_name`, `zone_title`, `zone_views`,
UNIX_TIMESTAMP(`zone_created`) AS `zone_created`,
UNIX_TIMESTAMP(`zone_updated`) AS `zone_updated`
FROM `ytkns_zones`
ORDER BY RAND()
LIMIT 1
');
$zone = $getZone->execute() ? $getZone->fetchObject(self::class) : null;
return $zone;
}
public static function byName(string $name): self { public static function byName(string $name): self {
$getZone = DB::prepare(' $getZone = DB::prepare('
SELECT `zone_id`, `user_id`, `zone_name`, `zone_title`, `zone_views`, SELECT `zone_id`, `user_id`, `zone_name`, `zone_title`, `zone_views`,

View file

@ -13,7 +13,9 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
window.onload = function() { window.onload = function() {
document.getElementById('ytkns-footer').appendChild(document.createTextNode('| JS: :edit_js_ver | CSS: :edit_css_ver')); var footer = document.getElementById('ytkns-footer');
if(footer)
footer.appendChild(document.createTextNode('| JS: :edit_js_ver | CSS: :edit_css_ver'));
ytknsEditorMain( ytknsEditorMain(
document.getElementById('editor'), document.getElementById('editor'),