e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

Enhancement: Plugin e_template.php addon to override theme templates. #3195

Open Jimmi08 opened 6 years ago

Jimmi08 commented 6 years ago

Old plugins in e_meta.php replaced Global Template Constants

require_once(e_PLUGIN."forum/templates/forum_viewtopic_template.php");  

$forum_old = "{POSTS}";
$forum_new = "{POSTS}{THANKSPOSTS}";

$FORUMTHREADSTYLE = str_replace($forum_old, $forum_new, $FORUMTHREADSTYLE);
$FORUMREPLYSTYLE  = str_replace($forum_old, $forum_new, $FORUMREPLYSTYLE);

or

$USER_FULL_TEMPLATE = str_replace($forum_old, $forum_new, $USER_FULL_TEMPLATE);

How to do this with new version when they are filled later in forum_viewtopic.php:

$FORUM_VIEWTOPIC_TEMPLATE = e107::getTemplate('forum','forum_viewtopic');
$FORUMREPLYSTYLE        = $FORUM_VIEWTOPIC_TEMPLATE['replies'];

but before it was written this way:

if (!$FORUMREPLYSTYLE) $FORUMREPLYSTYLE = $FORUMTHREADSTYLE; so if constant was defined, that from plugin was used.

Maybe I am wrong, but how override forum (or any) template from plugin, not from theme?

rica-carv commented 6 years ago

Currently, i think the only way to override a tamplate is at theme level, another plugin can't do it. I've already needed that in my Euser plugin, but it's development is stalled preciselly because of that....

Moc commented 6 years ago

I think it should be possible...

@CaMer0n @lonalore thoughts please :)

Jimmi08 commented 6 years ago

https://github.com/e107inc/e107/issues/3211

Jimmi08 commented 6 years ago

I think that this is problem or bug in new version. Everywhere where was test

