Skip to content

Commit

Permalink
Improvement on Seo Page Create and Image Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldreams committed Aug 28, 2019
1 parent 29c4d63 commit bc837b2
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 82 deletions.
4 changes: 2 additions & 2 deletions resources/views/forms/fields/page_fields.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="form-group col-sm-6">
<label for="page_title">Title <i class="fa fa-info" title="This will be shown on browser tab."></i></label>
<input type="text" class="form-control" name="page[title]" id="page_title"
value="{{old('page.title',$model->getTitle())}}"
placeholder="" maxlength="100">
value="{{old('page.title',$model->getTitle())}}" required
placeholder="Page Title" maxlength="100">

@if($errors->has('page.title'))
<span class="form-control-feedback">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/forms/page.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form action="{{isset($route)?$route: route('seo::pages.store')}}" method="POST">
<form action="{{isset($route)?$route: route('seo::pages.store')}}" method="POST" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" name="_method" value="{{isset($method)?$method:'POST'}}"/>
@include('seo::includes.page_meta_tags')
Expand Down
8 changes: 4 additions & 4 deletions resources/views/forms/tag.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<label for="{{$tag->id}}">{{$tag->input_label}}</label>
<br/>
@if($tag->input_type=='file')
<div class="custom-file">
<input type="file" id="Image" name="meta[{{$tag->id}}]" class="custom-file-input form-control-lg">
<span class="custom-file-control">
<div class="">
<input type="file" id="Image" name="meta[{{$tag->id}}]" class="form-control-lg">
<span class="">
@if(!empty($tag->content))
{{pathinfo($tag->content,PATHINFO_BASENAME)}}
<img src="{{$tag->content}}" width="120px">
@endif
</span>
</div>
Expand Down
132 changes: 65 additions & 67 deletions resources/views/includes/page_meta_tags.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
href="https://developers.facebook.com/tools/debug/sharing/?q={{urlencode($record->getFullUrl())}}">
<i class="fa fa-facebook-official"></i> Validate
</a>
<a class="btn btn-outline-secondary" href="https://cards-dev.twitter.com/validator" target="_blank">
<a class="btn btn-outline-secondary" href="https://cards-dev.twitter.com/validator"
target="_blank">
<i class="fa fa-twitter"></i> Card Validate
</a>
<a class="btn btn-outline-secondary" target="_blank"
Expand Down Expand Up @@ -62,12 +63,10 @@
<a class="nav-item nav-link" id="nav-page-tab" data-toggle="tab" href="#nav-meta" role="tab"
aria-controls="nav-meta">Others
</a>
@if(!empty($record->id))
<a class="nav-item nav-link" id="nav-keyword-tab" data-toggle="tab" href="#nav-keyword-analysis"
role="tab"
aria-controls="nav-meta"><i class="fa fa-search"></i> Keyword Analysis
</a>
@endif
<a class="nav-item nav-link" id="nav-keyword-tab" data-toggle="tab" href="#nav-keyword-analysis"
role="tab"
aria-controls="nav-meta"><i class="fa fa-search"></i> Keyword Analysis
</a>
</nav>
<div class="tab-content mt-3" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-global" role="tabpanel"
Expand All @@ -90,77 +89,76 @@
<div class="tab-pane fade hide" id="nav-meta" role="tabpanel" aria-labelledby="nav-page-tab">
@include('seo::forms.fields.page_meta_others')
</div>
@if(!empty($record->id))
<div class="tab-pane fade hide" id="nav-keyword-analysis" role="tabpanel"
aria-labelledby="nav-keyword-tab">

<div class="form-group form-group-sm">
<label class="" for="page_focus_keyword">Focus Keyword</label>
<input type="text" name="page[focus_keyword]" value="{{$record->focus_keyword}}"
placeholder="e.g. Travel"
class="form-control">
<div class="tab-pane fade hide" id="nav-keyword-analysis" role="tabpanel"
aria-labelledby="nav-keyword-tab">

@if($errors->has('page.robot_index'))
<span class="form-control-feedback">
<div class="form-group form-group-sm">
<label class="" for="page_focus_keyword">Focus Keyword</label>
<input type="text" name="page[focus_keyword]" value="{{$record->focus_keyword}}"
placeholder="e.g. Travel"
class="form-control">

