Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/public/storage
/storage/*.key
/storage/medialibrary
/storage/media-library
/vendor
/.idea
/.vagrant
Expand Down
44 changes: 44 additions & 0 deletions app/Conversions/Svg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Conversions;

use Illuminate\Support\Collection;
use Imagick;
use ImagickPixel;
use Spatie\MediaLibrary\Conversions\Conversion;
use Spatie\MediaLibrary\Conversions\ImageGenerators\ImageGenerator;

class Svg extends ImageGenerator
{
/**
* Converts SVG to PNG, preserving transparency
*/
public function convert(string $file, Conversion $conversion = null): string
{
$imageFile = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.png';

$image = new Imagick();
$image->setBackgroundColor(new ImagickPixel('transparent')); // set bg BEFORE reading file to preserve transparency
$image->readImage($file);
$image->setImageFormat('png');

file_put_contents($imageFile, $image->getImageBlob());

return $imageFile;
}

public function requirementsAreInstalled(): bool
{
return class_exists(\Imagick::class);
}

public function supportedExtensions(): Collection
{
return collect(['svg']);
}

public function supportedMimeTypes(): Collection
{
return collect(['image/svg+xml']);
}
}
18 changes: 14 additions & 4 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ public function updateImage(Request $request, string $setting_name): RedirectRes
if ($request->hasFile($setting_name)) {
$setting = Setting::firstOrCreate(['name' => $setting_name]);
$setting->addMedia($request->file($setting_name))->toMediaCollection($setting_name);
// $message = $setting->processImage($request->file($image_name), 'settings');
// $url = $setting->getFullImageUrlAttribute();

$setting->value = url($setting->getFirstMediaUrl($setting_name) ?: '/img/default.png');
$image = $setting->getFirstMedia($setting_name);

$setting->update([
'value' => url($image?->getUrl() ?: '/img/default.png'),
]);

foreach (['thumb', 'medium', 'large'] as $conversion) {
if ($image->hasGeneratedConversion($conversion)) {
Setting::updateOrCreate(
['name' => "{$setting_name}_{$conversion}"],
['value' => $image->getUrl($conversion)]
);
}
}

$setting->save();
$message = 'Settings image has been updated.';
} else {
$message = 'Cannot update settings image.';
Expand Down
1 change: 1 addition & 0 deletions app/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function registerImageThumbnails(Media $media = null, $name, $width, $
->width($width)
->height($height)
->crop(Manipulations::CROP_TOP, $width, $height)
->format(Manipulations::FORMAT_PNG)
->performOnCollections('logo');
}

Expand Down
4 changes: 2 additions & 2 deletions config/media-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@
Spatie\MediaLibrary\Conversions\ImageGenerators\Image::class,
Spatie\MediaLibrary\Conversions\ImageGenerators\Webp::class,
Spatie\MediaLibrary\Conversions\ImageGenerators\Pdf::class,
Spatie\MediaLibrary\Conversions\ImageGenerators\Svg::class,
Spatie\MediaLibrary\Conversions\ImageGenerators\Video::class,
App\Conversions\Svg::class,
],

/*
* The path where to store temporary files while performing image conversions.
* If set to null, storage_path('medialibrary/temp') will be used.
* If set to null, storage_path('media-library/temp') will be used.
*/
'temporary_directory_path' => null,

Expand Down
14 changes: 14 additions & 0 deletions config/purify.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
'AutoFormat.RemoveEmpty' => false,
],

'trix_email' => [
'HTML.Doctype' => 'HTML 4.01 Transitional',
'HTML.AllowedElements' => 'a,span',
'HTML.AllowedAttributes' => 'a.href,a.style,span.style',
'AutoFormat.RemoveEmpty' => true,
'AutoFormat.RemoveEmpty.RemoveNbsp' => true,
'CSS.AllowedProperties' => 'color,text-decoration',
'Output.TidyFormat' => true,
'HTML.Nofollow' => false,
'Core.NormalizeNewlines' => true,
'AutoFormat.AutoParagraph' => false,
'AutoFormat.RemoveSpansWithoutAttributes' => true,
],

],

