Kunena Plugin (revamped)

John_Strambo

New Member
Hello, i am a total noob at PHP but i know a little bit of C/C++ and debugging apps so, because i made our clan website that required applications and we are running kunena, I took the liberty of quickly setting up eclipse and xdebug to check what was going on there (i dont know anything about version control etc so i'm posting all my finding and mods here:

PHP:
<?php

/**
 * Creates a thread in kunena forum
 * @package Joomla
 * @subpackage Fabrik
 * @author Rob Clayburn
 * @copyright (C) Rob Clayburn
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();


//require the abstract plugin class
require_once(COM_FABRIK_FRONTEND.DS.'models'.DS.'plugin-form.php');

class plgFabrik_FormKunena extends plgFabrik_Form {

	var $vb_forum_field = '';
	var $vb_path = '';
	var $vb_globals = '';

	/**
	 * process the plugin, called when form is submitted
	 *
	 * @param object $params
	 * @param object form
	 */

	function onBeforeStore(&$params, &$formModel)
	{		
		//return;		
		jimport('joomla.filesystem.file');
		//$files[]  = COM_FABRIK_BASE.'administrator'.DS.'components'.DS.'com_kunena'.DS.'language'.DS.'kunena.english.php';
		$files[] = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'class.kunena.php';
		$define = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.defines.php';
		$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.defines.php';
		//$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.session.class.php';
		$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.link.class.php';
		$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.link.class.php';
		//$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'template'.DS.'default'.DS.'smile.class.php';
		$files[]  = COM_FABRIK_BASE.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.smile.class.php';
		if (!JFile::exists($define)) {
			return JError::raiseError(500, 'could not find the Kunena component');
		}
		require_once($define);
		foreach ($files as $file) {
			require_once($file);
		}
		
		//if (JFile::exists(KUNENA_ABSTMPLTPATH . '/post.php')) {
		//	$postfile = KUNENA_ABSTMPLTPATH . '/post.php';
		//}
		if (JFile::exists(KUNENA_PATH_FUNCS . '/post.php')) {
			$postfile = KUNENA_PATH_FUNCS . '/post.php';
		}
		else {
			$postfile = KUNENA_PATH_TEMPLATE_DEFAULT .DS. 'post.php';
		}
		$w = new FabrikWorker();
		
		//$fbSession = CKunenaSession::getInstance();
		//dont need this, session is loaded in CKunenaPost


		$catid =$params->get('kunena_category', 0);
		$parentid = 0;
		$action = 'post';
		//added action in request
		JRequest::setVar('action',$action);
		$func = 'post';
		$contentURL = 'empty';
		JRequest::setVar('catid', $catid);
		$msg = $w->parseMessageForPlaceHolder($params->get('kunena_content'), $formModel->_fullFormData);
		$subject = $params->get('kunena_title');
		JRequest::SetVar('message', $msg);
		$subject = $w->parseMessageForPlaceHolder($subject, $formModel->_fullFormData);
		//added subject in request
		JRequest::SetVar('subject', $subject);
		$origId = JRequest::getVar('id');
		JRequest::setVar('id', 0);
		/*
		ob_start();
		include ($postfile);
		ob_end_clean();
		*/
		ob_start();
		include ($postfile);
		$mypost = new CKunenaPost();
		$mypost->display(); //it will call post() if action is 'post'
		ob_end_clean();
		JRequest::setVar('id', $origId);
	}

}
?>

with this mods i am able to get a post in the forum on form submit using Joomla 2.5/Fabrik 3.0.5.2/Kunena 1.7.2

The only part that is quite obscure to me (remeber, PHP noob here) is the necessity of ob_start(); ob_end_clean(); or not.
 
I also verified that the CKunenaPost->post() method at the end redirect to the forum in the post it just posted. This somehow interrupt processing of other Fabrik plugins (i.e. I had email notification on form submit).

I changed the function from onBeforeStore to onAfterProcess in fabrik plugin kunena.php file and it fixed it. Now i am receiving application mail notification and a post is created in the forum.
Also some other trick to use if you wanna display username in post title is not to use the placeholder for the username stored in your fabrik list(e.g. {yourtable___user_name} set as plugin user and option username if you are for any reasons storing it) but use the placeholder {$my->username}
 
I know nothing about Kunena.

Is 1.7.2 the current version?

Do we know how backward compatible your fix is with previous versions?

-- hugh
 
1.7.2 is the most current stable release.

I downloaded kunena packages 1.5 and 1.6 and for what i could see from the former kunena fabrik plugin it was crafted for 1.5 (i.e. post.php was in the template folder, there was a dedicated Session php file, etc).

My implementation should work from 1.6 up as files position, new classes implementation, etc, are the same among 1.6 to 1.7.2
 
can you either post a pull request via git hub, or attach all the code as a zip in this thread so I can update

thx
Rob
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top