Custom SEO (#154)
* Enable Pro plan - WIP * no pricing page if have no paid plans * Set pricing ids in env * views & submissions FREE for all * extra param for env * form password FREE for all * Custom Code is PRO feature * Replace codeinput prism with codemirror * Better form Cleaning message * Added risky user email spam protection * fix form cleaning * Custom SEO * fix custom seo formcleaner * remvoe fix condition
This commit is contained in:
@@ -121,6 +121,9 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||
// Security & Privacy
|
||||
'can_be_indexed' => 'boolean',
|
||||
'password' => 'sometimes|nullable',
|
||||
|
||||
// Custom SEO
|
||||
'seo_meta' => 'nullable|array'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ class FormResource extends JsonResource
|
||||
'slack_webhook_url' => $this->slack_webhook_url,
|
||||
'discord_webhook_url' => $this->discord_webhook_url,
|
||||
'removed_properties' => $this->removed_properties,
|
||||
'last_edited_human' => $this->updated_at?->diffForHumans()
|
||||
'last_edited_human' => $this->updated_at?->diffForHumans(),
|
||||
'seo_meta' => $this->seo_meta
|
||||
] : [];
|
||||
|
||||
$baseData = $this->getFilteredFormData(parent::toArray($request), $this->userIsFormOwner());
|
||||
|
||||
@@ -83,7 +83,10 @@ class Form extends Model
|
||||
|
||||
// Security & Privacy
|
||||
'can_be_indexed',
|
||||
'password'
|
||||
'password',
|
||||
|
||||
// Custom SEO
|
||||
'seo_meta'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -91,7 +94,8 @@ class Form extends Model
|
||||
'database_fields_update' => 'array',
|
||||
'closes_at' => 'datetime',
|
||||
'tags' => 'array',
|
||||
'removed_properties' => 'array'
|
||||
'removed_properties' => 'array',
|
||||
'seo_meta' => 'object'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
|
||||
@@ -23,6 +23,9 @@ class FormCleaner
|
||||
|
||||
private array $data;
|
||||
|
||||
// For remove keys those have empty value
|
||||
private array $customKeys = ['seo_meta'];
|
||||
|
||||
private array $formDefaults = [
|
||||
'notifies' => false,
|
||||
'no_branding' => false,
|
||||
@@ -32,6 +35,7 @@ class FormCleaner
|
||||
'discord_webhook_url' => null,
|
||||
'editable_submissions' => false,
|
||||
'custom_code' => null,
|
||||
'seo_meta' => []
|
||||
];
|
||||
|
||||
private array $fieldDefaults = [
|
||||
@@ -49,6 +53,7 @@ class FormCleaner
|
||||
'discord_webhook_url' => "Discord webhook disabled.",
|
||||
'editable_submissions' => 'Users will not be able to edit their submissions.',
|
||||
'custom_code' => 'Custom code was disabled',
|
||||
'seo_meta' => 'Custom code was disabled',
|
||||
|
||||
// For fields
|
||||
'file_upload' => "Link field is not a file upload.",
|
||||
@@ -202,6 +207,9 @@ class FormCleaner
|
||||
// Get value from form
|
||||
$formVal = Arr::get($data, $key);
|
||||
|
||||
// Transform customkeys values
|
||||
$formVal = $this->cleanCustomKeys($key, $formVal);
|
||||
|
||||
// Transform boolean values
|
||||
$formVal = (($formVal === 0 || $formVal === "0") ? false : $formVal);
|
||||
$formVal = (($formVal === 1 || $formVal === "1") ? true : $formVal);
|
||||
@@ -242,4 +250,20 @@ class FormCleaner
|
||||
}*/
|
||||
}
|
||||
|
||||
// Remove keys those have empty value
|
||||
private function cleanCustomKeys($key, $formVal)
|
||||
{
|
||||
if (in_array($key, $this->customKeys) && $formVal !== null) {
|
||||
$newVal = [];
|
||||
foreach ($formVal as $k => $val) {
|
||||
if ($val) {
|
||||
$newVal[$k] = $val;
|
||||
}
|
||||
}
|
||||
return $newVal;
|
||||
}
|
||||
|
||||
return $formVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -160,15 +160,25 @@ class SeoMetaResolver
|
||||
{
|
||||
$form = Form::whereSlug($this->patternData['slug'])->firstOrFail();
|
||||
|
||||
$meta = [
|
||||
'title' => $form->title . $this->titleSuffix(),
|
||||
];
|
||||
if($form->description){
|
||||
$meta = [];
|
||||
if ($form->is_pro && $form->seo_meta->page_title) {
|
||||
$meta['title'] = $form->seo_meta->page_title;
|
||||
} else {
|
||||
$meta['title'] = $form->title . $this->titleSuffix();
|
||||
}
|
||||
|
||||
if ($form->is_pro && $form->seo_meta->page_description) {
|
||||
$meta['description'] = $form->seo_meta->page_description;
|
||||
} else if ($form->description) {
|
||||
$meta['description'] = Str::of($form->description)->limit(160);
|
||||
}
|
||||
if($form->cover_picture){
|
||||
|
||||
if ($form->is_pro && $form->seo_meta->page_thumbnail) {
|
||||
$meta['image'] = $form->seo_meta->page_thumbnail;
|
||||
} else if ($form->cover_picture) {
|
||||
$meta['image'] = $form->cover_picture;
|
||||
}
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user