travel guide
This commit is contained in:
parent
346a7427a5
commit
a1ca534f55
26 changed files with 5788 additions and 3191 deletions
231
app/Http/Controllers/CMS/CMSTravelGuideController.php
Executable file
231
app/Http/Controllers/CMS/CMSTravelGuideController.php
Executable file
|
|
@ -0,0 +1,231 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\CMS;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TravelGuide;
|
||||
use App\Models\TravelPageGuide;
|
||||
use AppBundle\Util;
|
||||
use Gregwar\Image\Image;
|
||||
use Illuminate\Http\Request;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
class CMSTravelGuideController extends Controller
|
||||
{
|
||||
|
||||
/*
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/*
|
||||
$alls = TravelGuide::all();
|
||||
foreach ($alls as $all){
|
||||
$all->full_text = $this->cleanHTML($all->full_text);
|
||||
$all->save();
|
||||
}
|
||||
*/
|
||||
$data = [
|
||||
'travel_guides' => TravelGuide::all(),
|
||||
];
|
||||
return view('cms.travel_guide.index', $data);
|
||||
|
||||
}
|
||||
|
||||
public function page()
|
||||
{
|
||||
$data = [
|
||||
'travel_guide_pages' => TravelPageGuide::getPageGuides(),
|
||||
];
|
||||
return view('cms.travel_guide.page', $data);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
$model = new TravelGuide();
|
||||
$id = 'new';
|
||||
$model->active = 1;
|
||||
|
||||
}else{
|
||||
$model = TravelGuide::findOrFail($id);
|
||||
$id = $model->id;
|
||||
}
|
||||
|
||||
if(Input::get('clean') == "true"){
|
||||
$model->full_text = $this->cleanHTML($model->full_text);
|
||||
|
||||
}
|
||||
|
||||
$data = [
|
||||
'travel_guide' => $model,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('cms.travel_guide.detail', $data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function cleanHTML($html)
|
||||
{
|
||||
|
||||
|
||||
$html = str_replace('font-size: 14px;', ' ', $html);
|
||||
$html = str_replace('font-weight: lighter; ', ' ', $html);
|
||||
$html = str_replace('font-family: Helvetica, Arial, sans-serif; ', ' ', $html);
|
||||
$html = str_replace('font-family: Verdana, sans-serif; ', ' ', $html);
|
||||
$html = str_replace('color: rgb(60, 60, 60); ', ' ', $html);
|
||||
$html = str_replace(' style=" padding: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 20px !important; line-height: 20px !important;"', ' ', $html);
|
||||
$html = str_replace('property="article"', ' ', $html);
|
||||
$html = str_replace(' ', ' ', $html);
|
||||
$html = str_replace('https://www.aegypten-online.de', 'https://www.sterntours.de', $html);
|
||||
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
@$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
|
||||
|
||||
$removeFullTags = ['span', 'a'];
|
||||
|
||||
foreach ($removeFullTags as $removeFullTag){
|
||||
$domElemsToRemove = [];
|
||||
$elements = $dom->getElementsByTagName($removeFullTag);
|
||||
foreach ($elements as $element) {
|
||||
$domElemsToRemove[] = $element;
|
||||
|
||||
}
|
||||
foreach ($domElemsToRemove as $domElem) {
|
||||
if($removeFullTag == 'span' && strpos($domElem->getAttribute('style'), 'font-weight: 700') !== false){
|
||||
$new_node = $dom->createTextNode("<strong>".$domElem->nodeValue."</strong>");
|
||||
}else{
|
||||
$new_node = $dom->createTextNode($domElem->nodeValue);
|
||||
}
|
||||
$domElem->parentNode->replaceChild($new_node, $domElem);
|
||||
}
|
||||
}
|
||||
$removeStyleTags = ['ul', 'li', 'h1', 'h2', 'br'];
|
||||
foreach ($removeStyleTags as $removeStyleTag){
|
||||
$elements = $dom->getElementsByTagName($removeStyleTag);
|
||||
foreach ($elements as $element) {
|
||||
$element->removeAttribute('style');
|
||||
}
|
||||
}
|
||||
$html = $dom->saveHTML();
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function pageDetail($id)
|
||||
{
|
||||
if($id == "new") {
|
||||
/* $model = new TravelGuide();
|
||||
$id = 'new';
|
||||
$model->active = 1;
|
||||
*/
|
||||
|
||||
}else{
|
||||
$model = TravelPageGuide::findOrFail($id);
|
||||
$id = $model->id;
|
||||
}
|
||||
$data = [
|
||||
'travel_guide_page' => $model,
|
||||
'id' => $id,
|
||||
];
|
||||
return view('cms.travel_guide.page_detail', $data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
$data['active'] = isset($data['active']) ? true : false;
|
||||
$data['scope'] = isset($data['scope']) ? true : false;
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
if($id != "new") {
|
||||
$model = TravelGuide::findOrFail($id);
|
||||
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
'slug' => 'unique:mysql_stern.travel_guides,slug,'.$model->id,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
|
||||
if($id == "new") {
|
||||
$model = TravelGuide::create($data);
|
||||
}else{
|
||||
$model = TravelGuide::findOrFail($id);
|
||||
$model->fill($data);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('cms_travel_guide_detail', [$model->id]));
|
||||
|
||||
}
|
||||
|
||||
public function pageStore($id)
|
||||
{
|
||||
$data = Input::all();
|
||||
$data['status'] = isset($data['status']) ? 1 : 0;
|
||||
$data['show_in_navi'] = isset($data['show_in_navi']) ? 1 : 0;
|
||||
$rules = array(
|
||||
'title' => 'required',
|
||||
);
|
||||
|
||||
if($id != "new") {
|
||||
$model = TravelPageGuide::findOrFail($id);
|
||||
|
||||
$rules = array(
|
||||
'title' => 'required',
|
||||
// 'slug' => 'unique:mysql_stern.travel_guides,slug,'.$model->id,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
|
||||
if($id == "new") {
|
||||
$model = TravelPageGuide::create($data);
|
||||
}else{
|
||||
$model = TravelPageGuide::findOrFail($id);
|
||||
$model->fill($data);
|
||||
$model->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('cms_travel_guide_page_detail', [$model->id]));
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$model = TravelGuide::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', __('Eintrag Reisemagazin gelöscht'));
|
||||
return redirect(route('cms_travel_guide_content'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue