Feuerwehr-eppingen/app/Helpers/URLHelper.php
ppa. Marco Glietsch e76da0d33e Anpassung
iCal-Link hat jetzt die Endung *.ical
2021-11-10 15:37:07 +01:00

180 lines
3.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Marco Glietsch
* Date: 14.05.2018
* Time: 16:20
*/
namespace App\Helpers;
use Carbon\Carbon;
class URLHelper
{
static function Post($post, $suffix = null)
{
return URLHelper::create($post, $suffix, false);
}
static function create($post = null, $suffix = null, $withFilter = true)
{
$url = URLHelper::base();
if(isset($post))
{
if(is_string($post))
{
$url .= "/$post";
}
else
{
if(isset($post->slug) && $post->type != 'dienst')
{
$url .= "/" . $post->type . "/" . $post->slug;
}
else
{
switch($post->type)
{
case 'mitglied':
$url .= "/mitglied/$post->department";
break;
case 'dienst':
$year = '';
$department = '';
$instance = '';
$slug = '';
if(isset($post->department))
{
$year = $post->year;
$department = $post->department;
$instance = $post->instance;
if(isset($post->next))
{
$slug = '#'.$post->next->slug;
}
}
else
{
$year = Carbon::parse($post->datetime)->format('Y');
$department = TagHelper::getTagNameByType($post, 'abteilung');
$instance = TagHelper::getTagNameByType($post, 'instanz');
$slug = '#'.$post->slug;
}
$url .= "/" . $post->type . "/" .$year. "/" .$department. "/". $instance;
if(is_string($suffix))
{
$url .= "/dienstplan.$suffix";
}
$url .= $slug;
break;
}
}
}
}
if(is_string($suffix))
{
if(strlen($url) > 1 && $post->type != 'dienst')
{
$url .= '/'.$suffix;
}
}
if($withFilter)
{
$url = URLHelper::addFilter($url);
}
return $url;
}
static function isLocal()
{
if(config('app.url') == "http://localhost" || config('app.url') == "http://ffw")
{
return true;
}
else
{
return false;
}
}
static function base()
{
return config('app.url');
}
static function current()
{
$request = app('request');
return $request->url();
}
static function createQuickLogin($hash)
{
$domain = config('app.url');
$url = "$domain/quicklogin/$hash";
return $url;
}
static function isAdminURL()
{
$path = app('request')->path();
if(strpos($path, 'admin') === 0)
{
return true;
}
else
{
return false;
}
}
static function addFilter($url)
{
if(app('request')->isMethod('GET'))
{
$pars = app('request')->request->all();
if(count($pars))
{
foreach($pars as $key => $value)
{
if($key != 'page')
{
reset($pars);
if($key === key($pars))
{
$url .= "?";
}
$url .= "$key=$value";
end($pars);
if($key !== key($pars))
{
$url .= "&";
}
}
}
}
}
return $url;
}
static function Facebook($model)
{
return "https://www.facebook.com/".$model->publication('facebook')->state;
}
static function Twitter($model)
{
return "https://twitter.com/FEppingen/status/".$model->publication('twitter')->state;
}
}