Qualquer projeto colaborativo necessita de consistência e estabilidade para permanecer fortalecido.
Essas normas são um objetivo a ser alcançado por todo o código do Moodle. É verdade que existem algumas áreas com falha nos códigos antigos, mas que estas serão corrigidas aos poucos. Todo código novo deve seguir essas normas.
Caso você precise atualizar um arquivo de ajuda:
Eu sei que é chato mudar o seu estilo se você está acostumado a outro, mas pondere isso com o aborrecimento de todas as pessoas que tentam dar sentido ao código do Moodle com estilos variados. Obviamente há prós e contras em qalquer estilo que você use, mas o estilo atual simplesmente é este, por favor respeite-o.
CORRETO: $quiz
CORRETO: $errorstring
CORRETO: $assignments (for an array of objects)
CORRETO: $i (but only in little loops)
ERRADO: $Quiz
ERRADO: $aReallyLongVariableNameWithoutAGoodReason
ERRADO: $error_string
define("FORUM_MODE_FLATOLDEST", 1);
function forum_set_display_mode($mode=0)
{
global $USER,
$CFG;
if ($mode)
{
$USER->mode
= $mode;
} else if (empty($USER->mode))
{
$USER->mode
= $CFG->forum_displaymode;
}
}
if ($quiz->attempts)
{
if ($numattempts >
$quiz->attempts)
{
error($strtoomanyattempts,
"view.php?id=$cm->id");
}
}
$var = 'texto sem variáveis';
$var = "com caracteres especiais como uma nova linha \n";
$var = 'muito longa com uma '.$single.' variável';
$var = "pouco $text com $many variáveis $within ";
/**
* Descrição primeiro, com asteriscos posicionados em ordem
* como neste exemplo. para referir-se a uma outra função,
* faça isto: {@link clean_param()}. Depois acrescente descrições
* para cada parâmetro como em seguida.
*
* @param int $postid The PHP type is followed by the variable name
* @param array $scale The PHP type is followed by the variable name
* @param array $ratings The PHP type is followed by the variable name
* @return mixed
*/
function forum_get_ratings_mean($postid,
$scale, $ratings=NULL)
{
if (!$ratings)
{
$ratings
= array(); //
Initialize the empty array
if ($rates
= get_records("forum_ratings",
"post", $postid))
{
//
Process each rating in turn
foreach
($rates as $rate)
{
....etc
foreach ($objects
as $key =>
$thing) {
process($thing);
}
if ($x ==
$y)
{
$a
= $b;
} else if ($x ==
$z) {
$a
= $c;
} else {
$a
= $d;
}
$a = array()
or $obj = new stdClass();
.optional_variable()
function. Use the optional_param()
function instead. Pick the correct PARAM_XXXX value for the data type you expect. To check and set an optional
value for a variable, use the set_default()
function.require_variable()
function. Use the required_param()
function instead. Pick the correct PARAM_XXXX value for the data type you expect.data_submitted()
, with care. Data must still be cleaned before use.$_GET
, $_POST
or $_REQUEST
. Use the
appropriate required_param()
or optional_param()
appropriate to your need.if (isset($_GET['something']))
.
Use, e.g., $something = optional_param( 'something',-1,PARAM_INT )
and then perform
proper test for it being in its expected range of values e.g., if ($something>=0) {...
.required_param()
, optional_param()
and other variables initialisation at the beginning of each file to make them easy to find.<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
.
When you process the form check with if (!confirm_sesskey()) {error('Bad Session Key');}
.clean_filename()
function, if this
has not been done already by appropriate use of required_param()
or optional_param()
addslashes()
applied to it before it
can be written back. A whole object of data can be hit at once with addslashes_object()
.POST
data (from a form with method="POST"
) as opposed to GET
data (ie, data from the URL line).$_SERVER
if you can avoid it. This has portability
issues.clean_param()
function using the appropriate PARAM_XXXX for the datatype.Version: $Id$