Building a new module

If you've problems with unsupported - non official ;-) - functionalities use this forum please.
User avatar
cyppher.nl
Posts: 138
Joined: Wed 19. May 2004, 18:38
Location: Hilversum, Netherlands

Building a new module

Postby cyppher.nl » Fri 7. Nov 2008, 21:54

cheers all,

Currently I'm preparing to build a new module for phpwcms. Basic concept is a custom product catalog which can output its data to an XML file for using in (custom) googlemaps infowindows.

As it's been a while since I've coded phpwcms modifications, I need some advice and best practices.
Couldn't find any recent info so here's my questions:

I've researched existing modules as the googlemaps plugin and the shopmodule. They all have backend.default, frontend.init, frontend.render and module.default php files and their core functions in the 'inc' folder.
What do I need to do (or reuse) to build the basic 'framework' for my new module, which functions and vars do I need no mather what?

I've tried but can't get my module to show up in the modules section in the backend. Am I right that enabling a module is no longer needed in 1.3.9? Phpwcms should now be able to detect modules itself, right? So how to enable a module in the backend?

Thanks in advance for all hints, I really like to document my findings and development to help others.

Cheers!
cyppher.
How do you do? And how do you do your wife?

User avatar
Jensensen
Posts: 2986
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: Building a new module

Postby Jensensen » Fri 7. Nov 2008, 22:33

Hi cyppher,

sounds good! Thanks! Great step! Appreciated!
Well, anyway it could be a good idea to contact the "headquarter" directly and to ask:

(A) whether a new mod is needed [generally] and
(B) for certain (actual) aspects of the dev state (while v1.3.9 is still devware ¡be aware¡)

I tell you, because only a few months ago some auspicious, promising new MODs
viewtopic.php?f=8&t=17335
viewtopic.php?f=8&t=17511
came up. After all, it took only weeks, but today ALL of them aren't developed further! :? :cry:

So, better ask the developer for detailed information...
Last edited by Jensensen on Sat 8. Nov 2008, 01:44, edited 1 time in total.
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.

User avatar
cyppher.nl
Posts: 138
Joined: Wed 19. May 2004, 18:38
Location: Hilversum, Netherlands

Re: Building a new module

Postby cyppher.nl » Sat 8. Nov 2008, 00:32

Jensensen wrote:Well, anyway it could be a good idea to contact the "headquarter" directly and to ask:

(A) weather a new mod is needed [generally] and
(B) for certain (actual) aspects of the dev state (while v1.3.9 is still devware ¡be aware¡)
So, better ask the developer for detailed information...

Hello Jensensen, thanks for your info.

Well, as I see it, my client needs this kind of functionality (product catalog, no shop, just a catalog with a portable data container e.g. xml) so I need to build the 'enhancement'. My approach would be to build a module that other people might find usable too.

As for the dev release 1.3.9 (whatever buildno.), Oliver claims on phpwcms.de that 1.3.9 is stable and it's recommended not to use 1.3.3 anymore. So it seems to me that there should be no problems developing for 1.3.9 (Oliver, please confirm!).

I'll post my preparations tomorrow, basic descriptions of needed functionality.
Oliver, in the meantime, could you reply please? What should be the best approach in your eyes to develop a module?

Any other experiences (web-casa > googlemaps, exdata, jwimagerotator, shop etc) with building modules are welcome :idea:

Thanks for the support!
How do you do? And how do you do your wife?

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Re: Building a new module

Postby marcus@localhorst » Sat 8. Nov 2008, 07:28

Hi,
I will try to share some of my experience.

1. take the files that come with mod_shop or mod_glossary - that's a good startpoint
it's good, to install both and look at the database, which tables are created! It's good at all, to study all files, to get an idea how it works.
the shop and glossary works different.
glossary got an own CP for rendering, shop use replacementtags.

2. duplicate, at example, the mod_shop folder and call it mod_yourmodulname (or however - you know)

3.to make your mod visible in Backend Modulsection and/or selectable as contentpart [1] follow this steps:
open module.default.php and edit the variables, it's explained in the file.
open lang/en.lang.php (depends on your BE language en should be default) and edit the first 2 vars

Code: Select all

$BLM['backend_menu'] = 'Your Module';
$BLM['listing_title'] = 'Your Module';

