* @package WB * @subpackage setup */ /** * make wombat site * * @author gERD Schaufelberger * @package WB * @subpackage setup */ class MKWombat { const SEVERITY_MSG = "msg"; const SEVERITY_WARN = "warning"; const SEVERITY_ERROR = "error"; /** * location of base dir * @var string */ private $base = ''; /** * location of system dir * @var string */ private $system = ''; /** * session data * @var array */ private $session = array(); /** * post data * @var array */ private $post = array( 'action' => 'welcome' ); /** * list of messages * @var array */ private $msg = array(); public function __construct() { $this->system = realpath(dirname(__FILE__)); $this->base = ''; session_start(); error_reporting( E_ALL | E_STRICT ); $this->post = array_merge( $this->post, $_REQUEST); $this->session =& $_SESSION; $this->self = $_SERVER['PHP_SELF'] . '?' . SID; } public function run() { $this->setBaseDir(); $this->displayMenu($this->post['action']); $this->displayAction($this->post['action']); } private function displayMenu($action) { $self = $this->self; echo <<
Welcome
Base Dir
EOF; if (empty($this->base)) { echo ''; return; } echo <<Setup Database
Component: User Login
Component: User Manager
CMS: Virtual File System, media file management
CMS: WXML multilanguage content editor
EOF; } private function displayAction($action) { $m = ucfirst(strtolower($action)); if (empty($m) || !method_exists($this, 'display'. $m)) { $m = 'Welcome'; } call_user_func(array($this, 'display' . $m)); } private function displayWelcome() { $self = $this->self; echo <<Welcome

This tool helps setting up a new web site based on the Wombat framework.

EOF; if (!isset($this->post['save']) && empty($this->post['save'])) { echo <<

Flush session data to start from scratch.

EOF; $this->printMsg(); return; } $this->session = array(); $this->addMsg('Restarted'); $this->printMsg(); } private function displayMkVFS() { $base = $this->base; if (empty($this->base)) { $this->printMsg(); return; } $self = $this->self; if (!isset($this->post['save']) && empty($this->post['save'])) { echo <<CMS: Virtual File System (VFS)

In order to insert media files like photos, videos and PDF-documents into any CMS-page, those file need to be hosted on the web-server. VFS manages those files, transcode them to other formats and keeps them in order.

Install VFS templates and config files?

EOF; $this->printMsg(); return; } $this->copy('etc-default/vfs.xml'); $this->mkDir('etc-default/vfs'); $this->copy('etc-default/vfs/gallery.xml'); $this->copy('etc-default/vfs/mkdir.xml'); $this->copy('etc-default/vfs/mvdir.xml'); $this->copy('etc-default/vfs/mvfile.xml'); $this->copy('etc-default/vfs/upload.xml'); $this->addMsg('Created VFS config files'); $this->mkDir('template/VFS'); $this->copy('template/VFS/anon.tmpl'); $this->copy('template/VFS/dir.tmpl'); $this->copy('template/VFS/display.tmpl'); $this->copy('template/VFS/displayInvalid.tmpl'); $this->copy('template/VFS/displayList.tmpl'); $this->copy('template/VFS/explorer.tmpl'); $this->copy('template/VFS/file.tmpl'); $this->copy('template/VFS/formmkdir.tmpl'); $this->copy('template/VFS/formupload-slot.tmpl'); $this->copy('template/VFS/formupload-swf.tmpl'); $this->copy('template/VFS/listdir.tmpl'); $this->copy('template/VFS/listfile.tmpl'); $this->copy('template/VFS/mkdir.tmpl'); $this->copy('template/VFS/mkdirValid.tmpl'); $this->copy('template/VFS/mvdirValid.tmpl'); $this->copy('template/VFS/mvfileValid.tmpl'); $this->copy('template/VFS/rm.tmpl'); $this->copy('template/VFS/rmdir.tmpl'); $this->copy('template/VFS/show.tmpl'); $this->copy('template/VFS/upload.tmpl'); $this->copy('template/VFS/uploadValid.tmpl'); $this->copy('template/VFS/toolbox.tmpl'); $this->mkDir('template/VFS/toolbox'); $this->mkDir('template/VFS/toolbox/edit'); $this->copy('template/VFS/toolbox/edit/__default.tmpl'); $this->copy('template/VFS/toolbox/edit/__nofile.tmpl'); $this->copy('template/VFS/toolbox/edit/image.tmpl'); $this->mkDir('template/VFS/toolbox/move'); $this->copy('template/VFS/toolbox/move/__nofile.tmpl'); $this->copy('template/VFS/toolbox/move/dir.tmpl'); $this->copy('template/VFS/toolbox/move/file.tmpl'); $this->mkDir('template/VFS/toolbox/select'); $this->copy('template/VFS/toolbox/select/any.tmpl'); $this->copy('template/VFS/toolbox/select/dir.tmpl'); $this->copy('template/VFS/toolbox/select/dirList.tmpl'); $this->copy('template/VFS/toolbox/select/file.tmpl'); $this->copy('template/VFS/toolbox/editInPlace.tmpl'); $this->copy('template/VFS/toolbox/editInPlaceDone.tmpl'); $this->addMsg('Created VFS template files'); $this->printMsg(); echo <<CMS: Virtual File System (VFS)

Basic VFS files are installed. Maybe you want to add some cron-jobs etc.

EOF; } private function displayMkWxml() { $base = $this->base; if (empty($this->base)) { $this->printMsg(); return; } $self = $this->self; if (!isset($this->post['save']) && empty($this->post['save'])) { echo <<CMS: WXML Article Editor

Wombat's XML based CMS uses the multilanguage editor to maintain CMS articles.

Install everything for the WXML CMS?

EOF; $this->printMsg(); return; } $this->mkDir('etc-default/wxml'); $this->copy('etc-default/wxml/config.xml'); $this->mkDir('etc-default/wxml/form'); $this->copy('etc-default/wxml/form/edit.xml'); $this->copy('etc-default/wxml/form/translate.xml'); $this->addMsg('Created WXML config files'); $this->mkDir('template/Wxml'); $this->copy('template/Wxml/badrequest.tmpl'); $this->copy('template/Wxml/edit.tmpl'); $this->copy('template/Wxml/editable.tmpl'); $this->copy('template/Wxml/editValid.tmpl'); $this->copy('template/Wxml/translate.tmpl'); $this->copy('template/Wxml/translateValid.tmpl'); $this->mkDir('template/Wxml/converter'); $this->mkDir('template/Wxml/converter/wb'); $this->mkDir('template/Wxml/converter/wb/vfsfile'); $this->copy('template/Wxml/converter/wb/vfsfile/download.tmpl'); $this->copy('template/Wxml/converter/wb/vfsfile/image.tmpl'); $this->copy('template/Wxml/converter/wb/vfsfile/video.tmpl'); $this->addMsg('Created WXML template files'); $this->mkDir('etc-default/xinha'); $this->mkDir('etc-default/xinha/dialog'); $this->copy('etc-default/xinha/dialog/url.xml'); $this->addMsg('Created Xinha config files'); $this->mkDir('template/Xinha'); $this->copy('template/Xinha/anonymous.tmpl'); $this->copy('template/Xinha/dialog.tmpl'); $this->mkDir('template/Xinha/dialog'); $this->mkDir('template/Xinha/dialog/smiley'); $this->copy('template/Xinha/dialog/smiley/insert.tmpl'); $this->copy('template/Xinha/dialog/smiley/list.tmpl'); $this->mkDir('template/Xinha/dialog/specialchar'); $this->copy('template/Xinha/dialog/specialchar/insert.tmpl'); $this->copy('template/Xinha/dialog/specialchar/list.tmpl'); $this->mkDir('template/Xinha/dialog/toc'); $this->mkDir('template/Xinha/dialog/toc/list'); $this->copy('template/Xinha/dialog/toc/list/default.tmpl'); $this->copy('template/Xinha/dialog/toc/insert.tmpl'); $this->copy('template/Xinha/dialog/toc/toc.tmpl'); $this->mkDir('template/Xinha/dialog/url'); $this->copy('template/Xinha/dialog/url/insert.tmpl'); $this->copy('template/Xinha/dialog/url/url.tmpl'); $this->mkDir('template/Xinha/dialog/vfsfile'); $this->copy('template/Xinha/dialog/vfsfile/insert.tmpl'); $this->copy('template/Xinha/dialog/vfsfile/list.tmpl'); $this->addMsg('Created Xinha template files'); $this->printMsg(); echo <<CMS: WXML Article Editor Installed

All files to use WXML CMS are installed. Use "Wxml" as processor in page definitions or simply use patTemplate:wxml-tag in any template file.

EOF; } private function displayMkUserLogin() { $base = $this->base; if (empty($this->base)) { $this->printMsg(); return; } $self = $this->self; if (!isset($this->post['save']) && empty($this->post['save'])) { echo <<Install Component: User_Login

Many features of Wombat require authorized user sessions. The component User_Login allows to login, register, change password etc.

Install User_Login templates and config files?

EOF; $this->printMsg(); return; } $this->mkDir('etc-default/user'); $this->mkDir('etc-default/user/login'); $this->copy('etc-default/user/login/activate.xml'); $this->copy('etc-default/user/login/approverenewpassword.xml'); $this->copy('etc-default/user/login/login.xml'); $this->copy('etc-default/user/login/password.xml'); $this->copy('etc-default/user/login/register.xml'); $this->copy('etc-default/user/login/renewpassword.xml'); $this->addMsg('Added config files'); $this->mkDir('template/User'); $this->mkDir('template/User/Login'); $this->copy('template/User/Login/activate.tmpl'); $this->copy('template/User/Login/activateValid.tmpl'); $this->copy('template/User/Login/anon.tmpl'); $this->copy('template/User/Login/approverenewpassword.tmpl'); $this->copy('template/User/Login/approverenewpasswordValid.tmpl'); $this->copy('template/User/Login/auth.tmpl'); $this->copy('template/User/Login/login.tmpl'); $this->copy('template/User/Login/password.tmpl'); $this->copy('template/User/Login/passwordValid.tmpl'); $this->copy('template/User/Login/register.tmpl'); $this->copy('template/User/Login/registerValid.tmpl'); $this->copy('template/User/Login/renewpassword.tmpl'); $this->copy('template/User/Login/renewpasswordValid.tmpl'); $this->addMsg('Added template files'); $this->mkDir('etc-default/event/user'); $this->copy('etc-default/event/user/approve.xml'); $this->copy('etc-default/event/user/passwordRenew.xml'); $this->copy('etc-default/event/user/register.xml'); $this->mkDir('template/Mailer'); $this->mkDir('template/Mailer/user'); $this->copy('template/Mailer/user/registered.tmpl'); $this->copy('template/Mailer/user/passwordrenew.tmpl'); $this->addMsg('Added files for event processing'); $this->printMsg(); echo <<Component: User_Login Installed

Use "User_Login" as processor in page definition. Change event configuration accordingly. Also ment templates and forms and probably table columns.

EOF; } private function displayMkUserManager() { $base = $this->base; if (empty($this->base)) { $this->printMsg(); return; } $self = $this->self; if (!isset($this->post['save']) && empty($this->post['save'])) { echo <<Install Component: User_Manager

Manage your site's uses with the comfortable out-of-the-box User_Manager component.

Install User_Manager templates and config files?

EOF; $this->printMsg(); return; } $this->mkDir('etc-default/user'); $this->mkDir('etc-default/user/manager'); $this->copy('etc-default/user/manager/userEdit.xml'); $this->addMsg('Added config files'); $this->mkDir('template/User'); $this->mkDir('template/User/Manager'); $this->copy('template/User/Manager/anon.tmpl'); $this->copy('template/User/Manager/pager.tmpl'); $this->copy('template/User/Manager/userDisplay.tmpl'); $this->copy('template/User/Manager/userEdit.tmpl'); $this->copy('template/User/Manager/userEditValid.tmpl'); $this->copy('template/User/Manager/userList.tmpl'); $this->copy('template/User/Manager/userList_entry.tmpl'); $this->copy('template/User/Manager/userRm.tmpl'); $this->copy('template/User/Manager/userRmDeleted.tmpl'); $this->addMsg('Added template files'); $this->printMsg(); echo <<Component: User_Manager Installed

Use "User_Manager" as processor in page definition. Change event configuration accordingly. Also ment templates and forms and probably table columns.

EOF; } private function displayMkDatabase() { $base = $this->base; $self = $this->self; if (empty($this->base)) { $this->printMsg(); return; } if (!isset($this->session['db']) || empty($this->session['db'])) { $this->session['db'] = array( 'host' => 'localhost', 'db' => '', 'user' => '', 'password' => '' ); } if (isset($this->post['db']) && !empty($this->post['db'])) { $this->session['db'] = $this->post['db']; } else { $dbhost = $this->session['db']['host']; $dbdb = $this->session['db']['db']; $dbuser = $this->session['db']['user']; $dbpassword = $this->session['db']['password']; echo <<Install Database

Many features of Wombat are database driven. Therefore, Wombat requires access to a MySQL database and a set of tables.

Database credentials
Host:
Database:
User:
Password:

EOF; return; } // verify connection settings $dbhost = $this->session['db']['host']; $dbdb = $this->session['db']['db']; $dbuser = $this->session['db']['user']; $dbpassword = $this->session['db']['password']; $this->dbc = @new mysqli($dbhost, $dbuser, $dbpassword, $dbdb); if ($this->dbc->connect_error) { $this->addMsg('Error connection to database: ' . $this->dbc->connect_error, self::SEVERITY_ERROR); $this->printMsg(); echo << You probably want to create a new database and/or user for you new wombat site.

    CREATE DATABASE `$dbdb` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
    GRANT USAGE ON *.* TO `$dbuser`@`$dbhost`;
    SET PASSWORD FOR `$dbuser`@`$dbhost` = password("$dbpassword");
    GRANT ALL PRIVILEGES ON `$dbdb`.* TO `$dbuser`@`$dbhost`;
EOF; return; } // write database config $config = file_get_contents($this->base . '/etc-default/config.xml'); $db = << $dbhost $dbdb $dbuser $dbpassword table EOF; $config = preg_replace('/(\s+?).*<\\/db>/ms', $db, $config); file_put_contents($this->base . '/etc-default/config.xml', $config); $this->addMsg('Updated database config to "etc-default/config.xml"'); // source table.sql if ($this->dbc->query('DESC wbuser')) { $this->addMsg('It looks like some wombat tables aready exist. Please verify tables manually.', self::SEVERITY_WARN); $this->printMsg(); return; } $source = file_get_contents($this->system . '/doc/table.sql'); if (!$this->dbc->multi_query($source)) { $this->addMsg('Failed to source "'.$this->system.'/doc/table.sql".', self::SEVERITY_ERROR); $this->printMsg(); return; } $this->addMsg('Created tables using "'. $this->system .'/doc/table.sql"'); $this->printMsg(); } private function displayMkbasedir() { $base = $this->base; $self = $this->self; if (empty($this->base)) { $this->printMsg(); echo <<Create and Populate BASEDIR

Create all basic files and folders in BASEDIR to use it as Wombat-based web-site. A proper set up BASEDIR is essential for any Wombat site.

BASEDIR:

EOF; return; } echo <<BASEDIR Created and Populated