@if($errors->has('page.robot_index'))
<span class="form-control-feedback">
<strong>{{ $errors->first('page.focus_keyword') }}</strong>
</span>
@endif
</div>
@if(!empty($keywordAnalysis))
<div class="row">
@if(isset($keywordAnalysis['good']) && !empty($keywordAnalysis['good']))
<div class="col-sm-4">
<div class="card border-success">
<div class="card-header bg-transparent border-success">
<i class="fa fa-check-square text-success"></i> Good
</div>
<div class="card-body text-small">
<ul class="list-group">
@foreach($keywordAnalysis['good'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
@endif
</div>
@if(!empty($keywordAnalysis) && !empty($record->id))
<div class="row">
@if(isset($keywordAnalysis['good']) && !empty($keywordAnalysis['good']))
<div class="col-sm-4">
<div class="card border-success">
<div class="card-header bg-transparent border-success">
<i class="fa fa-check-square text-success"></i> Good
</div>
<div class="card-body text-small">
<ul class="list-group">
@foreach($keywordAnalysis['good'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
</div>
@endif
@if(isset($keywordAnalysis['warnings']) && !empty($keywordAnalysis['warnings']))
<div class="col-sm-4">
<div class="card border-warning">
<div class="card-header bg-transparent border-warning">
<i class="fa fa-warning text-warning"></i> Warnings
</div>
<div class="card-body">
<ul class="list-group">
@foreach($keywordAnalysis['warnings'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
</div>
@endif
@if(isset($keywordAnalysis['warnings']) && !empty($keywordAnalysis['warnings']))
<div class="col-sm-4">
<div class="card border-warning">
<div class="card-header bg-transparent border-warning">
<i class="fa fa-warning text-warning"></i> Warnings
</div>
<div class="card-body">
<ul class="list-group">
@foreach($keywordAnalysis['warnings'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
</div>
@endif
@if(isset($keywordAnalysis['errors']) && !empty($keywordAnalysis['errors']))
<div class="col-sm-4">
<div class="card border-danger">
<div class="card-header bg-transparent border-danger">
<i class="fa fa-warning text-danger"></i> Errors
</div>
<div class="card-body">
<ul class="list-group">
@foreach($keywordAnalysis['errors'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
</div>
@endif
@if(isset($keywordAnalysis['errors']) && !empty($keywordAnalysis['errors']))
<div class="col-sm-4">
<div class="card border-danger">
<div class="card-header bg-transparent border-danger">
<i class="fa fa-warning text-danger"></i> Errors
</div>
<div class="card-body">
<ul class="list-group">
@foreach($keywordAnalysis['errors'] as $msg)
<li class="list-group-item">{{$msg}}</li>
@endforeach
</ul>
</div>
</div>
@endif
</div>
@endif

</div>
@endif
</div>
@endif
</div>
@endif
</div>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/pages/pages/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<i class="fa fa-plus text-muted"></i> New Page
@endsection
@section('tools')
<input type="submit" class="btn btn-primary" form="SeoFormPage" value="Save"/>

@endsection
@section('content')
<div class="row">
Expand Down
15 changes: 11 additions & 4 deletions src/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use SEO\Http\Requests\Pages\Destroy;
use SEO\Http\Requests\Pages\Download;
use SEO\Http\Requests\Pages\Edit;
use SEO\Http\Requests\Pages\Image;
use SEO\Http\Requests\Pages\Index;
use SEO\Http\Requests\Pages\Show;
use SEO\Http\Requests\Pages\Store;
Expand All @@ -27,6 +26,7 @@
use SEO\Models\PageMetaTag;
use SEO\Services\PageAnalysis;
use SEO\Tag;
use SEO\Seo;
use SEO\Services\KeywordAnalysis;
use Illuminate\Support\Facades\DB;

Expand Down Expand Up @@ -93,7 +93,7 @@ public function show(Show $request, Page $page)
public function create(Create $request)
{
$page = new Page();
$metaTags = $page->metaTags();
$metaTags = $page->pageLevel();

if (isset($metaTags['og'])) {
$og = $metaTags['og'];
Expand Down Expand Up @@ -125,7 +125,9 @@ public function store(Store $request)

if ($model->save()) {
$model->saveMeta(request()->get('meta', []));

$model->saveMeta(Seo::upload(request()->file('meta',[]), $model));
$tag = new Tag($model);
$tag->make()->save();
session()->flash(config('seo.flash_message'), 'Page saved successfully');
return redirect()->route('seo::pages.index');
} else {
Expand Down Expand Up @@ -188,7 +190,9 @@ public function update(Update $request, Page $page)

if ($page->save()) {
$page->saveMeta(request()->get('meta', []));

$page->saveMeta(Seo::upload(request()->file('meta',[]), $page));
$tag = new Tag($page);
$tag->make()->save();
session()->flash(config('seo.flash_message'), 'Page successfully updated');
return redirect()->route('seo::pages.index');
} else {
Expand Down Expand Up @@ -217,6 +221,9 @@ public function bulkUpdate(BulkUpdate $update)
$pageModel->description = $page['description'];
$pageModel->robot_index = !empty($page['robot_index']) ? $page['robot_index'] : 'noindex';
$pageModel->save();
$tag = new Tag($pageModel);
$tag->make()->save();

}
}
return redirect()->back()->with(config('seo.flash_message'), 'Pages saved successfully');
Expand Down
16 changes: 12 additions & 4 deletions src/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use SEO\Models\Page;
use SEO\Models\PageImage;
use SEO\Services\KeywordAnalysis;

class Seo
Expand Down Expand Up @@ -181,21 +182,28 @@ public function cache()
}

/**
* @param $files
* @param $metaImages
* @param $model
* @return array
*/
public static function upload($files)
public static function upload($metaImages, $model = '')
{
$imageMeta = [];
$metaImages = request()->file('meta', []);

$imageDriver = config('seo.storage.driver', 'public');
$imagePrefix = config('seo.storage.prefix', 'storage');
$imageFolder = config('seo.storage.folder', 'seo');

foreach ($metaImages as $id => $img) {
$path = $img->store($imageFolder, $imageDriver);
$imageMeta[$id] = asset($imagePrefix . '/' . $path);
$imageSrc = asset($imagePrefix . '/' . $path);
$imageMeta[$id] = $imageSrc;
if ($model instanceof Page) {
$pageImageModel = PageImage::firstOrCreate(['src' => $imageSrc, 'page_id' => $model->id]);
$pageImageModel->title = $model->title;
$pageImageModel->caption = $pageImageModel->title;
$pageImageModel->save();
}
}
return $imageMeta;
}
Expand Down

0 comments on commit bc837b2

Please sign in to comment.