Joomla! Discussion Forums



It is currently Wed Nov 25, 2009 4:11 pm (All times are UTC )

 




Post new topic Reply to topic  [ 11 posts ] 
Author Message
Posted: Fri Nov 06, 2009 8:07 am 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
A friend of mine is putting together a plug in for me for my site. This works by entering a reference in an article so that it appears against it.

However looking at the tutorial and examples + trying to find answers in the documantation, we are struggling to get the reference to appear where ever it is enter in that article. Instead because we have tried OnBeforeContent event and OnAfterContent event these just make it appear either at the top or bottom of the article.

Which event is needed to achieve the above?

_________________
Regards

TimCS


Top
   
 
Posted: Fri Nov 06, 2009 8:35 am 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Fri Aug 12, 2005 3:47 pm
Posts: 11688
Location: **Translation Matters**
Have you tried onPrepareContent ?

_________________
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.
---------------------------------
Joomla! Translation Coordination Team


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 11:23 am 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
infograf768 wrote:
Have you tried onPrepareContent ?



I may be doing some wrong here because when I use OnPrepareContent , I get no image now in the article (which is what replaces the reference that is entered)

We are doing :

Code:
$mainframe->registerEvent('onPrepareContent', 'pluginFunction');

Followed by :
Code:
function pluginfunction (&$article, &$params, $limitstart=0)


Is this right?

_________________
Regards

TimCS


Top
   
 
Posted: Fri Nov 06, 2009 11:33 am 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Fri Aug 12, 2005 3:47 pm
Posts: 11688
Location: **Translation Matters**
( &$row, &$params, $page=0 )

_________________
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.
---------------------------------
Joomla! Translation Coordination Team


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 11:57 am 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
infograf768 wrote:
( &$row, &$params, $page=0 )



I have changed the pluginfunctions to the above but now the reference that is entered in the article is being displayed instead of the image, I assume this is down to the return value which currently

return $output

_________________
Regards

TimCS


Top
   
 
Posted: Fri Nov 06, 2009 4:30 pm 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Fri Aug 12, 2005 3:47 pm
Posts: 11688
Location: **Translation Matters**
Difficult to help more without knowing what exactly this plugin is supposed to do.
Can you attach here?

_________________
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.
---------------------------------
Joomla! Translation Coordination Team


Top
  E-mail  
 
Posted: Sat Nov 07, 2009 11:50 am 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
The plug in is replacing a reference {rating}<number>{/rating} with a set of images. On the first attempt the code was set to this at the start:

Code:
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');

$mainframe->registerEvent('onBeforeDisplayContent', 'getRating');

global $css_added;

function getRating (&$article, &$params, $limitstart=0)
{
  /** start of function **/
}


But this just put the rating at the top of the article whereas I need it to be where ever the reference is placed within the article.

Then we changed it thinking you meant us to do this :

Code:
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');

$mainframe->registerEvent('onPrepareContent', 'getRating');

global $css_added;

function getRating (&$article, &$params, $limitstart=0)


You then pointed out that the parameters for the function should be
Code:
( &$row, &$params, $page=0 )
so we changed it to this :

Code:
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');

$mainframe->registerEvent('onPrepareContent', 'getRating');

global $css_added;

function getRating ( &$row, &$params, $page=0 )



However this just showed the reference e.g. {rating}4{/rating} instead of the images on the page.

So is it a case of actually using the OnPrepareContent function in the plugin and then within that, have the code to find and replace the e.g. {rating}5{/rating} to an image?

_________________
Regards

TimCS


Top
   
 
Posted: Sat Nov 07, 2009 12:47 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Online

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7681
Location: Europe
Did you enable the plugin as well?
Did you install the plugin? Or did you just copy the files to the server?

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Sat Nov 07, 2009 5:19 pm 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Fri Aug 12, 2005 3:47 pm
Posts: 11688
Location: **Translation Matters**
Quote:
So is it a case of actually using the OnPrepareContent function in the plugin and then within that, have the code to find and replace the e.g. {rating}5{/rating} to an image?

