Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Mentions: Re-Extended #1097

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
153 changes: 153 additions & 0 deletions app/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ function parse($text, &$pings = null) {
$text = parseCharacters($text, $characters);
$text = parseCharacterThumbs($text, $characters);
$text = parseGalleryThumbs($text, $submissions);
$text = parseItems($text, $items);
$text = parseTraitThumbs($text, $traits);
$text = parseItemThumbs($text, $items);
$text = parsePrompts($text, $prompts);
$text = parsePromptThumbs($text, $prompts);
// $text = parseRarityThumbs($text, $rarities);
// $text = parseSpeciesThumbs($text, $specieses);
// $text = parseSubtypeThumbs($text, $subtypes);
// $text = parseShopThumbs($text, $shops);
// $text = parseCurrencyThumbs($text, $currencies);
// $text = parseCharacterCategoryThumbs($text, $charactercategories);
// $text = parsePromptCategoryThumbs($text, $promptcategories);
// $text = parseTraitCategoryThumbs($text, $traitcategories);
// $text = parseItemCategoryThumbs($text, $itemcategories);
if ($pings) {
$pings = ['users' => $users, 'characters' => $characters];
}
Expand Down Expand Up @@ -305,6 +319,145 @@ function parseCharacterThumbs($text, &$characters) {
return $text;
}

/**
* Parses a piece of user-entered text to match item mentions
* and replace with a thumbnail link.
*
* @param string $text
* @param mixed $items
*
* @return string
*/
function parseItems($text, &$items) {
$matches = null;
$items = [];
$count = preg_match_all('/\[item=([^\[\]&<>?"\']+)\]/', $text, $matches);
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$item = App\Models\Item\Item::where('id', $match)->first();
if ($item) {
$items[] = $item;
$text = preg_replace('/\[item='.$match.'\]/', '<a href="'.$item->idUrl.'"><img src="'.$item->imageUrl.'" class="mw-100" alt="'.$item->name.'"></a>', $text);
}
}
}

return $text;
}

/**
* Parses a piece of user-entered text to match trait mentions
* and replace with the trait thumbnail.
*
* @param string $text
* @param mixed $traits
*
* @return string
*/
function parseTraitThumbs($text, &$traits) {
$matches = null;
$traits = [];
$count = preg_match_all('/\[traitthumb=([^\[\]&<>?"\']+)\]/', $text, $matches);
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$trait = App\Models\Feature\Feature::where('id', $match)->first();
if ($trait) {
$traits[] = $trait;
$trait_hasimg = $trait->has_image ? '<a class="badge" style="border-radius:.5em; '.$traitbg.'" href="'.$trait->url.'"><img class="my-1 modal-image" style="max-height:100%; height:150px; border-radius:.5em;" src="'.$trait->imageUrl.'" alt="'.$trait->name.'" /></a></ br>' : '';
$traitbg = $trait->rarity->color ? 'background-color:#'.$trait->rarity->color : '';
$text = preg_replace('/\[traitthumb='.$match.'\]/', '<div class="text-center align-self-center inventory-item px-1" style="display: inline-flex; max-width:15%; flex: 0 0 15%;"><p>'.$trait_hasimg.'<a class="display-trait" href="'.$trait->url.'">'.$trait->name.'</a></p></div>', $text);
}
}
}

return $text;
}

/**
* Parses a piece of user-entered text to match item mentions
* and replace with the item thumbnail.
*
* @param string $text
* @param mixed $items
*
* @return string
*/
function parseItemThumbs($text, &$items) {
$matches = null;
$items = [];
$count = preg_match_all('/\[itemthumb=([^\[\]&<>?"\']+)\]/', $text, $matches);
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$item = App\Models\Item\Item::where('id', $match)->first();
if ($item) {
$items[] = $item;
$item_hasimg = $item->has_image ? '<a class="badge" style="border-radius:.5em;" href="'.$item->idUrl.'"><img class="my-1 modal-image" style="max-height:100%; height:150px; border-radius:.5em;" src="'.$item->imageUrl.'" alt="'.$item->name.'" /></a></ br>' : '';
$text = preg_replace('/\[itemthumb='.$match.'\]/', '<div class="text-center align-self-center inventory-item px-1" style="display: inline-flex; max-width:15%; flex: 0 0 15%;"><p>'.$item_hasimg.'<a class="inventory-stack inventory-stack-name" href="'.$item->idUrl.'">'.$item->name.'</a></p></div>', $text);
}
}
}

return $text;
}

/**
* Parses a piece of user-entered text to match prompt mentions
* and replace with the prompt image.
*
* @param string $text
* @param mixed $prompts
*
* @return string
*/
function parsePrompts($text, &$prompts) {
$matches = null;
$prompts = [];
$count = preg_match_all('/\[prompt=([^\[\]&<>?"\']+)\]/', $text, $matches);
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$prompt = App\Models\Prompt\Prompt::where('id', $match)->first();
if ($prompt) {
$prompts[] = $prompt;
$text = preg_replace('/\[prompt='.$match.'\]/', '<a href="'.$prompt->idUrl.'"><img src="'.$prompt->imageUrl.'" class="mw-100" alt="'.$prompt->name.'"></a>', $text);
}
}
}

