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

Place public urls if you plan to use Attendize as a backend service intended for internal usage, with a separate frontend #975

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Expand Up @@ -6,6 +6,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=https://localhost:8081
PUBLIC_URL=

LOG_CHANNEL=stack

Expand Down
47 changes: 47 additions & 0 deletions app/Helpers/app_url.php
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

if (!function_exists('app_url')) {
/**
* Generate an absolute URL to the given path.
*
* @param string $path
* @param mixed $extra
* @param bool|null $secure
* @return string
*/
function app_url($path, $extra = [], $secure = null)
{
$urlGenerator = app('url');
$appUrl = env('APP_URL', '');

if (isset($appUrl) && $appUrl !== '') {
$parsedPath = parse_url($path);
$parsedAppUrl = parse_url($appUrl);

if ($parsedAppUrl) {
$parsedPath['host'] = $parsedAppUrl['host'];
$parsedPath['port'] = isset($parsedAppUrl['port']) ? $parsedAppUrl['port'] : null;
} else {
$parsedPath['host'] = $appUrl;
$parsedPath['port'] = null;
}

// Temporary replace default app domain with public domain
$urlGenerator->forceRootUrl($parsedPath['host']);

$path = unparse_url($parsedPath);
}

// Generate public url string
$result = $urlGenerator->to($path, $extra, $secure);

if (isset($appUrl) && $appUrl !== '') {
// Reset domain to default value
$urlGenerator->forceRootUrl('');
}

return $result;
}
}
36 changes: 36 additions & 0 deletions app/Helpers/public_route.php
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

if (!function_exists('public_route')) {
/**
* Generate the URL to a named route.
*
* @param array|string $name
* @param mixed $parameters
* @param bool $absolute
* @return string
*/
function public_route($name, $parameters = [], $absolute = true)
{
$urlGenerator = app('url');

if (!$absolute) {
return $urlGenerator->route($name, $parameters, $absolute);
}

$appUrl = env('APP_URL', $urlGenerator->getRequest()->root());
$publicUrl = env('PUBLIC_URL', '');

if (isset($publicUrl) && $publicUrl !== '') {
// Temporary replace default app domain with public domain
$route = Route::getRoutes()->getByName($name)->domain($publicUrl);
// Generate public url string
$result = $urlGenerator->toRoute($route, $parameters, true);
// Set domain to default value
$route = Route::getRoutes()->getByName($name)->domain($appUrl);
}

return $result;
}
}
23 changes: 23 additions & 0 deletions app/Helpers/unparse_url.php
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

