writing new plugin, help needed please

Creating and modifying plugins.
Post Reply
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

writing new plugin, help needed please

Post by carl_galloway »

Hi all, I'm working on a plugin to display text-link-ads which uses an external php file, and I want users to be able to upload the php code file and the blank xml file from within the plugin config in admin suite. Ideally I would like to be able to call or access the media manager from the plugins screen (just like when you're editing entries) and then use the file name for the php code to include the file.

1. So is it possible to use the media manager from a plugin?
2. And then can I save the filename separately so I can call it as a variable in my include statement?
3. Also, the xml file needs to be writeable, are uploaded files automatically writeable or do I need to do something else as well?

This is my first attempt at a plugin so I do want to learn, but I also need to know where to look and what to look for.

Thanks,

Carl
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: writing new plugin, help needed please

Post by garvinhicking »

Hi!

First, that sounds a bit tough. Uploading files from the plugin config section is not really meant to happen, because the FORM tag of the config doesn'T contain the multipart-action type. We could patch this of course, but then your plugin would only work with s9y versions starting now.

Your other route of using the Media manager sounds IMHO a tad better. However, there uploading active content like .php files is not allowed. So you'd need to upload .txt files (which can contain .php code, but are not parsed when calling them via HTTP).

To do that, you just access the media manager like this in your plugin:

Code: Select all

    function introspect_config_item($name, &$propbag) {
        switch($name) {
            case 'custom_file':
                $propbag->add('type', 'content');
                $propbag->add('name', 'Custom File');
                $propbag->add('description', 'Click this link to choose your file.');
                $propbag->add('default', '<input type="text" name="serendipity[plugin][custom_file]" id="plugin_custom_file" /><input type="button" name="insImage" value="' . IMAGE . '" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[htmltarget]=plugin_custom_file&serendipity[filename_only]=true\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" class="serendipityPrettyButton" />');
                break;
        }
    }                
You can see the image selector uses the ID of your custom HTML snippet to fill in the filename there. Just like the entryproperites plugin which allows to use images in the custom fields.

In your plugin you can then use

Code: Select all

<?php
include $this->get_config('custom_file');
?>
3. Also, the xml file needs to be writeable, are uploaded files automatically writeable or do I need to do something else as well?
Yes, uploaded files are writable for the PHP process, otherwise the ycouldn't be uploaded.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

ok, this plugin probably won't be used by too many people and rewriting the plugin code to allow use of the media manager to upload files isn't worth it.

I'll try your sufggestion and see if that looks like a winner - thanks.
Post Reply