11
mvandam
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/17 2:06

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


I think this is a very good division of the issues.

On the clonability side, I think most modules will have problems unless written *very* carefully. Ideally, you should just be able to change 'dirname' in xoops_version.php and have yourself a new copy. This would require the mod-writer to use the 'dirname' variable for ALL references to stuff in the module:

- database tables must be constructed from xoops_prefix + dirname + tablename
- any files/paths mentioned the dirname must be constructed from the dirname variable
- any URLs containg the dirname must be constructed from the dirname variable
- all constants (including language constants) must be constructed from e.g. _MI_ + dirname variable + language key
- others?

If these steps are not taken, there will be conflicts with two instances of the module running.


On the presentation side, I agree that yes you can have a lot of mileage with a given module just by changing some language strings (and perhaps templates).

12
theCat
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/17 10:38

  • theCat

  • Just popping in

  • Posts: 77

  • Since: 2004/2/2 2


Quote:
- others?

Don't forget functions and blocks.
Examples with news02
Search
Quote:
xoops_version ;
$modversion['search']['func'] = "news02_search";

include\search.inc.php :
function news02_search($queryarray, $andor, $limit, $offset, $userid)


comment
Quote:

xoops_version :
$modversion['comments']['callbackFile'] = 'include/comment_functions.php';
$modversion['comments']['callback']['approve'] = 'news02_com_approve';
$modversion['comments']['callback']['update'] = 'news02_com_update';


Notify
Quote:

xoops_version:
$modversion['notification']['lookup_func'] = 'news02_notify_iteminfo';


Blocks
Quote:

xoops_version:
$modversion['blocks'][3]['file'] = "news_top.php";
$modversion['blocks'][3]['show_func'] = "b_news02_top_show";
$modversion['blocks'][3]['edit_func'] = "b_news02_top_edit";

