From 3666027f2dc34707fe42f2c625c461ce91887f70 Mon Sep 17 00:00:00 2001 From: habarnam Date: Mon, 2 Jun 2008 22:22:38 +0300 Subject: [PATCH] Revert "* initial work towards factorizing the controllers (yeah, now it's tsControllerSomething not tsPage" This reverts commit 6565529c0f4b1e4b56abb504eca7faaab3741aad. --- _pages/contact/code.php | 12 +-- _pages/index/code.php | 40 +++---- _pages/test/code.php | 8 +- _res/_libs/ctrlfactory.class.php | 35 ------- _res/_libs/functions.inc.php | 1 - _res/_libs/mysqlim.class.php | 2 +- _res/_libs/output.class.php | 79 ++++++++++++++ _res/_libs/tdoabstract.class.php | 6 +- _res/_libs/tscontroller.class.php | 116 --------------------- _res/_libs/tscontrollercss.class.php | 48 --------- _res/_libs/tscontrollerrss.class.php | 81 -------------- _res/_libs/tsimage2.class.php | 2 +- ...tscontrollerhtml.class.php => tspage.class.php} | 79 +++++++++++--- _res/_libs/tsurl.class.php | 75 +++++++++++-- _res/_themes/default/_templates/rss.tpl | 22 ---- _res/loader.php | 16 ++- adm/_pages/index/code.php | 72 ++++++------- adm/_pages/login/code.php | 20 ++-- adm/_pages/upload/code.php | 8 +- ...erhtmladmin.class.php => tsadminpage.class.php} | 6 +- adm/_res/_libs/tsfile.class.php | 4 +- adm/_res/loader.php | 19 +++- image.php | 2 +- img2.php | 6 +- rss.php | 76 ++++++++++++-- style.php | 24 ++++- 26 files changed, 422 insertions(+), 437 deletions(-) delete mode 100644 _res/_libs/ctrlfactory.class.php create mode 100644 _res/_libs/output.class.php delete mode 100644 _res/_libs/tscontroller.class.php delete mode 100644 _res/_libs/tscontrollercss.class.php delete mode 100644 _res/_libs/tscontrollerrss.class.php rename _res/_libs/{tscontrollerhtml.class.php => tspage.class.php} (74%) delete mode 100644 _res/_themes/default/_templates/rss.tpl rename adm/_res/_libs/{tscontrollerhtmladmin.class.php => tsadminpage.class.php} (54%) rewrite rss.php (77%) diff --git a/_pages/contact/code.php b/_pages/contact/code.php index 074aa46..75b797c 100644 --- a/_pages/contact/code.php +++ b/_pages/contact/code.php @@ -1,10 +1,10 @@ varArray['Contact']; parent::__construct(); - $action = tsController::getRequest ('do'); + $action = tsPage::getRequest ('do'); if (empty($action)) $action = 'display'; @@ -15,17 +15,17 @@ class contact extends tsControllerHtml { } private function display() { - $this->varArray['action'] = tsController::setRequest ('contact', array('do' => 'send')); + $this->varArray['action'] = tsPage::setRequest ('contact', array('do' => 'send')); $this->varArray['contentFile'] = dirname(__FILE__).'/pages/form.tpl'; } private function send() { - $m = tsController::getRequest('m'); - $t = tsController::getRequest('t'); + $m = tsPage::getRequest('m'); + $t = tsPage::getRequest('t'); @mail (C_SYSTEM_EMAIL, 'Mesaj de la '.$m, $t, 'From:'.$m.'\r\nReply-to:'.$m); - tsController::redirect (tsController::setRequest ('contact', array ('do' => 'thank'))); + tsPage::redirect (tsPage::setRequest ('contact', array ('do' => 'thank'))); } diff --git a/_pages/index/code.php b/_pages/index/code.php index e043356..27ffeed 100644 --- a/_pages/index/code.php +++ b/_pages/index/code.php @@ -1,5 +1,5 @@ user = new tsUsers ($this->db); // TODO: I think it would be better to handle the GET params inside the // methods that handle the display. - $postId = tsController::getRequest('p'); - $search = tsController::getRequest('search'); + $postId = tsPage::getRequest('p'); + $search = tsPage::getRequest('search'); $p = new tdoPosts ($this->db); @@ -35,7 +35,7 @@ class index extends tsControllerHtml { $posts[0]['post_body'] = 'There are no posts currently'; } - $this->varArray['contact'] = tsController::setRequest('contact'); + $this->varArray['contact'] = tsPage::setRequest('contact'); // unset ($p); $this->display($posts); } @@ -43,13 +43,13 @@ class index extends tsControllerHtml { private function buildSidebar ($posts) { $actions = array (); if ($this->user->isLogged () ) { - $action['url'] = '/adm'.tsController::setRequest('index'); + $action['url'] = '/adm'.tsPage::setRequest('index'); $action['label'] = 'Admin'; $actions[] = $action; - $red = urlencode(tsController::setRequest(get_class ($this))); + $red = urlencode(tsPage::setRequest(get_class ($this))); - $action['url'] = '/adm'. tsController::setRequest ('login', array('do'=>'logout')); + $action['url'] = '/adm'. tsPage::setRequest ('login', array('do'=>'logout')); $action['label'] = 'Logout'; $actions[] = $action; } @@ -79,9 +79,9 @@ class index extends tsControllerHtml { // admin edit and stuff foreach ($posts as $key => $post) { if ($this->user->isLogged ()) { - $posts[$key]['eaction'] = '/adm' . tsController::setRequest('index', array('do' => 'post', 'i' => $post['post_id'])); + $posts[$key]['eaction'] = '/adm' . tsPage::setRequest('index', array('do' => 'post', 'i' => $post['post_id'])); } - $posts[$key]['addaction'] = tsController::setRequest (get_class ($this), array ('p' => $post['post_id'], '#reply')); + $posts[$key]['addaction'] = tsPage::setRequest (get_class ($this), array ('p' => $post['post_id'], '#reply')); } if (sizeof ($posts) > 1) { @@ -100,17 +100,17 @@ class index extends tsControllerHtml { $this->buildSidebar($posts); $this->varArray['title'] = $o->option_value; - $this->varArray['main'] = tsController::setRequest (get_class($this)); - $this->varArray['contact'] = tsController::setRequest ('contact'); - $this->varArray['search'] = tsController::setRequest (get_class($this), array ('do'=>'search')); + $this->varArray['main'] = tsPage::setRequest (get_class($this)); + $this->varArray['contact'] = tsPage::setRequest ('contact'); + $this->varArray['search'] = tsPage::setRequest (get_class($this), array ('do'=>'search')); } private function postComment () { - $parent = tsController::getRequest('p'); - $name = tsController::getRequest('n'); - $mail = tsController::getRequest('m'); - $name = tsController::getRequest('e'); - $post = tsController::getRequest('x'); + $parent = tsPage::getRequest('p'); + $name = tsPage::getRequest('n'); + $mail = tsPage::getRequest('m'); + $name = tsPage::getRequest('e'); + $post = tsPage::getRequest('x'); $user = new tdoUsers($this->db); $user->user_name = $name; @@ -126,7 +126,7 @@ class index extends tsControllerHtml { $comment->insert(); - tsController::redirect(tsController::setRequest(get_class ($this), array ('p' => $parent))); + tsPage::redirect(tsPage::setRequest(get_class ($this), array ('p' => $parent))); } // private function display ( $postId ) { @@ -134,8 +134,8 @@ class index extends tsControllerHtml { // } // private function edit () { -// $i = tsController::getRequest ('i'); -// //tsController::redirect(str_replace(array( URL.'/'),array( URL.'/adm/'), tsController::setRequest('index', array('do' => 'post', 'i' => $i)))); +// $i = tsPage::getRequest ('i'); +// //tsPage::redirect(str_replace(array( URL.'/'),array( URL.'/adm/'), tsPage::setRequest('index', array('do' => 'post', 'i' => $i)))); // } } diff --git a/_pages/test/code.php b/_pages/test/code.php index a80abc0..681572e 100644 --- a/_pages/test/code.php +++ b/_pages/test/code.php @@ -1,15 +1,15 @@ 'aremere')); + $tst = tsPage::setRequest(get_class($this), array('ana' => 'aremere')); var_dump($tst); - var_dump(tsController::getRequest('ana')); + var_dump(tsPage::getRequest('ana')); - $this->varArray['contact'] = tsController::setRequest('contact'); + $this->varArray['contact'] = tsPage::setRequest('contact'); } } diff --git a/_res/_libs/ctrlfactory.class.php b/_res/_libs/ctrlfactory.class.php deleted file mode 100644 index c17dcac..0000000 --- a/_res/_libs/ctrlfactory.class.php +++ /dev/null @@ -1,35 +0,0 @@ -link instanceof mysqli)) { + if (!is_a($this->link,'mysqli')) { return false; } if (!empty($query)) { diff --git a/_res/_libs/output.class.php b/_res/_libs/output.class.php new file mode 100644 index 0000000..2900549 --- /dev/null +++ b/_res/_libs/output.class.php @@ -0,0 +1,79 @@ + 0,'end' => 0); + + static private $instance = false; + + static protected function memcacheEnabled () { + /// this sucks on so many ways + if (extension_loaded ('memcache') && C_USE_MEMCACHE == true) { + $memcache = new Memcache; + if (@$memcache->connect('localhost', 11211)) { + memcache_debug (true); + return $memcache; + } + } + return false; + } + + public function store () { + + } + + /** + * static method to return the Output singleton instance + * + * @param string $to + * @return Output + */ + static function getInstance ($to) { + // we have already initialized the page singleton + if (Output::$instance instanceof Output) { + return Output::$instance; + } else { + // the memcache object should also be a singleton + // with a static instance I can call wherever. + $memcache = Output::memcacheEnabled (); + if ( $memcache) { + Output::$instance = $memcache->get ( Output::getHash ()); + } + + if (!(Output::$instance instanceof Output)) { + Output::$instance = new $to (); + } + } + return Output::$instance; + } + + static public function getHash () { + return md5($_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']); + } + + public function getTheme(){ + // this should most probably be changed to tsPage::getRequest ('theme') + if (!empty($_GET['theme']) && isDebug()) { + $this->theme = $_GET['theme']; + } elseif (!empty($_POST['theme'])) { + $this->theme = $_POST['theme']; + } elseif (!empty($_COOKIE['theme'])) { + $this->theme = $_COOKIE['theme']; + } + if (empty($this->theme) || + !is_dir(THEME_PATH.$this->theme) || + !is_dir(THEME_PATH.$this->theme.DIRECTORY_SEPARATOR."_css") || + !is_dir(THEME_PATH.$this->theme.DIRECTORY_SEPARATOR."_templates") + ) { + $this->theme = DEFAULT_THEME; + } + + return $this->theme; + } + + public function __construct(){} + + public function __destruct (){} + + abstract public function dispatch (); +} diff --git a/_res/_libs/tdoabstract.class.php b/_res/_libs/tdoabstract.class.php index a9fa5e8..6787dc3 100644 --- a/_res/_libs/tdoabstract.class.php +++ b/_res/_libs/tdoabstract.class.php @@ -604,10 +604,10 @@ class tdoAbstract { foreach ($valArray as $fieldName => $value) { if (array_key_exists ($fieldName, $this->fields)) { $this->fields[$fieldName]->set_value($value); - } elseif (!$strict) { + } elseif (!strinct) { // if the field name is not in the field list of the current object // it means that the valArray object is got from an JOIN sql - $this->fields[$fieldName] = new tdoAbstractField($value,'j1'); + $this->fields[$fieldName] = new tdoAbstractField($field,'j1'); $this->fields[$fieldName]->set_value ($value); } } @@ -926,7 +926,7 @@ class tdoAbstractJoin { foreach ($this->rightTable->wheres as $where) { $this->leftTable->addWhere ($where); } - $this->leftTable->wheres = array_merge($this->rightTable->wheres, $this->leftTable->wheres); + $this->leftTable->wheres = &array_merge($this->rightTable->wheres, $this->leftTable->wheres); } public function set_state ($st) { diff --git a/_res/_libs/tscontroller.class.php b/_res/_libs/tscontroller.class.php deleted file mode 100644 index 62886bf..0000000 --- a/_res/_libs/tscontroller.class.php +++ /dev/null @@ -1,116 +0,0 @@ - 0,'end' => 0); - - static private $instance = false; - - static protected function memcacheEnabled () { - /// this sucks on so many ways - if (extension_loaded ('memcache') && C_USE_MEMCACHE == true) { - $memcache = new Memcache; - if (@$memcache->connect('localhost', 11211)) { - memcache_debug (true); - return $memcache; - } - } - return false; - } - -/** - * function to redirect the client - * - * @param string $url - * @param bool $die - * @param bool $onlyJScript - */ - static public function redirect($url, $die = true, $onlyJScript = false) { - if ($onlyJScript == true || headers_sent()) { - printf ('Redirect

