Joomla! event for plugin edit page / onPluginEdit? - joomla

I have a system plugin and on its configuration page I'm adding some styles/scripts like this:
function onAfterDispatch(){
// some magic here....
if($app->isAdmin()){
# Get current component & its layout
$option = JRequest::getVar('option');
$layout = JRequest::getVar('layout');
# Add some styling on plugin's edit page
if($option == 'com_plugins' && $layout == 'edit') $doc->addStyleSheet($mediapath . '/themes/mystyle.css');
}
}
... which works great!
But, if the plugin is disabled the onAfterDispatch is not called and mystyle.css and other scripts that I wish to add on this page won't be loaded.
So, is there a method of doing this when plugin is disabled? I need some event like onPluginEdit or even onPluginSave...
*This is a plugin for J! 2.5 / 3.x

Related

Creating the cloning of forms in wordpress settings page Wordpress Plugin Development

I want to Add new form below the existing form in my wordpress plugin settings page by adding the Add more form and remove button what should i do
i tried the on click funciton but did not get event the first alert of testing done
$(document).ready(function(){
$("#addmorebtn").click(function(){
alert("testing done");
$(".multipleforms .single-form:last-child").clone().appendTo(".multipleforms");
});
$(document).on('click','btn-remove',function(){
if($(".multipleforms .single-form").length > 1)
{
$(this).parents(".single-form").remove();
}
});
});

Ckeditor plugin configuration not working