if (!function_exists('unparse_url')) {
/**
* @param array $parsedUrl
* @return string
*/
function unparse_url($parsedUrl)
{
$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] . '://' : '';
$host = isset($parsedUrl['host']) ? $parsedUrl['host'] : '';
$port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';
$user = isset($parsedUrl['user']) ? $parsedUrl['user'] : '';
$pass = isset($parsedUrl['pass']) ? ':' . $parsedUrl['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsedUrl['path']) ? $parsedUrl['path'] : '';
$query = isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '';
$fragment = isset($parsedUrl['fragment']) ? '#' . $parsedUrl['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
}
}
2 changes: 1 addition & 1 deletion app/Models/Event.php
Expand Up @@ -394,7 +394,7 @@ public function getIcsForEvent()
*/
public function getEventUrlAttribute()
{
return route("showEventPage", ["event_id" => $this->id, "event_slug" => Str::slug($this->title)]);
return public_route("showEventPage", ["event_id" => $this->id, "event_slug" => Str::slug($this->title)]);
//return URL::to('/') . '/e/' . $this->id . '/' . Str::slug($this->title);
}

Expand Down
3 changes: 3 additions & 0 deletions app/Providers/HelpersServiceProvider.php
Expand Up @@ -17,6 +17,9 @@ public function boot()
{
require app_path('Helpers/helpers.php');
require app_path('Helpers/strings.php');
require app_path('Helpers/public_route.php');
require app_path('Helpers/app_url.php');
require app_path('Helpers/unparse_url.php');
$this->paymentUtils();
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/Emails/Layouts/Master.blade.php
Expand Up @@ -22,7 +22,7 @@
<table style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6;width: 100%">
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<td style="text-align: center;padding: 10px;margin: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{url(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-dark.png'))}}" />
<img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{app_url(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-dark.png'))}}" />
</td>
</tr>
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/Emails/OrderAttendeeTicket.blade.php
Expand Up @@ -4,6 +4,6 @@

@lang("basic.hello") {{ $attendee->first_name }},<br><br>

{{ @trans("Order_Emails.tickets_attached") }} <a href="{{route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}}">{{route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}}</a>.
{{ @trans("Order_Emails.tickets_attached") }} <a href="{{public_route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}}">{{public_route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}}</a>.

@stop
4 changes: 2 additions & 2 deletions resources/views/Emails/OrderConfirmation.blade.php
Expand Up @@ -5,7 +5,7 @@

{!! @trans("Order_Emails.successful_order", ["name"=>$order->event->title]) !!}<br><br>

{{ @trans("Order_Emails.tickets_attached") }} <a href="{{route('showOrderDetails', ['order_reference' => $order->order_reference])}}">{{route('showOrderDetails', ['order_reference' => $order->order_reference])}}</a>.
{{ @trans("Order_Emails.tickets_attached") }} <a href="{{public_route('showOrderDetails', ['order_reference' => $order->order_reference])}}">{{public_route('showOrderDetails', ['order_reference' => $order->order_reference])}}</a>.

@if(!$order->is_payment_received)
<br><br>
Expand All @@ -20,7 +20,7 @@
Order Name: <strong>{{$order->full_name}}</strong><br>
Order Date: <strong>{{$order->created_at->format(config('attendize.default_datetime_format'))}}</strong><br>
Order Email: <strong>{{$order->email}}</strong><br>
<a href="{!! route('downloadCalendarIcs', ['event_id' => $order->event->id]) !!}">Add To Calendar</a>
<a href="{!! public_route('downloadCalendarIcs', ['event_id' => $order->event->id]) !!}">Add To Calendar</a>

@if ($order->is_business)
<h3>Business Details</h3>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/Emails/OrderNotification.blade.php
Expand Up @@ -133,7 +133,7 @@


<br><br>
@lang("Order_Emails.manage_order") <a href="{{route('showEventOrders', ['event_id' => $order->event->id, 'q'=>$order->order_reference])}}">{{route('showEventOrders', ['event_id' => $order->event->id, 'q'=>$order->order_reference])}}</a>
@lang("Order_Emails.manage_order") <a href="{{public_route('showEventOrders', ['event_id' => $order->event->id, 'q'=>$order->order_reference])}}">{{public_route('showEventOrders', ['event_id' => $order->event->id, 'q'=>$order->order_reference])}}</a>
<br><br>
</div>
<br><br>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/ManageOrganiser/Partials/TopNav.blade.php
Expand Up @@ -9,10 +9,10 @@
</li>
<!--/ Show Side Menu -->
<li class="nav-button ">
<a target="_blank" href="{{ route('showOrganiserHome',[$organiser->id]) }}">
<a target="_blank" href="{{ public_route('showOrganiserHome',[$organiser->id]) }}">
<span>
<i class="ico-eye2"></i>&nbsp;@lang("Organiser.organiser_page")
</span>
</a>
</li>
</ul>
</ul>
2 changes: 1 addition & 1 deletion resources/views/en/Emails/Layouts/Master.blade.php
Expand Up @@ -22,7 +22,7 @@
<table style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6;width: 100%">
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<td style="text-align: center;padding: 10px;margin: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{url(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-dark.png'))}}" />
<img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{app_url(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-dark.png'))}}" />
</td>
</tr>
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/en/Emails/attendeeTicket.blade.php
Expand Up @@ -2,7 +2,7 @@

We've attached your tickets to this email.<br><br>

You can view your order info and download your tickets at {{route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}} anytime.<br><br>
You can view your order info and download your tickets at {{public_route('showOrderDetails', ['order_reference' => $attendee->order->order_reference])}} anytime.<br><br>

Your order reference is <b>{{$attendee->order->order_reference}}</b>.<br>

Expand Down