FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Classes declared multiple times?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Classes declared multiple times? [message #164908] Sat, 02 April 2011 10:30 Go to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Managed to overcome a problem with an error in the fudapi file but now hit another in my integration quest.

Turns out Class db and associated functions are declared in index.php and in FUDforum/include/theme/EVERYTHEME/db.inc which results in collisions.

I would have thought such reused classes and functions would placed in one location and required once in the flow.



Despite the little hitches, really liking this application and I'll appreciate advice on how to get around this.

Thanks

Re: Classes declared multiple times? [message #164912 is a reply to message #164908] Sat, 02 April 2011 12:24 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
OK. Sorry for joining and firing so many queries (although most seem to be wisely ignoring me).

Just some additional information in case anyone is willing to help.

The setup requires that I change the original index.php to, say, orig_index.php and then add a new index.php that do the integration after calling orig_index.php.

I need to load the forum output into a variable as part of my integration process and have this code.

...
//Get forum output
ob_start();
require( '/path/to/orig_index.php');
$scriptOutput = ob_get_clean();
//End get forum output
...


However, this throws up errors about functions already declared.

When I call orig_index.php directly (after renaming back to index.php), I don't get these errors.

Seems to me that there is a loop going on.
Perhaps somewhere in the flow, there is a check of sorts and the file tries to load itself again.

Any pointers appreciated.

Thanks

Re: Classes declared multiple times? [message #164915 is a reply to message #164912] Sat, 02 April 2011 13:04 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Not sure I understand correctly, buy you shouldn't change index.php as it's regenerated with each theme rebuild.
Rather change src/root_index.php.t and thm/default/tmpl/root_index.tmpl.
If you edit root_index.tmpl, you will notice that it includes (actually embeds) db.inc.
Re: Classes declared multiple times? [message #164916 is a reply to message #164912] Sat, 02 April 2011 13:07 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
OK. Managed to figure out the problem. Just now need to figure out the solution.

The issue is because I had called GLOBALS.php earlier in the flow.

As this calls core.inc, the functions are already declared and when I try to load orig_index.php, it calls GLOBALS.php again which calls core.inc and hence the collisions.

So my options are:
1. Rewrite the script to load index.php earlier
2. Find out how to load GLOBALS.php without the other follow on stuff.
Re: Classes declared multiple times? [message #164917 is a reply to message #164915] Sat, 02 April 2011 13:09 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
naudefj wrote on Sat, 02 April 2011 16:04
Not sure I understand correctly, buy you shouldn't change index.php as it's regenerated with each theme rebuild.
Rather change src/root_index.php.t and thm/default/tmpl/root_index.tmpl.
If you edit root_index.tmpl, you will notice that it includes (actually embeds) db.inc.


HA!. That is another issue I'll need to take account of. I'll look into this later.


Re: Classes declared multiple times? [message #164918 is a reply to message #164917] Sat, 02 April 2011 13:32 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Collisions everywhere!!!

Looks like it is basically impossible to call index.php and fudapi.inc.php in the same flow with the problem being the way db.inc is handled by the software.

I.E. it appears in some form or another several times in different places.

I hope in the upcoming version, a Dont Repeat Yourself and/or Duplication Is Evil approach is embraced.

I'll have been home and dry if the db.inc simply lived in one location and every call to it was conditional.

So close yet so far. Damn!!!

Any one have any luck in taming this db class?

[Updated on: Sat, 02 April 2011 13:33]

Report message to a moderator

Re: Classes declared multiple times? [message #164919 is a reply to message #164918] Sat, 02 April 2011 13:48 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
OK. Managed to get FUDForum embedded in Joomla (Note: not wrapper) but I had to comment out "fud_use('db.inc');" on the last line of fudapi.inc.php.

Not yet sure what the implications of that action is.

Some pages embedded properly and others jumping back to the forum view directly. Not sure if it is caching at work.



Re: Classes declared multiple times? [message #164920 is a reply to message #164919] Sat, 02 April 2011 16:18 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Dayo wrote:
I had to comment out fud_use('db.inc');" on the last line of fudapi.inc.php. Not yet sure what the implications of that action is.


We can make it a conditional include in the next release:
if (!defined('fud_sql_lnk')) {
	fud_use('db.inc');
}


Aanhaling:
I hope in the upcoming version, a Dont Repeat Yourself and/or Duplication Is Evil approach is embraced.


There is no duplication in the actual code. You've been editing a "cached" file.

Would you mind sharing the code with us?
Re: Classes declared multiple times? [message #164921 is a reply to message #164920] Sat, 02 April 2011 16:41 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Quote:

We can make it a conditional include in the next release:
...
Would you mind sharing the code with us?

Certainly ... once I sort out the rough edges or at least get it to a point where you can help get past the line.

Also, after the heads up on index.php been rebuilt, I need to change the way it works. I think I'll add a file called main.php which will call index.php instead of replacing and renaming index.php. I'll then URL Rewrite index.php to main.php and since main.php will be static, this will get past the rebuilding issue.

Will get to that once I sort out some more serious issues such as some urls coming back as site . com // index . php etc.

Thanks for the if statement. Will use this instead.
Re: Classes declared multiple times? [message #164925 is a reply to message #164921] Sat, 02 April 2011 17:54 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Got the main.php URL Rewrite redirection going.

What would be really nice, admittedly largely a vanity thing, would be if the index file was in an admin configurable variable or constant.

Such that something like
$res[$k]->download_url = $GLOBALS['WWW_ROOT'] .'index.php?t=getfile&id='. $v->id;
was
$res[$k]->download_url = $GLOBALS['WWW_INDEX'] .'?t=getfile&id='. $v->id;
where $GLOBALS['WWW_INDEX'] = $GLOBALS['WWW_ROOT'] .$ADMIN_SELECTED_NAME;

or ...
$res[$k]->download_url = $GLOBALS['WWW_ROOT']  . $GLOBALS['WWW_INDEX'] .'?t=getfile&id='. $v->id;
where $GLOBALS['WWW_INDEX'] = $ADMIN_SELECTED_NAME; and $ADMIN_SELECTED_NAME of course defaults to 'index.php' if not set in both instances.

This would stop the link jumping on every url.

Admitted a long shot request which would need changing several lines of code where index.php is hard coded but would be a nice touch though.

I can dream.

[Updated on: Sat, 02 April 2011 17:59]

Report message to a moderator

Re: Classes declared multiple times? [message #164926 is a reply to message #164925] Sat, 02 April 2011 20:44 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
OK. My blitz goes on.

I notice there is a variable in the tmpl files called "ROOT" that is essentailly what I was talking about above.

Example is:

{SECTION: usercp_lnk2}
{ROOT}?t=help_index&{DEF: _rsid}
{SECTION: END}


Does any one know where this is set?

Thanks a mil!!
Re: Classes declared multiple times? [message #164927 is a reply to message #164926] Sat, 02 April 2011 21:02 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Found it.

Line 686 of compiler.inc $cmpl['ROOT'] = 'index.php'; to $cmpl['ROOT'] = 'main.php'; does the job.

This is vital as the webserver URL direct meant some pages, such as login, did not work.

Great thing about this is that it only changes the links in the templates and doesn't touch the actual main.php file. Awesome!

This also actually means that putting the option into the admin config is more straightforward than I initially thought. $cmpl['ROOT'] = $ADMIN_SELECTED_NAME; at that position will do the trick.

Hope this can be considered.
Re: Classes declared multiple times? [message #164929 is a reply to message #164927] Sun, 03 April 2011 05:09 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Dayo wrote:
Line 686 of compiler.inc $cmpl['ROOT'] = 'index.php'; to $cmpl['ROOT'] = 'main.php'; does the job.

Hope this can be considered.


Yes, I think we need to add it.
I frequently find myself changing it as well (to remove the index.php from the URL).

Anyway, I would love to look at the code to see if we can somehow re-factor it into a plugin.
Re: Classes declared multiple times? [message #164930 is a reply to message #164929] Sun, 03 April 2011 05:36 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
It would be great if this could be refactored. Just bear with me a bit.




Re: Classes declared multiple times? [message #164932 is a reply to message #164908] Sun, 03 April 2011 18:03 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Iraq
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
The if statement was not the answer to the issues unfortunately and the only reason it seemed to partially work before was due to other errors in code on my part.

After battling with the app all day today, I have just discovered the main source of the collisions in function __fud_login_common of forum_login.php.

This always calls db.inc in

	if (!$GLOBALS['PATH_TO_FUD_FORUM_DB_INC']) {
		require_once $GLOBALS['INCLUDE'] .'theme/default/db.inc';
	} else {
		require_once $GLOBALS['PATH_TO_FUD_FORUM_DB_INC'];
	}


Temporarily got around this by moving that block under the preceding if (!isset($GLOBALS['FUD_OPT_1'])) { statement.

Looks like i'll have to create my versions of the two files to get around the collisions as I suppose understandably, they were never designed to be called in a situation where index.php is being loaded.

Done for the day. Bed beckons!




Re: Classes declared multiple times? [message #164959 is a reply to message #164932] Sat, 09 April 2011 05:21 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
After a week at this, I have got full visual integration with a few minor kinks to solve on the user integration.

However, I now realise that the collision issues I had been facing, and the necessity to hack the code here and there, had been due to me trying to hijack rather than plug into the flow.

As result, and am going back to Square One with a fresh installation and will be looking to rewrite it as a plugin.

So consider all what was written previously about db.inc, changing the index etc invalid or at least not critical because of the available hooks although probably a good idea overall to have a few tweaks in the code here and there.
Re: Classes declared multiple times? [message #164966 is a reply to message #164959] Sat, 09 April 2011 14:52 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Dayo wrote:
After a week at this, I have got full visual integration with a few minor kinks to solve on the user integration.


Congratulations!

When you are done we can evaluate what changes we need in core to support your solution.
Re: Classes declared multiple times? [message #164967 is a reply to message #164966] Sat, 09 April 2011 15:08 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
Thanks.

Actually, I came to realise that the issues I was facing was becuase I was trying to hijack the flow rather than plug into it so over this weekend, I have refactored the code as a plugin (not yet tested) leveraging the "COMPILER_FINALIZE_PAGE" hook and I don't think any changes to the core are required.

Now working on how to get the plugin to do the following on being enabled to automatically reduce css conflicts:


  1. Find out which theme is currently active
  2. Take a copy of the theme css file
  3. Add an ancestor to every selector item in there
  4. Save this as a tmpl file
  5. Copy and amend forum_css.php.t file to build this new css file

Re: Classes declared multiple times? [message #164992 is a reply to message #164920] Tue, 12 April 2011 11:43 Go to previous messageGo to next message
Dayo is currently offline  Dayo   Bahrain
Messages: 101
Registered: April 2011
Karma: 0
Senior Member
naudefj wrote on Sat, 02 April 2011 19:18

We can make it a conditional include in the next release:
if (!defined('fud_sql_lnk')) {
	fud_use('db.inc');
}



Turns out this is not required as fud_use is conditional alreaady.
Re: Classes declared multiple times? [message #165000 is a reply to message #164992] Thu, 14 April 2011 16:09 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Great feedback!
Luckily we haven't committed anything yet.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Sending to mailing-list with a fixed email address
Next Topic: Tips for higher iPhone/Andriod/Pre compatibility
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 09:38:51 GMT 2024

Total time taken to generate the page: 0.02366 seconds