forked from pkriete/simplypost
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayout.php
213 lines (179 loc) · 4.36 KB
/
Layout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* SimplyPost
*
* @author Pascal Kriete
* @package SimplyPost
* @copyright Copyright (c) 2008, Pascal Kriete
* @license http://www.opensource.org/licenses/mit-license.php
*/
// ------------------------------------------------------------------------
/**
* Backend Layout Library
*
* @package SimplyPost
* @subpackage Libraries
* @category Backend Layout
* @author Pascal Kriete
*/
class Layout {
var $CI;
var $template = 'template';
var $title = 'SimplyPost Backend';
var $section = '';
var $breadcrumb = '';
var $root_url;
var $root_text = 'Home';
/**
* Constructor
*
* @access public
*/
function Layout()
{
$this->CI =& get_instance();
log_message('debug', "Layout Class Initialized");
$this->root_url = site_url('');
}
// --------------------------------------------------------------------
/**
* Set the title
*
* @access public
* @param new title
*/
function set_title($title)
{
$this->title = $this->title.' - '.$title;
}
// --------------------------------------------------------------------
/**
* Set the section to determine
* the sidebar setting
*
* @access public
* @param new title
*/
function set_section($section)
{
$this->section = $section;
}
// --------------------------------------------------------------------
/**
* Generate the breadcrumb
*
* @access public
* @param new title
*/
function gen_crumb($crumbs = array())
{
$this->breadcrumb = anchor($this->root_url, $this->root_text);
if (count($crumbs) > 1)
{
$front = array_slice($crumbs, 0, -1);
$end = array_slice($crumbs, -1);
foreach($front as $url => $title)
{
$this->breadcrumb .= ' › '.anchor($url, $title);
}
$this->breadcrumb .= ' › '.current($end);
}
else
{
if (count($crumbs) > 0)
{
$this->breadcrumb .= ' › '.current($crumbs);
}
}
}
// --------------------------------------------------------------------
/**
* Custom breadcrumb text
*
* @access public
* @param text
*/
function custom_crumb($crumb_text = '')
{
$this->breadcrumb = $crumb_text;
}
// --------------------------------------------------------------------
/**
* Change breadcrumb root
*
* @access public
* @param text
*/
function crumb_root($root_text, $root_url = '/')
{
$this->root_text = $root_text;
$this->root_url = $root_url;
}
// --------------------------------------------------------------------
/**
* Get flashdata
*
* @access public
* @param main content, data
*/
function _get_flashdata()
{
// @TODO: Should really be a loop (might want to display one of each type)
$text = '';
$level = '';
if ($text = $this->CI->session->flashdata('error'))
{
$level = 'error';
}
else if ($text = $this->CI->session->flashdata('note'))
{
$level = 'note';
}
else if ($text = $this->CI->session->flashdata('success'))
{
$level = 'success';
}
$this->CI->load->vars(array(
'flash_txt' => $text,
'flash_lvl' => $level
));
}
// --------------------------------------------------------------------
/**
* Render Final Layout
*
* @access public
* @param main content, data
*/
function render($view, $data = array())
{
$data = array_merge(array(
'logged_in' => $this->CI->permission->logged_in(),
'title' => $this->title,
'breadcrumb' => $this->breadcrumb,
'section' => $this->section,
'content' => $view
), $data);
$this->_get_flashdata();
$this->_headers();
$this->CI->load->view($this->template, $data);
}
// --------------------------------------------------------------------
/**
* Send no-cache headers
*
* @access protected
*/
function _headers()
{
// Go 'Way Overboard(TM)' on strict non-caching headers
$this->CI->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$this->CI->output->set_header('Last-Modified: '.gmdate("D, d M Y H:i:s").' GMT');
$this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->CI->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->CI->output->set_header('Pragma: no-cache');
}
}
// END Layout class
/* End of file Layout.php */
/* Location: ./application/libraries/Layout.php */