setSetup (new Setup_Manual ()); } function stepCheckTemplatesC () { $tester = new Tester_Smarty (); if (!$tester->run ()) { $dir = DATADIR . '/template_c'; echo << Directory $dir does not exist or has an invalid mode.

Please, make sure it does exist and is writable.

html; exit; } $this->moveToStep ('stepCheckEnvironment'); } function stepCheckEnvironment () { $view = new View_Setup ('checkEnvironment'); $this->setView ($view); $view->header = 'Checking requirments'; $tester = new Tester_Install (); $tester->setPainter (new Tester_Painter_Browser ()); $install_only = new Tester_InstallOnly (); foreach ($install_only->getTests () as $test) { $tester->addTest ($test); } $test_result = $tester->run (); $this->getForm () ->add ('html', 'test') ->add ('html', 'fixingcommands') ->noRequiredFields ('fixingcommands') ; if ($test_result) { $this->getForm () ->addSubmitButton ('Proceed to step 2', 'install'); } $this->getForm ()->test->value = '' . $tester->getStringResult () . '
'; if ($fixing_commands = $tester->getFixingCommands ()) { $fixing_commands_text = '' . join ("\n", $fixing_commands) . ''; $fixing_commands_text = '

To fix these problems run command shown below.

' . $fixing_commands_text . '
'; $this->getForm ()->fixingcommands->value = $fixing_commands_text; } if ($this->getForm ()->validate ()) { if (! isset ($_POST ['javascript_test_passed'])) { foreach ($tester->getTests () as $test) { if ($test instanceof Tester_Test_Javascript) { $test->setPassed (false); } } $test_result = $tester->run (); $this->getForm ()->test->value = '' . $tester->getStringResult () . '
'; } if ($test_result) { $this->moveToStep ('stepUserAgreement'); } } } function stepUserAgreement () { $view = new View_Setup ('userAgreement'); $this->setView ($view); $view->header = 'User agreement'; $this->getForm () ->addSubmitButton ('I accept. Start Installation.', 'install') ->addBackwardButton ('stepCheckEnvironment'); if ($this->getForm ()->validate ()) { $this->moveToStep ('stepUploadSetupSettings'); } } function stepUploadSetupSettings () { $view = new View_Setup ('uploadSetupSettings'); $this->setView ($view); $view->header = 'Existing setup settings'; $this->getForm () ->add ('file', 'settings', 'allowed_types=ini') ->addSubmitButton ('Proceed', 'install') ->addBackwardButton ('stepUserAgreement') ->noRequiredFields (); if ($this->getForm ()->validate ()) { if ($file = $this->getForm ()->settings->get_value ()) { try { $ini_file = new Zend_Config_Ini ($file['full_path']); $this->setPersistent ('config', $ini_file->toArray ()); $this->moveToStep ('stepCheckUploadedSettings'); return; } catch (Zend_Config_Exception $e) { $this->getForm ()->error ('settings', $e->getMessage ()); return; } } else { $this->moveToStep ('stepDatabaseConnectionSettings'); } } } function stepCheckUploadedSettings () { if (!$this->isDatabaseConnectionValid ()) { $this->moveToStep ('stepDatabaseConnectionSettings', 'stepCheckUploadedSettings'); return; } if (!$this->isAffiliateSettingsValid ()) { $this->moveToStep ('stepAffiliateSettings', 'stepCheckUploadedSettings'); return; } $this->moveToStep ('stepCreateTemporaryIniFile'); } function stepDatabaseConnectionSettings () { $view = new View_Setup ('databaseConnectionSettings'); $this->setView ($view); $view->header = 'Database connection'; $form = $this->getForm (); $form ->add ('text', 'host') ->set ('host','value','localhost') ->add ('text', 'port') ->set ('port','value','3306') ->add ('text', 'database') ->add ('text', 'table prefix') ->add_rule ('table_prefix', 'table_prefix', 'Only letters, numbers, and underscores are allowed starting with a letter.') ->add ('text', 'user') ->add ('text', 'password') ->add ('checkbox', 'dataset', 'label=Import initial dataset') ->noRequiredFields ('table_prefix', 'dataset') ->addSubmitButton ('Connect to Database', 'install') ->addBackwardButton ('stepUploadSetupSettings') ; $form->dataset->check (); $connection = $this->getPersistent ('connection'); if (isset ($connection)) { $form->host->value = $connection->getHost (); $form->port->value = $connection->getPort (); $form->database->value = $connection->getDatabase (); $form->table_prefix->value = $connection->getTablePrefix (); $form->user->value = $connection->getUser (); $form->password->value = $connection->getPassword (); } if ($this->getForm ()->validate ()) { $connection = new MySQLConnection (); $connection->setHost ($form->host->value) ->setPort ($form->port->value) ->setDatabase ($form->database->value) ->setTablePrefix ($form->table_prefix->value) ->setUser ($form->user->value) ->setPassword ($form->password->value); { $result = false; foreach ($this->getMysqlExtensionList() as $ext) { $connection->setType ($ext); $result = $connection->test (); if ($result) { break; } } } if ($result === true) { $this->setPersistent ('connection', $connection); $this->setPersistent ('dataset', $form->dataset->get_value()); $this->moveToStep ('stepAffiliateSettings'); } else { $this->getForm ()->error ('host', $result); } } } protected function getMysqlExtensionList () { return preg_grep ('~^mysqli?~', get_loaded_extensions ()); } function stepAffiliateSettings () { $view = new View_Setup ('affiliateSettings'); $this->setView ($view); $view->header = 'Affiliate settings'; $affiliate_login = Kohana::config ('core.affiliate_login', false, false); $preset_code = Kohana::config ('core.preset_code', false, false); $form = $this->getForm (); $form ->add ('text', 'login', 'label=Affiliate login,style=width:300px') ->add ('text', 'preset_code', 'label=Preset code,style=width:300px') ->add ('text', 'email', 'style=width:300px') ->add_rule ('email', 'email', 'The email is empty.') ->addSubmitButton ('Next', 'install') ->addBackwardButton ('stepDatabaseConnectionSettings') ; if (isset ($affiliate_login)) { $form->login->readonly = true; } if (isset ($preset_code)) { $form->preset_code->readonly = true; } $affiliate = $this->getPersistent ('affiliate'); if (isset ($affiliate)) { $form->login->value = $affiliate ['login']; $form->preset_code->value = $affiliate ['preset_code']; $form->email->value = $affiliate ['email']; } else { $affiliate = array ( 'login' => '', 'preset_code' => '', 'email' => '', ); if (isset ($affiliate_login)) { $form->login->value = $affiliate_login; $affiliate ['login'] = $affiliate_login; } if (isset ($preset_code)) { $form->preset_code->value = $preset_code; $affiliate ['preset_code'] = $preset_code; } if ($affiliate) { $this->setPersistent ('affiliate', $affiliate); } } if ($this->getForm ()->validate ()) { $new_affiliate = $this->getForm ()->get_values (); if (isset ($affiliate_login)) { $new_affiliate ['login'] = $affiliate_login; } if (isset ($preset_code)) { $new_affiliate ['preset_code'] = $preset_code; } list ($result, $message) = $this->getSetup ()->testAffiliateSettings ($new_affiliate); list ($result, $message) = array (true, url::base ()); if ($result === true) { $this->setPersistent ('affiliate', $new_affiliate); if (url::base () != $message) { $this->setPersistent ('preset_domain', $message); $this->moveToStep ('stepInvalidDomainWarning'); } else { $this->moveToStep ('stepChooseTemplateTypes'); } } else { $this->getForm ()->error ('login', $message); } } } function stepInvalidDomainWarning () { $view = new View_Setup ('warning'); $this->setView ($view); $view->header = 'Warning'; $form = $this->getForm (); $preset_domain = $this->getPersistent ('preset_domain'); $message = <<add ('html', 'test', $message) ->addSubmitButton ('Next', 'install') ->addBackwardButton ('stepAffiliateSettings') ; if ($this->getForm ()->validate ()) { $this->moveToStep ('stepChooseTemplateTypes'); } } function stepChooseTemplateTypes () { $parser = $this->getTmDirParser (); $view = new View_Setup ('templateSettings'); $this->setView ($view); $view->header = 'Template settings'; $categories = $parser->parseCategories (); usort ($categories, array ($this, 'sortByName')); $types = $parser->parseTypes (); usort ($types, array ($this, 'sortByName')); $hobbies = array ( 'No adult templates', 'Adult templates only', 'All templates', ); $this->getForm () ->add_select ('Show adult templates', $hobbies) ->add ('checkbox', 'Customize template categories') ->add ('checkbox', 'Customize template types') ->add ('html', 'customization') ->addSubmitButton ('Next', 'install') ->addBackwardButton ('stepAffiliateSettings') ->noRequiredFields (); $this->restorePersistent ('show_adult_templates', 0); $custom = new View_Page ('setup/typeCustomisation'); $custom->visible = $this->restorePersistent ('customize_template_categories', false); $custom->type = 'categories'; $custom->items = $categories; $custom->selected = $this->getPersistent ('custom_categories', array ()); $categories_and_types = "\n\n"; $categories_and_types .= $custom->render (); $custom->type = 'types'; $custom->visible = $this->restorePersistent ('customize_template_types', false); $custom->items = $types; $custom->selected = $this->getPersistent ('custom_types', array ()); $categories_and_types .= "\n\n"; $categories_and_types .= $custom->render (); $this->getForm ()->customization->value = $categories_and_types; if ($this->getForm ()->validate ()) { $this->setPersistent ('show_adult_templates'); $this->setPersistent ('customize_template_categories'); $this->setPersistent ('customize_template_types'); if (isset ($_POST['custom_types'])) { $this->setPersistent ('custom_types', array_keys ($_POST['custom_types'])); } else { $this->unsetPersistent ('custom_types'); } if (isset ($_POST['custom_categories'])) { $this->setPersistent ('custom_categories', array_keys ($_POST['custom_categories'])); } else { $this->unsetPersistent ('custom_categories'); } $this->moveToStep ('stepCreateTemporaryIniFile'); } } function stepCreateTemporaryIniFile () { $this->setConfig ($this->createTemporaryIniFile ()); $this->moveToStep ('stepInstallationItself'); } function stepInstallationItself () { $view = new View_Setup ('installationItself'); $this->setView ($view); $view->header = 'Installation'; $this->getForm () ->addSubmitButton ('Install', 'install') ->addBackwardButton ('stepChooseTemplateTypes') ; if ($this->getForm ()->validate ()) { try { $this->getSetup ()->setIniParser ($this->getIniParser ()); $this->getSetup ()->run (); $this->moveToStep ('stepPostInstall'); } catch (Exception $e) { $view->error = 'An error occured during setup. Please browse log file in order to figure out what went wrong.'; } } } function stepPostInstall () { $view = new View_Setup ('postInstall'); $this->setView ($view); $view->header = 'Post install'; $view->cron = $this->getSetup ()->generateCronString (); $view->login = $this->getSetup ()->getSetting (Setting_Model::S_ADMIN_LOGIN); $view->password = $this->getSetup ()->getSetting (Setting_Model::S_ADMIN_PASSWORD); } protected function setSetup ($setup) { $this->setup = $setup; } protected function getSetup () { return $this->setup; } private function isDatabaseConnectionValid () { if ($this->getPersistent ('connection')) { return true; } else { $connection = $this->getIniParser ()->parseDatabaseConnection (); return $connection->test () === true; } } private function isAffiliateSettingsValid () { if ($this->getPersistent ('affiliate')) { return true; } else { $affiliate = $this->getIniParser ()->parseAffiliate (); if ($affiliate) { list ($result) = $this->getSetup ()->testAffiliateSettings ($affiliate); if ($result === true) { return true; } } } } private function createTemporaryIniFile () { $config = $this->getConfig (); if (is_array ($config)) { $config = new Zend_Config ($config, true); } if (!isset ($config->default)) { $config->default = array (); } $default = $config->default; $connection = $this->getPersistent ('connection'); if (isset ($connection)) { $default->database = $connection->toArray (); $default->dataset = $this->getPersistent ('dataset', 0); } $affiliate = $this->getPersistent ('affiliate'); if (isset ($affiliate)) { $default->affiliate = $affiliate; } $show_adult_templates = $this->getPersistent ('show_adult_templates'); if (isset ($show_adult_templates)) { $default->template = array (); $default->template->adult = $show_adult_templates; $parser = $this->getTmDirParser (); if ($this->getPersistent ('customize_template_categories')) { $result = array (); $categories = $parser->parseCategories (); usort ($categories, array ($this, 'sortByName')); if ($this->getPersistent ('custom_categories')) { foreach ($categories as $category) { if (in_array ($category->getId (), $this->getPersistent ('custom_categories'))) { $result[] = $category->getName (); } } } $default->template->categories = array (); $default->template->categories->available = join ('|', $result); } if ($this->getPersistent ('customize_template_types')) { $result = array (); $types = $parser->parseTypes (); usort ($types, array ($this, 'sortByName')); if ($this->getPersistent ('custom_types')) { foreach ($types as $type) { if (in_array ($type->getId (), $this->getPersistent ('custom_types'))) { $result[] = $type->getName (); } } } $default->template->types = array (); $default->template->types->available = join ('|', $result); } } return $config; } function getIniParser () { $result = new Parser_Ini_Setup ($this->getConfig ()); $result->setKeyPrefix ('/default'); return $result; } function setConfig (Zend_Config $config) { $this->setPersistent ('config', $config); } function getConfig () { return $this->getPersistent ('config', array ()); } function sortByName ($a, $b) { return strcasecmp ($a->getName (), $b->getName ()); } function getTmDirParser () { $downloader = new TM_Downloader (); $file = $downloader->download (TM_Downloader::ENTITY_DICTIONARY); return new Parser_JSON_TMInfoDir (file_get_contents ($file)); } }