Yes, call the regex then one can use a replacer or do it directly in the function.
Look at the way core content plugins are made.

Example with a simple replacer
Code:
function getRating ( &$row, &$params, $page=0 )
{
// simple performance check to determine whether plugin should process further
   if ( JString::strpos( $row->text, 'rating' ) === false ) {
      return true;
   }   
// Get plugin info
   $plugin =& JPluginHelper::getPlugin('content', 'getrating');

   // define the regular expression for the plugin
   $regex = "#{rating}(.*?){/rating}#s";
   
$pluginParams = new JParameter( $plugin->params );

   // check whether plugin has been unpublished
   if ( !$pluginParams->get( 'enabled', 1 ) ) {
   $row->text = preg_replace( $regex, '', $row->text );
return true;
}

   // perform the replacement
   $row->text = preg_replace_callback( $regex, 'getRating_replacer', $row->text );

   return true;
}

function getRating_replacer ( &$matches) {
$plugin =& JPluginHelper::getPlugin('content', 'getrating');
$pluginParams = new JParameter( $plugin->params ); // if you have parameters
$rate = $matches[1];
if ($rate == 1) {
$text=...
} else if...

etc.
}
return $text;
}

Hope this helps.

_________________
Jean-Marie Simonet / infograf · http://www.info-graf.fr · GMT +1
Qui vult dare parva non debet magna rogare.
---------------------------------
Joomla! Translation Coordination Team


Top
  E-mail  
 
Posted: Sat Nov 07, 2009 9:36 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
Quote:
Did you enable the plugin as well?
Did you install the plugin? Or did you just copy the files to the server?


I did enable the plugin and I installed it from a zip file with all the required files inside that zip file using the administrator plug in install method. Its the same as i would do any other component,module,plugin if that helps.


infograf768 wrote:
Quote:
So is it a case of actually using the OnPrepareContent function in the plugin and then within that, have the code to find and replace the e.g. {rating}5{/rating} to an image?

Yes, call the regex then one can use a replacer or do it directly in the function.
Look at the way core content plugins are made.

Example with a simple replacer
Code:
function getRating ( &$row, &$params, $page=0 )
{
// simple performance check to determine whether plugin should process further
   if ( JString::strpos( $row->text, 'rating' ) === false ) {
      return true;
   }   
// Get plugin info
   $plugin =& JPluginHelper::getPlugin('content', 'getrating');

   // define the regular expression for the plugin
   $regex = "#{rating}(.*?){/rating}#s";
   
$pluginParams = new JParameter( $plugin->params );

   // check whether plugin has been unpublished
   if ( !$pluginParams->get( 'enabled', 1 ) ) {
   $row->text = preg_replace( $regex, '', $row->text );
return true;
}

   // perform the replacement
   $row->text = preg_replace_callback( $regex, 'getRating_replacer', $row->text );

   return true;
}

function getRating_replacer ( &$matches) {
$plugin =& JPluginHelper::getPlugin('content', 'getrating');
$pluginParams = new JParameter( $plugin->params ); // if you have parameters
$rate = $matches[1];
if ($rate == 1) {
$text=...
} else if...

etc.
}
return $text;
}

Hope this helps.


Cheers for this help infograf768, I know my friend has done a similar thing but I not sure if it is exactly as you have done here. I am sure this will help , thanks again for your help.

_________________
Regards

TimCS


Top
   
 
Posted: Wed Nov 11, 2009 4:24 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Wed Jan 16, 2008 10:13 am
Posts: 62
Just an update for all who helped here, my friend as now resolved this part of the problem and has gone on to improve this further.

He may soon , once completed, add this to the extentions directory so look out for it ! :)

_________________
Regards

TimCS


Top
   
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

Quick reply

 



Who is online

Users browsing this forum: becyn, hnavarro, ianmac, Matrix818181, MrTripi, phee and 41 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group