[pLog-svn] r585 - plog/trunk
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Mon Dec 27 23:21:03 GMT 2004
Author: oscar
Date: 2004-12-27 23:21:02 +0000 (Mon, 27 Dec 2004)
New Revision: 585
Modified:
plog/trunk/wizard.php
Log:
updated the wizard
Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php 2004-12-27 23:17:52 UTC (rev 584)
+++ plog/trunk/wizard.php 2004-12-27 23:21:02 UTC (rev 585)
@@ -7,7 +7,7 @@
//
// enable this for debugging purposes
//
- define( "DB_WIZARD_DEBUG", true );
+ define( "DB_WIZARD_DEBUG", false );
// many hosts don't have this enabled and we, for the time being, need it...
ini_set("arg_seperator.output", "&");
@@ -20,6 +20,7 @@
include_once( PLOG_CLASS_PATH."class/database/adodb/adodb.inc.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
include_once( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/passwordvalidator.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
@@ -32,6 +33,7 @@
include_once( PLOG_CLASS_PATH."class/gallery/resizers/gddetector.class.php" );
include_once( PLOG_CLASS_PATH."class/config/configfilestorage.class.php" );
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ include_once( PLOG_CLASS_PATH."class/locale/locales.class.php" );
define( "TEMP_FOLDER", "./tmp" );
@@ -570,11 +572,36 @@
$config = new ConfigFileStorage();
return $config->getValue( "db_prefix" );
}
+
+ /**
+ * some useful little functions
+ */
+ class WizardTools extends Object
+ {
+ /**
+ * returns true if plog has already been installed before or
+ * false otherwise
+ */
+ function isNewInstallation()
+ {
+ $configFile = new ConfigFileStorage();
+ // if plog hasn't been installed, this file will have empty settings
+ if( $configFile->getValue( "db_host") == "" && $configFile->getValue( "db_username") == "" &&
+ $configFile->getValue( "db_database") == "" && $configFile->getValue( "db_prefix" ) == "" &&
+ $configFile->getValue( "db_password" ) == "" )
+ $isNew = true;
+ else
+ $isNew = false;
+
+ return( $isNew );
+ }
+ }
/**
* Renders a template file.
*/
- class WizardView extends View {
+ class WizardView extends View
+ {
var $_templateName;
@@ -595,9 +622,9 @@
$t->assign( $this->_params->getAsArray());
$t->template_dir = "./templates";
$t->compile_dir = TEMP_FOLDER;
- $t->cache_dir = TEMP_FOLDER;
+ $t->cache_dir = TEMP_FOLDER;
$t->use_sub_dirs = false;
- $t->caching = false;
+ $t->caching = false;
print $t->fetch( $templateFileName );
}
@@ -606,198 +633,169 @@
/**
* Gets the information about the database from the user.
*/
- class WizardIntro extends Action {
+ class WizardIntro extends Action
+ {
+ function WizardIntro( $actionInfo, $request )
+ {
+ $this->Action( $actionInfo, $request );
+ }
function perform()
{
- $this->_view = new WizardView( "intro" );
+ // we can detect whether plog is already installed or not and direct users to the right
+ // place
+ if( WizardTools::isNewInstallation())
+ $this->_view = new WizardView( "intro" );
+ else
+ $this->_view = new WizardView( "update1" );
+
+ $this->setCommonData();
}
}
/**
- * Represents the first step
+ *
+ * Saves data to the configuration file
+ *
*/
- class WizardStepOne extends Action {
+ class WizardStepOne extends Action
+ {
var $_dbServer;
var $_dbUser;
var $_dbPassword;
var $_dbName;
var $_dbPrefix;
+
+ function WizardStepOne( $actionInfo, $request )
+ {
+ $this->Action( $actionInfo, $request );
+
+ // data validation
+ $this->registerFieldValidator( "dbServer", new StringValidator());
+ $this->registerFieldValidator( "dbUser", new StringValidator());
+ $this->registerFieldValidator( "dbPassword", new StringValidator(), true );
+ $this->registerFieldValidator( "dbName", new StringValidator());
+ $this->registerFieldValidator( "dbPrefix", new StringValidator(), true );
+ $errorView = new WizardView( "intro" );
+ $errorView->setErrorMessage( "Some data was incorrect or missing." );
+ $this->setValidationErrorView( $errorView );
+ }
- function validate()
+ function perform()
{
+ // fetch the data needed from the request
$this->_dbServer = $this->_request->getValue( "dbServer" );
$this->_dbUser = $this->_request->getValue( "dbUser" );
$this->_dbPassword = $this->_request->getValue( "dbPassword" );
$this->_dbName = $this->_request->getValue( "dbName" );
$this->_skipThis = $this->_request->getValue( "skipDbInfo" );
- $this->_dbPrefix = $this->_request->getValue( "dbPrefix", DEFAULT_DB_PREFIX );
+ $this->_dbPrefix = $this->_request->getValue( "dbPrefix", DEFAULT_DB_PREFIX );
+
+ // we should now save the data to the configuration file, just before
+ // we read it
+ $configFile = new ConfigFileStorage();
- // we can ignore everything here, since the user wanted
- // to skip this step...
- if( $this->_skipThis == "yes" )
- return true;
-
- // otherwise, continue with the normal process
- $errors = false;
-
- // validate the data
- $val1 = new StringValidator();
- if( !$val1->validate( $this->_dbServer )) {
- $message .= "Incorrect database server.<br/>";
- $errors = true;
+ // before doing anything, we should check of the configuration file is
+ // writable by this script, or else, throw an error and bail out gracefully
+ $configFileName = $configFile->getConfigFileName();
+ if( !File::isWritable( $configFileName )) {
+ $this->_view = new WizardView( "intro" );
+ $message = "Please make sure that the file $configFileName can be written by this script during
+ the installation process. It is needed to store the database configuration settings. Once the
+ installation is complete, please revert the permissions to no writing possible.";
+ $this->_view->setErrorMessage( $message );
+ $this->setCommonData( true );
+ return false;
}
- $val2 = new StringValidator();
- if( !$val2->validate( $this->_dbUser )) {
- $message .= "Incorrect database user.<br/>";
+ // continue if everything went fine
+ if( !$configFile->saveValue( "db_username", $this->_dbUser ) ||
+ !$configFile->saveValue( "db_password", $this->_dbPassword ) ||
+ !$configFile->saveValue( "db_host", $this->_dbServer ) ||
+ !$configFile->saveValue( "db_database", $this->_dbName ) ||
+ !$configFile->saveValue( "db_prefix", $this->_dbPrefix )) {
$errors = true;
}
-
- // empty passwords should be allowed!
- if( $this->_dbPassword != "" ) {
- $val3 = new StringValidator();
- if( !$val3->validate( $this->_dbPassword )) {
- $message .= "Incorrect database password.<br/>";
- $errors = true;
- }
- }
-
- $val4 = new StringValidator();
- if( !$val4->validate( $this->_dbName )) {
- $message .= "Incorrect database name.<br/>";
- $errors = true;
- }
-
- $val5 = new StringValidator();
- if( !$val5->validate( $this->_dbPrefix )) {
- $message .= "Incorrect database prefix.<br/>";
- $errors = true;
- }
-
- // we should show the same page again but with some information about the
- // errors
+
if( $errors ) {
+ $errorMessage = "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.";
$this->_view = new WizardView( "intro" );
- $this->_view->setValue( "errors", true );
- $this->_view->setValue( "message", $message );
- return false;
+ $this->_view->setErrorMessage( $errorMessage );
+
+ return( false );
}
+ else {
+ $this->_view = new WizardView( "step1" );
- return true;
- }
+ // now we better read the information from the config file to make sure that
+ // it has been correctly saved
+ $this->setCommonData( true );
- function perform()
- {
- // we should now save the data to the configuration file, just before
- // we read it
- $configFile = new ConfigFileStorage();
-
- if( $this->_skipThis != "yes" ) {
-
- // before doing anything, we should check of the configuration file is
- // writable by this script, or else, throw an error and bail out gracefully
- $configFileName = $configFile->getConfigFileName();
- if( !File::isWritable( $configFileName )) {
- $this->_view = new WizardView( "error" );
- $message = "Please make sure that the file $configFileName can be written by this script during
- the installation process. It is needed to store the database configuration settings. Once the
- installation is complete, please revert the permissions to no writing possible.";
- $this->_view->setValue( "message", $message );
- return false;
- }
-
- // continue if everything went fine
- if( !$configFile->saveValue( "db_username", $this->_dbUser )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
- if( !$configFile->saveValue( "db_password", $this->_dbPassword )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
- if( !$configFile->saveValue( "db_host", $this->_dbServer )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
- if( !$configFile->saveValue( "db_database", $this->_dbName )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
- if( !$configFile->saveValue( "db_prefix", $this->_dbPrefix )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
+ return true;
}
-
- $this->_view = new WizardView( "step1" );
-
- // now we better read the information from the config file to make sure that
- // it has been correctly saved
- $configFile->reload();
- $this->_view->setValue( "username", $configFile->getValue( "db_username" ));
- $this->_view->setValue( "password", $configFile->getValue( "db_password" ));
- $this->_view->setValue( "host", $configFile->getValue( "db_host" ));
- $this->_view->setValue( "database", $configFile->getValue( "db_database" ));
- $this->_view->setValue( "prefix", $configFile->getValue( "db_prefix" ));
-
- return true;
}
}
/**
+ *
* Second step where we connect to the database and create the tables.
+ *
*/
- class WizardStepTwo extends Action {
+ class WizardStepTwo extends Action
+ {
var $_db;
var $_database;
var $_createDatabase;
-
- function validate()
+
+ function setDbConfigValues( $view )
{
- $createDb = $this->_request->getValue( "createDatabase" );
- if( $createDb == "on" )
- $this->_createDatabase = true;
- else
- $this->_createDatabase = false;
-
+ $configFile = new ConfigFileStorage();
+ $configFile->reload();
+ $view->setValue( "dbUser", $configFile->getValue( "db_username" ));
+ $view->setValue( "dbPassword", $configFile->getValue( "db_password" ));
+ $view->setValue( "dbServer", $configFile->getValue( "db_host" ));
+ $view->setValue( "dbName", $configFile->getValue( "db_database" ));
+ $view->setValue( "dbPrefix", $configFile->getValue( "db_prefix" ));
return true;
}
-
+
function perform()
{
global $Tables;
global $Inserts;
+
+ $createDb = $this->_request->getValue( "createDatabase" );
// only check for errors in case the database table should already exist!
- if( !$this->_createDatabase ) {
+ if( !$createDb ) {
$this->_db = connectDb();
- if( !$this->_db ) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "There was an error connecting to the database. Please check your settings." );
+ if( !$this->_db ) {
+ $this->_view = new WizardView( "step1" );
+ $this->setDbConfigValues( &$this->_view );
+ $this->_view->setErrorMessage("There was an error connecting to the database. Please check your settings." );
+ $this->setCommonData( true );
return false;
}
}
- else
+ else {
+ // connect to the database if all went fine
$this->_db = connectDb( true );
+ }
$config = new ConfigFileStorage();
$this->_database = $config->getValue( "db_database" );
$this->_dbPrefix = $config->getValue( "db_prefix" );
// create the database
- if( $this->_createDatabase ) {
+ if( $createDb ) {
if( !$this->_db->Execute( "CREATE DATABASE ".$this->_database )) {
$message .= "Error creating the database: ".$this->_db->ErrorMsg();
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", $message );
+ $this->_view = new WizardView( "step1" );
+ $this->setDbConfigValues( &$this->_view );
+ $this->_view->setErrorMessage( $message );
+ $this->setCommonData( true );
return false;
}
else
@@ -813,7 +811,7 @@
foreach( $Tables as $table ) {
$query = str_replace( "{dbprefix}", $this->_dbPrefix, $table["code"] );
if( $this->_db->Execute( $query ))
- $message .= "Table ".$table["desc"]." created successfully.<br/>";
+ $message .= "Table <strong>".$table["desc"]."</strong> created successfully.<br/>";
else {
$message .= "Error creating table: ".$this->_db->ErrorMsg()."<br/>";
$errors = true;
@@ -822,9 +820,10 @@
if( $errors ) {
$message = "There was an error creating the tables in the database. Please make sure that the user chosen to connect to the database has enough permissions to create tables.<br/><br/>$message";
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", $message );
-
+ $this->_view = new WizardView( "step1" );
+ $this->_view->setErrorMessage( $message );
+ $this->setDbConfigValues( &$this->_view );
+ $this->setCommonData();
return false;
}
@@ -897,79 +896,74 @@
}
}
- class WizardStepThree extends Action {
-
+ /**
+ *
+ * this action only shows some feedback
+ *
+ */
+ class WizardStepThree extends Action
+ {
function perform()
{
$this->_view = new WizardView( "step3" );
+ $this->setCommonData();
}
}
- class WizardStepFour extends Action {
+ /**
+ *
+ * Create the first user in the database
+ *
+ */
+ class WizardStepFour extends Action
+ {
var $_userName;
var $_userPassword;
var $_confirmPassword;
var $_userEmail;
var $_userFullName;
+
+ function WizardStepFour( $actionInfo, $request )
+ {
+ $this->Action( $actionInfo, $request );
+
+ $this->registerFieldValidator( "userName", new StringValidator());
+ $this->registerFieldValidator( "userPassword", new PasswordValidator());
+ $this->registerFieldValidator( "userPasswordCheck", new PasswordValidator());
+ $this->registerFieldValidator( "userEmail", new EmailValidator());
+ $this->registerField( "userFullName" );
+ $view = new WizardView( "step3" );
+ $view->setErrorMessage( "Some data is missing or incorrect" );
+ $this->setValidationErrorView( $view );
+ }
- function validate()
+ // creates the user
+ function perform()
{
$this->_userName = $this->_request->getValue( "userName" );
$this->_userPassword = $this->_request->getValue( "userPassword" );
$this->_confirmPassword = $this->_request->getValue( "userPasswordCheck" );
$this->_userEmail = $this->_request->getValue( "userEmail" );
$this->_userFullName = $this->_request->getValue( "userFullName" );
- $this->_properties = $this->_request->getValue( "properties" );
$errors = false;
+
+ $db = connectDb();
- // validate the information
- $userVal = new StringValidator();
- if( !$userVal->validate( $this->_userName )) {
- $message .= "Incorrect user name, please try again.<br/>";
- $errors = true;
- }
-
- $passVal = new StringValidator();
- if( !$passVal->validate( $this->_userPassword )) {
- $message .= "Incorrect password, please try again. <br/>";
- $errors = true;
- }
-
- $emailVal = new EmailValidator();
- if( !$emailVal->validate( $this->_userEmail )) {
- $message .= "Incorrect email address, please try again. <br/>";
- $errors = true;
- }
-
- if( $this->_userPassword != $this->_confirmPassword ) {
- $message .= "Passwords do not match, please try again. <br/>";
- $errors = true;
- }
-
- if( $errors ) {
+ if( !$db ) {
$this->_view = new WizardView( "step3" );
- $this->_view->setValue( "message", $message );
- $this->_view->setValue( "errors", $errors );
+ $this->_view->setErrorMessage( "There was an error connecting to the database. Please check your settings." );
+ $this->setCommonData();
return false;
}
-
- return true;
- }
-
- // creates the user
- function perform()
- {
- $db = connectDb();
-
- if( !$db ) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "There was an error connecting to the database. Please check your settings." );
-
+
+ if( $this->_confirmPassword != $this->_userPassword ) {
+ $this->_view = new WizardView( "step3" );
+ $this->_form->setFieldValidationStatus( "userPasswordCheck", false );
+ $this->setCommonData( true );
return false;
}
-
$config =& Config::getConfig();
$dbPrefix = $config->getValue( "db_prefix" );
@@ -982,9 +976,10 @@
$this->_properties );
$userId = $users->addUser( $user );
if( !$userId ) {
- $this->_view = new WizardView( "error" );
+ $this->_view = new WizardView( "step3" );
$message = "There was an error adding the user. Make sure that the user does not already exist in the database (".$users->DbError().")";
- $this->_view->setValue( "message", $message );
+ $this->_view->setErrorMessage( $message );
+ $this->setCommonData();
return false;
}
@@ -996,58 +991,66 @@
$this->_view = new Wizardview( "step4" );
$this->_view->setValue( "ownerid", $userId );
+ $this->_view->setValue( "siteLocales", Locales::getLocales());
+ $ts = new TemplateSets();
+ $this->_view->setValue( "siteTemplates", $ts->getGlobalTemplateSets());
+ $this->setCommonData();
return true;
}
}
- class WizardStepFive extends Action {
+ class WizardStepFive extends Action
+ {
var $_blogName;
var $_ownerId;
var $_blogProperties;
+
+ function WizardStepFive( $actionInfo, $request )
+ {
+ $this->Action( $actionInfo, $request );
+
+ $this->registerFieldValidator( "blogName", new StringValidator());
+ $this->registerFieldValidator( "ownerid", new IntegerValidator());
+ $this->registerFieldValidator( "blogTemplate", new StringValidator());
+ $this->registerFieldValidator( "blogLocale", new StringValidator());
+ $view = new WizardView( "step4" );
+ $view->setErrorMessage( "Some data is missing or incorrect" );
+ $view->setValue( "siteLocales", Locales::getLocales());
+ $ts = new TemplateSets();
+ $view->setValue( "siteTemplates", $ts->getGlobalTemplateSets());
+ $this->setValidationErrorView( $view );
+ }
- function validate()
+ function perform()
{
+ // retrieve the values from the view
$this->_blogName = $this->_request->getValue( "blogName" );
- $this->_ownerId = $this->_request->getValue( "ownerId" );
- $this->_blogProperties = $this->_request->getValue( "properties" );
+ $this->_ownerId = $this->_request->getValue( "ownerid" );
+ $this->_blogProperties = $this->_request->getValue( "properties" );
+ $this->_blogTemplate = $this->_request->getValue( "blogTemplate" );
+ $this->_blogLocale = $this->_request->getValue( "blogLocale" );
- $errors = false;
- $val = new StringValidator();
- if( !$val->validate( $this->_blogName )) {
- $errors = true;
- $this->_view = new WizardView( "step4" );
- $this->_view->setValue( "message", "You should choose a better name for the blog." );
- $this->_view->setValue( "errors", true );
- // this value has to be put in the template again
- $this->_view->setValue( "ownerid", $this->_ownerId );
- return false;
- }
-
- return true;
- }
-
- function perform()
- {
- $db = connectDb();
-
- if( !$db ) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "There was an error connecting to the database. Please check your settings." );
-
- return false;
- }
-
-
+ // configure the blog
$blogs = new Blogs();
$blog = new BlogInfo( $this->_blogName, $this->_ownerId, "", "" );
$blog->setProperties( $this->_blogProperties );
$blog->setStatus( BLOG_STATUS_ACTIVE );
+ $blogSettings = $blog->getSettings();
+ $blogSettings->setValue( "locale", $this->_blogLocale );
+ $blogSettings->setValue( "template", $this->_blogTemplate );
+ $blog->setSettings( $blogSettings );
+
+ // and now save it to the database
$newblogId = $blogs->addBlog( $blog );
if( !$newblogId ) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "There was an error creating the new blog: ".$db->ErrorMsg());
+ $this->_view = new WizardView( "step4" );
+ $this->_view->setValue( "siteLocales", Locales::getLocales());
+ $ts = new TemplateSets();
+ $this->_view->setValue( "siteTemplates", $ts->getGlobalTemplateSets());
+ $this->_view->setErrorMessage( "There was an error creating the new blog" );
+ $this->setCommonData( true );
return false;
}
@@ -1057,24 +1060,26 @@
$articleCategory = new ArticleCategory( "General", "", $newblogId, true );
$catId = $articleCategories->addArticleCategory( $articleCategory );
- // add an article based on that category
- $articleTopic = "Congratulations, it worked!";
- $articleText = "Welcome to pLog! If you can read this, it means that your pLog installation is ready and that you can start blogging.";
+ // load the right locale
+ $locale =& Locales::getLocale( $this->_blogLocale );
+ // and load the right text
+ $articleTopic = $locale->tr( "register_default_article_topic" );
+ $articleText = $locale->tr( "register_default_article_text" );
$article = new Article( $articleTopic, $articleText, Array( $catId ), $this->_ownerId, $newblogId, POST_STATUS_PUBLISHED, 0, Array(), "welcome" );
$t = new Timestamp();
$article->setDateObject( $t );
$articles = new Articles();
$articles->addArticle( $article );
- // and finally set the default_blog_id setting in the config.properties.php file
- // to the identifier of the blog we've just created
+ // save a few things in the default configuration
$config =& Config::getConfig();
- if( !$config->saveValue( "default_blog_id", (int)$newblogId )) {
- $this->_view = new WizardView( "error" );
- $this->_view->setValue( "message", "Could not save values to the configuration file. Please make sure it is available and that has write permissions for the user under your web server is running.");
- return false;
- }
-
+ // default blog id
+ $config->saveValue( "default_blog_id", (int)$newblogId );
+ // default locale
+ $config->saveValue( "default_locale", $this->_blogLocale );
+ // and finally, the default template
+ $config->saveValue( "default_template", $this->_blogTemplate );
+
//
// detect wether we have GD available and set the blog to use it
//
@@ -1171,7 +1176,8 @@
// - for all resources, fill in the normalized_description field
- class UpdateStepOne extends Action {
+ class UpdateStepOne extends Action
+ {
function perform()
{
@@ -1186,7 +1192,8 @@
}
}
- class UpdateStepTwo extends Action {
+ class UpdateStepTwo extends Action
+ {
var $_db;
var $_dbPrefix;
@@ -1570,6 +1577,7 @@
return true;
}
+
function perform()
{
$updaters = Array( "updateArticleCategories", "updateArticleComments",
@@ -1606,4 +1614,4 @@
//// main part ////
$controller = new Controller( $_actionMap, "nextStep" );
$controller->process( HttpVars::getRequest());
-?>
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list