diff options
author | Antonio Gallo <tonicucoz@gmail.com> | 2011-02-15 00:32:19 +0000 |
---|---|---|
committer | Antonio Gallo <tonicucoz@gmail.com> | 2011-02-15 00:32:19 +0000 |
commit | 1854075a62c6ca0422040b4e5ebf89088b0d02b2 (patch) | |
tree | 4c725cb4ef2b6eab95c0db23cfedcfb3c1406be4 /h-source/Application/Controllers/WikiController.php | |
parent | 99e87e1869e49c67bea2b779283def0e98f39bca (diff) |
added wiki - part 1
Diffstat (limited to 'h-source/Application/Controllers/WikiController.php')
-rw-r--r-- | h-source/Application/Controllers/WikiController.php | 475 |
1 files changed, 475 insertions, 0 deletions
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 |