Advertisement:

Author Topic: loadPartialTemplate function Please?  (Read 37352 times)

Offline nend

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,755
  • 2 deep n2 the code
    • sicommnend on GitHub
    • SIComm.us
Re: loadPartialTemplate function Please?
« Reply #40 on: August 19, 2016, 12:47:25 AM »
Been playing around with a similar idea with function hijacking. When a function is called passed vars can be modified or the function replaced by another with integration hooks. This could be applied to themes, however it's no magic bullet.

It isn't SMF will not change, it is change takes time.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,792
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #41 on: August 19, 2016, 12:54:51 AM »
I'm not trying to get into a debate on whether or not I am comparing SMF to Wordpress, because I simply am not trying to do this.  I only provided an example of how Wordpress handles hooking functions.  I can see that it is pointless, this conversation, yes.  I might as well talk a different language.  Cheers :)

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,792
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #42 on: August 19, 2016, 12:58:13 AM »
@nend, yes, I showed an example of this in earlier post with the integrate_prepare_display_context hook.  The thing I would like to see here, is ability to change HTML, not so much variables.  Although variable changing would be nice also, but that is already pretty much possible, since $context is the main variable for templates and can be modified mostly in Source files.  Basically, I just would like to be able to hook in my own partial templates, like partial HTML inside of the template, without editing the template.

I suppose it might help if SMF did something like this inside of their templates:

Code: [Select]
if ( ! function_exists( 'template_main' ) )
{
    function template_main() {
        // All template code in here...
    }
}

Than maybe we could override these functions individually with our own...  I think if they were to do this with more functions, we can hook our own in another template to overwrite parts of HTML.  Possibly a start on this?  Haven't worked with SMF in awhile, so a bit out of practice here, but if they loosened up their templates a bit and used that code where it can actually work, than perhaps it might be a great start to editing Themes that are already installed...

Thoughts?
« Last Edit: August 19, 2016, 01:13:44 AM by SoLoGHoST »

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,027
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: loadPartialTemplate function Please?
« Reply #43 on: August 19, 2016, 09:49:01 AM »
Thats already possible. You can overwrite functions in PHP.  Theres also the layer system, you can CRUD any template and subtemplate layers.

And no, the way wordpress does stuff cannot be applied to SMF, WP and SMF are two different things.
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,985
  • Gender: Male
    • Kindred-999 on GitHub
Re: loadPartialTemplate function Please?
« Reply #44 on: August 19, 2016, 10:54:29 AM »
WordPress. I've been working with it for years and I absolutely hate using it for anything other than a very basic blog site. I actually agree with you regarding Drupal but not for the same reasons. Drupal has issues burying div inside div inside div so that modifying any css in their template is nearly impossible.

And arantor hit the nail on the head... WordPress is not good just because people use it...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,792
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #45 on: August 19, 2016, 12:43:19 PM »
Thats already possible. You can overwrite functions in PHP.  Theres also the layer system, you can CRUD any template and subtemplate layers.

Can you provide minor examples of this perhaps?  If you are referring to override_function, than that requires APD PECL extension. Maybe this is 1 of the reasons why SMF should go OOP?  Than we can use Interface to accommodate this better.
« Last Edit: August 19, 2016, 01:01:29 PM by SoLoGHoST »

Offline live627

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,265
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: loadPartialTemplate function Please?
« Reply #46 on: August 19, 2016, 07:03:03 PM »
Complete template override? Easy. I have some code I wrote several years ago to do this very thing:

Code: [Select]
function template_init()
{
add_integration_function('integrate_menu_buttons', 'fixSubTemplates', false);
}

function fixSubTemplates()
{
global $context;

$new_sub_template = empty($context['sub_template']) ? 'main_override' : $context['sub_template'] . '_override';

if (is_callable('template_' . $new_sub_template))
$context['sub_template'] = $new_sub_template;
}

The hook should be late enough in the runtime where you know the templates will have been already loaded, otherwise the overrides won't work.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline nend

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,755
  • 2 deep n2 the code
    • sicommnend on GitHub
    • SIComm.us
Re: loadPartialTemplate function Please?
« Reply #47 on: August 19, 2016, 10:27:02 PM »
@live627, nice, I didn't think of that.

Here's what I wrote a week or two ago.

Code: [Select]
$smcFunc += array(
'ufunc' => function ($func, $vars = null, $array = false)
{
// Allow hooking into functions to rewrite vars or send the data to another function instead.
call_integration_hook('integrate_before_func_'.$func, array(&$func,&$vars));
if (!empty($func))
$return = call_user_func_array($func, is_array($vars) && $array == true ? $vars : array(&$vars));
if (!empty($return)) {
// allow modifications of return data.
call_integration_hook('integrate_after_func_'.$func, array(&$return));
return $return;
} else
return false;
},
'load' => function ($path, $file, $type = 'generic')
{
// File hijacking, good for when you want to replace source files with others.
// Types source, theme, lang, generic
call_integration_hook('integrate_require_'.$type.'_'.$file, array(&$file));
require_once ($path.$file);
}
);

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,792
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #48 on: August 20, 2016, 01:42:21 AM »
Nice, but adding it to an integration called integrate_menu_buttons?  There should be built-in functionality for this that is obvious, not sneaky hacks.

In any case, thanks for sharing guys, but I feel like Suki was referring to overidding a function via PHP only, and I'd like to see an example of that without using the APD PECL extension.

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,027
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: loadPartialTemplate function Please?
« Reply #49 on: August 20, 2016, 11:32:26 AM »
Nice, but adding it to an integration called integrate_menu_buttons?  There should be built-in functionality for this that is obvious, not sneaky hacks.


Thats redundant. A hook is just a place in "space" and runtime, its name its just an indicator of where the hook is called, not its purpose.  A hook can be used in any purpose you want.

In any case, thanks for sharing guys, but I feel like Suki was referring to overidding a function via PHP only, and I'd like to see an example of that without using the APD PECL extension.

Nope.
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline live627

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,265
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: loadPartialTemplate function Please?
« Reply #50 on: August 20, 2016, 07:21:06 PM »
Quote
Nice, but adding it to an integration called integrate_menu_buttons?
Yeah. And  it works.

Hacks never look pretty.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,792
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #51 on: August 20, 2016, 09:34:19 PM »
Ok, thanks again all for your attention on this topic.  I'm very lucky to have the attention that you folks give here.  Such great talented coders that have a huge impact on SMF and it's development makes me very proud to have the replies on this topic from such great minded individuals.  Thanks and I look forward to what SMF becomes in the future.  :)