| Version 1 (modified by thomasb, 6 years ago) (diff) |
|---|
RoundCube Development Guidelines
Here are a few rules and explanations that should make it easier for new contributors to understand the structure and guidelines of the RoundCube code base. See PHP Commons for common functions and classes available in the RoundCube framework.
Directory structure
The root folder of a RoundCube installation contains the following folders:
- config/
- Home of the local configurations files
- program/
-
All application files are stored in this folder.
These files will be relaced when upgrading the installation
- program/js/
- Client JavaScript files
- program/lib/
- External libraries used for RoundCube
- program/include/
- Classes and core functions
- program/localization/
- Contains subfolders with localization files
- program/steps/
- Include files for every task/action
- bin/
- Commandline tools and shell scripts for internal use
- logs/
- Contains log files. This folder has to be writable for the webserver.
- temp/
-
Location of temporary saved files such as attachments and cache files.
This folder has to be writable for the webserver. - skins/
- Contains skin subfolders
- SQL/
- SQL files for database initialization and update. Only needed for installations or upgrades
Important files
All requests from the client are sent to index.php. This index file loads all core components and establishes connections to the database and the IMAP server. It analyzes the request and then includes on of the step files. Direct access to config, log and temp folders should not be permitted.
For Apache webservers which allow local overrides, the .htaccess file includes some PHP configuration settings as well as file access directives. More .htaccess files are located in the protected folders mentioned above.
Naming conventions
File names
In general all files should have the appropriate extension such as .php, .js, etc. For PHP include files that are not meant to be executed directly please use the extension .inc. This prevents them from being executed directly in case that the access restrictions do not work as intended.
All files should be named with lower case letters and underlines (for word separation).
Functions and variables
Function and variable names only contain lower case letters and numbers and use underlines for word separation. In classes private methods usually start with an underline.
Functions providing RoundCube specific functionality should start with either rcmail_ (webmail specific functions) or rcube_ (global/framework functions).
Code style
All code (PHP and JavaScript) obeys the same code style guidelines:
- Opening and closing brackets are on a new line
- Omit brackets for blocks containing only one statement
- Indentation contains of 2 spaces and no tabs!
- Conventional operators should be surrounded by a space
- Commas should be followed by a space
- Semi-colons in for statements should be followed by a space
- All names should be written in English
- Logical units within a block should be separated by at least one blank line
- Iterator variables should be called "i", "j", "k", etc.
- Globals vars (PHP) should be named in upper case
- Variables should be initialized where they are declared and they should be declared in the smallest scope possible
Good code:
function foo_bar($a)
{
$out = '';
if ($a == 1 || $a > 10)
{
$out .= "Case one\n";
write_log("Foo: $a");
}
for ($i=0; $i < 10; $i++)
$out .= $i."a";
return $out;
}
Bad code:
function fooBar($a) {
if ($a==1 || $a>10){
$out .= "Case one\n";
write_log("Foo: $a");
}
for ($i=0;$i<10;$i++) {
$out .= $i."a";
}
return $out;
}
PHP
All code should be functional in PHP 4.3.x and PHP 5.x. Especially for classes, you need to write constructors that work in both PHP versions. When working with files please also make sure that the code works with safe_mode enabled. Set error reporting to E_NOTICE to see if all variables are properly declared.
Comments/Documentation?
Please add comments to logical code blocks giving a short description what this part is intended to do. For PHP classes, please add PHPDoc styled descriptions for public methods. Private method descriptions are optional.
