<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/24/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Martinau</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/24/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Martinau"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/24/en/Special:Contributions/Martinau"/>
	<updated>2026-05-15T16:37:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/24/en/index.php?title=Development:Output_functions&amp;diff=52997</id>
		<title>Development:Output functions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/24/en/index.php?title=Development:Output_functions&amp;diff=52997"/>
		<updated>2009-03-19T13:25:42Z</updated>

		<summary type="html">&lt;p&gt;Martinau: fr link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page tries to explain a bit how dynamic data should be sent from Moodle to the browser in an organised and standard way. Obviously it&#039;s possible to have your own output methods but, thinking that you are going to share your code (yep, this is an OpenSource project!) and in the collaborative way we try to build and maintain the system every day, it would be really better to follow the basic guidelines explained below.&lt;br /&gt;
&lt;br /&gt;
By using them you will be helping to have better, more secure and readable code. Spend some minutes trying to understand them, please!&lt;br /&gt;
&lt;br /&gt;
Of course, these functions can be discussed, modified and new functions can arrive if there are some good reasons for it. Just discuss it in the [http://moodle.org/mod/forum/view.php?id=55 General developer forum] at [http://moodle.org moodle.org].&lt;br /&gt;
&lt;br /&gt;
For each of the functions below we&#039;ll try to explain when they should be used, explaining the most important parameters supported and their meaning. Let&#039;s review them!&lt;br /&gt;
&lt;br /&gt;
=== p() and s() ===&lt;br /&gt;
&lt;br /&gt;
 function s($var, $strip=false)&lt;br /&gt;
 function p($var, $strip=false)&lt;br /&gt;
&lt;br /&gt;
These functions share the same code so they will be explained together. The only difference is that s() returns the string while p() prints it directly.&lt;br /&gt;
&lt;br /&gt;
These functions should be used to:&lt;br /&gt;
&lt;br /&gt;
* print all the &#039;&#039;&#039;values of form fields&#039;&#039;&#039; like &amp;lt;nowiki&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/nowiki&amp;gt; or &amp;lt;nowiki&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
* to &#039;&#039;&#039;show plain (non html) text&#039;&#039;&#039; that has been introduced by the user (search string, quiz responses...).&lt;br /&gt;
* in general, all the &#039;&#039;&#039;dynamic data, not being html&#039;&#039;&#039;, that doesn&#039;t need to be cleaned nor processed by filters&lt;br /&gt;
&lt;br /&gt;
It is important not to use these functions for strings that contain html markup.&lt;br /&gt;
&lt;br /&gt;
The functions replace certain characters that would have special meaning in html ( &amp;lt;, &amp;gt;, &amp;quot;, &#039;, and &amp;amp;) by html entities so that they are displayed as intended. Note that even though the value of form fields printed with p() will have these characters converted to html entities, the submitted values will contain the original characters again.&lt;br /&gt;
&lt;br /&gt;
The key parameter for this function is:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;strip&#039;&#039;&#039;: it decides if we want to strip slashes from the string or no. By default it&#039;s &#039;false&#039; so no strip will be performed. We should set such parameter to &#039;true&#039; only when data to be processed isn&#039;t coming from database but from http requests (forms, links...).&lt;br /&gt;
&lt;br /&gt;
=== format_text() ===&lt;br /&gt;
&lt;br /&gt;
 function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL ) &lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* print &#039;&#039;&#039;any html/plain/markdown/moodle text&#039;&#039;&#039;, needing any of the features below. Mainly used for long strings like posts, answers, glossary items...&lt;br /&gt;
&lt;br /&gt;
Note that this function is really &#039;&#039;&#039;heavy&#039;&#039;&#039; because it supports &#039;&#039;&#039;cleaning&#039;&#039;&#039; of dangerous contents, delegates processing to enabled &#039;&#039;&#039;filter&#039;&#039;&#039;s, supports different &#039;&#039;&#039;formats&#039;&#039;&#039; of text (HTML, PLAIN, MARKDOWN, MOODLE) and performs a lot of &#039;&#039;&#039;automatic conversions&#039;&#039;&#039; like adding smilies, build links. Also, it includes a strong &#039;&#039;&#039;cache mechanism&#039;&#039;&#039; (DB based) that will alleviate the server from a lot of work processing the same texts time and again.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;format&#039;&#039;&#039;: To tell the function about how the data has been entered. It defaults to FORMAT_MOODLE that is a cool format to process plain text because it features automatic link conversion, smilies and good conversion to html output. Other formats are FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN. See [[Formatting options]].&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;options&#039;&#039;&#039;: Here we can specify how we want the process to be performed. You only need to define them if they are different from the default value assumed. Main options are:&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;noclean&#039;&#039;&#039;: To decide if we want to skip the clean-up of text, &#039;&#039;&#039;un-protecting us&#039;&#039;&#039; from attacks and other security flaws (defaults to false, so protection is enabled. You &#039;&#039;&#039;shouldn&#039;t set it to true ever&#039;&#039;&#039; unless you are 200% sure that only controlled users can edit it (mainly admins). &#039;&#039;&#039;Never use it for general text places&#039;&#039;&#039; (posts...) or you will be, sooner or later, attacked! Note that this option is ignored for FORMAT_PLAIN, the text is never cleaned.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;filter&#039;&#039;&#039;: To decide if you want to allow filters to process the text (defaults to true). This is ignored by FORMAT_PLAIN for which filters are never applied.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;smiley&#039;&#039;&#039;: To decide if we want automatic conversion of smilies to images (defaults to true). This is ignored by FORMAT_PLAIN for which smileys are never converted.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;para&#039;&#039;&#039;: To decide if you want every paragraph automatically enclosed between html paragraph tags (&amp;lt;nowiki&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/nowiki&amp;gt;) (defaults to true). This option only applies to FORMAT_MOODLE.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;newlines&#039;&#039;&#039;: To decide if linefeeds in text should be converted to html newlines (&amp;lt;nowiki&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/nowiki&amp;gt;) (defaults to true). This option only applies to FORMAT_MOODLE.&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help filters to know how they should work. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
&lt;br /&gt;
=== format_string() ===&lt;br /&gt;
&lt;br /&gt;
 function format_string ($string, $striplinks = true, $courseid=NULL )&lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* print &#039;&#039;&#039;short strings (non html) that need filter processing&#039;&#039;&#039; (activity titles, post subjects, glossary concepts...).&lt;br /&gt;
&lt;br /&gt;
Please note that this function is basically one stripped version of the full format_text() function detailed above and &#039;&#039;&#039;it doesn&#039;t offer any of its options or protections&#039;&#039;&#039;. It simply filters the strings and returns the result, so we must ensure that text being processed has been properly cleaned at input time, using the proper xxx_param() functions.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;striplinks&#039;&#039;&#039;: To decide if, after the text has been processed by filters, we must delete any link from the result text. Used when we want to show the text inside menus, page titles... (defaults to true).&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help filters to know how they should work. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
&lt;br /&gt;
=== print_textarea() ===&lt;br /&gt;
&lt;br /&gt;
 function print_textarea($usehtmleditor, $rows, $cols, $width, &lt;br /&gt;
                        $height, $name, $value=&amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;, $courseid=0, $return=false)&lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* display &amp;lt;nowiki&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/nowiki&amp;gt; fields when we want to allow users (based in their preferences and browser capabilities) &#039;&#039;&#039;to use the visual HTML editor&#039;&#039;&#039; instead of one standard &#039;plain&#039; area.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;usehtmleditor&#039;&#039;&#039;: to decide if the HTML editor must be showed. The value of this parameter must be calculated by the can_use_html_editor() function.&lt;br /&gt;
* &#039;&#039;&#039;rows, cols&#039;&#039;&#039;: to be applied if the standard textarea is showed.&lt;br /&gt;
* &#039;&#039;&#039;width, height&#039;&#039;&#039;: to be applied if the HTML editor is used.&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039;: the name of the field that will contain the text once the form is submitted.&lt;br /&gt;
* &#039;&#039;&#039;value&#039;&#039;&#039;: the initial value of the textarea.&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help the editor to know where it is working. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
* &#039;&#039;&#039;return&#039;&#039;&#039;: to decide if the generated html code must be returned to the caller (true) or printed directly (false). Defaults to false.&lt;br /&gt;
&lt;br /&gt;
[[pl:Funkcje wyjściowe]]&lt;br /&gt;
[[fr:Développement:Fonctions_output]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Output functions]]&lt;/div&gt;</summary>
		<author><name>Martinau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/24/en/index.php?title=Development:Output_functions&amp;diff=52996</id>
		<title>Development:Output functions</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/24/en/index.php?title=Development:Output_functions&amp;diff=52996"/>
		<updated>2009-03-19T13:25:23Z</updated>

		<summary type="html">&lt;p&gt;Martinau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page tries to explain a bit how dynamic data should be sent from Moodle to the browser in an organised and standard way. Obviously it&#039;s possible to have your own output methods but, thinking that you are going to share your code (yep, this is an OpenSource project!) and in the collaborative way we try to build and maintain the system every day, it would be really better to follow the basic guidelines explained below.&lt;br /&gt;
