2 abstract class tsController
{
6 $time = array('start' => 0,'end' => 0);
8 static private $instance = null;
10 static protected function memcacheEnabled () {
11 // this sucks on so many ways
12 if (extension_loaded ('memcache') && C_USE_MEMCACHE
== true) {
13 $memcache = new Memcache
;
14 if (@$memcache->connect('localhost', 11211)) {
15 memcache_debug (true);
23 * function to redirect the client
27 * @param bool $onlyJScript
29 static public function redirect ($url, $die = true, $onlyJScript = false) {
30 if ($onlyJScript == true ||
headers_sent()) {
31 printf ('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Redirect</title><meta http-equiv="Refresh" content="0;url=%s" /></head><body onload="try {self.location.href=\'%s\' } catch(e) {}"><p><a href="%s">REDIRECTING - PLEASE CLICK HERE !</a></p></body></html>', $url, $url, $url);
34 header ('Location: '.str_replace ('&', '&', $url));
41 // FIXME: I should stop using REQUEST for getting get and post variables !!!
42 static public function getRequest($varName = null) {
43 return tsUrl
::getRequest($varName);
47 * function to generate URLs compatible with tsController
49 * @param string $whereTo the page name
50 * @param string $varVal additional params
51 * @param string $method [get|TODO post]
55 public function setRequest ($whereTo = null, $varVal = array()){
56 if (!empty ($this->params
)) {
57 if (!empty ($whereTo))
58 array_shift ($this->params
);
59 array_merge ($this->params
, $varVal);
62 return tsUrl
::setRequest ($whereTo, $varVal);
66 * function to set the persistent URL parameters
67 * @param array $incArray
69 public function setParams ($incArray = array ()) {
70 if (!empty ($incArray))
71 $this->params
= array_merge ($this->params
, $incArray);
76 public function getParams () {
80 public function store () {
85 * static method to return the tsController singleton instance
88 * @return tsController
90 static function getInstance ($to) {
91 // we have already initialized the page singleton
92 if (tsController
::$instance instanceof tsController
) {
93 return tsController
::$instance;
95 // the memcache object should also be a singleton
96 // with a static instance I can call wherever.
97 if (extension_loaded ('Memcache')) {
98 $memcache = tsController
::memcacheEnabled ();
100 tsController
::$instance = $memcache->get ( tsController
::getHash ());
103 if (!(tsController
::$instance instanceof tsController
)) {
104 tsController
::$instance = new $to ();
107 return tsController
::$instance;
110 static public function getHash () {
111 if (empty ($_SERVER['QUERY_STRING'])) {
112 if (stristr($_SERVER['SERVER_SOFTWARE'], 'Apache'))
113 $redirectUri = 'REDIRECT_URL';
114 elseif (stristr($_SERVER['SERVER_SOFTWARE'], 'lighttpd'))
115 $redirectUri = 'REDIRECT_URI';
117 $redirectUri = 'REDIRECT_URI';
118 $qstring = $_SERVER[$redirectUri];
120 $qstring = $_SERVER['QUERY_STRING'];
122 return md5($_SERVER['HTTP_HOST'] . $qstring);
125 private function setHeaders () {
126 // set expire header.
127 header ('Expires: '.strftime ('%a, %d %m %Y %T GMT', time()+
2419200)); // one month
130 private function addToCache () {
131 if (!extension_loaded ('Memcache'))
133 $memcache = tsController
::memcacheEnabled ();
134 $hash = tsController
::getHash ();
135 if ($memcache instanceof Memcache
&& !$memcache->get ($hash)) {
136 $memcache->connect('localhost', 11211);
137 $memcache->add ($hash , $this, MEMCACHE_COMPRESSED
);
141 public function getTheme(){
142 // this should most probably be changed to tsController::getRequest ('theme')
143 if (!empty($_GET['theme']) && isDebug()) {
144 $this->theme
= $_GET['theme'];
145 } elseif (!empty($_POST['theme'])) {
146 $this->theme
= $_POST['theme'];
147 } elseif (!empty($_COOKIE['theme'])) {
148 $this->theme
= $_COOKIE['theme'];
150 if (empty($this->theme
) ||
151 !is_dir(THEME_PATH
.$this->theme
) ||
152 !is_dir(THEME_PATH
.$this->theme
. DIRECTORY_SEPARATOR
. "_css") ||
153 !is_dir(THEME_PATH
.$this->theme
. DIRECTORY_SEPARATOR
. "_templates")
155 $this->theme
= DEFAULT_THEME
;
161 public function __construct() {}
163 public function __destruct () {}
165 public function dispatch () {