Skip to main content
Topic: Replace quick reply using hooks (Read 3656 times) previous topic - next topic - Topic derived from package-info.xml to... .somet...
0 Members and 1 Guest are viewing this topic.

Replace quick reply using hooks

Basically, I like the idea but even the current thing is already difficult for me to understand. I will have to depend on available samples or  addons, if any, to learn.

Even removing current quickreply box and inserting a new quickreply box template in new place seems difficult to me. Luckily you posted some code for first post on every page. I find the way you insert a new layer is different than the guide, though, I think I can try to use that for my quickreply reposition addons.

Samples or addons are needed to understand Elkarte. If more new things are implemented, then, the more samples or addons the better.
Last Edit: October 26, 2014, 09:12:03 am by emanuele

Re: Re: package-info.xml to... .something else?

Reply #1

Yup. Indeed examples are very important.
In you case, if you want to replace the quick reply, I think something like this should work:
Code: [Select]
$template_layers = Template_Layers::getInstance();
$template_layers->remove('quickreply');
$template_layers->addAfter('your_new_layer', 'pages_and_buttons');
and then a template with a function named:
Code: [Select]
function template_your_new_layer_below()
and inside it you put the template for the quick reply.
Bugs creator.
Features destroyer.
Template killer.

Re: Re: package-info.xml to... .something else?

Reply #2

still have to change the code manually without hooks
Sorry for my English

Re: Re: package-info.xml to... .something else?

Reply #3

For what?
The quick reply?
Where?
Bugs creator.
Features destroyer.
Template killer.

Re: Re: package-info.xml to... .something else?

Reply #4

javascript files, template files
Sorry for my English

Re: Re: package-info.xml to... .something else?

Reply #5

I can't argue it can be a little tricky, but you don't need to edit any template file.
As I demonstrated above you can replace the template with your own without doing code edits.
Then there are two "odd" points:
1) if the member is using the WYSIWYG then SCEditor javascript is still loaded. True. Though since you are using another template it's just a matter of not instantiate it, and it will not be used. Yes, waste of bandwidth. But that can be avoided:
Code: [Select]
foreach ($context[javascript_files'] as $key => $file))
{
    if ($file['filename'] == 'sceditor.js')
    {
        unset($context[javascript_files'][$key]);
        break;
    }
}
Of course this has to be done after the javascript has been loaded and before the template is sent out.

2) each "quote" button has:
Code: [Select]
onclick="return oQuickReply.quote(', $message['id'], ');"
In that case, you can create a dummy javascript object oQuickReply with a dummy quote method, just to avoid errors, and then handle the quoting the way you want.

Did I miss anything?
Bugs creator.
Features destroyer.
Template killer.

Re: Re: package-info.xml to... .something else?

Reply #6

I do not know, I think it's dubious decision
Sorry for my English

Re: Re: package-info.xml to... .something else?

Reply #7

Quote from: emanuele – Yup. Indeed examples are very important.
In you case, if you want to replace the quick reply, I think something like this should work:
Code: [Select]
$template_layers = Template_Layers::getInstance();
$template_layers->remove('quickreply');
$template_layers->addAfter('your_new_layer', 'pages_and_buttons');
and then a template with a function named:
Code: [Select]
function template_your_new_layer_below()
and inside it you put the template for the quick reply.

Will this work with simple hook like what I usually did? Or it needs a more advanced integration hook like your sample for first post on top? It seems long enough for me to get confused. Anyway, I will try this and report.

Re: Replace quick reply using hooks

Reply #8

I split out the quick reply discussion (also to test once in a while the split function :P).

Hooks are hooks, there are no "advanced" hooks. ;)
What I proposed in the other topic is "for the future" and is better to call them "events" or something similar just to differentiate from hooks because there are some differences (sorry for the confusion, but consider it's a work in progress, so I'm not even sure it will land... well, it will, not sure when. lol).

In that case, yes, you can do "as usual":
create a function containing the code I posted,
"attach" that function to the hooks (add_integration_function),
* and when the system runs it will replace the quick reply.
That it's the easy description.

I'm going to write some "technical notes" here, if something is not clear, feel free to ask. ;)
A small suggestion: since this code has to remove a layer, it should he run after the layer has been added (you cannot remove something that is not there :P).
In Display.controller.php, I'm not sure there is a "correct" hook to use (i.e. one that is run after everything and doesn't have another specific meaning[1]).
But, ElkArte, has some "generic" hooks specific to each action:
https://github.com/elkarte/Elkarte/blob/v1.0.1/sources/SiteDispatcher.class.php#L302
https://github.com/elkarte/Elkarte/blob/v1.0.1/sources/SiteDispatcher.class.php#L325
for example, on the board index these two hooks translate to:
integrate_action_boardindex_before
integrate_action_boardindex_after

while, when you are reading a topic, you will have:
integrate_action_display_before
integrate_action_display_after

I would suggest you to use integrate_action_display_after, so:
Code: [Select]
add_integration_function('integrate_action_display_after', 'replace_quick_reply', 'SUBSDIR/your_file.php');

And then in your_file.php:
Code: [Select]
<?php
function replace_quick_reply()
{
    $template_layers = Template_Layers::getInstance();
    $template_layers->remove('quickreply');
    $template_layers->addAfter('your_new_layer', 'pages_and_buttons');
}
You may be tempted to use integrate_display_buttons or integrate_mod_buttons, but these have a very specific meaning, so they may be moved around without notice, so it's better to rely on them just for their actual meaning, that is change the buttons.
Bugs creator.
Features destroyer.
Template killer.

Re: Replace quick reply using hooks

Reply #9

Aaah... I was wondering around and around and around for this. Thank you very much for the code and note. This is very helpful to me. I will attempt this soonest and report. If everything is fine, then it will be updated in this mod topic as well. Thank you again.