Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

@@ -125,6 +125,7 @@ class CustomBadge extends ActiveRecord
$file->delete();
}
File::$safeFileExtensions[] = 'svg';
$this->file = (string) File::create( 'core_CustomBadges', 'custombadge-' . $this->id . '.svg', $this->raw );
}
@@ -137,7 +138,7 @@ class CustomBadge extends ActiveRecord
{
$foreground = $this->foreground ?: 'currentColor';
$icon = $this->compileIconElement();
$numberOverlay = static::getBadgeNumberOverlay( $this->number_overlay );
$numberOverlay = $this->getBadgeNumberOverlay( $this->number_overlay );
return <<<SVG
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" height="48">
@@ -170,7 +171,7 @@ SVG;
{
$points = static::getRadialPoints( $this->sides, ( $this->sides === 4 and $this->rotation % 90 === 45) ? sqrt( 47.4*47.4*2 ) : 47.4 );
$icon = $this->compileIconElement();
$numberOverlay = static::getBadgeNumberOverlay( $this->number_overlay );
$numberOverlay = $this->getBadgeNumberOverlay( $this->number_overlay );
$foreground = $this->foreground ?: 'currentColor';
$path = "";
@@ -198,7 +199,7 @@ SVG;
protected function generateSVG_circle() : string
{
$icon = $this->compileIconElement();
$numberOverlay = static::getBadgeNumberOverlay( $this->number_overlay );
$numberOverlay = $this->getBadgeNumberOverlay( $this->number_overlay );
$foreground = $this->foreground ?: 'currentColor';
return <<<SVG
@@ -221,7 +222,7 @@ SVG;
protected function generateSVG_star() : string
{
$icon = $this->compileIconElement();
$numberOverlay = static::getBadgeNumberOverlay( $this->number_overlay );
$numberOverlay = $this->getBadgeNumberOverlay( $this->number_overlay );
$foreground = $this->foreground ?: 'currentColor';
$innerPoints = static::getRadialPoints( $this->sides, (0.75 + (0.095 * ( $this->sides - 4 ) / 8)) * ( 45 * ( cos( pi() / $this->sides ) ) ), 0.5 );
$outerPoints = static::getRadialPoints( $this->sides, 47.4 );
@@ -250,7 +251,7 @@ SVG;
protected function generateSVG_flower() : string
{
$icon = $this->compileIconElement();
$numberOverlay = static::getBadgeNumberOverlay( $this->number_overlay );
$numberOverlay = $this->getBadgeNumberOverlay( $this->number_overlay );
$foreground = $this->foreground ?: 'currentColor';
$r = 45 * ((sin(pi() / $this->sides)) / (sin(pi() / $this->sides) + 1));
@@ -354,16 +355,10 @@ SVG;
{
// complicated, but emojis don't center well. This was tested on MacOS using Apple Emoji font and accounts for whether the badge uses a background shape or not. Might be worth adding a note that emojis might not look correct on all devices (as the font is device-specific)
$size = 50 + round( $sizeOffset * 2, 2 );
$offset = 50 + round( ($this->shape === "no_shape" ? 24 : 18) + (($this->iconSize - 1) * ($this->shape === 'no_shape' ? 12.5 : 8.75) / 4), 2 );
$offset = 50 + round( $size / 10, 2 );// - round( $size / 2, 2 );//round( ($this->shape === "no_shape" ? 24 : 18) + (($this->iconSize - 1) * ($this->shape === 'no_shape' ? 12.5 : 8.75) / 4), 2 );
return <<<SVG
<style>
svg text.svg__text_icon:not(#x) {
line-height: {$size}px;
vertical-align: middle;
}
</style>
<text text-anchor="middle" font-size="{$size}" x="50" y="{$offset}" class="svg__text_icon">{$iconData['raw']}</text>
<text text-anchor="middle" dominant-baseline="middle" font-size="{$size}" x="50" y="{$offset}" style="line-height: {$size}px;" class="svg__text_icon">{$iconData['raw']}</text>
SVG;
}
}
@@ -375,8 +370,24 @@ SVG;
*
* @return string
*/
protected static function getBadgeNumberOverlay( int $number ) : string
protected function getBadgeNumberOverlay( int $number ) : string
{
/* Do nothing if the number is empty */
if( $number == 0 )
{
return '';
}
/* Check if the class using this badge uses the overlay */
$class = $this->class;
if( $class )
{
if( isset( $class::$customBadgeNumberOverlay ) and !$class::$customBadgeNumberOverlay )
{
return "";
}
}
return <<<SVG
<style>
svg text.svg__text_overlay:not(#x) {