Coppermine Photo Gallery v1.5.x: Documentation and Manual

Table of Contents
No translation available

Coding guidelines

Target audience

This part of the documentation is not meant for end users of Coppermine, but only for developers. There is no support for this section, it comes as-is.

End users who wish to modify their copy of coppermine are encouraged to stick to these guidelines as well.

Scope

As Coppermine is a team effort, the team members who contribute code need to make sure that the code remains easy to read, understand and maintain. That's why there is a set of rules defined on this page that should be taken into account when working with the coppermine core code. Although this part of the documentation is aimed at dev team members, users who plan to contribute their code in any form are requested to respect the rules as well if possible (i.e. if you understand them fully).

The coding guidelines on this page are not set in stone - if you (as a dev team member) find during development that one of the guidelines needs review or change, start a thread on the dev board for discussion.


Indentation


General guidelines


PHP code

Formatting

Control Structures

These include if, for, while, switch.

Function Calls

Function Definitions

PHP Code Tags

Nesting of HTML in PHP

When more than one line of HTML needs to be printed, the heredoc syntax should be used instead of ending the PHP processing and starting it later.

Good:

// PHP content here
if ($foo == $bar) {
	print <<< EOT
	<h1>Hello {$bla}</h1>
EOT;
}

Bad:

// PHP content here
if ($foo == $bar) {
	?>
	<h1>Hello <?php echo $bla; ?></h1>
<?php
}

Line breaks

To echo line breaks to the HTML output, use the heredoc syntax or use the variable $LINEBREAK instead of hardcoding line breaks into the code.

Remember to make the variable global inside functions.

Good:

echo '<h1>Hello world</h1>' . $LINEBREAK;
echo '<p>foo bar</p>';
}

Bad:

echo "<h1>Hello world</h1>\n";
echo '<p>foo bar</p>';
}

Naming Conventions


Database queries


Documentation


HTML output

Image-tags in HTML output

Links in HTML output

Form elements in HTML output

Deprecated tags

Deprecated HTML tags like <font> mustn't be introduced into Coppermine unless there is a valid, documented reason to do so.

Prefered tags

The popular tags <b> and <i> are considered to be deprecated tags as well. Because of their popularity, browsers will probably support them for a long time. However, there are better alternatives. For <b>, the replacement tag is <strong>. For <i>, the replacement tag is <em>. If possible, the replacement tags should be used both in HTML output generated by Coppermine as well as the documentation.


Credits for coding guidelines

The core rules on this page have been sketched by Dr. Tarique Sani as a subset of the PEAR coding guidelines. HTML output and database sections are based on a thread created by Unknown W. Brackets from Simplemachines.