Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
seo.php
1<?php
3
4class Seo
5{
6 const TITLE = 'title';
7 const BROWSER_TITLE = 'browser_title';
8 const KEYWORDS = 'keywords';
9 const DESCRIPTION = 'description';
10
12 protected $properties = [];
13
14 public function __construct()
15 {
16
17 }
18
23 public function setProperties(array $values)
24 {
25 $values = array_filter($values, [__CLASS__, 'clearValues'], ARRAY_FILTER_USE_BOTH);
26 if (!empty($values))
27 {
28 $this->properties = array_merge($this->properties, $values);
29 }
30 }
31
37 public function setProperty($name, $value)
38 {
39 $name = (string)$name;
40 if ($name !== '' && $value !== null)
41 {
42 $this->properties[$name] = $value;
43 }
44 }
45
49 public function getProperties()
50 {
51 return (!empty($this->properties) ? $this->properties : null);
52 }
53
58 public function getProperty($name)
59 {
60 $name = (string)$name;
61 if ($name !== '')
62 {
63 return (isset($this->properties[$name]) ? $this->properties[$name] : null);
64 }
65 return null;
66 }
67
71 public function clear()
72 {
73 $this->clearProperties();
74 }
75
79 public function clearProperties()
80 {
81 $this->properties = [];
82 }
83
88 public function clearProperty($name)
89 {
90 $name = (string)$name;
91 if ($name !== '' && isset($this->properties[$name]))
92 {
93 unset($this->properties[$name]);
94 }
95 }
96
101 public function setTitle($value)
102 {
103 if (is_string($value))
104 {
105 $this->setProperty(self::TITLE, strip_tags(trim($value)));
106 }
107 }
108
113 public function setBrowserTitle($value)
114 {
115 if (is_string($value))
116 {
117 $this->setProperty(self::BROWSER_TITLE, strip_tags(trim($value)));
118 }
119 }
120
125 public function setKeywords($value)
126 {
127 if (is_array($value))
128 {
129 $value = array_filter($value, [__CLASS__, 'clearValues'], ARRAY_FILTER_USE_BOTH);
130 $value = implode(', ', $value);
131 }
132 if (is_string($value))
133 {
134 $this->setProperty(self::KEYWORDS, strip_tags(trim($value)));
135 }
136 }
137
142 public function setDescription($value)
143 {
144 if (is_string($value))
145 {
146 $this->setProperty(self::DESCRIPTION, strip_tags(trim($value)));
147 }
148 }
149
153 public function getTitle()
154 {
155 return $this->getProperty(self::TITLE);
156 }
157
161 public function getBrowserTitle()
162 {
163 return $this->getProperty(self::BROWSER_TITLE);
164 }
165
169 public function getKeywords()
170 {
171 return $this->getProperty(self::KEYWORDS);
172 }
173
177 public function getDescription()
178 {
179 return $this->getProperty(self::DESCRIPTION);
180 }
181
187 protected static function clearValues($value, $name)
188 {
189 return ((string)$name !== '' && $value !== null);
190 }
191}
static clearValues($value, $name)
Definition seo.php:187
setProperties(array $values)
Definition seo.php:23
setProperty($name, $value)
Definition seo.php:37