if(!defined($COPPA_FAIL)) , if (!$FORUMSTART) { ...

there should stay the same test for new template array:

If(!$FORUM_VIEWTOPIC_TEMPLATE['replies']) {
$FORUM_VIEWTOPIC_TEMPLATE['replies'] = $FORUM_VIEWTOPIC_TEMPLATE['thread']; 
}

and you can override this in e_meta.php

At least in forum these tests are ignored.

CaMer0n commented 6 years ago

@Jimmi08 Third-party plugin developers did many unconventional things in v1.x.
Tightened security, improved standards, and removal of globals in v2x now prevents this form of overriding from occurring. It was never a 'feature' as such, just a loophole which developers took advantage of. The test you mention above is not a good solution, but there might be a better one which could be implemented. (probably via e_shortcode.php)

Jimmi08 commented 6 years ago

Almost each old plugin uses this way to override or extend core templates. And themes did just styling, not manipulate with data.

How do you want to solve this:

$USER_FULL_TEMPLATE=str_replace('{USER_NAME}','{OIM_USER_NAME}',$USER_FULL_TEMPLATE); quick, easy, simple

it replaces core shortcode with plugin shortcode before template parsing. It has nothing with shortcodes, it's about possibility to override template before is parsed by other plugin.

you can't replace core or other plugin shortcodes by plugin, you can't extend them, you can't replace core template by plugin template...

Oh, and of course there is unconventional workaround too.

CaMer0n commented 6 years ago

@Jimmi08 I understand what you are requesting. What I'm saying is that the technique used by some third-party scripts in e_meta.php (designed for setting meta data, not manipulating theme templates) was never documented, because it was never an intended 'feature' in v1.x. (You will not find a core plugin in v1.x using this technique).

So, what you're requesting is an enhancement, not a bug fix.
e107 v2.x has no "solution" for this feature right now afaik, but I'm open to suggestions.

Jimmi08 commented 6 years ago

@CaMer0n this is starting be really problem/limitation. No idea how to solve this.

But I remember that captcha has way how to override secure image handler.

Question is - override template or shortcode? My opinion is that template should be overriden.

Maybe something like e_template.php ? Loaded after core/plugin templates and before parsing templates?

What I noticed, those are most used templates:

$FORUMTHREADSTYLE = str_replace($forum_old, $forum_new, $FORUMTHREADSTYLE);
$FORUMREPLYSTYLE = str_replace($forum_old, $forum_new, $FORUMREPLYSTYLE);
$USER_SHORT_TEMPLATE_START = str_replace($user_old, $user_new, $USER_SHORT_TEMPLATE_START);
$USER_SHORT_TEMPLATE = str_replace($user2_old, $user2_new, $USER_SHORT_TEMPLATE);
$USER_FULL_TEMPLATE = str_replace($user3_old, $user3_new, $USER_FULL_TEMPLATE);

So maybe just some/core templates could have this functionality? With new plugin you create your own templates. But you can't do it with core templates

What I noticed as problem with addons is that there is no priority, they are loaded by aplhabetical order.

Moc commented 6 years ago

@SimSync if you have time and interest, maybe you could look at this and see if you have some ideas for this.

SimSync commented 6 years ago

In wordpress, they use "hooks". You can register a function to be called on a specific "hook" in the hooked function to modify the output. e.g. Let's assume there would be a hook in the getTemplate() function, that is called after a template has been loaded, you could do the same what you did in v1: replace parts of the (or the whole) template with str_replace().

Jimmi08 commented 6 years ago

Thanks. I don't know if is waiting reaction from me or not.

You are right, but in e107 there are addons e_ for extending core functionality. ... and hooks in WP are confusing for many people too.

What is e_notify in WP terms? Hook? Or action?

I will try to explain where is problem for me, because I created this issue and I don't want to look that I don't answer or something. I just dislike if we are moving from what was typical for e107... not working e_PAGE is next example.

There are developers who can understand you ("the language of your tribe"). You can count them on fingers on one hand, maybe both. And they - like you - are working on core.

Then there are people like me and many others who are able coding and mostly copying someone else code. Who are using developer manual to get things working. I need examples, working code and other things. I don't understand what you are saying and what is needed to do and how to use it.

Only thing I know that with global variables and procedural programing I haven't problem to customize or change anything. Frankly, it's frustrating.

This is just explanation why I can't help with this and I will not mess your discussion anymore.

CaMer0n commented 6 years ago

@Jimmi08 Sorry, just saw your post and your earlier one. Yes, I'm thinking e_template.php could be a way to make this work, and it would need to be checked when we use e107::getTemplate();

The reality is that the functionality you are requesting has not existing for many years, yet your request is only a couple of months old and now is suddenly 'urgent' for you. With so many other bugs and stability issues to correct, I hope you can understand why this has not been prioritized.

This will be something we can consider for v2.2.0

Jimmi08 commented 6 years ago

Thanks. Urgent was in meaning that I need to know what is planned for this. Answer 2.2 is enough.

CaMer0n commented 5 years ago

@Jimmi08 Please remind me about this as soon as v2.2 is released. We can then experiment with something in the github repo with e_template.php etc.

Jimmi08 commented 5 years ago

@Moc I would close this or move milestone far far away. I was asking this and I don't need it anymore. Plugin global shortcodes are enough for me.

Jimmi08 commented 4 years ago

Adding example for better understanding:

In old version I would replace {NEWSAUTHOR} with {{NEWSAUTHOR}{HITS_UNIQUE} in a template string in e_header.php and not changes in theme would be needed.

The login menu uses {LM_EXTERNAL_LINKS} to display information from other plugins.

Not important now, it was just an explanation.

Jimmi08 commented 4 years ago

Funny, I just found that I use this in e_meta.php and it still works

$USER_TEMPLATE = e107::getCoreTemplate('user'); 

$user3_old = "{USER_LOGINNAME}";
$user3_new = "{USER_LOGINNAME} {UCLASS_BADGES}";

$user2_old = "{USER_NAME_LINK}";
$user2_new = "{USER_NAME_LINK} <br> {UCLASS_BADGES}";

$USER_FULL_TEMPLATE = str_replace($user3_old, $user3_new, $USER_FULL_TEMPLATE);
$USER_TEMPLATE['view'] = str_replace($user3_old, $user3_new, $USER_TEMPLATE['view']);
$USER_SHORT_TEMPLATE = str_replace($user2_old, $user2_new, $USER_SHORT_TEMPLATE);
$USER_TEMPLATE['list']['item'] = str_replace($user2_old, $user2_new, $USER_TEMPLATE['list']['item']);
CaMer0n commented 4 years ago

@Jimmi08 Best use e_module.php instead.

Moc commented 4 years ago

Is this supported then? Or do we still need something new like e_template.php. I am asking for the documentation status on this issue :)

Jimmi08 commented 4 years ago

@Moc it depends on the place, I think. It works with the user template. And now I found that I use it with e_meta with a signup template. I think it is because in those templates are still test if those variables are defined.

But I must say that just yesterday I had the opposite scenario: