work on profiles
This commit is contained in:
parent
d3eeaf6ced
commit
69e057a96e
File diff suppressed because one or more lines are too long
|
@ -39,8 +39,12 @@ section.profile {
|
||||||
h4 {
|
h4 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: rgba(0, 0, 0, 0.3);
|
color: white;
|
||||||
|
font-size: 0.75rem;
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
|
background-image: url('/assets/img/bar.jpg');
|
||||||
|
background-position: bottom center;
|
||||||
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.stats {
|
div.stats {
|
||||||
|
@ -50,9 +54,6 @@ section.profile {
|
||||||
gap: 0.25rem;
|
gap: 0.25rem;
|
||||||
|
|
||||||
& > div.cell {
|
& > div.cell {
|
||||||
color: white;
|
|
||||||
background: rgba(0, 0, 0, 0.3);
|
|
||||||
border-radius: 0.15rem;
|
|
||||||
padding: 0.25rem 0.5rem;
|
padding: 0.25rem 0.5rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -61,7 +62,6 @@ section.profile {
|
||||||
.label {
|
.label {
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: rgba(255, 255, 255, 0.75);
|
|
||||||
margin-right: 0.25rem;
|
margin-right: 0.25rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ function profile_controller_show_get($id)
|
||||||
{
|
{
|
||||||
auth_only_and_must_have_character();
|
auth_only_and_must_have_character();
|
||||||
|
|
||||||
if (($char = char_find($id)) == false) router_error(999);
|
if (($char = Character::find($id)) == false) router_error(999);
|
||||||
if (user()->char_id == $id) redirect('/profile');
|
if (user()->char_id == $id) redirect('/profile');
|
||||||
echo page('profile/show', ['char' => $char]);
|
echo page('profile/show', ['c' => $char]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,3 +296,43 @@ function all_keys_numeric(array $a): bool
|
||||||
foreach (array_keys($a) as $k) if (!is_int($k)) return false;
|
foreach (array_keys($a) as $k) if (!is_int($k)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse simple BBCode to HTML, and keep count of characters.
|
||||||
|
*/
|
||||||
|
function parse_bbcode(string $text): array
|
||||||
|
{
|
||||||
|
$html = $text;
|
||||||
|
|
||||||
|
// Store the original text without tags and whitespace for counting
|
||||||
|
$textForCounting = preg_replace('/\[.*?\]/', '', $text); // Remove BBCode tags
|
||||||
|
$textForCounting = preg_replace('/\s+/', '', $textForCounting); // Remove whitespace
|
||||||
|
$charCount = strlen($textForCounting);
|
||||||
|
|
||||||
|
// Basic BBCode conversions
|
||||||
|
$replacements = [
|
||||||
|
'/\[b\](.*?)\[\/b\]/is' => '<strong>$1</strong>',
|
||||||
|
'/\[i\](.*?)\[\/i\]/is' => '<em>$1</em>',
|
||||||
|
'/\[u\](.*?)\[\/u\]/is' => '<u>$1</u>',
|
||||||
|
'/\[url=(.*?)\](.*?)\[\/url\]/is' => '<a href="$1">$2</a>',
|
||||||
|
'/\[url\](.*?)\[\/url\]/is' => '<a href="$1">$1</a>',
|
||||||
|
//'/\[img\](.*?)\[\/img\]/is' => '<img src="$1" alt="" />',
|
||||||
|
'/\[size=([1-7])\](.*?)\[\/size\]/is' => '<font size="$1">$2</font>',
|
||||||
|
'/\[color=(#[A-F0-9]{6}|[a-z]+)\](.*?)\[\/color\]/is' => '<span style="color:$1">$2</span>',
|
||||||
|
'/\[quote\](.*?)\[\/quote\]/is' => '<blockquote>$1</blockquote>',
|
||||||
|
'/\[code\](.*?)\[\/code\]/is' => '<pre><code>$1</code></pre>',
|
||||||
|
'/\[list\](.*?)\[\/list\]/is' => '<ul>$1</ul>',
|
||||||
|
'/\[list=1\](.*?)\[\/list\]/is' => '<ol>$1</ol>',
|
||||||
|
'/\[\*\](.*?)(?=\[\*\]|\[\/list\])/is' => '<li>$1</li>'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($replacements as $pattern => $replacement) $html = preg_replace($pattern, $replacement, $html);
|
||||||
|
|
||||||
|
// Convert newlines to <br> tags
|
||||||
|
$html = nl2br($html);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'html' => $html,
|
||||||
|
'char_count' => $charCount
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,11 @@ class Character
|
||||||
public int $att_points;
|
public int $att_points;
|
||||||
public string $bio;
|
public string $bio;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The owning User of this Character. Is populated the first time user() is called.
|
||||||
|
*/
|
||||||
|
private User $user;
|
||||||
|
|
||||||
public function __construct(array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
foreach ($data as $k => $v) {
|
foreach ($data as $k => $v) {
|
||||||
|
@ -62,6 +67,9 @@ class Character
|
||||||
{
|
{
|
||||||
// Prep the data and merge in any overrides
|
// Prep the data and merge in any overrides
|
||||||
$data = ['user_id' => $user_id, 'name' => $name];
|
$data = ['user_id' => $user_id, 'name' => $name];
|
||||||
|
if (env('debug')) {
|
||||||
|
$overrides['bio'] = "Hello! [i]My[/i] name is [b]{$name}[/b].";
|
||||||
|
}
|
||||||
if (!empty($overrides)) $data = array_merge($data, $overrides);
|
if (!empty($overrides)) $data = array_merge($data, $overrides);
|
||||||
|
|
||||||
// Prep the fields for the query
|
// Prep the fields for the query
|
||||||
|
@ -137,7 +145,9 @@ class Character
|
||||||
*/
|
*/
|
||||||
public function user(): User|false
|
public function user(): User|false
|
||||||
{
|
{
|
||||||
return User::find($this->user_id);
|
if (!empty($this->user)) return $this->user;
|
||||||
|
$u = User::find($this->user_id);
|
||||||
|
return $u !== false ? $this->user = $u : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<header>
|
<header>
|
||||||
<h1><?= char()->name ?></h1>
|
<h1><?= char()->name ?></h1>
|
||||||
<h3>Level <?= char()->level ?> <?= char()->title()['name'] ?></h3>
|
<h3>Level <?= char()->level ?> <?= char()->title()['name'] ?></h3>
|
||||||
<h4>You</h4>
|
<h5>You</h5>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<section class="right">
|
<section class="right">
|
||||||
<div class="bio">
|
<div class="bio">
|
||||||
<h4>Biography</h4>
|
<h4>Biography</h4>
|
||||||
<?= char()->bio ?>
|
<?= !empty(char()->bio) ? parse_bbcode(char()->bio)['html'] : "<i>[No bio.]</i>" ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="gear">
|
<div class="gear">
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<section class="profile">
|
<section class="profile">
|
||||||
<header>
|
<header>
|
||||||
<h1><?= $char['name'] ?></h1>
|
<h1><?= $c->name ?></h1>
|
||||||
<h3>Level <?= $char['level'] ?> <?= char_get_title($char['id'])['name'] ?></h3>
|
<h3>Level <?= $c->level ?> <?= $c->title()['name'] ?></h3>
|
||||||
<h4>owned by <?= $char['user_id'] === user()->id ? 'you' : char_get_user($char)['username'] ?></h4>
|
<h5>owned by <?= $c->user_id === user()->id ? 'you' : $c->user()->username ?></h5>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
@ -11,12 +11,33 @@
|
||||||
<img src="/assets/img/rathalos.webp">
|
<img src="/assets/img/rathalos.webp">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?= c_profile_stats($char) ?>
|
<?= c_profile_stats($c) ?>
|
||||||
|
|
||||||
|
<div class="badges">
|
||||||
|
<h4>Badges</h4>
|
||||||
|
@TODO
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="traits">
|
||||||
|
<h4>Traits</h4>
|
||||||
|
@TODO
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="right">
|
<section class="right">
|
||||||
<div class="bio">
|
<div class="bio">
|
||||||
HELLO THERE MY FRIEND.
|
<h4>Biography</h4>
|
||||||
|
<?= !empty($c->bio) ? parse_bbcode($c->bio)['html'] : "<i>[No bio.]</i>" ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gear">
|
||||||
|
<h4>Equipped Gear</h4>
|
||||||
|
@TODO
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inv">
|
||||||
|
<h4>Inventory</h4>
|
||||||
|
@TODO
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user