text)) { $article->text = preg_replace_callback($regex, 'plgContentChronoforms::_processForm', $article->text); } else { $article->text = ''; } //check after text forms if ($context == "com_content.article") { $after_text = trim($this->params->get('after_text_forms')); if(!empty($after_text)) { $details = explode("\n", $after_text); foreach($details as $detail) { $form_details = explode("=", $detail); if(count($form_details) == 2 && !empty($form_details[1])) { $cats = explode(',', $form_details[1]); foreach($cats as $cat) { if($cat == $article->catid) { $article->text = $article->text . plgContentChronoforms::_displayForm($form_details[0]); } } } } } } return true; } protected function _processForm($matches){ if(isset($matches[1]) && !empty($matches[1])){ $formname = $matches[1]; return _displayForm($formname); } } protected function _displayForm($formname){ //load chronoforms classes require_once(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'chronoforms.html.php'); require_once(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'libraries'.DS.'chronoform.php'); $form = CFChronoForm::getInstance($formname, true); if(empty($form->form_name)){ return "There is no form with this name or may be the form is unpublished, Please check the form and the url and the form management."; } $event = JRequest::getVar('event'); if(empty($event)){ $event = 'load'; } $form->process($event); ob_start(); HTML_ChronoForms::processView($form); $output = ob_get_clean(); return $output; }}?>"> chronoform plugin, wanted to give something back. - Forums

Forums

chronoform plugin, wanted to give something back.

mgoeben 04 Aug, 2011
Hi!

Just wanted to give something back. I rewrote the plugin to match actual coding for Joomla 1.7.

Notice the check for $context = "com_content.article", because in featured and category views not the full article object is loaded instead it just holds only the introtext without any further information like cat_id, ...

This problem occurs if you use formname=1,2,3 as plugin param.

Thanks for the all the hard work you invested in chronoforms.

Regards

Marco

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

// Import Joomla! Plugin library file
jimport('joomla.plugin.plugin');

class plgContentChronoforms extends JPlugin
{
    function plgContentChronoforms( &$subject, $config )
    {
        parent::__construct( $subject, $config );
        $this->loadLanguage();
    }
    public function onContentPrepare($context, &$article, &$params, $page = 0)
    {
        // define the regular expression for the bot
        $regex = "#{chronoforms}(.*?){/chronoforms}#s";
        if(isset($article->text))
        {
            $article->text = preg_replace_callback($regex, 'plgContentChronoforms::_processForm', $article->text);
        }
        else
        {
            $article->text = '';
        }
        //check after text forms
        if ($context == "com_content.article")
        {
            $after_text = trim($this->params->get('after_text_forms'));
            if(!empty($after_text))
            {
                $details = explode("\n", $after_text);
                foreach($details as $detail)
                {
                    $form_details = explode("=", $detail);
                    if(count($form_details) == 2 && !empty($form_details[1]))
                    {
                        $cats = explode(',', $form_details[1]);
                        foreach($cats as $cat)
                        {
                            if($cat == $article->catid)
                            {
                                $article->text = $article->text . plgContentChronoforms::_displayForm($form_details[0]);
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    protected function _processForm($matches){
        if(isset($matches[1]) && !empty($matches[1])){
            $formname = $matches[1];
            return _displayForm($formname);
        }
    }

    protected function _displayForm($formname){
        //load chronoforms classes
        require_once(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'chronoforms.html.php');
        require_once(JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'libraries'.DS.'chronoform.php');
        $form = CFChronoForm::getInstance($formname, true);
        if(empty($form->form_name)){
            return "There is no form with this name or may be the form is unpublished, Please check the form and the url and the form management.";
        }
        $event = JRequest::getVar('event');
        if(empty($event)){
            $event = 'load';
        }
        $form->process($event);
        ob_start();
        HTML_ChronoForms::processView($form);
        $output = ob_get_clean();
        return $output;
    }
}
?>
This topic is locked and no more replies can be posted.