[PHP] Re: Intercepting fopen, mysql_connect, and similar functions for migration

2007-06-10 Thread Globalissa Info
Hello Kelly,
u I don't think there is any lasting value or time saving in changing bad
code, instead, my suggestion is to throw out the badly written code
altogether and start with something else you can actually work with. 

... but if you're going to keep it:

Following is a description of how to replace with constants that may be
univerally applied throughout your code, and changed in one place. This is
pretty much a universal practise in apps which are moved from site to site, it
sounds like you need it:

In changing websites you need a way to identify:

a. the changed absolute file path
b. the changed domain url

This may be achieved a number of ways. One way is:

a. create a constant called ABSOLUTE_FILE_PATH
b. create a constant called DOMAIN_URL

define(ABSOLUTE_FILE_PATH, /public_html/);
define(DOMAIN_URL, http://domain.com/;);

Save the constants in a file called config.php
Include config.php in every file that needs it
Invoke a path or url by using your new constants

example
include_once( config.php ); // bring in the constants
include( ABSOLUTE_FILE_PATH . subfolder/ ); // use a path

echoimg src=' . DOMAIN_URL . images/my_image.png'; // use a url

This leaves the mysql connection stuff: do the same thing
Put the connection data into config.php as constants:

define(DBNAME, enter_a_value_here ); 
define(DBUSERNAME, enter_a_value_here );
define(DBPASSWORD, enter_a_value_here );
define(DBSERVERHOST, enter_a_value_here ); // sometimes localhost

Include config.php (top of page) wherever you use database connects
Replace your db connect code with your new constants


Yes its a lot of work, but so is moving websites. When you're done you can
move the code anywhere by changing one file.

Sincerely,
Rob
http://phpyellow.com

===
Kelly wrote;
Date: Fri, 8 Jun 2007 19:42:10 -0600
From: Kelly Jones [EMAIL PROTECTED]
To: php-general@lists.php.net
Subject: Intercepting fopen, mysql_connect, and similar functions for 
migration
I'm migrating a website from one server to another, and my file paths
and dbs have changed.

For example /a/b/c/foo.txt on the old machine is at /x/y/z/foo.txt on
the new machine. The MySQL db foo on the old machine is bar on the
new machine.

Can I intercept fopen() and mysql_connect() so that when PHP does
fopen(/a/b/c/foo.txt), I magically (using Zend functions or method
overloading or anything else) convert it at runtime to
fopen(/x/y/z/foo.txt).

Same thing so that mysql_connect(foo) becomes mysql_connect(bar).

The code is badly written: doing a search/replace in the code wouldn't
really work. I really want to hook fopen()/mysql_connect() and
similar commands so I can tweak their args before they actually
execute. Is there any hope?

Sort of like an LD_PRELOAD for PHP?

-- 
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile. 
===

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Suggestions of GPL plugin-system?

2007-01-30 Thread Globalissa Info
Hello All (cc Ivo),
We have numerous modules in various software titles and these are included by
a simple conditional statement. If they exist, then include them.


Example:
!-- alphabetical - start --
?php // conditional include to support Lite Edition - start
if( file_exists( search_alphabetical_form.php ) ) {
include( search_alphabetical_form.php );
} // conditional include to support Lite Edition - end ?
!-- alphabetical - end --


... another example:

!-- conditional inclusion --
!-- banip - start --
  ?php if(@file_exists( ../modules/banip/banip.php )):? 
// your code here
  ?php endif;? 
!-- banip - end --


This works well for modules because if they don't exist then they aren't used.
You can use a constant for the installation absolute url when testing for
existence of the file. Also if you always put modules in your /modules folder
then you'll know where to look for them in any software title.  There's other
examples and other code in our free unencrypted phpYellow Lite Edition
downloadable at http://www.globalissa.com/downloads.php . You might also
notice that the @ character can be used to suppress issues with the
conditional call - test that first, and use it sparingly.


Sincerely,
Rob.
http://phpyellow.com

___
Ivo wrote:
Hi guys,

I've been developing a GPL PHP/MySQL app for some time now and I would
like to extend it with a module/plugin system. The idea would be that
people could add a directory in a plugin path that would contain a
bunch of PHP files extending the functionality of my application. This
directory would then be read out, some config file parsed and whatnot,
after which the module can be turned on by my application.

Now, I could try and figure this out by myself, but that would be
reinventing the wheel since I'm betting there is some good GPL modular
software around (such as Joomla, PHP-Nuke, PHPbb, etc, etc.) that you have
been working with as a coder. Could any of you suggest a certain GPL
application that has a great module setup that I could take a look at?

Thanks a lot for your time!

Ivo 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php