SMF Community Helpers > Mod Development
[MOD] Facebook Like Hide
4Kstore:
Hi people, Some time ago I made this mod, I would love that can review and tell me that things can improve.
It lacks a lot of features I have in mind but before going I wanted to know if the way this Implemented ajax can bring any problems. Using ajax with jquery because I really do not understand how they use AJAX in smf
What the mod is to hide the information until the user clicks the button "like" facebook.
It works for users and visitors, use a table to save the id_topic id_user and ip
When the user clicks the button, the mod show a message and refresh the page showing the hidden content.
I hope you can take a look to this mod.
Thanks!
NEW VERSION 1.1
Fixed:
Added Hooks
Using .error to handle some error from ajax
Organize structure
Added:
Counter before refresh.
Languages for Facebook script.
Posibility to show the button a guests or invite to register.
Posibility to skip the Like button if the user reply the topic.
Enabled - Disable mod.
New in this, i use JSON to pass information to JS file, i hope if you can review al the code and pointing if there is some wrong... I'm still learning..
Suki:
Ok, a few notes:
-Please keep the compatibility down to just 2.0.xx
- Might be useful to also provide a function when the ajax call fails form seom reason, jQuery.ajax() does provides some easy to use methods to handle errors.
- you can move fblikesAjax.php code to an inner action, this is not require but helps to keep things more organized.
-Separate your utf8 strings to another ifles properly encoded on UTF8 without BOM.
-You may wnat to use hooks for the BBC button, you can have a single source file with all your code, the BBC button, the action hook, the generic fblike() function, etc.
-Rather than checking the request value to be empty, check for its existence or its not existence: isset($_REQUEST['topic']), you can also check to be a valid int after the isset.
-This isn't nice: $urlajaxphp = preg_replace('/index.php/', '', $scripturl); use $boardurl instead.
4Kstore:
Thanks suki...
--- Quote from: Suki on August 27, 2012, 11:23:33 AM ---- Might be useful to also provide a function when the ajax call fails form seom reason, jQuery.ajax() does provides some easy to use methods to handle errors.
this is a good idea!
- you can move fblikesAjax.php code to an inner action, this is not require but helps to keep things more organized.
I'll try again, but I wanted to do and had problems with the call
-Separate your utf8 strings to another ifles properly encoded on UTF8 without BOM.
I will remove utf8
-You may wnat to use hooks for the BBC button, you can have a single source file with all your code, the BBC button, the action hook, the generic fblike() function, etc.
Yes, I was in my last mods using hooks and learning little by little
-Rather than checking the request value to be empty, check for its existence or its not existence: isset($_REQUEST['topic']), you can also check to be a valid int after the isset.
Yes, i forget this...
-This isn't nice: $urlajaxphp = preg_replace('/index.php/', '', $scripturl); use $boardurl instead.
ok, i try with this...
--- End quote ---
Again, thanks for the review.... this is a WIP but i posted here to know if I am correctly using ajax or if I have to improve something better
Suki:
Setting an inner action is easy, heres both ways with hooks and with manual edits:
with hooks, make an install.php or any other similar file and add:
add_integration_function('integrate_actions', 'actions'); / you can also call this at run time
Where "actions" is your own function or method, usually it will be located on your mod's source file
then the function actions is as simple as
actions(&$actions)
{
$actions['my_action'] = array(self::$name .'.php', self::$name .'::main');
}
where "my_action" is the actual name of your action, for example index.php?action=chat or action=modajax, dunno, something unique.
The array contains two parameters, the first one is the file where the main function will be, you can put there your own source file. SMF will call that file as if it resides on the root of the Sources folder, if your file is in a subfolder, you will have to specify that by putting the relative path to the file: /subFolder/my_file.php
The second parameter is the main function that will be called when something hits your action, can be a normal function or a static method
The manual way, index.php holds the monstrous $actionArray array, you just need to add your own array to it, the same twp parameters still apply.
The advantage of the hook is that you only need 1 hook and 1 function to create as much actions as you want, you can also modify every other action.
Now when you actually are using the action, put the correct link on your jquery ajax call, full url/index.php?index.php?action=myajax
then on your main function put all the code you need and construct a call to a template like you normally do, the key here is calling: $context['template_layers'] = array(); so obExit() won't call all the other layers but your own layer only, this means that the respond isn't going to show all the stuff SMF normally shows, the header template, footer template, etc
Set your response to a context var: $context['something'] = 'my response';
and just print or echo that context var on your template.
4Kstore:
Thanks suki, if you can see the new version... i added and fixed all you said.. (i hope)
and error i cant repair is when i write in the message box only a fblike tag i have an error:
Ex:
--- Code: ---[fblike]Text here![/fblike]
--- End code ---
--- Quote ---The following error or errors occurred while posting this message:
The message body was left empty.
--- End quote ---
But if i put something like this:
--- Code: ---[fblike]Text here![/fblike]
More text here
--- End code ---
The text posted normally
Navigation
[0] Message Index
[#] Next page
Go to full version