Advertisement:

Author Topic: Mod developer question: How do I replicate theme edits inside my Mod.php file?  (Read 5934 times)

Offline nend

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,755
  • 2 deep n2 the code
    • sicommnend on GitHub
    • SIComm.us
It really matters on where in the template the edit is needed. If it is in a function than it is harder. If you need to put the information above or under a template layer it gets a little easier.

You can also rewrite the buffer or even use JavaScript to rewrite the page, but then there is the chance the template is way different than the default template strings you are looking for.

Long story short, you might as well risk it with a template edit if your edit is right smack in the middle of a function. Allot less trouble. ;)

Offline live627

  • Developer
  • SMF Hero
  • *
  • Posts: 5,568
  • Gender: Male
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Quote
. Wouldn't it be great if  SMF developers could "Add" new codes from their mod file but prevent them from either "Replacing" or "Modifying" exisiting code? Meh, tiss an idea.  :P
integrate_buffer?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
You can't do the "add/replace" thing on the fly. It's just not possible because you would be replacing static code with dynamic operations. What if the "on-the-fly add/replace" fails for some reason? (the most obvious reason: code to search for is not found) Then you'd have most likely a crippled MOD because a part of it wouldn't be executed. Now you have at least a big read warning in Package Manager when trying to install it ;)

Hooks were originally developed for Sources (at least I think so :P ) because template are probably more difficult to expand. Says the dumb themer in me ;D
Anyway, as live627 said, considering that there are few hooks in template files, integrate_buffer is the answer.
http://wiki.simplemachines.org/smf/Integration_hooks#integrate_buffer

Check a MOD which uses it:
http://custom.simplemachines.org/mods/index.php?mod=3067
In short, before the generated HTML code is dumped to the browser, you can change it at will. Most likely you will want to perform a search for a certain (and unique!) text, then replace it (most likely with regex or str_replace if it's something simple) with itself plus and/or your MOD's generated HTML.

Not for the the faint of heart :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline Wellwisher

  • Jr. Member
  • **
  • Posts: 395
  • Gender: Male
You can't do the "add/replace" thing on the fly. It's just not possible because you would be replacing static code with dynamic operations. What if the "on-the-fly add/replace" fails for some reason? (the most obvious reason: code to search for is not found) Then you'd have most likely a crippled MOD because a part of it wouldn't be executed. Now you have at least a big read warning in Package Manager when trying to install it ;)

Hooks were originally developed for Sources (at least I think so :P ) because template are probably more difficult to expand. Says the dumb themer in me ;D
Anyway, as live627 said, considering that there are few hooks in template files, integrate_buffer is the answer.
http://wiki.simplemachines.org/smf/Integration_hooks#integrate_buffer

Check a MOD which uses it:
http://custom.simplemachines.org/mods/index.php?mod=3067
In short, before the generated HTML code is dumped to the browser, you can change it at will. Most likely you will want to perform a search for a certain (and unique!) text, then replace it (most likely with regex or str_replace if it's something simple) with itself plus and/or your MOD's generated HTML.

Not for the the faint of heart :P

Thank you @Nend for the suggestion. @Margarett Thank you too. I'll have fun tinkering around with this "integrate_buffer" hook! :laugh: I already hooked in all my functions thanks to your tutorial. I can easily achieve those two final theme edits with XML and if all else fails, I may have to stick to them.  :P But for now, I am just exploring how far I can push the mod for lol's. It's taught me a great deal, also learnt you can just have one hooks file for installing/ uninstalling, which was pretty cool.  ::)

Thanks again, much respect! 8)