1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Win\Utils; |
4
|
|
|
|
5
|
|
|
use Win\Utils\Str; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Utilitário de Seo |
9
|
|
|
*/ |
10
|
|
|
abstract class Seo |
11
|
|
|
{ |
12
|
|
|
public static $titlePrefix = ''; |
13
|
|
|
public static $titleSuffix = ''; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Keywords padrão. |
17
|
|
|
* Usadas quando as keywords informadas não tenha o tamanho suficiente |
18
|
|
|
* @var string[] |
19
|
|
|
*/ |
20
|
|
|
public static $keywords = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Descrição padrão. |
24
|
|
|
* Usadas quando a descrição informada não tenha o tamanho suficiente |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public static $description = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Retorna o título com o nome da aplicação no final |
31
|
|
|
* Mantendo o máximo de caracteres |
32
|
|
|
* @param string $title |
33
|
|
|
* @param string $maxLength |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public static function title($title, $maxLength = 70) |
37
|
|
|
{ |
38
|
|
|
$staticLength = Str::length(static::$titlePrefix) + Str::length(static::$titleSuffix); |
39
|
|
|
$maxLength = $maxLength - $staticLength; |
40
|
|
|
|
41
|
|
|
return static::$titlePrefix . Str::truncate($title, $maxLength) . static::$titleSuffix; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Retorna uma string em minúscula, separada por virgula |
47
|
|
|
* @param string[] $keys |
48
|
|
|
* @param int $maxLength |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public static function keywords($keys, $maxLength = 100) |
52
|
|
|
{ |
53
|
|
|
$keys = array_merge($keys, static::$keywords); |
54
|
|
|
$keys = Str::truncate(implode(', ', array_filter($keys)), $maxLength); |
55
|
|
|
|
56
|
|
|
return Str::lower(str_replace([',...', '...'], '', $keys)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Retorna a 'description' com tamanho ideal |
61
|
|
|
* @param string $description |
62
|
|
|
* @param int $maxLength |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public static function description($description, $maxLength = 150) |
66
|
|
|
{ |
67
|
|
|
if (Str::length($description) > 0) { |
68
|
|
|
return Str::truncate($description, $maxLength); |
69
|
|
|
} else { |
70
|
|
|
return static::$description; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|