Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
BUG in Input Formatter - extra formatting cycles.
Create default.php file with this code and place it in new Plugin directory
if this Plugin is enabled you'll see in every post
rolling staring and ending "0" of each message in discussion.
0 The first mesage will have one 0 in the end and the start of the message. 0
00 The second - two "0". 00
000 The third - threee and so on.... 000
0000 It means that message processor makes the extra work to display messages. 0000
00000 How to correct this ? 00000
<?php
$PluginInfo['AnyFormatterPlugin'] = array(
'Name' => 'ANY FORMATTER PLUGIN',
'Description' => '',
'Version' => '',
'Author' => "",
'AuthorEmail' => '',
'AuthorUrl' => ''
);
class FormatterPlugin extends Gdn_Plugin {
public function Base_Render_Before($Sender) {
}
public function DiscussionController_BeforeCommentBody_Handler($Sender) {
$Comment = $Sender->Discussion;
$Comment->Body = ParseSyntax($Comment->Body);
foreach($Sender->CommentData as $cdata) {
$cdata->Body = ParseSyntax($cdata->Body);;
}
}
// AJAX posting of comments
public function PostController_BeforeCommentBody_Handler($Sender) {
$this->DiscussionController_BeforeCommentBody_Handler($Sender);
}
// AJAX preview of new discussions
public function PostController_BeforeDiscussionRender_Handler($Sender) {
if ($Sender->View == 'preview') {
$Sender->Comment->Body = ParseSyntax($Sender->Comment->Body);
}
}
// AJAX preview of new comments
public function PostController_BeforeCommentRender_Handler($Sender) {
if ($Sender->View == 'preview') {
$Sender->Comment->Body = ParseSyntax($Sender->Comment->Body);
}
}
// AJAX discussion edit preview
public function PostController_BeforeDiscussionPreview_Handler($Sender) {
$Sender->Comment->Body = ParseSyntax($Sender->Comment->Body);
}
public function Setup() {
// Nothing to do here!
}
}
function ParseSyntax($String) {
$String="0".$String."0";
return $String;
}
if this Plugin is enabled you'll see in every post
rolling staring and ending "0" of each message in discussion.
0 The first mesage will have one 0 in the end and the start of the message. 0
00 The second - two "0". 00
000 The third - threee and so on.... 000
0000 It means that message processor makes the extra work to display messages. 0000
00000 How to correct this ? 00000
0
Comments
public function DiscussionController_BeforeCommentBody_Handler($Sender) { $Comment = $Sender->Discussion; $Comment->Body = ParseSyntax($Comment->Body); foreach($Sender->CommentData as $cdata) { $cdata->Body = ParseSyntax($cdata->Body);; } }
You need to properly understand how to make a plugin and know when hook is in a loop, rather than just botching you way through.
The irony is you are trying to get a syntax highlighter to work, you need to learn how to code.
try
BeforeCommentsRender
if you want to do it that way.grep is your friend.
<<<<The irony is you are trying to get a syntax highlighter to work, you need to learn how to code.>>>>>>
This is cleared code of plugin You adviced me
PS. and my plain code works the finest way. I can give you a link if you forgot which is my code
DiscussionController_BeforeCommentBody_Handler($Sender)
is a wastecode of plugin adviced by you .may I delete it at all if it is a wastecode ?
The long and the short of it is I don't have time to teach you how to program. It is still better to do a formatting addon as a plugin. It is theme independent, and you don't want to edit the core, becuase that will be replaced when you update. I also advised you not to put hunks of code in views. Another alternative is to create helper function or view module, but that is not really pluggable.
BeforeCommentBody is self explanatory. It triggers before each comment body. BeforeCommentsRender triggers before comments are rendered, which is before the loop.
You also may also need for your project to pick an earlier hook for any pre-processing, which is before it goes through the main formatter.
grep is your friend.
Don't try to teach a life anybody if you even have not tried to run the code . Ok?
And selfexplanatory functions are not such you think of them.
cause they simply don't work as they must. some of them don't work at all.
Try to do a simple parser yourself. It's very easy
Thanks a lot for your help nonetheless.
ps
if GeShi plugin works somehow then I can teach from it.
Try yourself )))
do a numerator of messages )))))))))))))
static $NUMBER; $MessageText = $NUMBER.' - ' $MessageText; $NUMBER=$NUMBER+1;
grep is your friend.
BeforeCommentBody triggers every comment as expected.
Now you have to figure out the code yourself. Find where those events are being fired work backwards.
grep is your friend.
public function DiscussionController_BeforeCommentBody_Handler($Sender
$Sender is a Parent object.
$Sender->Discussion->Body - is a first comment of discussion
$Sender->CommentData - an array of all messages in discussion
Very usable. Yes.
You've coded plenty of parsers.
Suggest a way to get a link to current comment from $sender object.
BeforeCommentsRender is before the render loop allowing you to loop through the comments as you are
BeforeCommentBody is during the loop. You have to use event arguments (which is the second parameter of the handler) Comment and Disccussion just before BeforeCommentDisplay. If you actually looked at the code where those event are, you will see this.
Seriously I don't know what more help I can give.
grep is your friend.
grep -R --include="*.php" "\->FireEvent(" .
grep -R --include="*.php" "\->FireEvent('.*Comment" .
grep is your friend.
No sense , that's a place where i was setting wrapper function .
<?php $Sender->FireEvent('BeforeCommentBody'); $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format); $Sender->FireEvent('AfterCommentFormat'); $Object = $Sender->EventArguments['Object']; echo $Object->FormatBody; $Sender->FireEvent('AfterCommentFormat'); $Object = $Sender->EventArguments['Object']; ?>
The only I have in the handler routune is a link to $Sender .
class FormatterPlugin extends Gdn_Plugin { public function Base_Render_Before($Sender) {} public function DiscussionController_BeforeCommentBody_Handler($Sender) { //static counter of messages static $i; if ($i==null) { $Comment = $Sender->Discussion; // PARSING FIRST COMMENT $Comment->Body = '1. '.$Comment->Body; $i=2;} $number=2; //CommentData contains messages from №2 foreach($Sender->CommentData as $cdata) { if ($number==$i) {// PARSING OTHER COMMENTS $cdata->Body = $number.'. '.$cdata->Body;} $number=$number+1;} //Next message $i=$i+1; } public function Setup() {// Nothing to do here!} }
grep is your friend.
this is really helpful.
but where from have You gotten Args syntax for your code?
$Sender->EventArguments['Object']
regardless of what type it is.Vanilla Forums COO [GitHub, Twitter, About.me]