TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 500
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 112
  • Total: 112

hooks--how to??

Started by darkangel, July 25, 2012, 10:21:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

darkangel

is there somewhere to show a person how to create a mod using hook method.

I would like to add a facebook share button to the primary post in each thread. Yes I know there is a mod to do just that but it will only work with twitter button now...seems FB changed something and now the FB share button does not work.

I really don't like the "like" button and would rather have the share button with the added benefit of being able to turn off/on and choose which sections in admin


just like the Facebook & Twitter Sharer mod,


IchBin

Hooks all work in the same way. The only difference is the way you will need to code to make them add the data that you need. For instance in my latest code for TP I've added a few more uses in the hooks. Instead of having TP modify the Subs.php file in SMF to add it's custom menu items I now call the hook.

Scattered throughout the code in SMF there are places where a hook is placed. The function is call_integration_hook(). If you look at Subs.php where the hook is placed right after the array for the menu is created you can see that the menu array $buttons is passed into it. This means that you can modify that array to add your own. The hook queries to see if you have added any entries in the smf_settings table for "integrate_menu_buttons". If it finds the entry it then calls the function you specified. It's a little confusing to understand, so I would say just take a look at the code on github that I have for TP. You'll see the do_hooks.php file which adds all the hooks on install that TP will use. You can see that each hook in that file requires a certain format:

'hookname' => 'hook_function',

So when the hook is called in SMF code, it automatically calls hook_function() in your code. All of TP hook functions are stored in the TPAssimilate.php file. You can look at the tpAddMenuItems() function to see how I loop over all the menu items adding each one to a new array until I insert our custom items. Then I return the new array.

I hope that makes sense. You can see how TP adds the copyright to SMF without having the modify any files in SMF. SMF stores the page output in a buffer, so before that buffer is output we look for a certain part in the buffer and add our own copyright by appending our text to it. That's just an example of how another hook can work.

darkangel

Thanks will take a looksee at the page. It does sound very complicated, but we shall see...lol not holding breath.

have a great day

This website is proudly hosted on Crocweb Cloud Website Hosting.