Jump To …

REDAXOCMS.php

We expect (but do not insist) the file to be PSR-compatible.

The name of the file must be $unique_name.php. If your name happens to be identical to another script, we will notify you and you must modify suitably.

The name of the class must be Netenberg_Script_$unique_name.

The class must derive from Netenberg_Script.

class Netenberg_Script_REDAXOCMS extends Netenberg_Script
{

This function is called as part of the actual installation process (Step 3).

$parameters is a dictionary that contains the values supplied by the user (Step 1) in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function install($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

This is an abstracted cURL object. You may use it for the sake of simplicity and also for ease of debugging. The full extent of this singleton is (will be made) available in the guide.

        $curl = new Netenberg_cURL;

You are encouraged to employ the usage of steps as follows:

 $step = 0;

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...
        $step = 0;

In this step, a fresh database is being created via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $parameters['mysql_hostname'],
            $parameters['mysql_username'],
            $parameters['mysql_password'],
            $parameters['mysql_database']
        ) = $control_panel->insertMySQL();

In this step, the source archive is being downloaded and extracted to the desired directory via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $operating_system->transpose(
            'http://www.redaxo.org/files/redaxo4_5_1.zip',
            array(
                '*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

In this step, permissions of redaxo directory has been changed to 777 i.e. read-write-execute permissions to all three user levels owner, group and others.

        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s/redaxo',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, true);
        }

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

In this step, permissions of files directory has been changed to 777 i.e. read-write-execute permissions to all three user levels owner, group and others.

        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s/files',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, true);
        }

$operating_system->mv() is a function used to move/rename file/folder. You can use any number of $operating_system->mv() statements as required or as specified in installation guidelenes. $operating_system->mv() takes only two mandatory argument path to source path to the destination

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

In this step, _htaccess is renamed to .htaccess.

        $operating_system->mv(sprintf(
            '%s/%s/_htaccess',
            $parameters['document_root'],
            $parameters['directory']
        ), sprintf(
            '%s/%s/.htaccess',
            $parameters['document_root'],
            $parameters['directory']
        ));

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $parse_url = parse_url(sprintf(
            'http://%s/%s', $parameters['domain'], $parameters['directory']
        ));
        $htaccess = sprintf(
            '%s/%s/.htaccess',
            $parameters['document_root'],
            $parameters['directory']
        );
        $contents = file_get_contents($htaccess);

In this step, we are editing parts of .htaccess file as required.

        $contents = preg_replace('#Options#', '# Options', $contents);

Here we are adding RewriteBase to make the script work in specific directory instead of document root.

        $contents = preg_replace(
            '#RewriteEngine on#',
            sprintf("RewriteEngine on\nRewriteBase %s", $parse_url['path']),
            $contents
        );
        file_put_contents($htaccess, $contents);

In this step, we invoke the REDAXOCMS installation wizard (step=2).

$curl->request is a function used to send Request to the URL. $curl->request() takes 5 arguments, i.e. URL to which request has to be sent, METHOD i.e. GET or POST, POSTFIELDS, which is present only for POST method, otherwise an empty array, HTTP HEADERS, and OPTIONS

Here we are making a GET Request to http://%s/%s/redaxo/index.php?checkmodus=0.5&lang=en_gb, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php?checkmodus=0.5&lang=en_gb',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

Here we are making a GET Request to http://%s/%s/redaxo/index.php?page=setup&checkmodus=1&lang=en_gb, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php?page=setup&checkmodus=1&lang=en_gb',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

Here we are making a GET Request to http://%s/%s/redaxo/index.php?page=setup&checkmodus=2&lang=en_gb, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php?page=setup&checkmodus=2&lang=en_gb',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

Here we are making a POST Request to http://%s/%s/redaxo/index.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'checkmodus' => '2',

$parameters['mysql_database'] refers to MySQL Database.

                'dbname' => $parameters['mysql_database'],

$parameters['error_email'] refers to value entered in the Email Field before the actual installation process starts.

                'error_email' => $parameters['error_email'],
                'lang' => 'en_gb',

$parameters['mysql_hostname'] refers to MySQL Hostname.

                'mysql_host' => $parameters['mysql_hostname'],
                'page' => 'setup',
                'psw_func' => '',

$parameters['mysql_username'] refers to MySQL Username.

                'redaxo_db_user_login' => $parameters['mysql_username'],

$parameters['mysql_password'] refers to MySQL Password.

                'redaxo_db_user_pass' => $parameters['mysql_password'],
                'send' => '1',
                'serveraddress' => sprintf('http://%s', $parameters['domain']),

$parameters['description'] refers to value entered in the Site Description Field before the actual installation process starts.

                'serverbezeichnung' => $parameters['description'],
            ),
            array(),
            array()
        );

