(PHPmyGallery 1.51 gold - FAQ/Help)

Select page Users - Developers - Other stuff

Chapters: [‾]

`1.` | Introduction
`2.` | Customizing
`2.1.` | Example
`2.2.` | Templates
`3.` | Coding PlugIns
`3.1.` | Files
`3.2.` | Links&Forms
`3.3.` | Multilanguage
`3.4.` | Sample Plugin GalleryConvertor
`3.5.` | Submitting
`4.` | Debugging
(to top)

#
1. Introduction

This help page covers the PHPmyGallery script from a coder's point of view. It won't teach you every detail but you can find a place where to start modifying the script. Have fun coding!

#
2. Customizing

This script is template based, which means you can change the look of the pages to what you like. It's easy to make PHPmyGallery match your design.
In PHPmyGallery a template is a textfile which is read by the script into memory, then the script replaces certain content with content of PHP variables created by the script. Content that has to be replaced is marked with an open curled brace ({), a dollar sign ($), a name (with letters, numbers, minus (also called hyphen), underscores and dots) and finally a closed curled brace (}). We will call this a template variable from now on.
So something like {$name} within the templates is replaced by the content of a PHP variable during the script. Templates can also be used within templates, for example {$text_content} of _conf/templates/phpmygallery.html is replaced with content that came from other templates.
To customise the look of the script, you have to know how to read and write HTML files yourself. Please note: Using graphical editors for editing templates can be a problem since some of them insert
and
which may result in wrong output to the browser.
You can implement your own layout by leaving the template variables and building your own HTML code around. You won't have to edit all of them to make them match your design.
All templates are in the _conf/templates/ directory. They are organised in several subdirectories:
The main script:
Template files within the _conf/templates/ directory are used throughout the script. phpmygallery.html is the main template for the gallery pages.
index_view - for displaying the available groups
group_view - for displaying the galleries within a group
gallery_view - for displaying the thumbnails/picturelinks within a gallery
picture_view - for displaying a picture of a gallery
plugins - for templates used by PlugIns
The admin menu:
adminmenu - Small templates used throughout the adminmenu. adminmenu.html is the main template for the admin menu.
adminmenu/faqhelp - for displaying the help pages
adminmenu/fileperms - for displaying the file permissions page
adminmenu/gallery_settings - for displaying the gallery settings page. Used for main settings, too
adminmenu/groups_settings - for displaying the groups settings page
adminmenu/htaccess_create - for displaying the htaccess file creation pages
adminmenu/index_view - for displaying the starting page of the admin menu
adminmenu/login - for displaying the login page
adminmenu/picture_descriptions - for displaying the picture descriptions page
adminmenu/plugins - for displaying the plugins listing page
adminmenu/sessionpwd_create - for displaying the password creating page
adminmenu/statistics - for displaying the statistics page
Experimenting with the templates can't do any harm, just read the Examples section and try fooling around. Always keep a backup of files you edit :)

## 2.1. Example

Let's say you want to have your own website logo to display on the pages (assuming your logo is named logo.gif (300x60) and is within a directory named gfx in your home directory), edit templates/all_pageLogo.html.
It should look like this:
<a href="{$link_tophpmygalleryindex}"><img src="PHPmyGallery_grey.gif" align="left" width="200" height="46" alt="" border="0"></a>
Change it to:
<a href="{$link_tophpmygalleryindex}"><img src="/gfx/logo.gif" align="left" width="300" height="60" alt="my logo" border="0"></a>
And there you go. PHPmyGallery should be displaying your own logo. Editing templates is mostly this easy. Just keep the template variables intact.
PHPmyGallery uses the phpmygallery.css file for colors and font sizes etc.

## 2.2. Templates

Templates are used in several ways all over the scripts. We will create a sample page rendered with the pktpl template system. At first, take a look at the templates files we create in the templates directory...
Sample.html:
<html>
<head>
<title>{$title}</title>
</head>
<body>
{$template_myTable}
</body>
</html>
Table.html:
<table>{$template_tableRows}</table>
TableRow.html:
<tr><td>{$text_left}</td><td>{$text_right}</td></tr>
Here is the script that renders the HTML page. We will discuss what it does how afterwards.
$pktpl_vars = pktpl_start(); would initialize the template variables to an empty array, we assume this already happened.
myScript.php:
1 $arr = array('One','Two','Three');
2 $pktpl_vars['title'] = 'Testing pktpl';
3
4 $rowCount = 0;
5 $rows = '';
6 foreach($arr as $v) {
7 $rowCount++;
8 $pktpl_vars['text_left'] = $rowCount.':';
9 $pktpl_vars['text_right'] = $v;
10
11 $rows .= pktpl('TableRow.html');
12 }
13 $pktpl_vars['template_tableRows'] = $rows;
14 $pktpl_vars['template_myTable'] = pktpl('Table.html');
15
16 echo( pktpl('Sample.html') );
Line 1: Initializing an array which will be used to generate HTML-table rows from. The array could also have come from the database or an external include file.
Line 2: Simply assigning a string to the pktpl_vars array. Notice that {$title} within our first template will be replaced by what is stored in $pktpl_vars['title']. If you use the same template variable name in several templates, make sure you overwrite the old version or you will see the old value in the other template. pktpl never resets the pktpl_vars array. Also check for PHP's automatic type-conversion for numbers to strings.
Lines 4-5: Initialisations for the foreach loop. Instead of $rows we could also have used $pktpl_vars['template_tableRows'] directly.
Lines 8-9: Assigning the values for {$text_left} and {$text_right} for the current iteration.
Line 11: The pktpl function opens the template and replaces all template variables found with the entries from the $pktpl_vars array. If a variable is not found in $pktpl_vars, the function replaces with an empty string. Finally, the function returns the template with all variables replaced. Note that we use .= to add each table row to the previous ones.
Line 13: Assign all rows at once to $pktpl_vars['template_tableRows']. {$template_tableRows} is used in the Table.html template.
Line 14: By calling the pktpl function here, {$template_myTable} will hold the complete table with all table rows as one string, once we call pktpl('Sample.html');
Line 16: The final step, one call to pktpl with Sample.html as parameter. The result is directly output to the browser.
There we have a complete HTML page done with pktpl. Now you only have to change the templates instead of the PHP code when you want to change the design.

