mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-09-12 13:52:01 +00:00
implement formatted post preview
This commit is contained in:
parent
95c8288558
commit
f3747ab3a3
44
src/application/controller/api/post/preview.php
Normal file
44
src/application/controller/api/post/preview.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Internal server error'),
|
||||
'filter' => '',
|
||||
'format' => '',
|
||||
];
|
||||
|
||||
if (isset($_SESSION['userName'])) {
|
||||
|
||||
if (isset($_POST['message'])) {
|
||||
|
||||
$filter = Filter::post($_POST['message']);
|
||||
$format = Format::post($filter);
|
||||
|
||||
$response = [
|
||||
'success' => true,
|
||||
'message' => _('Success'),
|
||||
'filter' => $filter,
|
||||
'format' => $format,
|
||||
];
|
||||
} else {
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Message required'),
|
||||
'filter' => '',
|
||||
'format' => '',
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$response = [
|
||||
'success' => false,
|
||||
'message' => _('Session expired. Please, reload the page.'),
|
||||
'filter' => '',
|
||||
'format' => '',
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($response);
|
@ -1,13 +1,18 @@
|
||||
<div class="modulePost" id="modulePost">
|
||||
<form action="/" method="POST" name="post">
|
||||
<div class="avatar">
|
||||
<img src="" alt="" />
|
||||
<img src="" alt="" id="modulePostAvatar" />
|
||||
</div>
|
||||
<div class="message">
|
||||
<textarea name="post" placeholder="<?php echo _('Enter your post...') ?>"></textarea>
|
||||
<textarea name="post" placeholder="<?php echo _('Enter your post...') ?>" id="modulePostMessage"></textarea>
|
||||
</div>
|
||||
<div class="preview" id="modulePostPreview">
|
||||
<div class="title">
|
||||
<i class="bi bi-chat-right-dots" title="<?php echo _('Preview') ?>"></i>
|
||||
</div>
|
||||
<div class="text"></div>
|
||||
</div>
|
||||
<div class="action">
|
||||
<div class="button" onclick="ModulePost.add()"><?php echo _('Send') ?></div>
|
||||
<div class="button" id="modulePostSend"><?php echo _('Send') ?></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -101,6 +101,9 @@ if (isset($_GET['_route_'])) {
|
||||
case 'api/post/get':
|
||||
require(PROJECT_DIR . '/application/controller/api/post/get.php');
|
||||
break;
|
||||
case 'api/post/preview':
|
||||
require(PROJECT_DIR . '/application/controller/api/post/preview.php');
|
||||
break;
|
||||
case 'api/follow/total':
|
||||
require(PROJECT_DIR . '/application/controller/api/follow/total.php');
|
||||
break;
|
||||
|
@ -51,6 +51,28 @@
|
||||
height: 90px;
|
||||
}
|
||||
|
||||
.modulePost .preview {
|
||||
color: #ccd3df;
|
||||
font-size: 12px;
|
||||
border-top: 1px #4d5666 solid;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.modulePost .preview .title {
|
||||
float: left;
|
||||
padding: 16px;
|
||||
width: 78px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.modulePost .preview .title i {
|
||||
margin: 0 auto
|
||||
}
|
||||
|
||||
.modulePost .preview .text {
|
||||
padding: 16px 16px 16px 90px;
|
||||
}
|
||||
|
||||
.modulePost .button {
|
||||
float: right;
|
||||
padding: 6px 16px;
|
||||
@ -65,9 +87,3 @@
|
||||
.modulePost .button:hover {
|
||||
background-color: #437baa
|
||||
}
|
||||
|
||||
.modulePost .content {
|
||||
background: rgb(89,99,116);
|
||||
border-radius: 3px;
|
||||
padding: 16px;
|
||||
}
|
@ -2,7 +2,6 @@ $(document).ready(function() {
|
||||
|
||||
// Init modules
|
||||
ModuleMenu.init('/');
|
||||
ModulePost.init('#modulePost');
|
||||
ModuleFeed.load('#moduleFeed', true);
|
||||
//ModuleUsers.load('#moduleUsers', true);
|
||||
|
||||
|
@ -2,25 +2,31 @@
|
||||
|
||||
class Filter {
|
||||
|
||||
public static function userName(mixed $userName) {
|
||||
public static function userName(mixed $string) {
|
||||
|
||||
return preg_replace('/[^a-zA-Z0-9_]+/u', '', $userName);
|
||||
$string = preg_replace('/[^a-zA-Z0-9_]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 16);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function userPrivateKey(mixed $userPrivateKey) {
|
||||
public static function userPrivateKey(mixed $string) {
|
||||
|
||||
return preg_replace('/[^a-zA-Z0-9_]+/u', '', $userPrivateKey);
|
||||
return preg_replace('/[^a-zA-Z0-9_]+/u', '', $string);
|
||||
}
|
||||
|
||||
public static function blockHash(mixed $blockHash) {
|
||||
public static function blockHash(mixed $string) {
|
||||
|
||||
return preg_replace('/[^a-zA-Z0-9]+/u', '', $blockHash);
|
||||
return preg_replace('/[^a-zA-Z0-9]+/u', '', $string);
|
||||
}
|
||||
|
||||
public static function fullName(string $string) {
|
||||
|
||||
$string = preg_replace('/[^\s\w]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 200);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -28,6 +34,8 @@ class Filter {
|
||||
|
||||
$string = preg_replace('/[^\s\w\.\,]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 200);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -35,6 +43,8 @@ class Filter {
|
||||
|
||||
$string = preg_replace('/[^\w\?\&\=\.\:\/]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 200);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -42,6 +52,8 @@ class Filter {
|
||||
|
||||
$string = preg_replace('/[^\w\-]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 200);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@ -49,12 +61,25 @@ class Filter {
|
||||
|
||||
$string = preg_replace('/[^\w]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 200);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function bio(string $string) {
|
||||
|
||||
$string = preg_replace('/[^\s\w\.\,\:\;\@\#\-\_\~\*\/]+/u', '', $string);
|
||||
$string = preg_replace('/[^\s\w\.\,\:\;\@\#\-\_\~\*\/\(\)\[\]]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 500);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function post(string $string) {
|
||||
|
||||
$string = preg_replace('/[^\s\w\.\,\:\;\@\#\-\_\~\*\/\(\)\[\]]+/u', '', $string);
|
||||
|
||||
$string = mb_substr($string, 0, 140);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
@ -45,8 +45,10 @@ class Format {
|
||||
}
|
||||
}
|
||||
|
||||
// Profile
|
||||
public static function bio(string $string) {
|
||||
public static function post(string $string) {
|
||||
|
||||
$string = html_entity_decode($string, ENT_QUOTES, 'UTF-8');
|
||||
$string = htmlentities($string, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$string = preg_replace("|([\s])\*([\S]+)\*([\s]?)|i", "$1<b>$2</b>$3", $string);
|
||||
$string = preg_replace("|([\s])\~([\S]+)\~([\s]?)|i", "$1<i>$2</i>$3", $string);
|
||||
|
Loading…
x
Reference in New Issue
Block a user