Jump To …

PivotX.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_PivotX 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://pivotx.net/files/pivotx_latest.zip',
            array(
                '*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

In this step, permissions for /pivotx/db is changed 777 recursively.

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

In this step, permissions for pivotx/templates is changed 777 recursively.

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

In this step, permissions for pivotx/images is changed 777 non-recursively.

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

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

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

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

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

                'pass1' => $parameters['password'],

$parameters['password2'] refers to value entered in the Password (Repeat) Field before the actual installation process starts.

                'pass2' => $parameters['password2'],

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

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

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

                'nickname' => $parameters['nickname'],
                'language' => 'en',
                'db_model' => 'mysql',

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

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

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

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

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

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

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

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

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

                'db_prefix' => 'pivotx_',
            ),
            array(),
            array()
        );

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

        if (strpos(
            $curl_exec[1], 'You can login with your new account now'
        ) !== 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 validates the username. Here the function is checking whether username contains any special characters.

    public function getCallback($contents)
    {
        if (preg_match('#[A-Z]#', $contents)) {
            return false;
        }
        if (preg_match('#[`\-=\[\]\;\',./~!@\#$%^&*()+{}|:"<>?]#', $contents)) {
            return false;
        }

        return true;
    }

This function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('Blogs');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('PivotX is a blogging tool and also a great tool to maintain more complex websites as well. Its powerful core and flexible template system make it easy for developers to adjust and extend. No matter if you want an easy-to-use, robust blogging tool or are looking to push things to the max - PivotX offers the best of both worlds.');
    }

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)
    {
        $lib_php = sprintf(
            '%s/%s/pivotx/lib.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($lib_php)) {
            return false;
        }
        $contents = file_get_contents($lib_php);

This statemnt performs a regular expression match on version of the installed copy on the contents of lib.php file.

        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 username textfield (and is mandatory).

        $form->addElement('text', 'username', array(
            'description' => sprintf(_('minimum %d characters; can only contain lowercase letters and digits and underscores'), 2),
            'label' => _('Username'),
            'required' => true,
            'validators' => array(

This validator statement checks whether username field contains minimum two charaters.

                array('StringLength', false, array(
                    'min' => 2,
                )),

This validator statement checks whether username field contains any special characters by calling getCallback function which is written above.

                array('Callback', false, array(
                    'callback' => array($this, 'getCallback'),
                )),
            )
        ));

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

        $form->addElement('password', 'password', array(
            'description' => sprintf(_('minimum %d characters'), 4),
            'label' => _('Password'),
            'required' => true,
            'validators' => array(

This validator statement checks whether password field contains minimum four charaters.

                array('StringLength', false, array(
                    'min' => 4,
                )),
            )
        ));

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

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

This statement adds the email (and is mandatory).

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

        $form->addElement('text', 'nickname', array(
            'description' => sprintf(_('minimum %d characters'), 2),
            'label' => _('Nick Name'),
            'required' => true,
            'validators' => array(

This validator statement checks whether password field contains minimum two charaters.

                array('StringLength', false, array(
                    'min' => 2,
                )),
            )
        ));

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 username, password, password2, email and nickname under the display group Administrator Details.

        $form->addDisplayGroup(
            array('username', 'password', 'password2', 'email', 'nickname'),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator 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://emagazine.aboutblank.nl/images/pivotx.png';
    }

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

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

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/pivotx" target="_blank">http://%s/%s/pivotx</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['username']),
                sprintf(_('Password: %s'), $parameters['password']),
            ),

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 4.1.

            'MySQL 4.1+' => (preg_match(
                '#Distrib\s*(4\.1|5)#', $mysql
            ) === 1)? true: false,

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

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

This statement checks whether GD 2 extension is enabled or not for the installed version of PHP.

            'PHP :: gd 2' => (preg_match(
                '#GD Version\s*=>\s*bundled\s*\(2|GD Support\s*=>\s*enabled#',
                $php
            ) === 1)? true: false,

This statement checks whether safe_mode directive in php_ini is set to Off or not

            'PHP :: safe_mode = Off' => (preg_match(
                '#^(safe_mode\s*=>\s*On|safe_mode\s*=>\s*on|safe_mode\s*=>\s*1)#',
                $php
            ) === 0)? true: false,

This statement checks whether PCRE extension is enabled or not for the installed version of PHP.

            'PHP :: pcre' => (preg_match(
                '#PCRE \(Perl Compatible Regular Expressions\) Support\s*=>\s*enabled#',
                $php
            ) === 1)? true: false,

This statement checks whether open_basedir directive in php_ini is set to empty or not

            'PHP :: open_basedir = \'\'' => (preg_match(
                '#(open_basedir\s*=>\s*\'\'|open_basedir\s*=>\s*no value)#',
                $php
            ) === 1)? true: false,
        );
    }

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

    public function getSize()
    {
        return 7993139;
    }

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

    public function getSlug()
    {
        return 'pivot-x';
    }

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://pivotx.net',
            _('Documentation') => 'http://pivotx.net/page/documentation',
            _('Support') => 'http://forum.pivotx.net',
        );
    }

This function provides the version (and is mandatory).

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

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

        $ser_config_php = sprintf(
            '%s/%s/pivotx/db/ser_config.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($ser_config_php)) {
            return false;
        }

This statement fetches the contents of ser_config.php

        $contents = file_get_contents($ser_config_php);

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

        preg_match('#db_databasename";s:27:"([^"]*)#', $contents, $database);

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

        preg_match('#db_username";s:4:"([^"]*)#', $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);
    }
}