Here we are making a POST Request to http://%s/%s/redaxo/index.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'page' => 'setup',
                'checkmodus' => '3',
                'send' => '1',
                'lang' => 'en_gb',
                'dbanlegen' => '0',
                'FORM[importfile]' => '',
            ),
            array(),
            array()
        );

Here we are making a POST Request to http://%s/%s/redaxo/index.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $curl_exec, $curl_errno, $curl_error, $curl_getinfo
        ) = $curl->request(
            sprintf(
                'http://%s/%s/redaxo/index.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'checkmodus' => '4',
                'lang' => 'en_gb',
                'page' => 'setup',

$parameters['user_login'] refers to value entered in the Username Field before the actual installation process starts.

                'redaxo_user_login' => $parameters['user_login'],

$parameters['user_pass'] refers to value entered in the Password Field before the actual installation process starts.

                'redaxo_user_pass' => $parameters['user_pass'],
                'send' => '1',
            ),
            array(),
            array()
        );

In this step, we check if the installation was successful.

        if (strpos($curl_exec[1], 'You did it') !== false) {

This indicates a success status (and is mandatory).

            log_('DEBUG', 'Success');

This allows the core system to register this installation within the user account (and is mandatory).

            return parent::install($parameters);
        }

This indicates a failure status (and is mandatory).

        log_('DEBUG', 'Failure');

        return false;
    }

This function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('Portals/CMS');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('REDAXO CMS is more than just a content management system. Due to the scope of services it can also be used for a variety of information management solutions under the REDAXO. GNU - GPL license and is allowed to be free and commercially used freely.');
    }

This function provides the details of an installed copy (and is mandatory).

$parameters is a dictionary that contains domain, directory, and document_root.

    public function getDetails($parameters)
    {
        $master_inc_php = sprintf(
            '%s/%s/redaxo/include/master.inc.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($master_inc_php)) {
            return false;
        }
        $contents = file_get_contents($master_inc_php);

This statemnt performs a regular expression match on version, subversion and minorversion of the installed copy on the contents of filefunc.inc.php file.

        preg_match('#\'VERSION\'\]\s*=\s*"(\d+)"#', $contents, $version);
        preg_match('#\'SUBVERSION\'\]\s*=\s*"(\d+)"#', $contents, $subversion);
        preg_match(
            '#\'MINORVERSION\'\]\s*=\s*"(\d+)"#', $contents, $minorversion
        );

        return array(
            'version' => sprintf(
                '%s.%s.%s', $version[1], $subversion[1], $minorversion[1]
            ),
        );
    }

This function builds the form presented to the user (Step 1) (and is mandatory). It is built upon the Zend_Form component of Zend Framework.

    public function getForm()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is an abstracted form object derived from Zend_Form. The full extent of this class is (will be made) available in the guide.

        $form = new Netenberg_Form();

This statement adds the domain selector (and is mandatory).

        $form->addElement('select', 'domain', array(
            'label' => _('Domain'),
            'multiOptions' => $control_panel->getDomains(),
            'required' => true,
        ));

This statement adds the directory selector (and is mandatory).

        $form->addElement('text', 'directory', array(
            'description' => _('Leave this field empty if you want to install in the web root for the domain you\'ve selected (i.e., http://domain.com/ ). If you\'d like to install in a subdirectory, please enter the path to the directory relative to the web root for your domain. The final destination subdirectory should not exist, but all others can exist (e.g., http://domain.com/some/sub/directory - In this case, "directory" should not already exist).'),
            'filters' => array(new Netenberg_Filter_Directory()),
            'label' => _('Directory'),
            'validators' => array(new Netenberg_Validate_Directory()),
        ));

This statement adds the username textfield (and is mandatory).

        $form->addElement('text', 'user_login', array(
            'label' => _('Username'),
            'required' => true,
        ));

This statement adds the password textfield (and is mandatory).

        $form->addElement('password', 'user_pass', array(
            'label' => _('Password'),
            'required' => true,
        ));

This statement adds the password repeat textfield (and is mandatory).

        $form->addElement('password', 'user_pass_', array(
            'label' => _('Password (Repeat)'),
            'required' => true,

This validator statement checks whether this field is identical to value of Password Textfield.

            'validators' => array(
                array('Identical', false, array(
                    'token' => 'user_pass',
                )),
            ),
        ));

This statement adds the email textfield (and is mandatory).

        $form->addElement('text', 'error_email', array(
            'label' => _('Email'),
            'required' => true,

This validator statement checks whether this field contains a valid Email Address.

            'validators' => array(
                array('EmailAddress', false),
            ),
        ));

This statement adds the description textfield (and is mandatory).

        $form->addElement('text', 'description', array(
            'label' => _('Site Description'),
            'required' => true,
        ));

This statement adds the Submit button to the form (and is mandatory).

        $form->addElement('button', 'submit');

This statement adds the Reset button to the form (and is mandatory).

        $form->addElement('button', 'reset');

