22
33namespace Code4mk \LaraHead ;
44
5+ /**
6+ * @author @code4mk <hiremostafa@gmail.com>
7+ * @author @0devco <with@0dev.co>
8+ * @copyright 0dev.co (https://0dev.co)
9+ */
10+
511use Illuminate \Support \HtmlString ;
612use Illuminate \Support \Arr ;
713
8- class Og
14+ class Head
915{
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 ;
1422
1523 public function setTitle ($ data )
1624 {
@@ -22,8 +30,6 @@ public function getTitle()
2230 return $ this ->title ;
2331 }
2432
25-
26-
2733 public function setMeta ($ name ,$ data = [])
2834 {
2935 $ this ->metas [$ name ] = $ this ->toHtmlString ('<meta ' . $ this ->attributes ($ data ) . '> ' );
@@ -34,14 +40,24 @@ public function getMeta($key)
3440 return Arr::get ($ this ->metas , $ key , '' );
3541 }
3642
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+
3753 public function setLink ($ name ,$ data = [])
3854 {
39- $ this ->metas [$ name ] = $ this ->toHtmlString ('<link ' . $ this ->attributes ($ data ) . '> ' );
55+ $ this ->links [$ name ] = $ this ->toHtmlString ('<link ' . $ this ->attributes ($ data ) . '> ' );
4056 }
4157
4258 public function getLink ($ key )
4359 {
44- return Arr::get ($ this ->metas , $ key , '' );
60+ return Arr::get ($ this ->links , $ key , '' );
4561 }
4662
4763 public function setOg ($ data = [])
@@ -53,9 +69,7 @@ public function setOg($data = [])
5369
5470 public function getOg ()
5571 {
56- //$m = implode("\n",$this->ogs)."</pre>";
5772 $ m = "\t\t" ;
58-
5973 return implode ("\n{$ m }" ,$ this ->ogs );
6074 }
6175
@@ -68,14 +82,9 @@ public function setTwitCards($data = [])
6882
6983 public function getTwitCards ()
7084 {
71- //$m = implode("\n",$this->ogs)."</pre>";
7285 $ m = "\t\t" ;
73-
7486 return implode ("\n{$ m }" ,$ this ->cards );
7587 }
76-
77-
78-
7988 /**
8089 * Build an HTML attribute string from an array.
8190 *
@@ -103,33 +112,22 @@ public function attributes($attributes)
103112 *
104113 * @return string
105114 */
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 ) . '" ' ;
133119 }
120+ }
134121
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+ }
135133}
0 commit comments