ElkArte Community

Extending Elk => Addons => Addons ideas and questions => Topic started by: ahrasis on October 23, 2014, 07:28:42 am

Title: Replace quick reply using hooks
Post by: ahrasis on October 23, 2014, 07:28:42 am
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.
Title: Re: Re: package-info.xml to... .something else?
Post by: emanuele on October 23, 2014, 08:09:03 am
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.
Title: Re: Re: package-info.xml to... .something else?
Post by: inter on October 23, 2014, 09:38:42 am
still have to change the code manually without hooks
Title: Re: Re: package-info.xml to... .something else?
Post by: emanuele on October 23, 2014, 09:47:09 am
For what?
The quick reply?
Where?
Title: Re: Re: package-info.xml to... .something else?
Post by: inter on October 23, 2014, 10:09:45 am
javascript files, template files
Title: Re: Re: package-info.xml to... .something else?
Post by: emanuele on October 23, 2014, 10:19:03 am
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?
Title: Re: Re: package-info.xml to... .something else?
Post by: inter on October 23, 2014, 10:32:44 am
I do not know, I think it's dubious decision
Title: Re: Re: package-info.xml to... .something else?
Post by: ahrasis on October 26, 2014, 06:08:37 am
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.
Title: Re: Replace quick reply using hooks
Post by: emanuele on October 26, 2014, 09:30:11 am
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.
Title: Re: Replace quick reply using hooks
Post by: ahrasis on October 30, 2014, 08:54:33 pm
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.