Please check ownership and permissions of your files in BASEDIR. It is recommended to set all files to read-only. Still, the web-server needs write access to "var" and subfolders. Hence it's probably a good idea to change owner and permissions:

    sudo chown -R USER:GROUP $base
    chmod -R go-w $base
    chmod -R go+w $base/var
EOF; // etc/wbLoader.php if (file_exists($base . '/etc/wbLoader.php')) { $this->addMsg('Create wbLoader Helper skipped, file exists', self::SEVERITY_WARN); } else { $this->addMsg('Create wbLoader Helper'); $file = array('system . '\';'; $file[] = '?>'; $file[] = ''; $file = implode("\n", $file); file_put_contents($base . '/etc/wbLoader.php', $file); } // etc/config.php if (file_exists($base . '/etc/config.php')) { $this->addMsg('Create optional config.php skipped, file exists', self::SEVERITY_WARN); } else { $this->addMsg('Create optional config.php'); $file = array(''; $file[] = ''; $file = implode("\n", $file); file_put_contents($base . '/etc/config.php', $file); } $this->printMsg(); } private function setBaseDir() { if ('mkbasedir' == $this->post['action']) { //$this->session['basedir'] = ''; $this->mkBaseDir(); } if (!isset($this->session['basedir']) || empty($this->session['basedir'])) { if ('welcome' != $this->post['action']) { $this->post['action'] = 'mkbasedir'; } return; } $this->base = $this->session['basedir']; if (!is_dir($this->base) || !is_writable($this->base)) { $this->addMsg( 'BASEDIR does not exist or is not writable' , self::SEVERITY_ERROR); } } private function mkBaseDir() { $base = realpath( $this->system . '/..'); if (!isset($this->post['basedir']) || empty($this->post['basedir'])) { $this->post['basedir'] = $base; return; } if (rtrim($this->post['basedir'], '/') == $base) { $this->addMsg('BASEDIR must not be the parent folder of Wombat\s SYSTEMDIR', self::SEVERITY_ERROR); return; } if ($this->post['basedir'] == $this->system) { $this->addMsg( 'SYSTEMDIR and BASEDIR must not be the same! The folder that holds the Wombat framework must not be your BASEDIR. That way, you never have to touch anything inside SYSTEMDIR and you may reuse SYSTEMDIR for further web-sites installed in other BASEDIRs.' , self::SEVERITY_ERROR); return; } // create basedir if (!is_dir($this->post['basedir'])) { if (!@mkdir($this->post['basedir'], 0777, true)) { $this->addMsg( 'Could not create BASEDIR. Maybe there is a problem regarding ownership or permissions.' , self::SEVERITY_ERROR); return; } } // writeable if (!is_writable($this->post['basedir'])) { $this->addMsg( 'Folder BASEDIR exists, but is not writeable.' , self::SEVERITY_ERROR); return; } $this->base = realpath($this->post['basedir']); $this->session['basedir'] = $this->base; $folders = array( 'etc', 'etc-default', 'etc-default/event', 'etc-default/site', 'etc-default/site/page', 'etc-default/site/event', 'include', 'include/WB', 'include/patEx', 'template', 'htdoc', 'htdoc/s', 'resource', 'resource/css', 'resource/js', 'template', 'template/Composite', 'template/Static', 'template/Mailer', 'var', 'var/log', 'var/cache', 'var/tmp' ); $this->mkDir($folders); $files = array( 'wbLoader.php', 'etc-default/config.xml', 'etc-default/event.xml', 'etc-default/locale.xml', 'etc-default/log.xml', 'etc-default/locale.xml', 'etc-default/table.xml', 'etc-default/site.xml', 'etc-default/site/content.xml', 'etc-default/site/page/__index.xml', 'etc-default/site/page/sitemap.xml', 'etc-default/site/page/robots.txt.xml', 'etc-default/site/page/blank.xml', 'htdoc/dispatcher.php', 'resource/css/main.css', 'resource/css/form.css', 'resource/css/window.css', 'resource/css/highlight.css', 'resource/css/icon.css', 'resource/css/lightbox.css', 'resource/css/tool.css', 'resource/css/vfs.css', 'template/site.tmpl', 'template/formError.tmpl', 'template/Composite/site.tmpl', 'template/Static/menu.tmpl', 'template/Static/home.tmpl', 'template/Static/blank.tmpl', 'template/Mailer/signature.tmpl', ); $this->copy($files); } private function addMsg($msg, $severity = self::SEVERITY_MSG) { $this->msg[] = array($msg, $severity); } private function printMsg() { echo "
\n"; foreach ($this->msg as $msg) { echo sprintf('

%s

', $msg[1], $msg[0]); } echo "
\n"; } /** * create folders * * * @param array|string $folders */ private function mkDir($folders = array()) { if (!is_array($folders)) { $folders = array($folders); } foreach ($folders as $f) { if (is_dir($this->base . '/' . $f)) { continue; } mkdir($this->base . '/' . $f); chmod($this->base . '/' . $f, 0777); $this->addMsg('Created folder ' . $f, self::SEVERITY_MSG); } } /** * copy bunch of files * * * @param array|string $files */ private function copy($files = array()) { if (!is_array($files)) { $files = array($files); } foreach ($files as $f) { if (file_exists($this->base . '/' . $f)) { continue; } copy($this->system . '/' . $f, $this->base . '/' . $f); chmod($this->base . '/' . $f, 0666); $this->addMsg('Copied ' . $f, self::SEVERITY_MSG); } } } $mkw = new MKWombat(); ?> Installer :: Wombat

Wombat Installation Helper

run(); ?>