dbQwikSite User Forum

Custom code functions
Page 1 of 1

Author:  beedeejay [ Mon Sep 08, 2008 6:04 pm ]
Post subject:  Custom code functions

Is it possible to include your own function's into qs_functions at design time?

Author:  Ugain [ Tue Sep 09, 2008 5:23 am ]
Post subject:  Re: Custom code functions

I believe the content of this file is driven by what you input to dbQwikSite dialogs

Author:  olivierg [ Thu Sep 11, 2008 10:07 am ]
Post subject:  Re: Custom code functions

Actually no, it is not driven by options you enter. It is pretty much hard wired.

If you look at your dbQwikSite installation path, e.g. C:\Program Files\dbQwikSite 5\Data\Includes\QSLib you will see qs_functions.xxx files, one for each language.

What you get in your generated folder is exactly these files. So one way would be to simply edit the qs_functions.php to add your own. But this is not recommended simply because these files will be overridden as soon as you run a live-update.

There is an alternative solution which I will post here very soon.

Author:  olivierg [ Thu Sep 11, 2008 6:19 pm ]
Post subject:  Re: Custom code functions

Ok, here is the solution. It will be a standard implementation very soon, but you can use it already following these instructions.

Many of you probably noticed the 'Plugins' menu in dbQwikSite. None of you know that you can write your own plugins. Probably because it is not documented anywhere... yet.

Plugins are usually visible in the menus of dbQwikSite, and not only under the 'plugins' menu. You just do not know there are many features implemented as 'plugins'.

One particularity of plugins is that they can be invoked not only from menus. They can also 'subscribe' to events fired by dbQwikSite main program. Events like On Create Project, or Before/After Site generation are available for Plugins' consumption.

What I am providing here is a Plugin that subscribes to the 'After Site Generation' event. It means that once dbQwikSite has done all its work to generate all the files, the Plugin will run and do things. Things like... copying your own files or overriding generated files.

How does this plugin work?

We have decided that a new folder would be added to 'My Documents\My QwikSites\', called 'My Libraries'. That folder is structured like this:

In other words: \My Documents\My QwikSites\My Libraries\...

The processing of these folders is as follow:

1. dbQwikSite copies all files AND sub-folders of the '..\Global\Common' folder
2a. dbQwikSite copies all files AND sub-folders of the '..\Global\Asp' folder if your target language is ASP
2b. dbQwikSite copies all files AND sub-folders of the '..\Global\Php' folder if your target language is PHP
3. dbQwikSite copies all files AND sub-folders of the '..\[ProjectName]\Common' folder
4a. dbQwikSite copies all files AND sub-folders of the '..\[ProjectName]\Asp' folder if your target language is ASP
4b. dbQwikSite copies all files AND sub-folders of the '..\[ProjectName]\Php' folder if your target language is PHP

(It copies to your target generation folder)

What does that mean?

If you work on multiple projects and you have common function files, or images, or Css, or anything that you want to automatically deploy with all of your projects, they should be within the ..\Global\ branch.

If you have files that are specific to a given project, specific by language if necessary, put these files under ..\[ProjectName]\ folders.

Obviously, if you have CSS, Images, JS scripts that are only for one project, you can put them in the project itself (in ..\Projects). But you have that flexibility.

If you look into the \asp and \php folders, you will see a file called user_includes.asp or php. Use this include file to either write your own functions in it, or include other files with an include statement. The user_includes is systematically included in all generated code.

The files being copied in the above sequence is overridding whatever is on the target. So if you have a user_includes.php in the Global branch AND a user_includes.php in the Project Name branch, the later wins, overridding the file from the Global branch. dbQwikSite will not smartly 'merge' the contents of both files.

If you have a sub-folder called ..\Common\images with an image file with the same name as an image in your project folder, the file provided in the Common branch will override the one in your project. As explained before, this plugin runs 'After Site Generation', so it overules anything you have in your project.

Some people may actually be interested in this feature in particular for Database Connections. Some of you have complained that you need to use very special ADO connection strings to secured systems, bridges, whatever. You can place a 'qs_connections.xxx' in the My Libraries\[ProjectName]\Asp (or Php) and this will override what dbQwikSite generated. So if dbQwikSite does not offer you enough flexibility with database connection string builder, you are free to use your own this way.

If you look at the generated ASP or PHP pages and locate the include statements, you will see an include of qs_functions.xxx. The qs_functions.xxx is the file that itself includes the user_includes.xxx. So now you know where it is included in your pages.

This plugin applies to ALL Editions, so it is not limited to Developer Edition users!

Installing the Plugin

Download this file:
My Libraries Plugin Files.rar

The rar file contains a number of files that need to be dispatched carefully. Here are the instructions:

1. Copy qs_functions.asp and qs_functions.php to C:\Program Files\dbQwikSite 5\Data\Includes\QSLib

2. Copy QS_ApplyLibraries.plug to C:\Program Files\dbQwikSite 5\Integration\core\utils

3. Unzip My Libraries (For Programs-Data).rar under C:\Program Files\dbQwikSite 5\Data (you should see 'My Libraries' under '\Data' after unzip)

4. Unzip My Libraries (For My Documents).rar under My Documents\My QwikSites\ (you should see 'My Libraries' under '\My QwikSites' after unzip)

Restart dbQwikSite, the plugin will be loaded and active. You will not see any menu item anywhere. It is a back-end plugin only.

Should you have any error at the end of Code Generation and it cannot be resolved, rename the file QS_ApplyLibraries.plug to QS_ApplyLibraries.plug_DISABLED so it is not loaded anymore (and post your issue to this post).

Final Notes:

- This Plugin is provided 'as-is'. If you have problems with it you can add entries in this post. Testers are welcome to report issues here.
- Do not ask for a Plugins Developer's Guide or any documentation related to Plugins. It does not exist yet.
- Do not send technical plugins questions to the Support team, they'd probably say Plug'what? :wink:
- If you have questions about plugins in general, you can post them on this forum (as a new discussion thread please!) and I will try to find time to answer them... but you may have to wait!

Author:  Gerald [ Thu Sep 11, 2008 11:03 pm ]
Post subject:  Re: Custom code functions

To help say it in a another way. After installing this plug in. You can put files into the My Libraries folder structure which either replace or add to the files generated.
This relates to the question "Can I change qs_functions.php?" The answer is yes, and if you put your copy into My Libraries/Global/php your copy of qs_functions will replace the standard one for ALL projects. If you put it into a /projectxxx/php it will only override qs_functions for that project.

The solution extends further than just replacing QS generated files. This plug-in makes it possible to include other files into your generated code. For example I use a set of php classes for mySQL that I want to be in /phpclasses in the deployed code. So if I put Global/PHP a folder called phpclasses containing all the php scripts for that class, I will now get /phpclasses in every project I generate. That's great, so the classes are there, but I need to include them in my pages with a "requires" statement. I can do that by adding the requires statement to the user includes.php. Now every page I generate will include the phpclasses reference.

If you need fine tuning, then Developer Edition and custom code is the best route, the good part about this plug in is that it can be used to globally affect all projects and that you can use it with any Edition not just Developer Edition.

Author:  commissionxchange [ Fri Feb 06, 2009 12:38 pm ]
Post subject:  Re: Custom code functions

Is this still valid? if so I think it deserves a sticky? Has there been any documentation on how to write plugins?

Page 1 of 1 All times are UTC + 7 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group