Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-file plugins
#1
Hello.
I'm writing a plugin myself, and as it would also include a bit of AJAX I'm trying to fit all the functions and checks in one single file.
Which is bad, in my opinion, it's starting to get messy.

My question is: should I provide myplugin.php with a "myplugin" folder, the first then requiring the proper scripts in "myplugin"?

I ask because I thought of a much cleaner solution, but it needs a modification of "admin/inc/plugin_functions.php":
  • Check plugin files in GSPLUGINPATH, ending in php (as it is now)
  • Check also for folders with a file "plugin.php" or "$(folder name).php" in them (proposed solution)
  • Include the found php file
Reply
#2
tankmiche Wrote:Should I provide myplugin.php with a “myplugin” folder, the first then requiring the proper scripts in “myplugin”?
Many plugins already come together with a folder to hold other files. So yes, that’s the best way to go.

You are right, it might be cleaner to check for folders within the plugins folder. Good idea that will be taken in consideration for the next update of the plugin system.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#3
Automatically including Files within a plugins folder could cause some issues, not all plugins are including files in the plugin itself but in the templates and other administration pages or nowhere at all.

How would it be determined witch files to include?

Does this make sense?
JWH Technologies
Have any marketing ideas for Get-Simple? Let me hear them!
Reply
#4
What I (like to) think tankmiche meant is something like this:

  1. Include all PHP files within GSPLUGINPATH.
  2. Read through folders within GSPLUGINPATH.
  3. If the folder within GSPLUGINPATH includes a file called plugin.php, include this one file.

This way, if I have a plugin that needs several files all of my files can go within the folder instead of having one file outside of the folder. It makes the plugins folder much easier to oversee. 1 file plugins can exist of only their 1 PHP file in the plugin folder. Other plugins exist of only a folder in the plugin folder. Instead of the way they do now: 1 PHP file and 1 folder.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#5
Exactly, sorry for the poor phrasing, when saying "include" I actually meant the require() function as is already used now in plugins_function(). OWS_Matthew, plugins are "included" this way in every page, even though most of them won't use their functions.

Here's the example form plugin_functions.php:23

Code:
foreach ($pluginfiles as $fi)
{
    $pathExt = pathinfo($fi,PATHINFO_EXTENSION );
    $pathName= pathinfo($fi,PATHINFO_FILENAME );
    if ($pathExt=="php")
    {
        $pluginsLoaded=true;
        require_once(GSPLUGINPATH . $fi);
    }
}

Here's the modified code:

Code:
foreach ($pluginfiles as $fi)
{
    $pathExt = pathinfo($fi,PATHINFO_EXTENSION );
    $pathName= pathinfo($fi,PATHINFO_FILENAME );

    if (is_file(GSPLUGINPATH . $fi)){
        if($pathExt == "php"){
            $pluginsLoaded=true;
            require_once(GSPLUGINPATH . $fi);
        }
    } else {
        if($fi != "." && $fi != ".." && is_file(GSPLUGINPATH . $fi . '/plugin.php')){
            $pluginsLoaded=true;
            require_once(GSPLUGINPATH . $fi . '/plugin.php');
        }
    }
}

I added is_file to the first check to avoid requiring directories, and then to check for the existance of a "plugin.php" file.
Note that the slash '/' is supposed to be fine for Win* platforms, and the "." and ".." directories are excluded from the list.
Reply
#6
thanks tankmiche - so this works fine in your setup? does your setup have a combination of plugins that are built the old way and also some with the /folder/plugin.php file?
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#7
ccagle8 Wrote:thanks tankmiche - so this works fine in your setup? does your setup have a combination of plugins that are built the old way and also some with the /folder/plugin.php file?
I'm actually in the middle of the upgrade to the latest version - my ftp service is very slow - as soon as I get a working copy I'll check for problems with older plugins.

Edit: I've checked the code with other plugins. An error occours if these coditions are all met:
  • (probable) A plugin "plugerror" is shipped file+directory
  • (improbable) The directory contains a file named plugin.php
  • (probable) The same file is included without "_once" whithin plugerror.php
  • (probable) The plugin system includes directory/plugin.php before plugerror.php

To avoid this risk we could include all files first, then directories with require_once() to prevent errors. Dunno.
Reply




Users browsing this thread: 1 Guest(s)