to interact with other extensions. Related readings:
onLinkrGetLinks
This event is called when the view is first being displayed. It passes one argument (currently installed version of Linkr) and expects an associative array of titles and javascript functions 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 integer function onLinkrGetLinks( $version ) { return array( // Link title => Javascript function 'Foo' => 'JavaScriptFunction()' ); } }Optionally, you can specify the each link's name by returning an array instead of the function (since 2.3.5):
function onLinkrGetLinks( $version ) { $links = array(); $links[] = array( 'name' => 'foo', 'text' => 'Foo Link', 'click' => 'JavaScriptFunction()' ); return $links; }
onLinkrGetTools
Since 2.3.5 The principal is the same as for onLinkrGetLinks, but the returned links will appear in the "Tools" row, next to "Bookmarks", "Related Articles", and "{ linkr:none }" in the Linkr window.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:
class plgContentFoo extends JPlugin { // Your code... // As of 2.2.2, $version is an integer // Since 2.3.5: $include is an array of // links that should be displayed function onLinkrLoadJS($version, $include) { // Make sure "Foo" link wasn't disabled if (!$include['foo']) { return ''; } // 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 integer function onLinkrLoadL18N($version, $include) { // 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, $include) { 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(array( 'name' => 'foo', 'text' => 'Foo', 'click' => 'JavaScriptFunction()' )); } // Scripts function onLinkrLoadJS($version, $inc) { if (!$inc['foo']) { return ''; } $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 .'")'; } }