OK - did you designed your module tables yet? that would be good, if not - no problem.
open backend.default.php, this is the controlfile for all actions in MODULE section.
search for

Code: Select all

include_once($phpwcms['modules'][$module]['path'].'setup/setup.php');
and comment it out.
why? it install the databasetables for your module, that you have created or need to create (study the files in setup folder to see what happen)
save all and open your Backend > MODULE
If all went well, your Module is selectable in BE Modulesection, right?

that was the easy part!

4. now it comes to your customization, and that's difficult to say how go further.
here some hints:
go to backend.default.php - the controller file - here you see, all $_GET actions are defined and on these actions some special file inclusions depending - means the different forms and display logics. that all is splitted in some other files found in the inc/ folder.
you will see some variables like $phpwcms['modules'][$module]
you should always work with basic things like print_r($GLOBALS); or print_r($phpwcms['modules'][$module]), to see which values are available (there is a special debugging function which format the code a bit, but I don't know the name right now)
best practice would be, to put all global variables for your module into $phpwcms['modules'][$module].
you can nearly reuse any function and variablescope given by phpwcms.
to write into your database you can use

Code: Select all

 _dbQuery($sql, 'INSERT');
instead of writing all the php functions.
you will stumble about all this basic things in the given module files!
oliver commented all things, so it should be easy to understand.

5. it's no problem to develop for 1.3.9 ^^

6. study the phpwcms sourcefiles (I can't say this often enought ^^) - it takes a while to get an overview, but if you spend some time, many things will be easy to solve.
use a texteditor, which is able to search through your whole local phpwcms files, to find functions, function calls, variables etc.

ok, I hope this helps a bit to start. it's hard to explain all steps, how to build a new module, which function to use and so on.
it depends on your programming skills and how you read given scripts. as I said, you can reuse a lot of functions and logic from the phpwcms core code.

have fun, marcus

[1] you are able to set an own Contentpart with forms (Glossary Module), but you can use Replacementtags in CPs if you prefer (the shop works this way)

breitsch
Posts: 473
Joined: Sun 6. Mar 2005, 23:12
Location: bern switzerland

Re: Building a new module

Postby breitsch » Sat 8. Nov 2008, 10:00

cyppher.nl wrote:Basic concept is a custom product catalog which can output its data to an XML file for using in (custom) googlemaps infowindows


Do you know ExData?
It's not equipped with XML and such stuff, but it has the googlemaps functionality included.
I adapted it once to something similar you might be working on.
http://www.volante.ch/index.php?referenzen
it's a catalog of buildings which can be sorted and filtered in various combinations and displayed in a listing with links to a detailed page for each entry, a imagelisting and the google map with all entries in it, each entry has a detailed info window with further content and the link back to the detailed page of the entry.

Maybe this could be useful to you.
The necessary changes to the original module are not dynamic, so it should be adapted to the specific needs.
PM me if interested.
http://www.youtube.com/watch?v=jqxENMKaeCU
because it's important!
breitsch

User avatar
update
Moderator
Posts: 6311
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Building a new module

Postby update » Sat 8. Nov 2008, 13:21

great explanation, marcus :) Thank you!
The exdata shown has a lot of googlemaps module integrated? I like that very much;)
It's mostly all about webdesign, logo design, new and old pages refresh, print BUT slowly switching to be supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.

User avatar
juergen
Moderator
Posts: 4545
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Building a new module

Postby juergen » Sat 8. Nov 2008, 20:31

In addition to marcus (or I didn't recognize)

Frontend Output of Modules are injected in a Var namend $content['all'] which is under the rendering control of phpwcms Templating.

Backend operations may work as normal PHP Files. (echo, (s)pprint...)

That is only marginal but helps a lot if knowing :mrgreen:

User avatar
Jensensen
Posts: 2986
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: Building a new module

Postby Jensensen » Tue 11. Nov 2008, 19:48

This time it really didn't take long until the newest attempt has already been cancelled. The last published MOD viewtopic.php?p=110987#p110987 [confinement: the headquarter wasn't involved!]
was available online for two hours only.
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.

User avatar
juergen
Moderator
Posts: 4545
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Building a new module

Postby juergen » Tue 11. Nov 2008, 21:13

Jens,

this happens ! Sometimes Mods are withdrawn for security reasons


Return to “hacks & enhancements Support”

Who is online

Users browsing this forum: No registered users and 1 guest