id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
220,400
moodle/moodle
lib/lessphp/Parser.php
Less_Parser.parseOperand
private function parseOperand (){ $negate = false; $offset = $this->pos+1; if( $offset >= $this->input_len ){ return; } $char = $this->input[$offset]; if( $char === '@' || $char === '(' ){ $negate = $this->MatchChar('-'); } $o = $this->MatchFuncs(array('parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall')); if( $negate ){ $o->parensInOp = true; $o = $this->NewObj1('Less_Tree_Negative',$o); } return $o; }
php
private function parseOperand (){ $negate = false; $offset = $this->pos+1; if( $offset >= $this->input_len ){ return; } $char = $this->input[$offset]; if( $char === '@' || $char === '(' ){ $negate = $this->MatchChar('-'); } $o = $this->MatchFuncs(array('parseSub','parseEntitiesDimension','parseEntitiesColor','parseEntitiesVariable','parseEntitiesCall')); if( $negate ){ $o->parensInOp = true; $o = $this->NewObj1('Less_Tree_Negative',$o); } return $o; }
[ "private", "function", "parseOperand", "(", ")", "{", "$", "negate", "=", "false", ";", "$", "offset", "=", "$", "this", "->", "pos", "+", "1", ";", "if", "(", "$", "offset", ">=", "$", "this", "->", "input_len", ")", "{", "return", ";", "}", "$", "char", "=", "$", "this", "->", "input", "[", "$", "offset", "]", ";", "if", "(", "$", "char", "===", "'@'", "||", "$", "char", "===", "'('", ")", "{", "$", "negate", "=", "$", "this", "->", "MatchChar", "(", "'-'", ")", ";", "}", "$", "o", "=", "$", "this", "->", "MatchFuncs", "(", "array", "(", "'parseSub'", ",", "'parseEntitiesDimension'", ",", "'parseEntitiesColor'", ",", "'parseEntitiesVariable'", ",", "'parseEntitiesCall'", ")", ")", ";", "if", "(", "$", "negate", ")", "{", "$", "o", "->", "parensInOp", "=", "true", ";", "$", "o", "=", "$", "this", "->", "NewObj1", "(", "'Less_Tree_Negative'", ",", "$", "o", ")", ";", "}", "return", "$", "o", ";", "}" ]
An operand is anything that can be part of an operation, such as a Color, or a Variable
[ "An", "operand", "is", "anything", "that", "can", "be", "part", "of", "an", "operation", "such", "as", "a", "Color", "or", "a", "Variable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2352-L2372
220,401
moodle/moodle
lib/lessphp/Parser.php
Less_Parser.parseExpression
private function parseExpression (){ $entities = array(); do{ $e = $this->MatchFuncs(array('parseAddition','parseEntity')); if( $e ){ $entities[] = $e; // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here if( !$this->PeekReg('/\\G\/[\/*]/') ){ $delim = $this->MatchChar('/'); if( $delim ){ $entities[] = $this->NewObj1('Less_Tree_Anonymous',$delim); } } } }while($e); if( $entities ){ return $this->NewObj1('Less_Tree_Expression',$entities); } }
php
private function parseExpression (){ $entities = array(); do{ $e = $this->MatchFuncs(array('parseAddition','parseEntity')); if( $e ){ $entities[] = $e; // operations do not allow keyword "/" dimension (e.g. small/20px) so we support that here if( !$this->PeekReg('/\\G\/[\/*]/') ){ $delim = $this->MatchChar('/'); if( $delim ){ $entities[] = $this->NewObj1('Less_Tree_Anonymous',$delim); } } } }while($e); if( $entities ){ return $this->NewObj1('Less_Tree_Expression',$entities); } }
[ "private", "function", "parseExpression", "(", ")", "{", "$", "entities", "=", "array", "(", ")", ";", "do", "{", "$", "e", "=", "$", "this", "->", "MatchFuncs", "(", "array", "(", "'parseAddition'", ",", "'parseEntity'", ")", ")", ";", "if", "(", "$", "e", ")", "{", "$", "entities", "[", "]", "=", "$", "e", ";", "// operations do not allow keyword \"/\" dimension (e.g. small/20px) so we support that here", "if", "(", "!", "$", "this", "->", "PeekReg", "(", "'/\\\\G\\/[\\/*]/'", ")", ")", "{", "$", "delim", "=", "$", "this", "->", "MatchChar", "(", "'/'", ")", ";", "if", "(", "$", "delim", ")", "{", "$", "entities", "[", "]", "=", "$", "this", "->", "NewObj1", "(", "'Less_Tree_Anonymous'", ",", "$", "delim", ")", ";", "}", "}", "}", "}", "while", "(", "$", "e", ")", ";", "if", "(", "$", "entities", ")", "{", "return", "$", "this", "->", "NewObj1", "(", "'Less_Tree_Expression'", ",", "$", "entities", ")", ";", "}", "}" ]
Expressions either represent mathematical operations, or white-space delimited Entities. 1px solid black @var * 2 @return Less_Tree_Expression|null
[ "Expressions", "either", "represent", "mathematical", "operations", "or", "white", "-", "space", "delimited", "Entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2384-L2404
220,402
moodle/moodle
lib/lessphp/Parser.php
Less_Parser.ArgString
public static function ArgString($arg){ $type = gettype($arg); if( $type === 'object'){ $string = $arg->cache_string; unset($arg->cache_string); return $string; }elseif( $type === 'array' ){ $string = ' Array('; foreach($arg as $k => $a){ $string .= var_export($k,true).' => '.self::ArgString($a).','; } return $string . ')'; } return var_export($arg,true); }
php
public static function ArgString($arg){ $type = gettype($arg); if( $type === 'object'){ $string = $arg->cache_string; unset($arg->cache_string); return $string; }elseif( $type === 'array' ){ $string = ' Array('; foreach($arg as $k => $a){ $string .= var_export($k,true).' => '.self::ArgString($a).','; } return $string . ')'; } return var_export($arg,true); }
[ "public", "static", "function", "ArgString", "(", "$", "arg", ")", "{", "$", "type", "=", "gettype", "(", "$", "arg", ")", ";", "if", "(", "$", "type", "===", "'object'", ")", "{", "$", "string", "=", "$", "arg", "->", "cache_string", ";", "unset", "(", "$", "arg", "->", "cache_string", ")", ";", "return", "$", "string", ";", "}", "elseif", "(", "$", "type", "===", "'array'", ")", "{", "$", "string", "=", "' Array('", ";", "foreach", "(", "$", "arg", "as", "$", "k", "=>", "$", "a", ")", "{", "$", "string", ".=", "var_export", "(", "$", "k", ",", "true", ")", ".", "' => '", ".", "self", "::", "ArgString", "(", "$", "a", ")", ".", "','", ";", "}", "return", "$", "string", ".", "')'", ";", "}", "return", "var_export", "(", "$", "arg", ",", "true", ")", ";", "}" ]
Convert an argument to a string for use in the parser cache @return string
[ "Convert", "an", "argument", "to", "a", "string", "for", "use", "in", "the", "parser", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2595-L2613
220,403
moodle/moodle
lib/classes/text.php
core_text.typo3
protected static function typo3($reset = false) { static $typo3cs = null; if ($reset) { $typo3cs = null; return null; } if (isset($typo3cs)) { return $typo3cs; } global $CFG; // Required files require_once($CFG->libdir.'/typo3/class.t3lib_cs.php'); require_once($CFG->libdir.'/typo3/class.t3lib_div.php'); require_once($CFG->libdir.'/typo3/interface.t3lib_singleton.php'); require_once($CFG->libdir.'/typo3/class.t3lib_l10n_locales.php'); // do not use mbstring or recode because it may return invalid results in some corner cases $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'iconv'; // Tell Typo3 we are curl enabled always (mandatory since 2.0) $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = '1'; // And this directory must exist to allow Typo to cache conversion // tables when using internal functions make_temp_directory('typo3temp/cs'); // Make sure typo is using our dir permissions $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = decoct($CFG->directorypermissions); // Default mask for Typo $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = decoct($CFG->filepermissions); // This full path constants must be defined too, transforming backslashes // to forward slashed because Typo3 requires it. if (!defined('PATH_t3lib')) { define('PATH_t3lib', str_replace('\\','/',$CFG->libdir.'/typo3/')); define('PATH_typo3', str_replace('\\','/',$CFG->libdir.'/typo3/')); define('PATH_site', str_replace('\\','/',$CFG->tempdir.'/')); define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); } $typo3cs = new t3lib_cs(); return $typo3cs; }
php
protected static function typo3($reset = false) { static $typo3cs = null; if ($reset) { $typo3cs = null; return null; } if (isset($typo3cs)) { return $typo3cs; } global $CFG; // Required files require_once($CFG->libdir.'/typo3/class.t3lib_cs.php'); require_once($CFG->libdir.'/typo3/class.t3lib_div.php'); require_once($CFG->libdir.'/typo3/interface.t3lib_singleton.php'); require_once($CFG->libdir.'/typo3/class.t3lib_l10n_locales.php'); // do not use mbstring or recode because it may return invalid results in some corner cases $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv'; $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'iconv'; // Tell Typo3 we are curl enabled always (mandatory since 2.0) $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = '1'; // And this directory must exist to allow Typo to cache conversion // tables when using internal functions make_temp_directory('typo3temp/cs'); // Make sure typo is using our dir permissions $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = decoct($CFG->directorypermissions); // Default mask for Typo $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = decoct($CFG->filepermissions); // This full path constants must be defined too, transforming backslashes // to forward slashed because Typo3 requires it. if (!defined('PATH_t3lib')) { define('PATH_t3lib', str_replace('\\','/',$CFG->libdir.'/typo3/')); define('PATH_typo3', str_replace('\\','/',$CFG->libdir.'/typo3/')); define('PATH_site', str_replace('\\','/',$CFG->tempdir.'/')); define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':''); } $typo3cs = new t3lib_cs(); return $typo3cs; }
[ "protected", "static", "function", "typo3", "(", "$", "reset", "=", "false", ")", "{", "static", "$", "typo3cs", "=", "null", ";", "if", "(", "$", "reset", ")", "{", "$", "typo3cs", "=", "null", ";", "return", "null", ";", "}", "if", "(", "isset", "(", "$", "typo3cs", ")", ")", "{", "return", "$", "typo3cs", ";", "}", "global", "$", "CFG", ";", "// Required files", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/typo3/class.t3lib_cs.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/typo3/class.t3lib_div.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/typo3/interface.t3lib_singleton.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/typo3/class.t3lib_l10n_locales.php'", ")", ";", "// do not use mbstring or recode because it may return invalid results in some corner cases", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_convMethod'", "]", "=", "'iconv'", ";", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'t3lib_cs_utils'", "]", "=", "'iconv'", ";", "// Tell Typo3 we are curl enabled always (mandatory since 2.0)", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'curlUse'", "]", "=", "'1'", ";", "// And this directory must exist to allow Typo to cache conversion", "// tables when using internal functions", "make_temp_directory", "(", "'typo3temp/cs'", ")", ";", "// Make sure typo is using our dir permissions", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'folderCreateMask'", "]", "=", "decoct", "(", "$", "CFG", "->", "directorypermissions", ")", ";", "// Default mask for Typo", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'fileCreateMask'", "]", "=", "decoct", "(", "$", "CFG", "->", "filepermissions", ")", ";", "// This full path constants must be defined too, transforming backslashes", "// to forward slashed because Typo3 requires it.", "if", "(", "!", "defined", "(", "'PATH_t3lib'", ")", ")", "{", "define", "(", "'PATH_t3lib'", ",", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "CFG", "->", "libdir", ".", "'/typo3/'", ")", ")", ";", "define", "(", "'PATH_typo3'", ",", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "CFG", "->", "libdir", ".", "'/typo3/'", ")", ")", ";", "define", "(", "'PATH_site'", ",", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "CFG", "->", "tempdir", ".", "'/'", ")", ")", ";", "define", "(", "'TYPO3_OS'", ",", "stristr", "(", "PHP_OS", ",", "'win'", ")", "&&", "!", "stristr", "(", "PHP_OS", ",", "'darwin'", ")", "?", "'WIN'", ":", "''", ")", ";", "}", "$", "typo3cs", "=", "new", "t3lib_cs", "(", ")", ";", "return", "$", "typo3cs", ";", "}" ]
Return t3lib helper class, which is used for conversion between charsets @param bool $reset @return t3lib_cs
[ "Return", "t3lib", "helper", "class", "which", "is", "used", "for", "conversion", "between", "charsets" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L62-L111
220,404
moodle/moodle
lib/classes/text.php
core_text.parse_charset
public static function parse_charset($charset) { $charset = strtolower($charset); // shortcuts so that we do not have to load typo3 on every page if ($charset === 'utf8' or $charset === 'utf-8') { return 'utf-8'; } if (preg_match('/^(cp|win|windows)-?(12[0-9]{2})$/', $charset, $matches)) { return 'windows-'.$matches[2]; } if (preg_match('/^iso-8859-[0-9]+$/', $charset, $matches)) { return $charset; } if ($charset === 'euc-jp') { return 'euc-jp'; } if ($charset === 'iso-2022-jp') { return 'iso-2022-jp'; } if ($charset === 'shift-jis' or $charset === 'shift_jis') { return 'shift_jis'; } if ($charset === 'gb2312') { return 'gb2312'; } if ($charset === 'gb18030') { return 'gb18030'; } // fallback to typo3 return self::typo3()->parse_charset($charset); }
php
public static function parse_charset($charset) { $charset = strtolower($charset); // shortcuts so that we do not have to load typo3 on every page if ($charset === 'utf8' or $charset === 'utf-8') { return 'utf-8'; } if (preg_match('/^(cp|win|windows)-?(12[0-9]{2})$/', $charset, $matches)) { return 'windows-'.$matches[2]; } if (preg_match('/^iso-8859-[0-9]+$/', $charset, $matches)) { return $charset; } if ($charset === 'euc-jp') { return 'euc-jp'; } if ($charset === 'iso-2022-jp') { return 'iso-2022-jp'; } if ($charset === 'shift-jis' or $charset === 'shift_jis') { return 'shift_jis'; } if ($charset === 'gb2312') { return 'gb2312'; } if ($charset === 'gb18030') { return 'gb18030'; } // fallback to typo3 return self::typo3()->parse_charset($charset); }
[ "public", "static", "function", "parse_charset", "(", "$", "charset", ")", "{", "$", "charset", "=", "strtolower", "(", "$", "charset", ")", ";", "// shortcuts so that we do not have to load typo3 on every page", "if", "(", "$", "charset", "===", "'utf8'", "or", "$", "charset", "===", "'utf-8'", ")", "{", "return", "'utf-8'", ";", "}", "if", "(", "preg_match", "(", "'/^(cp|win|windows)-?(12[0-9]{2})$/'", ",", "$", "charset", ",", "$", "matches", ")", ")", "{", "return", "'windows-'", ".", "$", "matches", "[", "2", "]", ";", "}", "if", "(", "preg_match", "(", "'/^iso-8859-[0-9]+$/'", ",", "$", "charset", ",", "$", "matches", ")", ")", "{", "return", "$", "charset", ";", "}", "if", "(", "$", "charset", "===", "'euc-jp'", ")", "{", "return", "'euc-jp'", ";", "}", "if", "(", "$", "charset", "===", "'iso-2022-jp'", ")", "{", "return", "'iso-2022-jp'", ";", "}", "if", "(", "$", "charset", "===", "'shift-jis'", "or", "$", "charset", "===", "'shift_jis'", ")", "{", "return", "'shift_jis'", ";", "}", "if", "(", "$", "charset", "===", "'gb2312'", ")", "{", "return", "'gb2312'", ";", "}", "if", "(", "$", "charset", "===", "'gb18030'", ")", "{", "return", "'gb18030'", ";", "}", "// fallback to typo3", "return", "self", "::", "typo3", "(", ")", "->", "parse_charset", "(", "$", "charset", ")", ";", "}" ]
Standardise charset name Please note it does not mean the returned charset is actually supported. @static @param string $charset raw charset name @return string normalised lowercase charset name
[ "Standardise", "charset", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L130-L165
220,405
moodle/moodle
lib/classes/text.php
core_text.str_max_bytes
public static function str_max_bytes($string, $bytes) { if (function_exists('mb_strcut')) { return mb_strcut($string, 0, $bytes, 'UTF-8'); } $oldlevel = error_reporting(E_PARSE); $result = self::typo3()->strtrunc('utf-8', $string, $bytes); error_reporting($oldlevel); return $result; }
php
public static function str_max_bytes($string, $bytes) { if (function_exists('mb_strcut')) { return mb_strcut($string, 0, $bytes, 'UTF-8'); } $oldlevel = error_reporting(E_PARSE); $result = self::typo3()->strtrunc('utf-8', $string, $bytes); error_reporting($oldlevel); return $result; }
[ "public", "static", "function", "str_max_bytes", "(", "$", "string", ",", "$", "bytes", ")", "{", "if", "(", "function_exists", "(", "'mb_strcut'", ")", ")", "{", "return", "mb_strcut", "(", "$", "string", ",", "0", ",", "$", "bytes", ",", "'UTF-8'", ")", ";", "}", "$", "oldlevel", "=", "error_reporting", "(", "E_PARSE", ")", ";", "$", "result", "=", "self", "::", "typo3", "(", ")", "->", "strtrunc", "(", "'utf-8'", ",", "$", "string", ",", "$", "bytes", ")", ";", "error_reporting", "(", "$", "oldlevel", ")", ";", "return", "$", "result", ";", "}" ]
Truncates a string to no more than a certain number of bytes in a multi-byte safe manner. UTF-8 only! Many of the other charsets we test for (like ISO-2022-JP and EUC-JP) are not supported by typo3, and will give invalid results, so we are supporting UTF-8 only. @param string $string String to truncate @param int $bytes Maximum length of bytes in the result @return string Portion of string specified by $bytes @since Moodle 3.1
[ "Truncates", "a", "string", "to", "no", "more", "than", "a", "certain", "number", "of", "bytes", "in", "a", "multi", "-", "byte", "safe", "manner", ".", "UTF", "-", "8", "only!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L268-L278
220,406
moodle/moodle
lib/classes/text.php
core_text.specialtoascii
public static function specialtoascii($text, $charset='utf-8') { $charset = self::parse_charset($charset); $oldlevel = error_reporting(E_PARSE); $result = self::typo3()->specCharsToASCII($charset, (string)$text); error_reporting($oldlevel); return $result; }
php
public static function specialtoascii($text, $charset='utf-8') { $charset = self::parse_charset($charset); $oldlevel = error_reporting(E_PARSE); $result = self::typo3()->specCharsToASCII($charset, (string)$text); error_reporting($oldlevel); return $result; }
[ "public", "static", "function", "specialtoascii", "(", "$", "text", ",", "$", "charset", "=", "'utf-8'", ")", "{", "$", "charset", "=", "self", "::", "parse_charset", "(", "$", "charset", ")", ";", "$", "oldlevel", "=", "error_reporting", "(", "E_PARSE", ")", ";", "$", "result", "=", "self", "::", "typo3", "(", ")", "->", "specCharsToASCII", "(", "$", "charset", ",", "(", "string", ")", "$", "text", ")", ";", "error_reporting", "(", "$", "oldlevel", ")", ";", "return", "$", "result", ";", "}" ]
Try to convert upper unicode characters to plain ascii, the returned string may contain unconverted unicode characters. @param string $text input string @param string $charset encoding of the text @return string converted ascii string
[ "Try", "to", "convert", "upper", "unicode", "characters", "to", "plain", "ascii", "the", "returned", "string", "may", "contain", "unconverted", "unicode", "characters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L430-L436
220,407
moodle/moodle
lib/classes/text.php
core_text.get_entities_table
protected static function get_entities_table() { static $trans_tbl = null; // Generate/create $trans_tbl if (!isset($trans_tbl)) { if (version_compare(phpversion(), '5.3.4') < 0) { $trans_tbl = array(); foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) { $trans_tbl[$key] = self::convert($val, 'ISO-8859-1', 'utf-8'); } } else if (version_compare(phpversion(), '5.4.0') < 0) { $trans_tbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'UTF-8'); $trans_tbl = array_flip($trans_tbl); } else { $trans_tbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_HTML401, 'UTF-8'); $trans_tbl = array_flip($trans_tbl); } } return $trans_tbl; }
php
protected static function get_entities_table() { static $trans_tbl = null; // Generate/create $trans_tbl if (!isset($trans_tbl)) { if (version_compare(phpversion(), '5.3.4') < 0) { $trans_tbl = array(); foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key) { $trans_tbl[$key] = self::convert($val, 'ISO-8859-1', 'utf-8'); } } else if (version_compare(phpversion(), '5.4.0') < 0) { $trans_tbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'UTF-8'); $trans_tbl = array_flip($trans_tbl); } else { $trans_tbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_HTML401, 'UTF-8'); $trans_tbl = array_flip($trans_tbl); } } return $trans_tbl; }
[ "protected", "static", "function", "get_entities_table", "(", ")", "{", "static", "$", "trans_tbl", "=", "null", ";", "// Generate/create $trans_tbl", "if", "(", "!", "isset", "(", "$", "trans_tbl", ")", ")", "{", "if", "(", "version_compare", "(", "phpversion", "(", ")", ",", "'5.3.4'", ")", "<", "0", ")", "{", "$", "trans_tbl", "=", "array", "(", ")", ";", "foreach", "(", "get_html_translation_table", "(", "HTML_ENTITIES", ")", "as", "$", "val", "=>", "$", "key", ")", "{", "$", "trans_tbl", "[", "$", "key", "]", "=", "self", "::", "convert", "(", "$", "val", ",", "'ISO-8859-1'", ",", "'utf-8'", ")", ";", "}", "}", "else", "if", "(", "version_compare", "(", "phpversion", "(", ")", ",", "'5.4.0'", ")", "<", "0", ")", "{", "$", "trans_tbl", "=", "get_html_translation_table", "(", "HTML_ENTITIES", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "$", "trans_tbl", "=", "array_flip", "(", "$", "trans_tbl", ")", ";", "}", "else", "{", "$", "trans_tbl", "=", "get_html_translation_table", "(", "HTML_ENTITIES", ",", "ENT_COMPAT", "|", "ENT_HTML401", ",", "'UTF-8'", ")", ";", "$", "trans_tbl", "=", "array_flip", "(", "$", "trans_tbl", ")", ";", "}", "}", "return", "$", "trans_tbl", ";", "}" ]
Returns HTML entity transliteration table. @return array with (html entity => utf-8) elements
[ "Returns", "HTML", "entity", "transliteration", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L529-L551
220,408
moodle/moodle
lib/classes/text.php
core_text.get_encodings
public static function get_encodings() { $encodings = array(); $encodings['UTF-8'] = 'UTF-8'; $winenc = strtoupper(get_string('localewincharset', 'langconfig')); if ($winenc != '') { $encodings[$winenc] = $winenc; } $nixenc = strtoupper(get_string('oldcharset', 'langconfig')); $encodings[$nixenc] = $nixenc; foreach (self::typo3()->synonyms as $enc) { $enc = strtoupper($enc); $encodings[$enc] = $enc; } return $encodings; }
php
public static function get_encodings() { $encodings = array(); $encodings['UTF-8'] = 'UTF-8'; $winenc = strtoupper(get_string('localewincharset', 'langconfig')); if ($winenc != '') { $encodings[$winenc] = $winenc; } $nixenc = strtoupper(get_string('oldcharset', 'langconfig')); $encodings[$nixenc] = $nixenc; foreach (self::typo3()->synonyms as $enc) { $enc = strtoupper($enc); $encodings[$enc] = $enc; } return $encodings; }
[ "public", "static", "function", "get_encodings", "(", ")", "{", "$", "encodings", "=", "array", "(", ")", ";", "$", "encodings", "[", "'UTF-8'", "]", "=", "'UTF-8'", ";", "$", "winenc", "=", "strtoupper", "(", "get_string", "(", "'localewincharset'", ",", "'langconfig'", ")", ")", ";", "if", "(", "$", "winenc", "!=", "''", ")", "{", "$", "encodings", "[", "$", "winenc", "]", "=", "$", "winenc", ";", "}", "$", "nixenc", "=", "strtoupper", "(", "get_string", "(", "'oldcharset'", ",", "'langconfig'", ")", ")", ";", "$", "encodings", "[", "$", "nixenc", "]", "=", "$", "nixenc", ";", "foreach", "(", "self", "::", "typo3", "(", ")", "->", "synonyms", "as", "$", "enc", ")", "{", "$", "enc", "=", "strtoupper", "(", "$", "enc", ")", ";", "$", "encodings", "[", "$", "enc", "]", "=", "$", "enc", ";", "}", "return", "$", "encodings", ";", "}" ]
Returns encoding options for select boxes, utf-8 and platform encoding first @return array encodings
[ "Returns", "encoding", "options", "for", "select", "boxes", "utf", "-", "8", "and", "platform", "encoding", "first" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L674-L689
220,409
moodle/moodle
lib/classes/text.php
core_text.utf8ord
public static function utf8ord($utf8char) { if ($utf8char == '') { return 0; } $ord0 = ord($utf8char{0}); if ($ord0 >= 0 && $ord0 <= 127) { return $ord0; } $ord1 = ord($utf8char{1}); if ($ord0 >= 192 && $ord0 <= 223) { return ($ord0 - 192) * 64 + ($ord1 - 128); } $ord2 = ord($utf8char{2}); if ($ord0 >= 224 && $ord0 <= 239) { return ($ord0 - 224) * 4096 + ($ord1 - 128) * 64 + ($ord2 - 128); } $ord3 = ord($utf8char{3}); if ($ord0 >= 240 && $ord0 <= 247) { return ($ord0 - 240) * 262144 + ($ord1 - 128 )* 4096 + ($ord2 - 128) * 64 + ($ord3 - 128); } return false; }
php
public static function utf8ord($utf8char) { if ($utf8char == '') { return 0; } $ord0 = ord($utf8char{0}); if ($ord0 >= 0 && $ord0 <= 127) { return $ord0; } $ord1 = ord($utf8char{1}); if ($ord0 >= 192 && $ord0 <= 223) { return ($ord0 - 192) * 64 + ($ord1 - 128); } $ord2 = ord($utf8char{2}); if ($ord0 >= 224 && $ord0 <= 239) { return ($ord0 - 224) * 4096 + ($ord1 - 128) * 64 + ($ord2 - 128); } $ord3 = ord($utf8char{3}); if ($ord0 >= 240 && $ord0 <= 247) { return ($ord0 - 240) * 262144 + ($ord1 - 128 )* 4096 + ($ord2 - 128) * 64 + ($ord3 - 128); } return false; }
[ "public", "static", "function", "utf8ord", "(", "$", "utf8char", ")", "{", "if", "(", "$", "utf8char", "==", "''", ")", "{", "return", "0", ";", "}", "$", "ord0", "=", "ord", "(", "$", "utf8char", "{", "0", "}", ")", ";", "if", "(", "$", "ord0", ">=", "0", "&&", "$", "ord0", "<=", "127", ")", "{", "return", "$", "ord0", ";", "}", "$", "ord1", "=", "ord", "(", "$", "utf8char", "{", "1", "}", ")", ";", "if", "(", "$", "ord0", ">=", "192", "&&", "$", "ord0", "<=", "223", ")", "{", "return", "(", "$", "ord0", "-", "192", ")", "*", "64", "+", "(", "$", "ord1", "-", "128", ")", ";", "}", "$", "ord2", "=", "ord", "(", "$", "utf8char", "{", "2", "}", ")", ";", "if", "(", "$", "ord0", ">=", "224", "&&", "$", "ord0", "<=", "239", ")", "{", "return", "(", "$", "ord0", "-", "224", ")", "*", "4096", "+", "(", "$", "ord1", "-", "128", ")", "*", "64", "+", "(", "$", "ord2", "-", "128", ")", ";", "}", "$", "ord3", "=", "ord", "(", "$", "utf8char", "{", "3", "}", ")", ";", "if", "(", "$", "ord0", ">=", "240", "&&", "$", "ord0", "<=", "247", ")", "{", "return", "(", "$", "ord0", "-", "240", ")", "*", "262144", "+", "(", "$", "ord1", "-", "128", ")", "*", "4096", "+", "(", "$", "ord2", "-", "128", ")", "*", "64", "+", "(", "$", "ord3", "-", "128", ")", ";", "}", "return", "false", ";", "}" ]
Returns the code of the given UTF-8 character @param string $utf8char one UTF-8 character @return int the code of the given character
[ "Returns", "the", "code", "of", "the", "given", "UTF", "-", "8", "character" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L720-L741
220,410
moodle/moodle
lib/classes/text.php
core_text.strtotitle
public static function strtotitle($text) { if (empty($text)) { return $text; } if (function_exists('mb_convert_case')) { return mb_convert_case($text, MB_CASE_TITLE, 'UTF-8'); } $text = self::strtolower($text); $words = explode(' ', $text); foreach ($words as $i=>$word) { $length = self::strlen($word); if (!$length) { continue; } else if ($length == 1) { $words[$i] = self::strtoupper($word); } else { $letter = self::substr($word, 0, 1); $letter = self::strtoupper($letter); $rest = self::substr($word, 1); $words[$i] = $letter.$rest; } } return implode(' ', $words); }
php
public static function strtotitle($text) { if (empty($text)) { return $text; } if (function_exists('mb_convert_case')) { return mb_convert_case($text, MB_CASE_TITLE, 'UTF-8'); } $text = self::strtolower($text); $words = explode(' ', $text); foreach ($words as $i=>$word) { $length = self::strlen($word); if (!$length) { continue; } else if ($length == 1) { $words[$i] = self::strtoupper($word); } else { $letter = self::substr($word, 0, 1); $letter = self::strtoupper($letter); $rest = self::substr($word, 1); $words[$i] = $letter.$rest; } } return implode(' ', $words); }
[ "public", "static", "function", "strtotitle", "(", "$", "text", ")", "{", "if", "(", "empty", "(", "$", "text", ")", ")", "{", "return", "$", "text", ";", "}", "if", "(", "function_exists", "(", "'mb_convert_case'", ")", ")", "{", "return", "mb_convert_case", "(", "$", "text", ",", "MB_CASE_TITLE", ",", "'UTF-8'", ")", ";", "}", "$", "text", "=", "self", "::", "strtolower", "(", "$", "text", ")", ";", "$", "words", "=", "explode", "(", "' '", ",", "$", "text", ")", ";", "foreach", "(", "$", "words", "as", "$", "i", "=>", "$", "word", ")", "{", "$", "length", "=", "self", "::", "strlen", "(", "$", "word", ")", ";", "if", "(", "!", "$", "length", ")", "{", "continue", ";", "}", "else", "if", "(", "$", "length", "==", "1", ")", "{", "$", "words", "[", "$", "i", "]", "=", "self", "::", "strtoupper", "(", "$", "word", ")", ";", "}", "else", "{", "$", "letter", "=", "self", "::", "substr", "(", "$", "word", ",", "0", ",", "1", ")", ";", "$", "letter", "=", "self", "::", "strtoupper", "(", "$", "letter", ")", ";", "$", "rest", "=", "self", "::", "substr", "(", "$", "word", ",", "1", ")", ";", "$", "words", "[", "$", "i", "]", "=", "$", "letter", ".", "$", "rest", ";", "}", "}", "return", "implode", "(", "' '", ",", "$", "words", ")", ";", "}" ]
Makes first letter of each word capital - words must be separated by spaces. Use with care, this function does not work properly in many locales!!! @param string $text input string @return string
[ "Makes", "first", "letter", "of", "each", "word", "capital", "-", "words", "must", "be", "separated", "by", "spaces", ".", "Use", "with", "care", "this", "function", "does", "not", "work", "properly", "in", "many", "locales!!!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/text.php#L750-L777
220,411
moodle/moodle
lib/grade/grade_item.php
grade_item.qualifies_for_regrading
public function qualifies_for_regrading() { if (empty($this->id)) { return false; } $db_item = new grade_item(array('id' => $this->id)); $calculationdiff = $db_item->calculation != $this->calculation; $categorydiff = $db_item->categoryid != $this->categoryid; $gradetypediff = $db_item->gradetype != $this->gradetype; $scaleiddiff = $db_item->scaleid != $this->scaleid; $outcomeiddiff = $db_item->outcomeid != $this->outcomeid; $locktimediff = $db_item->locktime != $this->locktime; $grademindiff = grade_floats_different($db_item->grademin, $this->grademin); $grademaxdiff = grade_floats_different($db_item->grademax, $this->grademax); $multfactordiff = grade_floats_different($db_item->multfactor, $this->multfactor); $plusfactordiff = grade_floats_different($db_item->plusfactor, $this->plusfactor); $acoefdiff = grade_floats_different($db_item->aggregationcoef, $this->aggregationcoef); $acoefdiff2 = grade_floats_different($db_item->aggregationcoef2, $this->aggregationcoef2); $weightoverride = grade_floats_different($db_item->weightoverride, $this->weightoverride); $needsupdatediff = !$db_item->needsupdate && $this->needsupdate; // force regrading only if setting the flag first time $lockeddiff = !empty($db_item->locked) && empty($this->locked); // force regrading only when unlocking return ($calculationdiff || $categorydiff || $gradetypediff || $grademaxdiff || $grademindiff || $scaleiddiff || $outcomeiddiff || $multfactordiff || $plusfactordiff || $needsupdatediff || $lockeddiff || $acoefdiff || $acoefdiff2 || $weightoverride || $locktimediff); }
php
public function qualifies_for_regrading() { if (empty($this->id)) { return false; } $db_item = new grade_item(array('id' => $this->id)); $calculationdiff = $db_item->calculation != $this->calculation; $categorydiff = $db_item->categoryid != $this->categoryid; $gradetypediff = $db_item->gradetype != $this->gradetype; $scaleiddiff = $db_item->scaleid != $this->scaleid; $outcomeiddiff = $db_item->outcomeid != $this->outcomeid; $locktimediff = $db_item->locktime != $this->locktime; $grademindiff = grade_floats_different($db_item->grademin, $this->grademin); $grademaxdiff = grade_floats_different($db_item->grademax, $this->grademax); $multfactordiff = grade_floats_different($db_item->multfactor, $this->multfactor); $plusfactordiff = grade_floats_different($db_item->plusfactor, $this->plusfactor); $acoefdiff = grade_floats_different($db_item->aggregationcoef, $this->aggregationcoef); $acoefdiff2 = grade_floats_different($db_item->aggregationcoef2, $this->aggregationcoef2); $weightoverride = grade_floats_different($db_item->weightoverride, $this->weightoverride); $needsupdatediff = !$db_item->needsupdate && $this->needsupdate; // force regrading only if setting the flag first time $lockeddiff = !empty($db_item->locked) && empty($this->locked); // force regrading only when unlocking return ($calculationdiff || $categorydiff || $gradetypediff || $grademaxdiff || $grademindiff || $scaleiddiff || $outcomeiddiff || $multfactordiff || $plusfactordiff || $needsupdatediff || $lockeddiff || $acoefdiff || $acoefdiff2 || $weightoverride || $locktimediff); }
[ "public", "function", "qualifies_for_regrading", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "id", ")", ")", "{", "return", "false", ";", "}", "$", "db_item", "=", "new", "grade_item", "(", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "calculationdiff", "=", "$", "db_item", "->", "calculation", "!=", "$", "this", "->", "calculation", ";", "$", "categorydiff", "=", "$", "db_item", "->", "categoryid", "!=", "$", "this", "->", "categoryid", ";", "$", "gradetypediff", "=", "$", "db_item", "->", "gradetype", "!=", "$", "this", "->", "gradetype", ";", "$", "scaleiddiff", "=", "$", "db_item", "->", "scaleid", "!=", "$", "this", "->", "scaleid", ";", "$", "outcomeiddiff", "=", "$", "db_item", "->", "outcomeid", "!=", "$", "this", "->", "outcomeid", ";", "$", "locktimediff", "=", "$", "db_item", "->", "locktime", "!=", "$", "this", "->", "locktime", ";", "$", "grademindiff", "=", "grade_floats_different", "(", "$", "db_item", "->", "grademin", ",", "$", "this", "->", "grademin", ")", ";", "$", "grademaxdiff", "=", "grade_floats_different", "(", "$", "db_item", "->", "grademax", ",", "$", "this", "->", "grademax", ")", ";", "$", "multfactordiff", "=", "grade_floats_different", "(", "$", "db_item", "->", "multfactor", ",", "$", "this", "->", "multfactor", ")", ";", "$", "plusfactordiff", "=", "grade_floats_different", "(", "$", "db_item", "->", "plusfactor", ",", "$", "this", "->", "plusfactor", ")", ";", "$", "acoefdiff", "=", "grade_floats_different", "(", "$", "db_item", "->", "aggregationcoef", ",", "$", "this", "->", "aggregationcoef", ")", ";", "$", "acoefdiff2", "=", "grade_floats_different", "(", "$", "db_item", "->", "aggregationcoef2", ",", "$", "this", "->", "aggregationcoef2", ")", ";", "$", "weightoverride", "=", "grade_floats_different", "(", "$", "db_item", "->", "weightoverride", ",", "$", "this", "->", "weightoverride", ")", ";", "$", "needsupdatediff", "=", "!", "$", "db_item", "->", "needsupdate", "&&", "$", "this", "->", "needsupdate", ";", "// force regrading only if setting the flag first time", "$", "lockeddiff", "=", "!", "empty", "(", "$", "db_item", "->", "locked", ")", "&&", "empty", "(", "$", "this", "->", "locked", ")", ";", "// force regrading only when unlocking", "return", "(", "$", "calculationdiff", "||", "$", "categorydiff", "||", "$", "gradetypediff", "||", "$", "grademaxdiff", "||", "$", "grademindiff", "||", "$", "scaleiddiff", "||", "$", "outcomeiddiff", "||", "$", "multfactordiff", "||", "$", "plusfactordiff", "||", "$", "needsupdatediff", "||", "$", "lockeddiff", "||", "$", "acoefdiff", "||", "$", "acoefdiff2", "||", "$", "weightoverride", "||", "$", "locktimediff", ")", ";", "}" ]
Compares the values held by this object with those of the matching record in DB, and returns whether or not these differences are sufficient to justify an update of all parent objects. This assumes that this object has an id number and a matching record in DB. If not, it will return false. @return bool
[ "Compares", "the", "values", "held", "by", "this", "object", "with", "those", "of", "the", "matching", "record", "in", "DB", "and", "returns", "whether", "or", "not", "these", "differences", "are", "sufficient", "to", "justify", "an", "update", "of", "all", "parent", "objects", ".", "This", "assumes", "that", "this", "object", "has", "an", "id", "number", "and", "a", "matching", "record", "in", "DB", ".", "If", "not", "it", "will", "return", "false", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L317-L344
220,412
moodle/moodle
lib/grade/grade_item.php
grade_item.delete_all_grades
public function delete_all_grades($source=null) { if (!$this->is_course_item()) { $this->force_regrading(); } if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) { foreach ($grades as $grade) { $grade->delete($source); } } // Delete all the historical files. // We only support feedback files for modules atm. if ($this->is_external_item()) { $fs = new file_storage(); $fs->delete_area_files($this->get_context()->id, GRADE_FILE_COMPONENT, GRADE_HISTORY_FEEDBACK_FILEAREA); } return true; }
php
public function delete_all_grades($source=null) { if (!$this->is_course_item()) { $this->force_regrading(); } if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) { foreach ($grades as $grade) { $grade->delete($source); } } // Delete all the historical files. // We only support feedback files for modules atm. if ($this->is_external_item()) { $fs = new file_storage(); $fs->delete_area_files($this->get_context()->id, GRADE_FILE_COMPONENT, GRADE_HISTORY_FEEDBACK_FILEAREA); } return true; }
[ "public", "function", "delete_all_grades", "(", "$", "source", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "is_course_item", "(", ")", ")", "{", "$", "this", "->", "force_regrading", "(", ")", ";", "}", "if", "(", "$", "grades", "=", "grade_grade", "::", "fetch_all", "(", "array", "(", "'itemid'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "foreach", "(", "$", "grades", "as", "$", "grade", ")", "{", "$", "grade", "->", "delete", "(", "$", "source", ")", ";", "}", "}", "// Delete all the historical files.", "// We only support feedback files for modules atm.", "if", "(", "$", "this", "->", "is_external_item", "(", ")", ")", "{", "$", "fs", "=", "new", "file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "this", "->", "get_context", "(", ")", "->", "id", ",", "GRADE_FILE_COMPONENT", ",", "GRADE_HISTORY_FEEDBACK_FILEAREA", ")", ";", "}", "return", "true", ";", "}" ]
Delete all grades @param string $source from where was the object deleted (mod/forum, manual, etc.) @return bool
[ "Delete", "all", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L413-L432
220,413
moodle/moodle
lib/grade/grade_item.php
grade_item.add_idnumber
public function add_idnumber($idnumber) { global $DB; if (!empty($this->idnumber)) { return false; } if ($this->itemtype == 'mod' and !$this->is_outcome_item()) { if ($this->itemnumber == 0) { // for activity modules, itemnumber 0 is synced with the course_modules if (!$cm = get_coursemodule_from_instance($this->itemmodule, $this->iteminstance, $this->courseid)) { return false; } if (!empty($cm->idnumber)) { return false; } $DB->set_field('course_modules', 'idnumber', $idnumber, array('id' => $cm->id)); $this->idnumber = $idnumber; return $this->update(); } else { $this->idnumber = $idnumber; return $this->update(); } } else { $this->idnumber = $idnumber; return $this->update(); } }
php
public function add_idnumber($idnumber) { global $DB; if (!empty($this->idnumber)) { return false; } if ($this->itemtype == 'mod' and !$this->is_outcome_item()) { if ($this->itemnumber == 0) { // for activity modules, itemnumber 0 is synced with the course_modules if (!$cm = get_coursemodule_from_instance($this->itemmodule, $this->iteminstance, $this->courseid)) { return false; } if (!empty($cm->idnumber)) { return false; } $DB->set_field('course_modules', 'idnumber', $idnumber, array('id' => $cm->id)); $this->idnumber = $idnumber; return $this->update(); } else { $this->idnumber = $idnumber; return $this->update(); } } else { $this->idnumber = $idnumber; return $this->update(); } }
[ "public", "function", "add_idnumber", "(", "$", "idnumber", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "idnumber", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "itemtype", "==", "'mod'", "and", "!", "$", "this", "->", "is_outcome_item", "(", ")", ")", "{", "if", "(", "$", "this", "->", "itemnumber", "==", "0", ")", "{", "// for activity modules, itemnumber 0 is synced with the course_modules", "if", "(", "!", "$", "cm", "=", "get_coursemodule_from_instance", "(", "$", "this", "->", "itemmodule", ",", "$", "this", "->", "iteminstance", ",", "$", "this", "->", "courseid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "cm", "->", "idnumber", ")", ")", "{", "return", "false", ";", "}", "$", "DB", "->", "set_field", "(", "'course_modules'", ",", "'idnumber'", ",", "$", "idnumber", ",", "array", "(", "'id'", "=>", "$", "cm", "->", "id", ")", ")", ";", "$", "this", "->", "idnumber", "=", "$", "idnumber", ";", "return", "$", "this", "->", "update", "(", ")", ";", "}", "else", "{", "$", "this", "->", "idnumber", "=", "$", "idnumber", ";", "return", "$", "this", "->", "update", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "idnumber", "=", "$", "idnumber", ";", "return", "$", "this", "->", "update", "(", ")", ";", "}", "}" ]
Set idnumber of grade item, updates also course_modules table @param string $idnumber (without magic quotes) @return bool success
[ "Set", "idnumber", "of", "grade", "item", "updates", "also", "course_modules", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L496-L523
220,414
moodle/moodle
lib/grade/grade_item.php
grade_item.set_hidden
public function set_hidden($hidden, $cascade=false) { parent::set_hidden($hidden, $cascade); if ($cascade) { if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) { foreach($grades as $grade) { $grade->grade_item =& $this; $grade->set_hidden($hidden, $cascade); } } } //if marking item visible make sure category is visible MDL-21367 if( !$hidden ) { $category_array = grade_category::fetch_all(array('id'=>$this->categoryid)); if ($category_array && array_key_exists($this->categoryid, $category_array)) { $category = $category_array[$this->categoryid]; //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden //if($category->is_hidden()) { $category->set_hidden($hidden, false); //} } } }
php
public function set_hidden($hidden, $cascade=false) { parent::set_hidden($hidden, $cascade); if ($cascade) { if ($grades = grade_grade::fetch_all(array('itemid'=>$this->id))) { foreach($grades as $grade) { $grade->grade_item =& $this; $grade->set_hidden($hidden, $cascade); } } } //if marking item visible make sure category is visible MDL-21367 if( !$hidden ) { $category_array = grade_category::fetch_all(array('id'=>$this->categoryid)); if ($category_array && array_key_exists($this->categoryid, $category_array)) { $category = $category_array[$this->categoryid]; //call set_hidden on the category regardless of whether it is hidden as its parent might be hidden //if($category->is_hidden()) { $category->set_hidden($hidden, false); //} } } }
[ "public", "function", "set_hidden", "(", "$", "hidden", ",", "$", "cascade", "=", "false", ")", "{", "parent", "::", "set_hidden", "(", "$", "hidden", ",", "$", "cascade", ")", ";", "if", "(", "$", "cascade", ")", "{", "if", "(", "$", "grades", "=", "grade_grade", "::", "fetch_all", "(", "array", "(", "'itemid'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "foreach", "(", "$", "grades", "as", "$", "grade", ")", "{", "$", "grade", "->", "grade_item", "=", "&", "$", "this", ";", "$", "grade", "->", "set_hidden", "(", "$", "hidden", ",", "$", "cascade", ")", ";", "}", "}", "}", "//if marking item visible make sure category is visible MDL-21367", "if", "(", "!", "$", "hidden", ")", "{", "$", "category_array", "=", "grade_category", "::", "fetch_all", "(", "array", "(", "'id'", "=>", "$", "this", "->", "categoryid", ")", ")", ";", "if", "(", "$", "category_array", "&&", "array_key_exists", "(", "$", "this", "->", "categoryid", ",", "$", "category_array", ")", ")", "{", "$", "category", "=", "$", "category_array", "[", "$", "this", "->", "categoryid", "]", ";", "//call set_hidden on the category regardless of whether it is hidden as its parent might be hidden", "//if($category->is_hidden()) {", "$", "category", "->", "set_hidden", "(", "$", "hidden", ",", "false", ")", ";", "//}", "}", "}", "}" ]
Set the hidden status of grade_item and all grades. 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until @param int $hidden new hidden status @param bool $cascade apply to child objects too
[ "Set", "the", "hidden", "status", "of", "grade_item", "and", "all", "grades", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L655-L678
220,415
moodle/moodle
lib/grade/grade_item.php
grade_item.has_hidden_grades
public function has_hidden_grades($groupsql="", array $params=null, $groupwheresql="") { global $DB; $params = (array)$params; $params['itemid'] = $this->id; return $DB->get_field_sql("SELECT COUNT(*) FROM {grade_grades} g LEFT JOIN " ."{user} u ON g.userid = u.id $groupsql WHERE itemid = :itemid AND hidden = 1 $groupwheresql", $params); }
php
public function has_hidden_grades($groupsql="", array $params=null, $groupwheresql="") { global $DB; $params = (array)$params; $params['itemid'] = $this->id; return $DB->get_field_sql("SELECT COUNT(*) FROM {grade_grades} g LEFT JOIN " ."{user} u ON g.userid = u.id $groupsql WHERE itemid = :itemid AND hidden = 1 $groupwheresql", $params); }
[ "public", "function", "has_hidden_grades", "(", "$", "groupsql", "=", "\"\"", ",", "array", "$", "params", "=", "null", ",", "$", "groupwheresql", "=", "\"\"", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "(", "array", ")", "$", "params", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "this", "->", "id", ";", "return", "$", "DB", "->", "get_field_sql", "(", "\"SELECT COUNT(*) FROM {grade_grades} g LEFT JOIN \"", ".", "\"{user} u ON g.userid = u.id $groupsql WHERE itemid = :itemid AND hidden = 1 $groupwheresql\"", ",", "$", "params", ")", ";", "}" ]
Returns the number of grades that are hidden @param string $groupsql SQL to limit the query by group @param array $params SQL params for $groupsql @param string $groupwheresql Where conditions for $groupsql @return int The number of hidden grades
[ "Returns", "the", "number", "of", "grades", "that", "are", "hidden" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L688-L695
220,416
moodle/moodle
lib/grade/grade_item.php
grade_item.regrade_final_grades
public function regrade_final_grades($userid=null) { global $CFG, $DB; // locked grade items already have correct final grades if ($this->is_locked()) { return true; } // calculation produces final value using formula from other final values if ($this->is_calculated()) { if ($this->compute($userid)) { return true; } else { return "Could not calculate grades for grade item"; // TODO: improve and localize } // noncalculated outcomes already have final values - raw grades not used } else if ($this->is_outcome_item()) { return true; // aggregate the category grade } else if ($this->is_category_item() or $this->is_course_item()) { // aggregate category grade item $category = $this->load_item_category(); $category->grade_item =& $this; if ($category->generate_grades($userid)) { return true; } else { return "Could not aggregate final grades for category:".$this->id; // TODO: improve and localize } } else if ($this->is_manual_item()) { // manual items track only final grades, no raw grades return true; } else if (!$this->is_raw_used()) { // hmm - raw grades are not used- nothing to regrade return true; } // normal grade item - just new final grades $result = true; $grade_inst = new grade_grade(); $fields = implode(',', $grade_inst->required_fields); if ($userid) { $params = array($this->id, $userid); $rs = $DB->get_recordset_select('grade_grades', "itemid=? AND userid=?", $params, '', $fields); } else { $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id), '', $fields); } if ($rs) { foreach ($rs as $grade_record) { $grade = new grade_grade($grade_record, false); if (!empty($grade_record->locked) or !empty($grade_record->overridden)) { // this grade is locked - final grade must be ok continue; } $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax); if (grade_floats_different($grade_record->finalgrade, $grade->finalgrade)) { $success = $grade->update('system'); // If successful trigger a user_graded event. if ($success) { $grade->load_grade_item(); \core\event\user_graded::create_from_grade($grade, \core\event\base::USER_OTHER)->trigger(); } else { $result = "Internal error updating final grade"; } } } $rs->close(); } return $result; }
php
public function regrade_final_grades($userid=null) { global $CFG, $DB; // locked grade items already have correct final grades if ($this->is_locked()) { return true; } // calculation produces final value using formula from other final values if ($this->is_calculated()) { if ($this->compute($userid)) { return true; } else { return "Could not calculate grades for grade item"; // TODO: improve and localize } // noncalculated outcomes already have final values - raw grades not used } else if ($this->is_outcome_item()) { return true; // aggregate the category grade } else if ($this->is_category_item() or $this->is_course_item()) { // aggregate category grade item $category = $this->load_item_category(); $category->grade_item =& $this; if ($category->generate_grades($userid)) { return true; } else { return "Could not aggregate final grades for category:".$this->id; // TODO: improve and localize } } else if ($this->is_manual_item()) { // manual items track only final grades, no raw grades return true; } else if (!$this->is_raw_used()) { // hmm - raw grades are not used- nothing to regrade return true; } // normal grade item - just new final grades $result = true; $grade_inst = new grade_grade(); $fields = implode(',', $grade_inst->required_fields); if ($userid) { $params = array($this->id, $userid); $rs = $DB->get_recordset_select('grade_grades', "itemid=? AND userid=?", $params, '', $fields); } else { $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id), '', $fields); } if ($rs) { foreach ($rs as $grade_record) { $grade = new grade_grade($grade_record, false); if (!empty($grade_record->locked) or !empty($grade_record->overridden)) { // this grade is locked - final grade must be ok continue; } $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax); if (grade_floats_different($grade_record->finalgrade, $grade->finalgrade)) { $success = $grade->update('system'); // If successful trigger a user_graded event. if ($success) { $grade->load_grade_item(); \core\event\user_graded::create_from_grade($grade, \core\event\base::USER_OTHER)->trigger(); } else { $result = "Internal error updating final grade"; } } } $rs->close(); } return $result; }
[ "public", "function", "regrade_final_grades", "(", "$", "userid", "=", "null", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "// locked grade items already have correct final grades", "if", "(", "$", "this", "->", "is_locked", "(", ")", ")", "{", "return", "true", ";", "}", "// calculation produces final value using formula from other final values", "if", "(", "$", "this", "->", "is_calculated", "(", ")", ")", "{", "if", "(", "$", "this", "->", "compute", "(", "$", "userid", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "\"Could not calculate grades for grade item\"", ";", "// TODO: improve and localize", "}", "// noncalculated outcomes already have final values - raw grades not used", "}", "else", "if", "(", "$", "this", "->", "is_outcome_item", "(", ")", ")", "{", "return", "true", ";", "// aggregate the category grade", "}", "else", "if", "(", "$", "this", "->", "is_category_item", "(", ")", "or", "$", "this", "->", "is_course_item", "(", ")", ")", "{", "// aggregate category grade item", "$", "category", "=", "$", "this", "->", "load_item_category", "(", ")", ";", "$", "category", "->", "grade_item", "=", "&", "$", "this", ";", "if", "(", "$", "category", "->", "generate_grades", "(", "$", "userid", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "\"Could not aggregate final grades for category:\"", ".", "$", "this", "->", "id", ";", "// TODO: improve and localize", "}", "}", "else", "if", "(", "$", "this", "->", "is_manual_item", "(", ")", ")", "{", "// manual items track only final grades, no raw grades", "return", "true", ";", "}", "else", "if", "(", "!", "$", "this", "->", "is_raw_used", "(", ")", ")", "{", "// hmm - raw grades are not used- nothing to regrade", "return", "true", ";", "}", "// normal grade item - just new final grades", "$", "result", "=", "true", ";", "$", "grade_inst", "=", "new", "grade_grade", "(", ")", ";", "$", "fields", "=", "implode", "(", "','", ",", "$", "grade_inst", "->", "required_fields", ")", ";", "if", "(", "$", "userid", ")", "{", "$", "params", "=", "array", "(", "$", "this", "->", "id", ",", "$", "userid", ")", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_select", "(", "'grade_grades'", ",", "\"itemid=? AND userid=?\"", ",", "$", "params", ",", "''", ",", "$", "fields", ")", ";", "}", "else", "{", "$", "rs", "=", "$", "DB", "->", "get_recordset", "(", "'grade_grades'", ",", "array", "(", "'itemid'", "=>", "$", "this", "->", "id", ")", ",", "''", ",", "$", "fields", ")", ";", "}", "if", "(", "$", "rs", ")", "{", "foreach", "(", "$", "rs", "as", "$", "grade_record", ")", "{", "$", "grade", "=", "new", "grade_grade", "(", "$", "grade_record", ",", "false", ")", ";", "if", "(", "!", "empty", "(", "$", "grade_record", "->", "locked", ")", "or", "!", "empty", "(", "$", "grade_record", "->", "overridden", ")", ")", "{", "// this grade is locked - final grade must be ok", "continue", ";", "}", "$", "grade", "->", "finalgrade", "=", "$", "this", "->", "adjust_raw_grade", "(", "$", "grade", "->", "rawgrade", ",", "$", "grade", "->", "rawgrademin", ",", "$", "grade", "->", "rawgrademax", ")", ";", "if", "(", "grade_floats_different", "(", "$", "grade_record", "->", "finalgrade", ",", "$", "grade", "->", "finalgrade", ")", ")", "{", "$", "success", "=", "$", "grade", "->", "update", "(", "'system'", ")", ";", "// If successful trigger a user_graded event.", "if", "(", "$", "success", ")", "{", "$", "grade", "->", "load_grade_item", "(", ")", ";", "\\", "core", "\\", "event", "\\", "user_graded", "::", "create_from_grade", "(", "$", "grade", ",", "\\", "core", "\\", "event", "\\", "base", "::", "USER_OTHER", ")", "->", "trigger", "(", ")", ";", "}", "else", "{", "$", "result", "=", "\"Internal error updating final grade\"", ";", "}", "}", "}", "$", "rs", "->", "close", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Performs the necessary calculations on the grades_final referenced by this grade_item. Also resets the needsupdate flag once successfully performed. This function must be used ONLY from lib/gradeslib.php/grade_regrade_final_grades(), because the regrading must be done in correct order!! @param int $userid Supply a user ID to limit the regrading to a single user @return bool true if ok, error string otherwise
[ "Performs", "the", "necessary", "calculations", "on", "the", "grades_final", "referenced", "by", "this", "grade_item", ".", "Also", "resets", "the", "needsupdate", "flag", "once", "successfully", "performed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L718-L795
220,417
moodle/moodle
lib/grade/grade_item.php
grade_item.adjust_raw_grade
public function adjust_raw_grade($rawgrade, $rawmin, $rawmax) { if (is_null($rawgrade)) { return null; } if ($this->gradetype == GRADE_TYPE_VALUE) { // Dealing with numerical grade if ($this->grademax < $this->grademin) { return null; } if ($this->grademax == $this->grademin) { return $this->grademax; // no range } // Standardise score to the new grade range // NOTE: skip if the activity provides a manual rescaling option. $manuallyrescale = (component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false); if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) { $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); } // Apply other grade_item factors $rawgrade *= $this->multfactor; $rawgrade += $this->plusfactor; return $this->bounded_grade($rawgrade); } else if ($this->gradetype == GRADE_TYPE_SCALE) { // Dealing with a scale value if (empty($this->scale)) { $this->load_scale(); } if ($this->grademax < 0) { return null; // scale not present - no grade } if ($this->grademax == 0) { return $this->grademax; // only one option } // Convert scale if needed // NOTE: skip if the activity provides a manual rescaling option. $manuallyrescale = (component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false); if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) { // This should never happen because scales are locked if they are in use. $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); } return $this->bounded_grade($rawgrade); } else if ($this->gradetype == GRADE_TYPE_TEXT or $this->gradetype == GRADE_TYPE_NONE) { // no value // somebody changed the grading type when grades already existed return null; } else { debugging("Unknown grade type"); return null; } }
php
public function adjust_raw_grade($rawgrade, $rawmin, $rawmax) { if (is_null($rawgrade)) { return null; } if ($this->gradetype == GRADE_TYPE_VALUE) { // Dealing with numerical grade if ($this->grademax < $this->grademin) { return null; } if ($this->grademax == $this->grademin) { return $this->grademax; // no range } // Standardise score to the new grade range // NOTE: skip if the activity provides a manual rescaling option. $manuallyrescale = (component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false); if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) { $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); } // Apply other grade_item factors $rawgrade *= $this->multfactor; $rawgrade += $this->plusfactor; return $this->bounded_grade($rawgrade); } else if ($this->gradetype == GRADE_TYPE_SCALE) { // Dealing with a scale value if (empty($this->scale)) { $this->load_scale(); } if ($this->grademax < 0) { return null; // scale not present - no grade } if ($this->grademax == 0) { return $this->grademax; // only one option } // Convert scale if needed // NOTE: skip if the activity provides a manual rescaling option. $manuallyrescale = (component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false); if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) { // This should never happen because scales are locked if they are in use. $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax); } return $this->bounded_grade($rawgrade); } else if ($this->gradetype == GRADE_TYPE_TEXT or $this->gradetype == GRADE_TYPE_NONE) { // no value // somebody changed the grading type when grades already existed return null; } else { debugging("Unknown grade type"); return null; } }
[ "public", "function", "adjust_raw_grade", "(", "$", "rawgrade", ",", "$", "rawmin", ",", "$", "rawmax", ")", "{", "if", "(", "is_null", "(", "$", "rawgrade", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "gradetype", "==", "GRADE_TYPE_VALUE", ")", "{", "// Dealing with numerical grade", "if", "(", "$", "this", "->", "grademax", "<", "$", "this", "->", "grademin", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "grademax", "==", "$", "this", "->", "grademin", ")", "{", "return", "$", "this", "->", "grademax", ";", "// no range", "}", "// Standardise score to the new grade range", "// NOTE: skip if the activity provides a manual rescaling option.", "$", "manuallyrescale", "=", "(", "component_callback_exists", "(", "'mod_'", ".", "$", "this", "->", "itemmodule", ",", "'rescale_activity_grades'", ")", "!==", "false", ")", ";", "if", "(", "!", "$", "manuallyrescale", "&&", "(", "$", "rawmin", "!=", "$", "this", "->", "grademin", "or", "$", "rawmax", "!=", "$", "this", "->", "grademax", ")", ")", "{", "$", "rawgrade", "=", "grade_grade", "::", "standardise_score", "(", "$", "rawgrade", ",", "$", "rawmin", ",", "$", "rawmax", ",", "$", "this", "->", "grademin", ",", "$", "this", "->", "grademax", ")", ";", "}", "// Apply other grade_item factors", "$", "rawgrade", "*=", "$", "this", "->", "multfactor", ";", "$", "rawgrade", "+=", "$", "this", "->", "plusfactor", ";", "return", "$", "this", "->", "bounded_grade", "(", "$", "rawgrade", ")", ";", "}", "else", "if", "(", "$", "this", "->", "gradetype", "==", "GRADE_TYPE_SCALE", ")", "{", "// Dealing with a scale value", "if", "(", "empty", "(", "$", "this", "->", "scale", ")", ")", "{", "$", "this", "->", "load_scale", "(", ")", ";", "}", "if", "(", "$", "this", "->", "grademax", "<", "0", ")", "{", "return", "null", ";", "// scale not present - no grade", "}", "if", "(", "$", "this", "->", "grademax", "==", "0", ")", "{", "return", "$", "this", "->", "grademax", ";", "// only one option", "}", "// Convert scale if needed", "// NOTE: skip if the activity provides a manual rescaling option.", "$", "manuallyrescale", "=", "(", "component_callback_exists", "(", "'mod_'", ".", "$", "this", "->", "itemmodule", ",", "'rescale_activity_grades'", ")", "!==", "false", ")", ";", "if", "(", "!", "$", "manuallyrescale", "&&", "(", "$", "rawmin", "!=", "$", "this", "->", "grademin", "or", "$", "rawmax", "!=", "$", "this", "->", "grademax", ")", ")", "{", "// This should never happen because scales are locked if they are in use.", "$", "rawgrade", "=", "grade_grade", "::", "standardise_score", "(", "$", "rawgrade", ",", "$", "rawmin", ",", "$", "rawmax", ",", "$", "this", "->", "grademin", ",", "$", "this", "->", "grademax", ")", ";", "}", "return", "$", "this", "->", "bounded_grade", "(", "$", "rawgrade", ")", ";", "}", "else", "if", "(", "$", "this", "->", "gradetype", "==", "GRADE_TYPE_TEXT", "or", "$", "this", "->", "gradetype", "==", "GRADE_TYPE_NONE", ")", "{", "// no value", "// somebody changed the grading type when grades already existed", "return", "null", ";", "}", "else", "{", "debugging", "(", "\"Unknown grade type\"", ")", ";", "return", "null", ";", "}", "}" ]
Given a float grade value or integer grade scale, applies a number of adjustment based on grade_item variables and returns the result. @param float $rawgrade The raw grade value @param float $rawmin original rawmin @param float $rawmax original rawmax @return mixed
[ "Given", "a", "float", "grade", "value", "or", "integer", "grade", "scale", "applies", "a", "number", "of", "adjustment", "based", "on", "grade_item", "variables", "and", "returns", "the", "result", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L806-L866
220,418
moodle/moodle
lib/grade/grade_item.php
grade_item.rescale_grades_keep_percentage
public function rescale_grades_keep_percentage($oldgrademin, $oldgrademax, $newgrademin, $newgrademax, $source = null) { global $DB; if (empty($this->id)) { return false; } if ($oldgrademax <= $oldgrademin) { // Grades cannot be scaled. return false; } $scale = ($newgrademax - $newgrademin) / ($oldgrademax - $oldgrademin); if (($newgrademax - $newgrademin) <= 1) { // We would lose too much precision, lets bail. return false; } $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id)); foreach ($rs as $graderecord) { // For each record, create an object to work on. $grade = new grade_grade($graderecord, false); // Set this object in the item so it doesn't re-fetch it. $grade->grade_item = $this; if (!$this->is_category_item() || ($this->is_category_item() && $grade->is_overridden())) { // Updating the raw grade automatically updates the min/max. if ($this->is_raw_used()) { $rawgrade = (($grade->rawgrade - $oldgrademin) * $scale) + $newgrademin; $this->update_raw_grade(false, $rawgrade, $source, false, FORMAT_MOODLE, null, null, null, $grade); } else { $finalgrade = (($grade->finalgrade - $oldgrademin) * $scale) + $newgrademin; $this->update_final_grade($grade->userid, $finalgrade, $source); } } } $rs->close(); // Mark this item for regrading. $this->force_regrading(); return true; }
php
public function rescale_grades_keep_percentage($oldgrademin, $oldgrademax, $newgrademin, $newgrademax, $source = null) { global $DB; if (empty($this->id)) { return false; } if ($oldgrademax <= $oldgrademin) { // Grades cannot be scaled. return false; } $scale = ($newgrademax - $newgrademin) / ($oldgrademax - $oldgrademin); if (($newgrademax - $newgrademin) <= 1) { // We would lose too much precision, lets bail. return false; } $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id)); foreach ($rs as $graderecord) { // For each record, create an object to work on. $grade = new grade_grade($graderecord, false); // Set this object in the item so it doesn't re-fetch it. $grade->grade_item = $this; if (!$this->is_category_item() || ($this->is_category_item() && $grade->is_overridden())) { // Updating the raw grade automatically updates the min/max. if ($this->is_raw_used()) { $rawgrade = (($grade->rawgrade - $oldgrademin) * $scale) + $newgrademin; $this->update_raw_grade(false, $rawgrade, $source, false, FORMAT_MOODLE, null, null, null, $grade); } else { $finalgrade = (($grade->finalgrade - $oldgrademin) * $scale) + $newgrademin; $this->update_final_grade($grade->userid, $finalgrade, $source); } } } $rs->close(); // Mark this item for regrading. $this->force_regrading(); return true; }
[ "public", "function", "rescale_grades_keep_percentage", "(", "$", "oldgrademin", ",", "$", "oldgrademax", ",", "$", "newgrademin", ",", "$", "newgrademax", ",", "$", "source", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "id", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "oldgrademax", "<=", "$", "oldgrademin", ")", "{", "// Grades cannot be scaled.", "return", "false", ";", "}", "$", "scale", "=", "(", "$", "newgrademax", "-", "$", "newgrademin", ")", "/", "(", "$", "oldgrademax", "-", "$", "oldgrademin", ")", ";", "if", "(", "(", "$", "newgrademax", "-", "$", "newgrademin", ")", "<=", "1", ")", "{", "// We would lose too much precision, lets bail.", "return", "false", ";", "}", "$", "rs", "=", "$", "DB", "->", "get_recordset", "(", "'grade_grades'", ",", "array", "(", "'itemid'", "=>", "$", "this", "->", "id", ")", ")", ";", "foreach", "(", "$", "rs", "as", "$", "graderecord", ")", "{", "// For each record, create an object to work on.", "$", "grade", "=", "new", "grade_grade", "(", "$", "graderecord", ",", "false", ")", ";", "// Set this object in the item so it doesn't re-fetch it.", "$", "grade", "->", "grade_item", "=", "$", "this", ";", "if", "(", "!", "$", "this", "->", "is_category_item", "(", ")", "||", "(", "$", "this", "->", "is_category_item", "(", ")", "&&", "$", "grade", "->", "is_overridden", "(", ")", ")", ")", "{", "// Updating the raw grade automatically updates the min/max.", "if", "(", "$", "this", "->", "is_raw_used", "(", ")", ")", "{", "$", "rawgrade", "=", "(", "(", "$", "grade", "->", "rawgrade", "-", "$", "oldgrademin", ")", "*", "$", "scale", ")", "+", "$", "newgrademin", ";", "$", "this", "->", "update_raw_grade", "(", "false", ",", "$", "rawgrade", ",", "$", "source", ",", "false", ",", "FORMAT_MOODLE", ",", "null", ",", "null", ",", "null", ",", "$", "grade", ")", ";", "}", "else", "{", "$", "finalgrade", "=", "(", "(", "$", "grade", "->", "finalgrade", "-", "$", "oldgrademin", ")", "*", "$", "scale", ")", "+", "$", "newgrademin", ";", "$", "this", "->", "update_final_grade", "(", "$", "grade", "->", "userid", ",", "$", "finalgrade", ",", "$", "source", ")", ";", "}", "}", "}", "$", "rs", "->", "close", "(", ")", ";", "// Mark this item for regrading.", "$", "this", "->", "force_regrading", "(", ")", ";", "return", "true", ";", "}" ]
Update the rawgrademax and rawgrademin for all grade_grades records for this item. Scale every rawgrade to maintain the percentage. This function should be called after the gradeitem has been updated to the new min and max values. @param float $oldgrademin The previous grade min value @param float $oldgrademax The previous grade max value @param float $newgrademin The new grade min value @param float $newgrademax The new grade max value @param string $source from where was the object inserted (mod/forum, manual, etc.) @return bool True on success
[ "Update", "the", "rawgrademax", "and", "rawgrademin", "for", "all", "grade_grades", "records", "for", "this", "item", ".", "Scale", "every", "rawgrade", "to", "maintain", "the", "percentage", ".", "This", "function", "should", "be", "called", "after", "the", "gradeitem", "has", "been", "updated", "to", "the", "new", "min", "and", "max", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L880-L922
220,419
moodle/moodle
lib/grade/grade_item.php
grade_item.force_regrading
public function force_regrading() { global $DB; $this->needsupdate = 1; //mark this item and course item only - categories and calculated items are always regraded $wheresql = "(itemtype='course' OR id=?) AND courseid=?"; $params = array($this->id, $this->courseid); $DB->set_field_select('grade_items', 'needsupdate', 1, $wheresql, $params); }
php
public function force_regrading() { global $DB; $this->needsupdate = 1; //mark this item and course item only - categories and calculated items are always regraded $wheresql = "(itemtype='course' OR id=?) AND courseid=?"; $params = array($this->id, $this->courseid); $DB->set_field_select('grade_items', 'needsupdate', 1, $wheresql, $params); }
[ "public", "function", "force_regrading", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "needsupdate", "=", "1", ";", "//mark this item and course item only - categories and calculated items are always regraded", "$", "wheresql", "=", "\"(itemtype='course' OR id=?) AND courseid=?\"", ";", "$", "params", "=", "array", "(", "$", "this", "->", "id", ",", "$", "this", "->", "courseid", ")", ";", "$", "DB", "->", "set_field_select", "(", "'grade_items'", ",", "'needsupdate'", ",", "1", ",", "$", "wheresql", ",", "$", "params", ")", ";", "}" ]
Sets this grade_item's needsupdate to true. Also marks the course item as needing update. @return void
[ "Sets", "this", "grade_item", "s", "needsupdate", "to", "true", ".", "Also", "marks", "the", "course", "item", "as", "needing", "update", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L929-L936
220,420
moodle/moodle
lib/grade/grade_item.php
grade_item.load_scale
public function load_scale() { if ($this->gradetype != GRADE_TYPE_SCALE) { $this->scaleid = null; } if (!empty($this->scaleid)) { //do not load scale if already present if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id'=>$this->scaleid)); if (!$this->scale) { debugging('Incorrect scale id: '.$this->scaleid); $this->scale = null; return null; } $this->scale->load_items(); } // Until scales are uniformly set to min=0 max=count(scaleitems)-1 throughout Moodle, we // stay with the current min=1 max=count(scaleitems) $this->grademax = count($this->scale->scale_items); $this->grademin = 1; } else { $this->scale = null; } return $this->scale; }
php
public function load_scale() { if ($this->gradetype != GRADE_TYPE_SCALE) { $this->scaleid = null; } if (!empty($this->scaleid)) { //do not load scale if already present if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id'=>$this->scaleid)); if (!$this->scale) { debugging('Incorrect scale id: '.$this->scaleid); $this->scale = null; return null; } $this->scale->load_items(); } // Until scales are uniformly set to min=0 max=count(scaleitems)-1 throughout Moodle, we // stay with the current min=1 max=count(scaleitems) $this->grademax = count($this->scale->scale_items); $this->grademin = 1; } else { $this->scale = null; } return $this->scale; }
[ "public", "function", "load_scale", "(", ")", "{", "if", "(", "$", "this", "->", "gradetype", "!=", "GRADE_TYPE_SCALE", ")", "{", "$", "this", "->", "scaleid", "=", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "scaleid", ")", ")", "{", "//do not load scale if already present", "if", "(", "empty", "(", "$", "this", "->", "scale", "->", "id", ")", "or", "$", "this", "->", "scale", "->", "id", "!=", "$", "this", "->", "scaleid", ")", "{", "$", "this", "->", "scale", "=", "grade_scale", "::", "fetch", "(", "array", "(", "'id'", "=>", "$", "this", "->", "scaleid", ")", ")", ";", "if", "(", "!", "$", "this", "->", "scale", ")", "{", "debugging", "(", "'Incorrect scale id: '", ".", "$", "this", "->", "scaleid", ")", ";", "$", "this", "->", "scale", "=", "null", ";", "return", "null", ";", "}", "$", "this", "->", "scale", "->", "load_items", "(", ")", ";", "}", "// Until scales are uniformly set to min=0 max=count(scaleitems)-1 throughout Moodle, we", "// stay with the current min=1 max=count(scaleitems)", "$", "this", "->", "grademax", "=", "count", "(", "$", "this", "->", "scale", "->", "scale_items", ")", ";", "$", "this", "->", "grademin", "=", "1", ";", "}", "else", "{", "$", "this", "->", "scale", "=", "null", ";", "}", "return", "$", "this", "->", "scale", ";", "}" ]
Instantiates a grade_scale object from the DB if this item's scaleid variable is set @return grade_scale Returns a grade_scale object or null if no scale used
[ "Instantiates", "a", "grade_scale", "object", "from", "the", "DB", "if", "this", "item", "s", "scaleid", "variable", "is", "set" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L943-L970
220,421
moodle/moodle
lib/grade/grade_item.php
grade_item.load_outcome
public function load_outcome() { if (!empty($this->outcomeid)) { $this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid)); } return $this->outcome; }
php
public function load_outcome() { if (!empty($this->outcomeid)) { $this->outcome = grade_outcome::fetch(array('id'=>$this->outcomeid)); } return $this->outcome; }
[ "public", "function", "load_outcome", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "outcomeid", ")", ")", "{", "$", "this", "->", "outcome", "=", "grade_outcome", "::", "fetch", "(", "array", "(", "'id'", "=>", "$", "this", "->", "outcomeid", ")", ")", ";", "}", "return", "$", "this", "->", "outcome", ";", "}" ]
Instantiates a grade_outcome object from the DB if this item's outcomeid variable is set @return grade_outcome This grade item's associated grade_outcome or null
[ "Instantiates", "a", "grade_outcome", "object", "from", "the", "DB", "if", "this", "item", "s", "outcomeid", "variable", "is", "set" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L977-L982
220,422
moodle/moodle
lib/grade/grade_item.php
grade_item.get_item_category
public function get_item_category() { if (!$this->is_course_item() and !$this->is_category_item()) { return false; } return grade_category::fetch(array('id'=>$this->iteminstance)); }
php
public function get_item_category() { if (!$this->is_course_item() and !$this->is_category_item()) { return false; } return grade_category::fetch(array('id'=>$this->iteminstance)); }
[ "public", "function", "get_item_category", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_course_item", "(", ")", "and", "!", "$", "this", "->", "is_category_item", "(", ")", ")", "{", "return", "false", ";", "}", "return", "grade_category", "::", "fetch", "(", "array", "(", "'id'", "=>", "$", "this", "->", "iteminstance", ")", ")", ";", "}" ]
Returns the grade_category for a grade category grade item @return grade_category|bool Returns a grade_category instance if applicable or false otherwise
[ "Returns", "the", "grade_category", "for", "a", "grade", "category", "grade", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1017-L1022
220,423
moodle/moodle
lib/grade/grade_item.php
grade_item.is_overridable_item
public function is_overridable_item() { if ($this->is_course_item() or $this->is_category_item()) { $overridable = (bool) get_config('moodle', 'grade_overridecat'); } else { $overridable = false; } return !$this->is_outcome_item() and ($this->is_external_item() or $this->is_calculated() or $overridable); }
php
public function is_overridable_item() { if ($this->is_course_item() or $this->is_category_item()) { $overridable = (bool) get_config('moodle', 'grade_overridecat'); } else { $overridable = false; } return !$this->is_outcome_item() and ($this->is_external_item() or $this->is_calculated() or $overridable); }
[ "public", "function", "is_overridable_item", "(", ")", "{", "if", "(", "$", "this", "->", "is_course_item", "(", ")", "or", "$", "this", "->", "is_category_item", "(", ")", ")", "{", "$", "overridable", "=", "(", "bool", ")", "get_config", "(", "'moodle'", ",", "'grade_overridecat'", ")", ";", "}", "else", "{", "$", "overridable", "=", "false", ";", "}", "return", "!", "$", "this", "->", "is_outcome_item", "(", ")", "and", "(", "$", "this", "->", "is_external_item", "(", ")", "or", "$", "this", "->", "is_calculated", "(", ")", "or", "$", "overridable", ")", ";", "}" ]
Is the grade item overridable @return bool
[ "Is", "the", "grade", "item", "overridable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1087-L1095
220,424
moodle/moodle
lib/grade/grade_item.php
grade_item.fetch_course_item
public static function fetch_course_item($courseid) { if ($course_item = grade_item::fetch(array('courseid'=>$courseid, 'itemtype'=>'course'))) { return $course_item; } // first get category - it creates the associated grade item $course_category = grade_category::fetch_course_category($courseid); return $course_category->get_grade_item(); }
php
public static function fetch_course_item($courseid) { if ($course_item = grade_item::fetch(array('courseid'=>$courseid, 'itemtype'=>'course'))) { return $course_item; } // first get category - it creates the associated grade item $course_category = grade_category::fetch_course_category($courseid); return $course_category->get_grade_item(); }
[ "public", "static", "function", "fetch_course_item", "(", "$", "courseid", ")", "{", "if", "(", "$", "course_item", "=", "grade_item", "::", "fetch", "(", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'itemtype'", "=>", "'course'", ")", ")", ")", "{", "return", "$", "course_item", ";", "}", "// first get category - it creates the associated grade item", "$", "course_category", "=", "grade_category", "::", "fetch_course_category", "(", "$", "courseid", ")", ";", "return", "$", "course_category", "->", "get_grade_item", "(", ")", ";", "}" ]
Returns the grade item associated with the course @param int $courseid @return grade_item Course level grade item object
[ "Returns", "the", "grade", "item", "associated", "with", "the", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1131-L1139
220,425
moodle/moodle
lib/grade/grade_item.php
grade_item.is_calculated
public function is_calculated() { if (empty($this->calculation)) { return false; } /* * The main reason why we use the ##gixxx## instead of [[idnumber]] is speed of depends_on(), * we would have to fetch all course grade items to find out the ids. * Also if user changes the idnumber the formula does not need to be updated. */ // first detect if we need to change calculation formula from [[idnumber]] to ##giXXX## (after backup, etc.) if (!$this->calculation_normalized and strpos($this->calculation, '[[') !== false) { $this->set_calculation($this->calculation); } return !empty($this->calculation); }
php
public function is_calculated() { if (empty($this->calculation)) { return false; } /* * The main reason why we use the ##gixxx## instead of [[idnumber]] is speed of depends_on(), * we would have to fetch all course grade items to find out the ids. * Also if user changes the idnumber the formula does not need to be updated. */ // first detect if we need to change calculation formula from [[idnumber]] to ##giXXX## (after backup, etc.) if (!$this->calculation_normalized and strpos($this->calculation, '[[') !== false) { $this->set_calculation($this->calculation); } return !empty($this->calculation); }
[ "public", "function", "is_calculated", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "calculation", ")", ")", "{", "return", "false", ";", "}", "/*\n * The main reason why we use the ##gixxx## instead of [[idnumber]] is speed of depends_on(),\n * we would have to fetch all course grade items to find out the ids.\n * Also if user changes the idnumber the formula does not need to be updated.\n */", "// first detect if we need to change calculation formula from [[idnumber]] to ##giXXX## (after backup, etc.)", "if", "(", "!", "$", "this", "->", "calculation_normalized", "and", "strpos", "(", "$", "this", "->", "calculation", ",", "'[['", ")", "!==", "false", ")", "{", "$", "this", "->", "set_calculation", "(", "$", "this", "->", "calculation", ")", ";", "}", "return", "!", "empty", "(", "$", "this", "->", "calculation", ")", ";", "}" ]
Checks if grade calculated. Returns this object's calculation. @return bool true if grade item calculated.
[ "Checks", "if", "grade", "calculated", ".", "Returns", "this", "object", "s", "calculation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1155-L1172
220,426
moodle/moodle
lib/grade/grade_item.php
grade_item.get_calculation
public function get_calculation() { if ($this->is_calculated()) { return grade_item::denormalize_formula($this->calculation, $this->courseid); } else { return NULL; } }
php
public function get_calculation() { if ($this->is_calculated()) { return grade_item::denormalize_formula($this->calculation, $this->courseid); } else { return NULL; } }
[ "public", "function", "get_calculation", "(", ")", "{", "if", "(", "$", "this", "->", "is_calculated", "(", ")", ")", "{", "return", "grade_item", "::", "denormalize_formula", "(", "$", "this", "->", "calculation", ",", "$", "this", "->", "courseid", ")", ";", "}", "else", "{", "return", "NULL", ";", "}", "}" ]
Returns calculation string if grade calculated. @return string Returns the grade item's calculation if calculation is used, null if not
[ "Returns", "calculation", "string", "if", "grade", "calculated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1179-L1186
220,427
moodle/moodle
lib/grade/grade_item.php
grade_item.set_sortorder
public function set_sortorder($sortorder) { if ($this->sortorder == $sortorder) { return; } $this->sortorder = $sortorder; $this->update(); }
php
public function set_sortorder($sortorder) { if ($this->sortorder == $sortorder) { return; } $this->sortorder = $sortorder; $this->update(); }
[ "public", "function", "set_sortorder", "(", "$", "sortorder", ")", "{", "if", "(", "$", "this", "->", "sortorder", "==", "$", "sortorder", ")", "{", "return", ";", "}", "$", "this", "->", "sortorder", "=", "$", "sortorder", ";", "$", "this", "->", "update", "(", ")", ";", "}" ]
Sets the sortorder of this grade_item. This method is also available in grade_category, for cases where the object type is not know. @param int $sortorder
[ "Sets", "the", "sortorder", "of", "this", "grade_item", ".", "This", "method", "is", "also", "available", "in", "grade_category", "for", "cases", "where", "the", "object", "type", "is", "not", "know", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1338-L1344
220,428
moodle/moodle
lib/grade/grade_item.php
grade_item.get_name
public function get_name($fulltotal=false) { global $CFG; require_once($CFG->dirroot . '/course/lib.php'); if (strval($this->itemname) !== '') { // MDL-10557 // Make it obvious to users if the course module to which this grade item relates, is currently being removed. $deletionpending = course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance); $deletionnotice = get_string('gradesmoduledeletionprefix', 'grades'); $options = ['context' => context_course::instance($this->courseid)]; return $deletionpending ? format_string($deletionnotice . ' ' . $this->itemname, true, $options) : format_string($this->itemname, true, $options); } else if ($this->is_course_item()) { return get_string('coursetotal', 'grades'); } else if ($this->is_category_item()) { if ($fulltotal) { $category = $this->load_parent_category(); $a = new stdClass(); $a->category = $category->get_name(); return get_string('categorytotalfull', 'grades', $a); } else { return get_string('categorytotal', 'grades'); } } else { return get_string('grade'); } }
php
public function get_name($fulltotal=false) { global $CFG; require_once($CFG->dirroot . '/course/lib.php'); if (strval($this->itemname) !== '') { // MDL-10557 // Make it obvious to users if the course module to which this grade item relates, is currently being removed. $deletionpending = course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance); $deletionnotice = get_string('gradesmoduledeletionprefix', 'grades'); $options = ['context' => context_course::instance($this->courseid)]; return $deletionpending ? format_string($deletionnotice . ' ' . $this->itemname, true, $options) : format_string($this->itemname, true, $options); } else if ($this->is_course_item()) { return get_string('coursetotal', 'grades'); } else if ($this->is_category_item()) { if ($fulltotal) { $category = $this->load_parent_category(); $a = new stdClass(); $a->category = $category->get_name(); return get_string('categorytotalfull', 'grades', $a); } else { return get_string('categorytotal', 'grades'); } } else { return get_string('grade'); } }
[ "public", "function", "get_name", "(", "$", "fulltotal", "=", "false", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/course/lib.php'", ")", ";", "if", "(", "strval", "(", "$", "this", "->", "itemname", ")", "!==", "''", ")", "{", "// MDL-10557", "// Make it obvious to users if the course module to which this grade item relates, is currently being removed.", "$", "deletionpending", "=", "course_module_instance_pending_deletion", "(", "$", "this", "->", "courseid", ",", "$", "this", "->", "itemmodule", ",", "$", "this", "->", "iteminstance", ")", ";", "$", "deletionnotice", "=", "get_string", "(", "'gradesmoduledeletionprefix'", ",", "'grades'", ")", ";", "$", "options", "=", "[", "'context'", "=>", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", "]", ";", "return", "$", "deletionpending", "?", "format_string", "(", "$", "deletionnotice", ".", "' '", ".", "$", "this", "->", "itemname", ",", "true", ",", "$", "options", ")", ":", "format_string", "(", "$", "this", "->", "itemname", ",", "true", ",", "$", "options", ")", ";", "}", "else", "if", "(", "$", "this", "->", "is_course_item", "(", ")", ")", "{", "return", "get_string", "(", "'coursetotal'", ",", "'grades'", ")", ";", "}", "else", "if", "(", "$", "this", "->", "is_category_item", "(", ")", ")", "{", "if", "(", "$", "fulltotal", ")", "{", "$", "category", "=", "$", "this", "->", "load_parent_category", "(", ")", ";", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "category", "=", "$", "category", "->", "get_name", "(", ")", ";", "return", "get_string", "(", "'categorytotalfull'", ",", "'grades'", ",", "$", "a", ")", ";", "}", "else", "{", "return", "get_string", "(", "'categorytotal'", ",", "'grades'", ")", ";", "}", "}", "else", "{", "return", "get_string", "(", "'grade'", ")", ";", "}", "}" ]
Returns the most descriptive field for this object. Determines what type of grade item it is then returns the appropriate string @param bool $fulltotal If the item is a category total, returns $categoryname."total" instead of "Category total" or "Course total" @return string name
[ "Returns", "the", "most", "descriptive", "field", "for", "this", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1408-L1439
220,429
moodle/moodle
lib/grade/grade_item.php
grade_item.set_parent
public function set_parent($parentid, $updateaggregationfields = true) { if ($this->is_course_item() or $this->is_category_item()) { print_error('cannotsetparentforcatoritem'); } if ($this->categoryid == $parentid) { return true; } // find parent and check course id if (!$parent_category = grade_category::fetch(array('id'=>$parentid, 'courseid'=>$this->courseid))) { return false; } $currentparent = $this->load_parent_category(); if ($updateaggregationfields) { $this->set_aggregation_fields_for_aggregation($currentparent->aggregation, $parent_category->aggregation); } $this->force_regrading(); // set new parent $this->categoryid = $parent_category->id; $this->parent_category =& $parent_category; return $this->update(); }
php
public function set_parent($parentid, $updateaggregationfields = true) { if ($this->is_course_item() or $this->is_category_item()) { print_error('cannotsetparentforcatoritem'); } if ($this->categoryid == $parentid) { return true; } // find parent and check course id if (!$parent_category = grade_category::fetch(array('id'=>$parentid, 'courseid'=>$this->courseid))) { return false; } $currentparent = $this->load_parent_category(); if ($updateaggregationfields) { $this->set_aggregation_fields_for_aggregation($currentparent->aggregation, $parent_category->aggregation); } $this->force_regrading(); // set new parent $this->categoryid = $parent_category->id; $this->parent_category =& $parent_category; return $this->update(); }
[ "public", "function", "set_parent", "(", "$", "parentid", ",", "$", "updateaggregationfields", "=", "true", ")", "{", "if", "(", "$", "this", "->", "is_course_item", "(", ")", "or", "$", "this", "->", "is_category_item", "(", ")", ")", "{", "print_error", "(", "'cannotsetparentforcatoritem'", ")", ";", "}", "if", "(", "$", "this", "->", "categoryid", "==", "$", "parentid", ")", "{", "return", "true", ";", "}", "// find parent and check course id", "if", "(", "!", "$", "parent_category", "=", "grade_category", "::", "fetch", "(", "array", "(", "'id'", "=>", "$", "parentid", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ")", ")", "{", "return", "false", ";", "}", "$", "currentparent", "=", "$", "this", "->", "load_parent_category", "(", ")", ";", "if", "(", "$", "updateaggregationfields", ")", "{", "$", "this", "->", "set_aggregation_fields_for_aggregation", "(", "$", "currentparent", "->", "aggregation", ",", "$", "parent_category", "->", "aggregation", ")", ";", "}", "$", "this", "->", "force_regrading", "(", ")", ";", "// set new parent", "$", "this", "->", "categoryid", "=", "$", "parent_category", "->", "id", ";", "$", "this", "->", "parent_category", "=", "&", "$", "parent_category", ";", "return", "$", "this", "->", "update", "(", ")", ";", "}" ]
Sets this item's categoryid. A generic method shared by objects that have a parent id of some kind. @param int $parentid The ID of the new parent @param bool $updateaggregationfields Whether or not to convert the aggregation fields when switching between category. Set this to false when the aggregation fields have been updated in prevision of the new category, typically when the item is freshly created. @return bool True if success
[ "Sets", "this", "item", "s", "categoryid", ".", "A", "generic", "method", "shared", "by", "objects", "that", "have", "a", "parent", "id", "of", "some", "kind", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1463-L1490
220,430
moodle/moodle
lib/grade/grade_item.php
grade_item.set_aggregation_fields_for_aggregation
public function set_aggregation_fields_for_aggregation($from, $to) { $defaults = grade_category::get_default_aggregation_coefficient_values($to); $origaggregationcoef = $this->aggregationcoef; $origaggregationcoef2 = $this->aggregationcoef2; $origweighoverride = $this->weightoverride; if ($from == GRADE_AGGREGATE_SUM && $to == GRADE_AGGREGATE_SUM && $this->weightoverride) { // Do nothing. We are switching from SUM to SUM and the weight is overriden, // a teacher would not expect any change in this situation. } else if ($from == GRADE_AGGREGATE_WEIGHTED_MEAN && $to == GRADE_AGGREGATE_WEIGHTED_MEAN) { // Do nothing. The weights can be kept in this case. } else if (in_array($from, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2)) && in_array($to, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2))) { // Reset all but the the extra credit field. $this->aggregationcoef2 = $defaults['aggregationcoef2']; $this->weightoverride = $defaults['weightoverride']; if ($to != GRADE_AGGREGATE_EXTRACREDIT_MEAN) { // Normalise extra credit, except for 'Mean with extra credit' which supports higher values than 1. $this->aggregationcoef = min(1, $this->aggregationcoef); } } else { // Reset all. $this->aggregationcoef = $defaults['aggregationcoef']; $this->aggregationcoef2 = $defaults['aggregationcoef2']; $this->weightoverride = $defaults['weightoverride']; } $acoefdiff = grade_floats_different($origaggregationcoef, $this->aggregationcoef); $acoefdiff2 = grade_floats_different($origaggregationcoef2, $this->aggregationcoef2); $weightoverride = grade_floats_different($origweighoverride, $this->weightoverride); return $acoefdiff || $acoefdiff2 || $weightoverride; }
php
public function set_aggregation_fields_for_aggregation($from, $to) { $defaults = grade_category::get_default_aggregation_coefficient_values($to); $origaggregationcoef = $this->aggregationcoef; $origaggregationcoef2 = $this->aggregationcoef2; $origweighoverride = $this->weightoverride; if ($from == GRADE_AGGREGATE_SUM && $to == GRADE_AGGREGATE_SUM && $this->weightoverride) { // Do nothing. We are switching from SUM to SUM and the weight is overriden, // a teacher would not expect any change in this situation. } else if ($from == GRADE_AGGREGATE_WEIGHTED_MEAN && $to == GRADE_AGGREGATE_WEIGHTED_MEAN) { // Do nothing. The weights can be kept in this case. } else if (in_array($from, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2)) && in_array($to, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2))) { // Reset all but the the extra credit field. $this->aggregationcoef2 = $defaults['aggregationcoef2']; $this->weightoverride = $defaults['weightoverride']; if ($to != GRADE_AGGREGATE_EXTRACREDIT_MEAN) { // Normalise extra credit, except for 'Mean with extra credit' which supports higher values than 1. $this->aggregationcoef = min(1, $this->aggregationcoef); } } else { // Reset all. $this->aggregationcoef = $defaults['aggregationcoef']; $this->aggregationcoef2 = $defaults['aggregationcoef2']; $this->weightoverride = $defaults['weightoverride']; } $acoefdiff = grade_floats_different($origaggregationcoef, $this->aggregationcoef); $acoefdiff2 = grade_floats_different($origaggregationcoef2, $this->aggregationcoef2); $weightoverride = grade_floats_different($origweighoverride, $this->weightoverride); return $acoefdiff || $acoefdiff2 || $weightoverride; }
[ "public", "function", "set_aggregation_fields_for_aggregation", "(", "$", "from", ",", "$", "to", ")", "{", "$", "defaults", "=", "grade_category", "::", "get_default_aggregation_coefficient_values", "(", "$", "to", ")", ";", "$", "origaggregationcoef", "=", "$", "this", "->", "aggregationcoef", ";", "$", "origaggregationcoef2", "=", "$", "this", "->", "aggregationcoef2", ";", "$", "origweighoverride", "=", "$", "this", "->", "weightoverride", ";", "if", "(", "$", "from", "==", "GRADE_AGGREGATE_SUM", "&&", "$", "to", "==", "GRADE_AGGREGATE_SUM", "&&", "$", "this", "->", "weightoverride", ")", "{", "// Do nothing. We are switching from SUM to SUM and the weight is overriden,", "// a teacher would not expect any change in this situation.", "}", "else", "if", "(", "$", "from", "==", "GRADE_AGGREGATE_WEIGHTED_MEAN", "&&", "$", "to", "==", "GRADE_AGGREGATE_WEIGHTED_MEAN", ")", "{", "// Do nothing. The weights can be kept in this case.", "}", "else", "if", "(", "in_array", "(", "$", "from", ",", "array", "(", "GRADE_AGGREGATE_SUM", ",", "GRADE_AGGREGATE_EXTRACREDIT_MEAN", ",", "GRADE_AGGREGATE_WEIGHTED_MEAN2", ")", ")", "&&", "in_array", "(", "$", "to", ",", "array", "(", "GRADE_AGGREGATE_SUM", ",", "GRADE_AGGREGATE_EXTRACREDIT_MEAN", ",", "GRADE_AGGREGATE_WEIGHTED_MEAN2", ")", ")", ")", "{", "// Reset all but the the extra credit field.", "$", "this", "->", "aggregationcoef2", "=", "$", "defaults", "[", "'aggregationcoef2'", "]", ";", "$", "this", "->", "weightoverride", "=", "$", "defaults", "[", "'weightoverride'", "]", ";", "if", "(", "$", "to", "!=", "GRADE_AGGREGATE_EXTRACREDIT_MEAN", ")", "{", "// Normalise extra credit, except for 'Mean with extra credit' which supports higher values than 1.", "$", "this", "->", "aggregationcoef", "=", "min", "(", "1", ",", "$", "this", "->", "aggregationcoef", ")", ";", "}", "}", "else", "{", "// Reset all.", "$", "this", "->", "aggregationcoef", "=", "$", "defaults", "[", "'aggregationcoef'", "]", ";", "$", "this", "->", "aggregationcoef2", "=", "$", "defaults", "[", "'aggregationcoef2'", "]", ";", "$", "this", "->", "weightoverride", "=", "$", "defaults", "[", "'weightoverride'", "]", ";", "}", "$", "acoefdiff", "=", "grade_floats_different", "(", "$", "origaggregationcoef", ",", "$", "this", "->", "aggregationcoef", ")", ";", "$", "acoefdiff2", "=", "grade_floats_different", "(", "$", "origaggregationcoef2", ",", "$", "this", "->", "aggregationcoef2", ")", ";", "$", "weightoverride", "=", "grade_floats_different", "(", "$", "origweighoverride", ",", "$", "this", "->", "weightoverride", ")", ";", "return", "$", "acoefdiff", "||", "$", "acoefdiff2", "||", "$", "weightoverride", ";", "}" ]
Update the aggregation fields when the aggregation changed. This method should always be called when the aggregation has changed, but also when the item was moved to another category, even it if uses the same aggregation method. Some values such as the weight only make sense within a category, once moved the values should be reset to let the user adapt them accordingly. Note that this method does not save the grade item. {@link grade_item::update()} has to be called manually after using this method. @param int $from Aggregation method constant value. @param int $to Aggregation method constant value. @return boolean True when at least one field was changed, false otherwise
[ "Update", "the", "aggregation", "fields", "when", "the", "aggregation", "changed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1508-L1545
220,431
moodle/moodle
lib/grade/grade_item.php
grade_item.bounded_grade
public function bounded_grade($gradevalue) { global $CFG; if (is_null($gradevalue)) { return null; } if ($this->gradetype == GRADE_TYPE_SCALE) { // no >100% grades hack for scale grades! // 1.5 is rounded to 2 ;-) return (int)bounded_number($this->grademin, round($gradevalue+0.00001), $this->grademax); } $grademax = $this->grademax; // NOTE: if you change this value you must manually reset the needsupdate flag in all grade items $maxcoef = isset($CFG->gradeoverhundredprocentmax) ? $CFG->gradeoverhundredprocentmax : 10; // 1000% max by default if (!empty($CFG->unlimitedgrades)) { // NOTE: if you change this value you must manually reset the needsupdate flag in all grade items $grademax = $grademax * $maxcoef; } else if ($this->is_category_item() or $this->is_course_item()) { $category = $this->load_item_category(); if ($category->aggregation >= 100) { // grade >100% hack $grademax = $grademax * $maxcoef; } } return (float)bounded_number($this->grademin, $gradevalue, $grademax); }
php
public function bounded_grade($gradevalue) { global $CFG; if (is_null($gradevalue)) { return null; } if ($this->gradetype == GRADE_TYPE_SCALE) { // no >100% grades hack for scale grades! // 1.5 is rounded to 2 ;-) return (int)bounded_number($this->grademin, round($gradevalue+0.00001), $this->grademax); } $grademax = $this->grademax; // NOTE: if you change this value you must manually reset the needsupdate flag in all grade items $maxcoef = isset($CFG->gradeoverhundredprocentmax) ? $CFG->gradeoverhundredprocentmax : 10; // 1000% max by default if (!empty($CFG->unlimitedgrades)) { // NOTE: if you change this value you must manually reset the needsupdate flag in all grade items $grademax = $grademax * $maxcoef; } else if ($this->is_category_item() or $this->is_course_item()) { $category = $this->load_item_category(); if ($category->aggregation >= 100) { // grade >100% hack $grademax = $grademax * $maxcoef; } } return (float)bounded_number($this->grademin, $gradevalue, $grademax); }
[ "public", "function", "bounded_grade", "(", "$", "gradevalue", ")", "{", "global", "$", "CFG", ";", "if", "(", "is_null", "(", "$", "gradevalue", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "gradetype", "==", "GRADE_TYPE_SCALE", ")", "{", "// no >100% grades hack for scale grades!", "// 1.5 is rounded to 2 ;-)", "return", "(", "int", ")", "bounded_number", "(", "$", "this", "->", "grademin", ",", "round", "(", "$", "gradevalue", "+", "0.00001", ")", ",", "$", "this", "->", "grademax", ")", ";", "}", "$", "grademax", "=", "$", "this", "->", "grademax", ";", "// NOTE: if you change this value you must manually reset the needsupdate flag in all grade items", "$", "maxcoef", "=", "isset", "(", "$", "CFG", "->", "gradeoverhundredprocentmax", ")", "?", "$", "CFG", "->", "gradeoverhundredprocentmax", ":", "10", ";", "// 1000% max by default", "if", "(", "!", "empty", "(", "$", "CFG", "->", "unlimitedgrades", ")", ")", "{", "// NOTE: if you change this value you must manually reset the needsupdate flag in all grade items", "$", "grademax", "=", "$", "grademax", "*", "$", "maxcoef", ";", "}", "else", "if", "(", "$", "this", "->", "is_category_item", "(", ")", "or", "$", "this", "->", "is_course_item", "(", ")", ")", "{", "$", "category", "=", "$", "this", "->", "load_item_category", "(", ")", ";", "if", "(", "$", "category", "->", "aggregation", ">=", "100", ")", "{", "// grade >100% hack", "$", "grademax", "=", "$", "grademax", "*", "$", "maxcoef", ";", "}", "}", "return", "(", "float", ")", "bounded_number", "(", "$", "this", "->", "grademin", ",", "$", "gradevalue", ",", "$", "grademax", ")", ";", "}" ]
Makes sure value is a valid grade value. @param float $gradevalue @return mixed float or int fixed grade value
[ "Makes", "sure", "value", "is", "a", "valid", "grade", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1553-L1583
220,432
moodle/moodle
lib/grade/grade_item.php
grade_item.depends_on
public function depends_on($reset_cache=false) { global $CFG, $DB; if ($reset_cache) { $this->dependson_cache = null; } else if (isset($this->dependson_cache)) { return $this->dependson_cache; } if ($this->is_locked()) { // locked items do not need to be regraded $this->dependson_cache = array(); return $this->dependson_cache; } if ($this->is_calculated()) { if (preg_match_all('/##gi(\d+)##/', $this->calculation, $matches)) { $this->dependson_cache = array_unique($matches[1]); // remove duplicates return $this->dependson_cache; } else { $this->dependson_cache = array(); return $this->dependson_cache; } } else if ($grade_category = $this->load_item_category()) { $params = array(); //only items with numeric or scale values can be aggregated if ($this->gradetype != GRADE_TYPE_VALUE and $this->gradetype != GRADE_TYPE_SCALE) { $this->dependson_cache = array(); return $this->dependson_cache; } $grade_category->apply_forced_settings(); if (empty($CFG->enableoutcomes) or $grade_category->aggregateoutcomes) { $outcomes_sql = ""; } else { $outcomes_sql = "AND gi.outcomeid IS NULL"; } if (empty($CFG->grade_includescalesinaggregation)) { $gtypes = "gi.gradetype = ?"; $params[] = GRADE_TYPE_VALUE; } else { $gtypes = "(gi.gradetype = ? OR gi.gradetype = ?)"; $params[] = GRADE_TYPE_VALUE; $params[] = GRADE_TYPE_SCALE; } $params[] = $grade_category->id; $params[] = $this->courseid; $params[] = $grade_category->id; $params[] = $this->courseid; if (empty($CFG->grade_includescalesinaggregation)) { $params[] = GRADE_TYPE_VALUE; } else { $params[] = GRADE_TYPE_VALUE; $params[] = GRADE_TYPE_SCALE; } $sql = "SELECT gi.id FROM {grade_items} gi WHERE $gtypes AND gi.categoryid = ? AND gi.courseid = ? $outcomes_sql UNION SELECT gi.id FROM {grade_items} gi, {grade_categories} gc WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id AND gc.parent = ? AND gi.courseid = ? AND $gtypes $outcomes_sql"; if ($children = $DB->get_records_sql($sql, $params)) { $this->dependson_cache = array_keys($children); return $this->dependson_cache; } else { $this->dependson_cache = array(); return $this->dependson_cache; } } else { $this->dependson_cache = array(); return $this->dependson_cache; } }
php
public function depends_on($reset_cache=false) { global $CFG, $DB; if ($reset_cache) { $this->dependson_cache = null; } else if (isset($this->dependson_cache)) { return $this->dependson_cache; } if ($this->is_locked()) { // locked items do not need to be regraded $this->dependson_cache = array(); return $this->dependson_cache; } if ($this->is_calculated()) { if (preg_match_all('/##gi(\d+)##/', $this->calculation, $matches)) { $this->dependson_cache = array_unique($matches[1]); // remove duplicates return $this->dependson_cache; } else { $this->dependson_cache = array(); return $this->dependson_cache; } } else if ($grade_category = $this->load_item_category()) { $params = array(); //only items with numeric or scale values can be aggregated if ($this->gradetype != GRADE_TYPE_VALUE and $this->gradetype != GRADE_TYPE_SCALE) { $this->dependson_cache = array(); return $this->dependson_cache; } $grade_category->apply_forced_settings(); if (empty($CFG->enableoutcomes) or $grade_category->aggregateoutcomes) { $outcomes_sql = ""; } else { $outcomes_sql = "AND gi.outcomeid IS NULL"; } if (empty($CFG->grade_includescalesinaggregation)) { $gtypes = "gi.gradetype = ?"; $params[] = GRADE_TYPE_VALUE; } else { $gtypes = "(gi.gradetype = ? OR gi.gradetype = ?)"; $params[] = GRADE_TYPE_VALUE; $params[] = GRADE_TYPE_SCALE; } $params[] = $grade_category->id; $params[] = $this->courseid; $params[] = $grade_category->id; $params[] = $this->courseid; if (empty($CFG->grade_includescalesinaggregation)) { $params[] = GRADE_TYPE_VALUE; } else { $params[] = GRADE_TYPE_VALUE; $params[] = GRADE_TYPE_SCALE; } $sql = "SELECT gi.id FROM {grade_items} gi WHERE $gtypes AND gi.categoryid = ? AND gi.courseid = ? $outcomes_sql UNION SELECT gi.id FROM {grade_items} gi, {grade_categories} gc WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id AND gc.parent = ? AND gi.courseid = ? AND $gtypes $outcomes_sql"; if ($children = $DB->get_records_sql($sql, $params)) { $this->dependson_cache = array_keys($children); return $this->dependson_cache; } else { $this->dependson_cache = array(); return $this->dependson_cache; } } else { $this->dependson_cache = array(); return $this->dependson_cache; } }
[ "public", "function", "depends_on", "(", "$", "reset_cache", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "if", "(", "$", "reset_cache", ")", "{", "$", "this", "->", "dependson_cache", "=", "null", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "dependson_cache", ")", ")", "{", "return", "$", "this", "->", "dependson_cache", ";", "}", "if", "(", "$", "this", "->", "is_locked", "(", ")", ")", "{", "// locked items do not need to be regraded", "$", "this", "->", "dependson_cache", "=", "array", "(", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "if", "(", "$", "this", "->", "is_calculated", "(", ")", ")", "{", "if", "(", "preg_match_all", "(", "'/##gi(\\d+)##/'", ",", "$", "this", "->", "calculation", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "dependson_cache", "=", "array_unique", "(", "$", "matches", "[", "1", "]", ")", ";", "// remove duplicates", "return", "$", "this", "->", "dependson_cache", ";", "}", "else", "{", "$", "this", "->", "dependson_cache", "=", "array", "(", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "}", "else", "if", "(", "$", "grade_category", "=", "$", "this", "->", "load_item_category", "(", ")", ")", "{", "$", "params", "=", "array", "(", ")", ";", "//only items with numeric or scale values can be aggregated", "if", "(", "$", "this", "->", "gradetype", "!=", "GRADE_TYPE_VALUE", "and", "$", "this", "->", "gradetype", "!=", "GRADE_TYPE_SCALE", ")", "{", "$", "this", "->", "dependson_cache", "=", "array", "(", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "$", "grade_category", "->", "apply_forced_settings", "(", ")", ";", "if", "(", "empty", "(", "$", "CFG", "->", "enableoutcomes", ")", "or", "$", "grade_category", "->", "aggregateoutcomes", ")", "{", "$", "outcomes_sql", "=", "\"\"", ";", "}", "else", "{", "$", "outcomes_sql", "=", "\"AND gi.outcomeid IS NULL\"", ";", "}", "if", "(", "empty", "(", "$", "CFG", "->", "grade_includescalesinaggregation", ")", ")", "{", "$", "gtypes", "=", "\"gi.gradetype = ?\"", ";", "$", "params", "[", "]", "=", "GRADE_TYPE_VALUE", ";", "}", "else", "{", "$", "gtypes", "=", "\"(gi.gradetype = ? OR gi.gradetype = ?)\"", ";", "$", "params", "[", "]", "=", "GRADE_TYPE_VALUE", ";", "$", "params", "[", "]", "=", "GRADE_TYPE_SCALE", ";", "}", "$", "params", "[", "]", "=", "$", "grade_category", "->", "id", ";", "$", "params", "[", "]", "=", "$", "this", "->", "courseid", ";", "$", "params", "[", "]", "=", "$", "grade_category", "->", "id", ";", "$", "params", "[", "]", "=", "$", "this", "->", "courseid", ";", "if", "(", "empty", "(", "$", "CFG", "->", "grade_includescalesinaggregation", ")", ")", "{", "$", "params", "[", "]", "=", "GRADE_TYPE_VALUE", ";", "}", "else", "{", "$", "params", "[", "]", "=", "GRADE_TYPE_VALUE", ";", "$", "params", "[", "]", "=", "GRADE_TYPE_SCALE", ";", "}", "$", "sql", "=", "\"SELECT gi.id\n FROM {grade_items} gi\n WHERE $gtypes\n AND gi.categoryid = ?\n AND gi.courseid = ?\n $outcomes_sql\n UNION\n\n SELECT gi.id\n FROM {grade_items} gi, {grade_categories} gc\n WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id\n AND gc.parent = ?\n AND gi.courseid = ?\n AND $gtypes\n $outcomes_sql\"", ";", "if", "(", "$", "children", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "$", "this", "->", "dependson_cache", "=", "array_keys", "(", "$", "children", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "else", "{", "$", "this", "->", "dependson_cache", "=", "array", "(", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "}", "else", "{", "$", "this", "->", "dependson_cache", "=", "array", "(", ")", ";", "return", "$", "this", "->", "dependson_cache", ";", "}", "}" ]
Finds out on which other items does this depend directly when doing calculation or category aggregation @param bool $reset_cache @return array of grade_item IDs this one depends on
[ "Finds", "out", "on", "which", "other", "items", "does", "this", "depend", "directly", "when", "doing", "calculation", "or", "category", "aggregation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1591-L1679
220,433
moodle/moodle
lib/grade/grade_item.php
grade_item.refresh_grades
public function refresh_grades($userid=0) { global $DB; if ($this->itemtype == 'mod') { if ($this->is_outcome_item()) { //nothing to do return true; } if (!$activity = $DB->get_record($this->itemmodule, array('id' => $this->iteminstance))) { debugging("Can not find $this->itemmodule activity with id $this->iteminstance"); return false; } if (!$cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) { debugging('Can not find course module'); return false; } $activity->modname = $this->itemmodule; $activity->cmidnumber = $cm->idnumber; return grade_update_mod_grades($activity, $userid); } return true; }
php
public function refresh_grades($userid=0) { global $DB; if ($this->itemtype == 'mod') { if ($this->is_outcome_item()) { //nothing to do return true; } if (!$activity = $DB->get_record($this->itemmodule, array('id' => $this->iteminstance))) { debugging("Can not find $this->itemmodule activity with id $this->iteminstance"); return false; } if (!$cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) { debugging('Can not find course module'); return false; } $activity->modname = $this->itemmodule; $activity->cmidnumber = $cm->idnumber; return grade_update_mod_grades($activity, $userid); } return true; }
[ "public", "function", "refresh_grades", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "itemtype", "==", "'mod'", ")", "{", "if", "(", "$", "this", "->", "is_outcome_item", "(", ")", ")", "{", "//nothing to do", "return", "true", ";", "}", "if", "(", "!", "$", "activity", "=", "$", "DB", "->", "get_record", "(", "$", "this", "->", "itemmodule", ",", "array", "(", "'id'", "=>", "$", "this", "->", "iteminstance", ")", ")", ")", "{", "debugging", "(", "\"Can not find $this->itemmodule activity with id $this->iteminstance\"", ")", ";", "return", "false", ";", "}", "if", "(", "!", "$", "cm", "=", "get_coursemodule_from_instance", "(", "$", "this", "->", "itemmodule", ",", "$", "activity", "->", "id", ",", "$", "this", "->", "courseid", ")", ")", "{", "debugging", "(", "'Can not find course module'", ")", ";", "return", "false", ";", "}", "$", "activity", "->", "modname", "=", "$", "this", "->", "itemmodule", ";", "$", "activity", "->", "cmidnumber", "=", "$", "cm", "->", "idnumber", ";", "return", "grade_update_mod_grades", "(", "$", "activity", ",", "$", "userid", ")", ";", "}", "return", "true", ";", "}" ]
Refetch grades from modules, plugins. @param int $userid optional, limit the refetch to a single user @return bool Returns true on success or if there is nothing to do
[ "Refetch", "grades", "from", "modules", "plugins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L1687-L1712
220,434
moodle/moodle
lib/grade/grade_item.php
grade_item.validate_formula
public function validate_formula($formulastr) { global $CFG, $DB; require_once($CFG->libdir.'/mathslib.php'); $formulastr = grade_item::normalize_formula($formulastr, $this->courseid); if (empty($formulastr)) { return true; } if (strpos($formulastr, '=') !== 0) { return get_string('errorcalculationnoequal', 'grades'); } // get used items if (preg_match_all('/##gi(\d+)##/', $formulastr, $matches)) { $useditems = array_unique($matches[1]); // remove duplicates } else { $useditems = array(); } // MDL-11902 // unset the value if formula is trying to reference to itself // but array keys does not match itemid if (!empty($this->id)) { $useditems = array_diff($useditems, array($this->id)); //unset($useditems[$this->id]); } // prepare formula and init maths library $formula = preg_replace('/##(gi\d+)##/', '\1', $formulastr); $formula = new calc_formula($formula); if (empty($useditems)) { $grade_items = array(); } else { list($usql, $params) = $DB->get_in_or_equal($useditems); $params[] = $this->courseid; $sql = "SELECT gi.* FROM {grade_items} gi WHERE gi.id $usql and gi.courseid=?"; // from the same course only! if (!$grade_items = $DB->get_records_sql($sql, $params)) { $grade_items = array(); } } $params = array(); foreach ($useditems as $itemid) { // make sure all grade items exist in this course if (!array_key_exists($itemid, $grade_items)) { return false; } // use max grade when testing formula, this should be ok in 99.9% // division by 0 is one of possible problems $params['gi'.$grade_items[$itemid]->id] = $grade_items[$itemid]->grademax; } // do the calculation $formula->set_params($params); $result = $formula->evaluate(); // false as result indicates some problem if ($result === false) { // TODO: add more error hints return get_string('errorcalculationunknown', 'grades'); } else { return true; } }
php
public function validate_formula($formulastr) { global $CFG, $DB; require_once($CFG->libdir.'/mathslib.php'); $formulastr = grade_item::normalize_formula($formulastr, $this->courseid); if (empty($formulastr)) { return true; } if (strpos($formulastr, '=') !== 0) { return get_string('errorcalculationnoequal', 'grades'); } // get used items if (preg_match_all('/##gi(\d+)##/', $formulastr, $matches)) { $useditems = array_unique($matches[1]); // remove duplicates } else { $useditems = array(); } // MDL-11902 // unset the value if formula is trying to reference to itself // but array keys does not match itemid if (!empty($this->id)) { $useditems = array_diff($useditems, array($this->id)); //unset($useditems[$this->id]); } // prepare formula and init maths library $formula = preg_replace('/##(gi\d+)##/', '\1', $formulastr); $formula = new calc_formula($formula); if (empty($useditems)) { $grade_items = array(); } else { list($usql, $params) = $DB->get_in_or_equal($useditems); $params[] = $this->courseid; $sql = "SELECT gi.* FROM {grade_items} gi WHERE gi.id $usql and gi.courseid=?"; // from the same course only! if (!$grade_items = $DB->get_records_sql($sql, $params)) { $grade_items = array(); } } $params = array(); foreach ($useditems as $itemid) { // make sure all grade items exist in this course if (!array_key_exists($itemid, $grade_items)) { return false; } // use max grade when testing formula, this should be ok in 99.9% // division by 0 is one of possible problems $params['gi'.$grade_items[$itemid]->id] = $grade_items[$itemid]->grademax; } // do the calculation $formula->set_params($params); $result = $formula->evaluate(); // false as result indicates some problem if ($result === false) { // TODO: add more error hints return get_string('errorcalculationunknown', 'grades'); } else { return true; } }
[ "public", "function", "validate_formula", "(", "$", "formulastr", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/mathslib.php'", ")", ";", "$", "formulastr", "=", "grade_item", "::", "normalize_formula", "(", "$", "formulastr", ",", "$", "this", "->", "courseid", ")", ";", "if", "(", "empty", "(", "$", "formulastr", ")", ")", "{", "return", "true", ";", "}", "if", "(", "strpos", "(", "$", "formulastr", ",", "'='", ")", "!==", "0", ")", "{", "return", "get_string", "(", "'errorcalculationnoequal'", ",", "'grades'", ")", ";", "}", "// get used items", "if", "(", "preg_match_all", "(", "'/##gi(\\d+)##/'", ",", "$", "formulastr", ",", "$", "matches", ")", ")", "{", "$", "useditems", "=", "array_unique", "(", "$", "matches", "[", "1", "]", ")", ";", "// remove duplicates", "}", "else", "{", "$", "useditems", "=", "array", "(", ")", ";", "}", "// MDL-11902", "// unset the value if formula is trying to reference to itself", "// but array keys does not match itemid", "if", "(", "!", "empty", "(", "$", "this", "->", "id", ")", ")", "{", "$", "useditems", "=", "array_diff", "(", "$", "useditems", ",", "array", "(", "$", "this", "->", "id", ")", ")", ";", "//unset($useditems[$this->id]);", "}", "// prepare formula and init maths library", "$", "formula", "=", "preg_replace", "(", "'/##(gi\\d+)##/'", ",", "'\\1'", ",", "$", "formulastr", ")", ";", "$", "formula", "=", "new", "calc_formula", "(", "$", "formula", ")", ";", "if", "(", "empty", "(", "$", "useditems", ")", ")", "{", "$", "grade_items", "=", "array", "(", ")", ";", "}", "else", "{", "list", "(", "$", "usql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "useditems", ")", ";", "$", "params", "[", "]", "=", "$", "this", "->", "courseid", ";", "$", "sql", "=", "\"SELECT gi.*\n FROM {grade_items} gi\n WHERE gi.id $usql and gi.courseid=?\"", ";", "// from the same course only!", "if", "(", "!", "$", "grade_items", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "$", "grade_items", "=", "array", "(", ")", ";", "}", "}", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "useditems", "as", "$", "itemid", ")", "{", "// make sure all grade items exist in this course", "if", "(", "!", "array_key_exists", "(", "$", "itemid", ",", "$", "grade_items", ")", ")", "{", "return", "false", ";", "}", "// use max grade when testing formula, this should be ok in 99.9%", "// division by 0 is one of possible problems", "$", "params", "[", "'gi'", ".", "$", "grade_items", "[", "$", "itemid", "]", "->", "id", "]", "=", "$", "grade_items", "[", "$", "itemid", "]", "->", "grademax", ";", "}", "// do the calculation", "$", "formula", "->", "set_params", "(", "$", "params", ")", ";", "$", "result", "=", "$", "formula", "->", "evaluate", "(", ")", ";", "// false as result indicates some problem", "if", "(", "$", "result", "===", "false", ")", "{", "// TODO: add more error hints", "return", "get_string", "(", "'errorcalculationunknown'", ",", "'grades'", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Validate the formula. @param string $formulastr @return bool true if calculation possible, false otherwise
[ "Validate", "the", "formula", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2293-L2364
220,435
moodle/moodle
lib/grade/grade_item.php
grade_item.get_displaytype
public function get_displaytype() { global $CFG; if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) { return grade_get_setting($this->courseid, 'displaytype', $CFG->grade_displaytype); } else { return $this->display; } }
php
public function get_displaytype() { global $CFG; if ($this->display == GRADE_DISPLAY_TYPE_DEFAULT) { return grade_get_setting($this->courseid, 'displaytype', $CFG->grade_displaytype); } else { return $this->display; } }
[ "public", "function", "get_displaytype", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "this", "->", "display", "==", "GRADE_DISPLAY_TYPE_DEFAULT", ")", "{", "return", "grade_get_setting", "(", "$", "this", "->", "courseid", ",", "'displaytype'", ",", "$", "CFG", "->", "grade_displaytype", ")", ";", "}", "else", "{", "return", "$", "this", "->", "display", ";", "}", "}" ]
Returns the value of the display type It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones. @return int Display type
[ "Returns", "the", "value", "of", "the", "display", "type" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2373-L2382
220,436
moodle/moodle
lib/grade/grade_item.php
grade_item.get_decimals
public function get_decimals() { global $CFG; if (is_null($this->decimals)) { return grade_get_setting($this->courseid, 'decimalpoints', $CFG->grade_decimalpoints); } else { return $this->decimals; } }
php
public function get_decimals() { global $CFG; if (is_null($this->decimals)) { return grade_get_setting($this->courseid, 'decimalpoints', $CFG->grade_decimalpoints); } else { return $this->decimals; } }
[ "public", "function", "get_decimals", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "is_null", "(", "$", "this", "->", "decimals", ")", ")", "{", "return", "grade_get_setting", "(", "$", "this", "->", "courseid", ",", "'decimalpoints'", ",", "$", "CFG", "->", "grade_decimalpoints", ")", ";", "}", "else", "{", "return", "$", "this", "->", "decimals", ";", "}", "}" ]
Returns the value of the decimals field It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones. @return int Decimals (0 - 5)
[ "Returns", "the", "value", "of", "the", "decimals", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2391-L2400
220,437
moodle/moodle
lib/grade/grade_item.php
grade_item.get_formatted_range
function get_formatted_range($rangesdisplaytype=null, $rangesdecimalpoints=null) { global $USER; // Determine which display type to use for this average if (isset($USER->gradeediting) && array_key_exists($this->courseid, $USER->gradeediting) && $USER->gradeediting[$this->courseid]) { $displaytype = GRADE_DISPLAY_TYPE_REAL; } else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs $displaytype = $this->get_displaytype(); } else { $displaytype = $rangesdisplaytype; } // Override grade_item setting if a display preference (not default) was set for the averages if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) { $decimalpoints = $this->get_decimals(); } else { $decimalpoints = $rangesdecimalpoints; } if ($displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) { $grademin = "0 %"; $grademax = "100 %"; } else { $grademin = grade_format_gradevalue($this->grademin, $this, true, $displaytype, $decimalpoints); $grademax = grade_format_gradevalue($this->grademax, $this, true, $displaytype, $decimalpoints); } return $grademin.'&ndash;'. $grademax; }
php
function get_formatted_range($rangesdisplaytype=null, $rangesdecimalpoints=null) { global $USER; // Determine which display type to use for this average if (isset($USER->gradeediting) && array_key_exists($this->courseid, $USER->gradeediting) && $USER->gradeediting[$this->courseid]) { $displaytype = GRADE_DISPLAY_TYPE_REAL; } else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs $displaytype = $this->get_displaytype(); } else { $displaytype = $rangesdisplaytype; } // Override grade_item setting if a display preference (not default) was set for the averages if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) { $decimalpoints = $this->get_decimals(); } else { $decimalpoints = $rangesdecimalpoints; } if ($displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) { $grademin = "0 %"; $grademax = "100 %"; } else { $grademin = grade_format_gradevalue($this->grademin, $this, true, $displaytype, $decimalpoints); $grademax = grade_format_gradevalue($this->grademax, $this, true, $displaytype, $decimalpoints); } return $grademin.'&ndash;'. $grademax; }
[ "function", "get_formatted_range", "(", "$", "rangesdisplaytype", "=", "null", ",", "$", "rangesdecimalpoints", "=", "null", ")", "{", "global", "$", "USER", ";", "// Determine which display type to use for this average", "if", "(", "isset", "(", "$", "USER", "->", "gradeediting", ")", "&&", "array_key_exists", "(", "$", "this", "->", "courseid", ",", "$", "USER", "->", "gradeediting", ")", "&&", "$", "USER", "->", "gradeediting", "[", "$", "this", "->", "courseid", "]", ")", "{", "$", "displaytype", "=", "GRADE_DISPLAY_TYPE_REAL", ";", "}", "else", "if", "(", "$", "rangesdisplaytype", "==", "GRADE_REPORT_PREFERENCE_INHERIT", ")", "{", "// no ==0 here, please resave report and user prefs", "$", "displaytype", "=", "$", "this", "->", "get_displaytype", "(", ")", ";", "}", "else", "{", "$", "displaytype", "=", "$", "rangesdisplaytype", ";", "}", "// Override grade_item setting if a display preference (not default) was set for the averages", "if", "(", "$", "rangesdecimalpoints", "==", "GRADE_REPORT_PREFERENCE_INHERIT", ")", "{", "$", "decimalpoints", "=", "$", "this", "->", "get_decimals", "(", ")", ";", "}", "else", "{", "$", "decimalpoints", "=", "$", "rangesdecimalpoints", ";", "}", "if", "(", "$", "displaytype", "==", "GRADE_DISPLAY_TYPE_PERCENTAGE", ")", "{", "$", "grademin", "=", "\"0 %\"", ";", "$", "grademax", "=", "\"100 %\"", ";", "}", "else", "{", "$", "grademin", "=", "grade_format_gradevalue", "(", "$", "this", "->", "grademin", ",", "$", "this", ",", "true", ",", "$", "displaytype", ",", "$", "decimalpoints", ")", ";", "$", "grademax", "=", "grade_format_gradevalue", "(", "$", "this", "->", "grademax", ",", "$", "this", ",", "true", ",", "$", "displaytype", ",", "$", "decimalpoints", ")", ";", "}", "return", "$", "grademin", ".", "'&ndash;'", ".", "$", "grademax", ";", "}" ]
Returns a string representing the range of grademin - grademax for this grade item. @param int $rangesdisplaytype @param int $rangesdecimalpoints @return string
[ "Returns", "a", "string", "representing", "the", "range", "of", "grademin", "-", "grademax", "for", "this", "grade", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2409-L2442
220,438
moodle/moodle
lib/grade/grade_item.php
grade_item.get_coefstring
public function get_coefstring() { $parent_category = $this->load_parent_category(); if ($this->is_category_item()) { $parent_category = $parent_category->load_parent_category(); } if ($parent_category->is_aggregationcoef_used()) { return $parent_category->get_coefstring(); } else { return false; } }
php
public function get_coefstring() { $parent_category = $this->load_parent_category(); if ($this->is_category_item()) { $parent_category = $parent_category->load_parent_category(); } if ($parent_category->is_aggregationcoef_used()) { return $parent_category->get_coefstring(); } else { return false; } }
[ "public", "function", "get_coefstring", "(", ")", "{", "$", "parent_category", "=", "$", "this", "->", "load_parent_category", "(", ")", ";", "if", "(", "$", "this", "->", "is_category_item", "(", ")", ")", "{", "$", "parent_category", "=", "$", "parent_category", "->", "load_parent_category", "(", ")", ";", "}", "if", "(", "$", "parent_category", "->", "is_aggregationcoef_used", "(", ")", ")", "{", "return", "$", "parent_category", "->", "get_coefstring", "(", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Queries parent categories recursively to find the aggregationcoef type that applies to this grade item. @return string|false Returns the coefficient string of false is no coefficient is being used
[ "Queries", "parent", "categories", "recursively", "to", "find", "the", "aggregationcoef", "type", "that", "applies", "to", "this", "grade", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2449-L2460
220,439
moodle/moodle
lib/grade/grade_item.php
grade_item.can_control_visibility
public function can_control_visibility() { if (core_component::get_plugin_directory($this->itemtype, $this->itemmodule)) { return !plugin_supports($this->itemtype, $this->itemmodule, FEATURE_CONTROLS_GRADE_VISIBILITY, false); } return parent::can_control_visibility(); }
php
public function can_control_visibility() { if (core_component::get_plugin_directory($this->itemtype, $this->itemmodule)) { return !plugin_supports($this->itemtype, $this->itemmodule, FEATURE_CONTROLS_GRADE_VISIBILITY, false); } return parent::can_control_visibility(); }
[ "public", "function", "can_control_visibility", "(", ")", "{", "if", "(", "core_component", "::", "get_plugin_directory", "(", "$", "this", "->", "itemtype", ",", "$", "this", "->", "itemmodule", ")", ")", "{", "return", "!", "plugin_supports", "(", "$", "this", "->", "itemtype", ",", "$", "this", "->", "itemmodule", ",", "FEATURE_CONTROLS_GRADE_VISIBILITY", ",", "false", ")", ";", "}", "return", "parent", "::", "can_control_visibility", "(", ")", ";", "}" ]
Returns whether the grade item can control the visibility of the grades @return bool
[ "Returns", "whether", "the", "grade", "item", "can", "control", "the", "visibility", "of", "the", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2467-L2472
220,440
moodle/moodle
lib/grade/grade_item.php
grade_item.get_context
public function get_context() { if ($this->itemtype == 'mod') { $modinfo = get_fast_modinfo($this->courseid); // Sometimes the course module cache is out of date and needs to be rebuilt. if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) { rebuild_course_cache($this->courseid, true); $modinfo = get_fast_modinfo($this->courseid); } // Even with a rebuilt cache the module does not exist. This means the // database is in an invalid state - we will log an error and return // the course context but the calling code should be updated. if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) { mtrace(get_string('moduleinstancedoesnotexist', 'error')); $context = \context_course::instance($this->courseid); } else { $cm = $modinfo->instances[$this->itemmodule][$this->iteminstance]; $context = \context_module::instance($cm->id); } } else { $context = \context_course::instance($this->courseid); } return $context; }
php
public function get_context() { if ($this->itemtype == 'mod') { $modinfo = get_fast_modinfo($this->courseid); // Sometimes the course module cache is out of date and needs to be rebuilt. if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) { rebuild_course_cache($this->courseid, true); $modinfo = get_fast_modinfo($this->courseid); } // Even with a rebuilt cache the module does not exist. This means the // database is in an invalid state - we will log an error and return // the course context but the calling code should be updated. if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) { mtrace(get_string('moduleinstancedoesnotexist', 'error')); $context = \context_course::instance($this->courseid); } else { $cm = $modinfo->instances[$this->itemmodule][$this->iteminstance]; $context = \context_module::instance($cm->id); } } else { $context = \context_course::instance($this->courseid); } return $context; }
[ "public", "function", "get_context", "(", ")", "{", "if", "(", "$", "this", "->", "itemtype", "==", "'mod'", ")", "{", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "courseid", ")", ";", "// Sometimes the course module cache is out of date and needs to be rebuilt.", "if", "(", "!", "isset", "(", "$", "modinfo", "->", "instances", "[", "$", "this", "->", "itemmodule", "]", "[", "$", "this", "->", "iteminstance", "]", ")", ")", "{", "rebuild_course_cache", "(", "$", "this", "->", "courseid", ",", "true", ")", ";", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "this", "->", "courseid", ")", ";", "}", "// Even with a rebuilt cache the module does not exist. This means the", "// database is in an invalid state - we will log an error and return", "// the course context but the calling code should be updated.", "if", "(", "!", "isset", "(", "$", "modinfo", "->", "instances", "[", "$", "this", "->", "itemmodule", "]", "[", "$", "this", "->", "iteminstance", "]", ")", ")", "{", "mtrace", "(", "get_string", "(", "'moduleinstancedoesnotexist'", ",", "'error'", ")", ")", ";", "$", "context", "=", "\\", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", ";", "}", "else", "{", "$", "cm", "=", "$", "modinfo", "->", "instances", "[", "$", "this", "->", "itemmodule", "]", "[", "$", "this", "->", "iteminstance", "]", ";", "$", "context", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "}", "}", "else", "{", "$", "context", "=", "\\", "context_course", "::", "instance", "(", "$", "this", "->", "courseid", ")", ";", "}", "return", "$", "context", ";", "}" ]
Helper function to get the accurate context for this grade column. @return context
[ "Helper", "function", "to", "get", "the", "accurate", "context", "for", "this", "grade", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/grade/grade_item.php#L2496-L2518
220,441
moodle/moodle
message/output/email/classes/output/renderer.php
renderer.render_email_digest
public function render_email_digest(email_digest $emaildigest) { $data = $emaildigest->export_for_template($this); return $this->render_from_template('message_email/' . $this->get_template_name(), $data); }
php
public function render_email_digest(email_digest $emaildigest) { $data = $emaildigest->export_for_template($this); return $this->render_from_template('message_email/' . $this->get_template_name(), $data); }
[ "public", "function", "render_email_digest", "(", "email_digest", "$", "emaildigest", ")", "{", "$", "data", "=", "$", "emaildigest", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'message_email/'", ".", "$", "this", "->", "get_template_name", "(", ")", ",", "$", "data", ")", ";", "}" ]
Formats the email used to send the certificate by the email_certificate_task. @param email_digest $emaildigest The certificate to email @return string
[ "Formats", "the", "email", "used", "to", "send", "the", "certificate", "by", "the", "email_certificate_task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/email/classes/output/renderer.php#L46-L49
220,442
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.breakLinesForEmail
public static function breakLinesForEmail($str, $newlineChar = LF, $lineWidth = 76) { self::logDeprecatedFunction(); return t3lib_utility_Mail::breakLinesForEmail($str, $newlineChar, $lineWidth); }
php
public static function breakLinesForEmail($str, $newlineChar = LF, $lineWidth = 76) { self::logDeprecatedFunction(); return t3lib_utility_Mail::breakLinesForEmail($str, $newlineChar, $lineWidth); }
[ "public", "static", "function", "breakLinesForEmail", "(", "$", "str", ",", "$", "newlineChar", "=", "LF", ",", "$", "lineWidth", "=", "76", ")", "{", "self", "::", "logDeprecatedFunction", "(", ")", ";", "return", "t3lib_utility_Mail", "::", "breakLinesForEmail", "(", "$", "str", ",", "$", "newlineChar", ",", "$", "lineWidth", ")", ";", "}" ]
Breaks up a single line of text for emails @param string $str The string to break up @param string $newlineChar The string to implode the broken lines with (default/typically \n) @param integer $lineWidth The line width @return string reformatted text @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0 - Use t3lib_utility_Mail::breakLinesForEmail()
[ "Breaks", "up", "a", "single", "line", "of", "text", "for", "emails" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L402-L405
220,443
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.cmpIP
public static function cmpIP($baseIP, $list) { $list = trim($list); if ($list === '') { return FALSE; } elseif ($list === '*') { return TRUE; } if (strpos($baseIP, ':') !== FALSE && self::validIPv6($baseIP)) { return self::cmpIPv6($baseIP, $list); } else { return self::cmpIPv4($baseIP, $list); } }
php
public static function cmpIP($baseIP, $list) { $list = trim($list); if ($list === '') { return FALSE; } elseif ($list === '*') { return TRUE; } if (strpos($baseIP, ':') !== FALSE && self::validIPv6($baseIP)) { return self::cmpIPv6($baseIP, $list); } else { return self::cmpIPv4($baseIP, $list); } }
[ "public", "static", "function", "cmpIP", "(", "$", "baseIP", ",", "$", "list", ")", "{", "$", "list", "=", "trim", "(", "$", "list", ")", ";", "if", "(", "$", "list", "===", "''", ")", "{", "return", "FALSE", ";", "}", "elseif", "(", "$", "list", "===", "'*'", ")", "{", "return", "TRUE", ";", "}", "if", "(", "strpos", "(", "$", "baseIP", ",", "':'", ")", "!==", "FALSE", "&&", "self", "::", "validIPv6", "(", "$", "baseIP", ")", ")", "{", "return", "self", "::", "cmpIPv6", "(", "$", "baseIP", ",", "$", "list", ")", ";", "}", "else", "{", "return", "self", "::", "cmpIPv4", "(", "$", "baseIP", ",", "$", "list", ")", ";", "}", "}" ]
Match IP number with list of numbers with wildcard Dispatcher method for switching into specialised IPv4 and IPv6 methods. @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR @param string $list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168). If list is "*" no check is done and the function returns TRUE immediately. An empty list always returns FALSE. @return boolean TRUE if an IP-mask from $list matches $baseIP
[ "Match", "IP", "number", "with", "list", "of", "numbers", "with", "wildcard", "Dispatcher", "method", "for", "switching", "into", "specialised", "IPv4", "and", "IPv6", "methods", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L415-L427
220,444
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.cmpIPv4
public static function cmpIPv4($baseIP, $list) { $IPpartsReq = explode('.', $baseIP); if (count($IPpartsReq) == 4) { $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $testList = explode('/', $test); if (count($testList) == 2) { list($test, $mask) = $testList; } else { $mask = FALSE; } if (intval($mask)) { // "192.168.3.0/24" $lnet = ip2long($test); $lip = ip2long($baseIP); $binnet = str_pad(decbin($lnet), 32, '0', STR_PAD_LEFT); $firstpart = substr($binnet, 0, $mask); $binip = str_pad(decbin($lip), 32, '0', STR_PAD_LEFT); $firstip = substr($binip, 0, $mask); $yes = (strcmp($firstpart, $firstip) == 0); } else { // "192.168.*.*" $IPparts = explode('.', $test); $yes = 1; foreach ($IPparts as $index => $val) { $val = trim($val); if (($val !== '*') && ($IPpartsReq[$index] !== $val)) { $yes = 0; } } } if ($yes) { return TRUE; } } } return FALSE; }
php
public static function cmpIPv4($baseIP, $list) { $IPpartsReq = explode('.', $baseIP); if (count($IPpartsReq) == 4) { $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $testList = explode('/', $test); if (count($testList) == 2) { list($test, $mask) = $testList; } else { $mask = FALSE; } if (intval($mask)) { // "192.168.3.0/24" $lnet = ip2long($test); $lip = ip2long($baseIP); $binnet = str_pad(decbin($lnet), 32, '0', STR_PAD_LEFT); $firstpart = substr($binnet, 0, $mask); $binip = str_pad(decbin($lip), 32, '0', STR_PAD_LEFT); $firstip = substr($binip, 0, $mask); $yes = (strcmp($firstpart, $firstip) == 0); } else { // "192.168.*.*" $IPparts = explode('.', $test); $yes = 1; foreach ($IPparts as $index => $val) { $val = trim($val); if (($val !== '*') && ($IPpartsReq[$index] !== $val)) { $yes = 0; } } } if ($yes) { return TRUE; } } } return FALSE; }
[ "public", "static", "function", "cmpIPv4", "(", "$", "baseIP", ",", "$", "list", ")", "{", "$", "IPpartsReq", "=", "explode", "(", "'.'", ",", "$", "baseIP", ")", ";", "if", "(", "count", "(", "$", "IPpartsReq", ")", "==", "4", ")", "{", "$", "values", "=", "self", "::", "trimExplode", "(", "','", ",", "$", "list", ",", "1", ")", ";", "foreach", "(", "$", "values", "as", "$", "test", ")", "{", "$", "testList", "=", "explode", "(", "'/'", ",", "$", "test", ")", ";", "if", "(", "count", "(", "$", "testList", ")", "==", "2", ")", "{", "list", "(", "$", "test", ",", "$", "mask", ")", "=", "$", "testList", ";", "}", "else", "{", "$", "mask", "=", "FALSE", ";", "}", "if", "(", "intval", "(", "$", "mask", ")", ")", "{", "// \"192.168.3.0/24\"", "$", "lnet", "=", "ip2long", "(", "$", "test", ")", ";", "$", "lip", "=", "ip2long", "(", "$", "baseIP", ")", ";", "$", "binnet", "=", "str_pad", "(", "decbin", "(", "$", "lnet", ")", ",", "32", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "firstpart", "=", "substr", "(", "$", "binnet", ",", "0", ",", "$", "mask", ")", ";", "$", "binip", "=", "str_pad", "(", "decbin", "(", "$", "lip", ")", ",", "32", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "firstip", "=", "substr", "(", "$", "binip", ",", "0", ",", "$", "mask", ")", ";", "$", "yes", "=", "(", "strcmp", "(", "$", "firstpart", ",", "$", "firstip", ")", "==", "0", ")", ";", "}", "else", "{", "// \"192.168.*.*\"", "$", "IPparts", "=", "explode", "(", "'.'", ",", "$", "test", ")", ";", "$", "yes", "=", "1", ";", "foreach", "(", "$", "IPparts", "as", "$", "index", "=>", "$", "val", ")", "{", "$", "val", "=", "trim", "(", "$", "val", ")", ";", "if", "(", "(", "$", "val", "!==", "'*'", ")", "&&", "(", "$", "IPpartsReq", "[", "$", "index", "]", "!==", "$", "val", ")", ")", "{", "$", "yes", "=", "0", ";", "}", "}", "}", "if", "(", "$", "yes", ")", "{", "return", "TRUE", ";", "}", "}", "}", "return", "FALSE", ";", "}" ]
Match IPv4 number with list of numbers with wildcard @param string $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR @param string $list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168), could also contain IPv6 addresses @return boolean TRUE if an IP-mask from $list matches $baseIP
[ "Match", "IPv4", "number", "with", "list", "of", "numbers", "with", "wildcard" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L436-L475
220,445
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.cmpIPv6
public static function cmpIPv6($baseIP, $list) { $success = FALSE; // Policy default: Deny connection $baseIP = self::normalizeIPv6($baseIP); $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $testList = explode('/', $test); if (count($testList) == 2) { list($test, $mask) = $testList; } else { $mask = FALSE; } if (self::validIPv6($test)) { $test = self::normalizeIPv6($test); $maskInt = intval($mask) ? intval($mask) : 128; if ($mask === '0') { // special case; /0 is an allowed mask - equals a wildcard $success = TRUE; } elseif ($maskInt == 128) { $success = ($test === $baseIP); } else { $testBin = self::IPv6Hex2Bin($test); $baseIPBin = self::IPv6Hex2Bin($baseIP); $success = TRUE; // modulo is 0 if this is a 8-bit-boundary $maskIntModulo = $maskInt % 8; $numFullCharactersUntilBoundary = intval($maskInt / 8); if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) { $success = FALSE; } elseif ($maskIntModulo > 0) { // if not an 8-bit-boundary, check bits of last character $testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT); $baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT); if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) { $success = FALSE; } } } } if ($success) { return TRUE; } } return FALSE; }
php
public static function cmpIPv6($baseIP, $list) { $success = FALSE; // Policy default: Deny connection $baseIP = self::normalizeIPv6($baseIP); $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $testList = explode('/', $test); if (count($testList) == 2) { list($test, $mask) = $testList; } else { $mask = FALSE; } if (self::validIPv6($test)) { $test = self::normalizeIPv6($test); $maskInt = intval($mask) ? intval($mask) : 128; if ($mask === '0') { // special case; /0 is an allowed mask - equals a wildcard $success = TRUE; } elseif ($maskInt == 128) { $success = ($test === $baseIP); } else { $testBin = self::IPv6Hex2Bin($test); $baseIPBin = self::IPv6Hex2Bin($baseIP); $success = TRUE; // modulo is 0 if this is a 8-bit-boundary $maskIntModulo = $maskInt % 8; $numFullCharactersUntilBoundary = intval($maskInt / 8); if (substr($testBin, 0, $numFullCharactersUntilBoundary) !== substr($baseIPBin, 0, $numFullCharactersUntilBoundary)) { $success = FALSE; } elseif ($maskIntModulo > 0) { // if not an 8-bit-boundary, check bits of last character $testLastBits = str_pad(decbin(ord(substr($testBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT); $baseIPLastBits = str_pad(decbin(ord(substr($baseIPBin, $numFullCharactersUntilBoundary, 1))), 8, '0', STR_PAD_LEFT); if (strncmp($testLastBits, $baseIPLastBits, $maskIntModulo) != 0) { $success = FALSE; } } } } if ($success) { return TRUE; } } return FALSE; }
[ "public", "static", "function", "cmpIPv6", "(", "$", "baseIP", ",", "$", "list", ")", "{", "$", "success", "=", "FALSE", ";", "// Policy default: Deny connection", "$", "baseIP", "=", "self", "::", "normalizeIPv6", "(", "$", "baseIP", ")", ";", "$", "values", "=", "self", "::", "trimExplode", "(", "','", ",", "$", "list", ",", "1", ")", ";", "foreach", "(", "$", "values", "as", "$", "test", ")", "{", "$", "testList", "=", "explode", "(", "'/'", ",", "$", "test", ")", ";", "if", "(", "count", "(", "$", "testList", ")", "==", "2", ")", "{", "list", "(", "$", "test", ",", "$", "mask", ")", "=", "$", "testList", ";", "}", "else", "{", "$", "mask", "=", "FALSE", ";", "}", "if", "(", "self", "::", "validIPv6", "(", "$", "test", ")", ")", "{", "$", "test", "=", "self", "::", "normalizeIPv6", "(", "$", "test", ")", ";", "$", "maskInt", "=", "intval", "(", "$", "mask", ")", "?", "intval", "(", "$", "mask", ")", ":", "128", ";", "if", "(", "$", "mask", "===", "'0'", ")", "{", "// special case; /0 is an allowed mask - equals a wildcard", "$", "success", "=", "TRUE", ";", "}", "elseif", "(", "$", "maskInt", "==", "128", ")", "{", "$", "success", "=", "(", "$", "test", "===", "$", "baseIP", ")", ";", "}", "else", "{", "$", "testBin", "=", "self", "::", "IPv6Hex2Bin", "(", "$", "test", ")", ";", "$", "baseIPBin", "=", "self", "::", "IPv6Hex2Bin", "(", "$", "baseIP", ")", ";", "$", "success", "=", "TRUE", ";", "// modulo is 0 if this is a 8-bit-boundary", "$", "maskIntModulo", "=", "$", "maskInt", "%", "8", ";", "$", "numFullCharactersUntilBoundary", "=", "intval", "(", "$", "maskInt", "/", "8", ")", ";", "if", "(", "substr", "(", "$", "testBin", ",", "0", ",", "$", "numFullCharactersUntilBoundary", ")", "!==", "substr", "(", "$", "baseIPBin", ",", "0", ",", "$", "numFullCharactersUntilBoundary", ")", ")", "{", "$", "success", "=", "FALSE", ";", "}", "elseif", "(", "$", "maskIntModulo", ">", "0", ")", "{", "// if not an 8-bit-boundary, check bits of last character", "$", "testLastBits", "=", "str_pad", "(", "decbin", "(", "ord", "(", "substr", "(", "$", "testBin", ",", "$", "numFullCharactersUntilBoundary", ",", "1", ")", ")", ")", ",", "8", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "$", "baseIPLastBits", "=", "str_pad", "(", "decbin", "(", "ord", "(", "substr", "(", "$", "baseIPBin", ",", "$", "numFullCharactersUntilBoundary", ",", "1", ")", ")", ")", ",", "8", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "if", "(", "strncmp", "(", "$", "testLastBits", ",", "$", "baseIPLastBits", ",", "$", "maskIntModulo", ")", "!=", "0", ")", "{", "$", "success", "=", "FALSE", ";", "}", "}", "}", "}", "if", "(", "$", "success", ")", "{", "return", "TRUE", ";", "}", "}", "return", "FALSE", ";", "}" ]
Match IPv6 address with a list of IPv6 prefixes @param string $baseIP is the current remote IP address for instance @param string $list is a comma-list of IPv6 prefixes, could also contain IPv4 addresses @return boolean TRUE if an baseIP matches any prefix
[ "Match", "IPv6", "address", "with", "a", "list", "of", "IPv6", "prefixes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L484-L530
220,446
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.IPv6Hex2Bin
public static function IPv6Hex2Bin($hex) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $bin = inet_pton($hex); } else { $hex = self::normalizeIPv6($hex); $hex = str_replace(':', '', $hex); // Replace colon to nothing $bin = pack("H*" , $hex); } return $bin; }
php
public static function IPv6Hex2Bin($hex) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $bin = inet_pton($hex); } else { $hex = self::normalizeIPv6($hex); $hex = str_replace(':', '', $hex); // Replace colon to nothing $bin = pack("H*" , $hex); } return $bin; }
[ "public", "static", "function", "IPv6Hex2Bin", "(", "$", "hex", ")", "{", "// use PHP-function if PHP was compiled with IPv6-support", "if", "(", "defined", "(", "'AF_INET6'", ")", ")", "{", "$", "bin", "=", "inet_pton", "(", "$", "hex", ")", ";", "}", "else", "{", "$", "hex", "=", "self", "::", "normalizeIPv6", "(", "$", "hex", ")", ";", "$", "hex", "=", "str_replace", "(", "':'", ",", "''", ",", "$", "hex", ")", ";", "// Replace colon to nothing", "$", "bin", "=", "pack", "(", "\"H*\"", ",", "$", "hex", ")", ";", "}", "return", "$", "bin", ";", "}" ]
Transform a regular IPv6 address from hex-representation into binary @param string $hex IPv6 address in hex-presentation @return string Binary representation (16 characters, 128 characters) @see IPv6Bin2Hex()
[ "Transform", "a", "regular", "IPv6", "address", "from", "hex", "-", "representation", "into", "binary" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L539-L549
220,447
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.IPv6Bin2Hex
public static function IPv6Bin2Hex($bin) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $hex = inet_ntop($bin); } else { $hex = unpack("H*" , $bin); $hex = chunk_split($hex[1], 4, ':'); // strip last colon (from chunk_split) $hex = substr($hex, 0, -1); // IPv6 is now in normalized form // compress it for easier handling and to match result from inet_ntop() $hex = self::compressIPv6($hex); } return $hex; }
php
public static function IPv6Bin2Hex($bin) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $hex = inet_ntop($bin); } else { $hex = unpack("H*" , $bin); $hex = chunk_split($hex[1], 4, ':'); // strip last colon (from chunk_split) $hex = substr($hex, 0, -1); // IPv6 is now in normalized form // compress it for easier handling and to match result from inet_ntop() $hex = self::compressIPv6($hex); } return $hex; }
[ "public", "static", "function", "IPv6Bin2Hex", "(", "$", "bin", ")", "{", "// use PHP-function if PHP was compiled with IPv6-support", "if", "(", "defined", "(", "'AF_INET6'", ")", ")", "{", "$", "hex", "=", "inet_ntop", "(", "$", "bin", ")", ";", "}", "else", "{", "$", "hex", "=", "unpack", "(", "\"H*\"", ",", "$", "bin", ")", ";", "$", "hex", "=", "chunk_split", "(", "$", "hex", "[", "1", "]", ",", "4", ",", "':'", ")", ";", "// strip last colon (from chunk_split)", "$", "hex", "=", "substr", "(", "$", "hex", ",", "0", ",", "-", "1", ")", ";", "// IPv6 is now in normalized form", "// compress it for easier handling and to match result from inet_ntop()", "$", "hex", "=", "self", "::", "compressIPv6", "(", "$", "hex", ")", ";", "}", "return", "$", "hex", ";", "}" ]
Transform an IPv6 address from binary to hex-representation @param string $bin IPv6 address in hex-presentation @return string Binary representation (16 characters, 128 characters) @see IPv6Hex2Bin()
[ "Transform", "an", "IPv6", "address", "from", "binary", "to", "hex", "-", "representation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L558-L573
220,448
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.normalizeIPv6
public static function normalizeIPv6($address) { $normalizedAddress = ''; $stageOneAddress = ''; // according to RFC lowercase-representation is recommended $address = strtolower($address); // normalized representation has 39 characters (0000:0000:0000:0000:0000:0000:0000:0000) if (strlen($address) == 39) { // already in full expanded form return $address; } $chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks if (count($chunks) == 2) { $chunksLeft = explode(':', $chunks[0]); $chunksRight = explode(':', $chunks[1]); $left = count($chunksLeft); $right = count($chunksRight); // Special case: leading zero-only blocks count to 1, should be 0 if ($left == 1 && strlen($chunksLeft[0]) == 0) { $left = 0; } $hiddenBlocks = 8 - ($left + $right); $hiddenPart = ''; $h = 0; while ($h < $hiddenBlocks) { $hiddenPart .= '0000:'; $h++; } if ($left == 0) { $stageOneAddress = $hiddenPart . $chunks[1]; } else { $stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1]; } } else { $stageOneAddress = $address; } // normalize the blocks: $blocks = explode(':', $stageOneAddress); $divCounter = 0; foreach ($blocks as $block) { $tmpBlock = ''; $i = 0; $hiddenZeros = 4 - strlen($block); while ($i < $hiddenZeros) { $tmpBlock .= '0'; $i++; } $normalizedAddress .= $tmpBlock . $block; if ($divCounter < 7) { $normalizedAddress .= ':'; $divCounter++; } } return $normalizedAddress; }
php
public static function normalizeIPv6($address) { $normalizedAddress = ''; $stageOneAddress = ''; // according to RFC lowercase-representation is recommended $address = strtolower($address); // normalized representation has 39 characters (0000:0000:0000:0000:0000:0000:0000:0000) if (strlen($address) == 39) { // already in full expanded form return $address; } $chunks = explode('::', $address); // Count 2 if if address has hidden zero blocks if (count($chunks) == 2) { $chunksLeft = explode(':', $chunks[0]); $chunksRight = explode(':', $chunks[1]); $left = count($chunksLeft); $right = count($chunksRight); // Special case: leading zero-only blocks count to 1, should be 0 if ($left == 1 && strlen($chunksLeft[0]) == 0) { $left = 0; } $hiddenBlocks = 8 - ($left + $right); $hiddenPart = ''; $h = 0; while ($h < $hiddenBlocks) { $hiddenPart .= '0000:'; $h++; } if ($left == 0) { $stageOneAddress = $hiddenPart . $chunks[1]; } else { $stageOneAddress = $chunks[0] . ':' . $hiddenPart . $chunks[1]; } } else { $stageOneAddress = $address; } // normalize the blocks: $blocks = explode(':', $stageOneAddress); $divCounter = 0; foreach ($blocks as $block) { $tmpBlock = ''; $i = 0; $hiddenZeros = 4 - strlen($block); while ($i < $hiddenZeros) { $tmpBlock .= '0'; $i++; } $normalizedAddress .= $tmpBlock . $block; if ($divCounter < 7) { $normalizedAddress .= ':'; $divCounter++; } } return $normalizedAddress; }
[ "public", "static", "function", "normalizeIPv6", "(", "$", "address", ")", "{", "$", "normalizedAddress", "=", "''", ";", "$", "stageOneAddress", "=", "''", ";", "// according to RFC lowercase-representation is recommended", "$", "address", "=", "strtolower", "(", "$", "address", ")", ";", "// normalized representation has 39 characters (0000:0000:0000:0000:0000:0000:0000:0000)", "if", "(", "strlen", "(", "$", "address", ")", "==", "39", ")", "{", "// already in full expanded form", "return", "$", "address", ";", "}", "$", "chunks", "=", "explode", "(", "'::'", ",", "$", "address", ")", ";", "// Count 2 if if address has hidden zero blocks", "if", "(", "count", "(", "$", "chunks", ")", "==", "2", ")", "{", "$", "chunksLeft", "=", "explode", "(", "':'", ",", "$", "chunks", "[", "0", "]", ")", ";", "$", "chunksRight", "=", "explode", "(", "':'", ",", "$", "chunks", "[", "1", "]", ")", ";", "$", "left", "=", "count", "(", "$", "chunksLeft", ")", ";", "$", "right", "=", "count", "(", "$", "chunksRight", ")", ";", "// Special case: leading zero-only blocks count to 1, should be 0", "if", "(", "$", "left", "==", "1", "&&", "strlen", "(", "$", "chunksLeft", "[", "0", "]", ")", "==", "0", ")", "{", "$", "left", "=", "0", ";", "}", "$", "hiddenBlocks", "=", "8", "-", "(", "$", "left", "+", "$", "right", ")", ";", "$", "hiddenPart", "=", "''", ";", "$", "h", "=", "0", ";", "while", "(", "$", "h", "<", "$", "hiddenBlocks", ")", "{", "$", "hiddenPart", ".=", "'0000:'", ";", "$", "h", "++", ";", "}", "if", "(", "$", "left", "==", "0", ")", "{", "$", "stageOneAddress", "=", "$", "hiddenPart", ".", "$", "chunks", "[", "1", "]", ";", "}", "else", "{", "$", "stageOneAddress", "=", "$", "chunks", "[", "0", "]", ".", "':'", ".", "$", "hiddenPart", ".", "$", "chunks", "[", "1", "]", ";", "}", "}", "else", "{", "$", "stageOneAddress", "=", "$", "address", ";", "}", "// normalize the blocks:", "$", "blocks", "=", "explode", "(", "':'", ",", "$", "stageOneAddress", ")", ";", "$", "divCounter", "=", "0", ";", "foreach", "(", "$", "blocks", "as", "$", "block", ")", "{", "$", "tmpBlock", "=", "''", ";", "$", "i", "=", "0", ";", "$", "hiddenZeros", "=", "4", "-", "strlen", "(", "$", "block", ")", ";", "while", "(", "$", "i", "<", "$", "hiddenZeros", ")", "{", "$", "tmpBlock", ".=", "'0'", ";", "$", "i", "++", ";", "}", "$", "normalizedAddress", ".=", "$", "tmpBlock", ".", "$", "block", ";", "if", "(", "$", "divCounter", "<", "7", ")", "{", "$", "normalizedAddress", ".=", "':'", ";", "$", "divCounter", "++", ";", "}", "}", "return", "$", "normalizedAddress", ";", "}" ]
Normalize an IPv6 address to full length @param string $address Given IPv6 address @return string Normalized address @see compressIPv6()
[ "Normalize", "an", "IPv6", "address", "to", "full", "length" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L582-L642
220,449
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.compressIPv6
public static function compressIPv6($address) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $bin = inet_pton($address); $address = inet_ntop($bin); } else { $address = self::normalizeIPv6($address); // append one colon for easier handling // will be removed later $address .= ':'; // according to IPv6-notation the longest match // of a package of '0000:' may be replaced with ':' // (resulting in something like '1234::abcd') for ($counter = 8; $counter > 1; $counter--) { $search = str_repeat('0000:', $counter); if (($pos = strpos($address, $search)) !== FALSE) { $address = substr($address, 0, $pos) . ':' . substr($address, $pos + ($counter*5)); break; } } // up to 3 zeros in the first part may be removed $address = preg_replace('/^0{1,3}/', '', $address); // up to 3 zeros at the beginning of other parts may be removed $address = preg_replace('/:0{1,3}/', ':', $address); // strip last colon (from chunk_split) $address = substr($address, 0, -1); } return $address; }
php
public static function compressIPv6($address) { // use PHP-function if PHP was compiled with IPv6-support if (defined('AF_INET6')) { $bin = inet_pton($address); $address = inet_ntop($bin); } else { $address = self::normalizeIPv6($address); // append one colon for easier handling // will be removed later $address .= ':'; // according to IPv6-notation the longest match // of a package of '0000:' may be replaced with ':' // (resulting in something like '1234::abcd') for ($counter = 8; $counter > 1; $counter--) { $search = str_repeat('0000:', $counter); if (($pos = strpos($address, $search)) !== FALSE) { $address = substr($address, 0, $pos) . ':' . substr($address, $pos + ($counter*5)); break; } } // up to 3 zeros in the first part may be removed $address = preg_replace('/^0{1,3}/', '', $address); // up to 3 zeros at the beginning of other parts may be removed $address = preg_replace('/:0{1,3}/', ':', $address); // strip last colon (from chunk_split) $address = substr($address, 0, -1); } return $address; }
[ "public", "static", "function", "compressIPv6", "(", "$", "address", ")", "{", "// use PHP-function if PHP was compiled with IPv6-support", "if", "(", "defined", "(", "'AF_INET6'", ")", ")", "{", "$", "bin", "=", "inet_pton", "(", "$", "address", ")", ";", "$", "address", "=", "inet_ntop", "(", "$", "bin", ")", ";", "}", "else", "{", "$", "address", "=", "self", "::", "normalizeIPv6", "(", "$", "address", ")", ";", "// append one colon for easier handling", "// will be removed later", "$", "address", ".=", "':'", ";", "// according to IPv6-notation the longest match", "// of a package of '0000:' may be replaced with ':'", "// (resulting in something like '1234::abcd')", "for", "(", "$", "counter", "=", "8", ";", "$", "counter", ">", "1", ";", "$", "counter", "--", ")", "{", "$", "search", "=", "str_repeat", "(", "'0000:'", ",", "$", "counter", ")", ";", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "address", ",", "$", "search", ")", ")", "!==", "FALSE", ")", "{", "$", "address", "=", "substr", "(", "$", "address", ",", "0", ",", "$", "pos", ")", ".", "':'", ".", "substr", "(", "$", "address", ",", "$", "pos", "+", "(", "$", "counter", "*", "5", ")", ")", ";", "break", ";", "}", "}", "// up to 3 zeros in the first part may be removed", "$", "address", "=", "preg_replace", "(", "'/^0{1,3}/'", ",", "''", ",", "$", "address", ")", ";", "// up to 3 zeros at the beginning of other parts may be removed", "$", "address", "=", "preg_replace", "(", "'/:0{1,3}/'", ",", "':'", ",", "$", "address", ")", ";", "// strip last colon (from chunk_split)", "$", "address", "=", "substr", "(", "$", "address", ",", "0", ",", "-", "1", ")", ";", "}", "return", "$", "address", ";", "}" ]
Compress an IPv6 address to the shortest notation @param string $address Given IPv6 address @return string Compressed address @see normalizeIPv6()
[ "Compress", "an", "IPv6", "address", "to", "the", "shortest", "notation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L652-L684
220,450
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.cmpFQDN
public static function cmpFQDN($baseHost, $list) { $baseHost = trim($baseHost); if (empty($baseHost)) { return FALSE; } if (self::validIPv4($baseHost) || self::validIPv6($baseHost)) { // resolve hostname // note: this is reverse-lookup and can be randomly set as soon as somebody is able to set // the reverse-DNS for his IP (security when for example used with REMOTE_ADDR) $baseHostName = gethostbyaddr($baseHost); if ($baseHostName === $baseHost) { // unable to resolve hostname return FALSE; } } else { $baseHostName = $baseHost; } $baseHostNameParts = explode('.', $baseHostName); $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $hostNameParts = explode('.', $test); // to match hostNameParts can only be shorter (in case of wildcards) or equal if (count($hostNameParts) > count($baseHostNameParts)) { continue; } $yes = TRUE; foreach ($hostNameParts as $index => $val) { $val = trim($val); if ($val === '*') { // wildcard valid for one or more hostname-parts $wildcardStart = $index + 1; // wildcard as last/only part always matches, otherwise perform recursive checks if ($wildcardStart < count($hostNameParts)) { $wildcardMatched = FALSE; $tempHostName = implode('.', array_slice($hostNameParts, $index + 1)); while (($wildcardStart < count($baseHostNameParts)) && (!$wildcardMatched)) { $tempBaseHostName = implode('.', array_slice($baseHostNameParts, $wildcardStart)); $wildcardMatched = self::cmpFQDN($tempBaseHostName, $tempHostName); $wildcardStart++; } if ($wildcardMatched) { // match found by recursive compare return TRUE; } else { $yes = FALSE; } } } elseif ($baseHostNameParts[$index] !== $val) { // in case of no match $yes = FALSE; } } if ($yes) { return TRUE; } } return FALSE; }
php
public static function cmpFQDN($baseHost, $list) { $baseHost = trim($baseHost); if (empty($baseHost)) { return FALSE; } if (self::validIPv4($baseHost) || self::validIPv6($baseHost)) { // resolve hostname // note: this is reverse-lookup and can be randomly set as soon as somebody is able to set // the reverse-DNS for his IP (security when for example used with REMOTE_ADDR) $baseHostName = gethostbyaddr($baseHost); if ($baseHostName === $baseHost) { // unable to resolve hostname return FALSE; } } else { $baseHostName = $baseHost; } $baseHostNameParts = explode('.', $baseHostName); $values = self::trimExplode(',', $list, 1); foreach ($values as $test) { $hostNameParts = explode('.', $test); // to match hostNameParts can only be shorter (in case of wildcards) or equal if (count($hostNameParts) > count($baseHostNameParts)) { continue; } $yes = TRUE; foreach ($hostNameParts as $index => $val) { $val = trim($val); if ($val === '*') { // wildcard valid for one or more hostname-parts $wildcardStart = $index + 1; // wildcard as last/only part always matches, otherwise perform recursive checks if ($wildcardStart < count($hostNameParts)) { $wildcardMatched = FALSE; $tempHostName = implode('.', array_slice($hostNameParts, $index + 1)); while (($wildcardStart < count($baseHostNameParts)) && (!$wildcardMatched)) { $tempBaseHostName = implode('.', array_slice($baseHostNameParts, $wildcardStart)); $wildcardMatched = self::cmpFQDN($tempBaseHostName, $tempHostName); $wildcardStart++; } if ($wildcardMatched) { // match found by recursive compare return TRUE; } else { $yes = FALSE; } } } elseif ($baseHostNameParts[$index] !== $val) { // in case of no match $yes = FALSE; } } if ($yes) { return TRUE; } } return FALSE; }
[ "public", "static", "function", "cmpFQDN", "(", "$", "baseHost", ",", "$", "list", ")", "{", "$", "baseHost", "=", "trim", "(", "$", "baseHost", ")", ";", "if", "(", "empty", "(", "$", "baseHost", ")", ")", "{", "return", "FALSE", ";", "}", "if", "(", "self", "::", "validIPv4", "(", "$", "baseHost", ")", "||", "self", "::", "validIPv6", "(", "$", "baseHost", ")", ")", "{", "// resolve hostname", "// note: this is reverse-lookup and can be randomly set as soon as somebody is able to set", "// the reverse-DNS for his IP (security when for example used with REMOTE_ADDR)", "$", "baseHostName", "=", "gethostbyaddr", "(", "$", "baseHost", ")", ";", "if", "(", "$", "baseHostName", "===", "$", "baseHost", ")", "{", "// unable to resolve hostname", "return", "FALSE", ";", "}", "}", "else", "{", "$", "baseHostName", "=", "$", "baseHost", ";", "}", "$", "baseHostNameParts", "=", "explode", "(", "'.'", ",", "$", "baseHostName", ")", ";", "$", "values", "=", "self", "::", "trimExplode", "(", "','", ",", "$", "list", ",", "1", ")", ";", "foreach", "(", "$", "values", "as", "$", "test", ")", "{", "$", "hostNameParts", "=", "explode", "(", "'.'", ",", "$", "test", ")", ";", "// to match hostNameParts can only be shorter (in case of wildcards) or equal", "if", "(", "count", "(", "$", "hostNameParts", ")", ">", "count", "(", "$", "baseHostNameParts", ")", ")", "{", "continue", ";", "}", "$", "yes", "=", "TRUE", ";", "foreach", "(", "$", "hostNameParts", "as", "$", "index", "=>", "$", "val", ")", "{", "$", "val", "=", "trim", "(", "$", "val", ")", ";", "if", "(", "$", "val", "===", "'*'", ")", "{", "// wildcard valid for one or more hostname-parts", "$", "wildcardStart", "=", "$", "index", "+", "1", ";", "// wildcard as last/only part always matches, otherwise perform recursive checks", "if", "(", "$", "wildcardStart", "<", "count", "(", "$", "hostNameParts", ")", ")", "{", "$", "wildcardMatched", "=", "FALSE", ";", "$", "tempHostName", "=", "implode", "(", "'.'", ",", "array_slice", "(", "$", "hostNameParts", ",", "$", "index", "+", "1", ")", ")", ";", "while", "(", "(", "$", "wildcardStart", "<", "count", "(", "$", "baseHostNameParts", ")", ")", "&&", "(", "!", "$", "wildcardMatched", ")", ")", "{", "$", "tempBaseHostName", "=", "implode", "(", "'.'", ",", "array_slice", "(", "$", "baseHostNameParts", ",", "$", "wildcardStart", ")", ")", ";", "$", "wildcardMatched", "=", "self", "::", "cmpFQDN", "(", "$", "tempBaseHostName", ",", "$", "tempHostName", ")", ";", "$", "wildcardStart", "++", ";", "}", "if", "(", "$", "wildcardMatched", ")", "{", "// match found by recursive compare", "return", "TRUE", ";", "}", "else", "{", "$", "yes", "=", "FALSE", ";", "}", "}", "}", "elseif", "(", "$", "baseHostNameParts", "[", "$", "index", "]", "!==", "$", "val", ")", "{", "// in case of no match", "$", "yes", "=", "FALSE", ";", "}", "}", "if", "(", "$", "yes", ")", "{", "return", "TRUE", ";", "}", "}", "return", "FALSE", ";", "}" ]
Match fully qualified domain name with list of strings with wildcard @param string $baseHost A hostname or an IPv4/IPv6-address (will by reverse-resolved; typically REMOTE_ADDR) @param string $list A comma-list of domain names to match with. *-wildcard allowed but cannot be part of a string, so it must match the full host name (eg. myhost.*.com => correct, myhost.*domain.com => wrong) @return boolean TRUE if a domain name mask from $list matches $baseIP
[ "Match", "fully", "qualified", "domain", "name", "with", "list", "of", "strings", "with", "wildcard" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L729-L791
220,451
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.rmFromList
public static function rmFromList($element, $list) { $items = explode(',', $list); foreach ($items as $k => $v) { if ($v == $element) { unset($items[$k]); } } return implode(',', $items); }
php
public static function rmFromList($element, $list) { $items = explode(',', $list); foreach ($items as $k => $v) { if ($v == $element) { unset($items[$k]); } } return implode(',', $items); }
[ "public", "static", "function", "rmFromList", "(", "$", "element", ",", "$", "list", ")", "{", "$", "items", "=", "explode", "(", "','", ",", "$", "list", ")", ";", "foreach", "(", "$", "items", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "==", "$", "element", ")", "{", "unset", "(", "$", "items", "[", "$", "k", "]", ")", ";", "}", "}", "return", "implode", "(", "','", ",", "$", "items", ")", ";", "}" ]
Removes an item from a comma-separated list of items. @param string $element element to remove @param string $list comma-separated list of items (string) @return string new comma-separated list of items
[ "Removes", "an", "item", "from", "a", "comma", "-", "separated", "list", "of", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L823-L831
220,452
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.int_from_ver
public static function int_from_ver($verNumberStr) { // Deprecation log is activated only for TYPO3 4.7 and above if (t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version) >= 4007000) { self::logDeprecatedFunction(); } return t3lib_utility_VersionNumber::convertVersionNumberToInteger($verNumberStr); }
php
public static function int_from_ver($verNumberStr) { // Deprecation log is activated only for TYPO3 4.7 and above if (t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version) >= 4007000) { self::logDeprecatedFunction(); } return t3lib_utility_VersionNumber::convertVersionNumberToInteger($verNumberStr); }
[ "public", "static", "function", "int_from_ver", "(", "$", "verNumberStr", ")", "{", "// Deprecation log is activated only for TYPO3 4.7 and above", "if", "(", "t3lib_utility_VersionNumber", "::", "convertVersionNumberToInteger", "(", "TYPO3_version", ")", ">=", "4007000", ")", "{", "self", "::", "logDeprecatedFunction", "(", ")", ";", "}", "return", "t3lib_utility_VersionNumber", "::", "convertVersionNumberToInteger", "(", "$", "verNumberStr", ")", ";", "}" ]
Returns an integer from a three part version number, eg '4.12.3' -> 4012003 @param string $verNumberStr Version number on format x.x.x @return integer Integer version of version number (where each part can count to 999) @deprecated since TYPO3 4.6, will be removed in TYPO3 6.1 - Use t3lib_utility_VersionNumber::convertVersionNumberToInteger() instead
[ "Returns", "an", "integer", "from", "a", "three", "part", "version", "number", "eg", "4", ".", "12", ".", "3", "-", ">", "4012003" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L896-L902
220,453
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.hmac
public static function hmac($input, $additionalSecret = '') { $hashAlgorithm = 'sha1'; $hashBlocksize = 64; $hmac = ''; $secret = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . $additionalSecret; if (extension_loaded('hash') && function_exists('hash_hmac') && function_exists('hash_algos') && in_array($hashAlgorithm, hash_algos())) { $hmac = hash_hmac($hashAlgorithm, $input, $secret); } else { // outer padding $opad = str_repeat(chr(0x5C), $hashBlocksize); // inner padding $ipad = str_repeat(chr(0x36), $hashBlocksize); if (strlen($secret) > $hashBlocksize) { // keys longer than block size are shorten $key = str_pad(pack('H*', call_user_func($hashAlgorithm, $secret)), $hashBlocksize, chr(0)); } else { // keys shorter than block size are zero-padded $key = str_pad($secret, $hashBlocksize, chr(0)); } $hmac = call_user_func($hashAlgorithm, ($key ^ $opad) . pack('H*', call_user_func($hashAlgorithm, ($key ^ $ipad) . $input))); } return $hmac; }
php
public static function hmac($input, $additionalSecret = '') { $hashAlgorithm = 'sha1'; $hashBlocksize = 64; $hmac = ''; $secret = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . $additionalSecret; if (extension_loaded('hash') && function_exists('hash_hmac') && function_exists('hash_algos') && in_array($hashAlgorithm, hash_algos())) { $hmac = hash_hmac($hashAlgorithm, $input, $secret); } else { // outer padding $opad = str_repeat(chr(0x5C), $hashBlocksize); // inner padding $ipad = str_repeat(chr(0x36), $hashBlocksize); if (strlen($secret) > $hashBlocksize) { // keys longer than block size are shorten $key = str_pad(pack('H*', call_user_func($hashAlgorithm, $secret)), $hashBlocksize, chr(0)); } else { // keys shorter than block size are zero-padded $key = str_pad($secret, $hashBlocksize, chr(0)); } $hmac = call_user_func($hashAlgorithm, ($key ^ $opad) . pack('H*', call_user_func($hashAlgorithm, ($key ^ $ipad) . $input))); } return $hmac; }
[ "public", "static", "function", "hmac", "(", "$", "input", ",", "$", "additionalSecret", "=", "''", ")", "{", "$", "hashAlgorithm", "=", "'sha1'", ";", "$", "hashBlocksize", "=", "64", ";", "$", "hmac", "=", "''", ";", "$", "secret", "=", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'encryptionKey'", "]", ".", "$", "additionalSecret", ";", "if", "(", "extension_loaded", "(", "'hash'", ")", "&&", "function_exists", "(", "'hash_hmac'", ")", "&&", "function_exists", "(", "'hash_algos'", ")", "&&", "in_array", "(", "$", "hashAlgorithm", ",", "hash_algos", "(", ")", ")", ")", "{", "$", "hmac", "=", "hash_hmac", "(", "$", "hashAlgorithm", ",", "$", "input", ",", "$", "secret", ")", ";", "}", "else", "{", "// outer padding", "$", "opad", "=", "str_repeat", "(", "chr", "(", "0x5C", ")", ",", "$", "hashBlocksize", ")", ";", "// inner padding", "$", "ipad", "=", "str_repeat", "(", "chr", "(", "0x36", ")", ",", "$", "hashBlocksize", ")", ";", "if", "(", "strlen", "(", "$", "secret", ")", ">", "$", "hashBlocksize", ")", "{", "// keys longer than block size are shorten", "$", "key", "=", "str_pad", "(", "pack", "(", "'H*'", ",", "call_user_func", "(", "$", "hashAlgorithm", ",", "$", "secret", ")", ")", ",", "$", "hashBlocksize", ",", "chr", "(", "0", ")", ")", ";", "}", "else", "{", "// keys shorter than block size are zero-padded", "$", "key", "=", "str_pad", "(", "$", "secret", ",", "$", "hashBlocksize", ",", "chr", "(", "0", ")", ")", ";", "}", "$", "hmac", "=", "call_user_func", "(", "$", "hashAlgorithm", ",", "(", "$", "key", "^", "$", "opad", ")", ".", "pack", "(", "'H*'", ",", "call_user_func", "(", "$", "hashAlgorithm", ",", "(", "$", "key", "^", "$", "ipad", ")", ".", "$", "input", ")", ")", ")", ";", "}", "return", "$", "hmac", ";", "}" ]
Returns a proper HMAC on a given input string and secret TYPO3 encryption key. @param string $input Input string to create HMAC from @param string $additionalSecret additionalSecret to prevent hmac beeing used in a different context @return string resulting (hexadecimal) HMAC currently with a length of 40 (HMAC-SHA-1)
[ "Returns", "a", "proper", "HMAC", "on", "a", "given", "input", "string", "and", "secret", "TYPO3", "encryption", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L950-L972
220,454
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.split_fileref
public static function split_fileref($fileref) { $reg = array(); if (preg_match('/(.*\/)(.*)$/', $fileref, $reg)) { $info['path'] = $reg[1]; $info['file'] = $reg[2]; } else { $info['path'] = ''; $info['file'] = $fileref; } $reg = ''; if (!is_dir($fileref) && preg_match('/(.*)\.([^\.]*$)/', $info['file'], $reg)) { $info['filebody'] = $reg[1]; $info['fileext'] = strtolower($reg[2]); $info['realFileext'] = $reg[2]; } else { $info['filebody'] = $info['file']; $info['fileext'] = ''; } reset($info); return $info; }
php
public static function split_fileref($fileref) { $reg = array(); if (preg_match('/(.*\/)(.*)$/', $fileref, $reg)) { $info['path'] = $reg[1]; $info['file'] = $reg[2]; } else { $info['path'] = ''; $info['file'] = $fileref; } $reg = ''; if (!is_dir($fileref) && preg_match('/(.*)\.([^\.]*$)/', $info['file'], $reg)) { $info['filebody'] = $reg[1]; $info['fileext'] = strtolower($reg[2]); $info['realFileext'] = $reg[2]; } else { $info['filebody'] = $info['file']; $info['fileext'] = ''; } reset($info); return $info; }
[ "public", "static", "function", "split_fileref", "(", "$", "fileref", ")", "{", "$", "reg", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/(.*\\/)(.*)$/'", ",", "$", "fileref", ",", "$", "reg", ")", ")", "{", "$", "info", "[", "'path'", "]", "=", "$", "reg", "[", "1", "]", ";", "$", "info", "[", "'file'", "]", "=", "$", "reg", "[", "2", "]", ";", "}", "else", "{", "$", "info", "[", "'path'", "]", "=", "''", ";", "$", "info", "[", "'file'", "]", "=", "$", "fileref", ";", "}", "$", "reg", "=", "''", ";", "if", "(", "!", "is_dir", "(", "$", "fileref", ")", "&&", "preg_match", "(", "'/(.*)\\.([^\\.]*$)/'", ",", "$", "info", "[", "'file'", "]", ",", "$", "reg", ")", ")", "{", "$", "info", "[", "'filebody'", "]", "=", "$", "reg", "[", "1", "]", ";", "$", "info", "[", "'fileext'", "]", "=", "strtolower", "(", "$", "reg", "[", "2", "]", ")", ";", "$", "info", "[", "'realFileext'", "]", "=", "$", "reg", "[", "2", "]", ";", "}", "else", "{", "$", "info", "[", "'filebody'", "]", "=", "$", "info", "[", "'file'", "]", ";", "$", "info", "[", "'fileext'", "]", "=", "''", ";", "}", "reset", "(", "$", "info", ")", ";", "return", "$", "info", ";", "}" ]
Splits a reference to a file in 5 parts @param string $fileref Filename/filepath to be analysed @return array Contains keys [path], [file], [filebody], [fileext], [realFileext]
[ "Splits", "a", "reference", "to", "a", "file", "in", "5", "parts" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1005-L1026
220,455
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.slashJS
public static function slashJS($string, $extended = FALSE, $char = "'") { if ($extended) { $string = str_replace("\\", "\\\\", $string); } return str_replace($char, "\\" . $char, $string); }
php
public static function slashJS($string, $extended = FALSE, $char = "'") { if ($extended) { $string = str_replace("\\", "\\\\", $string); } return str_replace($char, "\\" . $char, $string); }
[ "public", "static", "function", "slashJS", "(", "$", "string", ",", "$", "extended", "=", "FALSE", ",", "$", "char", "=", "\"'\"", ")", "{", "if", "(", "$", "extended", ")", "{", "$", "string", "=", "str_replace", "(", "\"\\\\\"", ",", "\"\\\\\\\\\"", ",", "$", "string", ")", ";", "}", "return", "str_replace", "(", "$", "char", ",", "\"\\\\\"", ".", "$", "char", ",", "$", "string", ")", ";", "}" ]
This function is used to escape any ' -characters when transferring text to JavaScript! @param string $string String to escape @param boolean $extended If set, also backslashes are escaped. @param string $char The character to escape, default is ' (single-quote) @return string Processed input string
[ "This", "function", "is", "used", "to", "escape", "any", "-", "characters", "when", "transferring", "text", "to", "JavaScript!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1233-L1238
220,456
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.validEmail
public static function validEmail($email) { // enforce maximum length to prevent libpcre recursion crash bug #52929 in PHP // fixed in PHP 5.3.4; length restriction per SMTP RFC 2821 if (strlen($email) > 320) { return FALSE; } require_once(PATH_typo3 . 'contrib/idna/idna_convert.class.php'); $IDN = new idna_convert(array('idn_version' => 2008)); return (filter_var($IDN->encode($email), FILTER_VALIDATE_EMAIL) !== FALSE); }
php
public static function validEmail($email) { // enforce maximum length to prevent libpcre recursion crash bug #52929 in PHP // fixed in PHP 5.3.4; length restriction per SMTP RFC 2821 if (strlen($email) > 320) { return FALSE; } require_once(PATH_typo3 . 'contrib/idna/idna_convert.class.php'); $IDN = new idna_convert(array('idn_version' => 2008)); return (filter_var($IDN->encode($email), FILTER_VALIDATE_EMAIL) !== FALSE); }
[ "public", "static", "function", "validEmail", "(", "$", "email", ")", "{", "// enforce maximum length to prevent libpcre recursion crash bug #52929 in PHP", "// fixed in PHP 5.3.4; length restriction per SMTP RFC 2821", "if", "(", "strlen", "(", "$", "email", ")", ">", "320", ")", "{", "return", "FALSE", ";", "}", "require_once", "(", "PATH_typo3", ".", "'contrib/idna/idna_convert.class.php'", ")", ";", "$", "IDN", "=", "new", "idna_convert", "(", "array", "(", "'idn_version'", "=>", "2008", ")", ")", ";", "return", "(", "filter_var", "(", "$", "IDN", "->", "encode", "(", "$", "email", ")", ",", "FILTER_VALIDATE_EMAIL", ")", "!==", "FALSE", ")", ";", "}" ]
Checking syntax of input email address @param string $email Input string to evaluate @return boolean Returns TRUE if the $email address (input string) is valid
[ "Checking", "syntax", "of", "input", "email", "address" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1268-L1278
220,457
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.generateRandomBytesFallback
protected static function generateRandomBytesFallback($bytesToReturn) { $bytes = ''; // We initialize with somewhat random. $randomState = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . base_convert(memory_get_usage() % pow(10, 6), 10, 2) . microtime() . uniqid('') . getmypid(); while (!isset($bytes{$bytesToReturn - 1})) { $randomState = sha1(microtime() . mt_rand() . $randomState); $bytes .= sha1(mt_rand() . $randomState, TRUE); } return $bytes; }
php
protected static function generateRandomBytesFallback($bytesToReturn) { $bytes = ''; // We initialize with somewhat random. $randomState = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . base_convert(memory_get_usage() % pow(10, 6), 10, 2) . microtime() . uniqid('') . getmypid(); while (!isset($bytes{$bytesToReturn - 1})) { $randomState = sha1(microtime() . mt_rand() . $randomState); $bytes .= sha1(mt_rand() . $randomState, TRUE); } return $bytes; }
[ "protected", "static", "function", "generateRandomBytesFallback", "(", "$", "bytesToReturn", ")", "{", "$", "bytes", "=", "''", ";", "// We initialize with somewhat random.", "$", "randomState", "=", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'encryptionKey'", "]", ".", "base_convert", "(", "memory_get_usage", "(", ")", "%", "pow", "(", "10", ",", "6", ")", ",", "10", ",", "2", ")", ".", "microtime", "(", ")", ".", "uniqid", "(", "''", ")", ".", "getmypid", "(", ")", ";", "while", "(", "!", "isset", "(", "$", "bytes", "{", "$", "bytesToReturn", "-", "1", "}", ")", ")", "{", "$", "randomState", "=", "sha1", "(", "microtime", "(", ")", ".", "mt_rand", "(", ")", ".", "$", "randomState", ")", ";", "$", "bytes", ".=", "sha1", "(", "mt_rand", "(", ")", ".", "$", "randomState", ",", "TRUE", ")", ";", "}", "return", "$", "bytes", ";", "}" ]
Generate pseudo random bytes as last resort @param $bytesToReturn @return string
[ "Generate", "pseudo", "random", "bytes", "as", "last", "resort" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1452-L1461
220,458
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.addSlashesOnArray
public static function addSlashesOnArray(array &$theArray) { foreach ($theArray as &$value) { if (is_array($value)) { self::addSlashesOnArray($value); } else { $value = addslashes($value); } } unset($value); reset($theArray); }
php
public static function addSlashesOnArray(array &$theArray) { foreach ($theArray as &$value) { if (is_array($value)) { self::addSlashesOnArray($value); } else { $value = addslashes($value); } } unset($value); reset($theArray); }
[ "public", "static", "function", "addSlashesOnArray", "(", "array", "&", "$", "theArray", ")", "{", "foreach", "(", "$", "theArray", "as", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "self", "::", "addSlashesOnArray", "(", "$", "value", ")", ";", "}", "else", "{", "$", "value", "=", "addslashes", "(", "$", "value", ")", ";", "}", "}", "unset", "(", "$", "value", ")", ";", "reset", "(", "$", "theArray", ")", ";", "}" ]
AddSlash array This function traverses a multidimensional array and adds slashes to the values. NOTE that the input array is and argument by reference.!! Twin-function to stripSlashesOnArray @param array $theArray Multidimensional input array, (REFERENCE!) @return array
[ "AddSlash", "array", "This", "function", "traverses", "a", "multidimensional", "array", "and", "adds", "slashes", "to", "the", "values", ".", "NOTE", "that", "the", "input", "array", "is", "and", "argument", "by", "reference", ".", "!!", "Twin", "-", "function", "to", "stripSlashesOnArray" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1792-L1802
220,459
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.stripSlashesOnArray
public static function stripSlashesOnArray(array &$theArray) { foreach ($theArray as &$value) { if (is_array($value)) { self::stripSlashesOnArray($value); } else { $value = stripslashes($value); } } unset($value); reset($theArray); }
php
public static function stripSlashesOnArray(array &$theArray) { foreach ($theArray as &$value) { if (is_array($value)) { self::stripSlashesOnArray($value); } else { $value = stripslashes($value); } } unset($value); reset($theArray); }
[ "public", "static", "function", "stripSlashesOnArray", "(", "array", "&", "$", "theArray", ")", "{", "foreach", "(", "$", "theArray", "as", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "self", "::", "stripSlashesOnArray", "(", "$", "value", ")", ";", "}", "else", "{", "$", "value", "=", "stripslashes", "(", "$", "value", ")", ";", "}", "}", "unset", "(", "$", "value", ")", ";", "reset", "(", "$", "theArray", ")", ";", "}" ]
StripSlash array This function traverses a multidimensional array and strips slashes to the values. NOTE that the input array is and argument by reference.!! Twin-function to addSlashesOnArray @param array $theArray Multidimensional input array, (REFERENCE!) @return array
[ "StripSlash", "array", "This", "function", "traverses", "a", "multidimensional", "array", "and", "strips", "slashes", "to", "the", "values", ".", "NOTE", "that", "the", "input", "array", "is", "and", "argument", "by", "reference", ".", "!!", "Twin", "-", "function", "to", "addSlashesOnArray" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1813-L1823
220,460
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.remapArrayKeys
public static function remapArrayKeys(&$array, $mappingTable) { if (is_array($mappingTable)) { foreach ($mappingTable as $old => $new) { if ($new && isset($array[$old])) { $array[$new] = $array[$old]; unset ($array[$old]); } } } }
php
public static function remapArrayKeys(&$array, $mappingTable) { if (is_array($mappingTable)) { foreach ($mappingTable as $old => $new) { if ($new && isset($array[$old])) { $array[$new] = $array[$old]; unset ($array[$old]); } } } }
[ "public", "static", "function", "remapArrayKeys", "(", "&", "$", "array", ",", "$", "mappingTable", ")", "{", "if", "(", "is_array", "(", "$", "mappingTable", ")", ")", "{", "foreach", "(", "$", "mappingTable", "as", "$", "old", "=>", "$", "new", ")", "{", "if", "(", "$", "new", "&&", "isset", "(", "$", "array", "[", "$", "old", "]", ")", ")", "{", "$", "array", "[", "$", "new", "]", "=", "$", "array", "[", "$", "old", "]", ";", "unset", "(", "$", "array", "[", "$", "old", "]", ")", ";", "}", "}", "}", "}" ]
Rename Array keys with a given mapping table @param array $array Array by reference which should be remapped @param array $mappingTable Array with remap information, array/$oldKey => $newKey)
[ "Rename", "Array", "keys", "with", "a", "given", "mapping", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L1848-L1857
220,461
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.split_tag_attributes
public static function split_tag_attributes($tag) { $tag_tmp = trim(preg_replace('/^<[^[:space:]]*/', '', trim($tag))); // Removes any > in the end of the string $tag_tmp = trim(rtrim($tag_tmp, '>')); $value = array(); while (strcmp($tag_tmp, '')) { // Compared with empty string instead , 030102 $firstChar = substr($tag_tmp, 0, 1); if (!strcmp($firstChar, '"') || !strcmp($firstChar, "'")) { $reg = explode($firstChar, $tag_tmp, 3); $value[] = $reg[1]; $tag_tmp = trim($reg[2]); } elseif (!strcmp($firstChar, '=')) { $value[] = '='; $tag_tmp = trim(substr($tag_tmp, 1)); // Removes = chars. } else { // There are '' around the value. We look for the next ' ' or '>' $reg = preg_split('/[[:space:]=]/', $tag_tmp, 2); $value[] = trim($reg[0]); $tag_tmp = trim(substr($tag_tmp, strlen($reg[0]), 1) . $reg[1]); } } reset($value); return $value; }
php
public static function split_tag_attributes($tag) { $tag_tmp = trim(preg_replace('/^<[^[:space:]]*/', '', trim($tag))); // Removes any > in the end of the string $tag_tmp = trim(rtrim($tag_tmp, '>')); $value = array(); while (strcmp($tag_tmp, '')) { // Compared with empty string instead , 030102 $firstChar = substr($tag_tmp, 0, 1); if (!strcmp($firstChar, '"') || !strcmp($firstChar, "'")) { $reg = explode($firstChar, $tag_tmp, 3); $value[] = $reg[1]; $tag_tmp = trim($reg[2]); } elseif (!strcmp($firstChar, '=')) { $value[] = '='; $tag_tmp = trim(substr($tag_tmp, 1)); // Removes = chars. } else { // There are '' around the value. We look for the next ' ' or '>' $reg = preg_split('/[[:space:]=]/', $tag_tmp, 2); $value[] = trim($reg[0]); $tag_tmp = trim(substr($tag_tmp, strlen($reg[0]), 1) . $reg[1]); } } reset($value); return $value; }
[ "public", "static", "function", "split_tag_attributes", "(", "$", "tag", ")", "{", "$", "tag_tmp", "=", "trim", "(", "preg_replace", "(", "'/^<[^[:space:]]*/'", ",", "''", ",", "trim", "(", "$", "tag", ")", ")", ")", ";", "// Removes any > in the end of the string", "$", "tag_tmp", "=", "trim", "(", "rtrim", "(", "$", "tag_tmp", ",", "'>'", ")", ")", ";", "$", "value", "=", "array", "(", ")", ";", "while", "(", "strcmp", "(", "$", "tag_tmp", ",", "''", ")", ")", "{", "// Compared with empty string instead , 030102", "$", "firstChar", "=", "substr", "(", "$", "tag_tmp", ",", "0", ",", "1", ")", ";", "if", "(", "!", "strcmp", "(", "$", "firstChar", ",", "'\"'", ")", "||", "!", "strcmp", "(", "$", "firstChar", ",", "\"'\"", ")", ")", "{", "$", "reg", "=", "explode", "(", "$", "firstChar", ",", "$", "tag_tmp", ",", "3", ")", ";", "$", "value", "[", "]", "=", "$", "reg", "[", "1", "]", ";", "$", "tag_tmp", "=", "trim", "(", "$", "reg", "[", "2", "]", ")", ";", "}", "elseif", "(", "!", "strcmp", "(", "$", "firstChar", ",", "'='", ")", ")", "{", "$", "value", "[", "]", "=", "'='", ";", "$", "tag_tmp", "=", "trim", "(", "substr", "(", "$", "tag_tmp", ",", "1", ")", ")", ";", "// Removes = chars.", "}", "else", "{", "// There are '' around the value. We look for the next ' ' or '>'", "$", "reg", "=", "preg_split", "(", "'/[[:space:]=]/'", ",", "$", "tag_tmp", ",", "2", ")", ";", "$", "value", "[", "]", "=", "trim", "(", "$", "reg", "[", "0", "]", ")", ";", "$", "tag_tmp", "=", "trim", "(", "substr", "(", "$", "tag_tmp", ",", "strlen", "(", "$", "reg", "[", "0", "]", ")", ",", "1", ")", ".", "$", "reg", "[", "1", "]", ")", ";", "}", "}", "reset", "(", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
Returns an array with the 'components' from an attribute list from an HTML tag. The result is normally analyzed by get_tag_attributes Removes tag-name if found @param string $tag HTML-tag string (or attributes only) @return array Array with the attribute values.
[ "Returns", "an", "array", "with", "the", "components", "from", "an", "attribute", "list", "from", "an", "HTML", "tag", ".", "The", "result", "is", "normally", "analyzed", "by", "get_tag_attributes", "Removes", "tag", "-", "name", "if", "found" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L2037-L2061
220,462
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.xml2tree
public static function xml2tree($string, $depth = 999) { $parser = xml_parser_create(); $vals = array(); $index = array(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_parse_into_struct($parser, $string, $vals, $index); if (xml_get_error_code($parser)) { return 'Line ' . xml_get_current_line_number($parser) . ': ' . xml_error_string(xml_get_error_code($parser)); } xml_parser_free($parser); $stack = array(array()); $stacktop = 0; $startPoint = 0; $tagi = array(); foreach ($vals as $key => $val) { $type = $val['type']; // open tag: if ($type == 'open' || $type == 'complete') { $stack[$stacktop++] = $tagi; if ($depth == $stacktop) { $startPoint = $key; } $tagi = array('tag' => $val['tag']); if (isset($val['attributes'])) { $tagi['attrs'] = $val['attributes']; } if (isset($val['value'])) { $tagi['values'][] = $val['value']; } } // finish tag: if ($type == 'complete' || $type == 'close') { $oldtagi = $tagi; $tagi = $stack[--$stacktop]; $oldtag = $oldtagi['tag']; unset($oldtagi['tag']); if ($depth == ($stacktop + 1)) { if ($key - $startPoint > 0) { $partArray = array_slice( $vals, $startPoint + 1, $key - $startPoint - 1 ); $oldtagi['XMLvalue'] = self::xmlRecompileFromStructValArray($partArray); } else { $oldtagi['XMLvalue'] = $oldtagi['values'][0]; } } $tagi['ch'][$oldtag][] = $oldtagi; unset($oldtagi); } // cdata if ($type == 'cdata') { $tagi['values'][] = $val['value']; } } return $tagi['ch']; }
php
public static function xml2tree($string, $depth = 999) { $parser = xml_parser_create(); $vals = array(); $index = array(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_parse_into_struct($parser, $string, $vals, $index); if (xml_get_error_code($parser)) { return 'Line ' . xml_get_current_line_number($parser) . ': ' . xml_error_string(xml_get_error_code($parser)); } xml_parser_free($parser); $stack = array(array()); $stacktop = 0; $startPoint = 0; $tagi = array(); foreach ($vals as $key => $val) { $type = $val['type']; // open tag: if ($type == 'open' || $type == 'complete') { $stack[$stacktop++] = $tagi; if ($depth == $stacktop) { $startPoint = $key; } $tagi = array('tag' => $val['tag']); if (isset($val['attributes'])) { $tagi['attrs'] = $val['attributes']; } if (isset($val['value'])) { $tagi['values'][] = $val['value']; } } // finish tag: if ($type == 'complete' || $type == 'close') { $oldtagi = $tagi; $tagi = $stack[--$stacktop]; $oldtag = $oldtagi['tag']; unset($oldtagi['tag']); if ($depth == ($stacktop + 1)) { if ($key - $startPoint > 0) { $partArray = array_slice( $vals, $startPoint + 1, $key - $startPoint - 1 ); $oldtagi['XMLvalue'] = self::xmlRecompileFromStructValArray($partArray); } else { $oldtagi['XMLvalue'] = $oldtagi['values'][0]; } } $tagi['ch'][$oldtag][] = $oldtagi; unset($oldtagi); } // cdata if ($type == 'cdata') { $tagi['values'][] = $val['value']; } } return $tagi['ch']; }
[ "public", "static", "function", "xml2tree", "(", "$", "string", ",", "$", "depth", "=", "999", ")", "{", "$", "parser", "=", "xml_parser_create", "(", ")", ";", "$", "vals", "=", "array", "(", ")", ";", "$", "index", "=", "array", "(", ")", ";", "xml_parser_set_option", "(", "$", "parser", ",", "XML_OPTION_CASE_FOLDING", ",", "0", ")", ";", "xml_parser_set_option", "(", "$", "parser", ",", "XML_OPTION_SKIP_WHITE", ",", "0", ")", ";", "xml_parse_into_struct", "(", "$", "parser", ",", "$", "string", ",", "$", "vals", ",", "$", "index", ")", ";", "if", "(", "xml_get_error_code", "(", "$", "parser", ")", ")", "{", "return", "'Line '", ".", "xml_get_current_line_number", "(", "$", "parser", ")", ".", "': '", ".", "xml_error_string", "(", "xml_get_error_code", "(", "$", "parser", ")", ")", ";", "}", "xml_parser_free", "(", "$", "parser", ")", ";", "$", "stack", "=", "array", "(", "array", "(", ")", ")", ";", "$", "stacktop", "=", "0", ";", "$", "startPoint", "=", "0", ";", "$", "tagi", "=", "array", "(", ")", ";", "foreach", "(", "$", "vals", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "type", "=", "$", "val", "[", "'type'", "]", ";", "// open tag:", "if", "(", "$", "type", "==", "'open'", "||", "$", "type", "==", "'complete'", ")", "{", "$", "stack", "[", "$", "stacktop", "++", "]", "=", "$", "tagi", ";", "if", "(", "$", "depth", "==", "$", "stacktop", ")", "{", "$", "startPoint", "=", "$", "key", ";", "}", "$", "tagi", "=", "array", "(", "'tag'", "=>", "$", "val", "[", "'tag'", "]", ")", ";", "if", "(", "isset", "(", "$", "val", "[", "'attributes'", "]", ")", ")", "{", "$", "tagi", "[", "'attrs'", "]", "=", "$", "val", "[", "'attributes'", "]", ";", "}", "if", "(", "isset", "(", "$", "val", "[", "'value'", "]", ")", ")", "{", "$", "tagi", "[", "'values'", "]", "[", "]", "=", "$", "val", "[", "'value'", "]", ";", "}", "}", "// finish tag:", "if", "(", "$", "type", "==", "'complete'", "||", "$", "type", "==", "'close'", ")", "{", "$", "oldtagi", "=", "$", "tagi", ";", "$", "tagi", "=", "$", "stack", "[", "--", "$", "stacktop", "]", ";", "$", "oldtag", "=", "$", "oldtagi", "[", "'tag'", "]", ";", "unset", "(", "$", "oldtagi", "[", "'tag'", "]", ")", ";", "if", "(", "$", "depth", "==", "(", "$", "stacktop", "+", "1", ")", ")", "{", "if", "(", "$", "key", "-", "$", "startPoint", ">", "0", ")", "{", "$", "partArray", "=", "array_slice", "(", "$", "vals", ",", "$", "startPoint", "+", "1", ",", "$", "key", "-", "$", "startPoint", "-", "1", ")", ";", "$", "oldtagi", "[", "'XMLvalue'", "]", "=", "self", "::", "xmlRecompileFromStructValArray", "(", "$", "partArray", ")", ";", "}", "else", "{", "$", "oldtagi", "[", "'XMLvalue'", "]", "=", "$", "oldtagi", "[", "'values'", "]", "[", "0", "]", ";", "}", "}", "$", "tagi", "[", "'ch'", "]", "[", "$", "oldtag", "]", "[", "]", "=", "$", "oldtagi", ";", "unset", "(", "$", "oldtagi", ")", ";", "}", "// cdata", "if", "(", "$", "type", "==", "'cdata'", ")", "{", "$", "tagi", "[", "'values'", "]", "[", "]", "=", "$", "val", "[", "'value'", "]", ";", "}", "}", "return", "$", "tagi", "[", "'ch'", "]", ";", "}" ]
Parses XML input into a PHP array with associative keys @param string $string XML data input @param integer $depth Number of element levels to resolve the XML into an array. Any further structure will be set as XML. @return mixed The array with the parsed structure unless the XML parser returns with an error in which case the error message string is returned. @author bisqwit at iki dot fi dot not dot for dot ads dot invalid / http://dk.php.net/xml_parse_into_struct + kasperYYYY@typo3.com
[ "Parses", "XML", "input", "into", "a", "PHP", "array", "with", "associative", "keys" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L2129-L2197
220,463
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.fixPermissions
public static function fixPermissions($path, $recursive = FALSE) { if (TYPO3_OS != 'WIN') { $result = FALSE; // Make path absolute if (!self::isAbsPath($path)) { $path = self::getFileAbsFileName($path, FALSE); } if (self::isAllowedAbsPath($path)) { if (@is_file($path)) { // "@" is there because file is not necessarily OWNED by the user $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'])); } elseif (@is_dir($path)) { // "@" is there because file is not necessarily OWNED by the user $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'])); } // Set createGroup if not empty if ($GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']) { // "@" is there because file is not necessarily OWNED by the user $changeGroupResult = @chgrp($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']); $result = $changeGroupResult ? $result : FALSE; } // Call recursive if recursive flag if set and $path is directory if ($recursive && @is_dir($path)) { $handle = opendir($path); while (($file = readdir($handle)) !== FALSE) { $recursionResult = NULL; if ($file !== '.' && $file !== '..') { if (@is_file($path . '/' . $file)) { $recursionResult = self::fixPermissions($path . '/' . $file); } elseif (@is_dir($path . '/' . $file)) { $recursionResult = self::fixPermissions($path . '/' . $file, TRUE); } if (isset($recursionResult) && !$recursionResult) { $result = FALSE; } } } closedir($handle); } } } else { $result = TRUE; } return $result; }
php
public static function fixPermissions($path, $recursive = FALSE) { if (TYPO3_OS != 'WIN') { $result = FALSE; // Make path absolute if (!self::isAbsPath($path)) { $path = self::getFileAbsFileName($path, FALSE); } if (self::isAllowedAbsPath($path)) { if (@is_file($path)) { // "@" is there because file is not necessarily OWNED by the user $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'])); } elseif (@is_dir($path)) { // "@" is there because file is not necessarily OWNED by the user $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'])); } // Set createGroup if not empty if ($GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']) { // "@" is there because file is not necessarily OWNED by the user $changeGroupResult = @chgrp($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup']); $result = $changeGroupResult ? $result : FALSE; } // Call recursive if recursive flag if set and $path is directory if ($recursive && @is_dir($path)) { $handle = opendir($path); while (($file = readdir($handle)) !== FALSE) { $recursionResult = NULL; if ($file !== '.' && $file !== '..') { if (@is_file($path . '/' . $file)) { $recursionResult = self::fixPermissions($path . '/' . $file); } elseif (@is_dir($path . '/' . $file)) { $recursionResult = self::fixPermissions($path . '/' . $file, TRUE); } if (isset($recursionResult) && !$recursionResult) { $result = FALSE; } } } closedir($handle); } } } else { $result = TRUE; } return $result; }
[ "public", "static", "function", "fixPermissions", "(", "$", "path", ",", "$", "recursive", "=", "FALSE", ")", "{", "if", "(", "TYPO3_OS", "!=", "'WIN'", ")", "{", "$", "result", "=", "FALSE", ";", "// Make path absolute", "if", "(", "!", "self", "::", "isAbsPath", "(", "$", "path", ")", ")", "{", "$", "path", "=", "self", "::", "getFileAbsFileName", "(", "$", "path", ",", "FALSE", ")", ";", "}", "if", "(", "self", "::", "isAllowedAbsPath", "(", "$", "path", ")", ")", "{", "if", "(", "@", "is_file", "(", "$", "path", ")", ")", "{", "// \"@\" is there because file is not necessarily OWNED by the user", "$", "result", "=", "@", "chmod", "(", "$", "path", ",", "octdec", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'fileCreateMask'", "]", ")", ")", ";", "}", "elseif", "(", "@", "is_dir", "(", "$", "path", ")", ")", "{", "// \"@\" is there because file is not necessarily OWNED by the user", "$", "result", "=", "@", "chmod", "(", "$", "path", ",", "octdec", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'folderCreateMask'", "]", ")", ")", ";", "}", "// Set createGroup if not empty", "if", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'createGroup'", "]", ")", "{", "// \"@\" is there because file is not necessarily OWNED by the user", "$", "changeGroupResult", "=", "@", "chgrp", "(", "$", "path", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'createGroup'", "]", ")", ";", "$", "result", "=", "$", "changeGroupResult", "?", "$", "result", ":", "FALSE", ";", "}", "// Call recursive if recursive flag if set and $path is directory", "if", "(", "$", "recursive", "&&", "@", "is_dir", "(", "$", "path", ")", ")", "{", "$", "handle", "=", "opendir", "(", "$", "path", ")", ";", "while", "(", "(", "$", "file", "=", "readdir", "(", "$", "handle", ")", ")", "!==", "FALSE", ")", "{", "$", "recursionResult", "=", "NULL", ";", "if", "(", "$", "file", "!==", "'.'", "&&", "$", "file", "!==", "'..'", ")", "{", "if", "(", "@", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "file", ")", ")", "{", "$", "recursionResult", "=", "self", "::", "fixPermissions", "(", "$", "path", ".", "'/'", ".", "$", "file", ")", ";", "}", "elseif", "(", "@", "is_dir", "(", "$", "path", ".", "'/'", ".", "$", "file", ")", ")", "{", "$", "recursionResult", "=", "self", "::", "fixPermissions", "(", "$", "path", ".", "'/'", ".", "$", "file", ",", "TRUE", ")", ";", "}", "if", "(", "isset", "(", "$", "recursionResult", ")", "&&", "!", "$", "recursionResult", ")", "{", "$", "result", "=", "FALSE", ";", "}", "}", "}", "closedir", "(", "$", "handle", ")", ";", "}", "}", "}", "else", "{", "$", "result", "=", "TRUE", ";", "}", "return", "$", "result", ";", "}" ]
Sets the file system mode and group ownership of a file or a folder. @param string $path Path of file or folder, must not be escaped. Path can be absolute or relative @param boolean $recursive If set, also fixes permissions of files and folders in the folder (if $path is a folder) @return mixed TRUE on success, FALSE on error, always TRUE on Windows OS
[ "Sets", "the", "file", "system", "mode", "and", "group", "ownership", "of", "a", "file", "or", "a", "folder", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L2806-L2854
220,464
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.mkdir_deep
public static function mkdir_deep($directory, $deepDirectory = '') { if (!is_string($directory)) { throw new \InvalidArgumentException( 'The specified directory is of type "' . gettype($directory) . '" but a string is expected.', 1303662955 ); } if (!is_string($deepDirectory)) { throw new \InvalidArgumentException( 'The specified directory is of type "' . gettype($deepDirectory) . '" but a string is expected.', 1303662956 ); } $fullPath = $directory . $deepDirectory; if (!is_dir($fullPath) && strlen($fullPath) > 0) { $firstCreatedPath = self::createDirectoryPath($fullPath); if ($firstCreatedPath !== '') { self::fixPermissions($firstCreatedPath, TRUE); } } }
php
public static function mkdir_deep($directory, $deepDirectory = '') { if (!is_string($directory)) { throw new \InvalidArgumentException( 'The specified directory is of type "' . gettype($directory) . '" but a string is expected.', 1303662955 ); } if (!is_string($deepDirectory)) { throw new \InvalidArgumentException( 'The specified directory is of type "' . gettype($deepDirectory) . '" but a string is expected.', 1303662956 ); } $fullPath = $directory . $deepDirectory; if (!is_dir($fullPath) && strlen($fullPath) > 0) { $firstCreatedPath = self::createDirectoryPath($fullPath); if ($firstCreatedPath !== '') { self::fixPermissions($firstCreatedPath, TRUE); } } }
[ "public", "static", "function", "mkdir_deep", "(", "$", "directory", ",", "$", "deepDirectory", "=", "''", ")", "{", "if", "(", "!", "is_string", "(", "$", "directory", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified directory is of type \"'", ".", "gettype", "(", "$", "directory", ")", ".", "'\" but a string is expected.'", ",", "1303662955", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "deepDirectory", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The specified directory is of type \"'", ".", "gettype", "(", "$", "deepDirectory", ")", ".", "'\" but a string is expected.'", ",", "1303662956", ")", ";", "}", "$", "fullPath", "=", "$", "directory", ".", "$", "deepDirectory", ";", "if", "(", "!", "is_dir", "(", "$", "fullPath", ")", "&&", "strlen", "(", "$", "fullPath", ")", ">", "0", ")", "{", "$", "firstCreatedPath", "=", "self", "::", "createDirectoryPath", "(", "$", "fullPath", ")", ";", "if", "(", "$", "firstCreatedPath", "!==", "''", ")", "{", "self", "::", "fixPermissions", "(", "$", "firstCreatedPath", ",", "TRUE", ")", ";", "}", "}", "}" ]
Creates a directory - including parent directories if necessary and sets permissions on newly created directories. @param string $directory Target directory to create. Must a have trailing slash if second parameter is given! Example: "/root/typo3site/typo3temp/foo/" @param string $deepDirectory Directory to create. This second parameter is kept for backwards compatibility since 4.6 where this method was split into a base directory and a deep directory to be created. Example: "xx/yy/" which creates "/root/typo3site/xx/yy/" if $directory is "/root/typo3site/" @return void @throws \InvalidArgumentException If $directory or $deepDirectory are not strings @throws \RuntimeException If directory could not be created
[ "Creates", "a", "directory", "-", "including", "parent", "directories", "if", "necessary", "and", "sets", "permissions", "on", "newly", "created", "directories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L2947-L2968
220,465
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.createDirectoryPath
protected static function createDirectoryPath($fullDirectoryPath) { $currentPath = $fullDirectoryPath; $firstCreatedPath = ''; $permissionMask = octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']); if (!@is_dir($currentPath)) { do { $firstCreatedPath = $currentPath; $separatorPosition = strrpos($currentPath, DIRECTORY_SEPARATOR); $currentPath = substr($currentPath, 0, $separatorPosition); } while (!is_dir($currentPath) && $separatorPosition !== FALSE); $result = @mkdir($fullDirectoryPath, $permissionMask, TRUE); if (!$result) { throw new \RuntimeException('Could not create directory "' . $fullDirectoryPath . '"!', 1170251400); } } return $firstCreatedPath; }
php
protected static function createDirectoryPath($fullDirectoryPath) { $currentPath = $fullDirectoryPath; $firstCreatedPath = ''; $permissionMask = octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']); if (!@is_dir($currentPath)) { do { $firstCreatedPath = $currentPath; $separatorPosition = strrpos($currentPath, DIRECTORY_SEPARATOR); $currentPath = substr($currentPath, 0, $separatorPosition); } while (!is_dir($currentPath) && $separatorPosition !== FALSE); $result = @mkdir($fullDirectoryPath, $permissionMask, TRUE); if (!$result) { throw new \RuntimeException('Could not create directory "' . $fullDirectoryPath . '"!', 1170251400); } } return $firstCreatedPath; }
[ "protected", "static", "function", "createDirectoryPath", "(", "$", "fullDirectoryPath", ")", "{", "$", "currentPath", "=", "$", "fullDirectoryPath", ";", "$", "firstCreatedPath", "=", "''", ";", "$", "permissionMask", "=", "octdec", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'folderCreateMask'", "]", ")", ";", "if", "(", "!", "@", "is_dir", "(", "$", "currentPath", ")", ")", "{", "do", "{", "$", "firstCreatedPath", "=", "$", "currentPath", ";", "$", "separatorPosition", "=", "strrpos", "(", "$", "currentPath", ",", "DIRECTORY_SEPARATOR", ")", ";", "$", "currentPath", "=", "substr", "(", "$", "currentPath", ",", "0", ",", "$", "separatorPosition", ")", ";", "}", "while", "(", "!", "is_dir", "(", "$", "currentPath", ")", "&&", "$", "separatorPosition", "!==", "FALSE", ")", ";", "$", "result", "=", "@", "mkdir", "(", "$", "fullDirectoryPath", ",", "$", "permissionMask", ",", "TRUE", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Could not create directory \"'", ".", "$", "fullDirectoryPath", ".", "'\"!'", ",", "1170251400", ")", ";", "}", "}", "return", "$", "firstCreatedPath", ";", "}" ]
Creates directories for the specified paths if they do not exist. This functions sets proper permission mask but does not set proper user and group. @static @param string $fullDirectoryPath @return string Path to the the first created directory in the hierarchy @see t3lib_div::mkdir_deep @throws \RuntimeException If directory could not be created
[ "Creates", "directories", "for", "the", "specified", "paths", "if", "they", "do", "not", "exist", ".", "This", "functions", "sets", "proper", "permission", "mask", "but", "does", "not", "set", "proper", "user", "and", "group", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L2981-L2998
220,466
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.rmdir
public static function rmdir($path, $removeNonEmpty = FALSE) { $OK = FALSE; $path = preg_replace('|/$|', '', $path); // Remove trailing slash if (file_exists($path)) { $OK = TRUE; if (is_dir($path)) { if ($removeNonEmpty == TRUE && $handle = opendir($path)) { while ($OK && FALSE !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } $OK = self::rmdir($path . '/' . $file, $removeNonEmpty); } closedir($handle); } if ($OK) { $OK = rmdir($path); } } else { // If $dirname is a file, simply remove it $OK = unlink($path); } clearstatcache(); } return $OK; }
php
public static function rmdir($path, $removeNonEmpty = FALSE) { $OK = FALSE; $path = preg_replace('|/$|', '', $path); // Remove trailing slash if (file_exists($path)) { $OK = TRUE; if (is_dir($path)) { if ($removeNonEmpty == TRUE && $handle = opendir($path)) { while ($OK && FALSE !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } $OK = self::rmdir($path . '/' . $file, $removeNonEmpty); } closedir($handle); } if ($OK) { $OK = rmdir($path); } } else { // If $dirname is a file, simply remove it $OK = unlink($path); } clearstatcache(); } return $OK; }
[ "public", "static", "function", "rmdir", "(", "$", "path", ",", "$", "removeNonEmpty", "=", "FALSE", ")", "{", "$", "OK", "=", "FALSE", ";", "$", "path", "=", "preg_replace", "(", "'|/$|'", ",", "''", ",", "$", "path", ")", ";", "// Remove trailing slash", "if", "(", "file_exists", "(", "$", "path", ")", ")", "{", "$", "OK", "=", "TRUE", ";", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "if", "(", "$", "removeNonEmpty", "==", "TRUE", "&&", "$", "handle", "=", "opendir", "(", "$", "path", ")", ")", "{", "while", "(", "$", "OK", "&&", "FALSE", "!==", "(", "$", "file", "=", "readdir", "(", "$", "handle", ")", ")", ")", "{", "if", "(", "$", "file", "==", "'.'", "||", "$", "file", "==", "'..'", ")", "{", "continue", ";", "}", "$", "OK", "=", "self", "::", "rmdir", "(", "$", "path", ".", "'/'", ".", "$", "file", ",", "$", "removeNonEmpty", ")", ";", "}", "closedir", "(", "$", "handle", ")", ";", "}", "if", "(", "$", "OK", ")", "{", "$", "OK", "=", "rmdir", "(", "$", "path", ")", ";", "}", "}", "else", "{", "// If $dirname is a file, simply remove it", "$", "OK", "=", "unlink", "(", "$", "path", ")", ";", "}", "clearstatcache", "(", ")", ";", "}", "return", "$", "OK", ";", "}" ]
Wrapper function for rmdir, allowing recursive deletion of folders and files @param string $path Absolute path to folder, see PHP rmdir() function. Removes trailing slash internally. @param boolean $removeNonEmpty Allow deletion of non-empty directories @return boolean TRUE if @rmdir went well!
[ "Wrapper", "function", "for", "rmdir", "allowing", "recursive", "deletion", "of", "folders", "and", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3007-L3036
220,467
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getFilesInDir
public static function getFilesInDir($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '') { // Initialize variables: $filearray = array(); $sortarray = array(); $path = rtrim($path, '/'); // Find files+directories: if (@is_dir($path)) { $extensionList = strtolower($extensionList); $d = dir($path); if (is_object($d)) { while ($entry = $d->read()) { if (@is_file($path . '/' . $entry)) { $fI = pathinfo($entry); $key = md5($path . '/' . $entry); // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension) if ((!strlen($extensionList) || self::inList($extensionList, strtolower($fI['extension']))) && (!strlen($excludePattern) || !preg_match('/^' . $excludePattern . '$/', $entry))) { $filearray[$key] = ($prependPath ? $path . '/' : '') . $entry; if ($order == 'mtime') { $sortarray[$key] = filemtime($path . '/' . $entry); } elseif ($order) { $sortarray[$key] = strtolower($entry); } } } } $d->close(); } else { return 'error opening path: "' . $path . '"'; } } // Sort them: if ($order) { asort($sortarray); $newArr = array(); foreach ($sortarray as $k => $v) { $newArr[$k] = $filearray[$k]; } $filearray = $newArr; } // Return result reset($filearray); return $filearray; }
php
public static function getFilesInDir($path, $extensionList = '', $prependPath = FALSE, $order = '', $excludePattern = '') { // Initialize variables: $filearray = array(); $sortarray = array(); $path = rtrim($path, '/'); // Find files+directories: if (@is_dir($path)) { $extensionList = strtolower($extensionList); $d = dir($path); if (is_object($d)) { while ($entry = $d->read()) { if (@is_file($path . '/' . $entry)) { $fI = pathinfo($entry); $key = md5($path . '/' . $entry); // Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension) if ((!strlen($extensionList) || self::inList($extensionList, strtolower($fI['extension']))) && (!strlen($excludePattern) || !preg_match('/^' . $excludePattern . '$/', $entry))) { $filearray[$key] = ($prependPath ? $path . '/' : '') . $entry; if ($order == 'mtime') { $sortarray[$key] = filemtime($path . '/' . $entry); } elseif ($order) { $sortarray[$key] = strtolower($entry); } } } } $d->close(); } else { return 'error opening path: "' . $path . '"'; } } // Sort them: if ($order) { asort($sortarray); $newArr = array(); foreach ($sortarray as $k => $v) { $newArr[$k] = $filearray[$k]; } $filearray = $newArr; } // Return result reset($filearray); return $filearray; }
[ "public", "static", "function", "getFilesInDir", "(", "$", "path", ",", "$", "extensionList", "=", "''", ",", "$", "prependPath", "=", "FALSE", ",", "$", "order", "=", "''", ",", "$", "excludePattern", "=", "''", ")", "{", "// Initialize variables:", "$", "filearray", "=", "array", "(", ")", ";", "$", "sortarray", "=", "array", "(", ")", ";", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "// Find files+directories:", "if", "(", "@", "is_dir", "(", "$", "path", ")", ")", "{", "$", "extensionList", "=", "strtolower", "(", "$", "extensionList", ")", ";", "$", "d", "=", "dir", "(", "$", "path", ")", ";", "if", "(", "is_object", "(", "$", "d", ")", ")", "{", "while", "(", "$", "entry", "=", "$", "d", "->", "read", "(", ")", ")", "{", "if", "(", "@", "is_file", "(", "$", "path", ".", "'/'", ".", "$", "entry", ")", ")", "{", "$", "fI", "=", "pathinfo", "(", "$", "entry", ")", ";", "$", "key", "=", "md5", "(", "$", "path", ".", "'/'", ".", "$", "entry", ")", ";", "// Don't change this ever - extensions may depend on the fact that the hash is an md5 of the path! (import/export extension)", "if", "(", "(", "!", "strlen", "(", "$", "extensionList", ")", "||", "self", "::", "inList", "(", "$", "extensionList", ",", "strtolower", "(", "$", "fI", "[", "'extension'", "]", ")", ")", ")", "&&", "(", "!", "strlen", "(", "$", "excludePattern", ")", "||", "!", "preg_match", "(", "'/^'", ".", "$", "excludePattern", ".", "'$/'", ",", "$", "entry", ")", ")", ")", "{", "$", "filearray", "[", "$", "key", "]", "=", "(", "$", "prependPath", "?", "$", "path", ".", "'/'", ":", "''", ")", ".", "$", "entry", ";", "if", "(", "$", "order", "==", "'mtime'", ")", "{", "$", "sortarray", "[", "$", "key", "]", "=", "filemtime", "(", "$", "path", ".", "'/'", ".", "$", "entry", ")", ";", "}", "elseif", "(", "$", "order", ")", "{", "$", "sortarray", "[", "$", "key", "]", "=", "strtolower", "(", "$", "entry", ")", ";", "}", "}", "}", "}", "$", "d", "->", "close", "(", ")", ";", "}", "else", "{", "return", "'error opening path: \"'", ".", "$", "path", ".", "'\"'", ";", "}", "}", "// Sort them:", "if", "(", "$", "order", ")", "{", "asort", "(", "$", "sortarray", ")", ";", "$", "newArr", "=", "array", "(", ")", ";", "foreach", "(", "$", "sortarray", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "newArr", "[", "$", "k", "]", "=", "$", "filearray", "[", "$", "k", "]", ";", "}", "$", "filearray", "=", "$", "newArr", ";", "}", "// Return result", "reset", "(", "$", "filearray", ")", ";", "return", "$", "filearray", ";", "}" ]
Returns an array with the names of files in a specific path @param string $path Is the path to the file @param string $extensionList is the comma list of extensions to read only (blank = all) @param boolean $prependPath If set, then the path is prepended the file names. Otherwise only the file names are returned in the array @param string $order is sorting: 1= sort alphabetically, 'mtime' = sort by modification time. @param string $excludePattern A comma separated list of file names to exclude, no wildcards @return array Array of the files found
[ "Returns", "an", "array", "with", "the", "names", "of", "files", "in", "a", "specific", "path" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3073-L3119
220,468
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getAllFilesAndFoldersInPath
public static function getAllFilesAndFoldersInPath(array $fileArr, $path, $extList = '', $regDirs = FALSE, $recursivityLevels = 99, $excludePattern = '') { if ($regDirs) { $fileArr[] = $path; } $fileArr = array_merge($fileArr, self::getFilesInDir($path, $extList, 1, 1, $excludePattern)); $dirs = self::get_dirs($path); if (is_array($dirs) && $recursivityLevels > 0) { foreach ($dirs as $subdirs) { if ((string) $subdirs != '' && (!strlen($excludePattern) || !preg_match('/^' . $excludePattern . '$/', $subdirs))) { $fileArr = self::getAllFilesAndFoldersInPath($fileArr, $path . $subdirs . '/', $extList, $regDirs, $recursivityLevels - 1, $excludePattern); } } } return $fileArr; }
php
public static function getAllFilesAndFoldersInPath(array $fileArr, $path, $extList = '', $regDirs = FALSE, $recursivityLevels = 99, $excludePattern = '') { if ($regDirs) { $fileArr[] = $path; } $fileArr = array_merge($fileArr, self::getFilesInDir($path, $extList, 1, 1, $excludePattern)); $dirs = self::get_dirs($path); if (is_array($dirs) && $recursivityLevels > 0) { foreach ($dirs as $subdirs) { if ((string) $subdirs != '' && (!strlen($excludePattern) || !preg_match('/^' . $excludePattern . '$/', $subdirs))) { $fileArr = self::getAllFilesAndFoldersInPath($fileArr, $path . $subdirs . '/', $extList, $regDirs, $recursivityLevels - 1, $excludePattern); } } } return $fileArr; }
[ "public", "static", "function", "getAllFilesAndFoldersInPath", "(", "array", "$", "fileArr", ",", "$", "path", ",", "$", "extList", "=", "''", ",", "$", "regDirs", "=", "FALSE", ",", "$", "recursivityLevels", "=", "99", ",", "$", "excludePattern", "=", "''", ")", "{", "if", "(", "$", "regDirs", ")", "{", "$", "fileArr", "[", "]", "=", "$", "path", ";", "}", "$", "fileArr", "=", "array_merge", "(", "$", "fileArr", ",", "self", "::", "getFilesInDir", "(", "$", "path", ",", "$", "extList", ",", "1", ",", "1", ",", "$", "excludePattern", ")", ")", ";", "$", "dirs", "=", "self", "::", "get_dirs", "(", "$", "path", ")", ";", "if", "(", "is_array", "(", "$", "dirs", ")", "&&", "$", "recursivityLevels", ">", "0", ")", "{", "foreach", "(", "$", "dirs", "as", "$", "subdirs", ")", "{", "if", "(", "(", "string", ")", "$", "subdirs", "!=", "''", "&&", "(", "!", "strlen", "(", "$", "excludePattern", ")", "||", "!", "preg_match", "(", "'/^'", ".", "$", "excludePattern", ".", "'$/'", ",", "$", "subdirs", ")", ")", ")", "{", "$", "fileArr", "=", "self", "::", "getAllFilesAndFoldersInPath", "(", "$", "fileArr", ",", "$", "path", ".", "$", "subdirs", ".", "'/'", ",", "$", "extList", ",", "$", "regDirs", ",", "$", "recursivityLevels", "-", "1", ",", "$", "excludePattern", ")", ";", "}", "}", "}", "return", "$", "fileArr", ";", "}" ]
Recursively gather all files and folders of a path. @param array $fileArr Empty input array (will have files added to it) @param string $path The path to read recursively from (absolute) (include trailing slash!) @param string $extList Comma list of file extensions: Only files with extensions in this list (if applicable) will be selected. @param boolean $regDirs If set, directories are also included in output. @param integer $recursivityLevels The number of levels to dig down... @param string $excludePattern regex pattern of files/directories to exclude @return array An array with the found files/directories.
[ "Recursively", "gather", "all", "files", "and", "folders", "of", "a", "path", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3132-L3147
220,469
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getMaxUploadFileSize
public static function getMaxUploadFileSize($localLimit = 0) { // don't allow more than the global max file size at all $t3Limit = (intval($localLimit > 0 ? $localLimit : $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'])); // as TYPO3 is handling the file size in KB, multiply by 1024 to get bytes $t3Limit = $t3Limit * 1024; // check for PHP restrictions of the maximum size of one of the $_FILES $phpUploadLimit = self::getBytesFromSizeMeasurement(ini_get('upload_max_filesize')); // check for PHP restrictions of the maximum $_POST size $phpPostLimit = self::getBytesFromSizeMeasurement(ini_get('post_max_size')); // if the total amount of post data is smaller (!) than the upload_max_filesize directive, // then this is the real limit in PHP $phpUploadLimit = ($phpPostLimit < $phpUploadLimit ? $phpPostLimit : $phpUploadLimit); // is the allowed PHP limit (upload_max_filesize) lower than the TYPO3 limit?, also: revert back to KB return floor($phpUploadLimit < $t3Limit ? $phpUploadLimit : $t3Limit) / 1024; }
php
public static function getMaxUploadFileSize($localLimit = 0) { // don't allow more than the global max file size at all $t3Limit = (intval($localLimit > 0 ? $localLimit : $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'])); // as TYPO3 is handling the file size in KB, multiply by 1024 to get bytes $t3Limit = $t3Limit * 1024; // check for PHP restrictions of the maximum size of one of the $_FILES $phpUploadLimit = self::getBytesFromSizeMeasurement(ini_get('upload_max_filesize')); // check for PHP restrictions of the maximum $_POST size $phpPostLimit = self::getBytesFromSizeMeasurement(ini_get('post_max_size')); // if the total amount of post data is smaller (!) than the upload_max_filesize directive, // then this is the real limit in PHP $phpUploadLimit = ($phpPostLimit < $phpUploadLimit ? $phpPostLimit : $phpUploadLimit); // is the allowed PHP limit (upload_max_filesize) lower than the TYPO3 limit?, also: revert back to KB return floor($phpUploadLimit < $t3Limit ? $phpUploadLimit : $t3Limit) / 1024; }
[ "public", "static", "function", "getMaxUploadFileSize", "(", "$", "localLimit", "=", "0", ")", "{", "// don't allow more than the global max file size at all", "$", "t3Limit", "=", "(", "intval", "(", "$", "localLimit", ">", "0", "?", "$", "localLimit", ":", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'maxFileSize'", "]", ")", ")", ";", "// as TYPO3 is handling the file size in KB, multiply by 1024 to get bytes", "$", "t3Limit", "=", "$", "t3Limit", "*", "1024", ";", "// check for PHP restrictions of the maximum size of one of the $_FILES", "$", "phpUploadLimit", "=", "self", "::", "getBytesFromSizeMeasurement", "(", "ini_get", "(", "'upload_max_filesize'", ")", ")", ";", "// check for PHP restrictions of the maximum $_POST size", "$", "phpPostLimit", "=", "self", "::", "getBytesFromSizeMeasurement", "(", "ini_get", "(", "'post_max_size'", ")", ")", ";", "// if the total amount of post data is smaller (!) than the upload_max_filesize directive,", "// then this is the real limit in PHP", "$", "phpUploadLimit", "=", "(", "$", "phpPostLimit", "<", "$", "phpUploadLimit", "?", "$", "phpPostLimit", ":", "$", "phpUploadLimit", ")", ";", "// is the allowed PHP limit (upload_max_filesize) lower than the TYPO3 limit?, also: revert back to KB", "return", "floor", "(", "$", "phpUploadLimit", "<", "$", "t3Limit", "?", "$", "phpUploadLimit", ":", "$", "t3Limit", ")", "/", "1024", ";", "}" ]
Returns the maximum upload size for a file that is allowed. Measured in KB. This might be handy to find out the real upload limit that is possible for this TYPO3 installation. The first parameter can be used to set something that overrides the maxFileSize, usually for the TCA values. @param integer $localLimit: the number of Kilobytes (!) that should be used as the initial Limit, otherwise $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'] will be used @return integer the maximum size of uploads that are allowed (measured in kilobytes)
[ "Returns", "the", "maximum", "upload", "size", "for", "a", "file", "that", "is", "allowed", ".", "Measured", "in", "KB", ".", "This", "might", "be", "handy", "to", "find", "out", "the", "real", "upload", "limit", "that", "is", "possible", "for", "this", "TYPO3", "installation", ".", "The", "first", "parameter", "can", "be", "used", "to", "set", "something", "that", "overrides", "the", "maxFileSize", "usually", "for", "the", "TCA", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3234-L3250
220,470
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getBytesFromSizeMeasurement
public static function getBytesFromSizeMeasurement($measurement) { $bytes = doubleval($measurement); if (stripos($measurement, 'G')) { $bytes *= 1024 * 1024 * 1024; } elseif (stripos($measurement, 'M')) { $bytes *= 1024 * 1024; } elseif (stripos($measurement, 'K')) { $bytes *= 1024; } return $bytes; }
php
public static function getBytesFromSizeMeasurement($measurement) { $bytes = doubleval($measurement); if (stripos($measurement, 'G')) { $bytes *= 1024 * 1024 * 1024; } elseif (stripos($measurement, 'M')) { $bytes *= 1024 * 1024; } elseif (stripos($measurement, 'K')) { $bytes *= 1024; } return $bytes; }
[ "public", "static", "function", "getBytesFromSizeMeasurement", "(", "$", "measurement", ")", "{", "$", "bytes", "=", "doubleval", "(", "$", "measurement", ")", ";", "if", "(", "stripos", "(", "$", "measurement", ",", "'G'", ")", ")", "{", "$", "bytes", "*=", "1024", "*", "1024", "*", "1024", ";", "}", "elseif", "(", "stripos", "(", "$", "measurement", ",", "'M'", ")", ")", "{", "$", "bytes", "*=", "1024", "*", "1024", ";", "}", "elseif", "(", "stripos", "(", "$", "measurement", ",", "'K'", ")", ")", "{", "$", "bytes", "*=", "1024", ";", "}", "return", "$", "bytes", ";", "}" ]
Gets the bytes value from a measurement string like "100k". @param string $measurement: The measurement (e.g. "100k") @return integer The bytes value (e.g. 102400)
[ "Gets", "the", "bytes", "value", "from", "a", "measurement", "string", "like", "100k", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3258-L3268
220,471
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.createVersionNumberedFilename
public static function createVersionNumberedFilename($file, $forceQueryString = FALSE) { $lookupFile = explode('?', $file); $path = self::resolveBackPath(self::dirname(PATH_thisScript) . '/' . $lookupFile[0]); if (TYPO3_MODE == 'FE') { $mode = strtolower($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['versionNumberInFilename']); if ($mode === 'embed') { $mode = TRUE; } else { if ($mode === 'querystring') { $mode = FALSE; } else { $doNothing = TRUE; } } } else { $mode = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['versionNumberInFilename']; } if (!file_exists($path) || $doNothing) { // File not found, return filename unaltered $fullName = $file; } else { if (!$mode || $forceQueryString) { // If use of .htaccess rule is not configured, // we use the default query-string method if ($lookupFile[1]) { $separator = '&'; } else { $separator = '?'; } $fullName = $file . $separator . filemtime($path); } else { // Change the filename $name = explode('.', $lookupFile[0]); $extension = array_pop($name); array_push($name, filemtime($path), $extension); $fullName = implode('.', $name); // append potential query string $fullName .= $lookupFile[1] ? '?' . $lookupFile[1] : ''; } } return $fullName; }
php
public static function createVersionNumberedFilename($file, $forceQueryString = FALSE) { $lookupFile = explode('?', $file); $path = self::resolveBackPath(self::dirname(PATH_thisScript) . '/' . $lookupFile[0]); if (TYPO3_MODE == 'FE') { $mode = strtolower($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['versionNumberInFilename']); if ($mode === 'embed') { $mode = TRUE; } else { if ($mode === 'querystring') { $mode = FALSE; } else { $doNothing = TRUE; } } } else { $mode = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['versionNumberInFilename']; } if (!file_exists($path) || $doNothing) { // File not found, return filename unaltered $fullName = $file; } else { if (!$mode || $forceQueryString) { // If use of .htaccess rule is not configured, // we use the default query-string method if ($lookupFile[1]) { $separator = '&'; } else { $separator = '?'; } $fullName = $file . $separator . filemtime($path); } else { // Change the filename $name = explode('.', $lookupFile[0]); $extension = array_pop($name); array_push($name, filemtime($path), $extension); $fullName = implode('.', $name); // append potential query string $fullName .= $lookupFile[1] ? '?' . $lookupFile[1] : ''; } } return $fullName; }
[ "public", "static", "function", "createVersionNumberedFilename", "(", "$", "file", ",", "$", "forceQueryString", "=", "FALSE", ")", "{", "$", "lookupFile", "=", "explode", "(", "'?'", ",", "$", "file", ")", ";", "$", "path", "=", "self", "::", "resolveBackPath", "(", "self", "::", "dirname", "(", "PATH_thisScript", ")", ".", "'/'", ".", "$", "lookupFile", "[", "0", "]", ")", ";", "if", "(", "TYPO3_MODE", "==", "'FE'", ")", "{", "$", "mode", "=", "strtolower", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "TYPO3_MODE", "]", "[", "'versionNumberInFilename'", "]", ")", ";", "if", "(", "$", "mode", "===", "'embed'", ")", "{", "$", "mode", "=", "TRUE", ";", "}", "else", "{", "if", "(", "$", "mode", "===", "'querystring'", ")", "{", "$", "mode", "=", "FALSE", ";", "}", "else", "{", "$", "doNothing", "=", "TRUE", ";", "}", "}", "}", "else", "{", "$", "mode", "=", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "TYPO3_MODE", "]", "[", "'versionNumberInFilename'", "]", ";", "}", "if", "(", "!", "file_exists", "(", "$", "path", ")", "||", "$", "doNothing", ")", "{", "// File not found, return filename unaltered", "$", "fullName", "=", "$", "file", ";", "}", "else", "{", "if", "(", "!", "$", "mode", "||", "$", "forceQueryString", ")", "{", "// If use of .htaccess rule is not configured,", "// we use the default query-string method", "if", "(", "$", "lookupFile", "[", "1", "]", ")", "{", "$", "separator", "=", "'&'", ";", "}", "else", "{", "$", "separator", "=", "'?'", ";", "}", "$", "fullName", "=", "$", "file", ".", "$", "separator", ".", "filemtime", "(", "$", "path", ")", ";", "}", "else", "{", "// Change the filename", "$", "name", "=", "explode", "(", "'.'", ",", "$", "lookupFile", "[", "0", "]", ")", ";", "$", "extension", "=", "array_pop", "(", "$", "name", ")", ";", "array_push", "(", "$", "name", ",", "filemtime", "(", "$", "path", ")", ",", "$", "extension", ")", ";", "$", "fullName", "=", "implode", "(", "'.'", ",", "$", "name", ")", ";", "// append potential query string", "$", "fullName", ".=", "$", "lookupFile", "[", "1", "]", "?", "'?'", ".", "$", "lookupFile", "[", "1", "]", ":", "''", ";", "}", "}", "return", "$", "fullName", ";", "}" ]
Function for static version numbers on files, based on the filemtime This will make the filename automatically change when a file is changed, and by that re-cached by the browser. If the file does not exist physically the original file passed to the function is returned without the timestamp. Behaviour is influenced by the setting TYPO3_CONF_VARS[TYPO3_MODE][versionNumberInFilename] = TRUE (BE) / "embed" (FE) : modify filename = FALSE (BE) / "querystring" (FE) : add timestamp as parameter @param string $file Relative path to file including all potential query parameters (not htmlspecialchared yet) @param boolean $forceQueryString If settings would suggest to embed in filename, this parameter allows us to force the versioning to occur in the query string. This is needed for scriptaculous.js which cannot have a different filename in order to load its modules (?load=...) @return Relative path with version filename including the timestamp
[ "Function", "for", "static", "version", "numbers", "on", "files", "based", "on", "the", "filemtime" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3297-L3344
220,472
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getHostname
public static function getHostname($requestHost = TRUE) { $host = ''; // If not called from the command-line, resolve on getIndpEnv() // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if ($requestHost && (!defined('TYPO3_cliMode') || !TYPO3_cliMode)) { $host = self::getIndpEnv('HTTP_HOST'); } if (!$host) { // will fail for PHP 4.1 and 4.2 $host = @php_uname('n'); // 'n' is ignored in broken installations if (strpos($host, ' ')) { $host = ''; } } // we have not found a FQDN yet if ($host && strpos($host, '.') === FALSE) { $ip = gethostbyname($host); // we got an IP address if ($ip != $host) { $fqdn = gethostbyaddr($ip); if ($ip != $fqdn) { $host = $fqdn; } } } if (!$host) { $host = 'localhost.localdomain'; } return $host; }
php
public static function getHostname($requestHost = TRUE) { $host = ''; // If not called from the command-line, resolve on getIndpEnv() // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if ($requestHost && (!defined('TYPO3_cliMode') || !TYPO3_cliMode)) { $host = self::getIndpEnv('HTTP_HOST'); } if (!$host) { // will fail for PHP 4.1 and 4.2 $host = @php_uname('n'); // 'n' is ignored in broken installations if (strpos($host, ' ')) { $host = ''; } } // we have not found a FQDN yet if ($host && strpos($host, '.') === FALSE) { $ip = gethostbyname($host); // we got an IP address if ($ip != $host) { $fqdn = gethostbyaddr($ip); if ($ip != $fqdn) { $host = $fqdn; } } } if (!$host) { $host = 'localhost.localdomain'; } return $host; }
[ "public", "static", "function", "getHostname", "(", "$", "requestHost", "=", "TRUE", ")", "{", "$", "host", "=", "''", ";", "// If not called from the command-line, resolve on getIndpEnv()", "// Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined", "if", "(", "$", "requestHost", "&&", "(", "!", "defined", "(", "'TYPO3_cliMode'", ")", "||", "!", "TYPO3_cliMode", ")", ")", "{", "$", "host", "=", "self", "::", "getIndpEnv", "(", "'HTTP_HOST'", ")", ";", "}", "if", "(", "!", "$", "host", ")", "{", "// will fail for PHP 4.1 and 4.2", "$", "host", "=", "@", "php_uname", "(", "'n'", ")", ";", "// 'n' is ignored in broken installations", "if", "(", "strpos", "(", "$", "host", ",", "' '", ")", ")", "{", "$", "host", "=", "''", ";", "}", "}", "// we have not found a FQDN yet", "if", "(", "$", "host", "&&", "strpos", "(", "$", "host", ",", "'.'", ")", "===", "FALSE", ")", "{", "$", "ip", "=", "gethostbyname", "(", "$", "host", ")", ";", "// we got an IP address", "if", "(", "$", "ip", "!=", "$", "host", ")", "{", "$", "fqdn", "=", "gethostbyaddr", "(", "$", "ip", ")", ";", "if", "(", "$", "ip", "!=", "$", "fqdn", ")", "{", "$", "host", "=", "$", "fqdn", ";", "}", "}", "}", "if", "(", "!", "$", "host", ")", "{", "$", "host", "=", "'localhost.localdomain'", ";", "}", "return", "$", "host", ";", "}" ]
Get the fully-qualified domain name of the host. @param boolean $requestHost Use request host (when not in CLI mode). @return string The fully-qualified host name.
[ "Get", "the", "fully", "-", "qualified", "domain", "name", "of", "the", "host", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3837-L3868
220,473
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.validPathStr
public static function validPathStr($theFile) { if (strpos($theFile, '//') === FALSE && strpos($theFile, '\\') === FALSE && !preg_match('#(?:^\.\.|/\.\./|[[:cntrl:]])#u', $theFile)) { return TRUE; } return FALSE; }
php
public static function validPathStr($theFile) { if (strpos($theFile, '//') === FALSE && strpos($theFile, '\\') === FALSE && !preg_match('#(?:^\.\.|/\.\./|[[:cntrl:]])#u', $theFile)) { return TRUE; } return FALSE; }
[ "public", "static", "function", "validPathStr", "(", "$", "theFile", ")", "{", "if", "(", "strpos", "(", "$", "theFile", ",", "'//'", ")", "===", "FALSE", "&&", "strpos", "(", "$", "theFile", ",", "'\\\\'", ")", "===", "FALSE", "&&", "!", "preg_match", "(", "'#(?:^\\.\\.|/\\.\\./|[[:cntrl:]])#u'", ",", "$", "theFile", ")", ")", "{", "return", "TRUE", ";", "}", "return", "FALSE", ";", "}" ]
Checks for malicious file paths. Returns TRUE if no '//', '..', '\' or control characters are found in the $theFile. This should make sure that the path is not pointing 'backwards' and further doesn't contain double/back slashes. So it's compatible with the UNIX style path strings valid for TYPO3 internally. @param string $theFile File path to evaluate @return boolean TRUE, $theFile is allowed path string, FALSE otherwise @see http://php.net/manual/en/security.filesystem.nullbytes.php @todo Possible improvement: Should it rawurldecode the string first to check if any of these characters is encoded?
[ "Checks", "for", "malicious", "file", "paths", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3926-L3932
220,474
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.isAllowedAbsPath
public static function isAllowedAbsPath($path) { if (self::isAbsPath($path) && self::validPathStr($path) && (self::isFirstPartOfStr($path, PATH_site) || ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && self::isFirstPartOfStr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'])) ) ) { return TRUE; } }
php
public static function isAllowedAbsPath($path) { if (self::isAbsPath($path) && self::validPathStr($path) && (self::isFirstPartOfStr($path, PATH_site) || ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'] && self::isFirstPartOfStr($path, $GLOBALS['TYPO3_CONF_VARS']['BE']['lockRootPath'])) ) ) { return TRUE; } }
[ "public", "static", "function", "isAllowedAbsPath", "(", "$", "path", ")", "{", "if", "(", "self", "::", "isAbsPath", "(", "$", "path", ")", "&&", "self", "::", "validPathStr", "(", "$", "path", ")", "&&", "(", "self", "::", "isFirstPartOfStr", "(", "$", "path", ",", "PATH_site", ")", "||", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'lockRootPath'", "]", "&&", "self", "::", "isFirstPartOfStr", "(", "$", "path", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'lockRootPath'", "]", ")", ")", ")", ")", "{", "return", "TRUE", ";", "}", "}" ]
Returns TRUE if the path is absolute, without backpath '..' and within the PATH_site OR within the lockRootPath @param string $path File path to evaluate @return boolean
[ "Returns", "TRUE", "if", "the", "path", "is", "absolute", "without", "backpath", "..", "and", "within", "the", "PATH_site", "OR", "within", "the", "lockRootPath" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3956-L3966
220,475
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.verifyFilenameAgainstDenyPattern
public static function verifyFilenameAgainstDenyPattern($filename) { // Filenames are not allowed to contain control characters if (preg_match('/[[:cntrl:]]/', $filename)) { return FALSE; } if (strcmp($filename, '') && strcmp($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], '')) { $result = preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', $filename); if ($result) { return FALSE; } // so if a matching filename is found, return FALSE; } return TRUE; }
php
public static function verifyFilenameAgainstDenyPattern($filename) { // Filenames are not allowed to contain control characters if (preg_match('/[[:cntrl:]]/', $filename)) { return FALSE; } if (strcmp($filename, '') && strcmp($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], '')) { $result = preg_match('/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] . '/i', $filename); if ($result) { return FALSE; } // so if a matching filename is found, return FALSE; } return TRUE; }
[ "public", "static", "function", "verifyFilenameAgainstDenyPattern", "(", "$", "filename", ")", "{", "// Filenames are not allowed to contain control characters", "if", "(", "preg_match", "(", "'/[[:cntrl:]]/'", ",", "$", "filename", ")", ")", "{", "return", "FALSE", ";", "}", "if", "(", "strcmp", "(", "$", "filename", ",", "''", ")", "&&", "strcmp", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'fileDenyPattern'", "]", ",", "''", ")", ")", "{", "$", "result", "=", "preg_match", "(", "'/'", ".", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'BE'", "]", "[", "'fileDenyPattern'", "]", ".", "'/i'", ",", "$", "filename", ")", ";", "if", "(", "$", "result", ")", "{", "return", "FALSE", ";", "}", "// so if a matching filename is found, return FALSE;", "}", "return", "TRUE", ";", "}" ]
Verifies the input filename against the 'fileDenyPattern'. Returns TRUE if OK. @param string $filename File path to evaluate @return boolean
[ "Verifies", "the", "input", "filename", "against", "the", "fileDenyPattern", ".", "Returns", "TRUE", "if", "OK", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3974-L3987
220,476
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.sanitizeLocalUrl
public static function sanitizeLocalUrl($url = '') { $sanitizedUrl = ''; $decodedUrl = rawurldecode($url); if (!empty($url) && self::removeXSS($decodedUrl) === $decodedUrl) { $testAbsoluteUrl = self::resolveBackPath($decodedUrl); $testRelativeUrl = self::resolveBackPath( self::dirname(self::getIndpEnv('SCRIPT_NAME')) . '/' . $decodedUrl ); // Pass if URL is on the current host: if (self::isValidUrl($decodedUrl)) { if (self::isOnCurrentHost($decodedUrl) && strpos($decodedUrl, self::getIndpEnv('TYPO3_SITE_URL')) === 0) { $sanitizedUrl = $url; } // Pass if URL is an absolute file path: } elseif (self::isAbsPath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) { $sanitizedUrl = $url; // Pass if URL is absolute and below TYPO3 base directory: } elseif (strpos($testAbsoluteUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) === '/') { $sanitizedUrl = $url; // Pass if URL is relative and below TYPO3 base directory: } elseif (strpos($testRelativeUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) !== '/') { $sanitizedUrl = $url; } } if (!empty($url) && empty($sanitizedUrl)) { self::sysLog('The URL "' . $url . '" is not considered to be local and was denied.', 'Core', self::SYSLOG_SEVERITY_NOTICE); } return $sanitizedUrl; }
php
public static function sanitizeLocalUrl($url = '') { $sanitizedUrl = ''; $decodedUrl = rawurldecode($url); if (!empty($url) && self::removeXSS($decodedUrl) === $decodedUrl) { $testAbsoluteUrl = self::resolveBackPath($decodedUrl); $testRelativeUrl = self::resolveBackPath( self::dirname(self::getIndpEnv('SCRIPT_NAME')) . '/' . $decodedUrl ); // Pass if URL is on the current host: if (self::isValidUrl($decodedUrl)) { if (self::isOnCurrentHost($decodedUrl) && strpos($decodedUrl, self::getIndpEnv('TYPO3_SITE_URL')) === 0) { $sanitizedUrl = $url; } // Pass if URL is an absolute file path: } elseif (self::isAbsPath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) { $sanitizedUrl = $url; // Pass if URL is absolute and below TYPO3 base directory: } elseif (strpos($testAbsoluteUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) === '/') { $sanitizedUrl = $url; // Pass if URL is relative and below TYPO3 base directory: } elseif (strpos($testRelativeUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) !== '/') { $sanitizedUrl = $url; } } if (!empty($url) && empty($sanitizedUrl)) { self::sysLog('The URL "' . $url . '" is not considered to be local and was denied.', 'Core', self::SYSLOG_SEVERITY_NOTICE); } return $sanitizedUrl; }
[ "public", "static", "function", "sanitizeLocalUrl", "(", "$", "url", "=", "''", ")", "{", "$", "sanitizedUrl", "=", "''", ";", "$", "decodedUrl", "=", "rawurldecode", "(", "$", "url", ")", ";", "if", "(", "!", "empty", "(", "$", "url", ")", "&&", "self", "::", "removeXSS", "(", "$", "decodedUrl", ")", "===", "$", "decodedUrl", ")", "{", "$", "testAbsoluteUrl", "=", "self", "::", "resolveBackPath", "(", "$", "decodedUrl", ")", ";", "$", "testRelativeUrl", "=", "self", "::", "resolveBackPath", "(", "self", "::", "dirname", "(", "self", "::", "getIndpEnv", "(", "'SCRIPT_NAME'", ")", ")", ".", "'/'", ".", "$", "decodedUrl", ")", ";", "// Pass if URL is on the current host:", "if", "(", "self", "::", "isValidUrl", "(", "$", "decodedUrl", ")", ")", "{", "if", "(", "self", "::", "isOnCurrentHost", "(", "$", "decodedUrl", ")", "&&", "strpos", "(", "$", "decodedUrl", ",", "self", "::", "getIndpEnv", "(", "'TYPO3_SITE_URL'", ")", ")", "===", "0", ")", "{", "$", "sanitizedUrl", "=", "$", "url", ";", "}", "// Pass if URL is an absolute file path:", "}", "elseif", "(", "self", "::", "isAbsPath", "(", "$", "decodedUrl", ")", "&&", "self", "::", "isAllowedAbsPath", "(", "$", "decodedUrl", ")", ")", "{", "$", "sanitizedUrl", "=", "$", "url", ";", "// Pass if URL is absolute and below TYPO3 base directory:", "}", "elseif", "(", "strpos", "(", "$", "testAbsoluteUrl", ",", "self", "::", "getIndpEnv", "(", "'TYPO3_SITE_PATH'", ")", ")", "===", "0", "&&", "substr", "(", "$", "decodedUrl", ",", "0", ",", "1", ")", "===", "'/'", ")", "{", "$", "sanitizedUrl", "=", "$", "url", ";", "// Pass if URL is relative and below TYPO3 base directory:", "}", "elseif", "(", "strpos", "(", "$", "testRelativeUrl", ",", "self", "::", "getIndpEnv", "(", "'TYPO3_SITE_PATH'", ")", ")", "===", "0", "&&", "substr", "(", "$", "decodedUrl", ",", "0", ",", "1", ")", "!==", "'/'", ")", "{", "$", "sanitizedUrl", "=", "$", "url", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "url", ")", "&&", "empty", "(", "$", "sanitizedUrl", ")", ")", "{", "self", "::", "sysLog", "(", "'The URL \"'", ".", "$", "url", ".", "'\" is not considered to be local and was denied.'", ",", "'Core'", ",", "self", "::", "SYSLOG_SEVERITY_NOTICE", ")", ";", "}", "return", "$", "sanitizedUrl", ";", "}" ]
Checks if a given string is a valid frame URL to be loaded in the backend. @param string $url potential URL to check @return string either $url if $url is considered to be harmless, or an empty string otherwise
[ "Checks", "if", "a", "given", "string", "is", "a", "valid", "frame", "URL", "to", "be", "loaded", "in", "the", "backend", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L3997-L4029
220,477
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.cHashParams
public static function cHashParams($addQueryParams) { t3lib_div::logDeprecatedFunction(); $params = explode('&', substr($addQueryParams, 1)); // Splitting parameters up /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); $pA = $cacheHash->getRelevantParameters($addQueryParams); // Hook: Allows to manipulate the parameters which are taken to build the chash: if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['cHashParamsHook'])) { $cHashParamsHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['cHashParamsHook']; if (is_array($cHashParamsHook)) { $hookParameters = array( 'addQueryParams' => &$addQueryParams, 'params' => &$params, 'pA' => &$pA, ); $hookReference = NULL; foreach ($cHashParamsHook as $hookFunction) { self::callUserFunction($hookFunction, $hookParameters, $hookReference); } } } return $pA; }
php
public static function cHashParams($addQueryParams) { t3lib_div::logDeprecatedFunction(); $params = explode('&', substr($addQueryParams, 1)); // Splitting parameters up /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); $pA = $cacheHash->getRelevantParameters($addQueryParams); // Hook: Allows to manipulate the parameters which are taken to build the chash: if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['cHashParamsHook'])) { $cHashParamsHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['cHashParamsHook']; if (is_array($cHashParamsHook)) { $hookParameters = array( 'addQueryParams' => &$addQueryParams, 'params' => &$params, 'pA' => &$pA, ); $hookReference = NULL; foreach ($cHashParamsHook as $hookFunction) { self::callUserFunction($hookFunction, $hookParameters, $hookReference); } } } return $pA; }
[ "public", "static", "function", "cHashParams", "(", "$", "addQueryParams", ")", "{", "t3lib_div", "::", "logDeprecatedFunction", "(", ")", ";", "$", "params", "=", "explode", "(", "'&'", ",", "substr", "(", "$", "addQueryParams", ",", "1", ")", ")", ";", "// Splitting parameters up", "/* @var $cacheHash t3lib_cacheHash */", "$", "cacheHash", "=", "t3lib_div", "::", "makeInstance", "(", "'t3lib_cacheHash'", ")", ";", "$", "pA", "=", "$", "cacheHash", "->", "getRelevantParameters", "(", "$", "addQueryParams", ")", ";", "// Hook: Allows to manipulate the parameters which are taken to build the chash:", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'cHashParamsHook'", "]", ")", ")", "{", "$", "cHashParamsHook", "=", "&", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'cHashParamsHook'", "]", ";", "if", "(", "is_array", "(", "$", "cHashParamsHook", ")", ")", "{", "$", "hookParameters", "=", "array", "(", "'addQueryParams'", "=>", "&", "$", "addQueryParams", ",", "'params'", "=>", "&", "$", "params", ",", "'pA'", "=>", "&", "$", "pA", ",", ")", ";", "$", "hookReference", "=", "NULL", ";", "foreach", "(", "$", "cHashParamsHook", "as", "$", "hookFunction", ")", "{", "self", "::", "callUserFunction", "(", "$", "hookFunction", ",", "$", "hookParameters", ",", "$", "hookReference", ")", ";", "}", "}", "}", "return", "$", "pA", ";", "}" ]
Splits the input query-parameters into an array with certain parameters filtered out. Used to create the cHash value @param string $addQueryParams Query-parameters: "&xxx=yyy&zzz=uuu" @return array Array with key/value pairs of query-parameters WITHOUT a certain list of variable names (like id, type, no_cache etc.) and WITH a variable, encryptionKey, specific for this server/installation @see tslib_fe::makeCacheHash(), tslib_cObj::typoLink(), t3lib_div::calculateCHash() @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
[ "Splits", "the", "input", "query", "-", "parameters", "into", "an", "array", "with", "certain", "parameters", "filtered", "out", ".", "Used", "to", "create", "the", "cHash", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4145-L4169
220,478
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.generateCHash
public static function generateCHash($addQueryParams) { t3lib_div::logDeprecatedFunction(); /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); return $cacheHash->generateForParameters($addQueryParams); }
php
public static function generateCHash($addQueryParams) { t3lib_div::logDeprecatedFunction(); /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); return $cacheHash->generateForParameters($addQueryParams); }
[ "public", "static", "function", "generateCHash", "(", "$", "addQueryParams", ")", "{", "t3lib_div", "::", "logDeprecatedFunction", "(", ")", ";", "/* @var $cacheHash t3lib_cacheHash */", "$", "cacheHash", "=", "t3lib_div", "::", "makeInstance", "(", "'t3lib_cacheHash'", ")", ";", "return", "$", "cacheHash", "->", "generateForParameters", "(", "$", "addQueryParams", ")", ";", "}" ]
Returns the cHash based on provided query parameters and added values from internal call @param string $addQueryParams Query-parameters: "&xxx=yyy&zzz=uuu" @return string Hash of all the values @see t3lib_div::cHashParams(), t3lib_div::calculateCHash() @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
[ "Returns", "the", "cHash", "based", "on", "provided", "query", "parameters", "and", "added", "values", "from", "internal", "call" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4179-L4184
220,479
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.calculateCHash
public static function calculateCHash($params) { t3lib_div::logDeprecatedFunction(); /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); return $cacheHash->calculateCacheHash($params); }
php
public static function calculateCHash($params) { t3lib_div::logDeprecatedFunction(); /* @var $cacheHash t3lib_cacheHash */ $cacheHash = t3lib_div::makeInstance('t3lib_cacheHash'); return $cacheHash->calculateCacheHash($params); }
[ "public", "static", "function", "calculateCHash", "(", "$", "params", ")", "{", "t3lib_div", "::", "logDeprecatedFunction", "(", ")", ";", "/* @var $cacheHash t3lib_cacheHash */", "$", "cacheHash", "=", "t3lib_div", "::", "makeInstance", "(", "'t3lib_cacheHash'", ")", ";", "return", "$", "cacheHash", "->", "calculateCacheHash", "(", "$", "params", ")", ";", "}" ]
Calculates the cHash based on the provided parameters @param array $params Array of key-value pairs @return string Hash of all the values @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
[ "Calculates", "the", "cHash", "based", "on", "the", "provided", "parameters" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4193-L4198
220,480
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.llXmlAutoFileName
public static function llXmlAutoFileName($fileRef, $language, $sameLocation = FALSE) { if ($sameLocation) { $location = 'EXT:'; } else { $location = 'typo3conf/l10n/' . $language . '/'; // Default location of translations } // Analyse file reference: if (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) { // Is system: $validatedPrefix = PATH_typo3 . 'sysext/'; #$location = 'EXT:csh_'.$language.'/'; // For system extensions translations are found in "csh_*" extensions (language packs) } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) { // Is global: $validatedPrefix = PATH_typo3 . 'ext/'; } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) { // Is local: $validatedPrefix = PATH_typo3conf . 'ext/'; } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'typo3_src/tests/')) { // Is test: $validatedPrefix = PATH_site . 'typo3_src/tests/'; $location = $validatedPrefix; } else { $validatedPrefix = ''; } if ($validatedPrefix) { // Divide file reference into extension key, directory (if any) and base name: list($file_extKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2); $temp = self::revExplode('/', $file_extPath, 2); if (count($temp) == 1) { array_unshift($temp, ''); } // Add empty first-entry if not there. list($file_extPath, $file_fileName) = $temp; // If $fileRef is already prefix with "[language key]" then we should return it as this if (substr($file_fileName, 0, strlen($language) + 1) === $language . '.') { return $fileRef; } // The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it. return $location . $file_extKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName; } else { return NULL; } }
php
public static function llXmlAutoFileName($fileRef, $language, $sameLocation = FALSE) { if ($sameLocation) { $location = 'EXT:'; } else { $location = 'typo3conf/l10n/' . $language . '/'; // Default location of translations } // Analyse file reference: if (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) { // Is system: $validatedPrefix = PATH_typo3 . 'sysext/'; #$location = 'EXT:csh_'.$language.'/'; // For system extensions translations are found in "csh_*" extensions (language packs) } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) { // Is global: $validatedPrefix = PATH_typo3 . 'ext/'; } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) { // Is local: $validatedPrefix = PATH_typo3conf . 'ext/'; } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'typo3_src/tests/')) { // Is test: $validatedPrefix = PATH_site . 'typo3_src/tests/'; $location = $validatedPrefix; } else { $validatedPrefix = ''; } if ($validatedPrefix) { // Divide file reference into extension key, directory (if any) and base name: list($file_extKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2); $temp = self::revExplode('/', $file_extPath, 2); if (count($temp) == 1) { array_unshift($temp, ''); } // Add empty first-entry if not there. list($file_extPath, $file_fileName) = $temp; // If $fileRef is already prefix with "[language key]" then we should return it as this if (substr($file_fileName, 0, strlen($language) + 1) === $language . '.') { return $fileRef; } // The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it. return $location . $file_extKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName; } else { return NULL; } }
[ "public", "static", "function", "llXmlAutoFileName", "(", "$", "fileRef", ",", "$", "language", ",", "$", "sameLocation", "=", "FALSE", ")", "{", "if", "(", "$", "sameLocation", ")", "{", "$", "location", "=", "'EXT:'", ";", "}", "else", "{", "$", "location", "=", "'typo3conf/l10n/'", ".", "$", "language", ".", "'/'", ";", "// Default location of translations", "}", "// Analyse file reference:", "if", "(", "self", "::", "isFirstPartOfStr", "(", "$", "fileRef", ",", "PATH_typo3", ".", "'sysext/'", ")", ")", "{", "// Is system:", "$", "validatedPrefix", "=", "PATH_typo3", ".", "'sysext/'", ";", "#$location = 'EXT:csh_'.$language.'/';\t// For system extensions translations are found in \"csh_*\" extensions (language packs)", "}", "elseif", "(", "self", "::", "isFirstPartOfStr", "(", "$", "fileRef", ",", "PATH_typo3", ".", "'ext/'", ")", ")", "{", "// Is global:", "$", "validatedPrefix", "=", "PATH_typo3", ".", "'ext/'", ";", "}", "elseif", "(", "self", "::", "isFirstPartOfStr", "(", "$", "fileRef", ",", "PATH_typo3conf", ".", "'ext/'", ")", ")", "{", "// Is local:", "$", "validatedPrefix", "=", "PATH_typo3conf", ".", "'ext/'", ";", "}", "elseif", "(", "self", "::", "isFirstPartOfStr", "(", "$", "fileRef", ",", "PATH_site", ".", "'typo3_src/tests/'", ")", ")", "{", "// Is test:", "$", "validatedPrefix", "=", "PATH_site", ".", "'typo3_src/tests/'", ";", "$", "location", "=", "$", "validatedPrefix", ";", "}", "else", "{", "$", "validatedPrefix", "=", "''", ";", "}", "if", "(", "$", "validatedPrefix", ")", "{", "// Divide file reference into extension key, directory (if any) and base name:", "list", "(", "$", "file_extKey", ",", "$", "file_extPath", ")", "=", "explode", "(", "'/'", ",", "substr", "(", "$", "fileRef", ",", "strlen", "(", "$", "validatedPrefix", ")", ")", ",", "2", ")", ";", "$", "temp", "=", "self", "::", "revExplode", "(", "'/'", ",", "$", "file_extPath", ",", "2", ")", ";", "if", "(", "count", "(", "$", "temp", ")", "==", "1", ")", "{", "array_unshift", "(", "$", "temp", ",", "''", ")", ";", "}", "// Add empty first-entry if not there.", "list", "(", "$", "file_extPath", ",", "$", "file_fileName", ")", "=", "$", "temp", ";", "// If $fileRef is already prefix with \"[language key]\" then we should return it as this", "if", "(", "substr", "(", "$", "file_fileName", ",", "0", ",", "strlen", "(", "$", "language", ")", "+", "1", ")", "===", "$", "language", ".", "'.'", ")", "{", "return", "$", "fileRef", ";", "}", "// The filename is prefixed with \"[language key].\" because it prevents the llxmltranslate tool from detecting it.", "return", "$", "location", ".", "$", "file_extKey", ".", "'/'", ".", "(", "$", "file_extPath", "?", "$", "file_extPath", ".", "'/'", ":", "''", ")", ".", "$", "language", ".", "'.'", ".", "$", "file_fileName", ";", "}", "else", "{", "return", "NULL", ";", "}", "}" ]
Returns auto-filename for locallang-XML localizations. @param string $fileRef Absolute file reference to locallang-XML file. Must be inside system/global/local extension @param string $language Language key @param boolean $sameLocation if TRUE, then locallang-XML localization file name will be returned with same directory as $fileRef @return string Returns the filename reference for the language unless error occurred (or local mode is used) in which case it will be NULL
[ "Returns", "auto", "-", "filename", "for", "locallang", "-", "XML", "localizations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4503-L4548
220,481
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.resolveAllSheetsInDS
public static function resolveAllSheetsInDS(array $dataStructArray) { if (is_array($dataStructArray['sheets'])) { $out = array('sheets' => array()); foreach ($dataStructArray['sheets'] as $sheetId => $sDat) { list($ds, $aS) = self::resolveSheetDefInDS($dataStructArray, $sheetId); if ($sheetId == $aS) { $out['sheets'][$aS] = $ds; } } } else { list($ds) = self::resolveSheetDefInDS($dataStructArray); $out = array('sheets' => array('sDEF' => $ds)); } return $out; }
php
public static function resolveAllSheetsInDS(array $dataStructArray) { if (is_array($dataStructArray['sheets'])) { $out = array('sheets' => array()); foreach ($dataStructArray['sheets'] as $sheetId => $sDat) { list($ds, $aS) = self::resolveSheetDefInDS($dataStructArray, $sheetId); if ($sheetId == $aS) { $out['sheets'][$aS] = $ds; } } } else { list($ds) = self::resolveSheetDefInDS($dataStructArray); $out = array('sheets' => array('sDEF' => $ds)); } return $out; }
[ "public", "static", "function", "resolveAllSheetsInDS", "(", "array", "$", "dataStructArray", ")", "{", "if", "(", "is_array", "(", "$", "dataStructArray", "[", "'sheets'", "]", ")", ")", "{", "$", "out", "=", "array", "(", "'sheets'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "dataStructArray", "[", "'sheets'", "]", "as", "$", "sheetId", "=>", "$", "sDat", ")", "{", "list", "(", "$", "ds", ",", "$", "aS", ")", "=", "self", "::", "resolveSheetDefInDS", "(", "$", "dataStructArray", ",", "$", "sheetId", ")", ";", "if", "(", "$", "sheetId", "==", "$", "aS", ")", "{", "$", "out", "[", "'sheets'", "]", "[", "$", "aS", "]", "=", "$", "ds", ";", "}", "}", "}", "else", "{", "list", "(", "$", "ds", ")", "=", "self", "::", "resolveSheetDefInDS", "(", "$", "dataStructArray", ")", ";", "$", "out", "=", "array", "(", "'sheets'", "=>", "array", "(", "'sDEF'", "=>", "$", "ds", ")", ")", ";", "}", "return", "$", "out", ";", "}" ]
Resolves ALL sheet definitions in dataStructArray If no sheet is found, then the default "sDEF" will be created with the dataStructure inside. @param array $dataStructArray Input data structure, possibly with a sheet-definition and references to external data source files. @return array Output data structure with all sheets resolved as arrays.
[ "Resolves", "ALL", "sheet", "definitions", "in", "dataStructArray", "If", "no", "sheet", "is", "found", "then", "the", "default", "sDEF", "will", "be", "created", "with", "the", "dataStructure", "inside", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4630-L4644
220,482
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getValidClassPrefixes
public static function getValidClassPrefixes() { $validPrefixes = array('tx_', 'Tx_', 'user_', 'User_'); if ( isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) && is_string($GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) ) { $validPrefixes = array_merge( $validPrefixes, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) ); } return $validPrefixes; }
php
public static function getValidClassPrefixes() { $validPrefixes = array('tx_', 'Tx_', 'user_', 'User_'); if ( isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) && is_string($GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) ) { $validPrefixes = array_merge( $validPrefixes, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['additionalAllowedClassPrefixes']) ); } return $validPrefixes; }
[ "public", "static", "function", "getValidClassPrefixes", "(", ")", "{", "$", "validPrefixes", "=", "array", "(", "'tx_'", ",", "'Tx_'", ",", "'user_'", ",", "'User_'", ")", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'additionalAllowedClassPrefixes'", "]", ")", "&&", "is_string", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'additionalAllowedClassPrefixes'", "]", ")", ")", "{", "$", "validPrefixes", "=", "array_merge", "(", "$", "validPrefixes", ",", "t3lib_div", "::", "trimExplode", "(", "','", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'additionalAllowedClassPrefixes'", "]", ")", ")", ";", "}", "return", "$", "validPrefixes", ";", "}" ]
Returns all valid class prefixes. @return array Array of valid prefixed of class names
[ "Returns", "all", "valid", "class", "prefixes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4859-L4871
220,483
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.getClassName
protected static function getClassName($className) { if (class_exists($className)) { while (class_exists('ux_' . $className, FALSE)) { $className = 'ux_' . $className; } } return $className; }
php
protected static function getClassName($className) { if (class_exists($className)) { while (class_exists('ux_' . $className, FALSE)) { $className = 'ux_' . $className; } } return $className; }
[ "protected", "static", "function", "getClassName", "(", "$", "className", ")", "{", "if", "(", "class_exists", "(", "$", "className", ")", ")", "{", "while", "(", "class_exists", "(", "'ux_'", ".", "$", "className", ",", "FALSE", ")", ")", "{", "$", "className", "=", "'ux_'", ".", "$", "className", ";", "}", "}", "return", "$", "className", ";", "}" ]
Returns the class name for a new instance, taking into account the class-extension API. @param string $className Base class name to evaluate @return string Final class name to instantiate with "new [classname]"
[ "Returns", "the", "class", "name", "for", "a", "new", "instance", "taking", "into", "account", "the", "class", "-", "extension", "API", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L4976-L4984
220,484
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.setSingletonInstance
public static function setSingletonInstance($className, t3lib_Singleton $instance) { self::checkInstanceClassName($className, $instance); self::$singletonInstances[$className] = $instance; }
php
public static function setSingletonInstance($className, t3lib_Singleton $instance) { self::checkInstanceClassName($className, $instance); self::$singletonInstances[$className] = $instance; }
[ "public", "static", "function", "setSingletonInstance", "(", "$", "className", ",", "t3lib_Singleton", "$", "instance", ")", "{", "self", "::", "checkInstanceClassName", "(", "$", "className", ",", "$", "instance", ")", ";", "self", "::", "$", "singletonInstances", "[", "$", "className", "]", "=", "$", "instance", ";", "}" ]
Sets the instance of a singleton class to be returned by makeInstance. If this function is called multiple times for the same $className, makeInstance will return the last set instance. Warning: This is a helper method for unit tests. Do not call this directly in production code! @see makeInstance @param string $className the name of the class to set, must not be empty @param t3lib_Singleton $instance the instance to set, must be an instance of $className @return void
[ "Sets", "the", "instance", "of", "a", "singleton", "class", "to", "be", "returned", "by", "makeInstance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5001-L5004
220,485
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.addInstance
public static function addInstance($className, $instance) { self::checkInstanceClassName($className, $instance); if ($instance instanceof t3lib_Singleton) { throw new InvalidArgumentException( '$instance must not be an instance of t3lib_Singleton. ' . 'For setting singletons, please use setSingletonInstance.', 1288969325 ); } if (!isset(self::$nonSingletonInstances[$className])) { self::$nonSingletonInstances[$className] = array(); } self::$nonSingletonInstances[$className][] = $instance; }
php
public static function addInstance($className, $instance) { self::checkInstanceClassName($className, $instance); if ($instance instanceof t3lib_Singleton) { throw new InvalidArgumentException( '$instance must not be an instance of t3lib_Singleton. ' . 'For setting singletons, please use setSingletonInstance.', 1288969325 ); } if (!isset(self::$nonSingletonInstances[$className])) { self::$nonSingletonInstances[$className] = array(); } self::$nonSingletonInstances[$className][] = $instance; }
[ "public", "static", "function", "addInstance", "(", "$", "className", ",", "$", "instance", ")", "{", "self", "::", "checkInstanceClassName", "(", "$", "className", ",", "$", "instance", ")", ";", "if", "(", "$", "instance", "instanceof", "t3lib_Singleton", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$instance must not be an instance of t3lib_Singleton. '", ".", "'For setting singletons, please use setSingletonInstance.'", ",", "1288969325", ")", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "nonSingletonInstances", "[", "$", "className", "]", ")", ")", "{", "self", "::", "$", "nonSingletonInstances", "[", "$", "className", "]", "=", "array", "(", ")", ";", "}", "self", "::", "$", "nonSingletonInstances", "[", "$", "className", "]", "[", "]", "=", "$", "instance", ";", "}" ]
Sets the instance of a non-singleton class to be returned by makeInstance. If this function is called multiple times for the same $className, makeInstance will return the instances in the order in which they have been added (FIFO). Warning: This is a helper method for unit tests. Do not call this directly in production code! @see makeInstance @throws InvalidArgumentException if class extends t3lib_Singleton @param string $className the name of the class to set, must not be empty @param object $instance the instance to set, must be an instance of $className @return void
[ "Sets", "the", "instance", "of", "a", "non", "-", "singleton", "class", "to", "be", "returned", "by", "makeInstance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5023-L5038
220,486
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.makeInstanceService
public static function makeInstanceService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) { $error = FALSE; if (!is_array($excludeServiceKeys)) { $excludeServiceKeys = self::trimExplode(',', $excludeServiceKeys, 1); } $requestInfo = array( 'requestedServiceType' => $serviceType, 'requestedServiceSubType' => $serviceSubType, 'requestedExcludeServiceKeys' => $excludeServiceKeys, ); while ($info = t3lib_extMgm::findService($serviceType, $serviceSubType, $excludeServiceKeys)) { // provide information about requested service to service object $info = array_merge($info, $requestInfo); // Check persistent object and if found, call directly and exit. if (is_object($GLOBALS['T3_VAR']['makeInstanceService'][$info['className']])) { // update request info in persistent object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->info = $info; // reset service and return object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->reset(); return $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]; // include file and create object } else { $requireFile = self::getFileAbsFileName($info['classFile']); if (@is_file($requireFile)) { self::requireOnce($requireFile); $obj = self::makeInstance($info['className']); if (is_object($obj)) { if (!@is_callable(array($obj, 'init'))) { // use silent logging??? I don't think so. die ('Broken service:' . t3lib_utility_Debug::viewArray($info)); } $obj->info = $info; if ($obj->init()) { // service available? // create persistent object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']] = $obj; // needed to delete temp files register_shutdown_function(array(&$obj, '__destruct')); return $obj; // object is passed as reference by function definition } $error = $obj->getLastErrorArray(); unset($obj); } } } // deactivate the service t3lib_extMgm::deactivateService($info['serviceType'], $info['serviceKey']); } return $error; }
php
public static function makeInstanceService($serviceType, $serviceSubType = '', $excludeServiceKeys = array()) { $error = FALSE; if (!is_array($excludeServiceKeys)) { $excludeServiceKeys = self::trimExplode(',', $excludeServiceKeys, 1); } $requestInfo = array( 'requestedServiceType' => $serviceType, 'requestedServiceSubType' => $serviceSubType, 'requestedExcludeServiceKeys' => $excludeServiceKeys, ); while ($info = t3lib_extMgm::findService($serviceType, $serviceSubType, $excludeServiceKeys)) { // provide information about requested service to service object $info = array_merge($info, $requestInfo); // Check persistent object and if found, call directly and exit. if (is_object($GLOBALS['T3_VAR']['makeInstanceService'][$info['className']])) { // update request info in persistent object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->info = $info; // reset service and return object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->reset(); return $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]; // include file and create object } else { $requireFile = self::getFileAbsFileName($info['classFile']); if (@is_file($requireFile)) { self::requireOnce($requireFile); $obj = self::makeInstance($info['className']); if (is_object($obj)) { if (!@is_callable(array($obj, 'init'))) { // use silent logging??? I don't think so. die ('Broken service:' . t3lib_utility_Debug::viewArray($info)); } $obj->info = $info; if ($obj->init()) { // service available? // create persistent object $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']] = $obj; // needed to delete temp files register_shutdown_function(array(&$obj, '__destruct')); return $obj; // object is passed as reference by function definition } $error = $obj->getLastErrorArray(); unset($obj); } } } // deactivate the service t3lib_extMgm::deactivateService($info['serviceType'], $info['serviceKey']); } return $error; }
[ "public", "static", "function", "makeInstanceService", "(", "$", "serviceType", ",", "$", "serviceSubType", "=", "''", ",", "$", "excludeServiceKeys", "=", "array", "(", ")", ")", "{", "$", "error", "=", "FALSE", ";", "if", "(", "!", "is_array", "(", "$", "excludeServiceKeys", ")", ")", "{", "$", "excludeServiceKeys", "=", "self", "::", "trimExplode", "(", "','", ",", "$", "excludeServiceKeys", ",", "1", ")", ";", "}", "$", "requestInfo", "=", "array", "(", "'requestedServiceType'", "=>", "$", "serviceType", ",", "'requestedServiceSubType'", "=>", "$", "serviceSubType", ",", "'requestedExcludeServiceKeys'", "=>", "$", "excludeServiceKeys", ",", ")", ";", "while", "(", "$", "info", "=", "t3lib_extMgm", "::", "findService", "(", "$", "serviceType", ",", "$", "serviceSubType", ",", "$", "excludeServiceKeys", ")", ")", "{", "// provide information about requested service to service object", "$", "info", "=", "array_merge", "(", "$", "info", ",", "$", "requestInfo", ")", ";", "// Check persistent object and if found, call directly and exit.", "if", "(", "is_object", "(", "$", "GLOBALS", "[", "'T3_VAR'", "]", "[", "'makeInstanceService'", "]", "[", "$", "info", "[", "'className'", "]", "]", ")", ")", "{", "// update request info in persistent object", "$", "GLOBALS", "[", "'T3_VAR'", "]", "[", "'makeInstanceService'", "]", "[", "$", "info", "[", "'className'", "]", "]", "->", "info", "=", "$", "info", ";", "// reset service and return object", "$", "GLOBALS", "[", "'T3_VAR'", "]", "[", "'makeInstanceService'", "]", "[", "$", "info", "[", "'className'", "]", "]", "->", "reset", "(", ")", ";", "return", "$", "GLOBALS", "[", "'T3_VAR'", "]", "[", "'makeInstanceService'", "]", "[", "$", "info", "[", "'className'", "]", "]", ";", "// include file and create object", "}", "else", "{", "$", "requireFile", "=", "self", "::", "getFileAbsFileName", "(", "$", "info", "[", "'classFile'", "]", ")", ";", "if", "(", "@", "is_file", "(", "$", "requireFile", ")", ")", "{", "self", "::", "requireOnce", "(", "$", "requireFile", ")", ";", "$", "obj", "=", "self", "::", "makeInstance", "(", "$", "info", "[", "'className'", "]", ")", ";", "if", "(", "is_object", "(", "$", "obj", ")", ")", "{", "if", "(", "!", "@", "is_callable", "(", "array", "(", "$", "obj", ",", "'init'", ")", ")", ")", "{", "// use silent logging??? I don't think so.", "die", "(", "'Broken service:'", ".", "t3lib_utility_Debug", "::", "viewArray", "(", "$", "info", ")", ")", ";", "}", "$", "obj", "->", "info", "=", "$", "info", ";", "if", "(", "$", "obj", "->", "init", "(", ")", ")", "{", "// service available?", "// create persistent object", "$", "GLOBALS", "[", "'T3_VAR'", "]", "[", "'makeInstanceService'", "]", "[", "$", "info", "[", "'className'", "]", "]", "=", "$", "obj", ";", "// needed to delete temp files", "register_shutdown_function", "(", "array", "(", "&", "$", "obj", ",", "'__destruct'", ")", ")", ";", "return", "$", "obj", ";", "// object is passed as reference by function definition", "}", "$", "error", "=", "$", "obj", "->", "getLastErrorArray", "(", ")", ";", "unset", "(", "$", "obj", ")", ";", "}", "}", "}", "// deactivate the service", "t3lib_extMgm", "::", "deactivateService", "(", "$", "info", "[", "'serviceType'", "]", ",", "$", "info", "[", "'serviceKey'", "]", ")", ";", "}", "return", "$", "error", ";", "}" ]
Find the best service and check if it works. Returns object of the service class. @param string $serviceType Type of service (service key). @param string $serviceSubType Sub type like file extensions or similar. Defined by the service. @param mixed $excludeServiceKeys List of service keys which should be excluded in the search for a service. Array or comma list. @return object The service object or an array with error info's.
[ "Find", "the", "best", "service", "and", "check", "if", "it", "works", ".", "Returns", "object", "of", "the", "service", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5086-L5145
220,487
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.quoted_printable
public static function quoted_printable($string, $maxlen = 76) { // Make sure the string contains only Unix line breaks $string = str_replace(CRLF, LF, $string); // Replace Windows breaks (\r\n) $string = str_replace(CR, LF, $string); // Replace Mac breaks (\r) $linebreak = LF; // Default line break for Unix systems. if (TYPO3_OS == 'WIN') { $linebreak = CRLF; // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the line break needs to be \r\n. } $newString = ''; $theLines = explode(LF, $string); // Split lines foreach ($theLines as $val) { $newVal = ''; $theValLen = strlen($val); $len = 0; for ($index = 0; $index < $theValLen; $index++) { // Walk through each character of this line $char = substr($val, $index, 1); $ordVal = ord($char); if ($len > ($maxlen - 4) || ($len > ($maxlen - 14) && $ordVal == 32)) { $newVal .= '=' . $linebreak; // Add a line break $len = 0; // Reset the length counter } if (($ordVal >= 33 && $ordVal <= 60) || ($ordVal >= 62 && $ordVal <= 126) || $ordVal == 9 || $ordVal == 32) { $newVal .= $char; // This character is ok, add it to the message $len++; } else { $newVal .= sprintf('=%02X', $ordVal); // Special character, needs to be encoded $len += 3; } } $newVal = preg_replace('/' . chr(32) . '$/', '=20', $newVal); // Replaces a possible SPACE-character at the end of a line $newVal = preg_replace('/' . TAB . '$/', '=09', $newVal); // Replaces a possible TAB-character at the end of a line $newString .= $newVal . $linebreak; } return preg_replace('/' . $linebreak . '$/', '', $newString); // Remove last newline }
php
public static function quoted_printable($string, $maxlen = 76) { // Make sure the string contains only Unix line breaks $string = str_replace(CRLF, LF, $string); // Replace Windows breaks (\r\n) $string = str_replace(CR, LF, $string); // Replace Mac breaks (\r) $linebreak = LF; // Default line break for Unix systems. if (TYPO3_OS == 'WIN') { $linebreak = CRLF; // Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the line break needs to be \r\n. } $newString = ''; $theLines = explode(LF, $string); // Split lines foreach ($theLines as $val) { $newVal = ''; $theValLen = strlen($val); $len = 0; for ($index = 0; $index < $theValLen; $index++) { // Walk through each character of this line $char = substr($val, $index, 1); $ordVal = ord($char); if ($len > ($maxlen - 4) || ($len > ($maxlen - 14) && $ordVal == 32)) { $newVal .= '=' . $linebreak; // Add a line break $len = 0; // Reset the length counter } if (($ordVal >= 33 && $ordVal <= 60) || ($ordVal >= 62 && $ordVal <= 126) || $ordVal == 9 || $ordVal == 32) { $newVal .= $char; // This character is ok, add it to the message $len++; } else { $newVal .= sprintf('=%02X', $ordVal); // Special character, needs to be encoded $len += 3; } } $newVal = preg_replace('/' . chr(32) . '$/', '=20', $newVal); // Replaces a possible SPACE-character at the end of a line $newVal = preg_replace('/' . TAB . '$/', '=09', $newVal); // Replaces a possible TAB-character at the end of a line $newString .= $newVal . $linebreak; } return preg_replace('/' . $linebreak . '$/', '', $newString); // Remove last newline }
[ "public", "static", "function", "quoted_printable", "(", "$", "string", ",", "$", "maxlen", "=", "76", ")", "{", "// Make sure the string contains only Unix line breaks", "$", "string", "=", "str_replace", "(", "CRLF", ",", "LF", ",", "$", "string", ")", ";", "// Replace Windows breaks (\\r\\n)", "$", "string", "=", "str_replace", "(", "CR", ",", "LF", ",", "$", "string", ")", ";", "// Replace Mac breaks (\\r)", "$", "linebreak", "=", "LF", ";", "// Default line break for Unix systems.", "if", "(", "TYPO3_OS", "==", "'WIN'", ")", "{", "$", "linebreak", "=", "CRLF", ";", "// Line break for Windows. This is needed because PHP on Windows systems send mails via SMTP instead of using sendmail, and thus the line break needs to be \\r\\n.", "}", "$", "newString", "=", "''", ";", "$", "theLines", "=", "explode", "(", "LF", ",", "$", "string", ")", ";", "// Split lines", "foreach", "(", "$", "theLines", "as", "$", "val", ")", "{", "$", "newVal", "=", "''", ";", "$", "theValLen", "=", "strlen", "(", "$", "val", ")", ";", "$", "len", "=", "0", ";", "for", "(", "$", "index", "=", "0", ";", "$", "index", "<", "$", "theValLen", ";", "$", "index", "++", ")", "{", "// Walk through each character of this line", "$", "char", "=", "substr", "(", "$", "val", ",", "$", "index", ",", "1", ")", ";", "$", "ordVal", "=", "ord", "(", "$", "char", ")", ";", "if", "(", "$", "len", ">", "(", "$", "maxlen", "-", "4", ")", "||", "(", "$", "len", ">", "(", "$", "maxlen", "-", "14", ")", "&&", "$", "ordVal", "==", "32", ")", ")", "{", "$", "newVal", ".=", "'='", ".", "$", "linebreak", ";", "// Add a line break", "$", "len", "=", "0", ";", "// Reset the length counter", "}", "if", "(", "(", "$", "ordVal", ">=", "33", "&&", "$", "ordVal", "<=", "60", ")", "||", "(", "$", "ordVal", ">=", "62", "&&", "$", "ordVal", "<=", "126", ")", "||", "$", "ordVal", "==", "9", "||", "$", "ordVal", "==", "32", ")", "{", "$", "newVal", ".=", "$", "char", ";", "// This character is ok, add it to the message", "$", "len", "++", ";", "}", "else", "{", "$", "newVal", ".=", "sprintf", "(", "'=%02X'", ",", "$", "ordVal", ")", ";", "// Special character, needs to be encoded", "$", "len", "+=", "3", ";", "}", "}", "$", "newVal", "=", "preg_replace", "(", "'/'", ".", "chr", "(", "32", ")", ".", "'$/'", ",", "'=20'", ",", "$", "newVal", ")", ";", "// Replaces a possible SPACE-character at the end of a line", "$", "newVal", "=", "preg_replace", "(", "'/'", ".", "TAB", ".", "'$/'", ",", "'=09'", ",", "$", "newVal", ")", ";", "// Replaces a possible TAB-character at the end of a line", "$", "newString", ".=", "$", "newVal", ".", "$", "linebreak", ";", "}", "return", "preg_replace", "(", "'/'", ".", "$", "linebreak", ".", "'$/'", ",", "''", ",", "$", "newString", ")", ";", "// Remove last newline", "}" ]
Implementation of quoted-printable encode. See RFC 1521, section 5.1 Quoted-Printable Content-Transfer-Encoding @param string $string Content to encode @param integer $maxlen Length of the lines, default is 76 @return string The QP encoded string
[ "Implementation", "of", "quoted", "-", "printable", "encode", ".", "See", "RFC", "1521", "section", "5", ".", "1", "Quoted", "-", "Printable", "Content", "-", "Transfer", "-", "Encoding" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5259-L5295
220,488
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.freetypeDpiComp
public static function freetypeDpiComp($font_size) { $dpi = intval($GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi']); if ($dpi != 72) { $font_size = $font_size / $dpi * 72; } return $font_size; }
php
public static function freetypeDpiComp($font_size) { $dpi = intval($GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi']); if ($dpi != 72) { $font_size = $font_size / $dpi * 72; } return $font_size; }
[ "public", "static", "function", "freetypeDpiComp", "(", "$", "font_size", ")", "{", "$", "dpi", "=", "intval", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'GFX'", "]", "[", "'TTFdpi'", "]", ")", ";", "if", "(", "$", "dpi", "!=", "72", ")", "{", "$", "font_size", "=", "$", "font_size", "/", "$", "dpi", "*", "72", ";", "}", "return", "$", "font_size", ";", "}" ]
Function to compensate for FreeType2 96 dpi @param integer $font_size Fontsize for freetype function call @return integer Compensated fontsize based on $GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi']
[ "Function", "to", "compensate", "for", "FreeType2", "96", "dpi" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5429-L5435
220,489
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.initSysLog
public static function initSysLog() { // for CLI logging name is <fqdn-hostname>:<TYPO3-path> // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if (defined('TYPO3_cliMode') && TYPO3_cliMode) { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getHostname($requestHost = FALSE) . ':' . PATH_site; } // for Web logging name is <protocol>://<request-hostame>/<site-path> else { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getIndpEnv('TYPO3_SITE_URL'); } // init custom logging if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'])) { $params = array('initLog' => TRUE); $fakeThis = FALSE; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'] as $hookMethod) { self::callUserFunction($hookMethod, $params, $fakeThis); } } // init TYPO3 logging foreach (explode(';', $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'], 2) as $log) { list($type, $destination) = explode(',', $log, 3); if ($type == 'syslog') { if (TYPO3_OS == 'WIN') { $facility = LOG_USER; } else { $facility = constant('LOG_' . strtoupper($destination)); } openlog($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'], LOG_ODELAY, $facility); } } $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = t3lib_utility_Math::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'], 0, 4); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit'] = TRUE; }
php
public static function initSysLog() { // for CLI logging name is <fqdn-hostname>:<TYPO3-path> // Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined if (defined('TYPO3_cliMode') && TYPO3_cliMode) { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getHostname($requestHost = FALSE) . ':' . PATH_site; } // for Web logging name is <protocol>://<request-hostame>/<site-path> else { $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] = self::getIndpEnv('TYPO3_SITE_URL'); } // init custom logging if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'])) { $params = array('initLog' => TRUE); $fakeThis = FALSE; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'] as $hookMethod) { self::callUserFunction($hookMethod, $params, $fakeThis); } } // init TYPO3 logging foreach (explode(';', $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'], 2) as $log) { list($type, $destination) = explode(',', $log, 3); if ($type == 'syslog') { if (TYPO3_OS == 'WIN') { $facility = LOG_USER; } else { $facility = constant('LOG_' . strtoupper($destination)); } openlog($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'], LOG_ODELAY, $facility); } } $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = t3lib_utility_Math::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'], 0, 4); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit'] = TRUE; }
[ "public", "static", "function", "initSysLog", "(", ")", "{", "// for CLI logging name is <fqdn-hostname>:<TYPO3-path>", "// Note that TYPO3_REQUESTTYPE is not used here as it may not yet be defined", "if", "(", "defined", "(", "'TYPO3_cliMode'", ")", "&&", "TYPO3_cliMode", ")", "{", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLogHost'", "]", "=", "self", "::", "getHostname", "(", "$", "requestHost", "=", "FALSE", ")", ".", "':'", ".", "PATH_site", ";", "}", "// for Web logging name is <protocol>://<request-hostame>/<site-path>", "else", "{", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLogHost'", "]", "=", "self", "::", "getIndpEnv", "(", "'TYPO3_SITE_URL'", ")", ";", "}", "// init custom logging", "if", "(", "is_array", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLog'", "]", ")", ")", "{", "$", "params", "=", "array", "(", "'initLog'", "=>", "TRUE", ")", ";", "$", "fakeThis", "=", "FALSE", ";", "foreach", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLog'", "]", "as", "$", "hookMethod", ")", "{", "self", "::", "callUserFunction", "(", "$", "hookMethod", ",", "$", "params", ",", "$", "fakeThis", ")", ";", "}", "}", "// init TYPO3 logging", "foreach", "(", "explode", "(", "';'", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'systemLog'", "]", ",", "2", ")", "as", "$", "log", ")", "{", "list", "(", "$", "type", ",", "$", "destination", ")", "=", "explode", "(", "','", ",", "$", "log", ",", "3", ")", ";", "if", "(", "$", "type", "==", "'syslog'", ")", "{", "if", "(", "TYPO3_OS", "==", "'WIN'", ")", "{", "$", "facility", "=", "LOG_USER", ";", "}", "else", "{", "$", "facility", "=", "constant", "(", "'LOG_'", ".", "strtoupper", "(", "$", "destination", ")", ")", ";", "}", "openlog", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLogHost'", "]", ",", "LOG_ODELAY", ",", "$", "facility", ")", ";", "}", "}", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'systemLogLevel'", "]", "=", "t3lib_utility_Math", "::", "forceIntegerInRange", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'systemLogLevel'", "]", ",", "0", ",", "4", ")", ";", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SC_OPTIONS'", "]", "[", "'t3lib/class.t3lib_div.php'", "]", "[", "'systemLogInit'", "]", "=", "TRUE", ";", "}" ]
Initialize the system log. @return void @see sysLog()
[ "Initialize", "the", "system", "log", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5443-L5479
220,490
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.deprecationLog
public static function deprecationLog($msg) { if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) { return; } $log = $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']; $date = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ': '); // legacy values (no strict comparison, $log can be boolean, string or int) if ($log === TRUE || $log == '1') { $log = 'file'; } if (stripos($log, 'file') !== FALSE) { // In case lock is acquired before autoloader was defined: if (class_exists('t3lib_lock') === FALSE) { require_once PATH_t3lib . 'class.t3lib_lock.php'; } // write a longer message to the deprecation log $destination = self::getDeprecationLogFileName(); $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']); /** @var t3lib_lock $lockObject */ $lockObject->setEnableLogging(FALSE); $lockObject->acquire(); $file = @fopen($destination, 'a'); if ($file) { @fwrite($file, $date . $msg . LF); @fclose($file); self::fixPermissions($destination); } $lockObject->release(); } if (stripos($log, 'devlog') !== FALSE) { // copy message also to the developer log self::devLog($msg, 'Core', self::SYSLOG_SEVERITY_WARNING); } // do not use console in login screen if (stripos($log, 'console') !== FALSE && isset($GLOBALS['BE_USER']->user['uid'])) { t3lib_utility_Debug::debug($msg, $date, 'Deprecation Log'); } }
php
public static function deprecationLog($msg) { if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) { return; } $log = $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']; $date = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] . ': '); // legacy values (no strict comparison, $log can be boolean, string or int) if ($log === TRUE || $log == '1') { $log = 'file'; } if (stripos($log, 'file') !== FALSE) { // In case lock is acquired before autoloader was defined: if (class_exists('t3lib_lock') === FALSE) { require_once PATH_t3lib . 'class.t3lib_lock.php'; } // write a longer message to the deprecation log $destination = self::getDeprecationLogFileName(); $lockObject = t3lib_div::makeInstance('t3lib_lock', $destination, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']); /** @var t3lib_lock $lockObject */ $lockObject->setEnableLogging(FALSE); $lockObject->acquire(); $file = @fopen($destination, 'a'); if ($file) { @fwrite($file, $date . $msg . LF); @fclose($file); self::fixPermissions($destination); } $lockObject->release(); } if (stripos($log, 'devlog') !== FALSE) { // copy message also to the developer log self::devLog($msg, 'Core', self::SYSLOG_SEVERITY_WARNING); } // do not use console in login screen if (stripos($log, 'console') !== FALSE && isset($GLOBALS['BE_USER']->user['uid'])) { t3lib_utility_Debug::debug($msg, $date, 'Deprecation Log'); } }
[ "public", "static", "function", "deprecationLog", "(", "$", "msg", ")", "{", "if", "(", "!", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'enableDeprecationLog'", "]", ")", "{", "return", ";", "}", "$", "log", "=", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'enableDeprecationLog'", "]", ";", "$", "date", "=", "date", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'ddmmyy'", "]", ".", "' '", ".", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'hhmm'", "]", ".", "': '", ")", ";", "// legacy values (no strict comparison, $log can be boolean, string or int)", "if", "(", "$", "log", "===", "TRUE", "||", "$", "log", "==", "'1'", ")", "{", "$", "log", "=", "'file'", ";", "}", "if", "(", "stripos", "(", "$", "log", ",", "'file'", ")", "!==", "FALSE", ")", "{", "// In case lock is acquired before autoloader was defined:", "if", "(", "class_exists", "(", "'t3lib_lock'", ")", "===", "FALSE", ")", "{", "require_once", "PATH_t3lib", ".", "'class.t3lib_lock.php'", ";", "}", "// write a longer message to the deprecation log", "$", "destination", "=", "self", "::", "getDeprecationLogFileName", "(", ")", ";", "$", "lockObject", "=", "t3lib_div", "::", "makeInstance", "(", "'t3lib_lock'", ",", "$", "destination", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'lockingMode'", "]", ")", ";", "/** @var t3lib_lock $lockObject */", "$", "lockObject", "->", "setEnableLogging", "(", "FALSE", ")", ";", "$", "lockObject", "->", "acquire", "(", ")", ";", "$", "file", "=", "@", "fopen", "(", "$", "destination", ",", "'a'", ")", ";", "if", "(", "$", "file", ")", "{", "@", "fwrite", "(", "$", "file", ",", "$", "date", ".", "$", "msg", ".", "LF", ")", ";", "@", "fclose", "(", "$", "file", ")", ";", "self", "::", "fixPermissions", "(", "$", "destination", ")", ";", "}", "$", "lockObject", "->", "release", "(", ")", ";", "}", "if", "(", "stripos", "(", "$", "log", ",", "'devlog'", ")", "!==", "FALSE", ")", "{", "// copy message also to the developer log", "self", "::", "devLog", "(", "$", "msg", ",", "'Core'", ",", "self", "::", "SYSLOG_SEVERITY_WARNING", ")", ";", "}", "// do not use console in login screen", "if", "(", "stripos", "(", "$", "log", ",", "'console'", ")", "!==", "FALSE", "&&", "isset", "(", "$", "GLOBALS", "[", "'BE_USER'", "]", "->", "user", "[", "'uid'", "]", ")", ")", "{", "t3lib_utility_Debug", "::", "debug", "(", "$", "msg", ",", "$", "date", ",", "'Deprecation Log'", ")", ";", "}", "}" ]
Writes a message to the deprecation log. @param string $msg Message (in English). @return void
[ "Writes", "a", "message", "to", "the", "deprecation", "log", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5608-L5650
220,491
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.logDeprecatedFunction
public static function logDeprecatedFunction() { if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) { return; } // This require_once is needed for deprecation calls // thrown early during bootstrap, if the autoloader is // not instantiated yet. This can happen for example if // ext_localconf triggers a deprecation. require_once __DIR__.'/class.t3lib_utility_debug.php'; $trail = debug_backtrace(); if ($trail[1]['type']) { $function = new ReflectionMethod($trail[1]['class'], $trail[1]['function']); } else { $function = new ReflectionFunction($trail[1]['function']); } $msg = ''; if (preg_match('/@deprecated\s+(.*)/', $function->getDocComment(), $match)) { $msg = $match[1]; } // trigger PHP error with a short message: <function> is deprecated (called from <source>, defined in <source>) $errorMsg = 'Function ' . $trail[1]['function']; if ($trail[1]['class']) { $errorMsg .= ' of class ' . $trail[1]['class']; } $errorMsg .= ' is deprecated (called from ' . $trail[1]['file'] . '#' . $trail[1]['line'] . ', defined in ' . $function->getFileName() . '#' . $function->getStartLine() . ')'; // write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>) $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function']; $logMsg .= '() - ' . $msg.' - ' . t3lib_utility_Debug::debugTrail(); $logMsg .= ' (' . substr($function->getFileName(), strlen(PATH_site)) . '#' . $function->getStartLine() . ')'; self::deprecationLog($logMsg); }
php
public static function logDeprecatedFunction() { if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) { return; } // This require_once is needed for deprecation calls // thrown early during bootstrap, if the autoloader is // not instantiated yet. This can happen for example if // ext_localconf triggers a deprecation. require_once __DIR__.'/class.t3lib_utility_debug.php'; $trail = debug_backtrace(); if ($trail[1]['type']) { $function = new ReflectionMethod($trail[1]['class'], $trail[1]['function']); } else { $function = new ReflectionFunction($trail[1]['function']); } $msg = ''; if (preg_match('/@deprecated\s+(.*)/', $function->getDocComment(), $match)) { $msg = $match[1]; } // trigger PHP error with a short message: <function> is deprecated (called from <source>, defined in <source>) $errorMsg = 'Function ' . $trail[1]['function']; if ($trail[1]['class']) { $errorMsg .= ' of class ' . $trail[1]['class']; } $errorMsg .= ' is deprecated (called from ' . $trail[1]['file'] . '#' . $trail[1]['line'] . ', defined in ' . $function->getFileName() . '#' . $function->getStartLine() . ')'; // write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>) $logMsg = $trail[1]['class'] . $trail[1]['type'] . $trail[1]['function']; $logMsg .= '() - ' . $msg.' - ' . t3lib_utility_Debug::debugTrail(); $logMsg .= ' (' . substr($function->getFileName(), strlen(PATH_site)) . '#' . $function->getStartLine() . ')'; self::deprecationLog($logMsg); }
[ "public", "static", "function", "logDeprecatedFunction", "(", ")", "{", "if", "(", "!", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'enableDeprecationLog'", "]", ")", "{", "return", ";", "}", "// This require_once is needed for deprecation calls", "// thrown early during bootstrap, if the autoloader is", "// not instantiated yet. This can happen for example if", "// ext_localconf triggers a deprecation.", "require_once", "__DIR__", ".", "'/class.t3lib_utility_debug.php'", ";", "$", "trail", "=", "debug_backtrace", "(", ")", ";", "if", "(", "$", "trail", "[", "1", "]", "[", "'type'", "]", ")", "{", "$", "function", "=", "new", "ReflectionMethod", "(", "$", "trail", "[", "1", "]", "[", "'class'", "]", ",", "$", "trail", "[", "1", "]", "[", "'function'", "]", ")", ";", "}", "else", "{", "$", "function", "=", "new", "ReflectionFunction", "(", "$", "trail", "[", "1", "]", "[", "'function'", "]", ")", ";", "}", "$", "msg", "=", "''", ";", "if", "(", "preg_match", "(", "'/@deprecated\\s+(.*)/'", ",", "$", "function", "->", "getDocComment", "(", ")", ",", "$", "match", ")", ")", "{", "$", "msg", "=", "$", "match", "[", "1", "]", ";", "}", "// trigger PHP error with a short message: <function> is deprecated (called from <source>, defined in <source>)", "$", "errorMsg", "=", "'Function '", ".", "$", "trail", "[", "1", "]", "[", "'function'", "]", ";", "if", "(", "$", "trail", "[", "1", "]", "[", "'class'", "]", ")", "{", "$", "errorMsg", ".=", "' of class '", ".", "$", "trail", "[", "1", "]", "[", "'class'", "]", ";", "}", "$", "errorMsg", ".=", "' is deprecated (called from '", ".", "$", "trail", "[", "1", "]", "[", "'file'", "]", ".", "'#'", ".", "$", "trail", "[", "1", "]", "[", "'line'", "]", ".", "', defined in '", ".", "$", "function", "->", "getFileName", "(", ")", ".", "'#'", ".", "$", "function", "->", "getStartLine", "(", ")", ".", "')'", ";", "// write a longer message to the deprecation log: <function> <annotion> - <trace> (<source>)", "$", "logMsg", "=", "$", "trail", "[", "1", "]", "[", "'class'", "]", ".", "$", "trail", "[", "1", "]", "[", "'type'", "]", ".", "$", "trail", "[", "1", "]", "[", "'function'", "]", ";", "$", "logMsg", ".=", "'() - '", ".", "$", "msg", ".", "' - '", ".", "t3lib_utility_Debug", "::", "debugTrail", "(", ")", ";", "$", "logMsg", ".=", "' ('", ".", "substr", "(", "$", "function", "->", "getFileName", "(", ")", ",", "strlen", "(", "PATH_site", ")", ")", ".", "'#'", ".", "$", "function", "->", "getStartLine", "(", ")", ".", "')'", ";", "self", "::", "deprecationLog", "(", "$", "logMsg", ")", ";", "}" ]
Logs a call to a deprecated function. The log message will be taken from the annotation. @return void
[ "Logs", "a", "call", "to", "a", "deprecated", "function", ".", "The", "log", "message", "will", "be", "taken", "from", "the", "annotation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5671-L5707
220,492
moodle/moodle
lib/typo3/class.t3lib_div.php
t3lib_div.flushOutputBuffers
public static function flushOutputBuffers() { $obContent = ''; while ($content = ob_get_clean()) { $obContent .= $content; } // if previously a "Content-Encoding: whatever" has been set, we have to unset it if (!headers_sent()) { $headersList = headers_list(); foreach ($headersList as $header) { // split it up at the : list($key, $value) = self::trimExplode(':', $header, TRUE); // check if we have a Content-Encoding other than 'None' if (strtolower($key) === 'content-encoding' && strtolower($value) !== 'none') { header('Content-Encoding: None'); break; } } } echo $obContent; }
php
public static function flushOutputBuffers() { $obContent = ''; while ($content = ob_get_clean()) { $obContent .= $content; } // if previously a "Content-Encoding: whatever" has been set, we have to unset it if (!headers_sent()) { $headersList = headers_list(); foreach ($headersList as $header) { // split it up at the : list($key, $value) = self::trimExplode(':', $header, TRUE); // check if we have a Content-Encoding other than 'None' if (strtolower($key) === 'content-encoding' && strtolower($value) !== 'none') { header('Content-Encoding: None'); break; } } } echo $obContent; }
[ "public", "static", "function", "flushOutputBuffers", "(", ")", "{", "$", "obContent", "=", "''", ";", "while", "(", "$", "content", "=", "ob_get_clean", "(", ")", ")", "{", "$", "obContent", ".=", "$", "content", ";", "}", "// if previously a \"Content-Encoding: whatever\" has been set, we have to unset it", "if", "(", "!", "headers_sent", "(", ")", ")", "{", "$", "headersList", "=", "headers_list", "(", ")", ";", "foreach", "(", "$", "headersList", "as", "$", "header", ")", "{", "// split it up at the :", "list", "(", "$", "key", ",", "$", "value", ")", "=", "self", "::", "trimExplode", "(", "':'", ",", "$", "header", ",", "TRUE", ")", ";", "// check if we have a Content-Encoding other than 'None'", "if", "(", "strtolower", "(", "$", "key", ")", "===", "'content-encoding'", "&&", "strtolower", "(", "$", "value", ")", "!==", "'none'", ")", "{", "header", "(", "'Content-Encoding: None'", ")", ";", "break", ";", "}", "}", "}", "echo", "$", "obContent", ";", "}" ]
Ends and flushes all output buffers @return void
[ "Ends", "and", "flushes", "all", "output", "buffers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_div.php#L5815-L5836
220,493
moodle/moodle
calendar/classes/local/event/mappers/create_update_form_mapper.php
create_update_form_mapper.from_legacy_event_to_data
public function from_legacy_event_to_data(\calendar_event $legacyevent) { $legacyevent->count_repeats(); $data = $legacyevent->properties(); $data->timedurationuntil = $legacyevent->timestart + $legacyevent->timeduration; $data->duration = (empty($legacyevent->timeduration)) ? 0 : 1; if ($legacyevent->eventtype == 'group') { // Set up the correct value for the to display on the form. $data->groupid = $legacyevent->groupid; $data->groupcourseid = $legacyevent->courseid; } if ($legacyevent->eventtype == 'course') { // Set up the correct value for the to display on the form. $data->courseid = $legacyevent->courseid; } $data->description = [ 'text' => $data->description, 'format' => $data->format ]; // We don't want to return the context because it's not a // form value and breaks the validation. if (isset($data->context)) { unset($data->context); } return $data; }
php
public function from_legacy_event_to_data(\calendar_event $legacyevent) { $legacyevent->count_repeats(); $data = $legacyevent->properties(); $data->timedurationuntil = $legacyevent->timestart + $legacyevent->timeduration; $data->duration = (empty($legacyevent->timeduration)) ? 0 : 1; if ($legacyevent->eventtype == 'group') { // Set up the correct value for the to display on the form. $data->groupid = $legacyevent->groupid; $data->groupcourseid = $legacyevent->courseid; } if ($legacyevent->eventtype == 'course') { // Set up the correct value for the to display on the form. $data->courseid = $legacyevent->courseid; } $data->description = [ 'text' => $data->description, 'format' => $data->format ]; // We don't want to return the context because it's not a // form value and breaks the validation. if (isset($data->context)) { unset($data->context); } return $data; }
[ "public", "function", "from_legacy_event_to_data", "(", "\\", "calendar_event", "$", "legacyevent", ")", "{", "$", "legacyevent", "->", "count_repeats", "(", ")", ";", "$", "data", "=", "$", "legacyevent", "->", "properties", "(", ")", ";", "$", "data", "->", "timedurationuntil", "=", "$", "legacyevent", "->", "timestart", "+", "$", "legacyevent", "->", "timeduration", ";", "$", "data", "->", "duration", "=", "(", "empty", "(", "$", "legacyevent", "->", "timeduration", ")", ")", "?", "0", ":", "1", ";", "if", "(", "$", "legacyevent", "->", "eventtype", "==", "'group'", ")", "{", "// Set up the correct value for the to display on the form.", "$", "data", "->", "groupid", "=", "$", "legacyevent", "->", "groupid", ";", "$", "data", "->", "groupcourseid", "=", "$", "legacyevent", "->", "courseid", ";", "}", "if", "(", "$", "legacyevent", "->", "eventtype", "==", "'course'", ")", "{", "// Set up the correct value for the to display on the form.", "$", "data", "->", "courseid", "=", "$", "legacyevent", "->", "courseid", ";", "}", "$", "data", "->", "description", "=", "[", "'text'", "=>", "$", "data", "->", "description", ",", "'format'", "=>", "$", "data", "->", "format", "]", ";", "// We don't want to return the context because it's not a", "// form value and breaks the validation.", "if", "(", "isset", "(", "$", "data", "->", "context", ")", ")", "{", "unset", "(", "$", "data", "->", "context", ")", ";", "}", "return", "$", "data", ";", "}" ]
Generate the appropriate data for the form from a legacy event. @param \calendar_event $legacyevent @return stdClass
[ "Generate", "the", "appropriate", "data", "for", "the", "form", "from", "a", "legacy", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/mappers/create_update_form_mapper.php#L53-L80
220,494
moodle/moodle
calendar/classes/local/event/mappers/create_update_form_mapper.php
create_update_form_mapper.from_data_to_event_properties
public function from_data_to_event_properties(\stdClass $data) { $properties = clone($data); if ($data->eventtype == 'group') { if (isset($data->groupcourseid)) { $properties->courseid = $data->groupcourseid; unset($properties->groupcourseid); } if (isset($data->groupid)) { $properties->groupid = $data->groupid; } } else { // Default course id if none is set. if (empty($properties->courseid)) { if ($properties->eventtype == 'site') { $properties->courseid = SITEID; } else { $properties->courseid = 0; } } else { $properties->courseid = $data->courseid; } } // Decode the form fields back into valid event property. $properties->timeduration = $this->get_time_duration_from_form_data($data); return $properties; }
php
public function from_data_to_event_properties(\stdClass $data) { $properties = clone($data); if ($data->eventtype == 'group') { if (isset($data->groupcourseid)) { $properties->courseid = $data->groupcourseid; unset($properties->groupcourseid); } if (isset($data->groupid)) { $properties->groupid = $data->groupid; } } else { // Default course id if none is set. if (empty($properties->courseid)) { if ($properties->eventtype == 'site') { $properties->courseid = SITEID; } else { $properties->courseid = 0; } } else { $properties->courseid = $data->courseid; } } // Decode the form fields back into valid event property. $properties->timeduration = $this->get_time_duration_from_form_data($data); return $properties; }
[ "public", "function", "from_data_to_event_properties", "(", "\\", "stdClass", "$", "data", ")", "{", "$", "properties", "=", "clone", "(", "$", "data", ")", ";", "if", "(", "$", "data", "->", "eventtype", "==", "'group'", ")", "{", "if", "(", "isset", "(", "$", "data", "->", "groupcourseid", ")", ")", "{", "$", "properties", "->", "courseid", "=", "$", "data", "->", "groupcourseid", ";", "unset", "(", "$", "properties", "->", "groupcourseid", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "->", "groupid", ")", ")", "{", "$", "properties", "->", "groupid", "=", "$", "data", "->", "groupid", ";", "}", "}", "else", "{", "// Default course id if none is set.", "if", "(", "empty", "(", "$", "properties", "->", "courseid", ")", ")", "{", "if", "(", "$", "properties", "->", "eventtype", "==", "'site'", ")", "{", "$", "properties", "->", "courseid", "=", "SITEID", ";", "}", "else", "{", "$", "properties", "->", "courseid", "=", "0", ";", "}", "}", "else", "{", "$", "properties", "->", "courseid", "=", "$", "data", "->", "courseid", ";", "}", "}", "// Decode the form fields back into valid event property.", "$", "properties", "->", "timeduration", "=", "$", "this", "->", "get_time_duration_from_form_data", "(", "$", "data", ")", ";", "return", "$", "properties", ";", "}" ]
Generate the appropriate calendar_event properties from the form data. @param \stdClass $data @return stdClass
[ "Generate", "the", "appropriate", "calendar_event", "properties", "from", "the", "form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/mappers/create_update_form_mapper.php#L88-L116
220,495
moodle/moodle
calendar/classes/local/event/mappers/create_update_form_mapper.php
create_update_form_mapper.get_time_duration_from_form_data
private function get_time_duration_from_form_data(\stdClass $data) { if ($data->duration == 1) { return $data->timedurationuntil - $data->timestart; } else if ($data->duration == 2) { return $data->timedurationminutes * MINSECS; } else { return 0; } }
php
private function get_time_duration_from_form_data(\stdClass $data) { if ($data->duration == 1) { return $data->timedurationuntil - $data->timestart; } else if ($data->duration == 2) { return $data->timedurationminutes * MINSECS; } else { return 0; } }
[ "private", "function", "get_time_duration_from_form_data", "(", "\\", "stdClass", "$", "data", ")", "{", "if", "(", "$", "data", "->", "duration", "==", "1", ")", "{", "return", "$", "data", "->", "timedurationuntil", "-", "$", "data", "->", "timestart", ";", "}", "else", "if", "(", "$", "data", "->", "duration", "==", "2", ")", "{", "return", "$", "data", "->", "timedurationminutes", "*", "MINSECS", ";", "}", "else", "{", "return", "0", ";", "}", "}" ]
A helper function to calculate the time duration for an event based on the event_form data. @param \stdClass $data event_form data @return int
[ "A", "helper", "function", "to", "calculate", "the", "time", "duration", "for", "an", "event", "based", "on", "the", "event_form", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/mappers/create_update_form_mapper.php#L125-L133
220,496
moodle/moodle
admin/tool/log/store/database/classes/helper.php
helper.get_drivers
public static function get_drivers() { return array( '' => get_string('choosedots'), 'native/mysqli' => \moodle_database::get_driver_instance('mysqli', 'native')->get_name(), 'native/mariadb' => \moodle_database::get_driver_instance('mariadb', 'native')->get_name(), 'native/pgsql' => \moodle_database::get_driver_instance('pgsql', 'native')->get_name(), 'native/oci' => \moodle_database::get_driver_instance('oci', 'native')->get_name(), 'native/sqlsrv' => \moodle_database::get_driver_instance('sqlsrv', 'native')->get_name() ); }
php
public static function get_drivers() { return array( '' => get_string('choosedots'), 'native/mysqli' => \moodle_database::get_driver_instance('mysqli', 'native')->get_name(), 'native/mariadb' => \moodle_database::get_driver_instance('mariadb', 'native')->get_name(), 'native/pgsql' => \moodle_database::get_driver_instance('pgsql', 'native')->get_name(), 'native/oci' => \moodle_database::get_driver_instance('oci', 'native')->get_name(), 'native/sqlsrv' => \moodle_database::get_driver_instance('sqlsrv', 'native')->get_name() ); }
[ "public", "static", "function", "get_drivers", "(", ")", "{", "return", "array", "(", "''", "=>", "get_string", "(", "'choosedots'", ")", ",", "'native/mysqli'", "=>", "\\", "moodle_database", "::", "get_driver_instance", "(", "'mysqli'", ",", "'native'", ")", "->", "get_name", "(", ")", ",", "'native/mariadb'", "=>", "\\", "moodle_database", "::", "get_driver_instance", "(", "'mariadb'", ",", "'native'", ")", "->", "get_name", "(", ")", ",", "'native/pgsql'", "=>", "\\", "moodle_database", "::", "get_driver_instance", "(", "'pgsql'", ",", "'native'", ")", "->", "get_name", "(", ")", ",", "'native/oci'", "=>", "\\", "moodle_database", "::", "get_driver_instance", "(", "'oci'", ",", "'native'", ")", "->", "get_name", "(", ")", ",", "'native/sqlsrv'", "=>", "\\", "moodle_database", "::", "get_driver_instance", "(", "'sqlsrv'", ",", "'native'", ")", "->", "get_name", "(", ")", ")", ";", "}" ]
Returns list of fully working database drivers present in system. @return array
[ "Returns", "list", "of", "fully", "working", "database", "drivers", "present", "in", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/helper.php#L40-L49
220,497
moodle/moodle
admin/tool/log/store/database/classes/helper.php
helper.get_level_options
public static function get_level_options() { return array( \core\event\base::LEVEL_TEACHING => get_string('teaching', 'logstore_database'), \core\event\base::LEVEL_PARTICIPATING => get_string('participating', 'logstore_database'), \core\event\base::LEVEL_OTHER => get_string('other', 'logstore_database'), ); }
php
public static function get_level_options() { return array( \core\event\base::LEVEL_TEACHING => get_string('teaching', 'logstore_database'), \core\event\base::LEVEL_PARTICIPATING => get_string('participating', 'logstore_database'), \core\event\base::LEVEL_OTHER => get_string('other', 'logstore_database'), ); }
[ "public", "static", "function", "get_level_options", "(", ")", "{", "return", "array", "(", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_TEACHING", "=>", "get_string", "(", "'teaching'", ",", "'logstore_database'", ")", ",", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_PARTICIPATING", "=>", "get_string", "(", "'participating'", ",", "'logstore_database'", ")", ",", "\\", "core", "\\", "event", "\\", "base", "::", "LEVEL_OTHER", "=>", "get_string", "(", "'other'", ",", "'logstore_database'", ")", ",", ")", ";", "}" ]
Get a list of edu levels. @return array
[ "Get", "a", "list", "of", "edu", "levels", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/classes/helper.php#L56-L62
220,498
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.prepare_data
protected function prepare_data(int $timenow) { global $DB; $sql = "SELECT p.*, f.id AS forum, f.course FROM {forum_queue} q INNER JOIN {forum_posts} p ON p.id = q.postid INNER JOIN {forum_discussions} d ON d.id = p.discussion INNER JOIN {forum} f ON f.id = d.forum WHERE q.userid = :userid AND q.timemodified < :timemodified ORDER BY d.id, q.timemodified ASC"; $queueparams = [ 'userid' => $this->recipient->id, 'timemodified' => $timenow, ]; $posts = $DB->get_recordset_sql($sql, $queueparams); $discussionids = []; $forumids = []; $courseids = []; $userids = []; foreach ($posts as $post) { $discussionids[] = $post->discussion; $forumids[] = $post->forum; $courseids[] = $post->course; $userids[] = $post->userid; unset($post->forum); if (!isset($this->posts[$post->discussion])) { $this->posts[$post->discussion] = []; } $this->posts[$post->discussion][$post->id] = $post; } $posts->close(); if (empty($discussionids)) { // All posts have been removed since the task was queued. $this->empty_queue($this->recipient->id, $timenow); return; } list($in, $params) = $DB->get_in_or_equal($discussionids); $this->discussions = $DB->get_records_select('forum_discussions', "id {$in}", $params); list($in, $params) = $DB->get_in_or_equal($forumids); $this->forums = $DB->get_records_select('forum', "id {$in}", $params); list($in, $params) = $DB->get_in_or_equal($courseids); $this->courses = $DB->get_records_select('course', "id $in", $params); list($in, $params) = $DB->get_in_or_equal($userids); $this->users = $DB->get_records_select('user', "id $in", $params); $this->fill_digest_cache(); $this->empty_queue($this->recipient->id, $timenow); }
php
protected function prepare_data(int $timenow) { global $DB; $sql = "SELECT p.*, f.id AS forum, f.course FROM {forum_queue} q INNER JOIN {forum_posts} p ON p.id = q.postid INNER JOIN {forum_discussions} d ON d.id = p.discussion INNER JOIN {forum} f ON f.id = d.forum WHERE q.userid = :userid AND q.timemodified < :timemodified ORDER BY d.id, q.timemodified ASC"; $queueparams = [ 'userid' => $this->recipient->id, 'timemodified' => $timenow, ]; $posts = $DB->get_recordset_sql($sql, $queueparams); $discussionids = []; $forumids = []; $courseids = []; $userids = []; foreach ($posts as $post) { $discussionids[] = $post->discussion; $forumids[] = $post->forum; $courseids[] = $post->course; $userids[] = $post->userid; unset($post->forum); if (!isset($this->posts[$post->discussion])) { $this->posts[$post->discussion] = []; } $this->posts[$post->discussion][$post->id] = $post; } $posts->close(); if (empty($discussionids)) { // All posts have been removed since the task was queued. $this->empty_queue($this->recipient->id, $timenow); return; } list($in, $params) = $DB->get_in_or_equal($discussionids); $this->discussions = $DB->get_records_select('forum_discussions', "id {$in}", $params); list($in, $params) = $DB->get_in_or_equal($forumids); $this->forums = $DB->get_records_select('forum', "id {$in}", $params); list($in, $params) = $DB->get_in_or_equal($courseids); $this->courses = $DB->get_records_select('course', "id $in", $params); list($in, $params) = $DB->get_in_or_equal($userids); $this->users = $DB->get_records_select('user', "id $in", $params); $this->fill_digest_cache(); $this->empty_queue($this->recipient->id, $timenow); }
[ "protected", "function", "prepare_data", "(", "int", "$", "timenow", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT p.*, f.id AS forum, f.course\n FROM {forum_queue} q\n INNER JOIN {forum_posts} p ON p.id = q.postid\n INNER JOIN {forum_discussions} d ON d.id = p.discussion\n INNER JOIN {forum} f ON f.id = d.forum\n WHERE q.userid = :userid\n AND q.timemodified < :timemodified\n ORDER BY d.id, q.timemodified ASC\"", ";", "$", "queueparams", "=", "[", "'userid'", "=>", "$", "this", "->", "recipient", "->", "id", ",", "'timemodified'", "=>", "$", "timenow", ",", "]", ";", "$", "posts", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "queueparams", ")", ";", "$", "discussionids", "=", "[", "]", ";", "$", "forumids", "=", "[", "]", ";", "$", "courseids", "=", "[", "]", ";", "$", "userids", "=", "[", "]", ";", "foreach", "(", "$", "posts", "as", "$", "post", ")", "{", "$", "discussionids", "[", "]", "=", "$", "post", "->", "discussion", ";", "$", "forumids", "[", "]", "=", "$", "post", "->", "forum", ";", "$", "courseids", "[", "]", "=", "$", "post", "->", "course", ";", "$", "userids", "[", "]", "=", "$", "post", "->", "userid", ";", "unset", "(", "$", "post", "->", "forum", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "posts", "[", "$", "post", "->", "discussion", "]", ")", ")", "{", "$", "this", "->", "posts", "[", "$", "post", "->", "discussion", "]", "=", "[", "]", ";", "}", "$", "this", "->", "posts", "[", "$", "post", "->", "discussion", "]", "[", "$", "post", "->", "id", "]", "=", "$", "post", ";", "}", "$", "posts", "->", "close", "(", ")", ";", "if", "(", "empty", "(", "$", "discussionids", ")", ")", "{", "// All posts have been removed since the task was queued.", "$", "this", "->", "empty_queue", "(", "$", "this", "->", "recipient", "->", "id", ",", "$", "timenow", ")", ";", "return", ";", "}", "list", "(", "$", "in", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "discussionids", ")", ";", "$", "this", "->", "discussions", "=", "$", "DB", "->", "get_records_select", "(", "'forum_discussions'", ",", "\"id {$in}\"", ",", "$", "params", ")", ";", "list", "(", "$", "in", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "forumids", ")", ";", "$", "this", "->", "forums", "=", "$", "DB", "->", "get_records_select", "(", "'forum'", ",", "\"id {$in}\"", ",", "$", "params", ")", ";", "list", "(", "$", "in", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courseids", ")", ";", "$", "this", "->", "courses", "=", "$", "DB", "->", "get_records_select", "(", "'course'", ",", "\"id $in\"", ",", "$", "params", ")", ";", "list", "(", "$", "in", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ")", ";", "$", "this", "->", "users", "=", "$", "DB", "->", "get_records_select", "(", "'user'", ",", "\"id $in\"", ",", "$", "params", ")", ";", "$", "this", "->", "fill_digest_cache", "(", ")", ";", "$", "this", "->", "empty_queue", "(", "$", "this", "->", "recipient", "->", "id", ",", "$", "timenow", ")", ";", "}" ]
Prepare the data for this run. Note: This will also remove posts from the queue. @param int $timenow
[ "Prepare", "the", "data", "for", "this", "run", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L272-L328
220,499
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.empty_queue
protected function empty_queue(int $userid, int $timemodified) : void { global $DB; $DB->delete_records_select('forum_queue', "userid = :userid AND timemodified < :timemodified", [ 'userid' => $userid, 'timemodified' => $timemodified, ]); }
php
protected function empty_queue(int $userid, int $timemodified) : void { global $DB; $DB->delete_records_select('forum_queue', "userid = :userid AND timemodified < :timemodified", [ 'userid' => $userid, 'timemodified' => $timemodified, ]); }
[ "protected", "function", "empty_queue", "(", "int", "$", "userid", ",", "int", "$", "timemodified", ")", ":", "void", "{", "global", "$", "DB", ";", "$", "DB", "->", "delete_records_select", "(", "'forum_queue'", ",", "\"userid = :userid AND timemodified < :timemodified\"", ",", "[", "'userid'", "=>", "$", "userid", ",", "'timemodified'", "=>", "$", "timemodified", ",", "]", ")", ";", "}" ]
Empty the queue of posts for this user. @param int $userid user id which queue elements are going to be removed. @param int $timemodified up time limit of the queue elements to be removed.
[ "Empty", "the", "queue", "of", "posts", "for", "this", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L336-L343