1
|
|
|
<?php namespace Arcanesoft\Seo\Helpers; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Arr; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SeoChecker |
7
|
|
|
* |
8
|
|
|
* @package Arcanesoft\Seo\Helpers |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class SeoChecker |
12
|
|
|
{ |
13
|
|
|
/* ----------------------------------------------------------------- |
14
|
|
|
| Constants |
15
|
|
|
| ----------------------------------------------------------------- |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
const STATUS_DANGER = 'danger'; |
19
|
|
|
const STATUS_GOOD = 'good'; |
20
|
|
|
const STATUS_WARNING = 'warning'; |
21
|
|
|
|
22
|
|
|
/* ----------------------------------------------------------------- |
23
|
|
|
| Main Methods |
24
|
|
|
| ----------------------------------------------------------------- |
25
|
|
|
*/ |
26
|
|
|
/** |
27
|
|
|
* Check the title content. |
28
|
|
|
* |
29
|
|
|
* @param string $title |
30
|
|
|
* @param int $min |
31
|
|
|
* @param int $max |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public static function checkTitle($title, $min = 40, $max = 60) |
36
|
|
|
{ |
37
|
|
|
return self::check($title, $min, $max); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Check the description content. |
42
|
|
|
* |
43
|
|
|
* @param string $description |
44
|
|
|
* @param int $min |
45
|
|
|
* @param int $max |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public static function checkDescription($description, $min = 140, $max = 160) |
50
|
|
|
{ |
51
|
|
|
return self::check($description, $min, $max); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the label class for the given status. |
56
|
|
|
* |
57
|
|
|
* @param string $status |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public static function label($status) |
62
|
|
|
{ |
63
|
|
|
$statuses = [ |
64
|
|
|
SeoChecker::STATUS_DANGER => 'danger', |
65
|
|
|
SeoChecker::STATUS_GOOD => 'success', |
66
|
|
|
SeoChecker::STATUS_WARNING => 'warning', |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
return Arr::get($statuses, $status, 'default'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/* ----------------------------------------------------------------- |
73
|
|
|
| Other Methods |
74
|
|
|
| ----------------------------------------------------------------- |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Check the value with min & max length. |
79
|
|
|
* |
80
|
|
|
* @param string $value |
81
|
|
|
* @param int $min |
82
|
|
|
* @param int $max |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
protected static function check($value, $min, $max) |
87
|
|
|
{ |
88
|
|
|
$length = strlen($value); |
89
|
|
|
|
90
|
|
|
if ($length < $min) |
91
|
|
|
return self::STATUS_WARNING; |
92
|
|
|
|
93
|
|
|
if ($min <= $length && $length <= $max) |
94
|
|
|
return self::STATUS_GOOD; |
95
|
|
|
|
96
|
|
|
return self::STATUS_DANGER; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|