3
3
class Neat
4
4
{
5
5
6
- private $ config ;
7
- private $ layout ;
8
- private $ data = array ();
9
- private $ ci_instance ;
10
- private $ elements_folder ;
11
- private $ html_webroot ;
12
- public $ css_output = array ();
13
- public $ js_output = array ();
14
- public $ metatags = array ();
6
+ private $ config ;
7
+ private $ layout ;
8
+ private $ data = array ();
9
+ private $ ci_instance ;
10
+ private $ elements_folder ;
11
+ private $ html_webroot ;
12
+
13
+ public $ page_title ;
14
+ public $ css_output = array ();
15
+ public $ js_output = array ();
16
+ public $ js_body_output = array ();
17
+ public $ metatags = array ();
15
18
16
19
public function __construct () {
17
20
@@ -34,82 +37,158 @@ function setLayout($name) {
34
37
35
38
}
36
39
37
- function render ($ view , $ data = null , $ return = false ) {
38
-
39
- if ($ data != null && is_array ($ data )) {
40
+ function render ( $ view , $ data = null , $ return = false ) {
41
+
42
+ if ( $ data != null && is_array ($ data ) ) {
40
43
41
44
$ this ->data = array_merge ($ this ->data , $ data );
42
-
45
+
43
46
}
44
-
47
+
45
48
$ content_layout = array ();
49
+ $ content_layout ['content_for_layout ' ] = $ this ->ci_instance ->load ->view ($ view , $ this ->data , true );
46
50
47
- $ content_layout ['content_for_layout ' ] = $ this ->ci_instance ->load ->view ($ view , $ this ->data , true );
51
+ $ content_layout ['title_for_layout ' ] = trim ($ this ->page_title );
52
+ $ content_layout ['meta_for_layout ' ] = trim ($ this ->get_meta ());
53
+ $ content_layout ['style_for_layout ' ] = trim ($ this ->get_css ());
54
+ $ content_layout ['script_for_layout ' ] = trim ($ this ->get_js ());
55
+ $ content_layout ['script_for_body ' ] = trim ($ this ->get_js_in_body ());
48
56
49
57
if ($ return ) {
50
-
58
+
51
59
$ output = $ this ->ci_instance ->load ->view ($ this ->layout , $ content_layout , true );
52
60
return $ output ;
53
-
61
+
54
62
} else {
55
63
56
64
$ this ->ci_instance ->load ->view ($ this ->layout , $ content_layout , false );
57
-
65
+
58
66
}
59
-
67
+
60
68
}
61
-
69
+
62
70
function get_elements ($ name ) {
63
71
64
72
$ output = $ this ->ci_instance ->load ->view ($ this ->elements_folder .'/ ' .$ name , $ this ->data , false ) ;
65
73
return $ output ;
66
-
74
+
67
75
}
68
-
76
+
69
77
// Must be called before render method so data applies to view
70
78
public function bind_data ($ key , $ value ) {
71
79
72
80
$ this ->data [$ key ] = $ value ;
73
81
return $ this ;
74
-
82
+
75
83
}
76
84
85
+ public function setPageTitle ($ page_title ) {
86
+
87
+ $ this ->page_title =$ page_title ;
88
+
89
+ }
90
+
77
91
public function css ($ href = '' , $ rel = 'stylesheet ' , $ type = 'text/css ' , $ title = '' , $ media = '' , $ index_page = FALSE ) {
78
-
92
+
79
93
$ css_output = '' ;
80
-
94
+
81
95
if (strpos ($ href , '// ' ) !== false ) {
82
-
96
+
83
97
$ this ->css_output [] = link_tag ($ href , $ rel , $ type , $ title , $ media , $ index_page = FALSE );
84
-
98
+
85
99
}else {
86
-
100
+
87
101
$ this ->css_output [] = link_tag ($ this ->html_webroot .$ href , $ rel , $ type , $ title , $ media , $ index_page = FALSE );
88
-
102
+
89
103
}
90
104
91
-
92
105
}
93
-
94
- public function js ($ src = '' , $ language = 'javascript ' , $ type = 'text/javascript ' ) {
95
106
96
- if ( strpos ( $ src, ' // ' ) !== false ) {
97
-
98
- $ this -> js_output [] = ' <script type=" ' . $ type . ' " src=" ' . $ src . ' "></script> ' ;
107
+ public function js ( $ src = '' , $ in_body = false , $ language = ' javascript ' , $ type = ' text/javascript ' ) {
108
+
109
+ if (! $ in_body ){
99
110
100
- }else {
111
+ if (strpos ($ src , '// ' ) !== false ) {
112
+
113
+ $ this ->js_output [] = '<script type=" ' .$ type .'" src=" ' .$ src .'"></script> ' ;
114
+
115
+ }else {
116
+
117
+ $ this ->js_output [] = '<script type=" ' .$ type .'" src=" ' .$ this ->html_webroot .$ src .'"></script> ' ;
118
+
119
+ }
101
120
102
- $ this ->js_output [] = '<script type=" ' .$ type .'" src=" ' .$ this ->html_webroot .$ src .'"></script> ' ;
121
+ } else {
122
+
123
+ if (strpos ($ src , '// ' ) !== false ) {
124
+
125
+ $ this ->js_body_output [] = '<script type=" ' .$ type .'" src=" ' .$ src .'"></script> ' ;
126
+
127
+ }else {
128
+
129
+ $ this ->js_body_output [] = '<script type=" ' .$ type .'" src=" ' .$ this ->html_webroot .$ src .'"></script> ' ;
130
+
131
+ }
103
132
104
133
}
105
-
134
+
106
135
}
107
-
136
+
108
137
public function meta_tag_link ($ name = "" , $ content = "" , $ type = 'name ' ) {
109
138
110
139
$ this ->metatags []=meta ($ name ,$ content ,$ type );
111
140
112
141
}
113
-
114
142
143
+ public function get_js () {
144
+ $ js_links ='' ;
145
+ if (!empty ($ this ->js_output )) {
146
+ foreach ($ this ->js_output as $ js ) {
147
+ $ js_links .= $ js ;
148
+ }
149
+ }
150
+ unset($ this ->js_output );
151
+ return $ js_links ;
152
+ }
153
+
154
+ public function get_js_in_body () {
155
+ $ js_body_links = '' ;
156
+ if (!empty ($ this ->js_body_output )) {
157
+ foreach ($ this ->js_body_output as $ js ) {
158
+ $ js_body_links .= $ js ;
159
+ }
160
+ }
161
+ unset($ this ->js_body_output );
162
+ return $ js_body_links ;
163
+ }
164
+
165
+ public function get_css () {
166
+ $ css_links = '' ;
167
+ if (!empty ($ this ->css_output )) {
168
+ foreach ($ this ->css_output as $ css ) {
169
+ $ css_links .= $ css ;
170
+ }
171
+ }
172
+ unset($ this ->css_output );
173
+ return $ css_links ;
174
+ }
175
+
176
+ public function get_meta () {
177
+ $ meta_link ='' ;
178
+ if (!empty ($ this ->metatags )) {
179
+ foreach ($ this ->metatags as $ meta ) {
180
+ $ meta_link .= $ meta ;
181
+ }
182
+ }
183
+ unset($ this ->metatags );
184
+ return $ meta_link ;
185
+ }
186
+
187
+ function handle_qoutes ($ txt ){
188
+ //return htmlspecialchars(stripslashes($txt), ENT_QUOTES);
189
+ return html_entity_decode (stripslashes ($ txt ),ENT_QUOTES , 'UTF-8 ' );
190
+ }
191
+
192
+
193
+
115
194
}
0 commit comments