Tutorial of making hooks mods needed.

Started by MESWEB, January 30, 2015, 12:49:13 PM

Previous topic - Next topic

MESWEB

I'm just fresh with coding PHP with OOP. Can someone write tutorial about making hooks mods like adding image link to site or something basic? I want to create own mod I have finished script PHP(OOP) working fine on localhost. But when I add this code to smf i see only blank screen or not see link in menu bar. So this should be better for anyone if someone would be create tutorial for beginners.

Suki

You can use hooks with procedural code.

There cannot be a tutorial on what you want to do specifically, basically, that will mean doing all the work for you.

If you want to incorporate a script into SMF then we need to see that script and how it operates.

I don't really understand what you mean by "adding image link".
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

MESWEB

Quote from: Suki on January 30, 2015, 12:56:03 PM
I don't really understand what you mean by "adding image link".
Just simple image with link:
<a><img></img><a>

So first I want test my mod at localhost then if pass test I make forum post about this and share this mod to testing. But I don't know how to connect any working script with SMF.

Suki

So, where does this anchor tag will be placed? whats its purpose?
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

MESWEB

This button is a register button I want put this button to header and registration form - just like SAFacebook Integration.

Suki

Then check what that mod does and apply it to whatever you want to do?

You could always start with some basic stuff, that is, to add your anchor tag to the register template and index.template.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

MESWEB

This not helped me. I integrated my code with SMF and now I'm redirecting from $scripturl to my registration url from my mod. Why SMF redirecting automatically to my url?

Biology Forums

I sort of agree with the OP. I wish there was a basic tutorial.

The best way to learn this stuff is to open a prepackaged mod and dissect its install file. See how someone else did it and learn from that. That's how I learned a third of the stuff I know about SMF. Trial and error lol

margarett

Quote from: Shuban on February 03, 2015, 01:46:28 AM
Trial and error lol
^^ This :P

I also agree that a tutorial would help in some cases. BUT depending on what you want to do, the approach varies:
* Build a BBC-hooked MOD. Pretty basic nowadays (that's why we are not accepting MODs like these that aren't using hooks). Pick one or 2 existing MODs, check how the tag is added, check how the image is added (if required). Adapt and build, done
* Build a custom action. The part to add the action is kinda easy. You can even use the Custom Actions MOD (which is not using hooks itself :P ). Now... What would *THAT* action do? You need to be able to code that... And call a template from the Source. And play with permissions. And..........
* Add a button to the main menu. There's also a direct hook for it, also check some MODs that add these buttons on how to do it.
* (...)

The thing is... There are really too many things you can do in order to do ONE tutorial on how to use hooks... And in each hook you can do pretty much whatever you want because you have all of SMF available at that point. Hooks are only different (not exactly true) in the point of SMF's execution point they are available (which basically represent how much of the final page content was already loaded).

Nevertheless, a kind of tutorial for this it's one of the things I have on my to-do list. But I first need to define an approach for it (and find the time to do it :P )
Ideas are welcome :)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

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

Kindred

we are working on improving the Hooks wiki page...  (and margarett, that is where the most effort should be put, IMO) 
a tutorial on how to build a mod using hooks?   That seems like an incredible amount of work for a low return...

Quote from: margarett on February 03, 2015, 06:31:47 AM
The thing is... There are really too many things you can do in order to do ONE tutorial on how to use hooks... And in each hook you can do pretty much whatever you want because you have all of SMF available at that point. Hooks are only different (not exactly true) in the point of SMF's execution point they are available (which basically represent how much of the final page content was already loaded).

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sorck

Quote from: Kindred on February 03, 2015, 09:12:29 AM
we are working on improving the Hooks wiki page...  (and margarett, that is where the most effort should be put, IMO) 
a tutorial on how to build a mod using hooks?   That seems like an incredible amount of work for a low return...

I know it's a little detached from the Hooks page on the wiki but I have a nearly full SMF 2.1 β1 hooks list* [and slowly accumulating examples for each hook... slowly in that I've only done 4 so far :P Though I'm avoiding ones that have 2.0 docs as they've generally not changed in 2.1, plus it's a waste to duplicate the effort]. The examples I'm writing are pretty trivial - it's more of just pointing out what the supplied parameters are (or where the best documentation for the parameter is by specifying where they are initially declared).

