From 232aa1924c8c0f10d87b210b46c9f061af5c844c Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Sun, 17 Oct 2010 13:29:57 +0000 Subject: added files --- .../Application/Controllers/BaseController.php | 171 +++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 h-source/Application/Controllers/BaseController.php (limited to 'h-source/Application/Controllers/BaseController.php') diff --git a/h-source/Application/Controllers/BaseController.php b/h-source/Application/Controllers/BaseController.php new file mode 100644 index 0000000..b201165 --- /dev/null +++ b/h-source/Application/Controllers/BaseController.php @@ -0,0 +1,171 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +class BaseController extends Controller +{ + + protected $lang; + protected $ismoderator; + protected $querySanitized = true; + + protected $_topMenuClasses = array( + "home" => null, + "hardware" => null, + "credits" => null, + "issues" => null, + "contact" => null, + "search" => null, + "news" => null, + "download" => null, + "help" => null, + ); + + public function __construct($model, $controller, $queryString) { + parent::__construct($model, $controller, $queryString); + + header("Cache-Control: no-cache"); + + $this->model('BoxesModel'); + + $this->load('header'); + $this->load('footer','last'); + + $this->session('registered'); + $this->s['registered']->checkStatus(); + + $data['username'] = null; + $data['islogged'] = 'no'; + $data['token'] = 'token'; + $data['ismoderator'] = false; + $this->ismoderator = false; + + if ($this->s['registered']->status['status'] === 'logged') + { + $data['username'] = $this->s['registered']->status['user']; + $data['islogged'] = 'yes'; + $data['token'] = $this->s['registered']->status['token']; + $data['ismoderator'] = in_array('moderator',$this->s['registered']->status['groups']) ? true : false; + $this->ismoderator = $data['ismoderator']; + } + + $data['lang'] = 'en'; + $this->lang = 'en'; + + if (isset($this->_queryString[0])) + { + $lang = (strcmp($this->_queryString[0],'') !== 0) ? $this->_queryString[0] : 'en'; + $data['lang'] = Lang::sanitize($lang); + $this->lang = $data['lang']; + Lang::$current = $data['lang']; + } + + $data['tm'] = $this->_topMenuClasses; + +// print_r($this->_queryString); + $this->_queryString = $this->sanitizeQueryString($this->_queryString); + + $this->append($data); + + } + + protected function right($lang = 'en') + { + $hard = new HardwareModel(); + + $data['stat'] = $hard->clear()->select('type,count(*) AS numb')->where(array('-deleted'=>'no'))->groupBy('type')->toList('type','aggregate.numb')->send(); + + $logged = $this->s['registered']->getUsersLogged(); + + $data['numbLogged'] = count($logged); + + // get the right column container + $this->m['BoxesModel']->setWhereQueryClause(array('title'=>'right_bottom')); + $boxes = $this->m['BoxesModel']->getAll('boxes'); + + if (count($boxes) > 0) + { + $xml = htmlspecialchars_decode($boxes[0]['boxes']['message'],ENT_QUOTES); + + $box_news = new BoxParser($xml); + $data['htmlRightBox'] = $box_news->render(); + } + else + { + $data['htmlRightBox'] = null; + } + + $data['language_links'] = $this->buildLanguageLinks($this->lang); + +// print_r($this->_queryString); + + $this->append($data); + $this->load('right'); + } + + protected function sanitizeQueryString($queryArray) + { + $resArray = array(); + foreach ($queryArray as $item) + { + if (preg_match('/^[a-zA-Z0-9\-\_\.\+\s]+$/',$item)) + { + $resArray[] = sanitizeAll($item); + } + else + { + $this->querySanitized = false; + return array('en'); + } + } + return $resArray; + } + + protected function buildLanguageLinks($lang) + { + $status = $this->_queryString; + $cPage = $this->querySanitized ? $this->currPage : $this->baseUrl."/home/index"; + $link = "\n"; + return $link; + } + + protected function cleverLoad($file) + { + $fileInt = $file."_".$this->lang; + if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS . ucwords($this->controller) . DS . $fileInt . '.php')) + { + $this->load($fileInt); + } + else + { + $this->load($file); + } + } + +} \ No newline at end of file -- cgit v1.2.3