Recent Topics

1 Aug 02, 2006 17:37    

Heres my structure;


/plugins/
  /gallery_plugin/
    _gallery.plugin.php
    /1_1/
      /gallery_plugin/
        _gallery.plugin.php
        etc
   /1_2/
     etc
   /2_0/
     etc

Now /plugins/gallery_plugin/_gallery.plugin.php contains;

<?php

require(dirname(__FILE__).'/1_2/gallery_plugin/_gallery.plugin.php');

?>

Now when a plugin is in a sub-dir like above, then the events are not found. But they are when there are none of this sub-dir stuff i'm doing.

Now the problem is with Plugins->get_registered_events(); as it scans the php file contents for events. And it gets the php files location via $Plugin->classfile_path so a workaround would be this;

		if( !strstr( $Plugin->classfile_path, 'gallery_plugin' ) )
			$classfile_contents = file_get_contents( $Plugin->classfile_path );
		else
			$classfile_contents = file_get_contents( 'D:/Files/Documents/Site/Dev/b2evolution/blogs/plugins/gallery_plugin/1_2/gallery_plugin/_gallery.plugin.php' );

Which works.

Now a proper fix, would be so classes can specify their own classfile_path parameter.

-Balupton signing out.

Creds to Yabba for helping me debug this, although i swear i told you it had something to do with the classfile_path when we started ;)

2 Aug 02, 2006 18:03

How does the subplugin get instantiated?

Does your main/regular instantiate it? How?

btw: what a path..! (/blogs/plugins/gallery_plugin/1_2/gallery_plugin/_gallery.plugin.php 8| )

4 Aug 02, 2006 18:28

Ah.. I see..

Use symlinks instead.. :p

There's no easy solution. The best I could think of, would be to test if $classfile_path is already set (and not set it then) and then use

var $classfile_path = __FILE__;


in the real plugin.
But that's an additional isset() check (not too bad, but not really needed either), does probably not work with PHP4 and you would have to "patch" the plugin file nonetheless and could therefor also do it in PluginInit() (speaking for 1.9/HEAD).

real solution: symlinks (instead of a real file with require()). I've read somewhere, somewhen that you can simulate symlinks on Windows - heck, a normal "Link" should work probably.

5 Aug 02, 2006 18:33

you mean that isset would have to go in _plugins.class.php not my plugin. Well i think this is the best solution anyway... But why would it not work with php4?

Edit: actually, instead of scanning the php class file for events, why don't plugin developers just have a array with the events they use, like GetDefaultSettings, but GetEvents(); or something....... I don't know why this wasn't done in the first place... Seems the best thing to me.

6 Aug 02, 2006 20:06

you mean that isset would have to go in _plugins.class.php not my plugin. Well i think this is the best solution anyway...

This is a "solution" to a very specific, local problem.

__FILE__ in "var $..." does work in PHP4, just tested. But again, a local problem (you might ship your plugin with this "feature", but in general it just "clutters" the plugin class file and is not needed).

GetEvents() has not been used, because of the magic geekiness, which the current solution provides. It's a bit like testing for functionality in Javascript rather than detecting the browser by parsing the user agent string.

However, adding an optional GetEvents(), which would not trigger the "parsing of events" is a good/valid point.

It does not fix the $classfile_path problem, though.

Why do you not just use filesystem links?

7 Aug 03, 2006 04:07

blueyed wrote:

you mean that isset would have to go in _plugins.class.php not my plugin. Well i think this is the best solution anyway...

This is a "solution" to a very specific, local problem.

__FILE__ in "var $..." does work in PHP4, just tested. But again, a local problem (you might ship your plugin with this "feature", but in general it just "clutters" the plugin class file and is not needed).

GetEvents() has not been used, because of the magic geekiness, which the current solution provides. It's a bit like testing for functionality in Javascript rather than detecting the browser by parsing the user agent string.

However, adding an optional GetEvents(), which would not trigger the "parsing of events" is a good/valid point.

It does not fix the $classfile_path problem, though.

Why do you not just use filesystem links?

I use windows, and then i would need to do all crazy stuff. But this is a problem with b2evolution, not my setup.

Adding GetEvents() fixes the problem, and it is the only problem i can see with the classfile_path....

Although what was the problem with the plugin setting it's own classfile_path again?
php.net wrote:

The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.

8 Aug 03, 2006 04:33

Well here is a 'fix':

In $Plugins->Register change;

		else
		{
			$Plugin = new $classname;	// COPY !
		}
		
		$Plugin->classfile_path = $classfile_path;

		// Tell him his ID :)
		if( $ID == 0 )
		{
			$Plugin->ID = --$this->smallest_internal_ID;
		}

to

		else
		{
			$Plugin = new $classname;	// COPY !
		}
		
		if( !isset($Plugin->classfile_path) )
			$Plugin->classfile_path = $classfile_path;

		// Tell him his ID :)
		if( $ID == 0 )
		{
			$Plugin->ID = --$this->smallest_internal_ID;
		}

And just add;

var $classfile_path = __FILE__;


to the plugin.

Probably a better way to do this, anyway that works, and is a better fix than symlinks imho.

9 Aug 03, 2006 15:10

"better fix than symlinks"? :D

You are using a regular file, with just an include/require line in it, to serve as a symlink.. why is that better than using a symlink right away?

And, as said, you should be able to use "Links"/Shortcuts in Widows, too.

The file layout you use, is just for your testing.

I, for myself, just use symlinks which I put into my /plugins/ folder and which point to some directory in /svn/evocms-plugins/XXX/trunk/.


Form is loading...