The list is here: https://cdn.rawgit.com/Sorck/SMF2.1-Hooks/0e43b7c63ca947831d57ece38fb2a6977564aa4c/hooks.html
The documentation pages are in .yaml files in my repos docs directory, the actual documentation is in markdown instead of BBCode/WikiCode but it wouldn't be difficult to convert them (and there's currently no html viewer for individual docs pages short of looking at the source).

*one hook call seems to be rather dynamic - I've not had the chance to dig it out yet and look at it.



Back to the OP's question.
For now the best way to do almost anything is to find a mod that does something similar and see how they solve the problem. That's how many people will have written their first mod. If the hook you want hasn't been used in a mod you've looked at then try the hooks page and see if one of them is suitable. If you're not quite sure then look at the source code where it's called (though this is really for people who've written mods before who want to dig deeper into the SMF hooks.

Maybe a very simple SMF Hook Mod Boilerplate could be put together that uses 'proper' conventions for everything? It could show a sample of using just the core hooks for dealing with adding an action and menu and maybe modifications page in the admin CP, but also show basic database functions and language files etc. The problem is of course that it soon becomes several hundred lines and looks a little daunting to the first time hooks user/mod writer.

I assume something similar already exists somewhere though.

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

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

Kindred

yes indeed...   many thanks for starting that effort!
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sorck

Quote from: Kindred on February 03, 2015, 10:51:32 AM
yes indeed...   many thanks for starting that effort!
No problem. :)

Writing documentation can be surprisingly relaxing. :P (And a lot more productive than watching TV...)

MESWEB

Quote from: margarett on February 03, 2015, 06:31:47 AM
Quote from: Shuban on February 03, 2015, 01:46:28 AM
Trial and error lol
Nevertheless, a kind of tutorial for this it's one of the things I have on my to-do list. But I first need to define an approach for it (and find the time to do it :P )
Ideas are welcome :)
Sounds great :) I'm waiting for first tuts. I answer for others here - I all the time try understand existing mods but sometimes author are very smart and he don't write documentation in .php file as comments. I found sometimes comments in Latin language (we have XXI century and Latin language we using only on medicine :)). So this comments are coded in Latin. So if I need understand what author write I need go to school and teach Latin? Better if all authors of mod use Enigma to code comments :). I will try write my own hooks but without any tutorial is very hard.

Kindred

who is posting comments in latin?

I would assume that SOME comments on mods might be in other languages, but I have never seen any in Latin
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Suki

Quote from: MESWEB on February 03, 2015, 12:42:02 PM
Quote from: margarett on February 03, 2015, 06:31:47 AM
Quote from: Shuban on February 03, 2015, 01:46:28 AM
Trial and error lol
Nevertheless, a kind of tutorial for this it's one of the things I have on my to-do list. But I first need to define an approach for it (and find the time to do it :P )
Ideas are welcome :)
Sounds great :) I'm waiting for first tuts. I answer for others here - I all the time try understand existing mods but sometimes author are very smart and he don't write documentation in .php file as comments. I found sometimes comments in Latin language (we have XXI century and Latin language we using only on medicine :)). So this comments are coded in Latin. So if I need understand what author write I need go to school and teach Latin? Better if all authors of mod use Enigma to code comments :). I will try write my own hooks but without any tutorial is very hard.

It totally depends on the source you are looking at. SMF's code has at least in-line comments with explanations on whats been done. All the code I made has at least one comment every 3 lines of code

As for encoding, you only need to use a code editor, any good code editor should be able to pick the file's encoding and use that rather than forcing a predefined codification.

If you mean Latin as in the Latin language then, thats another different story altogether, any mod submitted to the cust site here requires comments to be written in English. Now, I haven't seen any comments on any mod written in actual Latin; Spanish, yeah, some Portuguese too (those are the ones that resembles Latin the most and have a larger mod community) but actual Latin, nope.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Kindred

yup... Spanish, Italian, Portuguese I have seen...
even Russian and German -- but never Latin.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MESWEB

This code came from Optimus mod:
<?php
// Çäåñü ïîäêëþ÷àåì âñå èìåþùèåñÿ ôóíêöèè ñ íàñòðîéêàìè ìîäà
?>

I don't know what kind of language is this - but this is hard to decode :)

Kindred

looks like your editor screwed something up, actually...

// Раздел настроек мода в админке

// Здесь подключаем все имеющиеся функции с настройками мода

// Первая страница настроек


etc...

it's russian for me...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: