aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Controllers/BaseController.php
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2010-10-17 13:29:57 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2010-10-17 13:29:57 +0000
commit232aa1924c8c0f10d87b210b46c9f061af5c844c (patch)
tree2351f2aaff7ad244f60358954e4711692fb8aadc /h-source/Application/Controllers/BaseController.php
parenta17e3e0495bee3705d3c1e5ead2db1a8359e64e9 (diff)
added files
Diffstat (limited to 'h-source/Application/Controllers/BaseController.php')
-rw-r--r--h-source/Application/Controllers/BaseController.php171
1 files changed, 171 insertions, 0 deletions
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 @@
+<?php
+
+// h-source, a web software to build a community of people that want to share their hardware information.
+// Copyright (C) 2010 Antonio Gallo (h-source-copyright.txt)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+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 = "<ul class='languages_link_box'>\n";
+ foreach (Lang::$complete as $abbr => $fullName)
+ {
+ $linkClass = (strcmp($abbr,$lang) === 0) ? "class='current_lang'" : null;
+ $status[0] = $abbr;
+ $href = Url::createUrl($status);
+ $fullNameArray = explode(',',$fullName);
+ $text = "<img src='".$this->baseUrl."/Public/Img/Famfamfam/".$fullNameArray[0]."'><span>".$fullNameArray[1]."</span>";
+ $link .= "\t<li><a $linkClass href='".$cPage.$href."'>$text</a></li>\n";
+ }
+ $link .= "</ul>\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