return $text;
}

/**
* Parses a piece of user-entered text to match prompt mentions
* and replace with the prompt thumbnail.
*
* @param string $text
* @param mixed $prompts
*
* @return string
*/
function parsePromptThumbs($text, &$prompts) {
$matches = null;
$prompts = [];
$count = preg_match_all('/\[promptthumb=([^\[\]&<>?"\']+)\]/', $text, $matches);
if ($count) {
$matches = array_unique($matches[1]);
foreach ($matches as $match) {
$prompt = App\Models\Prompt\Prompt::where('id', $match)->first();
if ($prompt) {
$prompts[] = $prompt;
$prompt_hasimg = $prompt->has_image ? '<a class="badge" style="border-radius:.5em;" href="'.$prompt->idUrl.'"><img class="my-1 modal-image" style="max-height:100%; height:150px; border-radius:.5em;" src="'.$prompt->imageUrl.'" alt="'.$prompt->name.'" /></a></ br>' : '';
$text = preg_replace('/\[promptthumb='.$match.'\]/', '<div class="text-center align-self-center inventory-item px-1" style="display: inline-flex; max-width:15%; flex: 0 0 15%;"><p>'.$prompt_hasimg.'<a class="inventory-stack inventory-stack-name" href="prompts/'.$prompt->id.'">'.$prompt->name.'</a></p></div>', $text);
}
}
}

return $text;
}

/**
* Parses a piece of user-entered text to match gallery submission thumb mentions
* and replace with a link.
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Prompt/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public function getUrlAttribute() {
return url('prompts/prompts?name='.$this->name);
}

/**
* Gets the URL of the individual prompt's page, by ID.
*
* @return string
*/
public function getIdUrlAttribute() {
return url('prompts/'.$this->id);
}

/**
* Gets the prompt's asset type for asset management.
*
Expand Down
168 changes: 168 additions & 0 deletions config/lorekeeper/mentions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php

/*
|--------------------------------------------------------------------------
| Mentions
|--------------------------------------------------------------------------
|
| These are settings that affect, specifically, how mentions are used.
| Mentions are basically shorthand codes mainly for staff to refer
| to users, characters, gallery submissions and more in the WYSIWYG editor.
|
| Each mention has an 'enable' setting which decides if the mention
| functions and a 'show_text' setting which whether the "Mention This"
| block is displayed on-site. Use 0 to disable and 1 to enable.
|
| Please note that these settings are not retroactive, and mentions will
| only be applied to (or removed from) areas in which they are used when
| the text is next edited.
|
*/

return [

/*
|--------------------------------------------------------------------------
| User Mentions
|--------------------------------------------------------------------------
|
| Links to the mentioned user, includes icon and coloration of user's rank.
|
| If the mentioned user changes usernames, mentions using this method break.
|
| Usage:
| @username
| - Replace username with the user's username.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'user_mention' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| User and Avatar Mentions
|--------------------------------------------------------------------------
|
| Links to the mentioned user, includes user's avatar as well as the icon
| and coloration of user's rank.
|
| If the mentioned user changes usernames, mentions using this method break.
|
| Usage:
| %username
| - Replace username with the user's username.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'user_and_avatar_mention' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| User Permalinks
|--------------------------------------------------------------------------
|
| Links to the mentioned user, includes icon and coloration of user's rank.
SpeedyD marked this conversation as resolved.
Show resolved Hide resolved
|
| Mentions using this method persist even if the mentioned user changes
| usernames, but will not update to the new username until edited again.
|
| Usage:
| [user=id]
| - Replace id with the user's id.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'user_permalink' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| User Avatar Permalinks
|--------------------------------------------------------------------------
|
| Displays the mentioned user's avatar.
|
| Mentions using this method persist even if the mentioned user changes
| usernames, but will not update to the new username until edited again.
|
| Usage:
| [userav=id]
| - Replace id with the user's id.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'user_avatar_permalink' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| Character Permalinks
|--------------------------------------------------------------------------
|
| Links to the mentioned character.
|
| Usage:
| [character=slug]
| - Replace slug with the character's slug.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'character_permalink' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| Character Thumbnail Permalinks
|--------------------------------------------------------------------------
|
| Displays the mentioned character's thumbnail.
|
| Usage:
| [charthumb=slug]
| - Replace slug with the character's slug.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'character_thumb_permalink' => [
'enable' => 1,
'show_text' => 1,
],

/*
|--------------------------------------------------------------------------
| Gallery Thumbnail Permalinks
|--------------------------------------------------------------------------
|
| Display the mentioned gallery submission's thumbnail.
|
| Usage:
| [thumb=id]
| - Replace id with the gallery submission's id.
|
| This option has been enabled by default for backwards compatibility.
|
*/
'gallery_thumb_permalink' => [
'enable' => 1,
'show_text' => 1,
],

];