Work in progress.
This commit is contained in:
parent
af60ea5693
commit
d52cb3af63
8 changed files with 70 additions and 112 deletions
|
@ -5,6 +5,7 @@
|
||||||
&__sidebar {
|
&__sidebar {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
margin-left: 2px;
|
margin-left: 2px;
|
||||||
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__main {
|
&__main {
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Misuzu\Parsers\BBCode;
|
namespace Misuzu\Parsers\BBCode;
|
||||||
|
|
||||||
use Misuzu\Parsers\Parser;
|
use Misuzu\Parsers\ParserInterface;
|
||||||
|
|
||||||
final class BBCodeParser extends Parser
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
|
*/
|
||||||
|
class BBCodeParser implements ParserInterface
|
||||||
{
|
{
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
public static function instance(): BBCodeParser
|
||||||
|
{
|
||||||
|
return is_null(static::$instance) ? (static::$instance = new BBCodeParser()) : static::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
private $tags = [];
|
private $tags = [];
|
||||||
|
|
||||||
public function __construct(array $tags = [])
|
public function __construct(array $tags = [])
|
||||||
{
|
{
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
if (empty($tags)) {
|
if (empty($tags)) {
|
||||||
$tags = [
|
$tags = [
|
||||||
// Advanced markup
|
// Advanced markup
|
||||||
|
@ -48,4 +56,9 @@ final class BBCodeParser extends Parser
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function parseLine(string $line): string
|
||||||
|
{
|
||||||
|
return $this->parseText($line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,15 @@ namespace Misuzu\Parsers;
|
||||||
|
|
||||||
use Parsedown;
|
use Parsedown;
|
||||||
|
|
||||||
final class MarkdownParser extends Parser
|
class MarkdownParser extends Parsedown implements ParserInterface
|
||||||
{
|
{
|
||||||
private $parsedown;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->parsedown = new Parsedown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parseText(string $text): string
|
public function parseText(string $text): string
|
||||||
{
|
{
|
||||||
return $this->parsedown->text($text);
|
return $this->text($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parseLine(string $line): string
|
||||||
|
{
|
||||||
|
return $this->line($line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Misuzu\Parsers;
|
|
||||||
|
|
||||||
abstract class Parser
|
|
||||||
{
|
|
||||||
private static $instances = [];
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
self::$instances[static::class] = $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getInstance(): ?Parser
|
|
||||||
{
|
|
||||||
if (!array_key_exists(static::class, self::$instances)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::$instances[static::class];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getOrCreateInstance(...$args): Parser
|
|
||||||
{
|
|
||||||
$instance = static::getInstance();
|
|
||||||
|
|
||||||
if ($instance === null) {
|
|
||||||
$instance = new static(...$args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function parseText(string $text): string;
|
|
||||||
}
|
|
8
src/Parsers/ParserInterface.php
Normal file
8
src/Parsers/ParserInterface.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\Parsers;
|
||||||
|
|
||||||
|
interface ParserInterface
|
||||||
|
{
|
||||||
|
public function parseText(string $text): string;
|
||||||
|
public function parseLine(string $line): string;
|
||||||
|
}
|
|
@ -80,9 +80,9 @@ function zalgo_run(
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
$going_up = has_flag($direction, MSZ_ZALGO_DIR_UP);
|
$going_up = ($direction & MSZ_ZALGO_DIR_UP) > 0;
|
||||||
$going_mid = has_flag($direction, MSZ_ZALGO_DIR_MID);
|
$going_mid = ($direction & MSZ_ZALGO_DIR_MID) > 0;
|
||||||
$going_down = has_flag($direction, MSZ_ZALGO_DIR_DOWN);
|
$going_down = ($direction & MSZ_ZALGO_DIR_DOWN) > 0;
|
||||||
|
|
||||||
$str = '';
|
$str = '';
|
||||||
|
|
||||||
|
|
46
utility.php
46
utility.php
|
@ -1,29 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// both of these are provided by illuminate/database already
|
|
||||||
// but i feel like it makes sense to add these definitions regardless
|
|
||||||
|
|
||||||
if (!function_exists('starts_with')) {
|
|
||||||
function starts_with(string $string, string $text): bool
|
function starts_with(string $string, string $text): bool
|
||||||
{
|
{
|
||||||
return substr($string, 0, strlen($text)) === $text;
|
return substr($string, 0, strlen($text)) === $text;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('ends_with')) {
|
|
||||||
function ends_with(string $string, string $text): bool
|
function ends_with(string $string, string $text): bool
|
||||||
{
|
{
|
||||||
return substr($string, 0 - strlen($text)) === $text;
|
return substr($string, 0 - strlen($text)) === $text;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function json_encode_m($obj): string
|
|
||||||
{
|
|
||||||
if (!headers_sent()) {
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode($obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_cookie_m(string $name, string $value, int $expires): void
|
function set_cookie_m(string $name, string $value, int $expires): void
|
||||||
{
|
{
|
||||||
|
@ -54,20 +38,6 @@ function dechex_pad(int $value, int $padding = 2): string
|
||||||
return str_pad(dechex($value), $padding, '0', STR_PAD_LEFT);
|
return str_pad(dechex($value), $padding, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
function array_rand_value(array $array, $fallback = null)
|
|
||||||
{
|
|
||||||
if (!$array) {
|
|
||||||
return $fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array[array_rand($array)];
|
|
||||||
}
|
|
||||||
|
|
||||||
function has_flag(int $flags, int $flag): bool
|
|
||||||
{
|
|
||||||
return ($flags & $flag) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function byte_symbol($bytes, $decimal = false)
|
function byte_symbol($bytes, $decimal = false)
|
||||||
{
|
{
|
||||||
if ($bytes < 1) {
|
if ($bytes < 1) {
|
||||||
|
@ -84,12 +54,12 @@ function byte_symbol($bytes, $decimal = false)
|
||||||
return sprintf("%.2f %s%sB", $bytes, $symbol, $symbol !== '' && !$decimal ? 'i' : '');
|
return sprintf("%.2f %s%sB", $bytes, $symbol, $symbol !== '' && !$decimal ? 'i' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// this should be rewritten to only load the database once per Application instance.
|
|
||||||
// for now this will do since the only time this function is called is once during registration.
|
|
||||||
// also make sure an instance of Application with config exists before calling this!
|
|
||||||
function get_country_code(string $ipAddr, string $fallback = 'XX'): string
|
function get_country_code(string $ipAddr, string $fallback = 'XX'): string
|
||||||
{
|
{
|
||||||
|
global $_msz_geoip;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (!$_msz_geoip) {
|
||||||
$app = \Misuzu\Application::getInstance();
|
$app = \Misuzu\Application::getInstance();
|
||||||
$config = $app->getConfig();
|
$config = $app->getConfig();
|
||||||
|
|
||||||
|
@ -103,8 +73,10 @@ function get_country_code(string $ipAddr, string $fallback = 'XX'): string
|
||||||
return $fallback;
|
return $fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
$geoip = new \GeoIp2\Database\Reader($database_path);
|
$_msz_geoip = new \GeoIp2\Database\Reader($database_path);
|
||||||
$record = $geoip->country($ipAddr);
|
}
|
||||||
|
|
||||||
|
$record = $_msz_geoip->country($ipAddr);
|
||||||
|
|
||||||
return $record->country->isoCode;
|
return $record->country->isoCode;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -223,12 +195,12 @@ function pdo_prepare_array(array $keys, bool $useKeys = false, string $format =
|
||||||
|
|
||||||
function parse_markdown(string $text): string
|
function parse_markdown(string $text): string
|
||||||
{
|
{
|
||||||
return \Misuzu\Parsers\MarkdownParser::getOrCreateInstance()->parseText($text);
|
return \Misuzu\Parsers\MarkdownParser::instance()->parseText($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_bbcode(string $text): string
|
function parse_bbcode(string $text): string
|
||||||
{
|
{
|
||||||
return \Misuzu\Parsers\BBCode\BBCodeParser::getOrCreateInstance()->parseText($text);
|
return \Misuzu\Parsers\BBCode\BBCodeParser::instance()->parseText($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_error(int $code, string $template = 'errors.%d'): string
|
function render_error(int $code, string $template = 'errors.%d'): string
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
<div class="container__content news__preview__content">
|
<div class="container__content news__preview__content">
|
||||||
<div class="news__preview__text">
|
<div class="news__preview__text">
|
||||||
{{ post.post_text|first_paragraph|raw }}
|
{{ post.post_text|first_paragraph|md|raw }}
|
||||||
<p><b><i><a href="/news.php?p={{ post.post_id }}">View full post</a></i></b></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="news__preview__info">
|
<div class="news__preview__info">
|
||||||
|
@ -15,12 +14,14 @@
|
||||||
{{ post.created_at|time_diff }}
|
{{ post.created_at|time_diff }}
|
||||||
</time>
|
</time>
|
||||||
|
|
||||||
|
{% if post.user_id is not null %}
|
||||||
<a class="news__preview__user" href="/profile.php?u={{ post.user_id }}">
|
<a class="news__preview__user" href="/profile.php?u={{ post.user_id }}">
|
||||||
<div class="news__preview__user__name" style="{{ post.user_colour|html_colour }}">
|
<div class="news__preview__user__name" style="{{ post.user_colour|html_colour }}">
|
||||||
{{ post.username }}
|
{{ post.username }}
|
||||||
</div>
|
</div>
|
||||||
<div class="avatar news__preview__user__avatar" style="background-image:url('/profile.php?u={{ post.user_id }}&m=avatar')"></div>
|
<div class="avatar news__preview__user__avatar" style="background-image:url('/profile.php?u={{ post.user_id }}&m=avatar')"></div>
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue