diff --git a/app/Helpers/Helpers.php b/app/Helpers/Helpers.php index a9eefbafc9..70c2f308fa 100644 --- a/app/Helpers/Helpers.php +++ b/app/Helpers/Helpers.php @@ -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]; } @@ -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.'\]/', ''.$item->name.'', $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 ? ''.$trait->name.'' : ''; + $traitbg = $trait->rarity->color ? 'background-color:#'.$trait->rarity->color : ''; + $text = preg_replace('/\[traitthumb='.$match.'\]/', '

'.$trait_hasimg.''.$trait->name.'

', $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 ? ''.$item->name.'' : ''; + $text = preg_replace('/\[itemthumb='.$match.'\]/', '

'.$item_hasimg.''.$item->name.'

', $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.'\]/', ''.$prompt->name.'', $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 ? ''.$prompt->name.'' : ''; + $text = preg_replace('/\[promptthumb='.$match.'\]/', '

'.$prompt_hasimg.''.$prompt->name.'

', $text); + } + } + } + + return $text; +} + /** * Parses a piece of user-entered text to match gallery submission thumb mentions * and replace with a link. diff --git a/app/Models/Prompt/Prompt.php b/app/Models/Prompt/Prompt.php index bd78af27ef..02d44fbc2a 100644 --- a/app/Models/Prompt/Prompt.php +++ b/app/Models/Prompt/Prompt.php @@ -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. * diff --git a/config/lorekeeper/mentions.php b/config/lorekeeper/mentions.php new file mode 100644 index 0000000000..e78cc0518c --- /dev/null +++ b/config/lorekeeper/mentions.php @@ -0,0 +1,168 @@ + [ + '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. + | + | 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, + ], + +];