====== Coding guideline ======
We all have different ways to write our code. That's okay, if you are working alone on a project, but it will become a mess when more people are working on it. That's why pluck-cms has some coding rules, or a way the code should be written.
There are a few reasons for this:
* The code will look the same.
* It's easier to read.
* You can work on code that another person has written.
===== Newline style =====
In text files, a newline is signified by a character. You don't notice anything of this, because that character is automatically inserted by the text editor you use to write your code. It's important to know however, that there are different ways too signify a new line. The two most used are listed below.
* //CR+LF// or //CRLF// (Windows style)
* //LF// (Unix style)
For pluck, we have chosen to work with **Unix style newlines (LF)**. When writing code for pluck, please make sure the text editor you are using is set to **LF**. This is important, because otherwise the markup of the code might get messed up. Next to that, //Bazaar// (the Version Control System we use for pluck) likes LF better.
===== HTML =====
Coming soon...
===== CSS =====
CSS should be formated like this:
html, #foobar {
color: white;
background-color: black;
}
===== PHP - NOTE: This part is not finished! =====
==== General ====
== Use ' and not ": ==
WRONG:
echo "test";
RIGHT:
echo 'test';
----
\\
You should __ONLY__ use **"** when you want to make a new line, and __ONLY__ for **\n**:
WRONG:
echo "$test\n";
RIGHT:
echo $test."\n";
----
\\
There should be a space between **echo** and the string:
WRONG:
echo'test';
RIGHT:
echo 'test';
==== Control Structures ====
[[http://php.net/manual/en/language.control-structures.php|Control Structures]] should have a space between the statement and the first parametrise, but not between the expression(s) and the parentheses. There should also be a space between the last parametrise and the first brace:
WRONG:
require_once( 'test.php' );
if( $test == true ){
$test = 'hello';
return$test;
}
RIGHT:
require_once ('test.php');
if ($test == true) {
$test = 'hello';
return $test;
}
----
\\
If the content of the Control Structure is only on one line, you should omit the braces:
WRONG:
if ($test == true) {
return $test;
}
RIGHT:
if ($test == true)
return $test;
==== Functions ====
When calling a function, there should be no space around the parentheses:
WRONG:
isset ( );
isset ( $test );
RIGHT:
isset();
isset($test);
==== Predefined functions and constants =====
Don't try to reinvent the wheel; when working on pluck, you can use the predefined functions and constants. These functions and constants are stored in these files:
* data/inc/functions.all.php
* data/inc/functions.admin.php
* data/inc/functions.site.php
* data/inc/variables.all.php
* data/inc/variables.admin.php
* data/inc/variables.site.php
The functions and constants defined in a file containing //all// can be used in both the admin center and the code of the website. Functions and constants with //admin// can only be used in the admin center, and with //site// can only be used in the website.
The functions and constants are explained on this wiki on the pages listed below. If you add a function/constant, please add a description to the page on the wiki. This makes it easier for other developers and module developers to work on pluck efficiently.
* **[[http://www.pluck-cms.org/docs_functions/|Function list]]**
* [[dev:constants|Constant list]]