Forums

Handling 'Extra' codes in plugins

GreyHead 13 Jun, 2009
This has been partly implemented in some plugins (others have boxes that do not function).

NB Some parameters were 'extras2' and others were 'extra2' - have standardised on 'extra2'

I have added saving and restoring code for all 10 'Extra code' boxes to the Plugin Helper. This should work automatically if the helper save_conf function is called by the plugin.

NB Array values are converted into 'ini' style strings before saving.

Load code from helpers/plugin.php is
// initialise extras
$extras = range(1, 10);
foreach ($extras as $k => $v ) {
    $extras[$k] = "extra$v";
}
foreach ( $extras as $extra ) {
    $$extra = new JParameter($row->$extra);
}

Save function is
    function save_conf( $option )
    {
        global $mainframe;

        //$db =& JFactory::getDBO();
        $post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );

        $row =& JTable::getInstance('chronocontactplugins', 'Table');
        if ( !$row->bind( $post ) ) {
            JError::raiseWarning(100, $row->getError());
            $mainframe->redirect( "index2.php?option=$option" );
        }

        $params = JRequest::getVar( 'params', '', 'post', 'array', array(0) );
        //$mainframe->enqueuemessage(print_r($params, true));
        if ( is_array( $params ) ) {
            $txt = array();
            foreach ( $params as $k => $v ) {
                if ( is_array($v) ) {
                    $v = implode('|', $v);
                }
                if ( $v ) {
                    $txt[] = "$k=$v";
                }
            }
            $row->params = implode( "\n", $txt );
        }
        // process extras
        $extras = range(1, 10);
        foreach ($extras as $k => $v ) {
            $extras[$k] = "extra$v";
        }
        foreach ( $extras as $extra ) {
            $value = JRequest::getVar( $extra, '', 'post' );
            //$mainframe->enqueuemessage('Value: '.print_r($value, true));
            if ( is_array( $value ) ) {
                $txt = array();
                foreach ( $value as $k => $v) {
                    if ( $v ) {
                        $txt[] = "$k=$v";
                    }
                }
                $row->$extra = implode( "\n", $txt );
            }
           }
        //$mainframe->enqueuemessage(print_r($row, true));
        if ( !$row->store() ) {
            JError::raiseWarning(100, $row->getError());
            $mainframe->redirect( "index2.php?option=$option" );
        }

        $mainframe->redirect( "index2.php?option=".$option, "Config Saved" );
        $row =& JTable::getInstance('chronocontactplugins', 'Table');
    }
This topic is locked and no more replies can be posted.