Jump To …

Chive.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_Chive 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');

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, 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(
            'https://launchpadlibrarian.net/121321185/chive_1.2.tar.gz',
            array(
                'chive/*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

$operating_system->chmod() used to set permissions

You can write any number of chmod statements as required or as instructed in the installation guidelines $operating_system->chmod() fucntion takes three mandatory arguments. path to the specified file/folder, permissions i.e 777 for directory or may be 666 or 644 for a file etc., and true (for recursive) or false (for non-recursive).

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

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s/assets',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, true);
        }

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s/protected',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, true);
        }

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

parse_url function parses an URL and return its components

        $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);

The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.

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

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

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 function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('DB Tools');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('Chive is a free, open source, web-based database management tool, designed to bring joy to web developers - with easy administration, super fast UI and state of the art web technologies.');
    }

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)
    {
        $main_php = sprintf(
            '%s/%s/protected/config/main.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($main_php)) {
            return false;
        }
        $contents = file_get_contents($main_php);
        preg_match('#version\'\s*=>\s*\'([^\']*)#', $contents, $version);

        return array(
            'version' => $version[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 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 Submit and Reset buttons in 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.chive-project.com/style/images/logo-big.png';
    }

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

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

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(

This statement provides the URL for Backend page.

            _('Backend') => array(
                sprintf(
                    '<a href="http://%s/%s" target="_blank">http://%s/%s</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
            ),
        );
    }

This function provides the requirements (and is mandatory).

    public function getRequirements()
    {
        $control_panel = Zend_Registry::get('control_panel');
        $apache = $control_panel->getApache();
        $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 2.

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

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

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

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

    public function getSize()
    {
        return 2120764;
    }

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

    public function getSlug()
    {
        return 'chive';
    }

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.chive-project.com',
        );
    }

This function provides the version (and is mandatory).

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

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.

In this step, we remove the directory via the operating system singleton.

        $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);
    }
}