Jump To …

limny.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_limny 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.limny.org/releases/limny-3.3.2.tar.bz2',
            array(
                'limny-3.3.2/*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

In this step, permissions for whole installation directory is changed 777 recursively.

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

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

parse_url parses URL and gives 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);

Here we are adding RewriteBase statement to .htaccess inorder to make the installation work in a specific directory instead of Document Root.

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

In this step we are making a POST Request to the URL http://%s/%s/install/install.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/install.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/install.php?s=2, where %s refer to domain and directory respectively.

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

In this step we are making a POST Request to the URL http://%s/%s/install/install.php?s=3, 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/install/install.php?s=3',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'next' => 'Next Step',
                's' => '3',
            ),
            array(),
            array()
        );

This statement performs a regular expression match to fetch value of the Hidden Input Field named db_file which is required in the next POST Request

        preg_match(
            '#input\s*name="db_file"\s*type="text"\s*value="([^"]*)#',
            $curl_exec[1],
            $sqlite
        );

In this step we are making a POST Request to the URL http://%s/%s/install/install.php?s=3, 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/install/install.php?s=3',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(

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

                'ad_email' => $parameters['ad_email'],

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

                'ad_pass' => $parameters['ad_pass'],

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

                'ad_user' => $parameters['ad_user'],

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

                'cf_header' => $parameters['cf_header'],
                'cf_site' => sprintf(
                    'http://%s/%s',
                    $parameters['domain'],
                    $parameters['directory']
                ),

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

                'cf_title' => $parameters['cf_title'],

$sqlite[1] is the value of the input field db_file which is fetched in the previous step.

                'db_file' => $sqlite[1],

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

                'db_host' => $parameters['mysql_hostname'],

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

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

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

                'db_pass' => $parameters['mysql_password'],

limny_ is the table prefix prefixed with names of MySQL tables which will be created during installation.

                'db_tblpr' => 'limny_',

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

                'db_user' => $parameters['mysql_username'],
                'install' => 'Install',
                's' => '2',
                'type' => 'mysql',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/install.php?s=4, 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/install/install.php?s=4',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'join' => 'no',
                'next' => 'Next Step',
                's' => '4',
            ),
            array(),
            array()
        );

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

        if (strpos($curl_exec[1], 'Thank you for installing Limny') !== false) {

In this step, we are removing install directory as instructed in the Installation Guidelines.

            log_('DEBUG', sprintf(_('Step %d'), ++$step));
            $operating_system->rm(sprintf(
                '%s/%s/install',
                $parameters['document_root'],
                $parameters['directory']
            ), true);

In this step we are modifying functions.php

            log_('DEBUG', sprintf(_('Step %d'), ++$step));
            $functions_php = sprintf(
                '%s/%s/incs/functions.php',
                $parameters['document_root'],
                $parameters['directory']
            );
            $contents = file_get_contents($functions_php);
            $contents = preg_replace(
                '#str_replace\(\$_SERVER\[\'DOCUMENT_ROOT\'\],\s*\'\',\s*__PATH__\)#',
                sprintf('\'%s\'', $parse_url['path']),
                $contents
            );
            file_put_contents($functions_php, $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 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 _('Limny is a free and open-source content management framework with a focus on ease to use and develop. It can be used as a stable and powerful core for heavy and light web applications by having main features of web applications such as user and roles management, multilingual system and multiple theme support. Also its rich graphic library helps designers to create colorable themes instead of designing multiple themes.');
    }

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)
    {

In some scripts, version is specified in the some table in the database. Then we have to access that version from database using mysqli_Query built-in function.

        $config_php = sprintf(
            '%s/%s/config.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        $contents = file_get_contents($config_php);

Here we are performing regular expression matching to fetch MySQL Hostname from contents of config.php

        preg_match(
            '#hostname\'\s*=>\s*\'([^\']*)#', $contents, $mysql_hostname
        );

Here we are performing regular expression matching to fetch MySQL Database from contents of config.php

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

Here we are performing regular expression matching to fetch MySQL Username from contents of config.php

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

Here we are performing regular expression matching to fetch MySQL Password from contents of config.php

        preg_match(
            '#password\'\s*=>\s*\'([^\']*)#', $contents, $mysql_password
        );

This statement establishes connection to MySQL using mysqli_connect built-in function.

        $mysqli_connect = mysqli_connect(
            $mysql_hostname[1],
            $mysql_username[1],
            $mysql_password[1]
        );
        if (!$mysqli_connect) {
            return false;
        }

This statement selects the specific database.

        mysqli_select_db($mysqli_connect, $mysql_database[1]);

This statement queries limny_config table to fetch version using **mysqli_query built-in fnction.

        $value = mysqli_query(
            $mysqli_connect,
            "SELECT value FROM limny_config where name='version'"
        );

mysqli_fetch_array is a built-in function which fetches a result row as an associative array

        $value = mysqli_fetch_assoc($value);

This statement closes the previously established MySQL connection.

        mysqli_close($mysqli_connect);

        return array(
            'version' => $value['value'],
        );
    }

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', 'ad_user', array(
            'label' => _('Username'),
            'required' => true,
        ));

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

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

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

        $form->addElement('password', 'ad_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' => 'ad_pass',
                )),
            ),
        ));

This statement adds the email (and is mandatory).

        $form->addElement('text', 'ad_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 site title (and is mandatory).

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

This statement adds the site header (and is mandatory).

        $form->addElement('text', 'cf_header', array(
            'label' => _('Site Header'),
            '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 ad_user, ad_pass, adpass and ad_email under the display group Administrator Details.

        $form->addDisplayGroup(
            array(
                'ad_user',
                'ad_pass',
                'ad_pass_',
                'ad_email',
            ),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator Details'),
            )
        );

This statement places the cf_title and cite_header under the display group Other Deatils.

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

This statement places the Submit and Reset buttons at 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.limny.org/misc/logo.png';
    }

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

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

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 page is a login-page which is used to login into Administrator's Account.

            _('Backend') => array(
                sprintf(
                    '<a href="http://%s/%s/admin" target="_blank">http://%s/%s/admin</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['ad_user']),
                sprintf(_('Password: %s'), $parameters['ad_pass']),
            ),

This statement provides the URL for the Frontend page. Frontend page is a page which end-user can see when he/she opens the website.

            _('Frontend') => 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()
    {

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 installed MySQL's version is greater than 5.

            'MySQL 5.0+' => (
                strpos($mysql, 'Distrib 5') !== false
            )? true: false,

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

            '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 777830;
    }

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

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

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.limny.org',
            _('Documentation') => 'http://docs.limny.org',
        );
    }

This function provides the version (and is mandatory).

    public function getVersion()
    {
        return '3.3.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.

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

        $config_php = sprintf(
            '%s/%s/config.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($config_php)) {
            return false;
        }
        $contents = file_get_contents($config_php);

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

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

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

        preg_match(
            '#username\'\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]);

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