Browse Source

implement formatted post preview

main
ghost 3 years ago
parent
commit
f3747ab3a3
  1. 44
      src/application/controller/api/post/preview.php
  2. 13
      src/application/view/common/module/post.phtml
  3. 3
      src/bootstrap.php
  4. 28
      src/public/css/template/default/module/post.css
  5. 1
      src/public/js/home.js
  6. 39
      src/system/helper/filter.php
  7. 6
      src/system/helper/format.php

44
src/application/controller/api/post/preview.php

@ -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);

13
src/application/view/common/module/post.phtml

@ -1,13 +1,18 @@
<div class="modulePost" id="modulePost"> <div class="modulePost" id="modulePost">
<form action="/" method="POST" name="post"> <form action="/" method="POST" name="post">
<div class="avatar"> <div class="avatar">
<img src="" alt="" /> <img src="" alt="" id="modulePostAvatar" />
</div> </div>
<div class="message"> <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>
<div class="action"> <div class="action">
<div class="button" onclick="ModulePost.add()"><?php echo _('Send') ?></div> <div class="button" id="modulePostSend"><?php echo _('Send') ?></div>
</div> </div>
</form>
</div> </div>

3
src/bootstrap.php

@ -101,6 +101,9 @@ if (isset($_GET['_route_'])) {
case 'api/post/get': case 'api/post/get':
require(PROJECT_DIR . '/application/controller/api/post/get.php'); require(PROJECT_DIR . '/application/controller/api/post/get.php');
break; break;
case 'api/post/preview':
require(PROJECT_DIR . '/application/controller/api/post/preview.php');
break;
case 'api/follow/total': case 'api/follow/total':
require(PROJECT_DIR . '/application/controller/api/follow/total.php'); require(PROJECT_DIR . '/application/controller/api/follow/total.php');
break; break;

28
src/public/css/template/default/module/post.css

@ -51,6 +51,28 @@
height: 90px; 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 { .modulePost .button {
float: right; float: right;
padding: 6px 16px; padding: 6px 16px;
@ -65,9 +87,3 @@
.modulePost .button:hover { .modulePost .button:hover {
background-color: #437baa background-color: #437baa
} }
.modulePost .content {
background: rgb(89,99,116);
border-radius: 3px;
padding: 16px;
}

1
src/public/js/home.js

@ -2,7 +2,6 @@ $(document).ready(function() {
// Init modules // Init modules
ModuleMenu.init('/'); ModuleMenu.init('/');
ModulePost.init('#modulePost');
ModuleFeed.load('#moduleFeed', true); ModuleFeed.load('#moduleFeed', true);
//ModuleUsers.load('#moduleUsers', true); //ModuleUsers.load('#moduleUsers', true);

39
src/system/helper/filter.php

@ -2,25 +2,31 @@
class Filter { 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) { public static function fullName(string $string) {
$string = preg_replace('/[^\s\w]+/u', '', $string); $string = preg_replace('/[^\s\w]+/u', '', $string);
$string = mb_substr($string, 0, 200);
return $string; return $string;
} }
@ -28,6 +34,8 @@ class Filter {
$string = preg_replace('/[^\s\w\.\,]+/u', '', $string); $string = preg_replace('/[^\s\w\.\,]+/u', '', $string);
$string = mb_substr($string, 0, 200);
return $string; return $string;
} }
@ -35,6 +43,8 @@ class Filter {
$string = preg_replace('/[^\w\?\&\=\.\:\/]+/u', '', $string); $string = preg_replace('/[^\w\?\&\=\.\:\/]+/u', '', $string);
$string = mb_substr($string, 0, 200);
return $string; return $string;
} }
@ -42,6 +52,8 @@ class Filter {
$string = preg_replace('/[^\w\-]+/u', '', $string); $string = preg_replace('/[^\w\-]+/u', '', $string);
$string = mb_substr($string, 0, 200);
return $string; return $string;
} }
@ -49,12 +61,25 @@ class Filter {
$string = preg_replace('/[^\w]+/u', '', $string); $string = preg_replace('/[^\w]+/u', '', $string);
$string = mb_substr($string, 0, 200);
return $string; return $string;
} }
public static function bio(string $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; return $string;
} }

6
src/system/helper/format.php

@ -45,8 +45,10 @@ class Format {
} }
} }
// Profile public static function post(string $string) {
public static function bio(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<b>$2</b>$3", $string);
$string = preg_replace("|([\s])\~([\S]+)\~([\s]?)|i", "$1<i>$2</i>$3", $string); $string = preg_replace("|([\s])\~([\S]+)\~([\s]?)|i", "$1<i>$2</i>$3", $string);

Loading…
Cancel
Save