4 * @package html Output class
5 * @desc the God class. It does everything, from database initialization
6 * to error reporting and page buffering. <- yeah it might be stupid
8 * @public the smarty template class instance and the theme path
9 * @private the page identification
12 class tsControllerHtml
extends tsController
{
25 * the constructor that does it all.
26 * starts output buffering, and initializes different things
29 public function __construct(){
30 $prevOutput = ob_get_clean(); // errors previous to the tsController init
32 // $this->output = $this->setOutput();
33 // Override standard string functions
34 if (extension_loaded('mbstring')) {
35 ini_set('mbstring.func_overload', 7);
37 $this->smarty
= new Smarty();
39 // set_error_handler(array($this, 'triggerError'));
40 // commented in the light of the xdebug profiling -
41 // dropped loading times by .01 seconds
42 if (!empty($prevOutput)) {
43 $this->errors
= "\n".'<!-- output previous init at '.date('G:i:s').' -->'."\n".$prevOutput."\n";
50 // get the persistent url params (NAV_VAR and ACT_VAR)
51 // $to = tsController::getRequest(NAV_VAR);
53 // $persistent[NAV_VAR] = $to;
55 // $do = tsController::getRequest(ACT_VAR);
57 // $persistent[ACT_VAR] = $do;
59 // $this->setParams($persistent);
65 // function __destruct(){
66 // $this->db->close();
69 protected function connectDb () {
70 $this->db
= sqlFactory
::connect (DB_TYPE
);
72 if (defined ('DB_NAME') && DB_NAME
&& !empty($this->db
->link
)) {
73 $this->db
->selectDatabase(DB_NAME
);
80 public function setTheme (){
83 $this->themePath
= THEME_PATH
. $this->theme
;
84 if (!is_dir($this->themePath
)) {
85 $this->theme
= DEFAULT_THEME
;
86 $this->themePath
= THEME_PATH
. $this->theme
;
89 $this->setThemeCookie();
92 private function setThemeCookie () {
93 if (empty ($_COOKIE['theme']) ||
$_COOKIE['theme'] != $this->theme
) {
94 $test = setcookie ('theme', $this->theme
, time()+
1296000, '/');
98 private function reportErrors (){
99 if (!stristr (C_SYSTEM_DEBUG_IPS
, $_SERVER['REMOTE_ADDR'])) {
102 if (!empty ($this->errors
)) {
103 $errors = $this->errors
;
104 $this->errors
= '<!-- ERRORS: '.get_class($this).' at '.date('G:i:s').'-->'."\n".$errors;
107 if (defined ('ERROR_LEVEL') && ERROR_LEVEL
== 9 )
108 $this->errors
.= "\n".var_export (debug_backtrace(), true);
109 switch (C_SYSTEM_DEBUG_METHOD
){
111 $this->smarty
->assign('errors', $this->errors
);
115 $mailMsg = $this->errors
;
116 // mail (DEBUG_MAIL,'DEBUG:',$mailMsg);
123 public function triggerError($errNo=0, $errStr='', $errFile='', $errLine=''){
124 if (empty($this->errors
)){
125 $this->errors
= "\n";
126 // if (is_a($this->smarty,'Smarty'))
127 // $this->smarty->assign('errors', var_export($this->errors));
131 $errType = 'WARNING';
136 case (256): // errNo = 4
137 $errType = 'USER_ERROR';
139 case (512): // errNo = 8
140 $errType = 'USER_WARNING';
142 case (1024): // errNo = 16
143 $errType = 'USER_NOTICE';
145 case (2048): // errNo = 16
146 $errType = 'USER_ERROR';
148 // case (4096): // errNo = 16
155 $baseColor = array('R'=>100,'G'=>16,'B'=>16);
156 $color = (string)dechex($baseColor['R']+
40 * (log($errNo, 2))).(string)dechex($baseColor['G']+
(20 - 4*log($errNo, 2))*(log($errNo, 2))).(string)dechex($baseColor['B']+
(20 - 4*log($errNo, 2))*(log($errNo, 2)));
158 $baseColor = array('R'=>16,'G'=>16,'B'=>100);
159 $errNo = $errNo / 128;
160 $color = (string)dechex($baseColor['R']+
(20 - 4*log($errNo, 2)) * (log($errNo, 2))).(string)dechex($baseColor['G']+
(20 - 4*log($errNo, 2))*(log($errNo, 2))).(string)dechex($baseColor['B']+
40*(log($errNo, 2)));
163 $this->errors
.= '<span style="color:#'.strtoupper($color).'">';
164 $this->errors
.= '<b>'.$errType.'</b> '.$errStr;
165 if (false || tsController
::getRequest('bt') == 'full') {
166 $this->errors
.= ' at line '.$errLine.' in file '.$errFile;
167 $t = debug_backtrace();
168 // $this->errors .= '<pre>'.var_export($t,true).'</pre>';
171 $this->errors
.= ' </span><br/>'."\n";
175 public function dispatch (){
180 if (!($this->smarty
instanceof Smarty
))
181 $this->smarty
= new Smarty();
183 $this->smarty
->compile_check
= true;
184 // $this->smarty->debugging = C_SYSTEM_DEBUG;
185 $this->smarty
->compile_dir
= S_C_TEMPL_DIR
;
187 $this->smarty
->assign('header', $this->themePath
. DIRECTORY_SEPARATOR
. S_TEMPL_DIR
. 'header.tpl');
188 $this->smarty
->assign('footer', $this->themePath
. DIRECTORY_SEPARATOR
. S_TEMPL_DIR
. 'footer.tpl');
190 $this->smarty
->assign('url', URL
);
191 $this->smarty
->assign('style', '');
192 $this->smarty
->assign('contact', tsController
::setRequest('contact'));
194 $className = get_class ($this);
195 $methArr = get_class_methods ($this);
196 // echo PAGE_PATH . $className . DIRECTORY_SEPARATOR . $className . '.tpl';
197 if (is_file (PAGE_PATH
. $className . DIRECTORY_SEPARATOR
. $className . '.tpl')) {
198 $this->smarty
->assign ('contentFile', PAGE_PATH
. $className . DIRECTORY_SEPARATOR
. $className . '.tpl');
200 $this->smarty
->assign ('contentFile', $this->themePath
. DIRECTORY_SEPARATOR
. S_TEMPL_DIR
. 'tpl404.tpl');
203 /* Loading of any varArray template variables we have in the derived classes
204 --------------------------------------------------------------------- */
205 if (is_array($this->varArray
)) {
206 $this->smarty
->assign ($this->varArray
);
209 // if(!empty($GLOBALS['errors'])) {
210 // $GLOBALS['errors'] = '.';
213 if (!C_SYSTEM_DEBUG
) {
217 $this->errors
.= ob_get_clean();
218 ob_start(); // clean output - heheh, yeah right :P
219 $this->reportErrors ();
222 // $this->smarty->assign ('time', true);
223 $this->content
= $this->smarty
->fetch ($this->themePath
. DIRECTORY_SEPARATOR
. S_TEMPL_DIR
. 'main.tpl');
225 $this->postDispatch ($this->content
);
229 private function postDispatch ($incString){
230 // check to see if we're a 404 error
231 if (get_class ($this) == 'tsControllerHtml') {// yes 404
232 header ("HTTP/1.0 404 Not Found");
235 if ( stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') && !C_SYSTEM_DEBUG
) {
236 header('Content-type: application/xhtml+xml');
238 header('Content-type: text/html');
242 array ('%TIME%','%QUERIES%', '%MEMUSED%'),
244 number_format(microtime (true) - $GLOBALS['st'] , 5, ',', '.'),
246 number_format(memory_get_usage()/1024, 3, ',', '.')