REDIRECTING - PLEASE CLICK HERE !

', $url, $url, $url); - } else { - ob_end_clean(); - header ('Location: '.str_replace ('&', '&', $url)); - } - - if ($die) - die(); - } - - // FIXME: I should stop using REQUEST for getting get and post variables !!! - static public function getRequest($varName = null) { - return tsUrl::getRequest($varName); - } - - /** - * function to generate URLs compatible with tsController - * - * @param string $whereTo the page name - * @param string $varVal additional params - * @param string $method [get|TODO post] - * @return string - */ - - static public function setRequest ($whereTo = null, $varVal = null){ - return tsUrl::setRequest ($whereTo, $varVal); - } - - public function store () { - - } - - /** - * static method to return the tsController singleton instance - * - * @param string $to - * @return tsController - */ - static function getInstance ($to) { - // we have already initialized the page singleton - if (tsController::$instance instanceof tsController) { - return tsController::$instance; - } else { - // the memcache object should also be a singleton - // with a static instance I can call wherever. - $memcache = tsController::memcacheEnabled (); - if ( $memcache) { - tsController::$instance = $memcache->get ( tsController::getHash ()); - } - - if (!(tsController::$instance instanceof tsController)) { - tsController::$instance = new $to (); - } - } - return tsController::$instance; - } - - static public function getHash () { - return md5($_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']); - } - - public function getTheme(){ - // this should most probably be changed to tsController::getRequest ('theme') - if (!empty($_GET['theme']) && isDebug()) { - $this->theme = $_GET['theme']; - } elseif (!empty($_POST['theme'])) { - $this->theme = $_POST['theme']; - } elseif (!empty($_COOKIE['theme'])) { - $this->theme = $_COOKIE['theme']; - } - if (empty($this->theme) || - !is_dir(THEME_PATH.$this->theme) || - !is_dir(THEME_PATH.$this->theme.DIRECTORY_SEPARATOR."_css") || - !is_dir(THEME_PATH.$this->theme.DIRECTORY_SEPARATOR."_templates") - ) { - $this->theme = DEFAULT_THEME; - } - - return $this->theme; - } - - public function __construct(){} - - public function __destruct (){} - - abstract public function dispatch (); -} diff --git a/_res/_libs/tscontrollercss.class.php b/_res/_libs/tscontrollercss.class.php deleted file mode 100644 index d85bc7e..0000000 --- a/_res/_libs/tscontrollercss.class.php +++ /dev/null @@ -1,48 +0,0 @@ -theme = (!empty($_COOKIE['theme']) ? $_COOKIE['theme'] : DEFAULT_THEME); - if (!empty($_GET)) { - list($this->media) = array_keys($_GET); - } else { - $this->media = 'screen'; - } - - - if (!is_file(THEME_PATH. $tthis->heme . DIRECTORY_SEPARATOR .'_css'. DIRECTORY_SEPARATOR .$this->media.'.css')) { - $this->theme = DEFAULT_THEME; - $this->media = 'screen'; - } - - } - - public function dispatch (){ - $out = file_get_contents ( THEME_PATH. $this->theme . DIRECTORY_SEPARATOR .'_css'. DIRECTORY_SEPARATOR .$this->media.'.css'); - $this->postDispatch ( $out ); - } - - - private function postDispatch ($incString){ - if (stristr ($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { - $incString = str_replace(array('min-width:', 'max-width:'), 'width:', $incString); - } - echo $incString; - } -} diff --git a/_res/_libs/tscontrollerrss.class.php b/_res/_libs/tscontrollerrss.class.php deleted file mode 100644 index ac1ac3d..0000000 --- a/_res/_libs/tscontrollerrss.class.php +++ /dev/null @@ -1,81 +0,0 @@ -setTheme(); - - session_start(); - - $this->connectDb(); - - $date = 0; - $category = 0; - - $o = new tdoOptions ($this->db); - $o->option_name = 'title'; - $o->findFirst (); - - $user = new tsUsers ($this->db); - - $p = new tdoPosts ($this->db); - - $posts = $p->getAllPosts (($user->isLogged () ? $user->uid : null)); - - $this->varArray['url'] = URL . tsController::setRequest (); - - foreach ($posts as $key => $post) { - $post['post_url'] = URL.tsController::setRequest (null, array ('p' => $post['post_id'])); -// $post['post_body'] = preg_replace ('/\s/', ' ', $post['post_body']); - $post['post_time'] = date ('r', strtotime ($post['post_time'])); - $post['permalink'] = md5 ($post['post_time']); - - $posts[$key] = $post; - } - $this->varArray['posts'] = $posts; - ob_end_clean(); - } - - public function dispatch (){ - $this->db->close(); - $this->setTheme(); - - $this->smarty = new Smarty(); - - $this->smarty->compile_check = true; -// $this->smarty->debugging = C_SYSTEM_DEBUG; - $this->smarty->compile_dir = RES_PATH . S_C_TEMPL_DIR; - - if (is_array($this->varArray)) { - $this->smarty->assign ($this->varArray); - } - $this->content = $this->smarty->fetch ($this->themePath . DIRECTORY_SEPARATOR . S_TEMPL_DIR . 'rss.tpl'); - - $this->postDispatch ($this->content); - } - - protected function postDispatch ($incString) { - header ('Content-Type:application/rss+xml'); -// header ('Content-Type:text/plain'); - echo str_replace( - array ('%TIME%','%QUERIES%', '%MEMUSED%'), - array ( - number_format(microtime (true) - $GLOBALS['st'] , 5, ',', '.'), - $GLOBALS['qCnt'], - number_format(memory_get_usage()/1024, 3, ',', '.') - ), - $incString - ); - } -} diff --git a/_res/_libs/tsimage2.class.php b/_res/_libs/tsimage2.class.php index 78ba47a..722c848 100644 --- a/_res/_libs/tsimage2.class.php +++ b/_res/_libs/tsimage2.class.php @@ -1,6 +1,6 @@ 'gif', 2 => 'jpg', 3 => 'png'); public $path; private $content, diff --git a/_res/_libs/tscontrollerhtml.class.php b/_res/_libs/tspage.class.php similarity index 74% rename from _res/_libs/tscontrollerhtml.class.php rename to _res/_libs/tspage.class.php index 7b24134..e0ecf09 100644 --- a/_res/_libs/tscontrollerhtml.class.php +++ b/_res/_libs/tspage.class.php @@ -1,6 +1,6 @@ output = $this->setOutput(); // Override standard string functions @@ -35,9 +35,10 @@ class tsControllerHtml extends tsController { ini_set('mbstring.func_overload', 7); } -// set_error_handler(array($this, 'triggerError')); +// set_error_handler(array(&$this, 'triggerError')); // commented in the light of the xdebug profiling - -// dropped loading times by .01 seconds +// dropped loading times by almost one order of magnitude +// maybe it was just my imagination if (!empty($prevOutput)) { $this->errors = "\n".''."\n".$prevOutput."\n"; } else { @@ -48,16 +49,17 @@ class tsControllerHtml extends tsController { $this->setTheme(); session_start(); + $this->connectDb(); } // function __destruct(){ -// $this->db->close(); +//// $this->db->close(); // } - protected function connectDb () { - $this->db = sqlFactory::connect (DB_TYPE); - + private function connectDb () { + $this->db = sqlFactory::connect(DB_TYPE); + if (defined ('DB_NAME') && DB_NAME && !empty($this->db->link)) { $this->db->selectDatabase(DB_NAME); return true; @@ -66,6 +68,42 @@ class tsControllerHtml extends tsController { return false; } + /** + * function to redirect the client + * + * @param string $url + * @param bool $die + * @param bool $onlyJScript + */ + static public function redirect($url, $die = true, $onlyJScript = false) { + if ($onlyJScript == true || headers_sent()) { + printf ('Redirect

REDIRECTING - PLEASE CLICK HERE !

', $url, $url, $url); + } else { + ob_end_clean(); + header ('Location: '.str_replace ('&', '&', $url)); + } + + if ($die) + die(); + } + + // FIXME: I should stop using REQUEST for getting get and post variables !!! + public function getRequest($varName = null) { + return tsUrl::getRequest($varName); + } + + /** + * function to generate URLs compatible with tsPage + * + * @param string $whereTo the page name + * @param string $varVal additional params + * @param string $method [get|TODO post] + * @return string + */ + public function setRequest ($whereTo = null, $varVal = null){ + return tsUrl::setRequest ($whereTo, $varVal); + } + public function setTheme (){ $this->getTheme(); @@ -151,7 +189,7 @@ class tsControllerHtml extends tsController { $this->errors .= ''; $this->errors .= ''.$errType.' '.$errStr; - if (false || tsController::getRequest('bt') == 'full') { + if (false || tsPage::getRequest('bt') == 'full') { $this->errors .= ' at line '.$errLine.' in file '.$errFile; // $t = debug_backtrace(); // $this->errors .= '
'.var_export($t,true).'
'; @@ -162,11 +200,18 @@ class tsControllerHtml extends tsController { return; } +// private function setOutput (){ +// $userAgent = $_SERVER['HTTP_USER_AGENT']; +// //return 'wml'; +// } + public function dispatch (){ $this->db->close(); $this->setTheme(); - $this->smarty = new Smarty(); + $this->smarty = &new Smarty(); + + $this->smarty = &new Smarty(); $this->smarty->compile_check = true; // $this->smarty->debugging = C_SYSTEM_DEBUG; @@ -187,6 +232,13 @@ class tsControllerHtml extends tsController { $this->smarty->assign('contentFile', $this->themePath . DIRECTORY_SEPARATOR . S_TEMPL_DIR . 'tpl404.tpl'); } + /* Execution of any _exec method we have in the derived classes + --------------------------------------------------------------------- */ + foreach ($methArr as $method){ + if (stristr($method, '_exec')){ + $this->$method(); + } + } /* Loading of any varArray template variables we have in the derived classes --------------------------------------------------------------------- */ if (is_array($this->varArray)) { @@ -209,10 +261,10 @@ class tsControllerHtml extends tsController { // $this->smarty->assign ('time', true); $this->content = $this->smarty->fetch ($this->themePath . DIRECTORY_SEPARATOR . S_TEMPL_DIR . 'main.tpl'); - $memcache = tsController::memcacheEnabled (); + $memcache = Output::memcacheEnabled (); if ($memcache instanceof Memcache) { $memcache->connect('localhost', 11211); - $memcache->add (tsController::getHash () , $this, MEMCACHE_COMPRESSED); + $memcache->add (Output::getHash () , $this, MEMCACHE_COMPRESSED); } $this->postDispatch ($this->content); @@ -229,6 +281,7 @@ class tsControllerHtml extends tsController { header('Content-type: text/html'); } + echo str_replace( array ('%TIME%','%QUERIES%', '%MEMUSED%'), array ( diff --git a/_res/_libs/tsurl.class.php b/_res/_libs/tsurl.class.php index d9730d3..1feeedf 100644 --- a/_res/_libs/tsurl.class.php +++ b/_res/_libs/tsurl.class.php @@ -44,6 +44,14 @@ class tsUrl { } } +// public function getInstance () { +// if (tsUrl::$instance instanceof tsUrl) { +// tsUrl::$instance = new tsUrl (); +// } +// +// return tsUrl::$instance; +// } + public function __destruct () { } @@ -86,10 +94,10 @@ class tsUrl { $sizeof = 1; list($urlStr) = array_keys ($_GET); $parArr = explode ('/', $urlStr); // fixme: $separator needed - + $retArr[NAV_VAR] = tsUrl::getValue ($parArr[0], NAV_VAR); $retArr[ACT_VAR] = tsUrl::getValue ($parArr[1], ACT_VAR); - +// var_dump($retArr);die; // we have a 'do' action if ($retArr[ACT_VAR]) $sizeof = 2; @@ -103,6 +111,7 @@ class tsUrl { $retArr[$key] = $val; } } + return $retArr; } @@ -150,9 +159,9 @@ class tsUrl { if (!$varName) { return $params; - } elseif (!empty ($_REQUEST[$varName])) { - return $_REQUEST[$varName]; - } elseif (!empty ($params[$varName])) { + } else { + if (!empty ($_REQUEST[$varName])) + return $_REQUEST[$varName]; return $params[$varName]; } } @@ -166,11 +175,59 @@ class tsUrl { static public function setRequest ($whereTo = null, $varVal = null) { // var_dump($varVal); // generating friendly URLs - if (is_null($varVal) && !is_array ($varVal)) { - $varVal[] = (int)$varVal; + if (!is_array ($varVall)) { + $varVal[] = $varVall; } - - $paramArr = array_merge (array ('to' => $whereTo) , $varVal); + $paramArr = array_merge (array ('to'=>$whereTo) , $varVal); return URL . tsUrl::composeUrl ($paramArr); +// if (defined('METHOD') && METHOD == FRIENDLY) { +// if (!empty($whereTo)) +// $whereTo = $whereTo . '/'; +// +// if (is_array($varVal)) { +// foreach ($varVal as $key => $val){ +// if (is_numeric($key) && stristr ($val, '#')) { +// // probably an href with id in it +// $end = $val; +// } else { +// $retUrl .= $key . (!empty($val) ? ':' . $val . '/' : ''); +// } +// } +// } +// +// $outStr = URL; +// +// $outStr .= '/' . $whereTo . $retUrl; +// +// return $outStr; +// +// } else { +// if (!empty($whereTo)) +// $whereTo = NAV_VAR . '=' . $whereTo; +// +// if (is_array($varVal)) { +// foreach ($varVal as $key => $val){ +// if (is_numeric($key) && stristr ($val, '#')) { +// // probably an href with id in it +// $end = $val; +// } else { +// $tArr[] = $key.(!empty($val) ? '='.$val : ''); +// } +// } +// $retUrl = implode ('&', $tArr).$end; +// } elseif (is_string($varVal)){ +// $retUrl = $varVal; +// } +// +// $outStr = URL; +// +// if ($method == 'get'){ +// if (!empty ($whereTo) && !empty ($retUrl) ) +// $whereTo .= '&'; +// $outStr .= '/?' . $whereTo . $retUrl; +// } +// +// return $outStr; +// } } } diff --git a/_res/_themes/default/_templates/rss.tpl b/_res/_themes/default/_templates/rss.tpl deleted file mode 100644 index 51a1410..0000000 --- a/_res/_themes/default/_templates/rss.tpl +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {$o->option_value} - {$url} - The [very] basic code put at work - en-us - {$posts.0.post_time|date_format:"%a, %d %b %Y %T %Z"} - http://blogs.law.harvard.edu/tech/rss -{foreach from=$posts item=post} - - {$post.post_title|strip_tags} - {$post.post_url} - {$post.user_email} ({$post.user_name|lower}) - - {$post.post_time|date_format:"%a, %d %b %Y %T %Z"} - {$post.permalink} - -{/foreach} - - \ No newline at end of file diff --git a/_res/loader.php b/_res/loader.php index a372d06..d02ff0b 100644 --- a/_res/loader.php +++ b/_res/loader.php @@ -1,5 +1,19 @@ dispatch (); diff --git a/adm/_pages/index/code.php b/adm/_pages/index/code.php index 82a40cb..ebe00d4 100644 --- a/adm/_pages/index/code.php +++ b/adm/_pages/index/code.php @@ -1,10 +1,10 @@ db); $o->option_name = 'title'; $o->findFirst(); @@ -15,7 +15,7 @@ class index extends tsControllerHtmlAdmin { $this->varArray['tit'] = $o->option_value; $this->varArray['title'] = ' ['.$this->user->user_name.' @ '.$this->varArray['tit'].']'; - $action = tsController::getRequest('do'); + $action = tsPage::getRequest('do'); // avoid making useless queries if $action = edit || delete if (empty($action)) { @@ -37,8 +37,8 @@ class index extends tsControllerHtmlAdmin { $ps = $pt->getArray(); foreach ($ps as $post){ - $post['eaction'] = tsController::setRequest(get_class($this), array('do' => 'post', 'i' => $post['post_id'])); - $post['daction'] = tsController::setRequest(get_class($this), array('do' => 'delete', 'i' => $post['post_id'])); + $post['eaction'] = tsPage::setRequest(get_class($this), array('do' => 'post', 'i' => $post['post_id'])); + $post['daction'] = tsPage::setRequest(get_class($this), array('do' => 'delete', 'i' => $post['post_id'])); $post['post_title'] = stripslashes(strip_tags($post['post_title'])); $post['post_body'] = stripslashes(strip_tags($post['post_body'])); @@ -48,7 +48,7 @@ class index extends tsControllerHtmlAdmin { if (empty($posts)) { $posts[0]['post_title'] = '« empty »'; $posts[0]['post_body'] = 'There are no posts currently'; - $posts[0]['eaction'] = tsController::setRequest(get_class($this), array('do'=>'post')); + $posts[0]['eaction'] = tsPage::setRequest(get_class($this), array('do'=>'post')); } $this->varArray['posts'] = $posts; @@ -65,7 +65,7 @@ class index extends tsControllerHtmlAdmin { foreach ($menuKeys as $key) { if (stristr ($key, 'menu')){ $key = strtolower (preg_replace('/menu/','', $key)); - $this->menu[$key] = tsController::setRequest (get_class($this), array('do' => $key)); + $this->menu[$key] = tsPage::setRequest (get_class($this), array('do' => $key)); } } } @@ -75,7 +75,7 @@ class index extends tsControllerHtmlAdmin { } public function delete () { - $id = tsController::getRequest('i'); + $id = tsPage::getRequest('i'); $post = new tdoPosts($this->db); // $post->post_id = $id; @@ -84,11 +84,11 @@ class index extends tsControllerHtmlAdmin { $post->update($id); - tsController::redirect( tsController::setRequest(get_class($this)) ); + tsPage::redirect( tsPage::setRequest(get_class($this)) ); } public function edit () { - $postId = tsController::getRequest('i'); + $postId = tsPage::getRequest('i'); $post = new tdoPosts ($this->db); $cp = new tdoCategoriesPosts ($this->db); @@ -98,11 +98,11 @@ class index extends tsControllerHtmlAdmin { $post->buildObj (); } - $title = tsController::getRequest('t'); + $title = tsPage::getRequest('t'); $post->clean ($title, false); $post->post_title = $title; // post title - $body = tsController::getRequest('x'); + $body = tsPage::getRequest('x'); // this is just for fun, so I can display these values in the posts, // but not have them converted at edit time $body = str_replace (array('$TIME$', '$QUERIES$', '$MEMUSED$'), @@ -113,7 +113,7 @@ class index extends tsControllerHtmlAdmin { $post->post_body = $body; // post body - $modTime = tsController::getRequest('d'); + $modTime = tsPage::getRequest('d'); if (!empty($modTime)) { $post->post_time = date("Y-m-d G:i:s"); @@ -121,10 +121,10 @@ class index extends tsControllerHtmlAdmin { $post->post_author = $this->user->uid; - $post->post_private = (tsController::getRequest('p') ? 'Y' : 'N'); + $post->post_private = (tsPage::getRequest('p') ? 'Y' : 'N'); // getting the category id based on name - $incCat = tsController::getRequest ('c'); + $incCat = tsPage::getRequest ('c'); if (!empty($body) && !empty($title)) { $id = $post->replace ($postId); @@ -145,14 +145,14 @@ class index extends tsControllerHtmlAdmin { } } - tsController::redirect( tsController::setRequest(get_class($this), array('do'=> 'post', 'i' => (int)$id)) ); + tsPage::redirect( tsPage::setRequest(get_class($this), array('do'=> 'post', 'i' => (int)$id)) ); } public function post () { - $postId = tsController::getRequest('i'); + $postId = tsPage::getRequest('i'); // $this->initiateDisplay(); - $this->varArray['action'] = tsController::setRequest (get_class($this), array ('do'=> 'edit')); + $this->varArray['action'] = tsPage::setRequest (get_class($this), array ('do'=> 'edit')); $this->varArray['mainFile'] = dirname (__FILE__).'/pages/edit.tpl'; $c = new tdoCategories ($this->db); @@ -196,25 +196,25 @@ class index extends tsControllerHtmlAdmin { $this->varArray['categories'] = $cat; $this->varArray['now'] = date('Y-m-d G:i:s'); - $this->varArray['upload_url'] = tsController::setRequest ('upload', array('i' => $postId)); + $this->varArray['upload_url'] = tsPage::setRequest ('upload', array('i' => $postId)); } public function catedit () { $c = new tdoCategories ($this->db); // id - $i = tsController::getRequest('i'); + $i = tsPage::getRequest('i'); // delete - if (tsController::getRequest('delete') == 'yes'){ + if (tsPage::getRequest('delete') == 'yes'){ $c->category_active = 'N'; } // name - $n = tsController::getRequest('n'); + $n = tsPage::getRequest('n'); // description - $d = tsController::getRequest('d'); + $d = tsPage::getRequest('d'); // private - $p = tsController::getRequest('p'); + $p = tsPage::getRequest('p'); $c->category_name = $n; $c->category_description = $d; @@ -222,18 +222,18 @@ class index extends tsControllerHtmlAdmin { $c->replace ($i); - tsController::redirect ( tsController::setRequest(get_class($this), array('do' => 'categories'))); + tsPage::redirect ( tsPage::setRequest(get_class($this), array('do' => 'categories'))); } public function menuCategories () { -// tsController::redirect( tsController::setRequest(get_class($this)) ); +// tsPage::redirect( tsPage::setRequest(get_class($this)) ); $c = new tdoCategories($this->db); $c->category_active = 'Y'; $cs = $c->getArray(); $this->varArray['categories'] = $cs; - $this->varArray['action'] = tsController::setRequest(get_class($this), array('do'=>'catedit')); + $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'catedit')); $this->varArray['mainFile'] = dirname(__FILE__) . '/pages/categories.tpl'; } @@ -241,16 +241,16 @@ class index extends tsControllerHtmlAdmin { public function optedit () { $o = new tdoOptions($this->db); // id - $i = tsController::getRequest('i'); + $i = tsPage::getRequest('i'); // delete - if (tsController::getRequest('delete') == 'yes'){ + if (tsPage::getRequest('delete') == 'yes'){ $rows = $o->delete ($i); } else { // value - $v = tsController::getRequest ('v'); - $a = tsController::getRequest ('a') == 'Y' ? 'Y' : 'N'; - $n = tsController::getRequest ('n'); + $v = tsPage::getRequest ('v'); + $a = tsPage::getRequest ('a') == 'Y' ? 'Y' : 'N'; + $n = tsPage::getRequest ('n'); if (!empty($n)) { $o->option_name = $n; @@ -261,7 +261,7 @@ class index extends tsControllerHtmlAdmin { $o->replace ($i); } - tsController::redirect( tsController::setRequest (get_class($this), array('do'=>'options' ))); + tsPage::redirect( tsPage::setRequest (get_class($this), array('do'=>'options' ))); } public function menuOptions () { @@ -269,15 +269,15 @@ class index extends tsControllerHtmlAdmin { $os = $o->getArray(); $this->varArray['options'] = $os; - $this->varArray['action'] = tsController::setRequest(get_class($this), array('do'=>'optedit')); + $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'optedit')); $this->varArray['mainFile'] = dirname(__FILE__).'/pages/options.tpl'; } public function menuMain () { - tsController::redirect( tsController::setRequest(get_class($this) )); + tsPage::redirect( tsPage::setRequest(get_class($this) )); } public function menuLogout () { - tsController::redirect( tsController::setRequest('login', array('do'=>'logout')) ); + tsPage::redirect( tsPage::setRequest('login', array('do'=>'logout')) ); } } diff --git a/adm/_pages/login/code.php b/adm/_pages/login/code.php index ee9ef7c..244929d 100644 --- a/adm/_pages/login/code.php +++ b/adm/_pages/login/code.php @@ -1,5 +1,5 @@ varArray['title'] = 'adm'; - $action = tsController::getRequest ('do'); + $action = tsPage::getRequest ('do'); if (empty($action)) { $action = 'display'; // if ($this->user->isLogged()) -// tsController::redirect( tsController::setRequest('index') ); +// tsPage::redirect( tsPage::setRequest('index') ); } $this->$action (); } function display (){ - $this->varArray['action'] = tsController::setRequest(get_class ($this), array('do' => 'login')); + $this->varArray['action'] = tsPage::setRequest(get_class ($this), array('do' => 'login')); } function login () { - $userName = tsController::getRequest('n'); - $pass = tsController::getRequest('p'); + $userName = tsPage::getRequest('n'); + $pass = tsPage::getRequest('p'); if (!$this->user->isLogged() && !empty($userName) && !empty ($pass)) { $this->user->logIn ($userName,$pass); } // var_dump($_SESSION); - tsController::redirect ( tsController::setRequest ('index') ); + tsPage::redirect ( tsPage::setRequest ('index') ); // die(); } function logout () { $this->user->logOut (); // FIXME : this doesn't work - $red = urldecode (tsController::getRequest('r')); + $red = urldecode (tsPage::getRequest('r')); if (empty($red)) - $red = tsController::setRequest (get_class ($this)); - tsController::redirect ( $red ); + $red = tsPage::setRequest (get_class ($this)); + tsPage::redirect ( $red ); } } diff --git a/adm/_pages/upload/code.php b/adm/_pages/upload/code.php index d5d6bf4..a2d5be1 100644 --- a/adm/_pages/upload/code.php +++ b/adm/_pages/upload/code.php @@ -14,13 +14,13 @@ case 4: break; } */ -class upload extends tsControllerHtmlAdmin { +class upload extends tsAdminPage { public function __construct(){ parent::__construct(); $this->varArray['title'] = 'adm'; - $action = tsController::getRequest ('do'); + $action = tsPage::getRequest ('do'); if (empty ($action)) { $action = 'display'; @@ -46,7 +46,7 @@ class upload extends tsControllerHtmlAdmin { $this->varArray['pics'] = $out; $this->varArray['URL'] = BASE_URL; - $this->varArray['action'] = tsController::setRequest(get_class($this), array('do'=>'upload')); + $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'upload')); } private function upload () { @@ -59,6 +59,6 @@ class upload extends tsControllerHtmlAdmin { $t = move_uploaded_file ($_FILES['f']['tmp_name'] , $upload); var_dump($_FILES,$t); } -// tsController::redirect(tsController::setRequest(get_class($this))); +// tsPage::redirect(tsPage::setRequest(get_class($this))); } } diff --git a/adm/_res/_libs/tscontrollerhtmladmin.class.php b/adm/_res/_libs/tsadminpage.class.php similarity index 54% rename from adm/_res/_libs/tscontrollerhtmladmin.class.php rename to adm/_res/_libs/tsadminpage.class.php index b318e7a..9aa36e3 100644 --- a/adm/_res/_libs/tscontrollerhtmladmin.class.php +++ b/adm/_res/_libs/tsadminpage.class.php @@ -1,10 +1,10 @@ user = new tsUsers ($this->db); if (!$this->user->isLogged ()) - tsController::redirect(str_replace('&','&',tsController::setRequest ('login'))); + tsPage::redirect(str_replace('&','&',tsPage::setRequest ('login'))); } } diff --git a/adm/_res/_libs/tsfile.class.php b/adm/_res/_libs/tsfile.class.php index a5cfd4e..171108a 100644 --- a/adm/_res/_libs/tsfile.class.php +++ b/adm/_res/_libs/tsfile.class.php @@ -1,6 +1,6 @@ type); $fType = 'unknown'; // what TODO: about friendly URLs? - $fakeUrl = tsController::setRequest ('image', array('id'=>$fType)); + $fakeUrl = tsPage::setRequest ('image', array('id'=>$fType)); return BASE_URL.'/img2.php?id=' . $fType; } } diff --git a/adm/_res/loader.php b/adm/_res/loader.php index a372d06..c2833df 100644 --- a/adm/_res/loader.php +++ b/adm/_res/loader.php @@ -1,5 +1,16 @@ -dispatch (); diff --git a/image.php b/image.php index 136d1a6..2e46d15 100644 --- a/image.php +++ b/image.php @@ -8,7 +8,7 @@ ob_start(); require ('config.inc.php'); require (LIB_PATH.'functions.inc.php'); -$id = tsController::getRequest('id'); +$id = tsPage::getRequest('id'); ob_end_clean(); $a = new tsImage ($id); diff --git a/img2.php b/img2.php index 2a1cf69..12a9677 100644 --- a/img2.php +++ b/img2.php @@ -10,9 +10,9 @@ require ('config.inc.php'); require (LIB_PATH.'functions.inc.php'); $imgDir = 'pics'; -$id = tsController::getRequest ('id'); -$resizeW = tsController::getRequest ('w'); -$resizeH = tsController::getRequest ('h'); +$id = tsPage::getRequest ('id'); +$resizeW = tsPage::getRequest ('w'); +$resizeH = tsPage::getRequest ('h'); $a = new tsImage2 ( tsImage2::getPath ($id) ); $a->testPath (tsImage2::getPath ($id)); diff --git a/rss.php b/rss.php dissimilarity index 77% index 9425109..71e5ab0 100644 --- a/rss.php +++ b/rss.php @@ -1,10 +1,66 @@ -dispatch(); +selectDatabase (DB_NAME); + +$o = new tdoOptions ($db); +$o->option_name = 'title'; +$o->findFirst (); + +$user = new tsUsers ($db); + +$p = new tdoPosts ($db); + +$posts = $p->getAllPosts (($user->isLogged () ? $user->uid : null)); +$lastBuildDate = date ('r', strtotime ($posts[0]['post_time'])); + +$url = tsPage::setRequest (); +ob_end_clean (); +ob_start (); +echo <<<__ST + + + + + {$o->option_value} + {$url} + The [very] basic code put at work + en-us + {$lastBuildDate} + http://blogs.law.harvard.edu/tech/rss + +__ST; +foreach ($posts as $post) { +?> + + <?php echo strip_tags ($post['post_title']) ?> + $post['post_id'])) ?> + () + ]]> + + + + + + +dispatch(); +header('Content-type: text/css'); +$theme = (!empty($_COOKIE['theme']) ? $_COOKIE['theme'] : DEFAULT_THEME); +if (!empty($_GET)) { + list($media) = array_keys($_GET); +} else { + $media = 'screen'; +} + +if (!is_file(THEME_PATH. $theme . DIRECTORY_SEPARATOR .'_css'. DIRECTORY_SEPARATOR .$media.'.css')) { + $theme = DEFAULT_THEME; + $media = 'screen'; +} + +$out = file_get_contents ( THEME_PATH. $theme . DIRECTORY_SEPARATOR .'_css'. DIRECTORY_SEPARATOR .$media.'.css'); +ob_end_clean(); +if (stristr ($_SERVER['HTTP_USER_AGENT'], 'MSIE')) + $out = str_replace(array('min-width:', 'max-width:'), 'width:', $out); +echo $out; -- 2.11.4.GIT