×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Problem with event onAfterDisplayContent

Problem with event onAfterDisplayContent 12 years 2 months ago #15019

  • YuriBtr
  • YuriBtr's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Hi Daniel,
I've updated Compojoom comment system from 4.1.7 to 4.2.1 and found that my custom code which put comment quantity to preview of each article doesn't work. Further investigations showed that problem is in event, in pas it was "onPrepareContent", now I see that you've changed it to "onAfterDisplayContent" (I have J1.5).
In past I triggered event "onPrepareContent" at "components/com_content/views/category/view.html.php" and all work fine. Now, even if I change triggering on "onAfterDisplayContent", it gives nothing... Many hours I spend on this problem. I'm in dead end...

Is it possible for me to revert your code back to using "onPrepareContent"? Thanks in advance.


P.S. I found your message, you wrote there "onAfterContent" - is it wrong or not? In your code there "onAfterDisplayContent".

Re: upgrade from 4.1.7 to 4.2 gives template problems

Hey Kristof,

In compojoomComment 4.1 the comments were outputted onPrepareContent. This means:
the plugin gets the article $row and we attach the comments to the end of it. This is all good, but in a lot of cases we get conflicts with plugins that are also executed onPrepareContent - the best example is the e-mail cloaking plugin. It was transforming the emails in the comment form...

Since the onPrepareContent event is used to make changes to the article and since we don't do any changes to the article the best event for the comments is onAfterContent... And compojoomComment 4.2 does exactly this.

Now with your specific template the onAfterContent event is displayed way below after your article. What you need to do is a template override and move the <?php echo $this->onAfterContent; ?> tag to the place where you want the write comment to be.

Cheers,
Daniel

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15022

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
hey Yuri,
As far as I can see - you've found the reason why I have changed the event. I see that you have the knowledge to modify the code and write your own so In this case you can modify the plugin to do the trick onPrepareContent. Now that I think of this you can create a copy of the plugin that executes onPrepareContent and disable the original plugin - this way you will ensure that further modifications to the plugin won't screw you.

However keep in mind that the next major release ccomment5 will change a huge amount of code and will make the component frontend finally MVC oriented. Because of this you will then need to modify your plugin again.

Daniel

P.S. If you post a little bit of your code here I may be able to tell you what you need to change.

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15029

  • YuriBtr
  • YuriBtr's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Many thanks for your kind attention,
I'll try to describe my modifications that worked up to 4.1.7 version (including this one):
Main goal - to add possibility to put comments count (only numbers) in random place of article preview at blog layout.
Step #1
at file "components/com_comment/classes/joomlacomment/JOSC_visual.php", in function "insertCountButton" I commented out a piece of code and added one line after it:
/*		$html = $this->_readon;
 
		 {READON_xxx} 	
		$html	= str_replace('{READON_LINK}', $address , $html);
		$html	= str_replace('{READON_WRITE_COMMENT}', JText::_('JOOMLACOMMENT_WRITECOMMENT'), $html);
		$html	= str_replace('{READON_COUNT}', $number, $html);
		$html	= str_replace('{READON_COMMENTS}', $this->comments($number), $html);*/
 
$html =  $number;//this was added

Step #2
at file "components/com_content/views/category/view.html.php"
in function "getItems" in beginning of cycle "foreach($this->items as $key => $item)" paste following code:
$item->text = '';
 
// Get the page/component configuration and article parameters
$item->params = clone($this->params);
$aparams = new JParameter($item->attribs);
 
// Merge article parameters into the page configuration
$item->params->merge($aparams);
 
// Process the content preparation plugins
$dispatcher	=& JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onPrepareContent', array (& $item, & $item->params, 0));//here we calls event

Step #3
at file-templates, which overrides standard blog view "templates/mytemplate/html/com_content/frontpage/default_item.php" (valid for frontpage and usual blog view)
at the place where we need comments count, we put a construction like this:
<?php  if (isset($this->item->text)) echo  'Comments: ' . preg_replace("/[^0-9]/",'',$this->item->text); ?>


That was perfectly until 4.2.1 was installed. Now, even if I change in Step #2 event name "onPrepareContent" to "onAfterDisplayContent" or another events, nothing happens. At Step #3 i receive empty "$this->item->text"
I am really stucked with this problem. Please help, if possible.

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15030

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
why don't you add the onpreparecontent event and instead of trying to route the request trough the component, write your count query directly in the function...
function onPrepareContent ($all_parameters_that_you_need) {
$query = "Select COUNT(*) FROM #__comment where contentid="the content id"
 
return the count;
}
 

Also I don't know if you are on 1.7, but if you are you should know that the event has changed:

The content plugins in Joomla! 1.5 were using the onPrepareContent method, whereas the content plugins in Joomla! 1.6/1.7 use the onContentPrepare method.

docs.joomla.org/Making_single_installati...la!_1.5,_1.6_and_1.7

Hope that this brings you in the right direction.
Daniel

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15031

  • YuriBtr
  • YuriBtr's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Many thanks for your last message. Trying to understand your proposition, please advise, where function onPrepareContent must be realized? I have to declare it in "plugins/content/joscomment.php" (just near by function onAfterDisplayContent if I have Joomla 1.5)?

Thanks in advance

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15039

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Yes, add the function to the joscomment.php file. Look at the other plugins in the content folder for the right parameters for the function.

Daniel

Re: Problem with event onAfterDisplayContent 12 years 2 months ago #15040

  • YuriBtr
  • YuriBtr's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 0
Ok, many thanks. I'll try it now.
  • Page:
  • 1
Time to create page: 0.183 seconds