From: <al...@us...> - 2008-07-09 22:10:29
|
Revision: 608 http://sciret.svn.sourceforge.net/sciret/?rev=608&view=rev Author: alpeb Date: 2008-07-09 15:10:27 -0700 (Wed, 09 Jul 2008) Log Message: ----------- merged https://sciret.svn.sourceforge.net/svnroot/sciret/branches/release-candidates/sciret-1.2 -r 594:HEAD back into the trunk. Please no more unstable commits to the stable branch Modified Paths: -------------- trunk/actions/DeleteArticle.php trunk/actions/Install.php trunk/actions/Login.php trunk/actions/Logout.php trunk/actions/SaveArticle.php trunk/actions/SavePreferences.php trunk/classes/Controller.php trunk/classes/DB.php trunk/classes/MysqlResult.php trunk/flowMap.php trunk/index.php trunk/models/Article.php trunk/models/ArticleGateway.php trunk/models/ArticleIterator.php trunk/models/Category.php trunk/models/CategoryGateway.php trunk/models/Comment.php trunk/models/Configuration.php trunk/models/Favorite.php trunk/models/FavoriteGateway.php trunk/models/File.php trunk/models/History.php trunk/models/HistoryGateway.php trunk/models/Link.php trunk/models/Question.php trunk/models/QuestionGateway.php trunk/models/QuestionIterator.php trunk/models/Todo.php trunk/models/TodoGateway.php trunk/models/User.php trunk/models/UserGateway.php trunk/setup/final.sql trunk/views/EditArticle.php trunk/views/EditPreferences.php trunk/views/ManageUsers.php trunk/views/ViewArticle.php Added Paths: ----------- trunk/config.ini trunk/libs/ trunk/setup/upgrade_1.3.0.sql Removed Paths: ------------- trunk/config.php trunk/models/Model.php Modified: trunk/actions/DeleteArticle.php =================================================================== --- trunk/actions/DeleteArticle.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/DeleteArticle.php 2008-07-09 22:10:27 UTC (rev 608) @@ -20,7 +20,7 @@ if ($this->configuration->getConfigValue('restrictEditDelete')) { $article = new Article($artId); - if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & ROLE_ADMIN) != ROLE_ADMIN) { + if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & 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))); } Modified: trunk/actions/Install.php =================================================================== --- trunk/actions/Install.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/Install.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,8 +9,6 @@ * @packager TheGang */ -require 'actions/Action.php'; - class Install extends Action { var $db; Modified: trunk/actions/Login.php =================================================================== --- trunk/actions/Login.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/Login.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,20 +9,23 @@ * @packager TheGang */ -require 'actions/Action.php'; - class Login extends Action { function dispatch() { - require 'models/UserGateway.php'; - $userGateway = new UserGateway; - if (!$user = $userGateway->getValidatedUser($_POST['username'], $_POST['password'], $this->configuration)) { + $auth = Zend_Auth::getInstance(); + $db = Zend_Db::factory(Zend_Registry::get('config')->database); + $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password', 'MD5(?)'); + $authAdapter->setIdentity($_POST['username']) + ->setCredential($_POST['password']); + $result = $auth->authenticate($authAdapter); + if ($result->isValid()) { + $user = UserGateway::getValidatedUser($_POST['username'], $_POST['password'], $this->configuration); + $auth->getStorage()->write($user); + } else { $_SESSION['message'] = $this->user->lang('Wrong Username or Password'); Library::redirect(Library::getLink(array('view' => 'Login'))); } - $_SESSION['userId'] = $user->getId(); - 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()))); Modified: trunk/actions/Logout.php =================================================================== --- trunk/actions/Logout.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/Logout.php 2008-07-09 22:10:27 UTC (rev 608) @@ -14,7 +14,7 @@ class Logout extends Action { function dispatch() { - session_destroy(); + Zend_Auth::getInstance()->clearIdentity(); Library::Redirect(Library::getLink(array('view' => 'MainView'))); } } Modified: trunk/actions/SaveArticle.php =================================================================== --- trunk/actions/SaveArticle.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/SaveArticle.php 2008-07-09 22:10:27 UTC (rev 608) @@ -20,7 +20,7 @@ if ($articleId > 0 && $this->configuration->getConfigValue('restrictEditDelete')) { $article = new Article($articleId); - if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & ROLE_ADMIN) != ROLE_ADMIN) { + if ($article->getUserId() != $this->user->getId() && ($this->user->getRole() & 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))); } Modified: trunk/actions/SavePreferences.php =================================================================== --- trunk/actions/SavePreferences.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/actions/SavePreferences.php 2008-07-09 22:10:27 UTC (rev 608) @@ -32,7 +32,7 @@ $this->user->setPreference('navigationType', $_POST['navigationType']); } - if (($this->user->getRole() & ROLE_ADMIN) == ROLE_ADMIN) { + if (($this->user->getRole() & User::ROLE_ADMIN) == User::ROLE_ADMIN) { $this->configuration->setConfigValue('publishKB', $_POST['publishKB'] == '1'? '1' : '0'); $this->configuration->setConfigValue('publishArticlesAuto', $_POST['publishArticlesAuto'] == '1'? '1' : '0'); $this->configuration->setConfigValue('publishBookmarksAuto', $_POST['publishBookmarksAuto'] == '1'? '1' : '0'); Modified: trunk/classes/Controller.php =================================================================== --- trunk/classes/Controller.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/classes/Controller.php 2008-07-09 22:10:27 UTC (rev 608) @@ -59,7 +59,7 @@ (($this->user->getRole() & $this->views[$view][MINIMUM_ROLE]) != $this->views[$view][MINIMUM_ROLE]) // or user is anonymous and KB is not public - || ($this->user->getRole() == ROLE_ANONYMOUS && $this->views[$view][ALLOW_VIEW_ONLY_IF_PUBLIC_KB] && !$this->configuration->getConfigValue('publishKB')) + || ($this->user->getRole() == User::ROLE_ANONYMOUS && $this->views[$view][ALLOW_VIEW_ONLY_IF_PUBLIC_KB] && !$this->configuration->getConfigValue('publishKB')) ) { Library::redirect(Library::getLink(array('view' => 'Login'))); Modified: trunk/classes/DB.php =================================================================== --- trunk/classes/DB.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/classes/DB.php 2008-07-09 22:10:27 UTC (rev 608) @@ -1,40 +1,20 @@ <?php -/* -* @copyright Copyright (C) 2005-2007 TheGang http://www.the-gang.net -* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License -* @author Alejandro Pedraza -* @since Sciret 1.0 -* @package Sciret -* @packager TheGang -*/ - class DB { - // singleton PHP 4 hack - function DB($calledFromConnect = false) - { - if (!$calledFromConnect) { - trigger_error('Cannot instantiate class DB directly', E_USER_ERROR); - } - } + private static $instance; + + private static $skipFatalError = false; - // Database factory - // @access static - function &DBFactory($dbEngine, $dbHost, $dbUser, $dbPassword, $reconnect = false) { - static $db; + private function __construct() {} - $dbEngine = strtolower($dbEngine); + public static function setDBInstance($dbInstance) { + self::$instance =& $dbInstance; + } - if (!is_object($db) || $reconnect) { - switch ($dbEngine) { - default: - require_once 'classes/Mysql.php'; - $db = new MySQL($dbHost, $dbUser, $dbPassword); - } - } - - return $db; + public static function getInstance() + { + return self::$instance; } } Modified: trunk/classes/MysqlResult.php =================================================================== --- trunk/classes/MysqlResult.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/classes/MysqlResult.php 2008-07-09 22:10:27 UTC (rev 608) @@ -37,17 +37,16 @@ return mysql_num_rows($this->query); } + function rowCount() { + return $this->getNumRows(); + } + // @access public function getAffectedRows() { return mysql_affected_rows($this->mysql->dbConn); } // @access public - function getInsertId() { - return mysql_insert_id($this->mysql->dbConn); - } - - // @access public function getNumFields() { return mysql_num_fields($this->query); } Copied: trunk/config.ini (from rev 607, branches/release-candidates/sciret-1.2/config.ini) =================================================================== --- trunk/config.ini (rev 0) +++ trunk/config.ini 2008-07-09 22:10:27 UTC (rev 608) @@ -0,0 +1,10 @@ +[general] +slowdown_secs = 0 +language_default = "English" + +[database] +adapter = pdo_mysql +params.host = localhost +params.dbname = monkeys +params.username = root +params.password = Deleted: trunk/config.php =================================================================== --- trunk/config.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/config.php 2008-07-09 22:10:27 UTC (rev 608) @@ -1,14 +0,0 @@ -<?php - -define('DB_ENGINE', 'mysql'); -define('DB_HOST', 'localhost'); -define('DB_NAME', 'sciret'); -define('DB_USER', 'root'); -define('DB_PASSWORD', ''); - -define('LANGUAGE_DEFAULT', 'English'); - -// set to > 0 to simulate latency -define('SLOWDOWN_SECS', 0); - -?> \ No newline at end of file Modified: trunk/flowMap.php =================================================================== --- trunk/flowMap.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/flowMap.php 2008-07-09 22:10:27 UTC (rev 608) @@ -11,78 +11,78 @@ define('VIEW_DEFAULT', 'MainView'); -// ClassName => array(minimumRole, loadConfiguration, showHeader, allowOnlyIfPublicKB(for ROLE_ANONYMOUS)?) +// ClassName => array(minimumRole, loadConfiguration, showHeader, allowOnlyIfPublicKB(for User::ROLE_ANONYMOUS)?) $views = array( - 'NotInstalled' => array(ROLE_ANONYMOUS, false, false, false), - 'InstallEnterCredentials' => array(ROLE_ANONYMOUS, false, false, false), - 'InstallOk' => array(ROLE_ANONYMOUS, true, false, false), - 'Login' => array(ROLE_ANONYMOUS, true, true, false), - 'MainView' => array(ROLE_ANONYMOUS, true, true, true), - 'EditArticle' => array(ROLE_REGISTERED, true, true), - 'EditBookmark' => array(ROLE_REGISTERED, true, true), - 'ViewArticle' => array(ROLE_ANONYMOUS, true, true, true), - 'ViewBookmark' => array(ROLE_ANONYMOUS, true, true, true), - 'ManageUsers' => array(ROLE_ADMIN, true, true), - 'EditUser' => array(ROLE_REGISTERED, true, true), - 'AddQuestion' => array(ROLE_ANONYMOUS, true, true, true), - 'EditCategories' => array(ROLE_ANONYMOUS, true, true, true), - 'EditCategory' => array(ROLE_ADMIN, true, true), - 'EditPreferences' => array(ROLE_ANONYMOUS, true, true, true), - 'ManageArticles' => array(ROLE_REGISTERED, true, false), - 'ManageQuestions' => array(ROLE_REGISTERED, true, true), - 'SearchResults' => array(ROLE_ANONYMOUS, true, true, true), - 'AdvancedSearch' => array(ROLE_ANONYMOUS, true, true, true), - 'PrinterView' => array(ROLE_ANONYMOUS, true, false, true), - 'MailArticle' => array(ROLE_ANONYMOUS, true, true, true), - 'ViewComments' => array(ROLE_ANONYMOUS, true, false, true), - 'ViewBookmarkDetails' => array(ROLE_ANONYMOUS, true, false, true), - 'ViewRelatedArticles' => array(ROLE_ANONYMOUS, true, false, true), - 'GetFavoritesDropdown' => array(ROLE_REGISTERED, true, false), - 'GetTodosDropdown' => array(ROLE_REGISTERED, true, false), - 'EditTodo' => array(ROLE_REGISTERED, true, false), - 'Upgrade' => array(ROLE_ANONYMOUS, true, true, false), - 'UpgradeOk' => array(ROLE_ANONYMOUS, true, true, false), + 'NotInstalled' => array(User::ROLE_ANONYMOUS, false, false, false), + 'InstallEnterCredentials' => array(User::ROLE_ANONYMOUS, false, false, false), + 'InstallOk' => array(User::ROLE_ANONYMOUS, true, false, false), + 'Login' => array(User::ROLE_ANONYMOUS, true, true, false), + 'MainView' => array(User::ROLE_ANONYMOUS, true, true, true), + 'EditArticle' => array(User::ROLE_REGISTERED, true, true), + 'EditBookmark' => array(User::ROLE_REGISTERED, true, true), + 'ViewArticle' => array(User::ROLE_ANONYMOUS, true, true, true), + 'ViewBookmark' => array(User::ROLE_ANONYMOUS, true, true, true), + 'ManageUsers' => array(User::ROLE_ADMIN, true, true), + 'EditUser' => array(User::ROLE_REGISTERED, true, true), + 'AddQuestion' => array(User::ROLE_ANONYMOUS, true, true, true), + 'EditCategories' => array(User::ROLE_ANONYMOUS, true, true, true), + 'EditCategory' => array(User::ROLE_ADMIN, true, true), + 'EditPreferences' => array(User::ROLE_ANONYMOUS, true, true, true), + 'ManageArticles' => array(User::ROLE_REGISTERED, true, false), + 'ManageQuestions' => array(User::ROLE_REGISTERED, true, true), + 'SearchResults' => array(User::ROLE_ANONYMOUS, true, true, true), + 'AdvancedSearch' => array(User::ROLE_ANONYMOUS, true, true, true), + 'PrinterView' => array(User::ROLE_ANONYMOUS, true, false, true), + 'MailArticle' => array(User::ROLE_ANONYMOUS, true, true, true), + 'ViewComments' => array(User::ROLE_ANONYMOUS, true, false, true), + 'ViewBookmarkDetails' => array(User::ROLE_ANONYMOUS, true, false, true), + 'ViewRelatedArticles' => array(User::ROLE_ANONYMOUS, true, false, true), + 'GetFavoritesDropdown' => array(User::ROLE_REGISTERED, true, false), + 'GetTodosDropdown' => array(User::ROLE_REGISTERED, true, false), + 'EditTodo' => array(User::ROLE_REGISTERED, true, false), + 'Upgrade' => array(User::ROLE_ANONYMOUS, true, true, false), + 'UpgradeOk' => array(User::ROLE_ANONYMOUS, true, true, false), ); -// ClassName => array(minimumRole, loadConfiguration, allowOnlyIfPublicKB(for ROLE_ANONYMOUS)?) +// ClassName => array(minimumRole, loadConfiguration, allowOnlyIfPublicKB(for User::ROLE_ANONYMOUS)?) $actions = array( - 'Install' => array(ROLE_ANONYMOUS, false, false), - 'Login' => array(ROLE_ANONYMOUS, true, false), - 'Logout' => array(ROLE_REGISTERED, true), - 'SaveArticle' => array(ROLE_REGISTERED, true), - 'SaveBookmark' => array(ROLE_REGISTERED, true), - 'UploadFile' => array(ROLE_REGISTERED, true), - 'GetFile' => array(ROLE_ANONYMOUS, true, true), - 'DeleteFile' => array(ROLE_REGISTERED, true), - 'AddLink' => array(ROLE_REGISTERED, true), - 'DeleteLink' => array(ROLE_REGISTERED, true), - 'AddCommentAndRating' => array(ROLE_ANONYMOUS, true, true), - 'DeleteComment' => array(ROLE_REGISTERED, true), - 'PublishComment' => array(ROLE_REGISTERED, true), - 'EditUser' => array(ROLE_REGISTERED, true), - 'DeleteUser' => array(ROLE_ADMIN, true), - 'AddQuestion' => array(ROLE_ANONYMOUS, true, true), - 'SaveCategory' => array(ROLE_ADMIN, true), - 'DeleteCategory' => array(ROLE_ADMIN, true), - 'SavePreferences' => array(ROLE_ANONYMOUS, true, true), - 'DeleteArticle' => array(ROLE_REGISTERED, true), - 'PublishArticle' => array(ROLE_REGISTERED, true), - 'PublishQuestion' => array(ROLE_REGISTERED, true), - 'AddRelatedArticles' => array(ROLE_REGISTERED, true), - 'DeleteRelatedArticle' => array(ROLE_REGISTERED, true), - 'MailArticle' => array(ROLE_ANONYMOUS, true, true), - 'ArticleToPdf' => array(ROLE_ANONYMOUS, true, true), - 'DeleteQuestion' => array(ROLE_REGISTERED, true), - 'MarkArticle' => array(ROLE_REGISTERED, true), - 'MarkSearchResults' => array(ROLE_REGISTERED, true), - 'MarkLocation' => array(ROLE_REGISTERED, true), - 'SaveTodo' => array(ROLE_REGISTERED, true), - 'CompleteTodo' => array(ROLE_REGISTERED, true), - 'DeleteTodo' => array(ROLE_REGISTERED, true), - 'MarkArticleFinal' => array(ROLE_REGISTERED, true), - 'Upgrade' => array(ROLE_ANONYMOUS, true, false), - 'HideCategory' => array(ROLE_ANONYMOUS, true, true), - 'ShowCategory' => array(ROLE_ANONYMOUS, true, true), + 'Install' => array(User::ROLE_ANONYMOUS, false, false), + 'Login' => array(User::ROLE_ANONYMOUS, true, false), + 'Logout' => array(User::ROLE_REGISTERED, true), + 'SaveArticle' => array(User::ROLE_REGISTERED, true), + 'SaveBookmark' => array(User::ROLE_REGISTERED, true), + 'UploadFile' => array(User::ROLE_REGISTERED, true), + 'GetFile' => array(User::ROLE_ANONYMOUS, true, true), + 'DeleteFile' => array(User::ROLE_REGISTERED, true), + 'AddLink' => array(User::ROLE_REGISTERED, true), + 'DeleteLink' => array(User::ROLE_REGISTERED, true), + 'AddCommentAndRating' => array(User::ROLE_ANONYMOUS, true, true), + 'DeleteComment' => array(User::ROLE_REGISTERED, true), + 'PublishComment' => array(User::ROLE_REGISTERED, true), + 'EditUser' => array(User::ROLE_REGISTERED, true), + 'DeleteUser' => array(User::ROLE_ADMIN, true), + 'AddQuestion' => array(User::ROLE_ANONYMOUS, true, true), + 'SaveCategory' => array(User::ROLE_ADMIN, true), + 'DeleteCategory' => array(User::ROLE_ADMIN, true), + 'SavePreferences' => array(User::ROLE_ANONYMOUS, true, true), + 'DeleteArticle' => array(User::ROLE_REGISTERED, true), + 'PublishArticle' => array(User::ROLE_REGISTERED, true), + 'PublishQuestion' => array(User::ROLE_REGISTERED, true), + 'AddRelatedArticles' => array(User::ROLE_REGISTERED, true), + 'DeleteRelatedArticle' => array(User::ROLE_REGISTERED, true), + 'MailArticle' => array(User::ROLE_ANONYMOUS, true, true), + 'ArticleToPdf' => array(User::ROLE_ANONYMOUS, true, true), + 'DeleteQuestion' => array(User::ROLE_REGISTERED, true), + 'MarkArticle' => array(User::ROLE_REGISTERED, true), + 'MarkSearchResults' => array(User::ROLE_REGISTERED, true), + 'MarkLocation' => array(User::ROLE_REGISTERED, true), + 'SaveTodo' => array(User::ROLE_REGISTERED, true), + 'CompleteTodo' => array(User::ROLE_REGISTERED, true), + 'DeleteTodo' => array(User::ROLE_REGISTERED, true), + 'MarkArticleFinal' => array(User::ROLE_REGISTERED, true), + 'Upgrade' => array(User::ROLE_ANONYMOUS, true, false), + 'HideCategory' => array(User::ROLE_ANONYMOUS, true, true), + 'ShowCategory' => array(User::ROLE_ANONYMOUS, true, true), ); ?> Modified: trunk/index.php =================================================================== --- trunk/index.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/index.php 2008-07-09 22:10:27 UTC (rev 608) @@ -13,14 +13,25 @@ error_reporting(E_ALL); ini_set('display_errors', 1); +$pathList = array( + get_include_path(), + dirname(__FILE__), + dirname(__FILE__).'/libs', + dirname(__FILE__).'/classes', + dirname(__FILE__).'/models', + dirname(__FILE__).'/modules/default/models', + dirname(__FILE__).'/modules/blog/models', + dirname(__FILE__).'/actions', +); +set_include_path(implode(PATH_SEPARATOR, $pathList)); +require_once 'Zend/Loader.php'; + $times = explode(' ', microtime()); $GLOBALS['startTime'] = $times[0] + $times[1]; -require 'classes/Library.php'; -require 'classes/DB.php'; -require 'models/User.php'; -require 'classes/Controller.php'; -require 'config.php'; +$config = new Zend_Config_Ini(dirname(__FILE__). '/config.ini', null, array('allowModifications' => true)); +Zend_Registry::set('config', $config); + require 'flowMap.php'; // MAGIC_QUOTES HANDLING @@ -32,22 +43,45 @@ } set_magic_quotes_runtime(0); -$db =& DB::DBFactory(DB_ENGINE, DB_HOST, DB_USER, DB_PASSWORD); +/************************** +* DATABASE +/**************************/ +$config->database->params->driver_options = array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true); +$db = Zend_Db::factory($config->database); +$connectionFailed = false; +try { + $db->getConnection(); +} catch (Zend_Db_Adapter_Exception $e) { + $connectionFailed = true; +} +DB::setDBInstance($db); + if ((!in_array(@$_GET['action'], array('Install'))) && !in_array(@$_GET['view'], array('ConfigNotWritable', 'InstallEnterCredentials')) - && (DB_NAME == '' || !$db->connect() || !$db->selectDb(DB_NAME) || !$db->hasTables())) + && ($config->database->params->dbname == '' || $connectionFailed)) { $_GET['view'] = 'NotInstalled'; } -session_start(); -if (isset($_SESSION['userId'])) { - $user = new User($_SESSION['userId']); +Zend_Session::start(); +$auth = Zend_Auth::getInstance(); +if ($auth->hasIdentity()) { + $user = $auth->getStorage()->read(); + $user->init(); + if ($user->app == 'monkeys') { + $publicId = $user->publicId; + $user = new User($publicId); + $user->app = 'sciret'; + $auth->getStorage()->write($user); + } } else { - $user = new User; + // guest user + $user = new User(); } +Zend_Registry::set('user', $user); + $controller = new Controller($views, $actions, $user); if (isset($_GET['view'])) { @@ -58,4 +92,13 @@ $controller->processView(VIEW_DEFAULT); } + +/************************** +* AUTOLOADING FUNCTION +**************************/ +function __autoload($className) { + Zend_Loader::loadClass($className); +} + + ?> Copied: trunk/libs (from rev 607, branches/release-candidates/sciret-1.2/libs) Property changes on: trunk/libs ___________________________________________________________________ Name: svn:externals + Zend http://framework.zend.com/svn/framework/standard/tags/release-1.5.2/library/Zend Modified: trunk/models/Article.php =================================================================== --- trunk/models/Article.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Article.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,23 +9,20 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Article extends Model { +class Article { var $id; var $isBookmark = 0; var $questionId; var $catId; var $catLabel; var $title; - var $URL; + var $URL = ''; var $expDate; - var $question; + var $question = ''; var $content; var $excerpt; var $published = 1; var $draft = 0; - var $user; var $userId; var $views = 0; var $creationDate; @@ -44,15 +41,15 @@ var $votes5 = 0; var $internal = 0; + private $user; + function Article($id = false) { - parent::Model(); - if ($id) { // left join because cat_id=0 doesn't exist in the db $query = 'SELECT is_bookmark, title, url, expires, question, content, art.cat_id, cat.name AS catLabel, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, internal ' .'FROM articles art LEFT JOIN categories cat ON cat.cat_id=art.cat_id ' .'WHERE art_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->isBookmark = $row['is_bookmark']; @@ -81,13 +78,73 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO articles (is_bookmark, title, url, expires, question, content, cat_id, published, draft, user_id, views, internal, created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())'; - $result = $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->question, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->internal); - $this->id = $result->getInsertId(); + $result = $db->query( $query, array( + $this->isBookmark, + $this->title, + $this->URL, + $this->expDate, + $this->question, + $this->content, + $this->catId, + $this->published, + $this->draft, + $this->userId, + $this->views, + $this->internal + ) + ); + $this->id = $db->lastInsertId(); } else { - $query = 'UPDATE articles SET is_bookmark=?, title=?, url=?, expires=?, question=?, content=?, cat_id=?, published=?, draft=?, user_id=?, views=?, created=?, modified=?, modified_user_id=?, votes_1=?, votes_2=?, votes_3=?, votes_4=?, votes_5=?, internal=? WHERE art_id=?'; - $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->question, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->creationDate, $this->modificationDate, $this->modifiedByUserId, $this->votes1, $this->votes2, $this->votes3, $this->votes4, $this->votes5, $this->internal, $this->id); + $query = 'UPDATE articles SET ' + .'is_bookmark=?, ' + .'title=?, ' + .'url=?, ' + .'expires=?, ' + .'question=?, ' + .'content=?, ' + .'cat_id=?, ' + .'published=?, ' + .'draft=?, ' + .'user_id=?, ' + .'views=?, ' + .'created=?, ' + .'modified=?, ' + .'modified_user_id=?, ' + .'votes_1=?, ' + .'votes_2=?, ' + .'votes_3=?, ' + .'votes_4=?, ' + .'votes_5=?, ' + .'internal=? ' + .'WHERE art_id=?'; + DB::getInstance()->query( $query, + array( + $this->isBookmark, + $this->title, + $this->URL, + $this->expDate, + $this->question, + $this->content, + $this->catId, + $this->published, + $this->draft, + $this->userId, + $this->views, + $this->creationDate, + $this->modificationDate, + $this->modifiedByUserId, + $this->votes1, + $this->votes2, + $this->votes3, + $this->votes4, + $this->votes5, + $this->internal, + $this->id + ) + ); } } @@ -213,6 +270,11 @@ $this->views = (int)$views; } + public function getFormatedCreationDate() { + preg_match('/(\d\d\d\d)-(\d\d)-(\d\d)/', $this->getCreationDate(), $matches); + return $matches[2].'/'.$matches[3].'/'.$matches[1]; + } + function getCreationDate() { return $this->creationDate; } @@ -244,11 +306,15 @@ } function getUser() { + if (!isset($this->user)) { + $this->user = new User($this->getUserId()); + } + return $this->user; } - function setUser($userObj) { - $this->user = $userObj; + function setUser(&$userObj) { + $this->user =& $userObj; } function getModificationDate() { @@ -348,7 +414,7 @@ if (!isset($this->files)) { $query = 'SELECT file_id, art_id, filename, comment, hash FROM files WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->files = array(); while ($row = $result->fetch()) { $file = new File; @@ -377,7 +443,7 @@ if (!isset($this->links)) { $query = 'SELECT link_id, art_id, title, url FROM links WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->links = array(); while ($row = $result->fetch()) { $link = new Link; @@ -395,7 +461,7 @@ function getRelatedArticles() { if (!isset($this->relatedArticles)) { $query = 'SELECT art_id, related_art_id FROM articles_related WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->relatedArticles = array(); while ($row = $result->fetch()) { $this->relatedArticles[] = new Article($row['related_art_id']); @@ -420,7 +486,7 @@ $this->getRelatedArticles(); $query = 'DELETE FROM articles_related WHERE art_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); foreach ($arrRelatedArticles as $relatedArtId) { $article = new Article; @@ -430,13 +496,13 @@ foreach ($this->relatedArticles as $article) { $query = 'INSERT INTO articles_related (art_id, related_art_id) VALUES (?, ?)'; - $this->db->query($query, $this->id, $article->getId()); + DB::getInstance()->query($query, $this->id, $article->getId()); } } function deleteRelatedArticle($artId) { $query = 'DELETE FROM articles_related WHERE art_id=? AND related_art_id=?'; - $this->db->query($query, $this->id, $artId); + DB::getInstance()->query($query, array($this->id, $artId)); } function getComments() { @@ -444,7 +510,7 @@ if (!isset($this->comments)) { $query = 'SELECT comment_id, username, contents, entered, published FROM comments WHERE art_id = ?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->comments = array(); while ($row = $result->fetch()) { $comment = new Comment; Modified: trunk/models/ArticleGateway.php =================================================================== --- trunk/models/ArticleGateway.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/ArticleGateway.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,31 +9,25 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Article.php'; -require_once 'models/ArticleIterator.php'; - define('EXCERPT_LENGTH', 300); -class ArticleGateway extends Model { +class ArticleGateway { - function getArticles( $catId, - $includeSubCats, - $specialList = false, - $includeUnpublished = false, - $onlyUnpublished = false, - $offset = 0, - $numRecords = -1, - $set = 'all', - $sort = false, - $showExpired = false, - $showDrafts = false) + public static function getArticles( $catId, + $includeSubCats, + $specialList = false, + $includeUnpublished = false, + $onlyUnpublished = false, + $offset = 0, + $numRecords = -1, + $set = 'all', + $sort = false, + $showExpired = false, + $showDrafts = false) { // uncomment for testing //$numRecords = 3; - require_once 'models/CategoryGateway.php'; - $catId = (int)$catId; $whereArr = array(); @@ -111,14 +105,15 @@ break; } - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); - list($totalNumItems) = $result2->fetch(); + $result2 = DB::getInstance()->query($query2); + $rows = $result2->fetch(); + $totalNumItems = $rows['FOUND_ROWS()']; } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -144,7 +139,7 @@ .'FROM articles art LEFT JOIN files f on art.art_id = f.art_id LEFT JOIN users u ON art.user_id = u.user_id ' ."WHERE $where " .'GROUP BY art.art_id'; - $result = $this->db->query($query, $searchQuery); + $result = DB::getInstance()->query($query, $searchQuery); } else { switch ($set) { case 'bookmarks': @@ -164,15 +159,16 @@ if ($numRecords != -1) { $query .= ' LIMIT ' . (int)$offset . ', ' . (int)$numRecords; } - $result = $this->db->query($query, $searchQuery, $searchQuery); + $result = DB::getInstance()->query($query, $searchQuery, $searchQuery); } if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); - list($totalNumItems) = $result2->fetch(); + $result2 = DB::getInstance()->query($query2); + $rows = $result2->fetch(); + $totalNumItems = $rows['FOUND_ROWS()']; } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -209,7 +205,7 @@ if ($allWords != '') { $wordList = explode(' ', $allWords); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -222,7 +218,7 @@ } if ($exactPhrase != '') { - $exactPhrase = $this->db->escape_string($exactPhrase); + $exactPhrase = DB::escape_string($exactPhrase); if ($ocurrences == 'title') { $whereArr[] = "title LIKE '%$exactPhrase%'"; } elseif ($ocurrences == 'content') { @@ -235,7 +231,7 @@ if ($oneWord != '') { $wordList = explode(' ', $oneWord); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -250,7 +246,7 @@ if ($excludeList != '') { $wordList = explode(' ', $excludeList); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title NOT LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -317,14 +313,14 @@ if ($numRecords != -1) { $query .= ' LIMIT ' . (int)$offset . ', ' . (int)$numRecords; } - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); + $result2 = DB::getInstance()->query($query2); list($totalNumItems) = $result2->fetch(); } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -337,26 +333,26 @@ } $query = 'DELETE FROM articles WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM articles_related WHERE art_id=? OR related_art_id=?'; - $this->db->query($query, $id, $id); + DB::getInstance()->query($query, array($id, $id)); $query = 'DELETE FROM comments WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM links WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM history WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); } function numUnpublishedArticles() { $query = "SELECT art_id FROM articles WHERE published = 0"; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); - return $result->getNumRows(); + return $result->rowCount(); } } Modified: trunk/models/ArticleIterator.php =================================================================== --- trunk/models/ArticleIterator.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/ArticleIterator.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Article.php'; - -class ArticleIterator extends Model { +class ArticleIterator { var $resultSet; var $totalNumItems; @@ -53,13 +50,6 @@ $article->setNumFiles($row['num_files']); } - if (isset($row['firstname'])) { - $tUser = new User; - $tUser->setFirstName($row['firstname']); - $tUser->setLastName($row['lastname']); - $article->setUser($tUser); - } - return $article; } Modified: trunk/models/Category.php =================================================================== --- trunk/models/Category.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Category.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Category extends Model { +class Category { var $id; var $label = ''; var $description = ''; @@ -20,11 +18,9 @@ var $iconFileName = ''; function Category($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT cat_id, name, description, parent_id, icon FROM categories WHERE cat_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->label = $row['name']; @@ -36,31 +32,32 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO categories (name, description, parent_id, icon) VALUES(?, ?, ?, ?)'; - $result = $this->db->query($query, $this->label, $this->description, $this->parentId, $this->iconFileName); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->label, $this->description, $this->parentId, $this->iconFileName)); + $this->id = $db->lastInsertId(); } else { $query = 'UPDATE categories SET name=?, description=?, parent_id=?, icon=? WHERE cat_id=?'; - $result = $this->db->query($query, $this->label, $this->description, $this->parentId, $this->iconFileName, $this->id); + $result = $db->query($query, array($this->label, $this->description, $this->parentId, $this->iconFileName, $this->id)); } } function delete() { $query = 'SELECT cat_id FROM categories WHERE parent_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); if ($result->getNumRows() > 0) { return false; } $query = 'DELETE FROM categories WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); $query = 'UPDATE articles SET cat_id=0 WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); $query = 'UPDATE questions SET cat_id=0 WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); return true; } Modified: trunk/models/CategoryGateway.php =================================================================== --- trunk/models/CategoryGateway.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/CategoryGateway.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Category.php'; - -class CategoryGateway extends Model { +class CategoryGateway { var $categories; function getCategories() { @@ -22,7 +19,7 @@ $this->categories[0] = new Category; $query = 'SELECT cat_id, name, description, parent_id, icon FROM categories ORDER BY parent_id, name'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); while ($row = $result->fetch()) { $this->categories[$row['cat_id']] = new Category; $this->categories[$row['cat_id']]->setId($row['cat_id']); Modified: trunk/models/Comment.php =================================================================== --- trunk/models/Comment.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Comment.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Comment extends Model { +class Comment { var $id; var $userName; var $entered; @@ -20,11 +18,9 @@ var $articleId; function Comment($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT username, contents, entered, art_id, published FROM comments WHERE comment_id=?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->userName = $row['username']; $this->contents = $row['contents']; @@ -37,19 +33,20 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO comments (username, contents, entered, art_id, published) VALUES(?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->userName, $this->contents, $this->entered, $this->articleId, $this->published); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userName, $this->contents, $this->entered, $this->articleId, $this->published)); + $this->id = $db->lastInsertId(); } else { $query = 'UPDATE comments SET username=?, contents=?, entered=?, art_id=?, published=? WHERE comment_id=?'; - $this->db->query($query, $this->userName, $this->contents, $this->entered, $this->articleId, $this->published, $this->id); + $db->query($query, array($this->userName, $this->contents, $this->entered, $this->articleId, $this->published, $this->id)); } } function delete() { $query = 'DELETE FROM comments WHERE comment_id = ?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); } function getId() { Modified: trunk/models/Configuration.php =================================================================== --- trunk/models/Configuration.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Configuration.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,10 +9,8 @@ * @packager TheGang */ -require_once 'models/Model.php'; +class Configuration { -class Configuration extends Model { - var $configurationArray = array( // var name => array(defaultValue, isHidden) 'publishKB' => 1, @@ -25,10 +23,8 @@ ); function Configuration() { - parent::Model(); - $query = 'SELECT field, value FROM configuration'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); while ($row = $result->fetch()) { $this->configurationArray[$row['field']] = $row['value']; } @@ -36,11 +32,11 @@ function save() { $query = 'DELETE FROM configuration'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); foreach ($this->configurationArray as $field => $value) { $query = 'INSERT INTO configuration (field, value) VALUES (?, ?)'; - $result = $this->db->query($query, $field, $value); + $result = DB::getInstance()->query($query, $field, $value); } } Modified: trunk/models/Favorite.php =================================================================== --- trunk/models/Favorite.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Favorite.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,13 +9,11 @@ * @packager TheGang */ -require_once 'models/Model.php'; - define('FAVORITE_TYPE_ARTICLE', 1); define('FAVORITE_TYPE_LOCATION', 2); define('FAVORITE_TYPE_SEARCHRESULT', 3); -class Favorite extends Model { +class Favorite { var $id; var $userId; var $type; @@ -24,11 +22,10 @@ var $searchStr = ''; function Favorite($id = false) { - parent::Model(); if ($id) { $query = 'SELECT favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE favorite_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->userId = $row['user_id']; @@ -42,9 +39,10 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO favorites (user_id, favorite_type, art_id, cat_id, search_str) VALUES (?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->userId, $this->type, $this->artId, $this->catId, $this->searchStr); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userId, $this->type, $this->artId, $this->catId, $this->searchStr)); + $this->id = $db->lastInsertId(); } } Modified: trunk/models/FavoriteGateway.php =================================================================== --- trunk/models/FavoriteGateway.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/FavoriteGateway.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Favorite.php'; - -class FavoriteGateway extends Model { +class FavoriteGateway { var $favorites; function getFavorites($userId) { @@ -20,7 +17,7 @@ $this->favorites = array(); $query = 'SELECT favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE user_id = ?'; - $result = $this->db->query($query, $userId); + $result = DB::getInstance()->query($query, $userId); while ($row = $result->fetch()) { $favorite = new Favorite; @@ -39,36 +36,36 @@ function isArticleFavorite($artId, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE art_id = ? AND user_id = ?'; - $result = $this->db->query($query, $artId, $userId); + $result = DB::getInstance()->query($query, array($artId, $userId)); - return ($result->getNumRows() > 0); + return ($result->rowCount() > 0); } function deleteArticleFavorite($artId, $userId) { $query = 'DELETE FROM favorites WHERE art_id = ? AND user_id = ?'; - $result = $this->db->query($query, $artId, $userId); + $result = DB::getInstance()->query($query, $artId, $userId); } function deleteSearchResultFavorite($queryStr, $userId) { $query = 'DELETE FROM favorites WHERE search_str = ? AND user_id = ?'; - $result = $this->db->query($query, $queryStr, $userId); + $result = DB::getInstance()->query($query, $queryStr, $userId); } function deleteLocationFavorite($catId, $userId) { $query = 'DELETE FROM favorites WHERE cat_id = ? AND user_id = ?'; - $result = $this->db->query($query, $catId, $userId); + $result = DB::getInstance()->query($query, $catId, $userId); } function isSearchResultFavorite($queryStr, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE search_str = ? AND user_id = ?'; - $result = $this->db->query($query, $queryStr, $userId); + $result = DB::getInstance()->query($query, $queryStr, $userId); return ($result->getNumRows() > 0); } function isLocationFavorite($catId, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE cat_id = ? AND user_id = ?'; - $result = $this->db->query($query, $catId, $userId); + $result = DB::getInstance()->query($query, $catId, $userId); return ($result->getNumRows() > 0); } Modified: trunk/models/File.php =================================================================== --- trunk/models/File.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/File.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class File extends Model { +class File { var $id; var $articleId; var $fileName; @@ -19,11 +17,10 @@ var $hash; function File($id = false) { - parent::Model(); if ($id) { $query = 'SELECT art_id, filename, comment, hash FROM files WHERE file_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::$instance->query($query, $id); if (!$row = $result->fetch()) { return; } @@ -38,15 +35,16 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO files (art_id, filename, comment, hash) VALUES (?, ?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->fileName, $this->comment, $this->hash); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->fileName, $this->comment, $this->hash)); + $this->id = $db->lastInsertId(); } } function delete() { $query = 'DELETE FROM files WHERE file_id=?'; - $this->db->query($query, $this->id); + DB::$instance->query($query, $this->id); return @unlink('uploads/files/'.$this->hash); } Modified: trunk/models/History.php =================================================================== --- trunk/models/History.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/History.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class History extends Model { +class History { var $id; var $articleId; var $date; @@ -19,15 +17,12 @@ var $action; var $actionArgs = ''; - function History() { - parent::Model(); - } - function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO history (art_id, date, user, action, action_args) VALUES (?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->date, $this->userFullName, $this->action, $this->actionArgs); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->date, $this->userFullName, $this->action, $this->actionArgs)); + $this->id = $db->lastInsertId(); } } Modified: trunk/models/HistoryGateway.php =================================================================== --- trunk/models/HistoryGateway.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/HistoryGateway.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,18 +9,11 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/History.php'; +class HistoryGateway { -class HistoryGateway extends Model { - - function HistoryGateway() { - parent::Model(); - } - function getEvents($articleId) { $query = 'SELECT history_id, art_id, date, user, action, action_args FROM history WHERE art_id=? ORDER BY date DESC'; - $result = $this->db->query($query, $articleId); + $result = DB::getInstance()->query($query, $articleId); $historyArr = array(); while ($row = $result->fetch()) { $history = new History; Modified: trunk/models/Link.php =================================================================== --- trunk/models/Link.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Link.php 2008-07-09 22:10:27 UTC (rev 608) @@ -9,20 +9,16 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Link extends Model { +class Link { var $id; var $articleId; var $title; var $URL; function Link($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT art_id, title, url FROM links WHERE link_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->articleId = $row['art_id']; @@ -34,15 +30,16 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO links (art_id, title, url) VALUES (?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->title, $this->URL); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->title, $this->URL)); + $this->id = $db->lastInsertId(); } } function delete() { $query = 'DELETE FROM links WHERE link_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); } function getId() { Deleted: trunk/models/Model.php =================================================================== --- trunk/models/Model.php 2008-07-09 21:43:26 UTC (rev 607) +++ trunk/models/Model.php 2008-07-09 22:10:27 UTC (rev 608) @@ -1,21 +0,0 @@ -<?php - -/* -* @copyright Copyright (C) 2005-2007 TheGang http://www.the-gang.net -* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License -* @author Alejandro Pedraza -* @since Sciret 1.0 -* @package Sciret -* @packager TheGang -*/ - -class Model { - - var $db; - - function Model() { - $this->db =& DB::DBFactory(DB_ENGINE, DB_HOST, DB_USER, DB_PASSWORD); - } -} - -?> Modified: trunk/models/Question.php =================================================================== --- trunk/models/Question.php 2008-07-09 21:43:26 UTC (rev 607... [truncated message content] |