Web Tool Bag  
Home · Articles · Downloads · Discussion Forum · Web Links · News Categories · Synonyms DatabaseNovember 19 2017 10:51:51
Navigation
Home
Articles
Downloads
Discussion Forum
Web Links
News Categories
Synonyms Database
Search
Users Online
Guests Online: 1
No Members Online

Registered Members: 856
Unactivated Members: 118
Newest Member: lakim
Forum Threads
Newest Threads
Uncaught Error: _reg...
Module build failed:...
Installation
mochi script questions
Redirect with captch...
Hottest Threads
Installation [12]
Any questions and... [5]
Captcha picture d... [4]
Integrate with Vi... [4]
Mods: Sucess/Than... [4]
 
Latest Articles
PHP Fatal error: Ca...
Mouse pointer disapp...
UBUNTU install via U...
Geany tried to acces...
How to create MySql ...
Gallery 2 Module Development
Article about development of plugins and modules for Gallery 2.

Welcome to this Gallery2 Module Development tutorial.

The reason why i'll make this tutorial is because i personaly had trouble learning how to make custom modules.
I hope to make things more clear to you, so we'll find more tutorials online. :)

You will most likeley find some wrong phrases or grammer in this text, for english is not my native language.

Lets cut the talk, and i will explain some basics about modules, and how gallery2 works. (note that i will use G2 as a abbreviation for Gallery2)

How dous Gallery2 work?

- How the code lookes like
The thing what is very striking, is that G2 is Object Orientated. This basicly means you will be trown in quite some classes and methods.
You dont need to understand OOP (Object Orientated Programming) to make G2 Modules. It may be more easy to understand the code when you have some experience in OOP though.

- Storing data
Data can be stored in various ways.. Parameters, Maps and Entities. We'll start with parameters, for they are quite handy for storing a few values. With this, think about some text for a module, that you want to edit easily. Or maybe an email adress for a contact module?
But be carefull to not to store to much in your Parameter Map. When you'll build something like a guestbook, you dont want to use the Parameters. The parameter table is just one table, that contacts a few values of all modules. You dont want to fill the table with hundereds of entries of just one module.
When you will create something as big as a guestbook, you will choose for a map or entitie.

- How to controll the look of your module
G2 works with a Template Parser (Smarty). This means that you seperate your code from the layout. This is much cleaner, you will understand more about these templates when we'll start making a page.

- How your module is connected to G2
All of your actions are controlled via the API, this a sort of link between your module, and the core.


Make the base of the module!

Ok lets start with building our base. I will first show you the code, and after that we'll break the code, and handle each line.

CODE

Code:

1
<?php
2

3
/*
4
 * Gallery - a web based photo album viewer and editor
5
 * Copyright (C) 2000-2006 Bharat Mediratta
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or (at
10
 * your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful, but
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
20
 */

21

22
/*
23
 * Jim's test module (the name)
24
 *
25
 * A module to show you how the base works. (a more wide description)
26
 *
27
 * @package Jimsmodule (package name)
28
 * @author Jim Bokhove <your@email.com>
29
 * @version $Revision$ $Date: 2006/11/24 22:43:00 $
30
 */

31

32
class JimsModule extends GalleryModule {
33

34

35
    
function JimsModule() {
36
        
global $gallery;
37

38
        $this
->setId('jimsmodule');
39
        $this
->setName($gallery->i18n('Jims Module'));
40
        $this
->setDescription($gallery->i18n('Description? Well, this shows you the base.'));
41
        $this
->setVersion('0.0.1');
42
        $this
->setGroup('newgroup', $gallery->i18n('New Group'));
43
        $this
->setCallbacks('');
44
        $this
->setRequiredCoreApi(array(7, 10));
45
        $this
->setRequiredModuleApi(array(3, 2));
46
    
}
47

48
}
49

50

51
?>



- Eplained
First we need to define we're writing PHP code with
Followed by a block which contains Copyrights, license etc.

Now, you'll see a comment block with some info of your module. Just fill the lines with your own names, description etc.

After this is done, you will see the real deal. Starting some real code! "class JimsModule extends GalleryModule {" defines the name of the module. And also let G2 this is a module. You may only change the second word, and fill in your own. Dont change the GalleryModule name or something.

Ok, we have ourselves a start, now define the function of the class (OOP stuff, dont need to understand why..). WARNING: The function name, must be 100% the same as your class name! So when your classname is in this case JimsModule, your function also needs to be named JimsModule.

"global $gallery" grabs a variable from the system. We'll go further in this later.

Okay, now you'll see a few lines. These lines defines the name, description, version, etc etc.

Lets start with: $this->setId('jimsmodule');
Just fill in a clean name like above, no uppercase.

$this->setName($gallery->i18n('Jims Module'));
Defines a clean name, this is the name you will read in G2.

$this->setDescription($gallery->i18n('Description? Well, this shows you the base.'));
Description of your module.. No explenation needed right? :)

$this->setVersion('0.0.1');
The version of your script. Update this when you make a change on your module, this can be very handy, en ofcourse.. It is needed. :)

$this->setGroup('newgroup', $gallery->i18n('New Group'));
This defines the group. The group is where you will find your module listed in the admin panel. I used New Group to be more clear, but recommend to use an existing group. (just grab a group from the module page, which you think suits your module best.)

$this->setCallbacks('');
We'll come back to this line, it is not needed to fill in. But it comes with very nice feathures.

$this->setRequiredCoreApi(array(7, 10));
$this->setRequiredModuleApi(array(3, 2));
These are vesions of API's. This exists so you wont get problems when you import an old or new module, that dousn't work with your current G2 install. If you dont know what version you have, just grab a module from the galler2/modules/ directory. And open that module.inc file to check what the have.

And to end this, close your function and class with a }. And ofcourse we close the PHP script with ?>.

Save this file as module.inc

Now make a folder that contains the name of the module. ($this->setId('jimsmodule'); < this name)

Copy module.inc into the folder, and upload the folder to your gallery2/modules/ directory.

Now simply open your admin panel, go to the modules page. And you can activate your module. Next time we'll make a static page that uses a template.

http://www.combined-minds.net/

Posted by admin on December 10 2007 17:47:28 4234 Reads · Print
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Member Poll
Which PHP framework do you preffer?

Symfony

Zend

CodeIgniter

PHP on TRAX

eZ Components

Fusebox

PhpOpenbiz

Prado

QPHP

Seagull

You must login to vote.
Shoutbox
You must login to post a message.

Vince
03/10/2011 21:17
Hi, How to remove Register from Login screen? I don't want them to register and have full access! if you leave register then they should not have any rights until the admin assigns them

webtoolz
26/09/2011 11:28
Please describe your problem with more details. Thank you.

bimmer98
22/11/2010 20:31
Help. There was a problem with the request; error regarding feedbackzdr form program

Copyright © 2017 - www.webtoolbag.com