2
2
3
3
namespace Code4mk \LaraHead ;
4
4
5
+ /**
6
+ * @author @code4mk <hiremostafa@gmail.com>
7
+ * @author @0devco <with@0dev.co>
8
+ * @copyright 0dev.co (https://0dev.co)
9
+ */
10
+
5
11
use Illuminate \Support \HtmlString ;
6
12
use Illuminate \Support \Arr ;
7
13
8
- class Og
14
+ class Head
9
15
{
10
- public $ metas = [];
11
- public $ ogs = [];
12
- public $ cards = [];
13
- public $ title ;
16
+ private $ metas = [];
17
+ private $ links = [];
18
+ private $ scripts = [];
19
+ private $ ogs = [];
20
+ private $ cards = [];
21
+ private $ title ;
14
22
15
23
public function setTitle ($ data )
16
24
{
@@ -22,8 +30,6 @@ public function getTitle()
22
30
return $ this ->title ;
23
31
}
24
32
25
-
26
-
27
33
public function setMeta ($ name ,$ data = [])
28
34
{
29
35
$ this ->metas [$ name ] = $ this ->toHtmlString ('<meta ' . $ this ->attributes ($ data ) . '> ' );
@@ -34,14 +40,24 @@ public function getMeta($key)
34
40
return Arr::get ($ this ->metas , $ key , '' );
35
41
}
36
42
43
+ public function setScript ($ name ,$ data = [])
44
+ {
45
+ $ this ->scripts [$ name ] = $ this ->toHtmlString ('<script ' . $ this ->attributes ($ data ) . '> ' . "" . "</script> " );
46
+ }
47
+
48
+ public function getScript ($ key )
49
+ {
50
+ return Arr::get ($ this ->scripts , $ key , '' );
51
+ }
52
+
37
53
public function setLink ($ name ,$ data = [])
38
54
{
39
- $ this ->metas [$ name ] = $ this ->toHtmlString ('<link ' . $ this ->attributes ($ data ) . '> ' );
55
+ $ this ->links [$ name ] = $ this ->toHtmlString ('<link ' . $ this ->attributes ($ data ) . '> ' );
40
56
}
41
57
42
58
public function getLink ($ key )
43
59
{
44
- return Arr::get ($ this ->metas , $ key , '' );
60
+ return Arr::get ($ this ->links , $ key , '' );
45
61
}
46
62
47
63
public function setOg ($ data = [])
@@ -53,9 +69,7 @@ public function setOg($data = [])
53
69
54
70
public function getOg ()
55
71
{
56
- //$m = implode("\n",$this->ogs)."</pre>";
57
72
$ m = "\t\t" ;
58
-
59
73
return implode ("\n{$ m }" ,$ this ->ogs );
60
74
}
61
75
@@ -68,14 +82,9 @@ public function setTwitCards($data = [])
68
82
69
83
public function getTwitCards ()
70
84
{
71
- //$m = implode("\n",$this->ogs)."</pre>";
72
85
$ m = "\t\t" ;
73
-
74
86
return implode ("\n{$ m }" ,$ this ->cards );
75
87
}
76
-
77
-
78
-
79
88
/**
80
89
* Build an HTML attribute string from an array.
81
90
*
@@ -103,33 +112,22 @@ public function attributes($attributes)
103
112
*
104
113
* @return string
105
114
*/
106
- protected function attributeElement ($ key , $ value )
107
- {
108
- // For numeric keys we will assume that the value is a boolean attribute
109
- // where the presence of the attribute represents a true value and the
110
- // absence represents a false value.
111
- // This will convert HTML attributes such as "required" to a correct
112
- // form instead of using incorrect numerics.
113
-
114
-
115
- // Treat boolean attributes as HTML properties
116
-
117
-
118
- if (! is_null ($ value )) {
119
- return $ key . '=" ' . e ($ value , false ) . '" ' ;
120
- }
121
- }
122
-
123
- /**
124
- * Transform the string to an Html serializable object
125
- *
126
- * @param $html
127
- *
128
- * @return \Illuminate\Support\HtmlString
129
- */
130
- protected function toHtmlString ($ html )
131
- {
132
- return new HtmlString ($ html );
115
+ protected function attributeElement ($ key , $ value )
116
+ {
117
+ if (! is_null ($ value )) {
118
+ return $ key . '=" ' . e ($ value , false ) . '" ' ;
133
119
}
120
+ }
134
121
122
+ /**
123
+ * Transform the string to an Html serializable object
124
+ *
125
+ * @param $html
126
+ *
127
+ * @return \Illuminate\Support\HtmlString
128
+ */
129
+ protected function toHtmlString ($ html )
130
+ {
131
+ return new HtmlString ($ html );
132
+ }
135
133
}
0 commit comments