Wombat Installation Helper

* @license PHP License * @package WB * @subpackage Wikipedia */ error_reporting( E_ALL | E_STRICT ); class MKWombat { /** * location of base dir * @var string */ private $base; /** * location of system dir * @var string */ private $system; /** * post data * @var array */ private $post = array( 'action' => 'welcome', 'base' => '', 'dbhost' => 'localhost', 'dbdb' => 'wombat', 'dbuser' => '', 'dbpassword'=> '', ); public function __construct() { $this->system = realpath(dirname(__FILE__)); $this->base = realpath($this->system . '/..'); } public function setPost($post) { $this->post = array_merge($this->post, $post); } public function run() { if (!empty($this->post['base'])) { $this->base = $this->post['base']; } else { $this->post['base'] = $this->base; } $this->displayMenu(); $m = ucfirst(strtolower($this->post['action'])); if (empty($m) || !method_exists($this, 'run'. $m)) { $m = 'Welcome'; } call_user_func(array($this, 'run' . $m)); } private function displayMenu() { // populate vars foreach ($this->post as $key => $value) { $$key = $value; } $self = $_SERVER['PHP_SELF']; echo <<

Menu

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:

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:

Enable Feature: CMS (NOT IMPLEMENTED, YET)

The database driven CMS allows you to alter and translate content using a WYSIWIG editor while browsing you site.

Enable Feature: Virtual File System (VFS) (NOT IMPLEMENTED, YET)

Wombat's Virtual File System (VFS) brings multimedia content to your site. Among others, videos and photos are supported. VFS features displaying those files, make them downloadable. On the other hand user may upload multimedia content and organize it in folder based (virtual) file system.

EOF; } private function runWelcome() { echo <<Welcome

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

EOF; } private function runMkbasedir() { $base = $this->base; echo <<Make Basedir

Create basic files and folders in "$base" Check output below for errors!

In case everything went fine, that's all you need to use Wombat as framework for your own site.

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

Next Steps

  • Before you start touching any file: Adjust your editor's settings to UTF-8 encoding. Also UNIX EOL-style and using four spaces instead of TAB-character is recommended. Furthermore you must not use Windows-UNICODE file prefix.
  • First thing is to edit "$base/etc-default/config.xml" and change <server> and <docroot> according to your host's setup.
  • Adjust CSS: Edit "$base/etc-default/site.xml" and select the CSS files you want to use.
    Edit CSS files in "$base/resource/css"
  • Edit home template: "$base/template/Static/home.tmpl"
  • See how pages work "$base/etc-default/site/page/blank.xml", "$base/etc-default/site/page/__index.xml", "$base/etc-default/site/page/sitemap.xml" and "$base/etc-default/site/page/robots.txt.xml"
  • Check out where default content comes from "$base/etc-default/site/content.xml" and "$base/etc-default/site.xml".
  • Implement HTML layout in: "$base/template/Composite/site.tmpl" (e.g.)
  • Place static content (like images) of your web-site in "$base/htdoc/s/" (recommended).
  • ...or create and setup the database.

...but first, check output below:

EOF; if ($this->base == $this->system) { echo << 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.

Why not just create BASEDIR next to SYSTEMDIR?

EOF; return; } if (!is_dir($this->base)) { if (!@mkdir($this->base, 0777, true)) { echo << Could not create BASEDIR. Maybe there is a problem regarding ownership or permissions.

Try to create this folder manually (via FTP or something) and make it writable for everyone.

    mkdir $base
    chmod 777 $base
EOF; return; } } if (!is_writeable($this->base)) { echo << Folder BASEDIR exists, but is not writeable.

Change permissions of this folder.

    chmod 777 $base
EOF; return; } $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/Rss', '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/site.php', 'htdoc/css.php', 'htdoc/js.php', 'htdoc/ajax.php', 'htdoc/captcha.php', 'htdoc/file.php', 'htdoc/rest.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/Rss/broken.tmpl', 'template/Rss/list.tmpl', 'template/Rss/headline.tmpl', ); $this->copy($files); echo "

Create wbLoader Helper

\n"; flush(); $file = array('system . '\';'; $file[] = '?>'; $file[] = ''; $file = implode("\n", $file); file_put_contents($base . '/etc/wbLoader.php', $file); echo "

Create optional config.php

\n"; flush(); $file = array(''; $file[] = ''; $file = implode("\n", $file); file_put_contents($base . '/etc/config.php', $file); } private function runMkDatabase() { $base = $this->base; $system = $this->system; echo <<Prepare Database

Establish database connection and install tables.

EOF; if (!$this->testBasedir()) { return; } $files = array( 'etc-default/table.xml', ); $this->copy($files); // test database credentials if (empty($this->post['dbhost']) || empty($this->post['dbdb']) || empty($this->post['dbuser']) || empty($this->post['dbpassword']) ) { echo << Some of your database credentials are missing, please fill the form.

EOF; return; } echo "

Verify database config

\n"; flush(); $dbhost = $this->post['dbhost']; $dbdb = $this->post['dbdb']; $dbuser = $this->post['dbuser']; $dbpassword = $this->post['dbpassword']; $this->dbc = @new mysqli($dbhost, $dbuser, $dbpassword, $dbdb); if ($this->dbc->connect_error) { echo '

Error connection to database: ' . $this->dbc->connect_error . '

'; 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 echo "

Write database config to "etc-default/config.xml"

\n"; flush(); $config = file_get_contents($this->base . '/etc-default/config.xml'); $db = << $dbhost $dbhost $dbpassword $dbpassword table EOF; $config = preg_replace('/(\s+?).*<\\/db>/ms', $db, $config); file_put_contents($this->base . '/etc-default/config.xml', $config); // source table.sql echo "

Create tables using "$system/doc/table.sql"

\n"; flush(); if ($this->dbc->query('DESC wbuser')) { echo << It looks like some wombat tables aready exist. Please verify tables.

EOF; return; } $source = file_get_contents($this->system . '/doc/table.sql'); if (!$this->dbc->multi_query($source)) { echo << Failed to source "$system/doc/table.sql".

EOF; return; } } private function runMkCMS() { $base = $this->base; echo <<Make CMS

Prepare everything to use CMS.

EOF; if (!$this->testBasedir()) { return; } $folders = array( 'etc-default/xinha', 'etc-default/wxml', 'template/Wxml', 'template/Xinha', 'template/Xinha/dialog', 'template/Xinha/dialog/', 'template/Xinha/dialog/smiley', 'template/Xinha/dialog/specialchar', 'template/Xinha/dialog/url', 'template/Xinha/dialog/vfsfile', ); $this->mkDir($folders); $files = array( 'etc-default/wxml/config.xml', 'etc-default/wxml/form/edit.xml', 'etc-default/wxml/form/translate.xml', ); $this->copy($files); } private function runMkVFS() { $base = $this->base; echo <<Make VFS

Prepare everything to use VFS

EOF; if (!$this->testBasedir()) { return; } } /** * create folders * * * @param array $folders */ private function mkDir($folders = array()) { echo '

Create folders

'; echo '
    '; foreach ($folders as $f) { echo '
  • ' . $f . '
  • '; flush(); if (is_dir($this->base . '/' . $f)) { continue; } mkdir($this->base . '/' . $f); chmod($this->base . '/' . $f, 0777); } echo '
'; } /** * copy bunch of files * * * @param array $files */ private function copy($files = array()) { echo '

Copy files

'; echo '
    '; foreach ($files as $f) { echo '
  • ' . $f . '
  • '; flush(); if (file_exists($this->base . '/' . $f)) { continue; } copy($this->system . '/' . $f, $this->base . '/' . $f); chmod($this->base . '/' . $f, 0666); } echo '
'; } /** * check whether basedir is set up properly * * @return bool true on success */ private function testBasedir() { if (!is_dir($this->base) || !is_writeable($this->base)) { echo << BASEDIR does not exist, or is not writeable. Use make basedir first.

EOF; return false; } return true; } } $mkw = new MKWombat(); $mkw->setPost($_REQUEST); $mkw->run(); ?>