Pascal Dreissen
2016-07-08 a2401ddb28154829f254378b72e081ac2d4af289
commit | author | age
87793c 1 # Some guidelines for web development with php.
b64955 2 -----------------------------------------------------
316369 3 * Unix Line Breaks Only, NO windows breaks please.
46ea1a 4 * Tabs to indent lines, NO spaces
316369 5 * no accidental _<?php space before, within or after a file
33f193 6 * every PHP file starts and end with <?php ?> no spaces before or after
MB 7 * error_reporting(E_ALL|E_STRICT), yep PHP 5
46ea1a 8 * Magic quotes is gone, get used to it now. config = magic_quotes_gpc() Everything must be quoted
33f193 9 * Don't use ereg, split and other old function -> gone in PHP 5.4
MB 10 * Don't use features that are not supported in PHP 5.3, for compatibility with LTS OS releases, ISPConfig must support PHP 5.3+
46ea1a 11 * Don't use shorttags. A Shorttag is <? and that is confusing with <?xml -> always usw <?php
01c6f9 12 * Don't use namespaces
4369ab 13 * Column names in database tables and database table names are in lowercase
T 14 * Classes for the interface are located in interface/lib/classes/ and loaded with $app->uses() or $app->load() functions.
15 * Classes for the server are located in server/lib/classes/ and loaded with $app->uses() or $app->load() functions.
46ea1a 16 * please mark any section that need review or work on with /* TODO: short description */
3eeed9 17 * Make function / var names on the following way, first word lower, next word(s) first letter upper like. getFirstResult();
46ea1a 18 * always a space but NO newline before opening braces, e. g.
da7597 19 ```
46ea1a 20 class abc {
MB 21     public function cde() {
22         if($a == $b) {
23             return false;
24         }
25     }
26 }
da7597 27 ```
46ea1a 28 * no spaces after function/method or control names, e. g.
da7597 29 ```
46ea1a 30 function abc($x, $y) {
MB 31     if($condition == true) {
32         $x = 2;
33     }
34 }
da7597 35 ```
46ea1a 36 and NOT
da7597 37 ```
46ea1a 38 function abc ($x, $y) {
MB 39     if ( $condition == true ) {
40     
41     }
42 }
da7597 43 ```
b64955 44
da7597 45 # Commenting style
b64955 46
P 47 The comments break down into the following types
da7597 48 ```
b64955 49 // is uses for removing lines and debug dev etc
P 50 /* 
46ea1a 51     is used to comment out blocks
b64955 52 */
46ea1a 53
b64955 54 /** is used to create documentaion
46ea1a 55  * thats over 
MB 56  * lines
57  */
da7597 58 ```
b64955 59 If you need to block out a section then use
da7597 60 ```
b64955 61 /*
P 62 function redundant_code(){
46ea1a 63     something here
b64955 64 }
P 65 */
da7597 66 ```
b64955 67 To block out single lines use // and all // are assumed to be redundant test code and NOT comments
P 68
69 // print_r($foo);
70
71 Do not use the phpdoc on every function, eg 
da7597 72 ```
b64955 73 /**
72a844 74 * Login a user
b64955 75 * @param string user  username
P 76 * @param string password of user
77 */
78 function login($user, $pass){
46ea1a 79     
b64955 80 }
da7597 81 ```
46ea1a 82 as this function is self-explaining, the following clean code will suffice
da7597 83 ```
b64955 84 function login($user, $pass){
46ea1a 85     
b64955 86 }
da7597 87 ```
b64955 88
da7597 89 # Where to store custom settings
b64955 90
da7597 91 ## Interface settings
5f8086 92
T 93 The recommended place to store global interface settings is the ini style global config system 
94 (see system.ini.master file in install/tpl/ to set defaults). The settings file 
95 gets stored inside the ispconfig database. Settings can be accessed with the function:
96
da7597 97 ```
5f8086 98 $app->uses('ini_parser,getconf');
T 99 $interface_settings = $app->getconf->get_global_config('modulename');
da7597 100 ```
5f8086 101
T 102 where modulename corresponds to the config section in the system.ini.master file.
103 To make the settings editable under System > interface config, add the new configuration
104 fields to the file interface/web/admin/form/system_config.tform.php and the corresponding
105 tempalte file in the templates subfolder of the admin module.
106
da7597 107 ## Server settings
5f8086 108
T 109 Server settings are stored in the ini style server config system (see server.ini.master template file)
110 The settings file gets stored inside the ispconfig database in the server table. Settings can be 
111 accessed with the function $app->getconf->get_server_config(....)
112
113 Example to access the web configuration:
114
da7597 115 ```
5f8086 116 $app->uses('ini_parser,getconf');
T 117 $web_config = $app->getconf->get_server_config($server_id,'web');
da7597 118 ```
5f8086 119
da7597 120 # Learn about the form validators
d85c3d 121 There are form validators in interface/lib/classes/tform.inc.php to make validating forms easier.
L 122 Read about: REGEX,UNIQUE,NOTEMPTY,ISEMAIL,ISINT,ISPOSITIVE,ISIPV4,CUSTOM