&lt;br /&gt;
By using them you will be helping to have better, more secure and readable code. Spend some minutes trying to understand them, please!&lt;br /&gt;
&lt;br /&gt;
Of course, these functions can be discussed, modified and new functions can arrive if there are some good reasons for it. Just discuss it in the [http://moodle.org/mod/forum/view.php?id=55 General developer forum] at [http://moodle.org moodle.org].&lt;br /&gt;
&lt;br /&gt;
For each of the functions below we&#039;ll try to explain when they should be used, explaining the most important parameters supported and their meaning. Let&#039;s review them!&lt;br /&gt;
&lt;br /&gt;
=== p() and s() ===&lt;br /&gt;
&lt;br /&gt;
 function s($var, $strip=false)&lt;br /&gt;
 function p($var, $strip=false)&lt;br /&gt;
&lt;br /&gt;
These functions share the same code so they will be explained together. The only difference is that s() returns the string while p() prints it directly.&lt;br /&gt;
&lt;br /&gt;
These functions should be used to:&lt;br /&gt;
&lt;br /&gt;
* print all the &#039;&#039;&#039;values of form fields&#039;&#039;&#039; like &amp;lt;nowiki&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/nowiki&amp;gt; or &amp;lt;nowiki&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
* to &#039;&#039;&#039;show plain (non html) text&#039;&#039;&#039; that has been introduced by the user (search string, quiz responses...).&lt;br /&gt;
* in general, all the &#039;&#039;&#039;dynamic data, not being html&#039;&#039;&#039;, that doesn&#039;t need to be cleaned nor processed by filters&lt;br /&gt;
&lt;br /&gt;
It is important not to use these functions for strings that contain html markup.&lt;br /&gt;
&lt;br /&gt;
The functions replace certain characters that would have special meaning in html ( &amp;lt;, &amp;gt;, &amp;quot;, &#039;, and &amp;amp;) by html entities so that they are displayed as intended. Note that even though the value of form fields printed with p() will have these characters converted to html entities, the submitted values will contain the original characters again.&lt;br /&gt;
&lt;br /&gt;
The key parameter for this function is:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;strip&#039;&#039;&#039;: it decides if we want to strip slashes from the string or no. By default it&#039;s &#039;false&#039; so no strip will be performed. We should set such parameter to &#039;true&#039; only when data to be processed isn&#039;t coming from database but from http requests (forms, links...).&lt;br /&gt;
&lt;br /&gt;
=== format_text() ===&lt;br /&gt;
&lt;br /&gt;
 function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL ) &lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* print &#039;&#039;&#039;any html/plain/markdown/moodle text&#039;&#039;&#039;, needing any of the features below. Mainly used for long strings like posts, answers, glossary items...&lt;br /&gt;
&lt;br /&gt;
Note that this function is really &#039;&#039;&#039;heavy&#039;&#039;&#039; because it supports &#039;&#039;&#039;cleaning&#039;&#039;&#039; of dangerous contents, delegates processing to enabled &#039;&#039;&#039;filter&#039;&#039;&#039;s, supports different &#039;&#039;&#039;formats&#039;&#039;&#039; of text (HTML, PLAIN, MARKDOWN, MOODLE) and performs a lot of &#039;&#039;&#039;automatic conversions&#039;&#039;&#039; like adding smilies, build links. Also, it includes a strong &#039;&#039;&#039;cache mechanism&#039;&#039;&#039; (DB based) that will alleviate the server from a lot of work processing the same texts time and again.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;format&#039;&#039;&#039;: To tell the function about how the data has been entered. It defaults to FORMAT_MOODLE that is a cool format to process plain text because it features automatic link conversion, smilies and good conversion to html output. Other formats are FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN. See [[Formatting options]].&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;options&#039;&#039;&#039;: Here we can specify how we want the process to be performed. You only need to define them if they are different from the default value assumed. Main options are:&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;noclean&#039;&#039;&#039;: To decide if we want to skip the clean-up of text, &#039;&#039;&#039;un-protecting us&#039;&#039;&#039; from attacks and other security flaws (defaults to false, so protection is enabled. You &#039;&#039;&#039;shouldn&#039;t set it to true ever&#039;&#039;&#039; unless you are 200% sure that only controlled users can edit it (mainly admins). &#039;&#039;&#039;Never use it for general text places&#039;&#039;&#039; (posts...) or you will be, sooner or later, attacked! Note that this option is ignored for FORMAT_PLAIN, the text is never cleaned.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;filter&#039;&#039;&#039;: To decide if you want to allow filters to process the text (defaults to true). This is ignored by FORMAT_PLAIN for which filters are never applied.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;smiley&#039;&#039;&#039;: To decide if we want automatic conversion of smilies to images (defaults to true). This is ignored by FORMAT_PLAIN for which smileys are never converted.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;para&#039;&#039;&#039;: To decide if you want every paragraph automatically enclosed between html paragraph tags (&amp;lt;nowiki&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/nowiki&amp;gt;) (defaults to true). This option only applies to FORMAT_MOODLE.&lt;br /&gt;
**&#039;&#039;&#039;options-&amp;gt;newlines&#039;&#039;&#039;: To decide if linefeeds in text should be converted to html newlines (&amp;lt;nowiki&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;/nowiki&amp;gt;) (defaults to true). This option only applies to FORMAT_MOODLE.&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help filters to know how they should work. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
&lt;br /&gt;
=== format_string() ===&lt;br /&gt;
&lt;br /&gt;
 function format_string ($string, $striplinks = true, $courseid=NULL )&lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* print &#039;&#039;&#039;short strings (non html) that need filter processing&#039;&#039;&#039; (activity titles, post subjects, glossary concepts...).&lt;br /&gt;
&lt;br /&gt;
Please note that this function is basically one stripped version of the full format_text() function detailed above and &#039;&#039;&#039;it doesn&#039;t offer any of its options or protections&#039;&#039;&#039;. It simply filters the strings and returns the result, so we must ensure that text being processed has been properly cleaned at input time, using the proper xxx_param() functions.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;striplinks&#039;&#039;&#039;: To decide if, after the text has been processed by filters, we must delete any link from the result text. Used when we want to show the text inside menus, page titles... (defaults to true).&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help filters to know how they should work. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
&lt;br /&gt;
=== print_textarea() ===&lt;br /&gt;
&lt;br /&gt;
 function print_textarea($usehtmleditor, $rows, $cols, $width, &lt;br /&gt;
                        $height, $name, $value=&amp;lt;nowiki&amp;gt;&#039;&#039;&amp;lt;/nowiki&amp;gt;, $courseid=0, $return=false)&lt;br /&gt;
&lt;br /&gt;
This function should be used to:&lt;br /&gt;
&lt;br /&gt;
* display &amp;lt;nowiki&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/nowiki&amp;gt; fields when we want to allow users (based in their preferences and browser capabilities) &#039;&#039;&#039;to use the visual HTML editor&#039;&#039;&#039; instead of one standard &#039;plain&#039; area.&lt;br /&gt;
&lt;br /&gt;
Some interesting parameters for this function are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;usehtmleditor&#039;&#039;&#039;: to decide if the HTML editor must be showed. The value of this parameter must be calculated by the can_use_html_editor() function.&lt;br /&gt;
* &#039;&#039;&#039;rows, cols&#039;&#039;&#039;: to be applied if the standard textarea is showed.&lt;br /&gt;
* &#039;&#039;&#039;width, height&#039;&#039;&#039;: to be applied if the HTML editor is used.&lt;br /&gt;
* &#039;&#039;&#039;name&#039;&#039;&#039;: the name of the field that will contain the text once the form is submitted.&lt;br /&gt;
* &#039;&#039;&#039;value&#039;&#039;&#039;: the initial value of the textarea.&lt;br /&gt;
* &#039;&#039;&#039;courseid&#039;&#039;&#039;: This parameter should be passed always to help the editor to know where it is working. This parameter will become less and less important Moodle was 100% of the current course using some session or global variable (it&#039;s one work in progress just now) but, for now, it&#039;s recommended to set it always in the function call.&lt;br /&gt;
* &#039;&#039;&#039;return&#039;&#039;&#039;: to decide if the generated html code must be returned to the caller (true) or printed directly (false). Defaults to false.&lt;br /&gt;
&lt;br /&gt;
[[pl:Funkcje wyjściowe]]&lt;br /&gt;
[[:fr:Développement:Fonctions_output]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Output functions]]&lt;/div&gt;</summary>
		<author><name>Martinau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/24/en/index.php?title=Development:Slashes&amp;diff=52994</id>
		<title>Development:Slashes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/24/en/index.php?title=Development:Slashes&amp;diff=52994"/>
		<updated>2009-03-19T11:04:26Z</updated>

		<summary type="html">&lt;p&gt;Martinau: fr link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The functions &amp;lt;code&amp;gt;addslashes()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;stripslashes()&amp;lt;/code&amp;gt; are misused often, so here is a short explanation of what they are for and when they should be used.&lt;br /&gt;
&lt;br /&gt;
Before entering data into a database, special symbols like single or double quotes need to be escaped by a backslash. So for example every &#039; needs to be converted to \&#039; in any string that is to be stored in the database. When the string is fetched back from the database it comes back without those slashes. So if data that comes directly from the database is to be written back to the database it needs to have the slashes added to it again. This is an example where the &amp;lt;code&amp;gt;addslashes()&amp;lt;/code&amp;gt; function should be used. &lt;br /&gt;
&lt;br /&gt;
Because data submitted by the user will often need to be written to the database, Moodle ensures that it automatically gets slashes added to it. So you never have to use addslashes() on data that comes from the user. If however you want to display data that was submitted by the user then you have to strip the slashes that have been added. This is an example where the &amp;lt;code&amp;gt;stripslashes()&amp;lt;/code&amp;gt; function should be used.&lt;br /&gt;
&lt;br /&gt;
The whole situation can be summarized in the following diagram:&lt;br /&gt;
&lt;br /&gt;
[[Image:Stripslashes.jpg|none]]&lt;br /&gt;
&lt;br /&gt;
Neither &amp;lt;code&amp;gt;stripslashes()&amp;lt;/code&amp;gt; nor &amp;lt;code&amp;gt;addslashes()&amp;lt;/code&amp;gt; should be used when going from User Input to the Database or from the Database to Screen Output (black arrows) but &amp;lt;code&amp;gt;stripslashes()&amp;lt;/code&amp;gt; should be used when displaying user input on the screen (red arrow) and &amp;lt;code&amp;gt;addslashes()&amp;lt;/code&amp;gt; should be used when reinserting data in to the database that came from the database (blue arrow). These last two are rare, so the use of addslashes and stripslashes should be rare.&lt;br /&gt;
&lt;br /&gt;
Please note that when outputting strings from the database, you should never simply use echo or something similar but should use Moodle&#039;s [[Development:Output functions|output functions]].&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to add slashes or remove slashes from all properties of an object at once. Moodle provides the very convenient functions &amp;lt;code&amp;gt;addslashes_object()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;stripslashes_recursive()&amp;lt;/code&amp;gt;. The latter also works on arrays.&lt;br /&gt;
&lt;br /&gt;
One thing to watch out for is that the parameter type PARAM_CLEANHTML strips slashes, so you have to add slashes before putting data cleaned this way into the database or user PARAM_CLEAN instead.&lt;br /&gt;
&lt;br /&gt;
Moodle provides a function called &amp;lt;code&amp;gt;stripslashes_safe()&amp;lt;/code&amp;gt; which only strips slashes in front of single and double quotes and in front of a backslash, so \&#039; becomes &#039;, \&amp;quot; becomes &amp;quot;, and \\ becomes \. Any other slashes, as in C:\Moodle for example, are preserved. It was introduced because in some circumstances it may not matter if this function is applied too often. However I find this function dangerous, because it may make you think that everything is fine until one of your users wants to include a bit of code in their input for example. I would not have been able to write this paragraph (with the \&#039; in it) if it had been passed through &amp;lt;code&amp;gt;stripslashes_safe()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some core Moodle functions use &amp;lt;code&amp;gt;stripslashes_safe()&amp;lt;/code&amp;gt;:&lt;br /&gt;
 print_heading()&lt;br /&gt;
 print_heading_with_help()&lt;br /&gt;
 print_heading_block()&lt;br /&gt;
 print_simple_box()&lt;br /&gt;
It usually doesn&#039;t matter too much for headings, because including \\, \&#039;, or \&amp;quot; in headings is unusual, but it does matter in print_simple_box() and therefore the advice would be to avoid using this function and to use the &amp;lt;code&amp;gt;print_simple_box_start()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;print_simple_box_end()&amp;lt;/code&amp;gt; pair.&lt;br /&gt;
&lt;br /&gt;
[[fr:Développement:Slashes]]&lt;/div&gt;</summary>
		<author><name>Martinau</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/24/en/index.php?title=Development:Coding&amp;diff=52976</id>
		<title>Development:Coding</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/24/en/index.php?title=Development:Coding&amp;diff=52976"/>
		<updated>2009-03-18T16:09:59Z</updated>

		<summary type="html">&lt;p&gt;Martinau: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Any collaborative project needs consistency and stability to stay strong.&lt;br /&gt;
&lt;br /&gt;
These &#039;&#039;&#039;coding guidelines&#039;&#039;&#039; are to provide a goal for all Moodle code to strive to. It&#039;s true that some of the older existing code falls short in a few areas, but it will all be fixed eventually. All new code definitely must adhere to these standards as closely as possible.&lt;br /&gt;
&lt;br /&gt;
==General rules==&lt;br /&gt;
&lt;br /&gt;
# All &#039;&#039;&#039;code&#039;&#039;&#039; files should use the &#039;&#039;&#039;.php&#039;&#039;&#039; extension.&lt;br /&gt;
# All &#039;&#039;&#039;template&#039;&#039;&#039; files should use the &#039;&#039;&#039;.html&#039;&#039;&#039; extension.&lt;br /&gt;
# All text files should use &#039;&#039;&#039;Unix-style text format&#039;&#039;&#039; (most text editors have this as an option).&lt;br /&gt;
# All php tags must be &#039;full&#039; tags like &#039;&#039;&#039;&amp;lt;?php ?&amp;gt;&#039;&#039;&#039; ... not &#039;short&#039; tags like &amp;lt;? ?&amp;gt;.&lt;br /&gt;
# All existing &#039;&#039;&#039;copyright notices must be retained&#039;&#039;&#039;. You can add your own if necessary.&lt;br /&gt;
# Each file should &#039;&#039;&#039;include (require_once) the main config.php&#039;&#039;&#039; file.&lt;br /&gt;
# Any &#039;&#039;&#039;other include/require should use an absolute path&#039;&#039;&#039; beginning with $CFG-&amp;gt;dirroot or  $CFG-&amp;gt;libdir, not relative includes, which [http://uk.php.net/manual/en/function.include.php sometimes behave strangely under PHP].&lt;br /&gt;
# Includes should be done at the top of files or inside functions/methods, do not include/require in the middle of file in global scope&lt;br /&gt;
# Each file should &#039;&#039;&#039;check that the user is authenticated correctly&#039;&#039;&#039;, using require_login() and has_capability() or require_capability().&lt;br /&gt;
# All &#039;&#039;&#039;access to databases should use the functions in &#039;&#039;lib/dmllib.php&#039;&#039;&#039;&#039;&#039; whenever possible - this allows compatibility across a wide range of databases. You should find that almost anything is possible using these functions. If you must write SQL code then make sure it is: cross-platform; restricted to specific functions within your code (usually a lib.php file); and clearly marked.&lt;br /&gt;
# &#039;&#039;&#039;Don&#039;t create new global variables&#039;&#039;&#039;. Use only the Moodle-standard $CFG, $SESSION, $THEME, $SITE, $COURSE and $USER global variables.&lt;br /&gt;
# &#039;&#039;&#039;All variables should be initialised&#039;&#039;&#039; or at least tested for existence using isset() or empty() before they are used.&lt;br /&gt;
# &#039;&#039;&#039;All strings should be translatable&#039;&#039;&#039; - create new texts in the &amp;quot;lang/en_utf8&amp;quot; files with concise English lowercase names and retrieve them from your code using get_string() or print_string(). Never delete strings to ensure backwards compatibility of the language packs is maintained.&lt;br /&gt;
# &#039;&#039;&#039;Don&#039;t use p() and s() functions&#039;&#039;&#039; to print language strings. Those functions are not designed to print html with tags. Use echo() instead.&lt;br /&gt;
# All &#039;&#039;&#039;errors should be printed using print_error()&#039;&#039;&#039; to maximise translation and help for users (it automatically links to the docs wiki).&lt;br /&gt;
# All &#039;&#039;&#039;help files should be translatable&#039;&#039;&#039; - create new texts in the &amp;quot;lang/en_utf8/help&amp;quot; directory and call them using helpbutton(). If you need to update a help file:&lt;br /&gt;
#* with a minor change, where an old translation of the file would still make sense, then it&#039;s OK to make the change but you should notify translation AT moodle DOT org.&lt;br /&gt;
#* for a major change you should create a new file by adding an incrementing number (eg filename2.html) so that translators can easily see it&#039;s a new version of the file. Obviously the new code and the help index files should also be modified to point to the newest versions.&lt;br /&gt;
# Incoming data from the browser (sent via &#039;&#039;&#039;GET or POST) automatically has magic_quotes applied&#039;&#039;&#039; (regardless of the PHP settings) so that you can safely insert it straight into the database. &#039;&#039;&#039;All other raw data (from files, or from databases) must be escaped with addslashes()&#039;&#039;&#039; before inserting it into the database. Because this is so often done incorrectly, there is more explanation on this issue of adding and stripping slashes on a [[Developer:Slashes|separate page]].&lt;br /&gt;
# VERY IMPORTANT: Within Moodle, &#039;&#039;&#039;All texts should be printed using the format_text() function&#039;&#039;&#039;, especially those that have come from users. This ensures that text is filtered and cleaned correctly. More information can be found on the page about [[Development:Output_functions|output functions]].&lt;br /&gt;
# User actions should be logged using the [[Development:Logs|add_to_log()]] function. These logs are used for [[Settings#Show_activity_reports|activity reports]] and [[Logs]].&lt;br /&gt;
# &#039;&#039;&#039;Always create HTML links relative to the full site root&#039;&#039;&#039;, i.e. link to  &#039;&#039;$CFG-&amp;gt;wwwroot/mod/blonk/view.php?id=99&#039;&#039; rather than just &#039;&#039;view.php?id=99&#039;&#039;. This means that your code will work if called by a script in another folder, among other things.&lt;br /&gt;
# Modules should &#039;&#039;&#039;store config variables using &#039;&#039;set_config(&#039;varname&#039;, $value, &#039;mod/modulename&#039;)&#039;&#039;&#039;&#039;&#039; where the last parameter is the path to the module directory.&lt;br /&gt;
# &#039;&#039;&#039;Respect decimal separators specified&#039;&#039;&#039; in language pack - do not use number_format() directly, instead use format_float() and unformat_float() when displaying or processing floating point numbers (mandatory in 2.0)&lt;br /&gt;
&lt;br /&gt;
==Coding style==&lt;br /&gt;
&lt;br /&gt;
I know it can be a little annoying to change your style if you&#039;re used to something else, but balance that annoyance against the annoyance of all the people trying later on to make sense of Moodle code with mixed styles. There are obviously many good points for and against any style that people use, but the current style just is, so please stick to it.&lt;br /&gt;
&lt;br /&gt;
1. Indenting should be consistently 4 spaces. Don&#039;t use tabs AT ALL.&lt;br /&gt;
&lt;br /&gt;
2. Variable names should always be easy-to-read, meaningful lowercase English words. If you really need more than one word then run them together, but keep them short as possible. Use plural names for arrays of objects.&lt;br /&gt;
&lt;br /&gt;
      GOOD: $quiz&lt;br /&gt;
      GOOD: $errorstring&lt;br /&gt;
      GOOD: $assignments (for an array of objects)&lt;br /&gt;
      GOOD: $i (but only in little loops)&lt;br /&gt;
&lt;br /&gt;
      BAD: $Quiz&lt;br /&gt;
      BAD: $aReallyLongVariableNameWithoutAGoodReason&lt;br /&gt;
      BAD: $error_string&lt;br /&gt;
&lt;br /&gt;
3. Constants should always be in upper case, and always start with the name of the module. They should have words separated by underscores.&lt;br /&gt;
&lt;br /&gt;
      define(&amp;quot;FORUM_MODE_FLATOLDEST&amp;quot;, 1);&lt;br /&gt;
4. Function names should be simple English lowercase words, and start with the name of the module to avoid conflicts between modules. Words should be separated by underscores. Parameters should always have sensible defaults if possible. Note there is no space between the function name and the following (brackets).&lt;br /&gt;
&lt;br /&gt;
      function forum_set_display_mode($mode=0) {&lt;br /&gt;
          global $USER, $CFG;&lt;br /&gt;
          &lt;br /&gt;
          if ($mode) {&lt;br /&gt;
              $USER-&amp;gt;mode = $mode;&lt;br /&gt;
          } else if (empty($USER-&amp;gt;mode)) {&lt;br /&gt;
              $USER-&amp;gt;mode = $CFG-&amp;gt;forum_displaymode;&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
The same applies to naming classes and their methods. Use lowercase words separated by underscores.&lt;br /&gt;
&lt;br /&gt;
      class some_custom_class {&lt;br /&gt;
          function class_method() {&lt;br /&gt;
              ...&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
Note there are some exceptions in the code using camelcase: class SomeCustomClass {function classMethod(){...}}, but these are usually there because of compatibility with thirds party libraries (e.g. formslib).&lt;br /&gt;
&lt;br /&gt;
5. Blocks must always be enclosed in curly braces (even if there is only one line). Moodle uses this style:&lt;br /&gt;
&lt;br /&gt;
      if ($quiz-&amp;gt;attempts) {&lt;br /&gt;
          if ($numattempts &amp;gt; $quiz-&amp;gt;attempts) {&lt;br /&gt;
              error($strtoomanyattempts, &amp;quot;view.php?id=$cm-&amp;gt;id&amp;quot;);&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
6. Strings should be defined using single quotes where possible, so that [http://php.net/types.string less memory is used].&lt;br /&gt;
&lt;br /&gt;
      $var = &#039;some text without any variables&#039;;&lt;br /&gt;
      $var = &#039;with special characters like a new line &#039;.&amp;quot;\n&amp;quot;;&lt;br /&gt;
      $var = &#039;a very, very long string with a &#039;.$single.&#039; variable in it&#039;;&lt;br /&gt;
      $var = &amp;quot;some $text with $many variables $within it&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
7. Comments should be added as much as is practical, to explain the code flow and the purpose of functions and variables.&lt;br /&gt;
&lt;br /&gt;
* Every function (and class) should use the popular [http://www.phpdoc.org/ phpDoc format]. This allows code documentation to be generated automatically.&lt;br /&gt;
* Inline comments should use the // style, laid out neatly so that it fits among the code and lines up with it.&lt;br /&gt;
&lt;br /&gt;
      /**&lt;br /&gt;
      * The description should be first, with asterisks laid out exactly&lt;br /&gt;
      * like this example. If you want to refer to a another function,&lt;br /&gt;
      * do it like this: {@link clean_param()}. Then, add descriptions&lt;br /&gt;
      * for each parameter as follows.&lt;br /&gt;
      *&lt;br /&gt;
      * @param int $postid The PHP type is followed by the variable name&lt;br /&gt;
      * @param array $scale The PHP type is followed by the variable name&lt;br /&gt;
      * @param array $ratings The PHP type is followed by the variable name&lt;br /&gt;
      * @return mixed&lt;br /&gt;
      */&lt;br /&gt;
      function forum_get_ratings_mean($postid, $scale, $ratings=NULL) {&lt;br /&gt;
          if (!$ratings) {&lt;br /&gt;
              $ratings = array();     // Initialize the empty array&lt;br /&gt;
              if ($rates = get_records(&amp;quot;forum_ratings&amp;quot;, &amp;quot;post&amp;quot;, $postid)) {&lt;br /&gt;
                  // Process each rating in turn&lt;br /&gt;
                  foreach ($rates as $rate) {&lt;br /&gt;
      ....etc&lt;br /&gt;
&lt;br /&gt;
8. Space should be used liberally - don&#039;t be afraid to spread things out a little to gain some clarity. Generally, there should be one space between brackets and normal statements, but no space between brackets and variables or functions:&lt;br /&gt;
&lt;br /&gt;
      foreach ($objects as $key =&amp;gt; $thing) {&lt;br /&gt;
          process($thing);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      if ($x == $y) {&lt;br /&gt;
          $a = $b;&lt;br /&gt;
      } else if ($x == $z) {&lt;br /&gt;
          $a = $c;&lt;br /&gt;
      } else {&lt;br /&gt;
          $a = $d;&lt;br /&gt;
      }&lt;br /&gt;
&lt;br /&gt;
9. When making a COPY of an object, always use the php5 clone() function (otherwise you may end up with just a reference to the first object).  Moodle will make sure this works consistently on php4 too.&lt;br /&gt;
&lt;br /&gt;
      BAD:   $b = $a;&lt;br /&gt;
      GOOD:  $b = clone($a);&lt;br /&gt;
&lt;br /&gt;
If the thing you want to copy is not an object, but may contain objects (eg an array of objects) then use fullclone() instead.&lt;br /&gt;
&lt;br /&gt;
==Database structures==&lt;br /&gt;
&lt;br /&gt;
To help you create tables that meet these guidelines, we recommend you use the built in [[Development:XMLDB_defining_an_XML_structure#The_XMLDB_editor|database definition (XMLDB) editor]].&lt;br /&gt;
&lt;br /&gt;
# Every table must have an auto-incrementing id field (INT10) as primary index. (see [[IdColumnReasons]])&lt;br /&gt;
# The main table containing instances of each module must have the same name as the module (eg widget) and contain the following minimum fields:&lt;br /&gt;
#* id - as described above&lt;br /&gt;
#* course - the id of the course that each instance belongs to&lt;br /&gt;
#* name - the full name of each instance of the module&lt;br /&gt;
# Other tables associated with a module that contain information about &#039;things&#039; should be named widget_things (note the plural).&lt;br /&gt;
# Table and column names should avoid using [[Database reserved words|reserved words in any database]]. Please check them before creation. Table names may be up to 28 characters long, and Column names up to 30 characters.&lt;br /&gt;
# Column names should be always lowercase, simple and short, following the same rules as for variable names.&lt;br /&gt;
# Where possible, columns that contain a reference to the id field of another table (eg widget) should be called widgetid. (Note that this convention is newish and not followed in some older tables)&lt;br /&gt;
# Boolean fields should be implemented as small integer fields (eg INT4) containing 0 or 1, to allow for later expansion of values if necessary.&lt;br /&gt;
# Most tables should have a timemodified field (INT10) which is updated with a current timestamp obtained with the PHP time() function.&lt;br /&gt;
# Always define a default value for each field (and make it sensible)&lt;br /&gt;
# Each table name should start with the database prefix ($CFG-&amp;gt;prefix). In a lot of cases, this is taken care of for you automatically. Also, under Postgres, the name of every index must start with the prefix too.&lt;br /&gt;
# In order to guarantee [[Development:XMLDB problems#Table and column aliases - the AS keyword|cross-db compatibility]] follow these simple rules about the use of the &#039;&#039;&#039;AS&#039;&#039;&#039; keyword (only if you need table/colum aliases, of course):&lt;br /&gt;
#* &#039;&#039;&#039;Don&#039;t use&#039;&#039;&#039; the &#039;&#039;&#039;AS&#039;&#039;&#039; keyword for &#039;&#039;&#039;table aliases&#039;&#039;&#039;.&lt;br /&gt;
#* &#039;&#039;&#039;Do use&#039;&#039;&#039; the &#039;&#039;&#039;AS&#039;&#039;&#039; keyword for &#039;&#039;&#039;column aliases&#039;&#039;&#039;.&lt;br /&gt;
# &#039;&#039;&#039;Never&#039;&#039;&#039; create UNIQUE KEYs (constraints) at all. Instead use UNIQUE INDEXes. In the future, if we decide to add referential integrity to Moodle and we need UNIQUE KEYs they will be used, but not now. Please note that the XMLDB editor allows you to specify both XMLDB-only UNIQUE and FOREIGN constraints (and that&#039;s good, in order to have the XML well defined) but only underlying INDEXes will be generated. &lt;br /&gt;
# Those XMLDB-only UNIQUE KEYs (read previous point) only must be defined if such field/fields &#039;&#039;&#039;are going to be the target&#039;&#039;&#039; for some (XMLDB-only too) FOREIGN KEY. Else, create them as simple UNIQUE INDEXes.&lt;br /&gt;
# Tables associated &#039;&#039;&#039;with one block&#039;&#039;&#039; must follow this convention with their names: &#039;&#039;&#039;$CFG-&amp;gt;prefix + &amp;quot;block_&amp;quot; + name_of_the_block + anything_else&#039;&#039;&#039;. For example, assuming that $CFG-&amp;gt;prefix is &#039;mdl_&#039;, all the tables for the block &amp;quot;rss_client&amp;quot; must start by &#039;mdl_block_rss_client&#039; (being possible to add more words at the end, i.e. &#039;mdl_block_rss_client_anothertable&#039;...). This rule will be 100% enforced with Moodle 2.0, giving time to developers until then. See [http://tracker.moodle.org/browse/MDL-6786 Task 6786] for more info about this.&lt;br /&gt;
# &#039;&#039;&#039;Never&#039;&#039;&#039; make database changes in the STABLE branches.  If we did, then users upgrading from one stable version to the next would have duplicate changes occurring, which may cause serious errors.&lt;br /&gt;
# When refering to integer variable in SQL queries, do not surround the value in quotes. For example, get_records_select(&#039;question&#039;, &amp;quot;category=$catid&amp;quot;) is right. get_records_select(&#039;question&#039;, &amp;quot;category=&#039;$catid&#039;&amp;quot;) is wrong. It hides bugs where $catid is undefined. ([http://moodle.org/mod/forum/discuss.php?d=80629 This thread explains].)&lt;br /&gt;
&lt;br /&gt;
==Security issues (and handling form and URL data)==&lt;br /&gt;
&lt;br /&gt;
# Do not rely on &#039;register_globals&#039;. Every variable must be properly initialised in every code file. It must be obvious where the variable came from.&lt;br /&gt;
# Initialise all arrays and objects, even if empty. $a = array() or $obj = new stdClass();.&lt;br /&gt;
# Do not use the optional_variable() function (this function is now deprecated). Use the optional_param() function instead. Pick the correct PARAM_XXXX value for the data type you expect.&lt;br /&gt;
# Do not use the require_variable() function (this function is now deprecated). Use the required_param() function instead. Pick the correct PARAM_XXXX value for the data type you expect.&lt;br /&gt;
# Use data_submitted(), with care. Data must still be cleaned before use. Use confirm_sesskey() together with data_dubmitted() in order to prevent CSRF attacks.&lt;br /&gt;
# Do not use $_GET, $_POST or $_REQUEST. Use the appropriate required_param() or optional_param() appropriate to your need.&lt;br /&gt;
# Do not check for an action using something like if (isset($_GET[&#039;something&#039;])). Use, e.g., $something = optional_param( &#039;something&#039;,-1,PARAM_INT ) and then perform proper test for it being in its expected range of values e.g., if ($something&amp;gt;=0) {....&lt;br /&gt;
# Wherever possible group all your required_param(), optional_param() and other variables initialisation at the beginning of each file to make them easy to find.&lt;br /&gt;
# Use &#039;sesskey&#039; mechanism to protect form handling routines from attack. Basic example of use: when form is generated, include &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;sesskey&amp;quot; value=&amp;quot;&amp;lt;?php echo sesskey(); ?&amp;gt;&amp;quot; /&amp;gt;. When you process the form check with if (!confirm_sesskey()) { print_error(&#039;confirmsesskeybad&#039;);}.&lt;br /&gt;
# All filenames must be &#039;cleaned&#039; using the clean_filename() function, if this has not been done already by appropriate use of required_param() or optional_param()&lt;br /&gt;
# Any data read from the database must have [[Developer:Slashes|addslashes()]] applied to it before it can be written back. A whole object of data can be hit at once with addslashes_object(). For Moodle 2.0 the database layer has changed and you MUST NOT use addslashes() as this is now automated. &lt;br /&gt;
# addslashes_js() must be used for escaping of javascript strings&lt;br /&gt;
# Wherever possible, data to be stored in the database must come from POST data (from a form with method=&amp;quot;POST&amp;quot;) as opposed to GET data (ie, data from the URL line).&lt;br /&gt;
# Do not use data from $_SERVER if you can avoid it. This has portability issues.&lt;br /&gt;
# If it hasn&#039;t been done somewhere else, make sure all data written to the database has been through the clean_param() function using the appropriate PARAM_XXXX for the datatype.&lt;br /&gt;
# If you write custom SQL code, make very sure it is correct. In particular watch out for missing quotes around values. Possible SQL &#039;injection&#039; exploit.&lt;br /&gt;
# Check all data (particularly that written to the database) in every file it is used. Do not expect or rely on it being done somewhere else.&lt;br /&gt;
# Blocks of code to be included should contain a definite PHP structure (e.g, a class declaration, function definition(s) etc.) - straight blocks of code promote uninitialised variable usage.&lt;br /&gt;
# If you need to use shell_exec() (or any other shell invoking function), make sure you clean parameters first with escapeshellcmd()/escapeshellarg (otherwise, we open up for shell injection attacks).&lt;br /&gt;
&lt;br /&gt;
==Use of JavaScript within Moodle==&lt;br /&gt;
&lt;br /&gt;
On a separate page, see [[Development:JavaScript guidelines]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Coding]]&lt;br /&gt;
&lt;br /&gt;
[[es:Manual de Estilo de Código]]&lt;br /&gt;
[[ja:コーディング]]&lt;br /&gt;
[[zh:代码指南]]&lt;br /&gt;
[[pl:Kodowanie]]&lt;br /&gt;
[[pt:manual_de_codigo]]&lt;br /&gt;
[[fr:Développement:Directives_de_codage]]&lt;/div&gt;</summary>
		<author><name>Martinau</name></author>
	</entry>
</feed>