#
3. Coding PlugIns

Coding PlugIns for the backend can also be done easily if you read the Templates section. You place a .php file in the plug-ins directory containing any PHP code you like. As the last line, it has to set $pktpl_vars['template_admin_table'] to the HTML code you want to output.
Sample plugin (you can call it Sample.php):
$pktpl_vars['template_admin_table'] = "My name is Sheltem.";
Put this in the plug-ins directory and visit the admin menu plug-ins section. There it should be listed. Click on it now to see it work.
A plug-in can modify the whole database, use all template variables previously defined and use all templates within the templates directory.

## 3.1. Files

Normally, a PlugIn consists of several files: A php file to execute the plugin, a language pack file, a txt file with the same filename (with a short description that is displayed in the PlugIns section of the admin menu), a ReadMe_ file and optionally several templates.
For example, the GalleryConvertor PlugIn has GalleryConvertor.php, GalleryConvertor.txt, ReadMe_GalleryConvertor.txt, two language packs in lang/ and some templates in templates/plugins/GalleryConvertor/. If you want, you can use all the other templates within the templates directory if they suit the needs of the PlugIn. Your PlugIns should be organised like this, too.
pktpl should be called this way for your own PlugIn templates:
$pktpl_vars['variablename'] = pktpl('plugins/PluginName/templatefile.html');
Substitute variablename, PluginName and templatefile with what works for you.

## 3.2. Links&Forms

To use links and forms within your PlugIns, you have to format them a special way. Put the following in the action tag of forms or href tags of links...
Use this for your links:
{$backendscript_filename}?action=plugins&plugin={$pluginLink}{$your_vars}{$GET_params}
backendscript_filename - Links back to the admin menu's index.php (set automatically)
action=plugins - sets action to include _conf/_php-core/adminmenu/do_plugins.php
pluginLink - sets selected plugin to execute your plugin script again (set from within do_plugins.php automatically)
your_vars - replace this with one or more GET variables to do an action within your script. See below.
GET_params - holds the session id with sessions login or nothing if htaccess login (set automatically).
You can use variables passed by a form ($_POST) the way you are used to. Just the action tag has to look like shown above.
Implementing your_vars from the example above:
$var = $_GET['var'];
$pktpl_vars['your_vars'] = '&var='.$var;

## 3.3. Multilanguage

A Plugin should make use of the lang directory to put language specific messages there. As for GalleryConvertor, it can use GalleryConvertor.English.php or GalleryConvertor.Deutsch.php.
Within a language pack there has to be an array $l which is added to the pktpl_vars array by using the processLanguagePack function (_conf/_php-core/functions.php). Look up the function definition or take a look how GalleryConvertor makes it work.
The processLanguagePack function looks up if a language pack for the current language exists, if not it tries to use a default language which you supply to the function. It will put out an error message if both language files could not be found.

## 3.4. Sample Plugin GalleryConvertor

Please don't hesitate to use GalleryConvertor as a starting point to code your own PlugIns. It demonstrates how to load and save stuff from and to the database, and it uses several custom templates.
If you have further questions coming up, just use the Contact link from the admin menu.

## 3.5. Submitting

Use the contact form on PHPmyGallery's website (or use the Contact link in the admin menu) to inform me about your PlugIn.
I will respond with an email address you can send your zip file to. I will test your PlugIn as soon as I can and then send some feedback to you about it. If I find it to be useful I will make it available for download.
Have fun coding and do backups! :)

#
4. Debugging

If you have problems coding the script, you can use the built in debugger. It receives an HTML or plain-text formatted string within the variable $debugCode and displays it within the browser. This way you can locate a problem pretty fast.
This can be done from anywhere of the code. If you want to debug within a function, write global $debugCode; right after the opening brace ( { ) of the function.
Example:
function myFunction() {
global $debugText;
$debugText = "Easy debugging";
}
Any text that $debugText holds will be displayed within a grey window "above" the website.
Note: To debug an array, use the arr2php function of PHPmyGallery. It receives an array and the variable name as parameters.
Example:
$arr = array(1,2,3,4,5,10);
$debugText = arr2php($arr,"arr");
View available pktpl_vars entries:
$debugText = arr2php(array_keys($pktpl_vars),"pktpl_vars");
View available language variables:
$debugText = arr2php(array_keys($l),"l");

Created with PHPmyGallery 1.51 gold © Copyright 2002-2007 Peter Krebs (PeKa)