Linkr uses events to interact with other extensions.
Related readings:
Related readings:
onLinkrGetLinks
This event is called when the view is first being displayed. It passes one argument (current installed version of Linkr) and expects an associative array of titles and javascript statements to be returned. Here's an example of a plugin that would create links for a fictitious extension Foo:
class plgContentFoo extends JPlugin { // Your code... // As of 2.2.2, $version is an interger function onLinkrGetLinks( $version ) { return array( // Link title => Javascript statement 'Foo' => 'FooJavaScriptFunc()' ); } }
onLinkrLoadJS
This is where the plugin would return the javascript needed for it to work. It is recommended to use objects and variables, but you're plugin can work just fine with a combination of functions (see Object-Oriented Programming
). Here's an example from the Foo plugin:
). Here's an example from the Foo plugin:class plgContentFoo extends JPlugin { // Your code... // As of 2.2.2, $version is an interger function onLinkrLoadJS( $version ) { // URL for AJAX requests. Be sure to use full URLs $r = JURI::base() .'index.php?option=com_foo'. '&tmpl=component&view=foo'; // Security measure to prevent CSRF* $r .= '&'. JUtility::getToken() .'=1'; // Javascript return 'var LinkrFoo = { requestURL:"'. $r .'", /* etc, etc */ }'; } }
onLinkrLoadL18N
Since 2.3.1 This is where your plugin can supply a array of strings to be localized and stored in the LinkrHelper variable (on the client side). The Foo plugin's example:
class plgContentFoo extends JPlugin { // Your code... // As of 2.2.2, $version is an interger function onLinkrLoadL18N( $version ) { // Linkr will pass these strings // through JText and UTF8 encode them // before storing them in the // LinkrHelper variable return array( 'FOO', 'BAR', 'FOO_BAR', 'LADY', 'MAN', 'CHILD' ); } }
Tips/Tricks
You can make a link available only in the back-end. This is how you would check to see if the article is being edited from the front-end or back-end:
class plgContentFoo extends JPlugin { // Your code... function onLinkrLoadJS( $version ) { global $mainframe; if ( $mainframe->isAdmin() ) { // execute code } } }
Example
Here is what your plugin might look like:
// Plugin Librairies jimport( 'joomla.plugin.plugin' ); // Foo Plugin class plgContentFoo extends JPlugin { // Constructor function plgContentFoo( &$subject, $config ) { parent::__construct( $subject, $config ); } // Send links to Linkr function onLinkrGetLinks( $version ) { return array( // Link title => Javascript statement 'Foo' => 'FooJavaScriptFunc()' ); } // Scripts function onLinkrLoadJS( $version ) { $doc = & JFactory::getDocument(); $doc->addScript( 'plugins/content/foo/script.js' ); // URL for AJAX requests. Be sure to use full URLs $r = JURI::base() .'index.php?option=com_foo'. '&tmpl=component&view=foo&'. JUtility::getToken() .'=1'; return 'LinkrFoo.init("'. $r .'")'; } }



