Joomla Plugin With Helper File - plugins

Is there a conventional way of making a helper file to a Joomla Plugin? Like class names (helper or plgNameHelper) and the way of calling it?
class Helper
{
public static function test()
{
// some code
}
public static function anotherTest()
{
// some code
}
}

Conventionally, helper files have been for modules, not plugins. However it is a good idea to make a template, if the plugin changes the page HTML.

There is no conventional way of making a helper file to a Joomla Plugin but you can create Joomla! Library which can help you to auto load your classes by registering prefix.
I suggest you to read this link.

Related

LobbySystem not working? Minecraft Plugin

I have a problem:
I wrote a lobby plugin for a Minecraft server and now it doesn't quite work anymore.
In what way:
As soon as I reinstall the plugin, everything works perfectly. But as soon as I change something in a config file, only one method of the plugin loads.
I have linked the plugin here:
Plugin
Source Code
Would be cool if you guys can help me.
The issue appear because of lines like this one:
new File("plugins//Lobysystem//preandsuffixes.yml");
1) Don't write your own folder
Spigot already has API to do it. In the onEnable method, you can do saveDefaultConfig() that will create the folder for the plugin's config.
2) Use Spigot's informations
Such as spigot have multiple way to make config file fastly, you can do something like this (already with the plugin instance):
new File(getDataFolder(), "preandsuffixes.yml");
3) The static method will no longer work
Yes, if you have to use the plugin instance, all of the static {} method will not work. If you really want to keep a static method to load everything, you can do something like that:
public static loadConfig(Main plugin) {
myconfig = new File(plugin.getDataFolder(), "preandsuffixes.yml");
}
#Override
public void onEnable() {
loadConfig(this);
}
4) Stackoverflow guidelines
It's off-topic for an answer, but few tips :
Try to don't include link to download unknow source
Add a minimal reproductible example instead of just giving all the code
Don't decompile plugin.
Take the time to identify problem and to be more clear than "it was working but now it's no longer working"

Custom Helper Class not found in Prestashop module

I created a helper class in prestashop 1.6 module, in the override directory. I included the file in main module file but the class is not found in tpl files. I need it there to call one static method from smarty template.
Any ideas with this?
Thanks.

How to include 3rd party JavaScript libraries in a reusable gwt library/widget?

I'm trying to get my feet wet with GWT to see if migrating will work out. I usually try the more difficult parts first to make sure I can finish the project. The most difficult part of my project(s) is referencing 3rd party JS libs. In this example I'm trying to use PubNub as much of our platform uses it.
What I'd like to do is create a reusable object that can be used in other GWT projects in need of PubNub. I've got a simple little test running successfully (ie, I've got the basics of JNSI working), but my question is -> where do I put the reference to the 3rd party script in order to create the library/module properly?
Right now I just put the reference to the external scripts in the HTML page in the project, but I'm pretty sure this is incorrect from a reusability perspective, as this lib would be used in other projects, each of which would have their own base HTML page.
I tried putting the reference in the gwt.xml file, but this seems to lose the references (ie my test project no longer works as it did when the scripts were in the HTML page)
Do you have any tips on how to include 3rd party libraries in a reusable GWT library/widget?
Here you have an example using client bundles and script injector, you can use either synchronous loading or asynchronous.
When using sync the external js content will be embedded in the application, otherwise it will be include in a different fragment which will be got with an ajax request.
You can put your api in any server and load it with the ScriptInjector.
public class Example {
public static interface MyApiJs extends ClientBundle {
MyApiJs INSTANCE = GWT.create(MyApiJs.class);
#Source("my_api.js")
TextResource sync();
#Source("my_api.js") // Should be in the same domain or configure CORS
ExternalTextResource async();
}
public void loadSync() {
String js = MyApiJs.INSTANCE.sync().getText();
ScriptInjector.fromString(js).inject();
}
public void loadAsync() throws ResourceException {
MyApiJs.INSTANCE.async().getText(new ResourceCallback<TextResource>() {
public void onSuccess(TextResource r) {
String js = r.getText();
ScriptInjector.fromString(js).inject();
}
public void onError(ResourceException e) {
}
});
}
public void loadFromExternalUrl() {
ScriptInjector.fromUrl("http://.../my_api.js").inject();
}
}
[EDITED]
A better approach is to use a new feature in gwtquery 1.4.0 named JsniBundle. We introduced this feature during the GWT.create conferences at San Francisco and Frankfurt.
With this approach you can insert any external javascript (placed in your source tree or hosted in an external host) as a JSNI block. It has many benefits:
Take advantage of GWT jsni validators, obfuscators and optimizers.
Get rid of any jsni java method when the application does not use it.
The syntax is actually easy:
public interface JQueryBundle extends JsniBundle {
#LibrarySource("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
public void initJQuery();
}
JQueryBundle jQuery = GWT.create(JQueryBundle.class);
jQuery.initJQuery();

GWT: deferred loading of external JS resources

I have a widget depending on some external JS files, and I'd like to lazy load all these external resources. I've already used code splitting to lazy load the GWT code that concerns the widget, but the JS files defined in the gwt.xml, using the script tag, are loaded anyway, which is not desirable.
Is there a standard GWT way of loading these external resources on demand? I can do it myself using raw JS, but I'd rather not spend time on this too.
I think you'll want to take a look at the com.google.gwt.core.client.ScriptInjector class. From the javadocs:
Dynamically create a script tag and attach it to the DOM.
...
Usage with script loaded as URL:
ScriptInjector.fromUrl("http://example.com/foo.js").setCallback(
new Callback<Void, Exception>() {
public void onFailure(Exception reason) {
Window.alert("Script load failed.");
}
public void onSuccess(Void result) {
Window.alert("Script load success.");
}
}).inject();
This code can of course be invoked from within your split points, or indeed anywhere in your code.
ScriptInjector is quite portable. It doesn't have any external dependencies, so you should be able to backport it into your 2.3 application without much problem.

Zend Framework and switching view script paths

I have a problem. Basically, depending on whether a user goes to /es or /br or /cn etc on our website, we have different language template files. So far, we were using a custom templating engine to make this work, but are making a switch over to ZF. I can't seem to figure out how to get ZF to look for a view script in say cn/about-us if the language varuable is cn.
I can't (don't want to) use Zend_Translate for this because we have way too many translated template files and it's just not feasible using Zend_Translate for bazillion different files with multi-paragraphs of Chinese/Korean/Japanese, forgetting for a second that I don't speak those languages.
Can anybody help me?
You can write a controller plugin and use it's routeStartup() method to alter Zend_View settings (path to where your view scripts are located) and change the request uri before routing starts.
class My_Controller_Plugin_LanguageSwitcher extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
// examine the $_SERVER['REQUEST_URI'] and look for your language identifier
// fetch the View and set appropriate view scripts path using setScriptPath() method
// strip the language identifier from your REQUEST_URI
// change the request uri using $request->setRequestUri('your-new-uri-without-the-language- identifier');
}
}