/*
Expand Down
29 changes: 20 additions & 9 deletions resources/views/emails/reviewstudents.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('emails.template')

@php
$primary_color = $settings['primary_color'] ?? '#008542';
$primary_color = $settings['primary_color'] ?? '#154734';
@endphp

@section('message')
Expand All @@ -15,12 +15,23 @@

<p>If you would like to review these undergraduate student research applications, please visit the following page. On this page, you will also be able to delegate review of the applications to another person or indicate if you're not accepting students.</p>

<p style="text-align: center; margin: 2rem;">
<a
href="{{ route('profiles.students', ['profile' => $faculty, 'semester' => $semester]) }}"
style="color: white; background-color: {{ $primary_color }}; border: 1px solid {{ $primary_color }}; text-align: center; padding: 0.5rem 1.25rem; line-height: 1.5; font-weight: normal; text-decoration: none; box-shadow: 2px 2px 3px #ccc;"
>
Review Undergraduate Student Research Applications →
</a>
</p>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" align="center" style="margin: 32px auto;">
<tr>
<td align="center">
<a href="{{ route('profiles.students', ['profile' => $faculty, 'semester' => $semester]) }}"
style="
color: white;
background-color: {{ $primary_color }};
text-decoration: none;
font-family: Arial, sans-serif;
font-size: 16px;
display: inline-block;
padding: 10px 20px;
border: 1px solid {{ $primary_color }};
">
Review Undergraduate Student Research Applications →
</a>
</td>
</tr>
</table>
@stop
106 changes: 59 additions & 47 deletions resources/views/emails/template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<html lang="en-US">

@php
$bg_primary = $settings['primary_color'] ?? '#008542';
$bg_secondary = $settings['secondary_color'] ?? '#008542';
$bg_tertiary = $settings['tertiary_color'] ?? '#69BE28';
use Stevebauman\Purify\Facades\Purify;

$bg_primary = $settings['primary_color'] ?? '#154734';
$bg_secondary = $settings['secondary_color'] ?? '#C95100';
$bg_tertiary = $settings['tertiary_color'] ?? '#34827A';
@endphp

<head>
Expand All @@ -18,58 +20,68 @@
<!--<![endif]-->
a[href], a[href]:visited { color: {{ $bg_primary }}; }
.footer a[href], .footer a[href]:visited { color: #fff; }
td.footer-cell a[href] { color: #fff !important; font-size: 16px; text-decoration: underline; }
</style>
</head>

<body style="font-family:Helvetica,Arial,sans-serif;box-sizing: border-box;">

<table style="margin:auto;padding:0;max-width:800px;border-collapse: collapse;">
<tbody>

<!-- Header -->
<tr style="margin:0;padding:0;width:100%;background:{{ $bg_primary }};">
<td colspan="6" style="text-align:center;margin:0;padding:20px 15px;width:100%;color:#fff;">
<a style="display:flex; align-items: center; justify-content: center; color:#fff;text-decoration:none;" title="{{ $settings['site_title'] ?? 'Profiles' }}" href="{{ url('/') }}">
@if(isset($settings['logo']))
<img style="height:70px; margin-right:1rem;" class="profiles-logo" src="{{ $settings['logo'] }}" alt="Logo">
@endif
<span style="font-size:1.25rem; white-space:nowrap;">{{ $settings['site_title'] ?? 'Profiles' }}</span>
</a>
</td>
</tr>

<!-- Body -->

<tr style="margin:0;padding:0;width:100%;">
<td colspan="6" style="background:#fff;margin:0;padding:5%;width:100%;">

<!-- Message -->

@yield('message')

<hr style="margin-top: 4em;">

<p>This is an automated message from the <a href="{{ url('/') }}" title="{{ $settings['site_title'] ?? 'Profiles' }}">{{ $settings['site_title'] ?? 'Profiles' }}</a> website.</p>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
<table width="800" cellpadding="0" cellspacing="0" border="0" style="background-color: #ffffff; margin:0 auto; border-collapse:collapse;">

</td>
</tr>
<!-- Header -->
<tr style="height: 70px !important;">
<td align="center" style="background-color: {{ $bg_primary }}; padding: 20px 15px;">
<a href="{{ url('/') }}" style="text-decoration: none;">
<table cellpadding="0" cellspacing="0" border="0" align="center" role="presentation">
<tr>
@isset($settings['logo_thumb'])
<td style="padding-right: 10px;">
<img src="{{ $settings['logo_thumb'] }}" alt="{{ $settings['site_title'] ?? 'Profiles' }} logo" width="70" height="70">
</td>
@endisset
<td style="color: #ffffff; font-size: 20px; white-space: nowrap; font-family: Helvetica, Arial, sans-serif;">
{{ $settings['site_title'] ?? 'Profiles' }}
</td>
</tr>
</table>
</a>
</td>
</tr>

<!-- Body -->
<tr>
<td style="padding: 30px; color: #333333; font-size: 16px; line-height: 1.6;">
<!-- Message -->
@yield('message')
<hr style="margin-top: 4em;">
<p>This is an automated message from the <a href="{{ url('/') }}" title="{{ $settings['site_title'] ?? 'Profiles' }}">{{ $settings['site_title'] ?? 'Profiles' }}</a> website.</p>
</td>
</tr>

<!-- Footer -->
<!-- Footer -->
<tr style="background-color: {{ $bg_tertiary }};">
<td colspan="6" style="text-align:center;padding-top:12px"></td>
</tr>
<tr style="background-color: #919191; padding: 40px; color: #ffffff; font-size: 14px; text-align: center;">
<td colspan="6" style="text-align:center;padding:40px 40px;">

<tr style="color:#fff;margin:0;padding:0;width:100%;font-size:12px;background:{{ $bg_tertiary }};">
<td colspan="6" style="width:100%;text-align:center;padding-top:12px">
</td>
</tr>
<tr style="color:#fff;margin:0;padding:0;width:100%;font-size:16px;background:#8B8178;" class="footer">
<td colspan="6" style="width:100%;text-align:center;padding:40px 40px;">
@if(isset($settings['footer']))
{!! $settings['footer'] !!}
@else
Questions? <a href="{{ url('/faq') }}">Check our FAQ</a> or <a href="mailto:{{ config('mail.from.address') }}?subject=Profiles">contact us.</a>
@endif
</td>
</tr>
</tbody>
@if(isset($settings['footer']))
@php
$footer = Purify::config('trix_email')->clean($settings['footer']);
$footer = str_replace('<a ', '<a style="color:#ffffff; text-decoration:underline;" ', $footer);
@endphp
{!! $footer !!}
@else
Questions? <a href="{{ url('/faq') }}">Check our FAQ</a> or <a href="mailto:{{ config('mail.from.address') }}?subject=Profiles">contact us.</a>
@endif
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>

Expand Down
Loading