I have tried to add justify plugin to be able to align text right, left or centre. But after following the instructions in the documentation (http://apostrophecms.org/docs/tutorials/howtos/ckeditor.html), I wonder if the plugin should be located in a specific folder (mine is at public/modules/apostrophe-areas/js/ckeditorPlugins/justify/), as it disappears when the site is loaded, but if I include it in some other folder such as public/plugins/justify still doesn't work.
This is my code just in case: (located at lib/modules/apostrophe-areas/public/js/user.js)
apos.define('apostrophe-areas', {
construct: function(self, options) {
// Use the super pattern - don't forget to call the original method
var superEnableCkeditor = self.enableCkeditor;
self.enableCkeditor = function() {
superEnableCkeditor();
// Now do as we please
CKEDITOR.plugins.addExternal('justify', '/modules/apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js');
};
}
});
Also, it would be nice to know how the plugin should be called at the Toolbar settings for editable widgets.
Thanks!
The URL you need is:
/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/
The my- prefix is automatically prepended so that the public folders of both the original apostrophe-areas module and your project-level extension of it can have a distinct URL. Otherwise there would be no way for both to access their user.js, for instance.
I'll add this note to the HOWTO in question, which currently handwaves the issue by stubbing in a made-up URL.
As for how the plugin should be called, use the toolbar control name exported by that plugin — that part is a ckeditor question, not really an Apostrophe one. But looking at the source code of that plugin they are probably JustifyLeft, JustifyCenter, JustifyRight and JustifyBlock.
It turns out that it's not enough to simply call CKEDITOR.plugins.addExternal inside apostophe-areas. You also need to override self.beforeCkeditorInline of the apostrophe-rich-text-widgets-editor module and explicitly call self.config.extraPlugins = 'your_plugin_name';.
Here's what I ended up with:
In lib/modules/apostrophe-areas/public/js/user.js:
apos.define('apostrophe-areas', {
construct: function(self, options) {
// Use the super pattern - don't forget to call the original method
var superEnableCkeditor = self.enableCkeditor;
self.enableCkeditor = function() {
superEnableCkeditor();
// Now do as we please
CKEDITOR.plugins.addExternal('justify', '/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js');
};
}
});
then in in lib/modules/apostrophe-rich-text-widgets/public/js/editor.js:
apos.define('apostrophe-rich-text-widgets-editor', {
construct: function(self, options) {
self.beforeCkeditorInline = function() {
self.config.extraPlugins = 'justify';
};
}
});
For some reason doing CKEDITOR.config.extraPlugins = 'justify' inside apostrophe-areas does not work, probably due to the way how CKEDITOR is initialized;
One more thing: this particular plug-in (justify, that is) does not seem to follow the button definition logic. It has button icons defined as images, whereas CKEditor 4.6 used in Apostrophe CMS 2.3 uses font-awesome to display icons. It means that the icons that ship with the justify module won't be displayed and you'll have to write your own css for each button individually.
There is another issue which you'll probably face when you finally enable the justify buttons. The built-in html sanitizer will be strip off the styles justify adds to align the content.
Apostrophe CMS seems to be using sanitize-html to sanitize the input, so changing CKEditor settings won't have any effect. To solve the issue, add the following to your app.js:
'apostrophe-rich-text-widgets': {
// The standard list copied from the module, plus sup and sub
sanitizeHtml: {
allowedAttributes: {
a: ['href', 'name', 'target'],
img: ['src'],
'*': ['style'] //this will make sure the style attribute is not stripped off
}
}
}
Thank you both for your help. After following both approaches of: locating the plugin at my-apostrophe-areas folder as well as editing editor.js on the apostrophe-rich-text widget (the sanitize.html file was already using that configuration), I got the plugin working. However, I was still having the issue with the icons.
I fixed that adding the Font Awesome icons that correspond to align-justify, align-right, align-left and align-center at the end of public/modules/apostrophe-areas/js/vendor/ckeditor/skins/apostrophe/editor.less

How to disable cache for a image carousel in TYPO3

My TYPO3 extension has a lib that generates random 5 images from the total stock, for example out of the 100 images. This is done randomly every time the page is loaded. Only default the TYPO3 cache is enabled so every time the same 5 images are showed. As the lib is in the header of the website (so on every page) I don't want to disable the cache. How can I disable the cache of only this one lib?
TypoScript:
plugin.tx_ExtName.widgets {
Slider = USER
Slider {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
vendorName = Name
extensionName = ExtName
pluginName = Backend
controller = Customers
action = Slider
switchableControllerActions {
Customers{
1 = Slider
}
}
settings =< plugin.tx_ExtName.settings
persistence =< plugin.tx_ExtName.persistence
view =< plugin.tx_ExtName.view
}
}
lib {
slider < plugin.tx_ExtName.widgets.Slider
}
in your ext_localconf.php there, where you added your plugin make an usage of the 4-th param of configurePlugin method
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.' . $_EXTKEY,
'PluginName',
array('Customers' => 'slider',),
array('Customers' => 'slider',) // List non-cachable action(s)
);
Of course fix the VendorName and PluginName to your own. It will cause that plugin's actions won't be cached, while whole page will be kept in cache still.
Alternative solution
You can also use JavaScript for this, just place an JS array of paths in the source code and choose 5 random items on document load it will allow you to avoid non-cached content.
Alternative solution: plugin.tx_ExtName.widgets.Slider = USER_INT.
This makes sure that the Slider plugin is always uncached.

How to render this Joomla module to another position without loosing its connection to the article

This is code from the Dizi-images module (plugin/content/images/images.php) for Joomla. This works, it publishes a image or image gallery at the end of a specific article.
But if I want to publish the image/image gallery to another position (by changing its position in Joomla admin and the getModules-value in the code below) it looses its "connection" to the article. It shows up on every article on the site.
Is it possible to make this code below to be able to publish the image/image gallery to another position without loosing its connection to the specific article?
/*
* load front end images module
*/
public function onContentAfterDisplay( $context, &$row, &$params, $limitstart = null )
{
$jinput = JFactory::getApplication()->input;
$option = $jinput->get('option', '', '');
$view = $jinput->get('view', '', '');
if( $context == 'com_content.article' && ( $modules = JModuleHelper::getModules( 'images' ) ) )
{
return JModuleHelper::renderModule( $modules[ 0 ] );
}
return '';
}
Thanks
Magnus
Screenshot of the modules that I change position on (Joomla Admin/Extensions/Module Manager/)
The plug-in I use is "Dizi images gallery"-extension.
This shows the Dizi-images Tab. Where you add images/image gallery to the article your in.
These three lines of code will allow you load and render any existing modules as needed.
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_myimagemodulename', 'Images Gallery');
echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));
If you want to manage from the back end, you will need to make a duplicate of the existing module with different menu position assignments. It sounds like the only limitation is the source images folder, so the module should not mind!
** EDIT **
To create a new position like "right", you would need to add a new jdoc element to your templates index.php where you would like the new position:
<jdoc:include type="moduels" name="right" style="xhtml" />
Then in your templates manifest XML file, add the new position to list of existing positions:
<position>right</position>
Now if you navigate to the module copy you want to place there, you would be able to select the newly created "right" position.
** EDIT **
Noticed something in how the module instance is being loaded, the name should reflect the the module type and name.
$modules = JModuleHelper::getModules( 'images', 'Images gallery' )
And definitely migrate away from JRequest.
Why not just create a new instance of the module for the other position? That way this module stays just as it is and the new module is published elsewhere without conflicting with the code you have.
Also agree with Lodder, use JInput.

Auto save joomla article for client

i know its sounds a bit crazy, but so many clients have problems with not saving their article properly.
I just wanted to use a simple method to trigger the onclick of the APPLY button inside a joomla article in edit mode.
Primarily back end editing as i have a good admin template that allows me to show clients the bare bones.
I know that by clicking apply the page reloads but thats better than nothing.
How on earth do i add do this?
I was hoping something like this would work but i dont quite know how to trigger a button that seems to reside inside a toolbar function of some sort.
I have this:
<script type="text/javascript">
$(document).ready(function() {
$('??????').trigger('click');
});
</script>
What would replace the question marks?
Also i know i would need to put a timer into the jquery code but how do i get the link below to trigger?
http://mydomain.com/administrator/index.php?option=com_content&sectionid=1&task=edit&cid[]=97
In the toolbar.content.html.php file joomla has this:
class TOOLBAR_content
{
function _EDIT($edit)
{
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$cid = intval($cid[0]);
$text = ( $edit ? JText::_( 'Edit' ) : JText::_( 'New' ) );
JToolBarHelper::title( JText::_( 'Article' ).': <small><small>[ '. $text.' ]</small></small>', 'addedit.png' );
JToolBarHelper::preview( 'index.php?option=com_content&id='.$cid.'&tmpl=component', true );
JToolBarHelper::save();
/////////////////////////////////////
JToolBarHelper::apply(); // < // THIS IS WHAT I WANT TO TRIGGER
/////////////////////////////////////
if ( $edit ) {
// for existing articles the button is renamed `close`
JToolBarHelper::cancel( 'cancel', 'Close' );
} else {
JToolBarHelper::cancel();
}
}
...... more stuff here
}
I know this might sound crazy but wouldnt it be great if autosave could happen even without a reload, but i guess that would mean posting all the data using jquery rather than the php post and reload page method.
Anyways im not expecting a miracle here but if anyone could help that would be great.
Cheers in advance
John
PS:
i just tried something like this hoping maybe it will work but it just reloads the page:
function autosave()
{
window.location = "index.php?option=com_content&sectionid=<?php echo $_GET['sectionid'];?>&task=edit&cid[]=<?php echo $row->id;?>"
}
You won't be able to do it without forcing a reload unless you decide to re-write the whole of com_content with an ajax implementation.
Looking at the code you've posted I guessing Joomla! 1.5 - which by default has MooTools 1.12 or 1.2.5 (if you enabled the MooTools upgrade plugin in later versions of 1.5.x) - so more of a question but why not use that?
You will have to modify the admin template to embed the JS you need, 1.5 has few triggers and none that are really worth using in the admin screens (unless you're up for a fair bit of PHP coding)
Somewhere in the <head> tag of com_content's Article view you will need to add this:
<script type="text/javascript">
var interval = 30 //seconds
var timer = setTimeout(submitbutton('apply'),(interval * 1000));
}
</script>
Please note I haven't tried this just typed it straight into here.
Since you're on 1.5 have you tried the Simple Content Versioning extension - it has autosave functionality that appears to be what you want - and probably works whereas who knows with my code in #3.

Resources