Skip to content

Commit 4aef9bb

Browse files
islam khalilislam khalil
islam khalil
authored and
islam khalil
committed
yes
1 parent a735265 commit 4aef9bb

File tree

1 file changed

+119
-40
lines changed

1 file changed

+119
-40
lines changed

application/libraries/Neat.php

+119-40
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
class Neat
44
{
55

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();
1518

1619
public function __construct() {
1720

@@ -34,82 +37,158 @@ function setLayout($name) {
3437

3538
}
3639

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) ) {
4043

4144
$this->data = array_merge($this->data, $data);
42-
45+
4346
}
44-
47+
4548
$content_layout = array();
49+
$content_layout['content_for_layout'] = $this->ci_instance->load->view($view, $this->data, true);
4650

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());
4856

4957
if ($return) {
50-
58+
5159
$output = $this->ci_instance->load->view($this->layout, $content_layout, true);
5260
return $output;
53-
61+
5462
} else {
5563

5664
$this->ci_instance->load->view($this->layout, $content_layout, false);
57-
65+
5866
}
59-
67+
6068
}
61-
69+
6270
function get_elements($name) {
6371

6472
$output = $this->ci_instance->load->view($this->elements_folder.'/'.$name, $this->data, false) ;
6573
return $output;
66-
74+
6775
}
68-
76+
6977
// Must be called before render method so data applies to view
7078
public function bind_data($key, $value) {
7179

7280
$this->data[$key] = $value;
7381
return $this;
74-
82+
7583
}
7684

85+
public function setPageTitle($page_title) {
86+
87+
$this->page_title=$page_title;
88+
89+
}
90+
7791
public function css($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE) {
78-
92+
7993
$css_output = '';
80-
94+
8195
if (strpos($href, '//') !== false) {
82-
96+
8397
$this->css_output[] = link_tag($href , $rel, $type, $title, $media, $index_page = FALSE);
84-
98+
8599
}else{
86-
100+
87101
$this->css_output[] = link_tag($this->html_webroot.$href , $rel, $type, $title, $media, $index_page = FALSE);
88-
102+
89103
}
90104

91-
92105
}
93-
94-
public function js($src = '', $language = 'javascript', $type = 'text/javascript') {
95106

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){
99110

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+
}
101120

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+
}
103132

104133
}
105-
134+
106135
}
107-
136+
108137
public function meta_tag_link($name = "", $content = "", $type = 'name') {
109138

110139
$this->metatags[]=meta($name,$content,$type);
111140

112141
}
113-
114142

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+
115194
}

0 commit comments

Comments
 (0)