news_top.php
function b_news02_top_show($options) {

function b_news02_top_edit($options) {


13
krayc
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/17 14:00

  • krayc

  • Not too shy to talk

  • Posts: 107

  • Since: 2004/2/17


To refine the clonability from the admin/developer side.

Rather than get to fine-grained on the 'dirname' internally, wouldn't it make sene to use it where it is clear there would be a conflict with another module, such as table names, etc?

But as for function names (and I am not yet clear on the scope of function names) do they have to be different module to module?

And on this point, where I look to undertand scope? is this dictated by the PHP language?

In plain english, can two different modules have a class with the same name?
Or from the example above can "myMOD_search" be define in different modules without conflict?

krayc

14
phatjew
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/17 15:18

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


I agree that for function names, there is no reason to make a distinction between two copies of the same module -- after all, if it is truly a clone, then the same code is going to be executed.

As for two classes, that is the same. If you put your class inside your own module directory, it doesn't matter (since each clone will look at its own directory). If you put your class under the "class" directory, then you only need one copy for any number of clones, because the point of a class is that it is reusable.

I do agree, however, that blocks have to handled very carefully. Maybe just including the dirname in the name of the blocks will work. I'll be coding it over the next couple of weeks, so I'll update this thread with what I find out.

15
mvandam
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/18 8:25

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


Quote:

I agree that for function names, there is no reason to make a distinction between two copies of the same module -- after all, if it is truly a clone, then the same code is going to be executed.

As for two classes, that is the same. If you put your class inside your own module directory, it doesn't matter (since each clone will look at its own directory). If you put your class under the "class" directory, then you only need one copy for any number of clones, because the point of a class is that it is reusable.

Good point. However, modules are treated independently by Xoops, and if both modules are loaded (e.g. a block from each clone, or a menu item from each clone), then there are going to be clashes. (All functions and classes are defined in a global scope. If a file is included containing functions or classes which are already defined, then errors will result.)

In the cloned module, you'd probably have to make manual modifications to just include the code from the *other* module so files don't get included twice. (Or you could use 'if function_defined', 'if class_exists' to conditionally load files.) Not impossible, but also not as simple as just installing two copies of the module with different dirname.

16
phatjew
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/18 17:05

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Quote:
In the cloned module, you'd probably have to make manual modifications to just include the code from the *other* module so files don't get included twice. (Or you could use 'if function_defined', 'if class_exists' to conditionally load files.) Not impossible, but also not as simple as just installing two copies of the module with different dirname.


I did not realize that classes and functions defined inside a module would be global. Is that a good idea, in general?

Regardless, absolutely you'd have to be careful since they are defined globally. Could you maybe provide examples of how to use the 'if function_defined', 'if class_exists' to conditionally load files? I would think that 'if function_NOT_defined' would be the way to go, but I don't know how to do that, either.

Also, could you use "include_once" or something like that instead?


17
mvandam
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/19 0:04

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


Quote:

I did not realize that classes and functions defined inside a module would be global. Is that a good idea, in general?

This is something that PHP does... we really have no choice in the matter. That is why we have all the naming rules for functions, class, language constants etc... it is so that when we process blocks etc from several modules, that we don't get collisions when we include their classes and functions.

Quote:

Regardless, absolutely you'd have to be careful since they are defined globally. Could you maybe provide examples of how to use the 'if function_defined', 'if class_exists' to conditionally load files? I would think that 'if function_NOT_defined' would be the way to go, but I don't know how to do that, either.

Also, could you use "include_once" or something like that instead?

include_once might work, depending on how the module is implemented. If your cloned module shares the *same* files then this would be good enough (i.e. 'news2' actually includes files from the 'news1' directory). If they have the same files, but each has their OWN copy of the same files, then this won't help because PHP considers them as distinct files.

However, most of this is irrelevant because most people write their functions with hard-coded dirname-dependent things. For example a function 'news_get_all_articles' might contain something like: $sql = "SELECT * from xoops_news_articles", etc... In the cloned module we need xoops_news2_articles, so basically we need a *copy* of the function but we'd have to name it 'news2_get_all_articles' so both functions can be used together. Basically this requires everything to be duplicated, but with change of 'news' to 'news2' everywhere.

The alternative is to write modules such that the database table 'xoops_news_articles' is not hard-coded, but somehow looked up every time it is needed. Then two modules could share one copy of the code and still function independently. This would be very tricky, and XOOPS may not support enough core functionality to do this.

I'm not sure my suggestions of 'function_defined' are all that useful, but here's a little info. This is a built-in PHP feature:

if (!function_defined('news_get_all_articles')) {
    
// load some file containing this function
  
}


Sorry for the confusing post... hopefully it helps a bit . If you have any questions about it, let me know...

18
jurgis
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/19 0:43

  • jurgis

  • Just popping in

  • Posts: 72

  • Since: 2003/3/20


when cloning modules , where dirs are hardcoded grep can help a lot :) (in php and sql, as 1rst time i forgot sql and had some bad effect ;)
my choise washttp://www.wingrep.com/
really nice piece of work

19
phatjew
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/19 14:04

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


Quote:
However, most of this is irrelevant because most people write their functions with hard-coded dirname-dependent things.


I'm trying to avoid exactly this. I figure that if I write my functions in a generic fashion (using 'dirname' where appropriate, etc.), I shouldn't have any problems. What's the fastest way to access the current dirname? I know there is more than one way to do it, but if I am going to access it repeatedly I want to do so as efficiently as possible. The example above uses:

$module->getVar('dirname')


but, if I'm using a language constant for the dirname ,wouldn't it be faster to just use that constant?


jurgis, I completely agree on grep. I've used it on *nix for years, and love it. Thanks for the link to the windows version -- I didn't even know it existed.

20
mvandam
Re: XOOPS Dev Team: Would it be hard to propagate module name in all reference to the module?
  • 2004/3/19 18:56

  • mvandam

  • Quite a regular

  • Posts: 253

  • Since: 2003/2/7 2


Quote:

but, if I'm using a language constant for the dirname ,wouldn't it be faster to just use that constant?

The problem is the language constant will have to be different for the module and its clone. Thus you'd have to replace the language constant everywhere in the cloned module. e.g. _MI_NEWS_DIRNAME => _MI_NEWS2_DIRNAME. So I don't think it solves the problem . You'll have to use something which is dynamically updated, like $module->get('dirname'). There is a small performance penalty (only a function call because the module info is cached internally), and if you are careful about *when* you retrieve the info in your code you can minimize the overhead. Good luck!

Login

Who's Online

174 user(s) are online (113 user(s) are browsing Support Forums)


Members: 0


Guests: 174


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits