Creating a folder in Media Manager on Module installation

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
djtaylor1321
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jan 11, 2011 4:23 pm
Location: Washington, D.C.
Contact:

Creating a folder in Media Manager on Module installation

Post by djtaylor1321 » Tue Jan 11, 2011 4:40 pm

Hello! Since this is my first time posting on these forums, here is a brief introduction. My name is Dave, and I am a web developer, designer, and server administrator at a graduate school in Washington D.C. I work for the George Washington University, for the Graduate School of Education and Human Development.

I am currently developing a brand new site for my school, as our current CMS is terrible (has anyone even heard of Wise Publisher?). Right now I am working on developing a module that is displayed on the home page, and is a rotating banner. The module itself is complete, and seems to work fine in 1.6. However; my question is as follows:

Is it possible to automate the creation of a folder in the media manager (specifically /images/modules/mod_hero_large) when the module is first installed? I have searched the forums, and Google, and have found nothing. It seems it is possible to do something like this with a component, but not a module. Is there a way to do this, perhaps some kind of PHP script that runs when you open the module properties in the Module Manager?

I am fine doing it manually for now, but if you don't create the folder before opening the module properties, you are obviously shown a slew of errors. I would like to have the installation and set-up of the module as streamlined as possible.

Thanks in advance for any help (and my apologies if this has been answered somewhere else and I wasn't persistent enough in my search)!

mbabker
Joomla! Hero
Joomla! Hero
Posts: 2230
Joined: Sun Feb 28, 2010 8:26 pm

Re: Creating a folder in Media Manager on Module installatio

Post by mbabker » Tue Jan 11, 2011 5:06 pm

I don't believe there is a core solution for this. I was looking at an extension that has a <media> tag in the installation XML for 1.5, and it appears that they've written an additional installation script to do this. So, with a little bit of PHP coding, you could do it, but there isn't a native way with the Joomla! installer it appears. Of course, I could be wrong too.

djtaylor1321
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jan 11, 2011 4:23 pm
Location: Washington, D.C.
Contact:

Re: Creating a folder in Media Manager on Module installatio

Post by djtaylor1321 » Tue Jan 11, 2011 11:38 pm

Well, after doing some more research and messing around with the module's install package, I think I have made a bit of progress.

While digging around in the code of the few 1.6 native modules that are out there, I found one particular module with the element <scriptfile>mod_your_mod.install.php</scriptfile> in the module's XML file. It seems the file does run on installation, as I would get an error trying to install if that particular script had any problems with the PHP. When the install is complete, the script file is removed from the module folder in the Joomla directory.

However; I can't seem to get the script to create a folder in the images directory, but that may just be a problem with me not knowing how to properly use the JFolder class. I will post more after I have done some more testing.

Credit for discovering the <scriptfile></scriptfile> element goes to Walter Cedric. I found that element after dissecting his Random Image module.
http://www.waltercedric.com/joomla-main ... la-16.html

djtaylor1321
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jan 11, 2011 4:23 pm
Location: Washington, D.C.
Contact:

Re: Creating a folder in Media Manager on Module installatio

Post by djtaylor1321 » Wed Jan 12, 2011 4:17 pm

Made some more progress. It seems the file included in the <scriptfile></scriptfile> element does run during installation. If I put an extra bracket somewhere in the file, an error is thrown during install. However; any code that is correct doesn't seem to run. I try to get a simple alert box to show up, but no luck. See code below:

Code: Select all

<?php

// no direct access
defined('_JEXEC') or die;

} // incorrectly used bracket to see if Joomla is actually parsing this file during module installation

class mod_mediumHeroInstallerScript
{

	function install($parent)
	{	
		echo("<script type=\"text/javascript\">");
		echo("alert(\"The installer script does actually work for modules.\");");
		echo("</script>");
	}
	
	function uninstall($parent)
	{
		// uninstall script goes here
	}
	
	function update($parent)
	{
		// update script goes here
	}
	
	function preflight($type, $parent)
	{
		// preflight script goes here
	}
	
	function postflight($type, $parent)
	{
		// postflight script goes here
	}

}
I am referring to http://docs.joomla.org/Developing_a_Mod ... _-_Part_15 for my syntax of the scriptfile. That particular page is talking about a component, so it may just be that modules do not support the scriptfile element.


Locked

Return to “Extensions for Joomla! 2.5”