-
Notifications
You must be signed in to change notification settings - Fork 123
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
Feature/image blocking #926
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
| | ||
| Miscellaneous helper functions, primarily used for formatting. | ||
| | ||
*/ | ||
*/ | ||
|
||
/** | ||
* Returns class name if the current URL corresponds to the given path. | ||
|
@@ -17,7 +17,8 @@ | |
* | ||
* @return string | ||
*/ | ||
function set_active($path, $class = 'active') { | ||
function set_active($path, $class = 'active') | ||
{ | ||
return call_user_func_array('Request::is', (array) $path) ? $class : ''; | ||
} | ||
|
||
|
@@ -28,8 +29,9 @@ function set_active($path, $class = 'active') { | |
* | ||
* @return string | ||
*/ | ||
function add_help($text) { | ||
return '<i class="fas fa-question-circle help-icon" data-toggle="tooltip" title="'.$text.'"></i>'; | ||
function add_help($text) | ||
{ | ||
return '<i class="fas fa-question-circle help-icon" data-toggle="tooltip" title="' . $text . '"></i>'; | ||
} | ||
|
||
/** | ||
|
@@ -39,10 +41,11 @@ function add_help($text) { | |
* | ||
* @return string | ||
*/ | ||
function breadcrumbs($links) { | ||
function breadcrumbs($links) | ||
{ | ||
$ret = '<nav><ol class="breadcrumb">'; | ||
$count = 0; | ||
$ret .= '<li class="breadcrumb-item"><a href="'.url('/').'">'.config('lorekeeper.settings.site_name', 'Lorekeeper').'</a></li>'; | ||
$ret .= '<li class="breadcrumb-item"><a href="' . url('/') . '">' . config('lorekeeper.settings.site_name', 'Lorekeeper') . '</a></li>'; | ||
foreach ($links as $key => $link) { | ||
$isLast = ($count == count($links) - 1); | ||
|
||
|
@@ -53,7 +56,7 @@ function breadcrumbs($links) { | |
$ret .= '">'; | ||
|
||
if (!$isLast) { | ||
$ret .= '<a href="'.url($link).'">'; | ||
$ret .= '<a href="' . url($link) . '">'; | ||
} | ||
$ret .= $key; | ||
if (!$isLast) { | ||
|
@@ -77,12 +80,14 @@ function breadcrumbs($links) { | |
* | ||
* @return string | ||
*/ | ||
function format_date($timestamp, $showTime = true) { | ||
return $timestamp->format('j F Y'.($showTime ? ', H:i:s' : '')).($showTime ? ' <abbr data-toggle="tooltip" title="UTC'.$timestamp->timezone->toOffsetName().'">'.strtoupper($timestamp->timezone->getAbbreviatedName($timestamp->isDST())).'</abbr>' : ''); | ||
function format_date($timestamp, $showTime = true) | ||
{ | ||
return $timestamp->format('j F Y' . ($showTime ? ', H:i:s' : '')) . ($showTime ? ' <abbr data-toggle="tooltip" title="UTC' . $timestamp->timezone->toOffsetName() . '">' . strtoupper($timestamp->timezone->getAbbreviatedName($timestamp->isDST())) . '</abbr>' : ''); | ||
} | ||
|
||
function pretty_date($timestamp, $showTime = true) { | ||
return '<abbr data-toggle="tooltip" title="'.$timestamp->format('F j Y'.($showTime ? ', H:i:s' : '')).' '.strtoupper($timestamp->timezone->getAbbreviatedName($timestamp->isDST())).'">'.$timestamp->diffForHumans().'</abbr>'; | ||
function pretty_date($timestamp, $showTime = true) | ||
{ | ||
return '<abbr data-toggle="tooltip" title="' . $timestamp->format('F j Y' . ($showTime ? ', H:i:s' : '')) . ' ' . strtoupper($timestamp->timezone->getAbbreviatedName($timestamp->isDST())) . '">' . $timestamp->diffForHumans() . '</abbr>'; | ||
} | ||
|
||
/** | ||
|
@@ -94,8 +99,9 @@ function pretty_date($timestamp, $showTime = true) { | |
* | ||
* @return string | ||
*/ | ||
function format_masterlist_number($number, $digits) { | ||
return sprintf('%0'.$digits.'d', $number); | ||
function format_masterlist_number($number, $digits) | ||
{ | ||
return sprintf('%0' . $digits . 'd', $number); | ||
} | ||
|
||
/** | ||
|
@@ -106,12 +112,13 @@ function format_masterlist_number($number, $digits) { | |
* | ||
* @return string | ||
*/ | ||
function parse($text, &$pings = null) { | ||
function parse($text, &$pings = null) | ||
{ | ||
if (!$text) { | ||
return null; | ||
} | ||
|
||
require_once base_path().'/vendor/ezyang/htmlpurifier/library/HTMLPurifier.auto.php'; | ||
require_once base_path() . '/vendor/ezyang/htmlpurifier/library/HTMLPurifier.auto.php'; | ||
|
||
$config = HTMLPurifier_Config::createDefault(); | ||
$config->set('Attr.EnableID', true); | ||
|
@@ -153,7 +160,8 @@ function parse($text, &$pings = null) { | |
* | ||
* @return string | ||
*/ | ||
function parseUsers($text, &$users) { | ||
function parseUsers($text, &$users) | ||
{ | ||
$matches = null; | ||
$users = []; | ||
$count = preg_match_all('/\B@([A-Za-z0-9_-]+)/', $text, $matches); | ||
|
@@ -163,7 +171,7 @@ function parseUsers($text, &$users) { | |
$user = App\Models\User\User::where('name', $match)->first(); | ||
if ($user) { | ||
$users[] = $user; | ||
$text = preg_replace('/\B@'.$match.'/', $user->displayName, $text); | ||
$text = preg_replace('/\B@' . $match . '/', $user->displayName, $text); | ||
} | ||
} | ||
} | ||
|
@@ -180,7 +188,8 @@ function parseUsers($text, &$users) { | |
* | ||
* @return string | ||
*/ | ||
function parseUsersAndAvatars($text, &$users) { | ||
function parseUsersAndAvatars($text, &$users) | ||
{ | ||
$matches = null; | ||
$users = []; | ||
$count = preg_match_all('/\B%([A-Za-z0-9_-]+)/', $text, $matches); | ||
|
@@ -190,7 +199,7 @@ function parseUsersAndAvatars($text, &$users) { | |
$user = App\Models\User\User::where('name', $match)->first(); | ||
if ($user) { | ||
$users[] = $user; | ||
$text = preg_replace('/\B%'.$match.'/', '<a href="'.$user->url.'"><img src="'.$user->avatarUrl.'" style="width:70px; height:70px; border-radius:50%; " alt="'.$user->name.'\'s Avatar"></a>'.$user->displayName, $text); | ||
$text = preg_replace('/\B%' . $match . '/', '<a href="' . $user->url . '"><img src="' . $user->avatarUrl . '" style="width:70px; height:70px; border-radius:50%; " alt="' . $user->name . '\'s Avatar"></a>' . $user->displayName, $text); | ||
} | ||
} | ||
} | ||
|
@@ -207,7 +216,8 @@ function parseUsersAndAvatars($text, &$users) { | |
* | ||
* @return string | ||
*/ | ||
function parseUserIDs($text, &$users) { | ||
function parseUserIDs($text, &$users) | ||
{ | ||
$matches = null; | ||
$users = []; | ||
$count = preg_match_all('/\[user=([^\[\]&<>?"\']+)\]/', $text, $matches); | ||
|
@@ -217,7 +227,7 @@ function parseUserIDs($text, &$users) { | |
$user = App\Models\User\User::where('id', $match)->first(); | ||
if ($user) { | ||
$users[] = $user; | ||
$text = preg_replace('/\[user='.$match.'\]/', $user->displayName, $text); | ||
$text = preg_replace('/\[user=' . $match . '\]/', $user->displayName, $text); | ||
} | ||
} | ||
} | ||
|
@@ -234,7 +244,8 @@ function parseUserIDs($text, &$users) { | |
* | ||
* @return string | ||
*/ | ||
function parseUserIDsForAvatars($text, &$users) { | ||
function parseUserIDsForAvatars($text, &$users) | ||
{ | ||
$matches = null; | ||
$users = []; | ||
$count = preg_match_all('/\[userav=([^\[\]&<>?"\']+)\]/', $text, $matches); | ||
|
@@ -244,7 +255,7 @@ function parseUserIDsForAvatars($text, &$users) { | |
$user = App\Models\User\User::where('id', $match)->first(); | ||
if ($user) { | ||
$users[] = $user; | ||
$text = preg_replace('/\[userav='.$match.'\]/', '<a href="'.$user->url.'"><img src="'.$user->avatarUrl.'" style="width:70px; height:70px; border-radius:50%; " alt="'.$user->name.'\'s Avatar"></a>', $text); | ||
$text = preg_replace('/\[userav=' . $match . '\]/', '<a href="' . $user->url . '"><img src="' . $user->avatarUrl . '" style="width:70px; height:70px; border-radius:50%; " alt="' . $user->name . '\'s Avatar"></a>', $text); | ||
} | ||
} | ||
} | ||
|
@@ -261,7 +272,8 @@ function parseUserIDsForAvatars($text, &$users) { | |
* | ||
* @return string | ||
*/ | ||
function parseCharacters($text, &$characters) { | ||
function parseCharacters($text, &$characters) | ||
{ | ||
$matches = null; | ||
$characters = []; | ||
$count = preg_match_all('/\[character=([^\[\]&<>?"\']+)\]/', $text, $matches); | ||
|
@@ -271,7 +283,7 @@ function parseCharacters($text, &$characters) { | |
$character = App\Models\Character\Character::where('slug', $match)->first(); | ||
if ($character) { | ||
$characters[] = $character; | ||
$text = preg_replace('/\[character='.$match.'\]/', $character->displayName, $text); | ||
$text = preg_replace('/\[character=' . $match . '\]/', $character->displayName, $text); | ||
} | ||
} | ||
} | ||
|
@@ -288,7 +300,8 @@ function parseCharacters($text, &$characters) { | |
* | ||
* @return string | ||
*/ | ||
function parseCharacterThumbs($text, &$characters) { | ||
function parseCharacterThumbs($text, &$characters) | ||
{ | ||
$matches = null; | ||
$characters = []; | ||
$count = preg_match_all('/\[charthumb=([^\[\]&<>?"\']+)\]/', $text, $matches); | ||
|
@@ -298,7 +311,7 @@ function parseCharacterThumbs($text, &$characters) { | |
$character = App\Models\Character\Character::where('slug', $match)->first(); | ||
if ($character) { | ||
$characters[] = $character; | ||
$text = preg_replace('/\[charthumb='.$match.'\]/', '<a href="'.$character->url.'"><img class="img-thumbnail" alt="Thumbnail of '.$character->fullName.'" data-toggle="tooltip" title="'.$character->fullName.'" src="'.$character->image->thumbnailUrl.'"></a>', $text); | ||
$text = preg_replace('/\[charthumb=' . $match . '\]/', '<a href="' . $character->url . '"><img class="img-thumbnail" alt="Thumbnail of ' . $character->fullName . '" data-toggle="tooltip" title="' . $character->fullName . '" src="' . $character->image->thumbnailUrl . '"></a>', $text); | ||
} | ||
} | ||
} | ||
|
@@ -315,7 +328,8 @@ function parseCharacterThumbs($text, &$characters) { | |
* | ||
* @return string | ||
*/ | ||
function parseGalleryThumbs($text, &$submissions) { | ||
function parseGalleryThumbs($text, &$submissions) | ||
{ | ||
$matches = null; | ||
$submissions = []; | ||
$count = preg_match_all('/\[thumb=([^\[\]&<>?"\']+)\]/', $text, $matches); | ||
|
@@ -325,7 +339,7 @@ function parseGalleryThumbs($text, &$submissions) { | |
$submission = App\Models\Gallery\GallerySubmission::where('id', $match)->first(); | ||
if ($submission) { | ||
$submissions[] = $submission; | ||
$text = preg_replace('/\[thumb='.$match.'\]/', '<a href="'.$submission->url.'" data-toggle="tooltip" title="'.$submission->displayTitle.' by '.nl2br(htmlentities($submission->creditsPlain)).(isset($submission->content_warning) ? '<br/><strong>Content Warning:</strong> '.nl2br(htmlentities($submission->content_warning)) : '').'">'.view('widgets._gallery_thumb', ['submission' => $submission]).'</a>', $text); | ||
$text = preg_replace('/\[thumb=' . $match . '\]/', '<a href="' . $submission->url . '" data-toggle="tooltip" title="' . $submission->displayTitle . ' by ' . nl2br(htmlentities($submission->creditsPlain)) . (isset($submission->content_warning) ? '<br/><strong>Content Warning:</strong> ' . nl2br(htmlentities($submission->content_warning)) : '') . '">' . view('widgets._gallery_thumb', ['submission' => $submission]) . '</a>', $text); | ||
} | ||
} | ||
} | ||
|
@@ -340,7 +354,8 @@ function parseGalleryThumbs($text, &$submissions) { | |
* | ||
* @return string | ||
*/ | ||
function randomString($characters) { | ||
function randomString($characters) | ||
{ | ||
$src = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
$code = ''; | ||
for ($i = 0; $i < $characters; $i++) { | ||
|
@@ -359,12 +374,13 @@ function randomString($characters) { | |
* | ||
* @return App\Models\User\User|string | ||
*/ | ||
function checkAlias($url, $failOnError = true) { | ||
function checkAlias($url, $failOnError = true) | ||
{ | ||
if ($url) { | ||
$recipient = null; | ||
$matches = []; | ||
// Check to see if url is 1. from a site used for auth | ||
foreach (config('lorekeeper.sites') as $key=> $site) { | ||
foreach (config('lorekeeper.sites') as $key => $site) { | ||
if (isset($site['auth']) && $site['auth']) { | ||
preg_match_all($site['regex'], $url, $matches, PREG_SET_ORDER, 0); | ||
if ($matches != []) { | ||
|
@@ -403,10 +419,11 @@ function checkAlias($url, $failOnError = true) { | |
* | ||
* @return string | ||
*/ | ||
function prettyProfileLink($url) { | ||
function prettyProfileLink($url) | ||
{ | ||
$matches = []; | ||
// Check different sites and return site if a match is made, plus username (retreived from the URL) | ||
foreach (config('lorekeeper.sites') as $siteName=> $siteInfo) { | ||
foreach (config('lorekeeper.sites') as $siteName => $siteInfo) { | ||
if (preg_match_all($siteInfo['regex'], $url, $matches)) { | ||
$site = $siteName; | ||
$name = $matches[1][0]; | ||
|
@@ -418,9 +435,9 @@ function prettyProfileLink($url) { | |
|
||
// Return formatted link if possible; failing that, an unformatted link | ||
if (isset($name) && isset($site) && isset($link)) { | ||
return '<a href="https://'.$link.'"><i class="'.$icon.' mr-1" style="opacity: 50%;"></i>'.$name.'@'.(config('lorekeeper.sites.'.$site.'.display_name') != null ? config('lorekeeper.sites.'.$site.'.display_name') : $site).'</a>'; | ||
return '<a href="https://' . $link . '"><i class="' . $icon . ' mr-1" style="opacity: 50%;"></i>' . $name . '@' . (config('lorekeeper.sites.' . $site . '.display_name') != null ? config('lorekeeper.sites.' . $site . '.display_name') : $site) . '</a>'; | ||
} else { | ||
return '<a href="'.$url.'"><i class="fas fa-globe mr-1" style="opacity: 50%;"></i>'.$url.'</a>'; | ||
return '<a href="' . $url . '"><i class="fas fa-globe mr-1" style="opacity: 50%;"></i>' . $url . '</a>'; | ||
} | ||
} | ||
|
||
|
@@ -431,10 +448,11 @@ function prettyProfileLink($url) { | |
* | ||
* @return string | ||
*/ | ||
function prettyProfileName($url) { | ||
function prettyProfileName($url) | ||
{ | ||
$matches = []; | ||
// Check different sites and return site if a match is made, plus username (retreived from the URL) | ||
foreach (config('lorekeeper.sites') as $siteName=> $siteInfo) { | ||
foreach (config('lorekeeper.sites') as $siteName => $siteInfo) { | ||
if (preg_match_all($siteInfo['regex'], $url, $matches)) { | ||
$site = $siteName; | ||
$name = $matches[1][0]; | ||
|
@@ -444,8 +462,33 @@ function prettyProfileName($url) { | |
|
||
// Return formatted name if possible; failing that, an unformatted url | ||
if (isset($name) && isset($site)) { | ||
return $name.'@'.(config('lorekeeper.sites.'.$site.'.display_name') != null ? config('lorekeeper.sites.'.$site.'.display_name') : $site); | ||
return $name . '@' . (config('lorekeeper.sites.' . $site . '.display_name') != null ? config('lorekeeper.sites.' . $site . '.display_name') : $site); | ||
} else { | ||
return $url; | ||
} | ||
} | ||
|
||
/** | ||
* Check if user blocked an item | ||
* | ||
* @param string $url | ||
* | ||
* @return string | ||
*/ | ||
function checkItemBlock($item, $user) | ||
{ | ||
|
||
$model = get_class($item); | ||
|
||
$block = App\Models\ImageBlock::where([ | ||
['item_id', '=', $item->id], | ||
['item_type', '=', $model], | ||
['user_id', '=', $user->id], | ||
])->first(); | ||
|
||
if ($block) { | ||
return true; | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally speaking, with returns, you don't need to encase the second in the if/else-- nothing beyond a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, can even just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually follow up on this i'd do
|
||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: run composer lint to stop these weird style changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I'm just going to switch the relevant workflow to running on push for all branches again so neither reviewers nor contributors need to think about it, since my clever idea wrt running on PRs only was stymied (fairly reasonably) by repo perms... It was worth a shot |D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
can't work out all the time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that while I was thinking about it-- so it should now be as easy as just merging in latest develop. Hopefully.