This statement places the domain and directory selectors under the display group Location Details.

        $form->addDisplayGroup(
            array('domain', 'directory'),
            'location_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => 'Location Details',
            )
        );

This statement places the user_login, user_pass and userpass under the display group Administrator Details.

        $form->addDisplayGroup(
            array(
                'user_login',
                'user_pass',
                'user_pass_',
            ),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator Details'),
            )
        );

This statement places the description and error_email under the display group Other Details.

        $form->addDisplayGroup(
            array(
                'description',
                'error_email',
            ),
            'other_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Other Details'),
            )
        );

This statement places the Submit and Reset buttons at the end of the form.

        $form->addDisplayGroup(
            array('submit', 'reset'),
            'buttons',
            array(
                'decorators' => $form->getButtonGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
            )
        );

        return $form;
    }

This function provides the image (and is mandatory).

    public function getImage()
    {
        return 'http://www.redaxo.org/files/redaxo_logo_rz_2009.png';
    }

This function provides the name (and is mandatory). The name must be unique.

    public function getName()
    {
        return 'REDAXOCMS';
    }

This function provides the post-installation overview (and is mandatory).

$parameters is a dictionary that contains the values supplied by the user like domain, directory and username and/or password and/or email etc.

    public function getItems($parameters)
    {
        return array(
            _('Backend') => array(

This statement provides the URL for Backend page. Backend page is a login-page which is used to login into Administrator's Account.

                sprintf(
                    '<a href="http://%s/%s/redaxo" target="_blank">http://%s/%s/redaxo</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['user_login']),
                sprintf(_('Password: %s'), $parameters['user_pass']),
            ),
        );
    }

This function provides the requirements (and is mandatory).

    public function getRequirements()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

        $apache = $control_panel->getApache();
        $mysql = $control_panel->getMySQL();
        $php = $control_panel->getPHP();

        return array(

This statement checks whether enough space is available in your account to install this script.

            'Disk Space' => (
                $control_panel->getSize() >= $this->getSize()
            )? true: false,

This statement checks whether installed Apache's version is greater than 1.

            'Apache 1+' => (
                strpos($apache, 'Apache/1') !== false
                or
                strpos($apache, 'Apache/2') !== false
            )? true: false,

This statement checks whether mod_rewrite is enabled in the installed copy of Apache.

            'Apache :: mod_rewrite' => true,

This statement checks whether installed MySQL's version is greater than 5.0.7.

            'MySQL 5.0.7+' => (preg_match(
                '#Distrib\s*(5\.0\.[7-9]|5\.0\.[1-9][0-9]|5\.[1-9])#', $mysql
            ) === 1)? true: false,

This statement checks whether installed PHP's version is greater than 4.3.2

            'PHP 4.3.2+' => (preg_match(
                '#PHP Version\s*=>\s*(4\.3\.[2-9]|4\.4|5)#', $php
            ) === 1)? true: false,
        );
    }

This function provides the size (in bytes) (and is mandatory).

    public function getSize()
    {
        return 7025459;
    }

This function provides the slug (and is mandatory). The slug must be unique.

    public function getSlug()
    {
        return 'redaxo-cms';
    }

This function provides the URLs (and is mandatory).

We expect (but do not insist) URLs for four pages to be part of the array. They are URLs of Home, Community, Documentation and Support or Forum Pages.

    public function getUrls()
    {
        return array(
            _('Home') => 'http://www.redaxo.org',
            _('Documentation') => 'http://www.redaxo.org/de/wiki',
            _('Support') => 'http://www.redaxo.org/de/forum',
        );
    }

This function provides the version (and is mandatory).

    public function getVersion()
    {
        return '4.5.1';
    }

This function is called as part of the actual uninstallation process

$parameters is a dictionary that contains the values supplied by the user in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function uninstall($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

        $master_inc_php = sprintf(
            '%s/%s/redaxo/include/master.inc.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($master_inc_php)) {
            return false;
        }
        $contents = file_get_contents($master_inc_php);

This statement performs a regular expression match to fetch database name from the contents of master.inc.php

        preg_match(
            '#\'1\'\]\[\'NAME\'\]\s*=\s*\'([^\']*)#', $contents, $database
        );

This statement performs a regular expression match to fetch database username from the contents of master.inc.php

        preg_match(
            '#\'1\'\]\[\'LOGIN\'\]\s*=\s*\'([^\']*)#',
            $contents,
            $mysql_username
        );

In this step, we remove the database via the control panel singleton.

        $control_panel->deleteMySQL($mysql_username[1], $database[1]);

        $operating_system->dispose(sprintf(
            '%s/%s', $parameters['document_root'], $parameters['directory']
        ));

This allows the core system to unregister this installation within the user account (and is mandatory).

        return parent::uninstall($parameters);
    }
}