From: <al...@us...> - 2008-08-28 20:52:17
|
Revision: 660 http://sciret.svn.sourceforge.net/sciret/?rev=660&view=rev Author: alpeb Date: 2008-08-28 20:52:12 +0000 (Thu, 28 Aug 2008) Log Message: ----------- implemented Zend_Db_Table and Zend_Db_Table_Row classes for the user and user gateway classes. Also some coding standards changes Modified Paths: -------------- trunk/actions/CompleteTodo.php trunk/actions/DeleteArticle.php trunk/actions/DeleteTodo.php trunk/actions/DeleteUser.php trunk/actions/EditUser.php trunk/actions/Login.php trunk/actions/Logout.php trunk/actions/MarkArticle.php trunk/actions/MarkLocation.php trunk/actions/MarkSearchResults.php trunk/actions/SaveArticle.php trunk/actions/SaveBookmark.php trunk/actions/SaveTodo.php trunk/actions/Upgrade.php trunk/classes/Controller.php trunk/index.php trunk/models/Article.php trunk/models/User.php trunk/templates/EditBookmark.tpl trunk/views/EditArticle.php trunk/views/EditPreferences.php trunk/views/EditTodo.php trunk/views/EditUser.php trunk/views/GetFavoritesDropdown.php trunk/views/GetTodosDropdown.php trunk/views/MainView.php trunk/views/ManageArticles.php trunk/views/ManageUsers.php trunk/views/SearchResults.php trunk/views/View.php trunk/views/ViewArticle.php trunk/views/ViewBookmark.php Added Paths: ----------- trunk/models/Users.php Removed Paths: ------------- trunk/models/UserGateway.php Modified: trunk/actions/CompleteTodo.php =================================================================== --- trunk/actions/CompleteTodo.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/CompleteTodo.php 2008-08-28 20:52:12 UTC (rev 660) @@ -16,7 +16,7 @@ function dispatch() { $todo = new Todo($_POST['todoId']); - if ($todo->getUserId() != $this->user->getId()) { + if ($todo->getUserId() != $this->user->id) { echo 'FAILURE|' . $this->user->lang('Cannot complete other people\'s todo\'s'); exit; } Modified: trunk/actions/DeleteArticle.php =================================================================== --- trunk/actions/DeleteArticle.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/DeleteArticle.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,18 +9,17 @@ * @packager Keyboard Monkeys */ -require 'actions/Action.php'; -require 'models/ArticleGateway.php'; +class DeleteArticle extends Action +{ -class DeleteArticle extends Action { - - function dispatch() { + function dispatch() + { $artId = isset($_GET['id'])? (int)$_GET['id'] : 0; if ($this->configuration->getConfigValue('restrictEditDelete')) { $article = new Article($artId); - if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & User::ROLE_ADMIN) != User::ROLE_ADMIN) { + if ($article->getUserId() != $this->user->id && ($this->user->role & User::ROLE_ADMIN) != User::ROLE_ADMIN) { $_SESSION['message'] = $this->user->lang('Sorry, only the author or an admin can delete this article.'); Library::redirect(Library::getLink(array('view' => 'ViewArticle', 'id' => $artId))); } @@ -38,4 +37,3 @@ } } -?> Modified: trunk/actions/DeleteTodo.php =================================================================== --- trunk/actions/DeleteTodo.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/DeleteTodo.php 2008-08-28 20:52:12 UTC (rev 660) @@ -16,7 +16,7 @@ function dispatch() { $todoGateway = new TodoGateway; - if ($todoGateway->deleteTodo($_POST['todoId'], $this->user->getId())) { + if ($todoGateway->deleteTodo($_POST['todoId'], $this->user->id)) { echo 'OK'; } else { echo 'FAILURE'; Modified: trunk/actions/DeleteUser.php =================================================================== --- trunk/actions/DeleteUser.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/DeleteUser.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,11 +9,8 @@ * @packager Keyboard Monkeys */ -require 'actions/Action.php'; -require_once 'models/UserGateway.php'; - -class DeleteUser extends Action { - +class DeleteUser extends Action +{ function dispatch() { $userId = isset($_GET['userId'])? (int)$_GET['userId'] : 0; @@ -21,12 +18,10 @@ die($this->user->lang('You can\'t delete the main administrator user.')); } - $userGateway = new UserGateway; - $userGateway->deleteUser($userId); + $users = new Users(); + $users->deleteUser($userId); $_SESSION['message'] = $this->user->lang('User deleted successfully'); Library::redirect(Library::getLink(array('view' => 'ManageUsers'))); } } - -?> Modified: trunk/actions/EditUser.php =================================================================== --- trunk/actions/EditUser.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/EditUser.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,23 +9,22 @@ * @packager Keyboard Monkeys */ -require 'actions/Action.php'; -require_once 'models/User.php'; +class EditUser extends Action +{ -class EditUser extends Action { - - function dispatch() { - + function dispatch() + { // security check - if (!$this->user->isAdmin() && $this->user->getId() != $_POST['userId']) { + if (!$this->user->isAdmin() && $this->user->id != $_POST['userId']) { $_SESSION['message'] = $this->user->lang('What are you trying to do??'); Library::redirect(Library::getLink(array('view' => 'Login'))); } $userId = (int)$_POST['userId']; - $user = new User($userId); + $users = new Users(); - if (!$user->getId()) { + if (!$userId) { + $user = $users->createRow(); $missingFieldsArr = array(); if ($_POST['firstName'] == '') { $missingFieldsArr[] = $this->user->lang('First Name'); @@ -70,6 +69,7 @@ } } else { + $user = $users->getRowInstance($userId); if ( $user->isPasswordExpired($this->configuration->getConfigValue('passwordExpirationDays')) @@ -77,26 +77,26 @@ ) { $_SESSION['message'] = $this->user->lang('Your password has expired. Please change it below.'); - Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId()))); + Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->id))); } if ($_POST['password'] != $_POST['password2']) { $_SESSION['message'] = $this->user->lang('Password and Repeat Password fields don\'t match'); - Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId()))); - } elseif (!$user->changePassword($_POST['password'])) { + Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->id))); + } elseif ($_POST['password'] != '' && !$user->changePassword($_POST['password'])) { $_SESSION['message'] = $this->user->lang('Invalid password. Please don\'t use any of these characters: %s', implode(', ', $user->getDisallowedPasswordChars())); - Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId()))); + Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->id))); } } - $user->setFirstName($_POST['firstName']); - $user->setLastName($_POST['lastName']); - $user->setUserName($_POST['userName']); - $user->setEmail($_POST['email']); + $user->firstname = $_POST['firstName']; + $user->lastname = $_POST['lastName']; + $user->username = $_POST['userName']; + $user->email = $_POST['email']; $user->setAdmin($this->user->isAdmin() && isset($_POST['adminAccess'])); $user->save(); - if (!$user->getId()) { + if (!$user->id) { $_SESSION['message'] = $this->user->lang('User added successfully'); } else { $_SESSION['message'] = $this->user->lang('User edited successfully'); @@ -105,9 +105,7 @@ if ($this->user->isAdmin()) { Library::redirect(Library::getLink(array('view' => 'ManageUsers'))); } else { - Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId()))); + Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->id))); } } } - -?> Modified: trunk/actions/Login.php =================================================================== --- trunk/actions/Login.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/Login.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,9 +9,10 @@ * @packager Keyboard Monkeys */ -class Login extends Action { - - function dispatch() { +class Login extends Action +{ + function dispatch() + { $auth = Zend_Auth::getInstance(); $db = Zend_Db::factory(Zend_Registry::get('config')->database); $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', 'MD5(?)'); @@ -19,7 +20,8 @@ ->setCredential($_POST['password']); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { - $user = UserGateway::getValidatedUser($_POST['username'], $_POST['password'], $this->configuration); + $users = new Users(); + $user = $users->getUserGivenUsername($_POST['username']); $auth->getStorage()->write($user); } else { $_SESSION['message'] = $this->user->lang('Wrong Username or Password'); @@ -28,11 +30,9 @@ if ($user->isPasswordExpired($this->configuration->getConfigValue('passwordExpirationDays'))) { $_SESSION['message'] = $this->user->lang('Your password has expired. Please change it below.'); - Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId()))); + Library::redirect(Library::getLink(array('view' => 'EditUser', 'userId' => $user->id))); } Library::redirect(Library::getLink(array('view' => 'MainView'))); } } - -?> Modified: trunk/actions/Logout.php =================================================================== --- trunk/actions/Logout.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/Logout.php 2008-08-28 20:52:12 UTC (rev 660) @@ -11,12 +11,11 @@ require 'actions/Action.php'; -class Logout extends Action { - - function dispatch() { +class Logout extends Action +{ + function dispatch() + { Zend_Auth::getInstance()->clearIdentity(); Library::Redirect(Library::getLink(array('view' => 'MainView'))); } } - -?> Modified: trunk/actions/MarkArticle.php =================================================================== --- trunk/actions/MarkArticle.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/MarkArticle.php 2008-08-28 20:52:12 UTC (rev 660) @@ -18,20 +18,20 @@ $favoriteGateway = new FavoriteGateway; if ($_POST['favorite'] == 1) { - if ($favoriteGateway->isArticleFavorite($_POST['artId'], $this->user->getId())) { + if ($favoriteGateway->isArticleFavorite($_POST['artId'], $this->user->id)) { echo 'DUPLICATE|foo'; return; } $favorite = new Favorite; - $favorite->setUserId($this->user->getId()); + $favorite->setUserId($this->user->id); $favorite->setType(FAVORITE_TYPE_ARTICLE); $favorite->setArtId($_POST['artId']); $favorite->save(); echo 'FAVORITE OK|' . $this->user->lang('Article has been added to favorites successfully');; } else { - $favoriteGateway->deleteArticleFavorite($_POST['artId'], $this->user->getId()); + $favoriteGateway->deleteArticleFavorite($_POST['artId'], $this->user->id); echo 'UNFAVORITE OK|' . $this->user->lang('Article has been removed from favorites successfully');; } Modified: trunk/actions/MarkLocation.php =================================================================== --- trunk/actions/MarkLocation.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/MarkLocation.php 2008-08-28 20:52:12 UTC (rev 660) @@ -18,20 +18,20 @@ $favoriteGateway = new FavoriteGateway; if ($_POST['favorite'] == 1) { - if ($favoriteGateway->isLocationFavorite($_POST['catId'], $this->user->getId())) { + if ($favoriteGateway->isLocationFavorite($_POST['catId'], $this->user->id)) { echo 'DUPLICATE|foo'; return; } $favorite = new Favorite; - $favorite->setUserId($this->user->getId()); + $favorite->setUserId($this->user->id); $favorite->setType(FAVORITE_TYPE_LOCATION); $favorite->setCatId($_POST['catId']); $favorite->save(); echo 'FAVORITE OK|' . $this->user->lang('Location has been added to favorites successfully');; } else { - $favoriteGateway->deleteLocationFavorite($_POST['catId'], $this->user->getId()); + $favoriteGateway->deleteLocationFavorite($_POST['catId'], $this->user->id); echo 'UNFAVORITE OK|' . $this->user->lang('Location has been removed from favorites successfully');; } Modified: trunk/actions/MarkSearchResults.php =================================================================== --- trunk/actions/MarkSearchResults.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/MarkSearchResults.php 2008-08-28 20:52:12 UTC (rev 660) @@ -18,20 +18,20 @@ $favoriteGateway = new FavoriteGateway; if ($_POST['favorite'] == 1) { - if ($favoriteGateway->isSearchResultFavorite($_POST['query'], $this->user->getId())) { + if ($favoriteGateway->isSearchResultFavorite($_POST['query'], $this->user->id)) { echo 'DUPLICATE|foo'; return; } $favorite = new Favorite; - $favorite->setUserId($this->user->getId()); + $favorite->setUserId($this->user->id); $favorite->setType(FAVORITE_TYPE_SEARCHRESULT); $favorite->setSearchStr($_POST['query']); $favorite->save(); echo 'FAVORITE OK|' . $this->user->lang('Search has been added to favorites successfully'); } else { - $favoriteGateway->deleteSearchResultFavorite($_POST['query'], $this->user->getId()); + $favoriteGateway->deleteSearchResultFavorite($_POST['query'], $this->user->id); echo 'UNFAVORITE OK|' . $this->user->lang('Search has been removed from favorites successfully'); } Modified: trunk/actions/SaveArticle.php =================================================================== --- trunk/actions/SaveArticle.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/SaveArticle.php 2008-08-28 20:52:12 UTC (rev 660) @@ -20,7 +20,7 @@ if ($articleId > 0 && $this->configuration->getConfigValue('restrictEditDelete')) { $article = new Article($articleId); - if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & User::ROLE_ADMIN) != User::ROLE_ADMIN) { + if ($article->getUserId() != $this->user->id && ($this->user->role & User::ROLE_ADMIN) != User::ROLE_ADMIN) { $_SESSION['message'] = $this->user->lang('Sorry, only the author or an admin can modify this article.'); Library::redirect(Library::getLink(array('view' => 'ViewArticle', 'id' => $articleId))); } @@ -51,11 +51,11 @@ if ($articleId > 0) { $art->setModificationDate(date('Y-m-d H:i:s')); - $art->setModifiedByUserId($this->user->getId()); + $art->setModifiedByUserId($this->user->id); $historyMessage = $this->user->lang('Article modified'); } else { $art->setPublished($this->configuration->getConfigValue('publishArticlesAuto') == '1'? true : false); - $art->setUserId($this->user->getId()); + $art->setUserId($this->user->id); $historyMessage = $this->user->lang('Article created'); if (isset($_POST['questionID'])) { @@ -74,7 +74,7 @@ require_once 'models/Todo.php'; $todo = new Todo(); - $todo->setUserId($this->user->getId()); + $todo->setUserId($this->user->id); $todo->setTitle($_POST['title']); $todo->setStatus(TODO_STATUS_PENDING); $todo->setPrivate(true); Modified: trunk/actions/SaveBookmark.php =================================================================== --- trunk/actions/SaveBookmark.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/SaveBookmark.php 2008-08-28 20:52:12 UTC (rev 660) @@ -32,12 +32,12 @@ if ($bookmarkId > 0) { $art->setModificationDate(date('Y-m-d H:i:s')); - $art->setModifiedByUserId($this->user->getId()); + $art->setModifiedByUserId($this->user->id); $historyMessage = $this->user->lang('Bookmark modified'); } else { $art->setPublished($this->configuration->getConfigValue('publishBookmarksAuto') == '1'? true : false); $art->setDraft($_POST['draft']); - $art->setUserId($this->user->getId()); + $art->setUserId($this->user->id); $historyMessage = $this->user->lang('Bookmark created'); } $art->save(); @@ -48,7 +48,7 @@ require_once 'models/Todo.php'; $todo = new Todo(); - $todo->setUserId($this->user->getId()); + $todo->setUserId($this->user->id); $todo->setTitle($_POST['name']); $todo->setStatus(TODO_STATUS_PENDING); $todo->setPrivate(true); Modified: trunk/actions/SaveTodo.php =================================================================== --- trunk/actions/SaveTodo.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/SaveTodo.php 2008-08-28 20:52:12 UTC (rev 660) @@ -19,11 +19,11 @@ $todo = new Todo($todoId); - if ($todoId && $todo->getUserId() != $this->user->getId()) { + if ($todoId && $todo->getUserId() != $this->user->id) { die('You don\'t have permission to edit this To-Do'); } - $todo->setUserId($this->user->getId()); + $todo->setUserId($this->user->id); $todo->setTitle($_POST['title']); $todo->setContent($_POST['content']); $todo->setStatus(isset($_POST['completed'])? TODO_STATUS_COMPLETED : TODO_STATUS_PENDING); Modified: trunk/actions/Upgrade.php =================================================================== --- trunk/actions/Upgrade.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/actions/Upgrade.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,15 +9,13 @@ * @packager Keyboard Monkeys */ -require 'actions/Action.php'; +class Upgrade extends Action +{ + var $users; -class Upgrade extends Action { - var $userGateway; - function dispatch() { - require 'models/UserGateway.php'; - $this->userGateway = new UserGateway; - if (!($user = $this->userGateway->getValidatedUser($_POST['username'], $_POST['password'], $this->configuration)) || !$user->isAdmin()) { + $this->users = new Users(); + if (!($user = $this->users->getValidatedUser($_POST['username'], $_POST['password'], $this->configuration)) || !$user->isAdmin()) { $_SESSION['message'] = $this->user->lang('Wrong Username or Password'); Library::redirect(Library::getLink(array('view' => 'Upgrade'))); } @@ -57,7 +55,7 @@ $queries = file($fileName); foreach ($queries as $query) { if (trim($query) != '') { - $this->userGateway->db->query($query); // unorthodox? + DB::getInstance()->query($query); } } } Modified: trunk/classes/Controller.php =================================================================== --- trunk/classes/Controller.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/classes/Controller.php 2008-08-28 20:52:12 UTC (rev 660) @@ -56,10 +56,10 @@ if ( // user hasn't got enough privileges - (($this->user->getRole() & $this->views[$view][MINIMUM_ROLE]) != $this->views[$view][MINIMUM_ROLE]) + (($this->user->role & $this->views[$view][MINIMUM_ROLE]) != $this->views[$view][MINIMUM_ROLE]) // or user is anonymous and KB is not public - || ($this->user->getRole() == User::ROLE_ANONYMOUS && $this->views[$view][ALLOW_VIEW_ONLY_IF_PUBLIC_KB] && !$this->configuration->getConfigValue('publishKB')) + || ($this->user->role == User::ROLE_ANONYMOUS && $this->views[$view][ALLOW_VIEW_ONLY_IF_PUBLIC_KB] && !$this->configuration->getConfigValue('publishKB')) ) { Library::redirect(Library::getLink(array('view' => 'Login'))); @@ -87,7 +87,7 @@ $this->user->setSkipTranslations(true); } - if (($this->user->getRole() & $this->actions[$action][MINIMUM_ROLE]) != $this->actions[$action][MINIMUM_ROLE]) { + if (($this->user->role & $this->actions[$action][MINIMUM_ROLE]) != $this->actions[$action][MINIMUM_ROLE]) { Library::redirect(Library::getLink(array('view' => 'Login'))); } require "actions/$action.php"; Modified: trunk/index.php =================================================================== --- trunk/index.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/index.php 2008-08-28 20:52:12 UTC (rev 660) @@ -74,6 +74,7 @@ $profiler = new DBProfiler(); $db->setProfiler($profiler); } +Zend_Db_Table_Abstract::setDefaultAdapter($db); $connectionFailed = false; try { $db->getConnection(); @@ -94,18 +95,22 @@ Zend_Session::start(); $auth = Zend_Auth::getInstance(); +$users = new Users(); if ($auth->hasIdentity()) { $user = $auth->getStorage()->read(); $user->init(); if ($user->app == 'monkeys') { $publicId = $user->publicId; - $user = new User($publicId); + $user = $users->getRowInstance($publicId); $user->app = 'sciret'; $auth->getStorage()->write($user); } + + // reactivate row as live data + $user->setTable($users); } else { // guest user - $user = new User(); + $user = $users->createRow(); } Zend_Registry::set('user', $user); Modified: trunk/models/Article.php =================================================================== --- trunk/models/Article.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/models/Article.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,7 +9,8 @@ * @packager Keyboard Monkeys Ltd */ -class Article { +class Article +{ var $id; var $isBookmark = 0; var $questionId; @@ -285,14 +286,16 @@ function getCreatedBy() { require_once 'models/User.php'; - $creator = new User($this->userId); + $users = new Users(); + $creator = $users->getRowInstance($this->userId); return $creator->getFullName(); } function getModifiedBy() { require_once 'models/User.php'; - $modifier = new User($this->modifiedByUserId); + $users = new Users(); + $modifier = $users->getRowInstance($this->modifiedByUserId); return $modifier->getFullName(); } @@ -307,7 +310,8 @@ function getUser() { if (!isset($this->user)) { - $this->user = new User($this->getUserId()); + $users = new Users(); + $this->user = $users->getRowInstance($this->getUserId()); } return $this->user; Modified: trunk/models/User.php =================================================================== --- trunk/models/User.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/models/User.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,7 +9,8 @@ * @packager Keyboard Monkeys */ -class User { +class User extends Zend_Db_Table_Row_Abstract +{ const ROLE_ANONYMOUS = 1; const ROLE_REGISTERED = 3; // 2 | ROLE_ANONYMOUS; const ROLE_ADMIN = 7; // 4 | ROLE_REGISTERED ; @@ -20,158 +21,100 @@ public $app = 'sciret'; public $publicId; - var $id; - var $firstName; - var $lastName; - var $userName; - var $email; - var $password; - var $passwordChanged; - var $admin = 0; - var $role = User::ROLE_ANONYMOUS; var $langArr; var $skipTranslations = false; - var $preferences = array( - 'startBrowsing' => 'all', - 'articlesPerPage' => 10, - 'dateFormat' => 'Month Day, Year', - 'language' => '', // set in the constructor - 'navigationType' => 'catAndSubCats', - 'hiddenCategories' => '', - ); var $rtlLanguages = array('Hebrew'); var $disallowedPasswordChars = array('"', '@', '#', '%', '^', '&', '*', '(', ')', ','); - function User($id = false) { + private $_preferencesArr; - $this->preferences['language'] = Zend_Registry::get('config')->general->language_default; - - if ($id) { - $query = 'SELECT firstname, lastname, username, email, password, password_changed, admin, preferences FROM users WHERE id = ?'; - $result = DB::getInstance()->query($query, $id); - if ($row = $result->fetch()) { - $this->id = $id; - $this->firstName = $row['firstname']; - $this->lastName = $row['lastname']; - $this->userName = $row['username']; - $this->email = $row['email']; - $this->admin = $row['admin']; - $this->password = $row['password']; - $this->passwordChanged = $row['password_changed']; - if ($row['preferences'] != '') { - // this leaves the default values if preference is not set - $tPreferences = unserialize($row['preferences']); - foreach ($tPreferences as $key => $value) { - $this->preferences[$key] = $value; - } - } - - $this->setRole(); - } - } - - $this->init(); - } - - public function init() { + public function init() + { if ($this->id) { $this->publicId = $this->id; } - } - function save() { - $db = DB::getInstance(); - if (!isset($this->id)) { - $query = 'INSERT INTO users SET firstname=?, lastname=?, username=?, email=?, admin=?, password=MD5(?), password_changed=?, preferences=?'; - $result = $db->query($query, array($this->firstName, $this->lastName, $this->userName, $this->email, $this->admin, $this->password, $this->passwordChanged, serialize($this->preferences))); - $this->id = $db->lastInsertId(); - } else { - $query = 'UPDATE users SET firstname=?, lastname=?, username=?, email=?, password_changed=?, admin=?, preferences=? WHERE id=?'; - $result = $db->query($query, array($this->firstName, $this->lastName, $this->userName, $this->email, $this->passwordChanged, $this->admin, serialize($this->preferences), $this->id)); + if ($this->preferences) { + // this has to go here because when the object has been fetched from the DB, + // when init() is called it already has the fields filled in. + // It has to go under __set() below too, because when the object is initialized through + // createRow(), then when init() is called the fields haven't been initialized yet :/ + $this->_initPreferencesArr($this->preferences); } } - function getFirstName() { - return $this->firstName; + private function _initPreferencesArr($preferences) + { + $this->_preferencesArr = unserialize($preferences); + if ($this->_preferencesArr['language'] == '') { + $this->_preferencesArr['language'] = Zend_Registry::get('config')->general->language_default; + } } - function setFirstName($firstName) { - $this->firstName = $firstName; + public function __get($name) + { + if ($name == 'role') { + return $this->getRole(); + } + + return parent::__get($name); } - function getLastName() { - return $this->lastName; - } + public function __set($name, $value) + { + if ($name == 'preferences') { + $this->_initpreferencesArr($value); + } - function setLastName($lastName) { - $this->lastName = $lastName; + return parent::__set($name, $value); } - function getFullName() { - return $this->firstName . ' ' . $this->lastName; + public function save() + { + $this->preferences = serialize($this->_preferencesArr); + parent::save(); } - function getId() { - return $this->id; + function getFullName() + { + return $this->firstname . ' ' . $this->lastname; } - function setId($id) { + function setId($id) + { $this->publicId = (int)$id; $this->id = (int)$id; } - function isAnonymous() { - return !isset($this->id); + function isAnonymous() + { + return !($this->id); } - function getPasswordChanged() { - return $this->passwordChanged; + function isAdmin() + { + return $this->admin == 1; } - function setPasswordChanged($date) { - $this->passwordChanged = $date; + function setAdmin($isAdmin) + { + $this->admin = $isAdmin? 1 : 0; } - function isAdmin() { - return $this->admin == 1; - } + function getRole() + { + if ($this->isAnonymous()) { + return self::ROLE_ANONYMOUS; + } - function setAdmin($isAdmin) { - $this->admin = $isAdmin? 1 : 0; if ($this->admin == 1) { - $this->role = User::ROLE_ADMIN; + return self::ROLE_ADMIN; } - } - function getUserName() { - return $this->userName; + return self::ROLE_REGISTERED; } - function setUserName($userName) { - $this->userName = $userName; - } - - function getEmail() { - return $this->email; - } - - function setEmail($email) { - $this->email = $email; - } - - function getPassword() { - return $this->password; - } - - function setRole() { - $this->role = ($this->admin == 1)? User::ROLE_ADMIN : User::ROLE_REGISTERED; - } - - function getRole() { - return $this->role; - } - function _isPasswordValid($password) { foreach ($this->disallowedPasswordChars as $char) { @@ -183,13 +126,14 @@ return true; } - function setPassword($password) { + function setPassword($password) + { if (!$this->_isPasswordValid($password)) { return false; } - $this->password = $password; - $this->passwordChanged = date('Y-m-d'); + $this->password = md5($password); + $this->password_changed = date('Y-m-d'); return true; } @@ -199,38 +143,36 @@ return $this->rtlLanguages; } - function changePassword($password) { + function changePassword($password) + { // 18.12.2006 NE: Beim setzen des Passworts fehlte eine einschränkung auf den User, // dessen sein Passwort geändert werden sollte if (!$this->_isPasswordValid($password)) { return false; } - $query = 'UPDATE users SET password=MD5(?), password_changed = \''.date('Y-m-d').'\' WHERE `id` = ?'; - DB::getInstance()->query($query, $password, $this->id); - $this->passwordChanged = date('Y-m-d'); + $this->password = md5($password); + $this->password_changed = date('Y-m-d'); return true; } - - function getPreferences() { - return $this->preferences; - } - function getPreference($field) { - if ($this->role == User::ROLE_ANONYMOUS && isset($_COOKIE[$field])) { + function getPreference($field) + { + if ($this->isAnonymous() && isset($_COOKIE[$field])) { return $_COOKIE[$field]; } - return $this->preferences[$field]; + return $this->_preferencesArr[$field]; } - function setPreference($field, $value) { - if ($this->role == User::ROLE_ANONYMOUS) { + function setPreference($field, $value) + { + if ($this->isAnonymous()) { setcookie($field, $value, time() + 60*60*24*90); // cookie expires in 90 days } - $this->preferences[$field] = $value; + $this->_preferencesArr[$field] = $value; } function getDisallowedPasswordChars() @@ -238,7 +180,8 @@ return $this->disallowedPasswordChars; } - function formatDate($date) { + function formatDate($date) + { $timestamp = strtotime($date); switch ($this->getPreference('dateFormat')) { case 'Month Day, Year': @@ -280,11 +223,13 @@ } } - function setSkipTranslations($bool) { + function setSkipTranslations($bool) + { $this->skipTranslations = $bool; } - function lang($phrase, $args = false) { + function lang($phrase, $args = false) + { $phrase = stripslashes($phrase); if (!is_array($args)) { $args = func_get_args(); @@ -337,12 +282,11 @@ return vsprintf($phrase, $args); } - function isPasswordExpired($expirationDays) { + function isPasswordExpired($expirationDays) + { // there are 86400 seconds in one day - $passwordAge = (time() - strtotime($this->passwordChanged)) / 86400; + $passwordAge = (time() - strtotime($this->password_changed)) / 86400; return ($passwordAge > $expirationDays); } } - -?> Deleted: trunk/models/UserGateway.php =================================================================== --- trunk/models/UserGateway.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/models/UserGateway.php 2008-08-28 20:52:12 UTC (rev 660) @@ -1,69 +0,0 @@ -<?php - -/* -* @copyright Copyright (C) 2005-2008 Keyboard Monkeys Ltd. http://www.kb-m.com -* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License -* @author Alejandro Pedraza -* @since Sciret 1.2 -* @package Sciret -* @packager Keyboard Monkeys -*/ - -require_once 'models/User.php'; - -class UserGateway { - - public static function getValidatedUser($username, $password, $configuration) { - if (in_array($configuration->getConfigValue('version'), array(0, '1.1.0'))) { - $query = 'SELECT id, firstname, lastname, username, email, admin FROM users WHERE username=? AND password=MD5(?)'; - } else { - $query = 'SELECT id, firstname, lastname, username, email, password_changed, admin FROM users WHERE username=? AND password=MD5(?)'; - } - $result = DB::getInstance()->query($query, array($username, $password)); - if ($row = $result->fetch()) { - $user = new User; - $user->setId($row['id']); - $user->setFirstName($row['firstname']); - $user->setLastName($row['lastname']); - $user->setUserName($row['username']); - $user->setEmail($row['email']); - if (!in_array($configuration->getConfigValue('version'), array(0, '1.1.0'))) { - $user->setPasswordChanged($row['password_changed']); - } - $user->setAdmin($row['admin']); - $user->setRole(); - - return $user; - } - - return false; - } - - function getUsersList() { - $query = 'SELECT id, firstname, lastname, username, email, admin FROM users'; - $result = DB::getInstance()->query($query); - $users = array(); - while ($row = $result->fetch()) { - $user = new User; - $user->setId($row['id']); - $user->setFirstName($row['firstname']); - $user->setLastName($row['lastname']); - $user->setUserName($row['username']); - $user->setEmail($row['email']); - $user->setAdmin($row['admin']); - $users[] = $user; - } - - return $users; - } - - function deleteUser($userId) { - $query = 'DELETE FROM users WHERE id=?'; - DB::getInstance()->query($query, $userId); - - $query = 'UPDATE articles SET user_id = 1 WHERE user_id=?'; - DB::getInstance()->query($query, $userId); - } -} - -?> Added: trunk/models/Users.php =================================================================== --- trunk/models/Users.php (rev 0) +++ trunk/models/Users.php 2008-08-28 20:52:12 UTC (rev 660) @@ -0,0 +1,49 @@ +<?php + +class Users extends SciretTableGateway +{ + protected $_name = 'users'; + protected $_primary = 'id'; + protected $_rowClass = 'User'; + + public function createRow() + { + $preferences = array( + 'startBrowsing' => 'all', + 'articlesPerPage' => 10, + 'dateFormat' => 'Month Day, Year', + 'language' => '', // set in the constructor + 'navigationType' => 'catAndSubCats', + 'hiddenCategories' => '', + ); + + return parent::createRow(array( + 'password_changed' => '0000-00-00', + 'admin' => 0, + 'preferences' => serialize($preferences), + )); + } + + public function getUserGivenUsername($username) + { + $select = $this->select() + ->where('username=?', $username); + + return $this->fetchRow($select); + } + + function getUsersList() + { + $select = $this->select(); + return $this->fetchAll($select); + } + + function deleteUser($userId) + { + $where = $this->getAdapter()->quoteInto('id=?', $userId); + $this->delete($where); + + $where = $this->getAdapter()->quoteInto('user_id=?', $userId); + $this->getAdapter()->update('articles', array('user_id' => 1), $where); + } +} Modified: trunk/templates/EditBookmark.tpl =================================================================== --- trunk/templates/EditBookmark.tpl 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/templates/EditBookmark.tpl 2008-08-28 20:52:12 UTC (rev 660) @@ -10,87 +10,87 @@ --> <form name="saveArticleForm" method="POST" action="{formAction}"> -<input type="hidden" name="draft" value="0" /> -<table width="100%" border="0" cellspacing="1" cellpadding="3" border="1" style='border:1px solid black'> - <!-- BEGIN bookmark_id_block --> - <tr class="th"> - <input type="hidden" name="bookmarkId" value="{bookmarkId}" /> - <td style="text-align:right; font-weight:bold"> - [l]Bookmark ID[/l]: - </td> - <td> - {bookmarkId} - </td> - </tr> - <!-- END bookmark_id_block --> - <tr class="row_on"> - <td width="10%" style="text-align:right;"> - <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Category[/l]:</span> - </td> - <td width="90%"> - <select name="cat_id"> - <option value="0">[l]None[/l]</option> - <!-- BEGIN categories_block --> - <option value="{category_id}" {catSelected}>{category_label}</option> - <!-- END categories_block --> - </select> - </td> - </tr> - <tr class="row_off"> - <td align=right style="text-align:right"> - <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Name[/l]:</span> - </td> - <td> - <input type="text" size="70" name="name" value="{name}" /> - </td> - </tr> - <tr class="row_on"> - <td align=right style="text-align:right"> - <span style='font:normal 12px sans-serif; font-weight:bold'>[l]URL[/l]:</span> - </td> - <td> - <input type="text" size="70" name="url" value="{url}" /> - </td> - </tr> - <tr class="row_off"> - <td style="text-align:right; font:normal 12px sans-serif; font-weight:bold" nowrap="true"> - [l]Expiration Date[/l]: - </td> - <td> - <input type="hidden" id="hiddenDate" name="expDate" value="{expDate}" /> - <span id="dateShow">{expDateContents}</span> - <img src="images/datepopup.gif" id="expDateButton" style="cursor:pointer" /> - <span id="labelSetDate" style="display:{labelSetExpDateDisplay}">([l]Currently none.<br />Click icon to set one.[/l])</span> - <a id="removeDateLink" href="javascript:void(0);" onclick="removeExpirationDate();" style="display:{removeExpDateLinkDisplay}; font-weight:bold; font-size:10px">[l]Remove expiration date[/l]</a> - </td> - </tr> - <tr class="row_on"> - <td align="right" valign="top" style="text-align:right"> - <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Description[/l]:</span> - </td> - <td> - <textarea name="description" cols="67" rows="5" >{description}</textarea> - </td> - </tr> - <tr class="th"> - <td colspan=2> - - </td> - </tr> - <tr> - <td colspan="2"> - <input type="submit" value="[l]Save[/l]" /> - <b>{publicationNotice}</b> - </td> - </tr> - <!-- BEGIN saveAsDraftButton_block --> - <tr> - <td colspan="2"> - <input type="button" value="[l]Save as Draft[/l]" onclick="saveDraft(form);" /> - </td> - </tr> - <!-- END saveAsDraftButton_block --> -</table> + <input type="hidden" name="draft" value="0" /> + <table width="100%" border="0" cellspacing="1" cellpadding="3" border="1" style='border:1px solid black'> + <!-- BEGIN bookmark_id_block --> + <tr class="th"> + <input type="hidden" name="bookmarkId" value="{bookmarkId}" /> + <td style="text-align:right; font-weight:bold"> + [l]Bookmark ID[/l]: + </td> + <td> + {bookmarkId} + </td> + </tr> + <!-- END bookmark_id_block --> + <tr class="row_on"> + <td width="10%" style="text-align:right;"> + <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Category[/l]:</span> + </td> + <td width="90%"> + <select name="cat_id"> + <option value="0">[l]None[/l]</option> + <!-- BEGIN categories_block --> + <option value="{category_id}" {catSelected}>{category_label}</option> + <!-- END categories_block --> + </select> + </td> + </tr> + <tr class="row_off"> + <td align=right style="text-align:right"> + <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Name[/l]:</span> + </td> + <td> + <input type="text" size="50" name="name" value="{name}" /> + </td> + </tr> + <tr class="row_on"> + <td align=right style="text-align:right"> + <span style='font:normal 12px sans-serif; font-weight:bold'>[l]URL[/l]:</span> + </td> + <td> + <input type="text" size="50" name="url" value="{url}" /> + </td> + </tr> + <tr class="row_off"> + <td style="text-align:right; font:normal 12px sans-serif; font-weight:bold" nowrap="true"> + [l]Expiration Date[/l]: + </td> + <td> + <input type="hidden" id="hiddenDate" name="expDate" value="{expDate}" /> + <span id="dateShow">{expDateContents}</span> + <img src="images/datepopup.gif" id="expDateButton" style="cursor:pointer" /> + <span id="labelSetDate" style="display:{labelSetExpDateDisplay}">([l]Currently none.<br />Click icon to set one.[/l])</span> + <a id="removeDateLink" href="javascript:void(0);" onclick="removeExpirationDate();" style="display:{removeExpDateLinkDisplay}; font-weight:bold; font-size:10px">[l]Remove expiration date[/l]</a> + </td> + </tr> + <tr class="row_on"> + <td align="right" valign="top" style="text-align:right"> + <span style='font:normal 12px sans-serif; font-weight:bold'>[l]Description[/l]:</span> + </td> + <td> + <textarea name="description" cols="67" rows="5" >{description}</textarea> + </td> + </tr> + <tr class="th"> + <td colspan=2> + + </td> + </tr> + <tr> + <td colspan="2"> + <input type="submit" value="[l]Save[/l]" /> + <b>{publicationNotice}</b> + </td> + </tr> + <!-- BEGIN saveAsDraftButton_block --> + <tr> + <td colspan="2"> + <input type="button" value="[l]Save as Draft[/l]" onclick="saveDraft(form);" /> + </td> + </tr> + <!-- END saveAsDraftButton_block --> + </table> </form> <script type="text/javascript"> Calendar.setup( Modified: trunk/views/EditArticle.php =================================================================== --- trunk/views/EditArticle.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/EditArticle.php 2008-08-28 20:52:12 UTC (rev 660) @@ -66,9 +66,9 @@ $this->tpl->parse('article_id', 'article_id_block'); - if (($this->user->getRole() & User::ROLE_ADMIN) == User::ROLE_ADMIN) { + if ($this->user->isAdmin()) { $this->tpl->set_var(array( - )); + )); $this->tpl->parse('usage_id','usage_block'); } else { $this->tpl->set_var('usage_id', ''); Modified: trunk/views/EditPreferences.php =================================================================== --- trunk/views/EditPreferences.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/EditPreferences.php 2008-08-28 20:52:12 UTC (rev 660) @@ -11,9 +11,10 @@ require 'views/View.php'; -class EditPreferences extends View { - - function dispatch() { +class EditPreferences extends View +{ + function dispatch() + { $this->tpl->set_file('edit_preferences', 'EditPreferences.tpl'); $this->tpl->set_block('edit_preferences', 'languages_block', 'languages'); $this->tpl->set_block('edit_preferences', 'adminPreferences_block', 'adminPreferences'); @@ -92,5 +93,3 @@ $this->tpl->pparse('out', 'edit_preferences'); } } - -?> Modified: trunk/views/EditTodo.php =================================================================== --- trunk/views/EditTodo.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/EditTodo.php 2008-08-28 20:52:12 UTC (rev 660) @@ -37,7 +37,7 @@ $todo = new Todo($todoId); - if ($todo->getUserId() != $this->user->getId()) { + if ($todo->getUserId() != $this->user->id) { die('You don\'t have permission to edit this To-Do'); } Modified: trunk/views/EditUser.php =================================================================== --- trunk/views/EditUser.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/EditUser.php 2008-08-28 20:52:12 UTC (rev 660) @@ -11,11 +11,12 @@ require 'views/View.php'; -class EditUser extends View { - - function dispatch() { +class EditUser extends View +{ + function dispatch() + { // security check - if (!$this->user->isAdmin() && $this->user->getId() != $_GET['userId']) { + if (!$this->user->isAdmin() && $this->user->id != $_GET['userId']) { echo $this->user->lang('What are you trying to do??'); return; } @@ -26,14 +27,15 @@ $this->tpl->set_block('addUser', 'adminAccess_block', 'adminAccess'); $this->tpl->set_var('formAction', Library::getLink(array('action' => 'EditUser'))); - $user = new User($userId); - if ($user->getId()) { + $users = new Users(); + $user = $users->getRowInstance($userId); + if ($userId) { $this->tpl->set_var(array( - 'userId' => $user->getId(), - 'firstName' => $user->getFirstName(), - 'lastName' => $user->getLastName(), - 'userName' => $user->getUserName(), - 'email' => $user->getEmail(), + 'userId' => $user->id, + 'firstName' => $user->firstname, + 'lastName' => $user->lastname, + 'userName' => $user->username, + 'email' => $user->email, 'password' => '', 'password2' => '', 'checkedAdminAccess' => $user->isAdmin()? 'checked="true" ' : '', @@ -64,5 +66,3 @@ $this->tpl->pparse('out', 'addUser'); } } - -?> Modified: trunk/views/GetFavoritesDropdown.php =================================================================== --- trunk/views/GetFavoritesDropdown.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/GetFavoritesDropdown.php 2008-08-28 20:52:12 UTC (rev 660) @@ -10,14 +10,15 @@ */ require 'views/View.php'; -require 'models/FavoriteGateway.php'; define('TITLE_LENGTH', 35); -class GetFavoritesDropdown extends View { +class GetFavoritesDropdown extends View +{ var $categories; - function dispatch() { + function dispatch() + { $this->tpl->set_file('favoritesDropdown', 'FavoritesDropdown.tpl'); $this->tpl->set_block('favoritesDropdown', 'favoritesList_block', 'favoritesList'); $this->tpl->set_block('favoritesList_block', 'favoriteItem_block', 'favoriteItem'); @@ -27,7 +28,7 @@ $favoriteGateway = new FavoriteGateway; $thereAreFavorites = false; $firstIteration = true; - foreach ($favoriteGateway->getFavorites($this->user->getId()) as $favorite) { + foreach ($favoriteGateway->getFavorites($this->user->id) as $favorite) { $thereAreFavorites = true; switch($favorite->getType()) { case FAVORITE_TYPE_ARTICLE: @@ -81,5 +82,3 @@ $this->tpl->pparse('out', 'favoritesDropdown'); } } - -?> Modified: trunk/views/GetTodosDropdown.php =================================================================== --- trunk/views/GetTodosDropdown.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/GetTodosDropdown.php 2008-08-28 20:52:12 UTC (rev 660) @@ -10,12 +10,13 @@ */ require 'views/View.php'; -require 'models/TodoGateway.php'; -class GetTodosDropdown extends View { +class GetTodosDropdown extends View +{ var $categories; - function dispatch() { + function dispatch() + { $this->tpl->set_file('todosDropdown', 'TodosDropdown.tpl'); $this->tpl->set_block('todosDropdown', 'todosList_block', 'todosList'); $this->tpl->set_block('todosList_block', 'todoItem_block', 'todoItem'); @@ -30,7 +31,7 @@ $todoGateway = new TodoGateway; $thereAreTodos = false; $firstIteration = true; - foreach ($todoGateway->getTodos($this->user->getId()) as $todo) { + foreach ($todoGateway->getTodos($this->user->id) as $todo) { $thereAreTodos = true; $this->tpl->set_var(array( 'todoId' => $todo->getId(), @@ -68,7 +69,7 @@ if ($todo->getStatus() == TODO_STATUS_PENDING) { $this->tpl->set_var('textDecoration', ''); - if ($todo->getUserId() == $this->user->getId()) { + if ($todo->getUserId() == $this->user->id) { $this->tpl->parse('checkTodo', 'checkTodo_block'); } else { $this->tpl->set_var('checkTodo', ''); @@ -78,7 +79,7 @@ $this->tpl->set_var('checkTodo', ''); } - if ($todo->getUserId() != $this->user->getId()) { + if ($todo->getUserId() != $this->user->id) { $this->tpl->set_var('linkTodo1', ''); $this->tpl->set_var('linkTodo2', ''); } else { @@ -101,7 +102,8 @@ $this->tpl->pparse('out', 'todosDropdown'); } - function _filterContent($content) { + function _filterContent($content) + { $content = nl2br($content); $content = str_replace(array("\n", "\r"), array('', ''), $content); $content = addslashes($content); @@ -109,5 +111,3 @@ return $content; } } - -?> Modified: trunk/views/MainView.php =================================================================== --- trunk/views/MainView.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/MainView.php 2008-08-28 20:52:12 UTC (rev 660) @@ -14,10 +14,12 @@ require 'models/QuestionGateway.php'; require 'models/FavoriteGateway.php'; -class MainView extends View { +class MainView extends View +{ var $categories; - function dispatch() { + function dispatch() + { if (isset($_GET['catId'])) { $catId = (int)$_GET['catId']; } else { @@ -71,7 +73,7 @@ if ($catId != 0) { $favoriteGateway = new FavoriteGateway; - if ($favoriteGateway->isLocationFavorite($_GET['catId'], $this->user->getId())) { + if ($favoriteGateway->isLocationFavorite($_GET['catId'], $this->user->id)) { $this->tpl->set_var(array( 'favoriteLocationStarImgDisplay' => 'none', 'unFavoriteLocationStarImgDisplay' => 'inline', @@ -289,5 +291,3 @@ $this->tpl->pparse('out', 'main'); } } - -?> Modified: trunk/views/ManageArticles.php =================================================================== --- trunk/views/ManageArticles.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/ManageArticles.php 2008-08-28 20:52:12 UTC (rev 660) @@ -12,9 +12,10 @@ require 'views/View.php'; -class ManageArticles extends View { - - function dispatch() { +class ManageArticles extends View +{ + function dispatch() + { if (!isset($_GET['selectArticles']) || $_GET['selectArticles'] != 1) { $this->_showHeader(); } @@ -205,7 +206,9 @@ } $this->tpl->pparse('out', 'manageArticles'); + + if (!isset($_GET['selectArticles']) || $_GET['selectArticles'] != 1) { + $this->showFooter(); + } } } - -?> Modified: trunk/views/ManageUsers.php =================================================================== --- trunk/views/ManageUsers.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/ManageUsers.php 2008-08-28 20:52:12 UTC (rev 660) @@ -10,11 +10,11 @@ */ require 'views/View.php'; -require 'models/UserGateway.php'; -class ManageUsers extends view { - - function dispatch() { +class ManageUsers extends view +{ + function dispatch() + { $this->tpl->set_file('manageUsers', 'ManageUsers.tpl'); $this->tpl->set_block('manageUsers', 'usersBlock', 'users'); $this->tpl->set_block('usersBlock', 'delete_block', 'delete'); @@ -23,22 +23,22 @@ 'AddUserLink' => Library::getLink(array('view' => 'EditUser')), )); - $userGateway = new UserGateway; - $users = $userGateway->getUsersList(); + $users= new Users(); + $users = $users->getUsersList(); $firstIteration = true; $rowClass = 'row_off'; foreach ($users as $user) { $this->tpl->set_var(array( - 'editUserLink' => Library::getLink(array('view' => 'EditUser', 'userId' => $user->getId())), + 'editUserLink' => Library::getLink(array('view' => 'EditUser', 'userId' => $user->id)), 'rowClass' => $rowClass, 'name' => $user->getFullName(), 'nameSlashed' => addslashes($user->getFullName()), - 'userId' => $user->getId(), - 'userName' => $user->getUserName(), - 'email' => $user->getEmail(), - 'adminRights' => $user->getRole() == User::ROLE_ADMIN? $this->user->lang('Yes') : $this->user->lang('No'), + 'userId' => $user->id, + 'userName' => $user->username, + 'email' => $user->email, + 'adminRights' => $user->isAdmin()? $this->user->lang('Yes') : $this->user->lang('No'), )); - if ($user->getId() != 1) { + if ($user->id != 1) { $this->tpl->parse('delete', 'delete_block'); } else { $this->tpl->set_var('delete', ''); @@ -51,5 +51,3 @@ $this->tpl->pparse('out', 'manageUsers'); } } - -?> Modified: trunk/views/SearchResults.php =================================================================== --- trunk/views/SearchResults.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/SearchResults.php 2008-08-28 20:52:12 UTC (rev 660) @@ -9,14 +9,11 @@ * @packager Keyboard Monkeys */ -require 'views/View.php'; -require 'models/CategoryGateway.php'; -require 'models/FavoriteGateway.php'; +class SearchResults extends View +{ + function dispatch() + { -class SearchResults extends View { - - function dispatch() { - $this->tpl->set_var('checked_all', (!isset($_GET['set']) || $_GET['set'] == 'all')? 'checked="true"' : ''); $this->tpl->set_var('checked_articles', (isset($_GET['set']) && $_GET['set'] == 'articles')? 'checked="true"' : ''); $this->tpl->set_var('checked_bookmarks', (isset($_GET['set']) && $_GET['set'] == 'bookmarks')? 'checked="true"' : ''); @@ -27,7 +24,7 @@ $this->tpl->set_block('searchResults', 'numResults_block', 'numResults'); $favoriteGateway = new FavoriteGateway; - if (!isset($_GET['advancedSearch']) && $favoriteGateway->isSearchResultFavorite($_GET['query'], $this->user->getId())) { + if (!isset($_GET['advancedSearch']) && $favoriteGateway->isSearchResultFavorite($_GET['query'], $this->user->id)) { $this->tpl->set_var(array( 'favoriteSearchResultsStarImgDisplay' => 'none', 'unFavoriteSearchResultsStarImgDisplay' => 'inline', @@ -136,5 +133,3 @@ $this->tpl->pparse('out', 'searchResults'); } } - -?> Modified: trunk/views/View.php =================================================================== --- trunk/views/View.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/View.php 2008-08-28 20:52:12 UTC (rev 660) @@ -139,7 +139,7 @@ $this->tpl->set_block('header', 'editProfileLink_block', 'editProfileLink'); if (!$this->user->isAnonymous() && !$this->user->isAdmin()) { - $this->tpl->set_var('editProfileHref', Library::getLink(array('view' => 'EditUser', 'userId' => $this->user->getId()))); + $this->tpl->set_var('editProfileHref', Library::getLink(array('view' => 'EditUser', 'userId' => $this->user->id))); $this->tpl->parse('editProfileLink', 'editProfileLink_block'); } else { $this->tpl->set_var('editProfileLink', ''); Modified: trunk/views/ViewArticle.php =================================================================== --- trunk/views/ViewArticle.php 2008-08-28 20:50:05 UTC (rev 659) +++ trunk/views/ViewArticle.php 2008-08-28 20:52:12 UTC (rev 660) @@ -16,11 +16,13 @@ require 'views/ViewRelatedArticles.php'; require 'views/ViewComments.php'; -class ViewArticle extends View { +class ViewArticle extends View +{ var $article; - function preDispatch() { + function preDispatch() + { $thi... [truncated message content] |