diff options
Diffstat (limited to 'h-source/Application/Controllers')
4 files changed, 511 insertions, 25 deletions
diff --git a/h-source/Application/Controllers/BaseController.php b/h-source/Application/Controllers/BaseController.php index 7d03735..0f7c532 100644 --- a/h-source/Application/Controllers/BaseController.php +++ b/h-source/Application/Controllers/BaseController.php @@ -27,7 +27,7 @@ class BaseController extends Controller protected $ismoderator = false; protected $querySanitized = true; protected $token = 'token'; - + protected $_topMenuClasses = array( "home" => null, "hardware" => null, @@ -82,9 +82,11 @@ class BaseController extends Controller $data['tm'] = $this->_topMenuClasses; -// print_r($this->_queryString); $this->_queryString = $this->sanitizeQueryString($this->_queryString); - + + $data['querySanitized'] = $this->querySanitized; + $data['queryString'] = Url::createUrl($this->_queryString); + $this->append($data); } diff --git a/h-source/Application/Controllers/GenericController.php b/h-source/Application/Controllers/GenericController.php index 49685f3..884f915 100644 --- a/h-source/Application/Controllers/GenericController.php +++ b/h-source/Application/Controllers/GenericController.php @@ -117,7 +117,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/catalogue',0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/catalogue/".$this->lang,0); } } @@ -252,7 +252,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/view/'.$clean['id_hard'],0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/view/".$this->lang."/".$clean['id_hard'],0); } } else @@ -468,6 +468,7 @@ class GenericController extends BaseController $data['ne_name'] = null; $data['tree'] = null; $data['isDeleted'] = 'no'; + $data['title'] = 'revision - '.Website::$generalName; if (count($data['table']) > 0) { @@ -476,8 +477,6 @@ class GenericController extends BaseController $data['name'] = encodeUrl($data['ne_name']); $data['tree'] = $this->getSpecHardLink() . " » " . $this->getViewLink($data['id_hard'],$data['ne_name'])." » " . $this->getHistoryLink($data['id_hard']) . " » <span class='last_tree_element'>revision</span>"; - $data['title'] = 'revision - '.Website::$generalName; - $data['updated_by'] = $data['table'][0]['revisions']['updated_by']; $data['update_date'] = $data['table'][0]['revisions']['update_date']; } @@ -611,7 +610,7 @@ class GenericController extends BaseController } else { - $this->redirect('users/login/'.$this->lang.'/'.$this->controller.'/view/'.$clean['id_hard'],0); + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/view/".$this->lang."/".$clean['id_hard'],0); } } } @@ -675,4 +674,16 @@ class GenericController extends BaseController return "<a href='".$this->baseUrl.'/'.$this->controller.'/catalogue/'.$this->lang.$this->viewStatus."'>".$this->controller."</a>"; } + protected function goToLoginForm() + { + if ($this->querySanitized) + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/".$this->action.Url::createUrl($this->_queryString)); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=home/index".Url::createUrl($this->_queryString)); + } + } + }
\ No newline at end of file diff --git a/h-source/Application/Controllers/UsersController.php b/h-source/Application/Controllers/UsersController.php index 1249647..7f42a2a 100644 --- a/h-source/Application/Controllers/UsersController.php +++ b/h-source/Application/Controllers/UsersController.php @@ -42,28 +42,20 @@ class UsersController extends BaseController $this->append($data); } - public function login($lang = 'en', $type = null,$the_action = null,$the_id = null) + public function login($lang = 'en') { $data = array(); if ( strcmp($this->_updating,'no') === 0 ) { $data['flag'] = isset($type) ? 'setted' : null; - $html['type'] = in_array($type,Hardware::$controllers) ? sanitizeAll($type) : 'notebooks'; - $html['the_action'] = sanitizeAlphanum($the_action); - $html['the_id'] = (int)$the_id; $html['lang'] = Lang::sanitize($lang); $data['title'] = 'Login - '.Website::$generalName; + + $redirect = $this->request->get('redirect','','sanitizeAll'); - if (isset($type)) - { - $data['action'] = Url::getRoot("users/login/".$html['lang']."/".$html['type']."/".$html['the_action']."/".$html['the_id']); - } - else - { - $data['action'] = Url::getRoot("users/login/".$html['lang']); - } + $data['action'] = Url::getRoot("users/login/".$this->lang."?redirect=$redirect"); $data['notice'] = null; @@ -82,11 +74,9 @@ class UsersController extends BaseController $this->redirect('home/index/'.Lang::$current,3,'You are already logged...'); break; case 'accepted': - if (isset($type)) + if (strcmp($redirect,'') !== 0) { - $address = strcmp($html['the_action'],'view') === 0 ? $html['type']."/view/".$html['lang']."/".$html['the_id'] : $html['type']."/catalogue/".$html['lang']; - - $this->redirect($address,0); + $this->redirect($redirect,0); } else { @@ -117,7 +107,15 @@ class UsersController extends BaseController } else if ($res === 'was-logged') { - $this->redirect('home/index/'.Lang::$current,0); + $redirect = $this->request->get('redirect','','sanitizeAll'); + if (strcmp($redirect,'') !== 0) + { + $this->redirect($redirect,0); + } + else + { + $this->redirect('home/index/'.Lang::$current,0); + } } else if ($res === 'error') { diff --git a/h-source/Application/Controllers/WikiController.php b/h-source/Application/Controllers/WikiController.php new file mode 100644 index 0000000..33647ef --- /dev/null +++ b/h-source/Application/Controllers/WikiController.php @@ -0,0 +1,475 @@ +<?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 file is part of h-source +// +// h-source 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. +// +// h-source 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 h-source. If not, see <http://www.gnu.org/licenses/>. + +if (!defined('EG')) die('Direct access not allowed!'); + +class WikiController extends BaseController +{ + + public function __construct($model, $controller, $queryString) { + parent::__construct($model, $controller, $queryString); + + $this->model('UsersModel'); + $this->model('WikiModel'); + $this->model('WikirevisionsModel'); + $this->model('WikitalkModel'); + + $this->m['WikiModel']->id_user = (int)$this->s['registered']->status['id_user']; + } + + public function insert($lang = 'en') + { + $this->shift(1); + + $data['title'] = 'insert a wiki page - '.Website::$generalName; + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['notice'] = null; + + $this->s['registered']->checkStatus(); + + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + if (isset($_POST['insertAction'])) + { + //insert the new wiki page + $this->m['WikiModel']->updateTable('insert'); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + } + + $data['notice'] = $this->m['WikiModel']->notice; + + $data['submitName'] = "insertAction"; + $data['hiddenInput'] = null; + + $data['values'] = $this->m['WikiModel']->getFormValues('insert','sanitizeHtml'); + $this->append($data); + + $this->load('form'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/insert/".$this->lang,0); + } + } + + public function update($lang = 'en') + { + $this->shift(1); + + $data['title'] = 'update a wiki page - '.Website::$generalName; + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['notice'] = null; + $this->s['registered']->checkStatus(); + + if (isset($_POST['id_wiki'])) + { + //get the id + $clean['id_wiki'] = (int)$_POST['id_wiki']; + $title = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + + if ($this->s['registered']->status['status'] === 'logged') + { + + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + $deleted = $this->m['WikiModel']->select("wiki.deleted")->where(array("id_wiki"=>$clean['id_wiki']))->limit(1)->toList('wiki.deleted')->send(); + + if (strcmp($deleted[0],'no') === 0) + { + $data['tree_name'] = $title; + + if (isset($_POST['updateAction'])) + { + //carry out the update database action + $this->m['WikiModel']->updateTable('update'); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + } + + $data['notice'] = $this->m['WikiModel']->notice; + + $data['id_wiki'] = $clean['id_wiki']; + $data['submitName'] = "updateAction"; + + $data['values'] = $this->m['WikiModel']->getFormValues('update','sanitizeHtml'); + $data['hiddenInput'] = "<input type='hidden' name='id_wiki' value='".$clean['id_wiki']."'>\n"; + + $this->append($data); + + $this->load('form'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang,2,'deleted..'); + } + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/page/".$this->lang."/".encodeUrl($title),0); + } + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang); + } + } + + protected function viewRedirect($titleClean) + { + if ($this->m['WikiModel']->queryResult) + { + $this->redirect($this->controller.'/page/'.$this->lang.'/'.$titleClean); + } + } + + public function page($lang = 'en', $title_clean = null) + { + $this->shift(2); + + $data['title'] = 'main page - '.Website::$generalName; + $clean['title_clean'] = sanitizeAll($title_clean); + + $data['isDeleted'] = 'no'; + + $res = $this->m['WikiModel']->select()->where(array('title_clean'=>$clean['title_clean']))->send(); + + if ( count($res) > 0 ) + { + $data['table'] = $res; + $data['tree_name'] = $res[0]['wiki']['title']; + $data['title'] = $res[0]['wiki']['title'] . ' - ' . Website::$generalName; + $data['isDeleted'] = $res[0]['wiki']['deleted']; + + if ( count($res) < 2 ) + { + $data['talk_number'] = $this->m['WikitalkModel']->select('count(*) as numb,id_wiki')->where(array('id_wiki'=>$res[0]['wiki']['id_wiki'],'deleted'=>'no'))->rowNumber(); + + $viewFile = 'page'; + $data['id_wiki'] = $res[0]['wiki']['id_wiki']; + } + else + { + $viewFile = 'select'; + } + } + else + { + $viewFile = 'not_found'; + } + + $this->append($data); + + $this->load($viewFile); + $this->load('bottom_left'); + $this->right(); + } + + public function history($lang = 'en', $id = 0) + { + $argKeys = array( + 'page:forceNat' => 1, + ); + + $this->setArgKeys($argKeys); + $this->shift(2); + + $clean['id'] = (int)$id; + $data['id'] = $clean['id']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id']); + + $data['title'] = 'history - '.Website::$generalName; + + //get the first revision + $res = $this->m['WikirevisionsModel']->db->select('revisions','id_rev','id_wiki='.$clean['id'],null,'id_rev',1); + if (count($res) > 0) + { + $data['firstRev'] = $res[0]['wiki_revisions']['id_rev']; + } + + $res1 = $this->m['WikiModel']->db->select('wiki','update_date,created_by','id_wiki='.$clean['id']); + + $this->m['WikirevisionsModel']->setWhereQueryClause(array('id_wiki' => $clean['id'])); + + //load the Pages helper + $this->helper('Pages',$this->controller.'/history/'.$this->lang.'/'.$clean['id'],'page'); + //get the number of records + $recordNumber = $this->m['WikirevisionsModel']->rowNumber(); + $page = $this->viewArgs['page']; + //set the limit clause + $this->m['WikirevisionsModel']->limit = $this->h['Pages']->getLimit($page,$recordNumber,20); + $res2 = $this->m['WikirevisionsModel']->getFields('update_date,created_by,id_rev'); + + $data['pageList'] = $this->h['Pages']->render($page-3,7); + + $data['rev1'] = $res1; + $data['rev2'] = $res2; + + $this->append($data); + $this->load('history'); + $this->load('bottom_left'); + $this->right(); + } + + public function revision($lang = 'en', $id_rev = 0) + { + $argKeys = array( + 'page:forceNat' => 1, + ); + + $this->setArgKeys($argKeys); + $this->shift(2); + + $clean['id_rev'] = (int)$id_rev; + + $this->m['WikirevisionsModel']->setWhereQueryClause(array("id_rev" => $clean['id_rev'])); + $data['table'] = $this->m['WikirevisionsModel']->getAll(); + + $data['id_wiki'] = 0; + $data['created_by'] = null; + $data['update_date'] = null; + $data['tree_name'] = null; + $data['tree'] = null; + $data['tree'] = null; + $data['title'] = 'revision - '.Website::$generalName; + $data['isDeleted'] = 'no'; + + if (count($data['table']) > 0) + { + $data['id_wiki'] = (int)$data['table'][0]['wiki_revisions']['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($data['id_wiki']); + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($data['id_wiki']) . " » ".gtext('Revision'); + + $data['created_by'] = $data['table'][0]['wiki_revisions']['created_by']; + $data['update_date'] = $data['table'][0]['wiki_revisions']['update_date']; + } + + $this->append($data); + $this->load('page'); + $this->load('bottom_left'); + $this->right(); + } + + public function differences($lang = 'en', $id_wiki = 0, $id_rev = 0) + { + $this->shift(3); + + $data['title'] = 'differences - '.Website::$generalName; + + $clean['id_wiki'] = (int)$id_wiki; + $clean['id_rev'] = (int)$id_rev; + + $data['id_wiki'] = $clean['id_wiki']; + $tree_name = $this->m['WikiModel']->getTheModelName((int)$data['id_wiki']); + $data['tree_name'] = $tree_name; + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($data['id_wiki']) . " » ".gtext('Differences'); + + $data['showDiff'] = false; + + $diffArray = array(); + + if (strcmp($clean['id_wiki'],0) !== 0 and strcmp($clean['id_rev'],0) !== 0) + { + $this->m['WikirevisionsModel']->where(array('id_wiki' => $clean['id_wiki'],'id_rev' => '<='.$clean['id_rev'])); + $this->m['WikirevisionsModel']->limit = 2; + $res = $this->m['WikirevisionsModel']->getAll(); + if (count($res) > 1) + { + $newArray = $res[0]['wiki_revisions']; + $oldArray = $res[1]['wiki_revisions']; + + $data['update_new'] = $newArray['update_date']; + $data['update_old'] = $oldArray['update_date']; + $data['created_by'] = $newArray['created_by']; + + $diffArray = $this->m['WikiModel']->getDiffArray($oldArray, $newArray); + + $data['showDiff'] = true; + } + } + else if (strcmp($clean['id_wiki'],0) !== 0 and strcmp($clean['id_rev'],0) === 0) + { + $this->m['WikiModel']->where(array('id_wiki' => $clean['id_wiki'])); + $lastRes = $this->m['WikiModel']->getAll(); + + if (count($lastRes) > 0) + { + $this->m['WikirevisionsModel']->setWhereQueryClause(array('id_wiki' => $clean['id_wiki'])); + $this->m['WikirevisionsModel']->limit = 1; + $revRes = $this->m['WikirevisionsModel']->getAll(); + + if (count($revRes) > 0) + { + $newArray = $lastRes[0]['wiki']; + $oldArray = $revRes[0]['wiki_revisions']; + + $data['update_new'] = $newArray['update_date']; + $data['update_old'] = $oldArray['update_date']; + $data['created_by'] = $newArray['created_by']; + + $diffArray = $this->m['WikiModel']->getDiffArray($oldArray, $newArray); + + $data['showDiff'] = true; + } + } + + } + + $data['fieldsWithBreaks'] = $this->m['WikiModel']->fieldsWithBreaks; + $data['diffArray'] = $diffArray; + + $this->append($data); + $this->load('differences'); + $this->load('bottom_left'); + $this->right(); + } + + public function climb($lang = 'en', $id_rev = 0) + { + $this->shift(2); + + $this->m['WikiModel']->setFields('title,page','sanitizeAll'); + + $data['title'] = 'make current - '.Website::$generalName; + + $clean['id_rev'] = (int)$id_rev; + $clean['id_wiki'] = (int)$this->m['WikirevisionsModel']->getIdPage($clean['id_rev']); + + if ($clean['id_wiki'] !== 0) + { + $deleted = $this->m['WikiModel']->select("wiki.deleted")->where(array("id_wiki"=>$clean['id_wiki']))->limit(1)->toList('wiki.deleted')->send(); + + $data['isDeleted'] = $deleted[0]; + + $data['id_rev'] = $clean['id_rev']; + $data['id_wiki'] = $clean['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + $data['name'] = $data['tree_name']; + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » " . $this->getHistoryLink($clean['id_wiki']) . " » " . gtext('Make current'); + + $data['notice'] = null; + $this->s['registered']->checkStatus(); + + if ($this->s['registered']->status['status'] === 'logged') + { + + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + if (isset($_POST['confirmAction'])) + { + if (strcmp($deleted[0],'no') === 0) + { + $this->m['WikiModel']->makeCurrent($clean['id_rev']); + + $this->viewRedirect($this->m['WikiModel']->lastTitleClean); + + $data['notice'] = $this->m['WikiModel']->notice; + } + else + { + $this->redirect($this->controller.'/page/'.$this->lang,2,'deleted..'); + } + } + + $this->append($data); + $this->load('climb'); + $this->load('bottom_left'); + $this->right(); + } + else + { + $this->redirect("users/login/".$this->lang."?redirect=".$this->controller."/page/".$this->lang."/".encodeUrl($data['tree_name']),0); + } + } + } + + public function talk($lang = 'en', $id_wiki = 0) + { + $this->shift(2); + + $this->m['WikitalkModel']->setFields('title,message','sanitizeAll'); + + $data['title'] = 'talk - '.Website::$generalName; + + $clean['id_wiki'] = (int)$id_wiki; + $data['id_wiki'] = $clean['id_wiki']; + $data['tree_name'] = $this->m['WikiModel']->getTheModelName($clean['id_wiki']); + $data['tree'] = $this->getSpecPageLink() . " » " . $this->getViewLink($data['tree_name'])." » ".gtext('Talk'); + + if (isset($_POST['insertAction'])) + { + if ($this->s['registered']->status['status'] === 'logged') + { + if ($this->m['UsersModel']->isBlocked($this->s['registered']->status['id_user'])) $this->redirect('my/home/'.$this->lang,2,'your account has been blocked..'); + + $this->m['WikitalkModel']->values['created_by'] = $this->s['registered']->status['id_user']; + $this->m['WikitalkModel']->values['id_wiki'] = $clean['id_wiki']; + + $this->m['WikitalkModel']->updateTable('insert'); + + if ($this->m['WikitalkModel']->queryResult) + { + header('Refresh: 0;url=http://'.DOMAIN_NAME.$_SERVER['REQUEST_URI']); + exit; + } + } + } + + $data['table'] = $this->m['WikitalkModel']->select()->where(array('id_wiki'=>$clean['id_wiki']))->orderBy('id_talk')->send(); + + $data['values'] = $this->m['WikitalkModel']->getFormValues('insert','sanitizeHtml'); + $data['notice'] = $this->m['WikitalkModel']->notice; + +// javascript for moderator +// $data['md_javascript'] = "moderator_dialog(\"hide\",\"talk\");moderator_dialog(\"show\",\"talk\");"; +// $data['go_to'] = $this->currPage."/".$this->lang."/".$clean['id_wiki']; + + $this->append($data); + $this->load('talk'); + $this->right(); +// $this->loadViewAll('talk,moderator_dialog'); + } + + protected function getViewLink($ne_name) + { + return "<a href='".$this->baseUrl.'/'.$this->controller.'/page/'.$this->lang.'/'.encodeUrl($ne_name)."'>".$ne_name."</a>"; + } + + protected function getHistoryLink($id) + { + return "<a href='".$this->baseUrl.'/'.$this->controller.'/history/'.$this->lang.'/'.$id."'>".gtext('History')."</a>"; + } + + protected function getSpecPageLink() + { + return "<a href='".$this->baseUrl.'/'.$this->controller.'/page/'.$this->lang."'>".$this->controller."</a>"; + } + +}
\ No newline at end of file |