get(); $final_score = $seo->altImageCheck('about'); $persen = $seo->keyphraseDensity('about'); $keyphrase_check = $seo->keyphraseCheck('about'); $total_text_length = $seo->textLength('about'); return view('layout.about', compact('content', 'timeline','final_score','persen','keyphrase_check','total_text_length')); } public function edit(Request $request) { $act = $request->get('act'); if($act == 'section-3-image') { $media = Media::all(); $section_3_image = AboutPage::first()->section_3_image; if($section_3_image) { $alt = $this->checkALtMedia($section_3_image); } else { $alt = ''; } $url = route('layout.about-update-image'); $img = $request->get('img'); return view('layout.edit-image', compact('act', 'media', 'url', 'alt', 'img')); } else if($act == 'section-4-image') { $position = $request->get('position'); $media = Media::all(); if($position == 1) { $image = AboutPage::first()->section_4_1_image; } else if($position == 2) { $image = AboutPage::first()->section_4_2_image; } else if($position == 3) { $image = AboutPage::first()->section_4_3_image; } else { $image = AboutPage::first()->section_4_4_image; } if($image) { $alt = $this->checkALtMedia($image); } else { $alt = ''; } $url = route('layout.about-update-image'); $img = $request->get('img'); return view('layout.edit-image', compact('act', 'media', 'url', 'alt', 'img', 'position')); } else if($act == 'testimonial') { return Testimonial::all(); } else if($act == 'client-logo') { return Testimonial::where('logo', '!=', NULL)->get(); } } public function updateImage(Request $request) { $save = $request->get('save'); $act = $request->get('act'); $alt = $request->get('alt'); $about_page = AboutPage::first(); $media = new Media(); if($save == 'save-as') { if ($request->hasFile($act)) { $image = $request->file($act); // $ext = $image->getClientOriginalExtension(); if ($request->file($act)->isValid()) { // check if file exist $check_media = Media::where('name', $image->getClientOriginalName())->count(); if($check_media > 0) { $no = 2; $image_name = ''; while (true) { $image_name = str_replace('.'. $image->getClientOriginalExtension(), '', $image->getClientOriginalName()) . '-' .$no . '.' . $image->getClientOriginalExtension(); if(Media::where('name', $image_name)->count() < 1) { break; } $no++; } } else { $image_name = $image->getClientOriginalName(); } $upload_path = 'media'; $request->file($act)->move($upload_path, $image_name); if($act == 'section-3-image') { $about_page->section_3_image = $image_name; } else if($act == 'section-4-image') { $position = $request->get('position'); if($position == 1) { $about_page->section_4_1_image = $image_name; } else if($position == 2) { $about_page->section_4_2_image = $image_name; } else if($position == 3) { $about_page->section_4_3_image = $image_name; } else { $about_page->section_4_4_image = $image_name; } } $media->name = $image_name; $media->alt = $alt; $media->save(); } } } else { if ($request->hasFile($act)) { $image = $request->file($act); $ext = $image->getClientOriginalExtension(); if ($request->file($act)->isValid()) { $check_media = Media::where('name', str_replace('.' . $image->getClientOriginalExtension(), '', $image->getClientOriginalName()) . '.webp')->count(); if($check_media > 0) { $no = 2; $image_name = ''; while (true) { $image_name = str_replace('.'. $image->getClientOriginalExtension(), '', $image->getClientOriginalName()) . '-' .$no . '.' . $image->getClientOriginalExtension(); $image_webp = str_replace('.'. $image->getClientOriginalExtension(), '', $image->getClientOriginalName()) . '-' .$no . '.webp'; if(Media::where('name', $image_webp)->count() < 1) { break; } $no++; } } else { $image_name = $image->getClientOriginalName(); } $upload_path = 'media'; $request->file($act)->move($upload_path, $image_name); if($ext == 'png') { $img_new_a = imagecreatefrompng(public_path('media/' . $image_name)); } else { $img_new_a = imagecreatefromjpeg(public_path('media/' . $image_name)); } imagepalettetotruecolor($img_new_a); imagealphablending($img_new_a, true); imagesavealpha($img_new_a, true); imagewebp($img_new_a, public_path('media/' . str_replace('.'.$ext, '.webp',$image_name)), 80); imagedestroy($img_new_a); unlink(public_path('media/' . $image_name)); if($act == 'section-3-image') { $about_page->section_3_image = str_replace('.'.$ext, '.webp',$image_name); } else if($act == 'section-4-image') { $position = $request->get('position'); if($position == 1) { $about_page->section_4_1_image = str_replace('.'.$ext, '.webp',$image_name); } else if($position == 2) { $about_page->section_4_2_image = str_replace('.'.$ext, '.webp',$image_name); } else if($position == 3) { $about_page->section_4_3_image = str_replace('.'.$ext, '.webp',$image_name); } else { $about_page->section_4_4_image = str_replace('.'.$ext, '.webp',$image_name); } } $media->name = str_replace('.'.$ext, '.webp',$image_name); $media->alt = $alt; $media->save(); } } } $about_page->save(); return redirect()->route('layout.about')->with('message', 'Image Successfully Updated'); } public function update(Request $request) { $act = $request->get('act'); $act_type = $request->get('act_type'); if($act == 'section-1') { $desc = $request->get('desc'); $about_page = AboutPage::first(); $about_page->section_1_desc = $desc; $about_page->save(); } else if($act == 'section-2-title') { $small_title = $request->get('small_title'); $big_title = $request->get('big_title'); $about_page = AboutPage::first(); $about_page->section_2_small_title = $small_title; $about_page->section_2_big_title = $big_title; $about_page->save(); } else if($act == 'section-2-card') { $position = $request->get('position'); $title = $request->get('title'); $desc = $request->get('desc'); $about_page = AboutPage::first(); switch ($position) { case "1": $about_page->section_2_1_title = $title; $about_page->section_2_1_desc = $desc; break; case "2": $about_page->section_2_2_title = $title; $about_page->section_2_2_desc = $desc; break; case "3": $about_page->section_2_3_title = $title; $about_page->section_2_3_desc = $desc; break; default: break; }; $about_page->save(); } else if($act == 'section-3-title') { $small_title = $request->get('small_title'); $big_title = $request->get('big_title'); $about_page = AboutPage::first(); $about_page->section_3_small_title = $small_title; $about_page->section_3_big_title = $big_title; $about_page->save(); } else if($act == 'section-3-point') { $points = $request->get('points'); if(!empty($points)) { $about_page = AboutPage::first(); $about_page->section_3_point = json_encode($points); $about_page->save(); } } else if($act == 'section-3-button') { $btn = $request->get('btn'); $link = $request->get('link'); $about_page = AboutPage::first(); $about_page->section_3_btn = $btn; $about_page->section_3_link = $link; $about_page->save(); } else if($act == 'section-4') { $position = $request->get('position'); $title = $request->get('title'); $desc = $request->get('desc'); $about_page = AboutPage::first(); switch ($position) { case "1": $about_page->section_4_1_title = $title; $about_page->section_4_1_desc = $desc; break; case "2": $about_page->section_4_2_title = $title; $about_page->section_4_2_desc = $desc; break; case "3": $about_page->section_4_3_title = $title; $about_page->section_4_3_desc = $desc; break; case "4": $about_page->section_4_4_title = $title; $about_page->section_4_4_desc = $desc; break; default: break; }; $about_page->save(); } else if($act == 'add-timeline') { $year = $request->get('year'); $desc = $request->get('description'); $title = $request->get('title'); $timeline = new TimelineYear(); $timeline->year = $year; $timeline->save(); if($desc && $title) { if(!empty($desc) && !empty($title)) { for($i = 0; $i <= count($desc) - 1; $i++) { $timeline_desc = new TimelineDesc(); $timeline_desc->title = $title[$i]; $timeline_desc->description = $desc[$i]; $timeline_desc->timeline_year_id = $timeline->id; $timeline_desc->save(); } } } return view('layout.return-timeline', compact('timeline')); } else if($act == 'delete-timeline') { $timeline_year_id = $request->get('timeline_year_id'); TimelineYear::destroy($timeline_year_id); } else if($act == 'section-5') { $small_title = $request->get('small_title'); $big_title = $request->get('big_title'); $about_page = AboutPage::first(); $about_page->section_5_small_title = $small_title; $about_page->section_5_big_title = $big_title; $about_page->save(); } else if($act == 'section-6') { $small_title = $request->get('small_title'); $big_title = $request->get('big_title'); $about_page = AboutPage::first(); $about_page->section_6_small_title = $small_title; $about_page->section_6_big_title = $big_title; $about_page->save(); } else if($act == 'section-7') { $small_title = $request->get('small_title'); $big_title = $request->get('big_title'); $desc = $request->get('desc'); $about_page = AboutPage::first(); $about_page->section_7_small_title = $small_title; $about_page->section_7_big_title = $big_title; $about_page->section_7_desc = $desc; $about_page->save(); } else if($act == 'section-4-image') { if($act_type == 'save-alt') { $alt = $request->get('alt'); $img = $request->get('img'); $media = Media::where('name', $img)->first(); $media->alt = $alt; $media->save(); } else if($act_type == 'from-media') { $position = $request->get('position'); $img = $request->get('img'); $about_page = AboutPage::first(); if($position == 1) { $about_page->section_4_1_image = $img; } else if($position == 2) { $about_page->section_4_2_image = $img; } else if($position == 3) { $about_page->section_4_3_image = $img; } else { $about_page->section_4_4_image = $img; } $about_page->save(); } } else if($act == 'edit-timeline') { $timeline_desc = TimelineDesc::findOrfail($request->get('timeline_desc_id')); $timeline_desc->title = $request->get('title'); $timeline_desc->description = $request->get('description'); $timeline_desc->save(); } else if($act == 'delete-timeline-desc') { TimelineDesc::destroy($request->get('timeline_desc_id')); } else if($act == 'add-timeline-desc') { $timeline_desc = new TimelineDesc(); $timeline_desc->title = $request->get('title'); $timeline_desc->description = $request->get('description'); $timeline_desc->timeline_year_id = $request->get('timeline_year_id'); $timeline_desc->save(); return $timeline_desc->id; } else if($act == 'testimonial') { $about_page = AboutPage::first(); $position = $request->get('position'); if($position == 1) { $about_page->testimonial_1 = $request->get('testimonial_id'); } else if($position == 2) { $about_page->testimonial_2 = $request->get('testimonial_id'); } else if($position == 3) { $about_page->testimonial_3 = $request->get('testimonial_id'); } $about_page->save(); return Testimonial::findOrfail($request->get('testimonial_id')); } else if($act == 'client-logo') { $position = $request->get('position'); $about_page = AboutPage::first(); if($position == 1) { $about_page->client_logo_1 = $request->get('image'); } else if($position == 2) { $about_page->client_logo_2 = $request->get('image'); } else if($position == 3) { $about_page->client_logo_3 = $request->get('image'); } else if($position == 4) { $about_page->client_logo_4 = $request->get('image'); } $about_page->save(); } return 'true'; } private function checkALtMedia($image) { $media = Media::where('name', $image)->first(); if($media) { return $media->alt; } else { return ''; } } public static function checkAltMediaStatic($image) { $media = Media::where('name', $image)->first(); if($media) { return $media->alt; } else { return ''; } } public function updateseo(Request $request){ $seo = AboutPage::where('id', 1) -> update([ 'keyphrase' => $request -> focus_keyphrase, 'seo_title' => $request -> seo_title, 'meta_description' => $request -> meta_description, ]); return redirect()->route('layout.about')->with('message', 'SEO Successfully Updated'); } }